Esempio n. 1
0
        /// <summary>
        /// Gets static door array from door information stored in model data.
        /// </summary>
        /// <param name="modelData">Model data for doors.</param>
        /// <param name="blockIndex">Block index for RMB doors.</param>
        /// <param name="recordIndex">Record index of interior.</param>
        /// <param name="buildingMatrix">Individual building matrix.</param>
        /// <returns>Array of doors in this model data.</returns>
        public static StaticDoor[] GetStaticDoors(ref ModelData modelData, int blockIndex, int recordIndex, Matrix4x4 buildingMatrix)
        {
            // Exit if no doors
            if (modelData.Doors == null)
            {
                return(null);
            }

            // Add door triggers
            StaticDoor[] staticDoors = new StaticDoor[modelData.Doors.Length];
            for (int i = 0; i < modelData.Doors.Length; i++)
            {
                // Get door and diagonal verts
                ModelDoor door = modelData.Doors[i];
                Vector3   v0   = door.Vert0;
                Vector3   v2   = door.Vert2;

                // Get door size
                const float thickness = 0.025f;
                Vector3     size      = new Vector3(v2.x - v0.x, v2.y - v0.y, v2.z - v0.z) + door.Normal * thickness;

                // Add door to array
                StaticDoor newDoor = new StaticDoor()
                {
                    buildingMatrix = buildingMatrix,
                    doorType       = door.Type,
                    blockIndex     = blockIndex,
                    recordIndex    = recordIndex,
                    doorIndex      = door.Index,
                    centre         = (v0 + v2) / 2f,
                    normal         = door.Normal,
                    size           = size,
                };
                staticDoors[i] = newDoor;
            }

            return(staticDoors);
        }
Esempio n. 2
0
 public void setDestination(ModelDoor destination)
 {
     this.destination = destination;
 }
Esempio n. 3
0
 public ModelDoor(ModelRoom room, ModelDoor destination)
 {
     this.room        = room;
     this.destination = destination;
 }
Esempio n. 4
0
    public void createDoors(ModelRoom destination)
    {
        ModelDoor door  = new ModelDoor(this);
        ModelDoor door1 = new ModelDoor(destination, door);

        door.setDestination(door1);

        if (topNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.leftX, destination.leftX) + 1;
            int endRangePosition   = Mathf.Min(this.rightX, destination.rightX) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("1Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(startPosition, topY), new Vector2(startPosition + doorSize - 1, topY));
            door1.setPosition(new Vector2(startPosition, topY + 1), new Vector2(startPosition + doorSize - 1, topY + 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }


        if (bottomNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.leftX, destination.leftX) + 1;
            int endRangePosition   = Mathf.Min(this.rightX, destination.rightX) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("2Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(startPosition, bottomY), new Vector2(startPosition + doorSize - 1, bottomY));
            door1.setPosition(new Vector2(startPosition, bottomY - 1), new Vector2(startPosition + doorSize - 1, bottomY - 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }

        if (rightNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.bottomY, destination.bottomY) + 1;
            int endRangePosition   = Mathf.Min(this.topY, destination.topY) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("3Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(rightX, startPosition), new Vector2(rightX, startPosition + doorSize - 1));
            door1.setPosition(new Vector2(rightX + 1, startPosition), new Vector2(rightX + 1, startPosition + doorSize - 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }


        if (leftNeighbours.Contains(destination))
        {
            int startRangePosition = Mathf.Max(this.bottomY, destination.bottomY) + 1;
            int endRangePosition   = Mathf.Min(this.topY, destination.topY) - doorSize;
            if (startRangePosition > endRangePosition)
            {
                Debug.Log("4Error: Drzwi sie nie zmiescioly " + index + " dop " + destination.index);
                return;
            }
            int startPosition = startRangePosition + Random.Range(0, endRangePosition - startRangePosition);
            door.setPosition(new Vector2(leftX, startPosition), new Vector2(leftX, startPosition + doorSize - 1));
            door1.setPosition(new Vector2(leftX - 1, startPosition), new Vector2(leftX - 1, startPosition + doorSize - 1));
            this.doors.Add(door);
            destination.doors.Add(door1);
            return;
        }
        Debug.Log("cos jest nie tak");
    }