Exemple #1
0
        public bool IsOverlappingOrOverhanging(TileProxy other, AxisDirection upDirection, float maxOverlap)
        {
            Vector3 overlaps = UnityUtil.CalculatePerAxisOverlap(other.Placement.Bounds, Placement.Bounds);
            float   overlap;

            // Check for overlaps only along the ground plane, disregarding the up-axis
            // E.g. For +Y up, check for overlaps along X & Z axes
            switch (upDirection)
            {
            case AxisDirection.PosX:
            case AxisDirection.NegX:
                overlap = Mathf.Min(overlaps.y, overlaps.z);
                break;

            case AxisDirection.PosY:
            case AxisDirection.NegY:
                overlap = Mathf.Min(overlaps.x, overlaps.z);
                break;

            case AxisDirection.PosZ:
            case AxisDirection.NegZ:
                overlap = Mathf.Min(overlaps.x, overlaps.y);
                break;

            default:
                throw new NotImplementedException("AxisDirection '" + upDirection + "' is not implemented");
            }

            return(overlap > maxOverlap);
        }
Exemple #2
0
 public DoorwayProxy(TileProxy tileProxy, int index, DoorwaySocket socket, Vector3 localPosition, Quaternion localRotation)
 {
     TileProxy     = tileProxy;
     Index         = index;
     Socket        = socket;
     LocalPosition = localPosition;
     LocalRotation = localRotation;
 }
 public DoorwayPair(TileProxy previousTile, DoorwayProxy previousDoorway, TileProxy nextTemplate, DoorwayProxy nextDoorway, TileSet nextTileSet, float tileWeight, float doorwayWeight)
 {
     PreviousTile    = previousTile;
     PreviousDoorway = previousDoorway;
     NextTemplate    = nextTemplate;
     NextDoorway     = nextDoorway;
     NextTileSet     = nextTileSet;
     TileWeight      = tileWeight;
     DoorwayWeight   = doorwayWeight;
 }
Exemple #4
0
        private Vector3 CalculateOverlap(TileProxy other)
        {
            var boundsA = Placement.Bounds;
            var boundsB = other.Placement.Bounds;

            float overlapPx = boundsA.max.x - boundsB.min.x;
            float overlapNx = boundsB.max.x - boundsA.min.x;
            float overlapPy = boundsA.max.y - boundsB.min.y;
            float overlapNy = boundsB.max.y - boundsA.min.y;
            float overlapPz = boundsA.max.z - boundsB.min.z;
            float overlapNz = boundsB.max.z - boundsA.min.z;

            return(new Vector3(Mathf.Min(overlapPx, overlapNx),
                               Mathf.Min(overlapPy, overlapNy),
                               Mathf.Min(overlapPz, overlapNz)));
        }
        private bool IsValidDoorwayPairing(DoorwayProxy a, DoorwayProxy b, TileProxy nextTile, ref float weight)
        {
            // Enforce matching socket group
            if (!DoorwaySocket.CanSocketsConnect(a.Socket, b.Socket))
            {
                return(false);
            }

            // Enforce facing-direction
            Vector3?forcedDirection = null;

            // If AllowRotation has been set to false, or if the tile to be placed disallows rotation, we must force a connection from the correct direction
            bool disallowRotation = (AllowRotation.HasValue && !AllowRotation.Value) || (nextTile != null && !nextTile.PrefabTile.AllowRotation);

            // Always enforce facing direction for vertical doorways
            const float angleEpsilon = 1.0f;

            if (Vector3.Angle(a.Forward, UpVector) < angleEpsilon)
            {
                forcedDirection = -UpVector;
            }
            else if (Vector3.Angle(a.Forward, -UpVector) < angleEpsilon)
            {
                forcedDirection = UpVector;
            }
            else if (disallowRotation)
            {
                forcedDirection = -a.Forward;
            }

            if (forcedDirection.HasValue)
            {
                float       angleDiff    = Vector3.Angle(forcedDirection.Value, b.Forward);
                const float maxAngleDiff = 1.0f;

                if (angleDiff > maxAngleDiff)
                {
                    return(false);
                }
            }

            weight = CalculateDoorwayWeight(b);
            return(true);
        }
Exemple #6
0
        internal void RemoveTile(TileProxy tile)
        {
            AllTiles.Remove(tile);

            if (tile.Placement.IsOnMainPath)
            {
                MainPathTiles.Remove(tile);
            }
            else
            {
                BranchPathTiles.Remove(tile);
            }

            GameObject tileInstance;

            if (tileVisuals.TryGetValue(tile, out tileInstance))
            {
                GameObject.DestroyImmediate(tileInstance);
                tileVisuals.Remove(tile);
            }
        }
Exemple #7
0
        internal void AddTile(TileProxy tile)
        {
            AllTiles.Add(tile);

            if (tile.Placement.IsOnMainPath)
            {
                MainPathTiles.Add(tile);
            }
            else
            {
                BranchPathTiles.Add(tile);
            }

            if (visualsRoot != null)
            {
                var tileObj = GameObject.Instantiate(tile.Prefab, visualsRoot);
                tileObj.transform.localPosition = tile.Placement.Position;
                tileObj.transform.localRotation = tile.Placement.Rotation;

                tileVisuals[tile] = tileObj;
            }
        }
Exemple #8
0
        public TileProxy(TileProxy existingTile)
        {
            Prefab     = existingTile.Prefab;
            PrefabTile = existingTile.PrefabTile;
            Placement  = new TilePlacementData(existingTile.Placement);

            // Copy proxy doorways
            Doorways = new ReadOnlyCollection <DoorwayProxy>(doorways);

            foreach (var existingDoorway in existingTile.doorways)
            {
                var doorway = new DoorwayProxy(this, existingDoorway.Index, existingDoorway.Socket, existingDoorway.LocalPosition, existingDoorway.LocalRotation);
                doorways.Add(doorway);

                if (existingTile.Entrance == existingDoorway)
                {
                    Entrance = doorway;
                }
                if (existingTile.Exit == existingDoorway)
                {
                    Exit = doorway;
                }
            }
        }
Exemple #9
0
        public bool IsOverlapping(TileProxy other, float maxOverlap)
        {
            Vector3 overlap = CalculateOverlap(other);

            return(Mathf.Min(overlap.x, overlap.y, overlap.z) > maxOverlap);
        }