Ejemplo n.º 1
0
    public void CreatePlannedObject(Tile baseTile, int id)
    {
        if (baseTile == null)
        {
            Debug.LogError("Cannot init object on null tile");
            return;
        }

        InstalledObject obj = InstalledObjectHolder.CreateNewObject(id, baseTile);

        for (int i = 0; i < obj.Tiles.Count; i++)
        {
            if (!obj.PlacementValidation(obj.Tiles [i]))
            {
                Debug.Log("Cannot place plan here");
                return;
            }
        }

        for (int i = 0; i < obj.Tiles.Count; i++)
        {
            GameObject obj_go = new GameObject();
            obj_go.name = obj.Name;
            obj_go.transform.position = obj.Tiles[i].GetPosition();

            obj_go.transform.SetParent(this.transform, true);

            SpriteRenderer obj_go_sr = obj_go.AddComponent <SpriteRenderer> ();


            obj_go_sr.sprite           = InstalledObjectHolder.Sprites [id].Sprites [i];
            obj_go_sr.sortingLayerName = InstalledObjectHolder.Sprites [id].SortingLayer;
            obj_go_sr.sortingOrder     = InstalledObjectHolder.Sprites [id].SortingOrder;
            obj_go_sr.material         = Resources.Load <Material> ("Materials/Lit2DMat");

            obj_go_sr.color = new Color(obj_go_sr.color.r, obj_go_sr.color.g, obj_go_sr.color.b, obj_go_sr.color.a * 0.5f);
            plannedObjects.Add(obj.Tiles[i], obj_go);
            obj.Tiles[i].Planned = obj;
        }

        JobController.Instance.AddJob(Time.realtimeSinceStartup, new Job(baseTile, obj.OnInstalledComplete));
    }