Exemplo n.º 1
0
    protected Candidate ConnectNewCandidateToConnPoint(ConnPointCandidate lastConnPointCandidate)
    {
        Candidate lastCandidate = lastConnPointCandidate.Owner;

        //LOOK IF ELEMENT IN THE SPAWN ZONE
        ZoneItem zoneItem = GetCandidateSpawnZoneItem(lastConnPointCandidate, lastCandidate.Step);

        //PUT IN SEPARATE FUNCTION
        DungeonSet spawnZoneSet = null;

        if (zoneItem != null)
        {
            spawnZoneSet = zoneItem.spawnSet;

            if (spawnZoneSet == null && zoneItem.randomizeSpawnSet)
            {
                int randomSetIndex = Random.Range(1, factoryOwner.Sets.Count);
                spawnZoneSet      = factoryOwner.Sets[randomSetIndex];
                zoneItem.spawnSet = spawnZoneSet;
            }
        }

        DungeonSet lastCandidateSet = lastCandidate.Set;

        DungeonSet candidatesSet = SetPotentialCandidates(spawnZoneSet, lastCandidateSet);

        //PUT IN SEPARATE FUNCTION
        if (zoneItem != null && zoneItem.emptySpace)
        {
            potentialCandidates = lastCandidateSet.GetAllClosingElementsShuffled(random);
        }
        //

        Candidate newCandidate = null;

        int timesLooped         = 0;
        int maximumLoopsAllowed = potentialCandidates.Length << factoryOwner.loopCheckCount;

        do
        {
            if (timesLooped++ > maximumLoopsAllowed)
            {
                throw new System.Exception("CandidatesManager::Candidate generation takes too long - Possible infinite loop.");
            }

            newCandidate = CreateNewCandidate(lastConnPointCandidate, candidatesSet);
        } while (potentialCandidates.Length > 0 && newCandidate == null);

        if (newCandidate != null)
        {
            AcceptNewCandidate(newCandidate, lastCandidate);
        }

        return(newCandidate);
    }
Exemplo n.º 2
0
    public Candidate(GameObject gameObject, DungeonSet set)
    {
        this.gameObject = gameObject;
        this.set        = set;

        element = gameObject.GetComponent <Element>();
        volume  = gameObject.GetComponent <Volume>();

        halfStep = new Vector3(volume.VoxelScale * 0.5f, 0f, 0f);
        step     = new Vector3(volume.VoxelScale, 0f, 0f);
        id       = element.ID;

        CloneConnPoints();
    }
Exemplo n.º 3
0
    protected DungeonSet SetPotentialCandidates(DungeonSet candidatesSet, DungeonSet lastCandidateSet)
    {
        if (candidatesSet == null)
        {
            if (zonesGenerator.clamp)
            {
                candidatesSet       = lastCandidateSet;
                potentialCandidates = candidatesSet.GetAllClosingElementsShuffled(random);

                return(lastCandidateSet);
            }

            candidatesSet = factoryOwner.Sets[0];
        }

        bool onlyTwoWayElemsAllowed = OnlyTwoWayElemsAllowed();

        potentialCandidates = onlyTwoWayElemsAllowed ? candidatesSet.GetAllTwoWayOpenElementsShuffled(random) : candidatesSet.GetAllOpenElementsShuffled(random);

        return(candidatesSet);
    }
Exemplo n.º 4
0
    protected Candidate GetNewCandidate(Element[] possibleElements, DungeonSet ownerSet)
    {
        bool onlyTwoWayElemsAllowed = OnlyTwoWayElemsAllowed();

        GameObject randomElement;

        if (onlyTwoWayElemsAllowed)
        {
            int randomRoomIndex = random.range(0, possibleElements.Length - 1);
            randomElement = possibleElements[randomRoomIndex].gameObject;
        }
        else
        {
            randomElement = GetElemThatMightBeOneWay(possibleElements);
        }


        Candidate newCandidate = new Candidate(randomElement, ownerSet);

        newCandidate.SetWorldPosAndRotation(factoryOwner.ParentTransform.position, factoryOwner.ParentTransform.rotation);

        return(newCandidate);
    }
Exemplo n.º 5
0
    protected Candidate CreateNewCandidate(ConnPointCandidate lastConnPointCandidate, DungeonSet candidatesSet)
    {
        VoxelStep newCandidateStepVoxel = new VoxelStep();

        // GENERATE ROOM WITH ONE CONNECTION POINT (only after all target rooms have been exhausted)
        if (acceptedCandidates.Count >= factoryOwner.TargetElementsCount)
        {
            potentialCandidates = lastConnPointCandidate.OwnerSet.GetAllClosingElementsShuffled(random);
        }

        // GET RANDOM NEW CANDIDATE
        Candidate newCandidate = GetNewCandidate(potentialCandidates, candidatesSet);

        potentialCandidates = potentialCandidates.RemoveFromArray(newCandidate.Element);

        // CHECK IF NEW ELEMENT ALLOWED NEIGHBOUR TO LAST ELEMENT
        bool notAllowedNeighbours = CheckIfCandidatesCanBeNeighbours(GetFirstOpenCandidate(), newCandidate);

        if (notAllowedNeighbours)
        {
            potentialCandidates = candidatesSet.GetAllHallwayElementsShuffled(random);
            return(null);
        }

        // COONECT THE CANDIDATES
        ConnPointCandidate newConnPointCandidate = AlignNewCandidateWithConnPoint(lastConnPointCandidate, newCandidate);

        CandidatesConnection candidatesConnection = CreateCandidatesConnection(lastConnPointCandidate, newConnPointCandidate);

        candidatesConnection.LastCandidateWorldPos = GetFirstOpenCandidate().WorldPos;

        newCandidate.CandidatesConnection = candidatesConnection;

        //STEP VOXELS
        newCandidateStepVoxel.oldStepVoxelsPos = GetOldStepVoxels(lastConnPointCandidate);
        newCandidateStepVoxel.newStepVoxelsPos = GetNewStepVoxels(newCandidate);
        //

        //candidatesConnection.NewCandidateStepVoxel = newCandidateStepVoxel;

        //CHECK OVERLAP
        bool overlap = CheckIfNewElementOverlaps(newCandidateStepVoxel, newCandidate);

        if (overlap)
        {
            if (potentialCandidates.Length == 0)
            {
                potentialCandidates = candidatesSet.GetAllClosingElementsShuffled(random);
            }

            return(null);
        }

        return(newCandidate);
    }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.PropertyField(setName);
        EditorGUILayout.PropertyField(set);
        EditorGUILayout.Separator();

#pragma warning disable CS0618 // Type or member is obsolete
        EditorGUIUtility.LookLikeInspector();
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(ignoreList, true);
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
        EditorGUIUtility.LookLikeControls();
#pragma warning restore CS0618 // Type or member is obsolete


        string btntxt = "Update DungeonSet Asset";
        if (!set.objectReferenceValue)
        {
            btntxt = "Create DungeonSet Asset";
        }

        if (GUILayout.Button(btntxt))
        {
            string sn = SetName;

            Debug.Log("Starting to create asset: '" + sn + ".asset'");

            //if (!AssetDatabase.IsValidFolder("Assets/Dungeons/" + sn))
            //    AssetDatabase.CreateFolder("Assets/Dungeons", sn);
            //if (!AssetDatabase.IsValidFolder("Assets/Dungeons/" + sn + "/Templates"))
            //    AssetDatabase.CreateFolder("Assets/Dungeons/" + sn, "Templates");
            CreateFolderTo("Assets/Dungeons/" + sn + "/Templates");

            DungeonSet dungeonSet = AssetDatabase.LoadAssetAtPath <DungeonSet>("Assets/Dungeons/" + sn + "/" + sn + ".asset");
            if (!dungeonSet)
            {
                dungeonSet      = ScriptableObject.CreateInstance <DungeonSet>();
                dungeonSet.name = sn;
                AssetDatabase.CreateAsset(dungeonSet, "Assets/Dungeons/" + sn + "/" + sn + ".asset");
                Debug.Log("Creating dungeonset asset...");
            }

            GameObject[] ignores   = SetBuilder.IgnoreList;
            List <Room>  rooms     = new List <Room>(SetBuilder.transform.childCount);
            List <Door>  doors     = new List <Door>();
            List <Room>  spawns    = new List <Room>();
            List <Room>  bossRooms = new List <Room>();

            foreach (Transform transform in SetBuilder.transform)
            {
                if (ignores.Contains(transform.gameObject) ||
                    (!transform.GetComponent <Room>() && !transform.GetComponent <Door>()))
                {
                    continue;
                }

                GameObject prefab = PrefabUtility.CreatePrefab(
                    "Assets/Dungeons/" + sn + "/Templates/" + transform.name + ".prefab",
                    transform.gameObject,
                    PrefabUtility.GetPrefabType(transform.gameObject) == PrefabType.PrefabInstance ? ReplacePrefabOptions.ConnectToPrefab : ReplacePrefabOptions.Default);
                FinaliseRoomPrefab(prefab);

                try
                {
                    Room room = prefab.GetComponent <Room>();
                    if (room)
                    {
                        CheckRoom(room);
                        room.GetComponent <Volume>().RecalculateBounds();
                        if (room is SpawnRoom)
                        {
                            spawns.Add(room);
                        }
                        else if (room is BossRoom)
                        {
                            bossRooms.Add(room);
                        }
                        else
                        {
                            rooms.Add(room);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }

                Door door = prefab.GetComponent <Door>();
                if (door)
                {
                    doors.Add(door);
                }
            }


            dungeonSet.roomTemplates = rooms;
            dungeonSet.doors         = doors;
            dungeonSet.bosses        = bossRooms;
            dungeonSet.spawns        = spawns;

            EditorUtility.SetDirty(dungeonSet);

            AssetDatabase.SaveAssets();

            set.objectReferenceValue = dungeonSet;

            serializedObject.ApplyModifiedProperties();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = dungeonSet;

            Debug.Log("Completed creating asset: '" + sn + ".asset'");
        }
    }
Exemplo n.º 7
0
 public static void AddPathSprite(PathType type, DungeonSet set)
 {
     dungeonSets.Add(type, set);
 }