Created
January 17, 2018 13:16
-
-
Save raveneer/9c6e1268bc8de7b17160cfb6fb7af747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
using Entitas; | |
using UnityEngine.Tilemaps; | |
using Zenject; | |
/// <summary> | |
/// </summary> | |
public class ZoneDivideSystem : ReactiveSystem<GameEntity>, IInitializeSystem | |
{ | |
[Inject] private MapSpec _mapSpec; | |
[Inject] private ITMapDivider _mapDivider; | |
[Inject] private EventManager _eventManager; | |
private Contexts _contexts; | |
public int DevideRunCount = 0; | |
[Inject] | |
public ZoneDivideSystem(Contexts contexts) : base(contexts.game) | |
{ | |
_contexts = contexts; | |
} | |
public void Initialize() | |
{ | |
DivideZone(); | |
} | |
protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context) | |
{ | |
return context.CreateCollector(GameMatcher | |
.AllOf(GameMatcher.Coord, GameMatcher.PathBlock) | |
); | |
} | |
protected override bool Filter(GameEntity entity) | |
{ | |
return true; | |
} | |
protected override void Execute(List<GameEntity> entities) | |
{ | |
Tribes.Logger.Log("ZoneDivideSystem reactive!"); | |
if (entities.Count >= 2) | |
{ | |
DivideZone(); | |
DevideRunCount++; //리액티브 검증용 | |
return; | |
} | |
var entity = entities.First(); | |
var coord = entity.coord.Value; | |
var isPathblock = entity.isPathBlock; | |
var pathNodes = _contexts.game.pathNode.Nodes; | |
if (IsDivideZoneNeeded(coord, isPathblock, pathNodes)) | |
{ | |
DivideZone(); | |
DevideRunCount++; //리액티브 검증용 | |
} | |
else | |
{ | |
SetZoneNumberSingleTile(coord, !isPathblock, pathNodes); | |
} | |
} | |
private void DivideZone() | |
{ | |
Tribes.Logger.Log("!!!DivideZone!!!"); | |
var pathNodeArray = _contexts.game.pathNode.Nodes; | |
_mapDivider.Divide(pathNodeArray, 1); | |
_contexts.game.pathNodeEntity.ReplacePathNode(pathNodeArray); | |
_contexts.game.isNeedZoneDivide = false; | |
_contexts.game.isNeedZoneMapDraw = true; | |
} | |
public bool IsDivideZoneNeeded(Coord coord, bool isWalkable, TPathNode[,] pathNodes) | |
{ | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment