public void Init( BuildingItem data, BuildingDataSo so) { buildingSo = so; item = data; ResetBuilding(); SyncPosition(); }
public static BuildingDataStruct FromBuildingDataSo(BuildingDataSo so) { return(new BuildingDataStruct { TypeId = so.typeId, EntranceTile = so.entranceTile, Size = so.size, Type = so.type }); }
public static BuildingComp PlaceBuilding( BuildingDataSo so, BuildingItem data, Transform parent = null) { var o = new GameObject(so.name); o.transform.parent = parent; var comp = o.AddComponent <BuildingComp>(); comp.Init(data, so); return(comp); }
//public GameObject buildingShadowPrefab; //TESTING /* * public GridBuildingItem gridBuildingItem { get { * return buildingComp.item; * } } */ public void StartBuildSetup(BuildingDataSo buildingSo) { //Move to action button menu menuManager.SetActivePanel(buildActionButtonMenuId); //create our objects _overlayContainer = new GameObject("Building Overlay Container"); GameObject go; float2 cellSize = GridSystem.GETCellSize(); _overlayCells = new SpriteRenderer[buildingSo.size.x * buildingSo.size.y]; for (int x = 0; x < buildingSo.size.x; x++) { for (int y = 0; y < buildingSo.size.y; y++) { int index = x + (y * buildingSo.size.x); _overlayCells[index] = Instantiate(overlayPrefab, _overlayContainer.transform) .GetComponent <SpriteRenderer>(); _overlayCells[index].transform.position = new float3( x * cellSize.x, y * cellSize.y, 0); } } placeBuilding = true; placeBuildingSo = buildingSo; //we go thourgh this process to snap to grid _placeBuildingPos = GETMiddleScreenPosition(); placeBuildingGridPos = GridSystem.GETGridPosition(_placeBuildingPos); _placeBuildingPos = GridSystem.GETWorldPosition(placeBuildingGridPos, 0, MapType.current); _placeBuildingInitialPos = _placeBuildingPos; _placeBuildingPos.z = zLevel; _overlayContainer.transform.position = _placeBuildingPos; /// get the middle closes cell pos..... placeBuildingGridPos = GridSystem.GETGridPosition(_placeBuildingPos); //BUILD ITEM BuildingItem data = new BuildingItem { pos = placeBuildingGridPos, typeId = buildingSo.typeId, rotation = 0, mapType = MapType.current, stage = BuildingStage.placingStage }; buildingComp = BuildingComp.PlaceBuilding(buildingSo, data, _overlayContainer.transform); buildingComp.transform.localPosition = Vector3.zero; //buildingSO.placementOffset; /* * buildingPrefab = new GameObject(buildingSO.buildingName); * buildingPrefab.transform.position = placeBuildingPos; // middle closest cell * buildingComp = buildingPrefab.AddComponent<BuildingComp>(); * buildingComp.buildingSO = buildingSO; * * buildingComp.Init(data,buildingSO); */ //buildingShadowPrefab = Instantiate(buildingSO.clearPrefab); //buildingShadowPrefab.transform.position = placeBuildingPos; Debug.Log($"Started building process::: {_placeBuildingPos}"); DrawBuildingOverlay(); //buildingGridSize = buildingSize; }