Example #1
0
        private static bool IsGridPointMatch(WallRef originWall, WallRef otherWall, float offsetX = 0f, float offsetZ = 0f)
        {
            const float ProximityThreshold = 0.01f;
            var         checkPoint         = originWall.Position + new Vector3(offsetX, 0f, offsetZ);

            return(Vector3.Distance(checkPoint, otherWall.Position) < ProximityThreshold);
        }
Example #2
0
 private GameObject GetPrefab(WallRef wallRef, bool isProjection)
 {
     if (wallRef.Orientation == WallOrientations.Right || wallRef.Orientation == WallOrientations.Up)
     {
         return(isProjection ? wallProjectionPrefab : wallPrefab);
     }
     return(isProjection ? cornerWallProjectionPrefab : cornerWallPrefab);
 }
Example #3
0
        private static void SetWallPositionAndRotation(Transform wall, WallRef wallRef)
        {
            var   pos   = wallRef.Position;
            float angle = 0f;

            switch (wallRef.Orientation)
            {
            case WallOrientations.Up:
                angle = -90f;
                break;

            case WallOrientations.Right:
                break;

            case WallOrientations.UpLeft:
                angle = -90f;
                break;

            case WallOrientations.UpRight:
                break;

            case WallOrientations.DownLeft:
                pos  += Vector3.forward;
                angle = 180f;
                break;

            case WallOrientations.DownRight:
                pos  += Vector3.forward;
                angle = 90f;
                break;

            default:
                Debug.LogError("invalid orientation: " + wallRef.Orientation);
                break;
            }

            wall.position    = pos;
            wall.eulerAngles = new Vector3(0f, angle, 0f);
        }
Example #4
0
        private WallRef ResolveProjectedWallType(WallRef wallRef, List <WallRef> existingWalls)
        {
            var        orientation = wallRef.Orientation;
            var        position    = wallRef.Position;
            GameObject matchedWall = null;

            if (wallRef.Orientation == WallOrientations.Up)
            {
                var hasMatch = false;
                foreach (var w in existingWalls)
                {
                    if (wallsToReplace.Contains(w.Wall))
                    {
                        continue;
                    }
                    if (w.Orientation != WallOrientations.Right)
                    {
                        continue;
                    }

                    if (IsGridPointMatch(wallRef, w))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);          // TODO multiple matches are ignored for now
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        orientation = WallOrientations.UpRight;
                    }
                    else if (IsGridPointMatch(wallRef, w, -1))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        orientation = WallOrientations.UpLeft;
                    }
                    else if (IsGridPointMatch(wallRef, w, 0, 1))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        orientation = WallOrientations.DownRight;
                    }
                    else if (IsGridPointMatch(wallRef, w, -1, 1))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        orientation = WallOrientations.DownLeft;
                    }
                }
            }
            else if (wallRef.Orientation == WallOrientations.Right)
            {
                var hasMatch = false;
                foreach (var w in existingWalls)
                {
                    if (wallsToReplace.Contains(w.Wall))
                    {
                        continue;
                    }
                    if (w.Orientation != WallOrientations.Up)
                    {
                        continue;
                    }

                    if (IsGridPointMatch(wallRef, w))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);          // TODO multiple matches are ignored for now
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        orientation = WallOrientations.UpRight;
                    }
                    else if (IsGridPointMatch(wallRef, w, 1))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        position   += Vector3.right;
                        orientation = WallOrientations.UpLeft;
                    }
                    else if (IsGridPointMatch(wallRef, w, 0, -1))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        position   += Vector3.back;
                        orientation = WallOrientations.DownRight;
                    }
                    else if (IsGridPointMatch(wallRef, w, 1, -1))
                    {
                        if (hasMatch)
                        {
                            return(wallRef);
                        }
                        hasMatch    = true;
                        matchedWall = w.Wall;
                        position   += new Vector3(1, 0, -1);
                        orientation = WallOrientations.DownLeft;
                    }
                }
            }

            // TODO check projected corner walls

            if (matchedWall != null)
            {
                wallsToReplace.Add(matchedWall);
                matchedWall.SetActive(false);
            }

            wallRef.Position    = position;
            wallRef.Orientation = orientation;
            return(wallRef);
        }
Example #5
0
        private static WallRef GetWallAtPosition(WallRef wallRef, List <WallRef> existingWalls)
        {
            foreach (var wall in existingWalls)
            {
                switch (wall.Orientation)
                {
                case WallOrientations.Up:
                    if (!IsGridPointMatch(wallRef, wall))
                    {
                        continue;
                    }
                    if (wallRef.Orientation == WallOrientations.Up)
                    {
                        return(wall);
                    }
                    break;

                case WallOrientations.Right:
                    if (!IsGridPointMatch(wallRef, wall))
                    {
                        continue;
                    }
                    if (wallRef.Orientation == WallOrientations.Right)
                    {
                        return(wall);
                    }
                    break;

                case WallOrientations.UpLeft:
                    if (IsGridPointMatch(wallRef, wall) && wallRef.Orientation == WallOrientations.Up)
                    {
                        return(wall);
                    }
                    if (IsGridPointMatch(wallRef, wall, 1) && wallRef.Orientation == WallOrientations.Right)
                    {
                        return(wall);
                    }
                    break;

                case WallOrientations.UpRight:
                    if (IsGridPointMatch(wallRef, wall))
                    {
                        return(wall);
                    }
                    break;

                case WallOrientations.DownLeft:
                    if (IsGridPointMatch(wallRef, wall, 0, 1) && wallRef.Orientation == WallOrientations.Up)
                    {
                        return(wall);
                    }
                    if (IsGridPointMatch(wallRef, wall, 1) && wallRef.Orientation == WallOrientations.Right)
                    {
                        return(wall);
                    }
                    break;

                case WallOrientations.DownRight:
                    if (IsGridPointMatch(wallRef, wall, 0, 1) && wallRef.Orientation == WallOrientations.Up)
                    {
                        return(wall);
                    }
                    if (IsGridPointMatch(wallRef, wall, -1) && wallRef.Orientation == WallOrientations.Right)
                    {
                        return(wall);
                    }
                    break;

                default:
                    Debug.LogError("Invalid orientation: " + wall.Orientation);
                    break;
                }
            }
            return(new WallRef {
                Wall = null
            });
        }