void Start() { if (_instance != null) { Debug.LogError("There should not be two map controllers"); } _instance = this; plannedObjects = new Dictionary <Tile, GameObject> (); installedObjects = new Dictionary <Tile, GameObject> (); looseObjects = new Dictionary <Tile, GameObject> (); extraGraphicalElements = new Dictionary <Tile, GameObject> (); InitMap(); TileTypeHolder.Init(); LooseObjectFactory.Init(); //This order is important!!! JobList.Init(); InstalledObjectHolder.Init(); BuildMapTileType(); ExtraGraphicalElementHolder.Init(); }
public void ChangeObjID(int objID) { if (objID >= InstalledObjectHolder.MaxObjID || objID < 0) { MouseManagerBuildMode.Instance.DefaultCursor(); } else { currentInstalledObjID = objID; MouseManagerBuildMode.Instance.SetCursor(InstalledObjectHolder.GetObjInfo(objID), InstalledObjectHolder.GetSpriteHolder(objID)); } }
public void CreateObject(Tile baseTile, int id) { if (baseTile == null) { Debug.LogError("Cannot init object on null tile"); return; } InstalledObject obj; if (baseTile.Planned == null) { obj = InstalledObjectHolder.CreateNewObject(id, baseTile); } else { obj = baseTile.Planned; } DestroyPlannedObjectGraphic(baseTile.Planned); 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"); installedObjects.Add(obj.Tiles[i], obj_go); obj.Tiles[i].Installed = obj; } if (obj.SpawnAdd != null) { foreach (GameObject g in obj.SpawnAdd.Additions) { Instantiate(g, installedObjects[baseTile].transform); } } if (obj.OnPlaced != null) { obj.OnPlaced(baseTile, null); } }
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)); }