コード例 #1
0
    private static bool EndPlace()
    {
        bool canBuild = (BuildGridAPI.Construct(Target));

        Target.IsValidOnGrid = (canBuild);
        Target.IsMoving      = false;
        return(canBuild);
    }
コード例 #2
0
    private static bool EndPlace()
    {
        Coordinate coor     = Target.GridPosition;
        bool       canBuild = (BuildGridAPI.Build(coor, Target));

        Target.IsValidOnGrid = (canBuild);
        Target.IsMoving      = false;
        return(canBuild);
    }
コード例 #3
0
    private static bool UpdatePlace(Vector2d newPos)
    {
        Coordinate coor = BuildGridAPI.ToGridPos(newPos);

        Target.GridPosition = coor;
        bool canPlace = BuildGridAPI.CanBuild(coor, Target);

        Target.IsValidOnGrid = (canPlace);
        return(canPlace);
    }
コード例 #4
0
 public static void StartMove(IBuildable buildable)
 {
     SetTarget(buildable);
     StartPlace();
     TargetOriginalValid    = Target.IsValidOnGrid;
     TargetOriginalPosition = Target.GridPosition;
     if (TargetOriginalValid)
     {
         BuildGridAPI.Unbuild(TargetOriginalPosition, Target);
     }
     IsMovingBuilding = true;
 }
コード例 #5
0
 /// <summary>
 /// Returns whether or not the buildable could be built on where its movement ends.
 /// If not, the buildable is returned to its previous position.
 /// </summary>
 /// <returns><c>true</c>, if move was ended, <c>false</c> otherwise.</returns>
 public static PlacementResult EndMove()
 {
     IsMovingBuilding = false;
     if (EndPlace())
     {
         return(PlacementResult.Placed);
     }
     if (TargetOriginalValid)
     {
         Target.GridPosition = TargetOriginalPosition;
         BuildGridAPI.Build(TargetOriginalPosition, Target);
         Target.IsValidOnGrid = true;
         return(PlacementResult.Returned);
     }
     else
     {
         return(PlacementResult.Limbo);
     }
     //return PlacementResult.Returned;
 }
コード例 #6
0
        void DrawBuilding()
        {
            int length = BuildGridAPI.MainBuildGrid.GridLength;

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    BuildGridNode node = BuildGridAPI.MainBuildGrid.Grid[i, j];
                    if (node.Occupied)
                    {
                        Gizmos.color = Color.red;
                    }
                    else
                    {
                        Gizmos.color = Color.green;
                    }
                    Gizmos.DrawCube(BuildGridAPI.ToWorldPos(new Coordinate(i, j)).ToVector3(), nodeScale);
                }
            }
        }
コード例 #7
0
 public static void Initialize()
 {
     BuildGridAPI.Initialize();
     Reset();
 }
コード例 #8
0
 public static void Unbuild(IBuildable buildable)
 {
     BuildGridAPI.Unbuild(buildable.GridPosition, buildable);
 }
コード例 #9
0
 public static void Unbuild(IBuildable buildable)
 {
     BuildGridAPI.Unbuild(buildable);
 }
コード例 #10
0
    private static void AdjustWallSegments()
    {
        _startPillar.transform.LookAt(tempWallPillarGO.transform);
        tempWallPillarGO.transform.LookAt(_startPillar.transform.position);

        if (_pillarPrefabs.Count > 0)
        {
            GameObject adjustBasePole = _startPillar;
            for (int i = 0; i < _pillarPrefabs.Count; i++)
            {
                // no need to adjust start pillar
                if (i > 0)
                {
                    Vector3 newPos = adjustBasePole.transform.position + _startPillar.transform.TransformDirection(new Vector3(0, 0, _pillarOffset));
                    _pillarPrefabs[i].transform.position = newPos;
                    _pillarPrefabs[i].transform.rotation = _startPillar.transform.rotation;
                }

                Vector2d   posPillar  = new Vector2d(_pillarPrefabs[i].transform.position.x, _pillarPrefabs[i].transform.position.z);
                Coordinate coorPillar = BuildGridAPI.ToGridPos(posPillar);
                _pillarPrefabs[i].GetComponent <Structure>().GridPosition   = coorPillar;
                _pillarPrefabs[i].GetComponent <Structure>().ValidPlacement = BuildGridAPI.CanBuild(coorPillar, _pillarPrefabs[i].GetComponent <Structure>());

                if (_pillarPrefabs[i].GetComponent <Structure>().ValidPlacement)
                {
                    ConstructionHandler.SetTransparentMaterial(_pillarPrefabs[i], GameResourceManager.AllowedMaterial);
                }
                else
                {
                    ConstructionHandler.SetTransparentMaterial(_pillarPrefabs[i], GameResourceManager.NotAllowedMaterial);
                }

                if (_wallPrefabs.Count > 0)
                {
                    int        ndx = _pillarPrefabs.IndexOf(_pillarPrefabs[i]);
                    GameObject wallSegement;
                    if (_wallPrefabs.TryGetValue(ndx, out wallSegement))
                    {
                        GameObject nextPillar;
                        if (i + 1 < _pillarPrefabs.Count)
                        {
                            nextPillar = _pillarPrefabs[i + 1];
                        }
                        else
                        {
                            nextPillar = tempWallPillarGO;
                        }

                        int wallSegmentLength = (int)Math.Round(Vector3.Distance(_pillarPrefabs[i].transform.position, nextPillar.transform.position));
                        wallSegement.transform.localScale       = new Vector3(wallSegement.transform.localScale.x, wallSegement.transform.localScale.y, wallSegmentLength);
                        wallSegement.transform.localEulerAngles = adjustBasePole.transform.localEulerAngles;

                        Vector3 middle = 0.5f * (_pillarPrefabs[i].transform.position + nextPillar.transform.position);
                        wallSegement.transform.position = middle;

                        Vector2d   posSegment  = new Vector2d(wallSegement.transform.position.x, wallSegement.transform.position.z);
                        Coordinate coorSegment = BuildGridAPI.ToGridPos(posSegment);
                        wallSegement.GetComponent <Structure>().GridPosition   = coorSegment;
                        wallSegement.GetComponent <Structure>().ValidPlacement = BuildGridAPI.CanBuild(coorSegment, wallSegement.GetComponent <Structure>());

                        if (wallSegement.GetComponent <Structure>().ValidPlacement)
                        {
                            ConstructionHandler.SetTransparentMaterial(wallSegement, GameResourceManager.AllowedMaterial);
                        }
                        else
                        {
                            ConstructionHandler.SetTransparentMaterial(wallSegement, GameResourceManager.NotAllowedMaterial);
                        }
                    }
                }

                adjustBasePole = _pillarPrefabs[i];
            }
        }
    }