Ejemplo n.º 1
0
        public static void PreBuildTower(UnitTower tower)
        {
            BuildPlatform platform = null;
            LayerMask     mask     = 1 << TDTK.GetLayerPlatform();

            Collider[] cols = Physics.OverlapSphere(tower.GetPos(), GetGridSize(), mask);
            if (cols.Length > 0)
            {
                platform = cols[0].gameObject.GetComponent <BuildPlatform>();
            }

            if (platform != null)
            {
                NodeTD node = platform.GetNearestNode(tower.GetPos());
                if (Vector3.Distance(node.pos, tower.GetPos()) < GetGridSize())
                {
                    AddTower(tower, platform, node.ID);
                    tower.transform.position = node.pos;
                    return;
                }
            }

            //~ GameObject obj=new GameObject("platform");
            //~ SphereCollider collider=obj.AddComponent<SphereCollider>();
            //~ collider.radius=GetGridSize()*.5f;
            //~ obj.transform.parent=tower.transform;
            //~ obj.transform.localPosition=Vector3.zero;
            //~ obj.layer=TDTK.GetLayerPlatform();

            //~ platform=obj.AddComponent<BuildPlatform>();
            //~ platform.SingleNodePlatform();

            AddTower(tower, CreatePlatformForTower(tower, GetGridSize()), 0);
        }
Ejemplo n.º 2
0
        public void UpdateScreenPosition()
        {
            Vector3 screenPos = Camera.main.WorldToScreenPoint(tower.GetPos());          //+new Vector3(0, 0, 0));

            screenPos.z         = 0;
            rectT.localPosition = (screenPos + new Vector3(0, -20, 0)) * UI.GetScaleFactor();
        }
Ejemplo n.º 3
0
        public static void NewTower(UnitTower tower)
        {
            if (tower.IsSupport())
            {
                List <UnitTower> allTowerList = TowerManager.GetActiveTowerList();
                for (int i = 0; i < allTowerList.Count; i++)
                {
                    if (allTowerList[i].IsSupport())
                    {
                        continue;
                    }
                    if (allTowerList[i] == tower)
                    {
                        continue;
                    }

                    float dist = Vector3.Distance(allTowerList[i].GetPos(), tower.GetPos());
                    if (dist < tower.GetAttackRange())
                    {
                        tower.SupportBuffTower(allTowerList[i]);
                    }
                }
            }
            else
            {
                List <UnitTower> supportTowerList = TowerManager.GetSupportTowerList();
                for (int i = 0; i < supportTowerList.Count; i++)
                {
                    float dist = Vector3.Distance(supportTowerList[i].GetPos(), tower.GetPos());
                    if (dist < supportTowerList[i].GetAttackRange())
                    {
                        supportTowerList[i].SupportBuffTower(tower);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //recalculate path on one of the waypoint platform, called when tower is built or sold
        public void UpdatePlatformPath(BuildPlatform platform, UnitTower tower = null)
        {
            bool requireUpdate = false;

            for (int i = 0; i < wpSecList.Count; i++)
            {
                if (wpSecList[i].platform == platform)
                {
                    if (tower != null)                          //if the tower isn't built in the path, there's no need to update the path
                    {
                        bool inPath = false;
                        int  count  = wpSecList[i].branch ? nextPath.Count : 1;

                        for (int j = 0; j < count; j++)
                        {
                            List <Vector3> subPath = wpSecList[i].GetWaypointList(j);
                            for (int n = 0; n < subPath.Count; n++)
                            {
                                if (tower.GetPos() == subPath[n])
                                {
                                    inPath = true; break;
                                }

                                if (AStar.EnablePathSmoothing())
                                {
                                    float gridSize = TowerManager.GetGridSize() * 1.1f;
                                    if (n < subPath.Count - 1)                                // && (subPath[n].y!=subPath[n+1].y && subPath[n].y!=subPath[n+1].y)){
                                    {
                                        if (Vector3.Distance(subPath[n], tower.GetPos()) < gridSize && Vector3.Distance(subPath[n + 1], tower.GetPos()) < gridSize)
                                        {
                                            inPath = true; break;
                                        }
                                    }
                                }
                            }
                        }

                        if (!inPath)
                        {
                            continue;
                        }
                    }

                    wpSecList[i].UpdatePlatformPath();

                    bool pathIsBlocked = wpSecList[i].wpList.Count == 0;
                    if (i == wpSecList.Count - 1 && HasBranchingPlatformEnd())
                    {
                        for (int n = 0; n < nextPath.Count; n++)
                        {
                            if (wpSecList[i].wpListList[n].Count >= 0)
                            {
                                pathIsBlocked = false; break;
                            }
                        }
                    }

                    if (pathIsBlocked)                          //if(wpSecList[i].wpList.Count==0){
                    //add to a list and then call reverse later,
                    //in case calling Reverse() on the unit cause it to reverse to prev path intantly and remove itself on the path
                    {
                        List <UnitCreep> reverseList = new List <UnitCreep>();
                        for (int n = 0; n < creepOnPath.Count; n++)
                        {
                            if (creepOnPath[n].wpIdx > i)
                            {
                                continue;
                            }
                            List <Vector3> newPath = wpSecList[i].GetPathForUnit(creepOnPath[n]);
                            if (newPath.Count == 0)
                            {
                                reverseList.Add(creepOnPath[n]);
                            }
                        }
                        for (int n = 0; n < reverseList.Count; n++)
                        {
                            reverseList[n].Reverse();
                        }
                    }
                    else
                    {
                        for (int n = 0; n < creepOnPath.Count; n++)
                        {
                            if (creepOnPath[n].wpIdx != i)
                            {
                                continue;
                            }
                            creepOnPath[n].ForceAltPath();
                        }
                    }

                    requireUpdate = true;
                }
            }

            if (requireUpdate)
            {
                UpdateDistance();
            }
        }