예제 #1
0
    private void GeneratePrefabs()
    {
        List <int> chances     = chancesList.Select(c => c.Chance).ToList();
        GameObject chosenAsset = ChooseRandomAsset(chances, WildcardTarget.PREFABS);

        if (chosenAsset != null)
        {
            Component[] remainingProperties = gameObject.GetComponents <AbstractProperty> ();
            GameObject  instance            = InstantiatePrefab(chosenAsset);

            foreach (Component go in remainingProperties)
            {
                if (go is WildcardAsset)
                {
                    continue;
                }

                Component newComponent = instance.AddComponent(go.GetType());
                if (newComponent != null)
                {
                    newComponent.GetCopyOf(go);
                }

                AbstractProperty property = go as AbstractProperty;
                if (property != null)
                {
                    property.HasBeenDeleted = true;
                }
            }
            RegisterNewProperties(instance);
            RestoreOriginalAttributes(instance, chosenAsset);
            ChunkInstantiator.RegisterForRemoval(gameObject);
        }
    }
예제 #2
0
    private void RemoveChild(Transform _child)
    {
        ChunkInstantiator.RegisterForRemoval(_child.gameObject);
        List <AbstractProperty> properties = _child.GetComponents <AbstractProperty> ().ToList();

        properties.ForEach(p => p.HasBeenDeleted = true);
    }
예제 #3
0
    private AStarGrid grid;                              //The grid used by the AStar algorithm, used to retrieve the segment positions

    public HallwayHelper(AStarGrid grid, LevelGeneratorPreset preset, GameObject hallwayObject)
    {
        this.preset            = preset;
        this.chunkInstantiator = ChunkInstantiator.Instance;
        //this.preset = preset;
        this.grid             = grid;
        this.hallwayObject    = hallwayObject;
        this.hallwayTemplates = new List <HallwayTemplateMeta> ();
        BuildMetadata();
    }
예제 #4
0
    public static void UpdateScene()
    {
        if (isActive)
        {
            GameObject chunk = GameObject.FindGameObjectWithTag("Chunk");
            chunk = chunk == null?GameObject.FindGameObjectWithTag("HallwayPrototype") : chunk;

            ChunkInstantiator generator = ChunkInstantiator.Instance;
            generator.ProcessType = ProcessType.PREVIEW;

            if (chunk != null)
            {
                generator.InstantiateChunk(chunk, false);

                HandleGizmoVisibility();
            }
        }
    }
예제 #5
0
    private void InstantiateChunk(int _seed)
    {
        int startMillis = DateTime.Now.Millisecond;

        UnityEngine.Random.InitState(_seed);

        SceneUpdater.SetActive(false);
        DestroyMultiple(SceneInstances); //Remove old generated chunk
        SetObjectActive(true);           //Has to be active or else the copy could be inactive, too
        GameObject instance       = (GameObject)GameObject.Instantiate(OriginalObject, OriginalObject.transform.position, Quaternion.identity);
        GameObject instantiatable = FindInstantiatable(instance);

        SetObjectActive(false);
        ChunkInstantiator generator = ChunkInstantiator.Instance;

        generator.ProcessType = ProcessType.INEDITOR;
        generator.InstantiateChunk(instantiatable, false);
        instance.tag   = InstanceTag;
        durationMillis = DateTime.Now.Millisecond - startMillis;
    }
예제 #6
0
    public ProceduralLevel(LevelGraph graph, LevelGeneratorPreset preset, bool setIsStatic)
    {
        //IMPORTANT, multiply with the door size. Doors require the chunk to be aligned on the grid on GENERATION time
        //Ensure, that chunks are on the grid, since the doors align to the grid regardless of the chunk position, which
        //Will result in shifted doorpositions on repositioning the chunks
        tmpChunkPos            = DoorDefinition.GlobalSize * -5000f;
        tmpChunkStep           = DoorDefinition.GlobalSize * -50f;
        isGenerating           = true;
        this.preset            = preset;
        this.hallwayTiling     = preset.HallwayTiling;
        this.distance          = preset.RoomDistance;
        this.rootnode          = graph.Rootnode;
        this.spacing           = preset.Spacing;
        this.isSeparate        = preset.IsSeparateRooms;
        this.hallwayMaterials  = preset.HallwayMaterials;
        this.helper            = new ChunkHelper(preset);
        this.debugData         = new DebugData();
        this.chunkInstantiator = ChunkInstantiator.Instance;
        this.hallwayMeta       = new List <HallwayMeta> ();
        this.positionMeta      = new List <RoomTransformation>();
        this.levelMetadata     = new LevelMetadata();
        this.setIsStatic       = setIsStatic;

        GenerateLevel(graph);
        if (!isConstraintError)
        {
            ApplyTransformation();
            CreateHallways();
        }
        else
        {
            HandleRollback();
        }
        helper.CleanUp();
        ChunkInstantiator.RemoveManualProperties();
        isGenerating = false;
    }
예제 #7
0
    //If this gameObject contained any other abstract properties, they were copied to the
    //Newly instantiated one. Register these properties for them to get interpreted by the instantiator.
    private void RegisterNewProperties(GameObject copy)
    {
        ChunkInstantiator instantiator = ChunkInstantiator.Instance;

        instantiator.PushToWorkStack(copy);
    }