示例#1
0
		public static void Init(){
			if(instance!=null) return;
			
			GameObject obj=new GameObject();
			instance=obj.AddComponent<PathFinder>();
			
			obj.name="PathFinder";
		}
示例#2
0
 void Awake()
 {
     if(instance!=null) instance=this;
 }
示例#3
0
		public void Awake(){
			if(instance!=null) return;
			instance=this;
		}
示例#4
0
        public bool UpdatePathMaps(UnitTower tow, bool destroy = false)
        {
            int index_z = (int)Mathf.Round(tow.Platform.transform.position.z - platform_min_z) / 2;
            int index_x = (int)Mathf.Round(tow.Platform.transform.position.x - platform_min_x) / 2;

            if (index_z < 0)
            {
                return(true);
            }

            beerMap[index_x, index_z + 1] = destroy; // false -> new tower build there


            // Check if the last paths are still walkable
            // exit if true
            if (lastPathOne.Count >= 0 && lastPathTwo.Count >= 0)
            {
                bool lastPathOK = true;

                for (int i = 0; i < lastPathOne.Count; i++)
                {
                    if (beerMap[lastPathOne[i].X, lastPathOne[i].Y] == false)
                    {
                        lastPathOK = false;
                    }
                }

                for (int i = 0; i < lastPathTwo.Count; i++)
                {
                    if (beerMap[lastPathTwo[i].X, lastPathTwo[i].Y] == false)
                    {
                        lastPathOK = false;
                    }
                }

                if (lastPathOK)
                {
                    return(true);
                }
            }


            if (!GenerateGlobalPaths())
            {
                beerMap[index_x, index_z + 1] = !destroy;
                GenerateGlobalPaths();
                return(false);
            }

            // TODO position of this SpawnManager functions ?
            // Here becazse GenerateGlobalPaths is called at startup
            // Waves not generated at that time
            for (int i = 0; i < SpawnManager.instance.waveList.Count; i++)
            {
                SpawnManager.instance.waveGenerator.UpdateWavePath(SpawnManager.instance.waveList[i]);
            }

            UnitCreep[] creeps = ObjectPoolManager.FindObjectsOfType <UnitCreep>();
            foreach (UnitCreep creep in creeps)
            {
                // Problem with creeps not in the maze -> between start and normal platforms
                // or between normal platforms and goal
                // No new Path, if creep is already past the last tower row
                if (creep.transform.position.z > platform_min_z)
                {
                    int c_z;
                    if (creep.transform.position.z > platform_max_z)
                    {
                        c_z = 34;
                    }
                    else
                    {
                        c_z = Mathf.CeilToInt(creep.transform.position.z - platform_min_z) / 2; // Changed to CeilToInt and not round
                    }
                    int c_x = (int)Mathf.Round(creep.transform.position.x - platform_min_x) / 2;
                    parameters = new PathFindingParameters(new Point(c_x, c_z), pt_goal, beerMap, nodeMap);
                    pf         = new PathFinder(parameters);

                    PathTD pt = pf.FindPathTD(creep.transform, "CreepCustomPath");

                    creep.SetNewPath(pt);
                }
            }

            //Object[] towers = GameObject.FindObjectsOfType(typeof(UnitTower));

            //Object[] platforms = GameObject.FindObjectsOfType(typeof(PlatformTD));

            //Object[] paths = GameObject.FindObjectsOfType(typeof(PathTD));

            //SpawnManager.ChangeDefaultPath(paths[0] as PathTD);
            return(true);
        }