Пример #1
0
        public BuildInfo _CheckBuildPoint(Vector3 pointer, int towerID)
        {
            BuildInfo buildInfo = new BuildInfo();

            if (disableBuildWhenInPlay && SpawnManager.GetActiveUnitCount() > 0)
            {
                buildInfo.status = _TileStatus.NotInBuildPhase;
                return(buildInfo);
            }

            Camera mainCam = Camera.main;

            if (mainCam != null)
            {
                Ray        ray = mainCam.ScreenPointToRay(pointer);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, maskPlatform))
                {
                    for (int i = 0; i < buildPlatforms.Count; i++)
                    {
                        if (hit.transform == buildPlatforms[i].thisT)
                        {
                            PlatformTD platform = buildPlatforms[i];

                            //calculating the build center point base on the input position
                            Vector3 pos = GetTilePos(platform, hit.point);

                            buildInfo.position = pos;
                            buildInfo.platform = platform;

                            //checking if tower can be built on the platform, for dragNdrop mode
                            if (towerID >= 0 && !platform.availableTowerIDList.Contains(towerID))
                            {
                                buildInfo.status = _TileStatus.Unavailable;
                            }

                            if (buildInfo.status == _TileStatus.Available)
                            {
                                //check if the position is blocked, by any other obstabcle other than the baseplane itself
                                Collider[] cols = Physics.OverlapSphere(pos, gridSize / 2 * 0.9f, ~maskAll);
                                if (cols.Length > 0)
                                {
                                    buildInfo.status = _TileStatus.NoPlatform;
                                }
                                else
                                {
                                    buildInfo.status = _TileStatus.Available;
                                }

                                if (buildInfo.status == _TileStatus.Available)
                                {
                                    //check if the platform is walkable, if so, check if building on the point wont block all possible path
                                    if (platform.IsWalkable())
                                    {
                                        if (platform.CheckForBlock(pos))
                                        {
                                            buildInfo.status = _TileStatus.Blocked;
                                        }
                                    }

                                    //map platform availableTowerIDList (which is the towers' prefabID) to the list elements' ID in towerList
                                    buildInfo.availableTowerIDList = new List <int>();
                                    for (int m = 0; m < platform.availableTowerIDList.Count; m++)
                                    {
                                        for (int n = 0; n < towerList.Count; n++)
                                        {
                                            if (platform.availableTowerIDList[m] == towerList[n].prefabID)
                                            {
                                                buildInfo.availableTowerIDList.Add(n);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            break;
                        }
                    }
                }
                else
                {
                    buildInfo.status = _TileStatus.NoPlatform;
                }
            }
            else
            {
                buildInfo.status = _TileStatus.NoPlatform;
            }

            //reverse block status for mine
            if (buildInfo.status == _TileStatus.Blocked)
            {
                //for drag n drop mode
                if (towerID >= 0 && GetTowerPrefab(towerID).type == _TowerType.Mine)
                {
                    buildInfo.status = _TileStatus.Available;
                }
                if (towerID < 0)
                {
                    bool gotMineInList = false;
                    for (int i = 0; i < buildInfo.availableTowerIDList.Count; i++)
                    {
                        if (towerList[buildInfo.availableTowerIDList[i]].type == _TowerType.Mine)
                        {
                            gotMineInList = true;
                        }
                        else
                        {
                            buildInfo.availableTowerIDList.RemoveAt(i);
                            i -= 1;
                        }
                    }
                    if (gotMineInList)
                    {
                        buildInfo.status = _TileStatus.Available;
                    }
                }
            }


            if (!UseDragNDrop())             //for PointNClick
            {
                if (buildInfo.status != _TileStatus.Available)
                {
                    IndicatorControl.ClearBuildTileIndicator();
                }
                else
                {
                    IndicatorControl.SetBuildTileIndicator(buildInfo);
                }
            }

            return(buildInfo);
        }