Example #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);
        }
    }
Example #2
0
        public virtual void Setup()
        {
            hasBeenSetup = true;
            //Note that this will not work if you have several players!


            SimpleBuildingManager.Instance.RegisterBuilding(this);
            world = FindObjectOfType <WorldBehaviour>();

            switch (buildingInstanceData.buildingConstructionState)
            {
            case SimpleBuildingInstance.BuildingConstructionState.PLANNED:
                buildingInstanceData.amountLeftOnConstruction = buildingType.timeToBuild;
                StartCoroutine(ConstructBuilding());
                break;

            case SimpleBuildingInstance.BuildingConstructionState.BUILDING:
                StartCoroutine(ConstructBuilding());
                break;

            case SimpleBuildingInstance.BuildingConstructionState.FINISHED:
                if (OnBuildingFinishedConstruction != null)
                {
                    OnBuildingFinishedConstruction(gameObject);
                }
                break;

            case SimpleBuildingInstance.BuildingConstructionState.RAZED:
                //TODO: Add whatever should happen
                break;

            default:
                break;
            }
            SetNewConstructionState(buildingInstanceData.buildingConstructionState);
        }
 /// <summary>
 /// Used for initialization by Unity. The Start method is called just
 /// before any of the Update methods is called the first time.
 /// </summary>
 void Start()
 {
     this.obstacle = new Obstacle(this);
     world = GameObject.Find("World").GetComponent<WorldBehaviour>();
 }
Example #4
0
 private void InvokeStartGame()
 {
     WorldBehaviour.StartGame();
 }
 private void Awake()
 {
     instance        = this;
     objectShiftPool = new List <ObjectBehaviour>();
 }
Example #6
0
 public WorldFactory(WorldBehaviour worldBehaviour, GameObject chunkPrefab)
 {
     this.worldBehaviour = worldBehaviour;
     this.chunkPrefab    = chunkPrefab;
 }