/// <description> /// Methods for all structures on surfaces in the level view /// </description> //TODO: once a new structure is created, check its drawing order compared to all other structures allready placed. // then rearrange all the structures and place at correct position. public void OnStructurePlacedOnSurface(Models.Structures structureModel) { Console.Write ("Views.Levels -> OnStructurePlacedOnSurface : placing structure view"); //Create Game Object GameObject gameObject = new GameObject(); gameObject.name = "Structure_" + structureModel.SurfaceModel.X + "_" + structureModel.SurfaceModel.Y; //Set Parent? //Views.Surfaces surfaceView = surfaceModelViewMap[structureModel.SurfaceModel]; gameObject.transform.SetParent (this.transform, true); Views.Structures structureView = new Views.Structures (viewLevelInstance, gameObject); /* * Structure view currently statically assigned road tile */ //load structure sprite based on its string name in the structure name sprite map structureView.GameObject.AddComponent<SpriteRenderer> ().sprite = SpriteForStructure(structureModel); structureView.GameObject.GetComponent<SpriteRenderer> ().sortingOrder = Utility.SortingOrderNumber (level.Width, level.Height, structureModel.SurfaceModel.X, structureModel.SurfaceModel.Y); //Position the structure on to its surface Vector3 point = Utility.ConvertCartesianToIsometric (new Vector3 (structureModel.SurfaceModel.X, structureModel.SurfaceModel.Y, 0), offset); structureView.SetPosition (point.x, point.y, point.z); //When this is added check for its position, and then basically redraw all the tiles where overlap may occur. structureModelViewMap.Add (structureModel, structureView); structureModel.RegisterStructureChangesCallBack (OnStructureChanges); Console.Write ("Views.Levels -> OnStructurePlacedOnSurface : structure view placed"); }
public void OnStructureChanges(Models.Structures structureModel) { //TODO: implement this when a placed structure needs to expand, gets damaged, or destroyed // Console.Write("Views.Levels -> OnStructureChanges : Currently unimplementd"); if (structureModelViewMap.ContainsKey (structureModel) == false) { Debug.Log ("Views.Levels --> OnstructureChanges : something went horribly wrong, cant find the structure model in the model-view map"); } else { Views.Structures structureView = structureModelViewMap[structureModel]; structureView.GameObject.GetComponent<SpriteRenderer> ().sprite = SpriteForStructure (structureModel); } }