상속: MonoBehaviour
예제 #1
0
    static public Vector3 GetNearestFriend(Vector3 s)
    {
        List <BasicEntity> enemyList = StateStaticComponent.enemyActionList;
        int num = -1;
        int min = -1;

        for (int i = 0; i < enemyList.Count; i++)
        {
            BasicEntity e   = enemyList[i];
            Vector3     pos = e.GetComponent <BlockInfoComponent>().m_logicPosition;
            e.GetComponent <BlockInfoComponent>().m_blockType = BlockType.None;
            List <Vector3> path = FindPath.GetPath(s, pos);
            e.GetComponent <BlockInfoComponent>().m_blockType = BlockType.Enemy;
            if (path != null && path.Count > 0)
            {
                if (i == 0)
                {
                    num = 0;
                    min = path.Count;
                }
                if (min > path.Count)
                {
                    min = path.Count;
                    num = i;
                }
            }
        }
        if (num >= 0)
        {
            return(enemyList[num].GetComponent <BlockInfoComponent>().m_logicPosition);
        }
        return(Vector3.down);
    }
예제 #2
0
	FindPath pathfindingScript; //FindPath script reference

	// Use this for initialization
	void Awake () {
		pathfindingScript = GameObject.Find("AStar").GetComponent<FindPath> ();

		//If a transform has not yet been manually assigned in the editor...
		if (trans == null) {
			//Get this transform
			trans = GetComponent<Transform> ();
		}

		//If a target transform has not yet been manually assigned in the editor...
		if (target == null) {
			//Find the PLayer transform
			target = GameObject.Find ("Player").transform;
		}

		//For however many enemies there are...
		for (int i = 0; i < trans.childCount; i++) {
			//Assign the Enemy Movement script to each enemy
			trans.GetChild (i).gameObject.AddComponent<EnemyMovement> ();
			//Assign each enemy a raycast ray
			trans.GetChild (i).GetComponent<EnemyMovement> ().ray = GameObject.Find ("Enemies").transform.GetChild (i).FindChild ("RayCast").GetComponent<Transform>();
			//Assign each enemy a set of waypoints to follow
			trans.GetChild (i).GetComponent<EnemyMovement> ().waypointsParent = GameObject.Find ("Waypoints").transform.GetChild (i);
		}
	}
예제 #3
0
 public void StopAll()
 {
     if (FindPath.IsRuning)
     {
         FindPath.Stop();
     }
     if (GotoTianzhufeng.IsRuning)
     {
         GotoTianzhufeng.Stop();
     }
     if (LianDan.IsRuning)
     {
         LianDan.Stop();
     }
     if (SongJing.IsRuning)
     {
         SongJing.Stop();
     }
     if (Zhenfa.IsRuning)
     {
         Zhenfa.Stop();
     }
     if (LuanZhou.IsRuning)
     {
         LuanZhou.Stop();
     }
     if (Caiqi.IsRuning)
     {
         Caiqi.Stop();
     }
     if (WuDangNew.IsRuning)
     {
         WuDangNew.Stop();
     }
 }
예제 #4
0
    public void Escape(BasicEnemy enemy)
    {
        BasicEntity entity = enemy.m_entity;
        VoxelBlocks map    = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks> ();

        List <BasicEntity> enemyList = entity.GetComponent <MonitorComponent> ().m_enemy;

        if (AiToInput.CallFriend(entity, enemyList))
        {
            //呼叫成功
            StateComponent state = entity.GetComponent <StateComponent> ();

            state.AnimationStart();

            state.m_actionPoint -= 1;
            state.Invoke("AnimationEnd", 1);
            return;
        }

        Vector3 escapePos = FindPath.GetNearestFriend(entity.GetComponent <BlockInfoComponent> ().m_logicPosition);

        if (escapePos == Vector3.down)
        {
            //无路可走等死
            return;
        }
        else
        {
            AiToInput.Move(entity, escapePos);
        }
        return;
    }
예제 #5
0
    public void Attack(BasicEntity entity)
    {
        VoxelBlocks map  = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
        Vector3     ePos = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;

        Vector3 tPos = target.GetComponent <BlockInfoComponent> ().m_logicPosition;

        if ((Mathf.Abs(ePos.x - tPos.x) <= 1.5f) && (Mathf.Abs(ePos.y - tPos.y) <= 1.5f))
        {
            AiToInput.Attack(entity, tPos);
        }
        else
        {
            target.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.None;
            List <Vector3> path = FindPath.GetPath(ePos, tPos);
            target.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.Player;
            if (path != null)
            {
                path.Remove(tPos);
                tPos = path [path.Count - 1];
                AiToInput.Move(entity, tPos);
            }
            else
            {
                Debug.Log("Fail to Attack");
            }
        }
    }
    public void Survey(BasicEntity entity)
    {
        List <Vector3> voice    = entity.GetComponent <MonitorComponent> ().m_voice;
        Vector3        mPos     = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;
        List <Vector3> newVoice = new List <Vector3> ();
        List <int>     i        = new List <int> ();

        for (int j = 0; j < voice.Count; j++)
        {
            Vector3 pos = voice [j];
            if (mPos != pos && FindPath.GetPathByStep(mPos, pos, 100) != Vector3.down)
            {
                newVoice.Add(pos);
            }
            else
            {
                i.Add(j);
            }
        }
        for (int j = 0; j < i.Count; j++)
        {
            voice.Remove(voice [i [j]]);
        }

        if (newVoice.Count != 0)
        {
            AiToInput.Move(entity, newVoice [newVoice.Count - 1]);
        }
    }
예제 #7
0
    public void init()
    {
        //set ref
        GameObject agent     = Ref.getActiveAgent();
        GameObject managerGO = Ref.getManagerGO();
        GameObject plane     = Ref.getPlane();

        managerScript    = managerGO.GetComponent <Manager>();
        findPathScript   = agent.GetComponent <FindPath>();
        followPathScript = agent.GetComponent <FollowPath>();
        agentPropsScript = agent.GetComponent <AgentProps>();

        visObstManagerScript = agent.GetComponent <VisibleObstManager>();

        nodeDiameter = nodeRadius * 2;

        if (levelTxt != null)
        {
            lines = levelTxt.text.Split('\n');
            string firstLine = lines[0];
            gridWorldSize.x = int.Parse(firstLine.Split(' ')[0]);
            gridWorldSize.y = int.Parse(firstLine.Split(' ')[1]);
        }
        GridSizeX = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter);
        GridSizeY = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter);
        GridSizeZ = agentPropsScript.cooperationLenght * 2 + 1;

        plane.transform.localScale = new Vector3(GridSizeX / 10f, 1, GridSizeY / 10f);
        worldBottomLeft            = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

        CreateGrid();
    }
예제 #8
0
        public void TestGetWay2()
        {
            Field field = new Field(10, 10);

            field[1, 2].Contain = BubbleSize.Big;
            field[0, 3].Contain = BubbleSize.Big;
            Cell from = field[0, 2];
            Cell to   = field[3, 4];

            FindPath    findPath = new FindPath();
            List <Cell> way;
            List <Cell> expectedWay = new List <Cell>()
            {
                field[0, 2],
                field[0, 1],
                field[1, 1],
                field[2, 1],
                field[3, 1],
                field[3, 2],
                field[3, 3],
                field[3, 4]
            };

            Assert.IsTrue(findPath.TryGetPath(field, from, to, out way));
            CollectionAssert.AllItemsAreNotNull(way);
            CollectionAssert.AllItemsAreUnique(way);
            CollectionAssert.AreEqual(expectedWay, way);
        }
예제 #9
0
 /// <summary>
 /// Follow the specified path.
 /// </summary>
 /// <param name="path">Path.</param>
 public void Follow(FindPath path)
 {
     StopCoroutine("FollowPath");
     m_Path             = path;
     transform.position = m_Path.nodes[0].transform.position;
     StartCoroutine("FollowPath");
 }
예제 #10
0
 public static void ScheduleFindPath(Tile start, Tile end)
 {
     EndFindPath();
     waiting     = false;
     path        = new FindPath(start, end);
     current_job = path.Schedule();
 }
예제 #11
0
        public void TestGetWay2()
        {
            Field field = new Field(10, 10);

            field.Cells[1, 2].Contain = BubbleSize.Big;
            field.Cells[0, 3].Contain = BubbleSize.Big;
            Cell from = field.Cells[0, 2];
            Cell to   = field.Cells[3, 4];

            FindPath    findPath = new FindPath(field, from, to);
            List <Cell> Way;
            List <Cell> ExpectedWay = new List <Cell>()
            {
                field.Cells[0, 2],
                field.Cells[0, 1],
                field.Cells[1, 1],
                field.Cells[2, 1],
                field.Cells[3, 1],
                field.Cells[3, 2],
                field.Cells[3, 3],
                field.Cells[3, 4]
            };

            Assert.IsTrue(findPath.GetWay(out Way));
            CollectionAssert.AllItemsAreNotNull(Way);
            CollectionAssert.AllItemsAreUnique(Way);
            CollectionAssert.AreEqual(ExpectedWay, Way);
        }
예제 #12
0
 public override void OnInspectorGUI()
 {
     m_Graph.nodes.Clear();
     foreach (Transform child in m_Graph.transform)
     {
         Node node = child.GetComponent <Node>();
         if (node != null)
         {
             m_Graph.nodes.Add(node);
         }
     }
     base.OnInspectorGUI();
     EditorGUILayout.Separator();
     m_From = (Node)EditorGUILayout.ObjectField("From", m_From, typeof(Node), true);
     m_To   = (Node)EditorGUILayout.ObjectField("To", m_To, typeof(Node), true);
     //m_Follower = (Follower)EditorGUILayout.ObjectField("Follower", m_Follower, typeof(Follower), true);
     if (GUILayout.Button("Show Shortest Path"))
     {
         m_Path = m_Graph.GetShortestPath(m_From, m_To);
         if (m_Follower != null)
         {
             m_Follower.Follow(m_Path);
         }
         Debug.Log(m_Path);
         SceneView.RepaintAll();
     }
 }
    void OnTriggerEnter(Collider collider)
    {
        //Debug.Log(collider.name);

        if (collider.name == "Indicator")
        {
            findPath = collider.transform.GetComponent <FindPath>();

            if (gameObject.name == "Player")
            {
                findPath.SetDirection();
            }

            direction = findPath.direction + (findPath.transform.position - transform.position);
            playerManager.moveForward.SetDirection(direction);
        }

        if (collider.name == "Box")
        {
            // Debug.Log(collider.name);
            // Detener contador
        }

        if (collider.name.Contains("Platform"))
        {
            // Debug.Log(collider.name);
            // Comenzar contador para detectar box collider
        }
    }
예제 #14
0
    void Bomb(BasicEntity entity, float mr, float ridus, int demage)
    {
        InputComponent input = entity.GetComponent <InputComponent>();
        VoxelBlocks    map   = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();

        //获取鼠标位置与角色位置的距离
        float r = (input.currentPos - entity.GetComponent <BlockInfoComponent>().m_logicPosition).magnitude;

        //若距离大于预设值则退出
        if (r > mr)
        {
            return;
        }
        //获取炸弹投掷后可能影响的范围
        List <Vector3> ar = FindPath.GetArea(input.currentPos, Mathf.FloorToInt(ridus));
        //显示炸弹影响范围
        List <DeadComponent> mc = new List <DeadComponent>();

        UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();

        ui.ShowUI(ar, 3);

        //获取该范围内所有的敌人的生命脚本
        foreach (var pos in ar)
        {
            BlockInfo block = map.GetBlockByLogicPos(pos);
            if (block != null && block.entity != null)
            {
                if (block.entity.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy)
                {
                    mc.Add(block.entity.GetComponent <DeadComponent>());
                }
            }
        }
        //显示可被影响的敌人

        //若按下鼠标左键则扔出炸弹,影响周围敌人。
        if (input.leftButtonDown)
        {
            Debug.Log(mc.Count);
            foreach (var m in mc)
            {
                if (m != null)
                {
                    m.hp -= demage;
                }
            }
            ItemComponent itemComp = entity.GetComponent <ItemComponent>();
            //移除炸弹
            itemComp.item.Remove(ItemType.Bomb);
            entity.GetComponent <ItemComponent>().current = ItemType.Null;
            //使用一次消耗一点行动点
            StateComponent state = entity.GetComponent <StateComponent>();
            state.m_actionPoint -= 1;
            state.AnimationStart();

            state.Invoke("AnimationEnd", 1);
        }
    }
예제 #15
0
    public void Test()
    {
        FindPath.Instance().SetDestination(new Vector3(-18, -6));
        Waypoint next = FindPath.Instance().DoStep(FindPath.Instance().GetCurrentWaypoint(this.transform.position));

        Debug.Log(next.gameObject);
        transform.position = next.transform.position;
    }
예제 #16
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     dijkstra = new Dijkstra(graph);
 }
예제 #17
0
 public MovementState(Grid grid, Unit unit, Int2 destination, FindPath findPath)
 {
     _grid         = grid;
     _findPath     = findPath;
     _unit         = unit;
     _position     = grid[_unit];
     _nextPosition = _position;
     _destination  = destination;
 }
예제 #18
0
파일: Grid.cs 프로젝트: hafewa/APathDemo-1
    private float time = 0.0f;                 //计时

    void Start()
    {
        nodeDiameter = nodeRadius * 2;
        gridCountX   = Mathf.RoundToInt(gridSize.x / nodeDiameter);
        gridCountY   = Mathf.RoundToInt(gridSize.y / nodeDiameter);
        grid         = new Node[gridCountX, gridCountY];
        CreateGrid();
        path = GetComponent <FindPath>();//初始化
    }
예제 #19
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (var entity in entities)
        {
            KnockComponent   knock = entity.gameObject.GetComponent <KnockComponent>();
            AbilityComponent ab    = entity.GetComponent <AbilityComponent>();
            InputComponent   input = entity.GetComponent <InputComponent>();
            StateComponent   ap    = entity.GetComponent <StateComponent>();

            int i = AiToInput.GetAbilityCount(entity, M_LinkedType);
            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                knock.m_area = null;
                continue;
            }
            //获取影响范围
            if (knock.m_area == null)
            {
                knock.m_area = FindPath.GetArea(knock.GetComponent <BlockInfoComponent>().m_logicPosition, knock.m_ridus);
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();
            ui.ShowUI(knock.m_area, 3);
            VoxelBlocks        map   = GameObject.Find("Voxel Map").GetComponent <VoxelBlocks>();
            List <BasicEntity> enemy = new List <BasicEntity>();


            //获取影响范围内的敌人
            foreach (var pos in knock.m_area)
            {
                var e = map.GetBlockByLogicPos(pos).entity;
                if (e != null)
                {
                    if (e.GetComponent <BlockInfoComponent>().m_blockType == BlockType.Enemy)
                    {
                        enemy.Add(e);
                    }
                }
            }
            //UI显示范围与敌人
            if (input.leftButtonDown)
            {
                foreach (var e in enemy)
                {
                    Debug.Log(e.name);
                    e.GetComponent <MonitorComponent>().m_voice.Add(entity.GetComponent <BlockInfoComponent>().m_logicPosition);
                }
                ui.ShowUI(null, 3);
                StateComponent state = entity.GetComponent <StateComponent>();
                state.m_actionPoint -= 1;
                state.AnimationStart();

                state.Invoke("AnimationEnd", 1);
            }
        }
    }
    private void StartFindPath()
    {
        Drawing.ResetLine(AllVertexs);
        List <Vertex> path = FindPath.Find(AllVertexs, StartVertex, EndVertex, IsCustomSetWeight);

        if (path != null && path.Count > 0)
        {
            Drawing.Draw(path);
        }
        onResultPath?.Invoke(path);
    }
예제 #21
0
 public override void TakeAction()
 {
     // 1: Don't do anything if the object isn't mobile. (Can't move)
     // 2: Pop? if the ZoneID is NULL?
     // 3: Pop? if the destination Zone is NULL?
     if (!ParentBrain.isMobile())
     {
         FailToParent();
     }
     else if (ParentBrain.pPhysics.CurrentCell.ParentZone.ZoneID == null)
     {
         Pop();
     }
     else if (dZone == null)
     {
         Pop();
     }
     else
     {
         FindPath findPath = new FindPath(
             ParentBrain.pPhysics.CurrentCell.ParentZone.ZoneID,
             ParentBrain.pPhysics.CurrentCell.X,
             ParentBrain.pPhysics.CurrentCell.Y,
             dZone,
             dCx,
             dCy,
             ParentBrain.limitToAquatic(),
             false,
             ParentBrain.ParentObject);
         ParentBrain.ParentObject.UseEnergy(1000);
         if (findPath.bFound)
         {
             findPath.Directions.Reverse();
             int num = 0;
             if (MaxTurns > -1)
             {
                 Pop();
             }
             foreach (string direction in findPath.Directions)
             {
                 PushGoal((GoalHandler) new rr_PublicStep(direction));
                 ++num;
                 if (MaxTurns > -1 && num >= MaxTurns)
                 {
                     break;
                 }
             }
         }
         else
         {
             FailToParent();
         }
     }
 }
예제 #22
0
    public void init()
    {
        managerScript = GameObject.Find("Manager").GetComponent <Manager>();

        speed              = GetComponent <AgentProps>().getSpeed();
        findPathScript     = GetComponent <FindPath>();
        gridScript         = GameObject.Find("Grid").GetComponent <Grid>();
        waitTime           = managerScript.timeResolution;
        startNode          = gridScript.NodeFromWorldPoint(transform.position);
        prevPos            = transform.position;
        pathHalfPointIndex = (managerScript.getActiveAgent().GetComponent <AgentProps>().cooperationLenght * 2) / 2;
    }
예제 #23
0
 bool CheckPath(Room room)
 {
     for (int i = 0; i < room.exits.Count; i++)
     {
         FindPath path = new FindPath(room.grid, Elements.button);
         if (!path.IsPath(room.entrance, room.exits[i]))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #24
0
    public void Release()
    {
        Time.timeScale = 1f;
        this.Bullet.Release();
        this.PlayerBullet.Release();
        this.Effect.Release();
        this.Form.Release();
        this.GoodsCreate.Release();
        if (this._Path != null)
        {
            this._Path.DeInit();
        }
        this.Game.Release();
        this.EntityCache.Release();
        this.Entity.DeInit();
        this.Mode.DeInit();
        this.MapEffect.Release();
        LocalModelManager.Instance.Drop_Drop.ClearGoldDrop();
        CInstance <TipsManager> .Instance.Clear();

        Updater.GetUpdater().OnRelease();
        Updater.UpdaterDeinit();
        Goods1151.DoorData.DeInit();
        Object.DestroyImmediate(GameNode.m_Battle);
        GameNode.MapCacheNode.DestroyChildren();
        GameLogic.Hold.Sound.DeInit();
        if (this._MapCreator != null)
        {
            this._MapCreator.Deinit();
        }
        if (this._Entity != null)
        {
            Object.DestroyImmediate(this._Entity.gameObject);
            this._Entity = null;
        }
        TimerBase <Timer> .Unregister();

        TimeClock.Clear();
        GameNode.m_HP.DestroyChildren();
        this._Game         = null;
        this._Bullet       = null;
        this._PlayerBullet = null;
        this._Effect       = null;
        this._MapEffect    = null;
        this._EntityCache  = null;
        this._MapCreator   = null;
        this._Path         = null;
        this._GoodsCreate  = null;
        this._Mode         = null;
        this._Form         = null;
        Goods1151.DoorData = null;
        GC.Collect();
    }
    public void Initialize(Transform gridTransform, LayerMask unwalkableLayerMask, FP nodeUnitSize, int nodeAmountX, int nodeAmountY)
    {
        _transformPosition   = new TSVector(gridTransform.position.x, gridTransform.position.y, gridTransform.position.z);
        _transformScale      = new TSVector(gridTransform.localScale.x, gridTransform.localScale.y, gridTransform.localScale.z);
        _unwalkableLayerMask = unwalkableLayerMask;
        _nodeUnitSize        = nodeUnitSize;
        _nodeAmountX         = nodeAmountX;
        _nodeAmountY         = nodeAmountY;

        _grid = new Node[_nodeAmountX, _nodeAmountY];
        _path = new FindPath();
    }
예제 #26
0
        public void TestGetWay_WayDoesntExsist2()
        {
            Field field = new Field(10, 10);

            field.Cells[3, 4].Contain = BubbleSize.Big;
            Cell        from     = field.Cells[0, 2];
            Cell        to       = field.Cells[3, 4];
            FindPath    findPath = new FindPath(field, from, to);
            List <Cell> Way;

            Assert.IsFalse(findPath.GetWay(out Way));
        }
예제 #27
0
        public void Create_Map()
        {
            StringBuilder sb         = new StringBuilder();
            int           squareSize = 20;

            CreateMap cm  = new CreateMap();
            var       map = cm.CreateMapTiles(squareSize);

            for (int i = 0; i < squareSize; i++)
            {
                for (int j = 0; j < squareSize; j++)
                {
                    if (map.GetLocationType(j, i) == RTSGameMap.RTSGameMapOccupied.True)
                    {
                        sb.Append("#");
                    }
                    else
                    {
                        sb.Append(".");
                    }
                }
                Debug.WriteLine(sb.ToString());
                sb.Clear();
            }

            FindPath       fp         = new FindPath();
            List <History> mapHistory = fp.FindPathThroughMap(map);

            for (int i = 0; i < squareSize; i++)
            {
                for (int j = 0; j < squareSize; j++)
                {
                    if (map.GetLocationType(j, i) == RTSGameMap.RTSGameMapOccupied.True)
                    {
                        sb.Append("#");
                    }
                    else
                    {
                        if (mapHistory.Where(x => x.Location.x == j && x.Location.y == i).Any())
                        {
                            sb.Append("X");
                        }
                        else
                        {
                            sb.Append(".");
                        }
                    }
                }
                Debug.WriteLine(sb.ToString());
                sb.Clear();
            }
        }
예제 #28
0
        private static TerritoryIDType?CommanderDirective(BotMain bot, TerritoryIDType commanderOn)
        {
            var directive = bot.Directives.SingleOrDefault(o => o.StartsWith("CommanderRunTo "));

            if (directive == null)
            {
                return(null);
            }

            var runTo = (TerritoryIDType)int.Parse(directive.RemoveFromStartOfString("CommanderRunTo "));

            return(FindPath.TryFindShortestPath(bot, commanderOn, t => t == runTo)[0]);
        }
예제 #29
0
        public void TestGetWay_WayDoesntExsist1()
        {
            Field field = new Field(10, 10);

            field[1, 2].Contain = BubbleSize.Big;
            field[0, 3].Contain = BubbleSize.Big;
            field[0, 1].Contain = BubbleSize.Big;
            Cell        from     = field[0, 2];
            Cell        to       = field[3, 4];
            FindPath    findPath = new FindPath();
            List <Cell> way;

            Assert.IsFalse(findPath.TryGetPath(field, from, to, out way));
        }
예제 #30
0
        /// <summary>
        /// Find a path to a room, using a rule. If a room has been found a path is saved and the target room is set.
        /// </summary>
        /// <param name="rule">The rule that is used for searching a room.</param>
        public void FindAndTargetRoom(FindPath rule)
        {
            // If the person is inside the elevator, set its target room for when he exits.
            if (_elevator != null)
            {
                Path       = _pathFinder.Find(CurrentRoom, rule);
                TargetRoom = Path.Last();
                return;
            }

            // Set the bool if the elevator is allowed to be used.
            _pathFinder.UseElevator = !Evacuating;

            // Find the path to the target room.
            Path = _pathFinder.Find(CurrentRoom, rule);

            // Do some elevator shiz.
            if (CalledElevator)
            {
                if (TargetShaft != null)
                {
                    TargetShaft.ElevatorArrival -= TargetShaft_ElevatorArrival;
                    _elevator   = null;
                    TargetShaft = null;
                    StartShaft.ElevatorArrival -= Person_ElevatorArrival;
                    StartShaft = null;
                }
                CalledElevator = false;
            }

            // Do stuff if there is a path.
            if (Path != null)
            {
                // The target room is the last room in the path.
                TargetRoom = Path.Last();

                // Get out of the room if the person is inside the room.
                if (Inside)
                {
                    Inside = false;
                    CurrentRoom.PeopleCount--;

                    // Call the departure event.
                    OnDeparture();
                }

                // Move this person to the center of the room.
                CurrentTask = PersonTask.MovingCenter;
            }
        }
예제 #31
0
파일: Cell.cs 프로젝트: Jonhiew98/Unity
    public void FindDijkstraPath()
    {
        if (startNode != null && endNode != null)
        {
            // Execute Shortest Path.
            FindPath         finder = gameObject.GetComponent <FindPath>();
            List <Transform> paths  = finder.findDijkstraPath(startNode, endNode);

            foreach (Transform path in paths)
            {
                Renderer sr = path.GetComponent <Renderer>();
                sr.material.color = Color.yellow;
            }
        }
    }
예제 #32
0
	FindPath pathfindingScript; //FindPath script reference

	//Instead of Start() for script referencing
	void Awake() {
		//Gets the script from the object found
		pathfindingScript = GameObject.Find("AStar").GetComponent<FindPath> ();
	}
 void Awake()
 {
     instance = this;
     pathFinding = GetComponent<FindPath>();
 }