Exemple #1
0
    private void ShowSystem()
    {
        if (this.rootGo != null)
        {
            GameObject.Destroy(this.rootGo);
        }

        this.builtArchitectures = new List <ArchState>();

        this.rootGo = new GameObject("Architecture");

        var gridSize = new GridSize(10f, 10, 10);

        var offset = gridSize.GetSizeVector() * -0.5f + (new Vector3(1f, 0f, 1f) * (gridSize.nodeSize / 2f));

        for (int x = 0; x < gridSize.horizNodes; x++)
        {
            for (int y = 0; y < gridSize.vertNodes; y++)
            {
                var w = 3f + (gridSize.nodeSize - 4f) * Random.value;
                var d = 3f + (gridSize.nodeSize - 4f) * Random.value;
                var h = 3f + 5f * Random.value;

                var rootArgs = new List <string> {
                    w.ToString(), h.ToString(), d.ToString()
                };
                var globalArgs = new Dictionary <string, string>();

                var archWeights = this.architectures.Select(item => item.weight).ToArray();
                var archItem    = this.architectures.PickRandomWeighted(archWeights, UnityRandomNumber.Instance);
                var asset       = Resources.Load <TextAsset>(archItem.assetName);

                var architecture = architectureBuilder.Build(asset.name, asset.text, rootArgs, globalArgs, archItem.theme);
                this.builtArchitectures.Add(new ArchState {
                    Arch = architecture
                });

                var pos = offset + new Vector3((float)x * gridSize.nodeSize, 0f, (float)y * gridSize.nodeSize);
                var go  = BuildGameObject(architecture.Mesh);
                go.transform.position = pos;
            }
        }
    }