Exemple #1
0
    void OnEnable()
    {
        if (!(worldBehaviour == this || worldBehaviour == null))
        {
            Debug.LogError("'worldBehaviour' assigned to different WorldBehaviour, reassigning...");
        }
        worldBehaviour = this;

        TileRegistry.Initialize();

        foreach (Transform child in transform)
        {
            if (!Application.isPlaying)
            {
                DestroyImmediate(child.gameObject);
            }
            else
            {
                Destroy(child.gameObject);
            }
        }

        World = new World(2);


        if (layerObjects == null)
        {
            layerObjects    = new GameObject[World.Layers.Length];
            layerBehaviours = new LayerBehaviour[World.Layers.Length];
            for (int i = 0; i < World.Layers.Length; i++)
            {
                World.Layers[i] = new Layer(new Vector2i(100, 100));                 //Test code
                layerObjects[i] = new GameObject("Layer " + i, typeof(LayerBehaviour), typeof(MeshFilter), typeof(MeshRenderer));
                layerObjects[i].transform.SetParent(transform);
                layerBehaviours[i]                = layerObjects[i].GetComponent <LayerBehaviour>();
                layerBehaviours[i].World          = World;
                layerBehaviours[i].WorldBehaviour = this;
                layerBehaviours[i].Index          = i;
                layerObjects[i].GetComponent <MeshRenderer>().material = material;
            }
        }
        if (autoloadWorld)
        {
            World.Load(worldPath);
        }
    }