예제 #1
0
파일: Navigation.cs 프로젝트: Luden/SandBox
        public Navigation(IUnitObject unitObject)
        {
            var provider = ManagerProvider.Instance;

            _timeManager  = provider.TimeManager;
            _unitObject   = unitObject;
            Neighbourhood = new Neighbourhood(_unitObject);
        }
예제 #2
0
 /// <summary>
 /// Adds a path from a coordinate to the object.
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void AddPathFrom(IUnitObject obj, int x, int y)
 {
     if (finished)
     {
         Node node = mapData.GetNode(x, y);
         if (node.ClosedListId == searchID)
         {
             obj.Unit.Body.RetracePath(node);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Add all search agents prior searching to the closed list.
 /// </summary>
 /// <param name="subject"></param>
 /// <param name="allAgents"></param>
 private void AddSearchAgentsToClosed(IUnitObject subject, UnitObjectCollection allAgents)
 {
     for (int i = 0; i < allAgents.Count; i++)
     {
         IUnitObject obj = allAgents[i];
         if (!ReferenceEquals(subject, obj))
         {
             Vector2Int tilePosition = obj.Unit.Body.TilePosition;
             Node       node         = mapData.GetNode(tilePosition.x, tilePosition.y);
             node.ClosedListId = searchID;
             node.InitializeMaximized();
         }
     }
 }
예제 #4
0
파일: Unit.cs 프로젝트: Luden/SandBox
        public Unit(int id, IUnitObject unitObject, Faction startingFaction)
        {
            Id         = id;
            UnitObject = unitObject;

            var provider = ManagerProvider.Instance;

            Player           = provider.PlayerManager.GetPlayer(startingFaction);
            CommandProcessor = new CommandProcessor(provider.CommandManager.CommandFactory, provider.TimeManager, provider.GameSettings.UnitCommandsUpdatePeriod, this);
            Partset          = new Partset();
            Navigation       = new Navigation(UnitObject);
            Following        = new Following(Navigation, provider.TimeManager);
            Targeting        = new UnitTargeting(Player.Faction);
            Arsenal          = new Arsenal(Id, Navigation, Targeting, Following, Partset, provider.ShotsManager, provider.TimeManager);
            Selectable       = new Selectable();
            Visibility       = new Visibility(Player.Faction);
            Hull             = new Hull();
            Hull.OnDeath    += Die;
        }
예제 #5
0
        void Start()
        {
            gameCore     = GameObject.Find("GameCore").GetComponent <GameCore>();
            components   = GameObject.Find("GameComponents").GetComponent <GameComponents>();
            smoothCamera = GameObject.Find("MainCamera").GetComponent <SmoothCamera>();
            partyLeader  = GameObject.Find("PartyLeader").GetComponent <PartyLeader>();

            movementNodes = new NodeCollection();

            explorationUI = new ExplorationUI(gameCore.Party, partyLeader, smoothCamera, nodeSelection, pathPoints);

            Dictionary <ExplorationStates, IState <ExplorationScene> > states = new Dictionary <ExplorationStates, IState <ExplorationScene> >();

            states.Add(ExplorationStates.CALCULATE_PATH, new ExplorationCalculatePathState());
            states.Add(ExplorationStates.PREPARE_UI, new ExplorationPrepareUIState());
            states.Add(ExplorationStates.RUN_ACTION, new ExplorationRunActionState());
            states.Add(ExplorationStates.WAIT_FOR_UI_ACTION, new ExplorationWaitForUIActionState());
            StateMachine = new StateMachine <ExplorationScene, ExplorationStates>(this, states);
            StateMachine.Initialize(ExplorationStates.CALCULATE_PATH);
        }
예제 #6
0
        public ExplorationUI(Party party, IUnitObject partyLeader, SmoothCamera smoothCamera, GridSelection nodeSelection, PathPointCollection pathPoints)
        {
            this.party        = party;
            this.partyLeader  = partyLeader;
            this.smoothCamera = smoothCamera;

            movementNodes      = null;
            retraceNode        = null;
            this.nodeSelection = nodeSelection;
            this.pathPoints    = pathPoints;

            Dictionary <ExplorationUIStates, IState <ExplorationUI> > states = new Dictionary <ExplorationUIStates, IState <ExplorationUI> >();

            states.Add(ExplorationUIStates.HALT, new ExplorationUIHaltState());
            states.Add(ExplorationUIStates.WAIT_FOR_INPUT, new ExplorationUIWaitForInputState());
            states.Add(ExplorationUIStates.TRACE_PATH, new ExplorationUITracePathState());
            states.Add(ExplorationUIStates.WAIT_FOR_CONFIRM, new ExplorationUIWaitForConfirmState());
            states.Add(ExplorationUIStates.FIRE_MOVE_ACTION, new ExplorationUIFireMoveActionState());
            StateMachine = new StateMachine <ExplorationUI, ExplorationUIStates>(this, states);
            StateMachine.Initialize(ExplorationUIStates.HALT);
        }
예제 #7
0
    public void AddUnit(IUnitObject unitObject, Faction faction, Dictionary <int, PartType> parts = null)
    {
        var unit = new Unit(++_lastID, unitObject, faction);

        unitObject.Init(unit);

        if (parts != null)
        {
            foreach (var pair in parts)
            {
                unit.Partset.AttachPart(pair.Key, _partsManager.CreatePart(pair.Value));
            }
        }

        Units.Add(unit);
        unit.OnDeath += OnUnitDeath;

        if (OnUnitCreated != null)
        {
            OnUnitCreated(unit);
        }
    }
예제 #8
0
        /// <summary>
        /// Initialize the pathfinder before starting the search.
        /// </summary>
        /// <param name="searchAgent"></param>
        /// <param name="allAgents"></param>
        public void Initialize(IUnitObject searchAgent, UnitObjectCollection allAgents)
        {
            searchID++;

            Vector2Int tilePosition = searchAgent.Unit.Body.TilePosition;
            Node       startNode    = mapData.GetNode(tilePosition.x, tilePosition.y);

            startNode.InitializeMinimized();

            openList.Clear();

            startNode.OpenListId = searchID;
            openList.Add(startNode);

            AddSearchAgentsToClosed(searchAgent, allAgents);

            initialized = true;
            finished    = false;
            iterations  = 0;

            current = null;
        }
예제 #9
0
 void OnTriggerExit(IUnitObject other)
 {
     _neighbours.Remove(other);
 }
예제 #10
0
 void OnTriggerEnter(IUnitObject other)
 {
     _neighbours.Add(other);
 }
예제 #11
0
 public Neighbourhood(IUnitObject unitObject)
 {
     _unitObject = unitObject;
     _unitObject.OnColliderEnter += OnTriggerEnter;
     _unitObject.OnColliderExit  += OnTriggerExit;
 }