コード例 #1
0
        protected virtual void LockDoorway(Doorway doorway, Key key, KeyManager keyManager)
        {
            var placement = doorway.Tile.Placement;
            var prefabs   = doorway.Tile.TileSet.LockPrefabs.Where(x => { return(DoorwaySocket.IsMatchingSocket(x.SocketGroup, doorway.SocketGroup)); }).Select(x => x.LockPrefabs).ToArray();

            if (prefabs.Length == 0)
            {
                return;
            }

            var chosenEntry = prefabs[RandomStream.Next(0, prefabs.Length)].GetRandom(RandomStream, placement.IsOnMainPath, placement.NormalizedDepth, null, true);
            var prefab      = chosenEntry.Value;

            GameObject doorObj = GameObject.Instantiate(prefab);

            doorObj.transform.parent   = Root.transform;
            doorObj.transform.position = doorway.transform.position;
            doorObj.transform.rotation = doorway.transform.rotation;

            // Set this locked door as the current door prefab
            doorway.SetUsedPrefab(doorObj);
            doorway.ConnectedDoorway.SetUsedPrefab(doorObj);

            DungeonUtil.AddAndSetupDoorComponent(CurrentDungeon, doorObj, doorway);

            foreach (var keylock in doorObj.GetComponentsInChildren <Component>().OfType <IKeyLock>())
            {
                keylock.OnKeyAssigned(key, keyManager);
            }
        }
コード例 #2
0
ファイル: Dungeon.cs プロジェクト: r3c0d3/planetexplorers
        internal void MakeConnection(Doorway a, Doorway b, System.Random randomStream)
        {
            bool areDoorwaysFromDifferentDungeons = (a.Dungeon != b.Dungeon);

            a.Tile.Placement.UnusedDoorways.Remove(a);
            a.Tile.Placement.UsedDoorways.Add(a);

            b.Tile.Placement.UnusedDoorways.Remove(b);
            b.Tile.Placement.UsedDoorways.Add(b);

            a.ConnectedDoorway = b;
            b.ConnectedDoorway = a;

            if (!areDoorwaysFromDifferentDungeons)
            {
                var conn = new DoorwayConnection(a, b);
                connections.Add(conn);
            }

            // Add door prefab
            List <GameObject> doorPrefabs = (a.DoorPrefabs.Count > 0) ? a.DoorPrefabs : b.DoorPrefabs;

            if (doorPrefabs.Count > 0 && !(a.HasDoorPrefab || b.HasDoorPrefab))
            {
                GameObject doorPrefab = doorPrefabs[randomStream.Next(0, doorPrefabs.Count)];

                if (doorPrefab != null)
                {
                    GameObject door = (GameObject)GameObject.Instantiate(doorPrefab);
                    door.transform.parent     = gameObject.transform;
                    door.transform.position   = a.transform.position;
                    door.transform.rotation   = a.transform.rotation;
                    door.transform.localScale = a.transform.localScale;

                    doors.Add(door);

                    a.SetUsedPrefab(door);
                    b.SetUsedPrefab(door);

                    DungeonUtil.AddAndSetupDoorComponent(this, door, a);
                }
            }
        }
コード例 #3
0
        private void SpawnDoorPrefab(Doorway a, Doorway b, System.Random randomStream)
        {
            // This door already has a prefab instance placed, exit early
            if (a.HasDoorPrefabInstance || b.HasDoorPrefabInstance)
            {
                return;
            }

            // Add door prefab
            Doorway chosenDoor;

            bool doorwayAHasEntries = a.ConnectorPrefabWeights.HasAnyViableEntries();
            bool doorwayBHasEntries = b.ConnectorPrefabWeights.HasAnyViableEntries();

            // No doorway has a prefab to place, exit early
            if (!doorwayAHasEntries && !doorwayBHasEntries)
            {
                return;
            }

            // If both doorways have door prefabs..
            if (doorwayAHasEntries && doorwayBHasEntries)
            {
                // ..A is selected if its priority is greater than or equal to B..
                if (a.DoorPrefabPriority >= b.DoorPrefabPriority)
                {
                    chosenDoor = a;
                }
                // .. otherwise, B is chosen..
                else
                {
                    chosenDoor = b;
                }
            }
            // ..if only one doorway has a prefab, use that one
            else
            {
                chosenDoor = (doorwayAHasEntries) ? a : b;
            }


            GameObject doorPrefab = chosenDoor.ConnectorPrefabWeights.GetRandom(randomStream);

            if (doorPrefab != null)
            {
                GameObject door = Instantiate(doorPrefab, chosenDoor.transform);
                door.transform.localPosition = Vector3.zero;

                if (!chosenDoor.AvoidRotatingDoorPrefab)
                {
                    door.transform.localRotation = Quaternion.identity;
                }

                doors.Add(door);

                DungeonUtil.AddAndSetupDoorComponent(this, door, chosenDoor);

                a.SetUsedPrefab(door);
                b.SetUsedPrefab(door);
            }
        }
コード例 #4
0
        internal void MakeConnection(Doorway a, Doorway b, System.Random randomStream)
        {
            bool areDoorwaysFromDifferentDungeons = (a.Dungeon != b.Dungeon);

            a.Tile.Placement.UnusedDoorways.Remove(a);
            a.Tile.Placement.UsedDoorways.Add(a);

            b.Tile.Placement.UnusedDoorways.Remove(b);
            b.Tile.Placement.UsedDoorways.Add(b);

            a.ConnectedDoorway = b;
            b.ConnectedDoorway = a;

            if (!areDoorwaysFromDifferentDungeons)
            {
                var conn = new DoorwayConnection(a, b);
                connections.Add(conn);
            }

            // Add door prefab
            Doorway chosenDoor;

            // If both doorways have door prefabs..
            if (a.DoorPrefabs.Count > 0 && b.DoorPrefabs.Count > 0)
            {
                // ..A is selected if its priority is greater than or equal to B..
                if (a.DoorPrefabPriority >= b.DoorPrefabPriority)
                {
                    chosenDoor = a;
                }
                // .. otherwise, B is chosen..
                else
                {
                    chosenDoor = b;
                }
            }
            // ..if only one doorway has a prefab, use that one
            else
            {
                chosenDoor = (a.DoorPrefabs.Count > 0) ? a : b;
            }


            List <GameObject> doorPrefabs = chosenDoor.DoorPrefabs;

            if (doorPrefabs.Count > 0 && !(a.HasDoorPrefab || b.HasDoorPrefab))
            {
                GameObject doorPrefab = doorPrefabs[randomStream.Next(0, doorPrefabs.Count)];

                if (doorPrefab != null)
                {
                    GameObject door = (GameObject)GameObject.Instantiate(doorPrefab);
                    door.transform.parent     = gameObject.transform;
                    door.transform.position   = a.transform.position;
                    door.transform.localScale = a.transform.localScale;

                    if (!chosenDoor.AvoidRotatingDoorPrefab)
                    {
                        door.transform.rotation = a.transform.rotation;
                    }

                    doors.Add(door);

                    a.SetUsedPrefab(door);
                    b.SetUsedPrefab(door);

                    DungeonUtil.AddAndSetupDoorComponent(this, door, a);
                }
            }
        }