public void fromSaveData(SaveData saveData) { ColonyData data = (ColonyData)saveData; Debug.Log("加载殖民地====!!"); this.container = new Container(data.containerID); if (data.buildingIndexID != null) { Debug.Log("data.buildingIndexID : " + data.buildingIndexID.Count); foreach (var kv in data.buildingIndexID) { SaveData originData = SaveManager.Instance.GetSaveData(kv.Value); if (originData == null) { continue; } CreatableSaveData buildingData = (CreatableSaveData)originData; BuildingBase building = buildingData.Create <BuildingBase>(kv.Value); SetBuildingAtIndex(kv.Key, building); if (kv.Value.Equals(data.controlCenterID)) { controllCenter = building; } } } Debug.Log("殖民地加载完毕====!!"); }
IEnumerator DropControllCenter(Transform startPos, Planet thatPlanet) { float minDis = float.MaxValue; Vector3 targetPos = startPos.position; int nearestIndex = 0; for (int i = 0; i < thatPlanet.AreaCount; i++) { Vector3 landPos = thatPlanet.GetIndexPosition(i); float dis = Vector3.Distance(landPos, startPos.position); if (dis < minDis) { minDis = dis; targetPos = landPos; nearestIndex = i; } } Debug.Log("nearestIndex" + nearestIndex); while (Vector3.Distance(startPos.position, targetPos) > 0.1f) { startPos.position = Vector3.Lerp(startPos.position, targetPos, centerFlySpeed); yield return(null); } thatPlanet.CreateColony(); BuildingBase building = Instantiate <GameObject>(ControlCenter.GetBuildingPrefab(BuildingType.CONTROL_CENTER)).GetComponent <BuildingBase>(); Build(building, nearestIndex, thatPlanet); EventManager.Instance.PostEvent(GameEvent.COLONY_SET_UP, thatPlanet); Destroy(startPos.gameObject); }
/// <summary> /// 需传入一个GameObject的Component /// </summary> public void Build(BuildingBase building, int index = int.MaxValue, Planet planetToBuild = null) { bool isCurrent = false; if (planetToBuild == null) { planetToBuild = currentPlanet; } if (index == int.MaxValue) { index = LookLandIndex; } if (index == LookLandIndex && planetToBuild.Equals(currentPlanet)) { isCurrent = true; } // 将建筑建造到殖民地 planetToBuild.colony.SetBuildingAtIndex(index, building); if (isCurrent) { Debug.Log("It Look !!!!!!!!!!!!!!!!"); currentBuilding = building; LookBuilding(index); } }
/// <summary> /// 在指定下标绑定建筑 /// </summary> public void SetBuildingAtIndex(int index, BuildingBase building) { index = momPlanet.GetValidIndex(index); // 将建筑建造到星球 // 需要计算heightRatio 妈耶, 8.5是需要调整的, 建筑中心离底边, 8.5越高 float heightRatio = (momPlanet.Radius + 8.5f) / momPlanet.Radius; momPlanet.SetGameObjectAtIndex(building.gameObject, index, heightRatio); // 位置确定后生成buildingID if (building.id == null || (building.id.className + "").Equals("")) { building.InitID(); } // 建筑绑定殖民地 building.SetMomColony(this, index); // 第一个建筑必须是控制中心 if (buildings == null || buildings.Count == 0) { Debug.Assert(building.Type == BuildingType.CONTROL_CENTER, "第一个建筑应该是控制中心!"); controllCenter = building; buildings = new Dictionary <int, BuildingBase>(); buildings.Add(index, building); return; } buildings.Add(index, building); }
public void Recycle(BuildingBase building = null) { if (building == null) { building = currentBuilding; } BuildingUI.Instance.Recycle(building); }
public void Upgrade(BuildingBase building = null) { if (building == null) { building = currentBuilding; } BuildingUI.Instance.Upgrade(building); }
/// <summary> /// 默认打开当前Building /// </summary> public void Open(BuildingBase building = null) { if (building == null) { building = currentBuilding; } BuildingUI.Instance.Open(building); }
/// <summary> /// 建筑新的建筑, TEST /// </summary> public void New() { //BuildingBase building = Instantiate<GameObject>(ShipFactory.GetBuildingPrefab(BuildingType.SHIP_FACTORY)).GetComponent<BuildingBase>(); //Build(building ,LookLandIndex,currentPlanet); BuildingBase building = Instantiate <GameObject>(ResourceCollector.GetBuildingPrefab(BuildingType.RESOURCE_COLLECTOR)).GetComponent <BuildingBase>(); Build(building, LookLandIndex, currentPlanet); }
public void ExitPlanet() { watchState = WatchState.LOOK; currentBuildingName = "NULL"; currentBuilding = null; CameraController.Instance.SetSize(currentPlanet.Radius * 3); CameraController.Instance.LookAt(currentPlanet.transform); CameraController.Instance.SetRotation(Vector3.zero); }
public override T Create <T>(ID id) { GameObject go = GameObject.Instantiate(BuildingBase.GetBuildingPrefab(BuildingType.RESOURCE_COLLECTOR)); ResourceCollector cc = go.GetComponent <ResourceCollector>(); id.Init(); cc.id = id; SaveManager.Instance.Load(cc, id); return((T)(System.Object)cc); }
public override T Create <T>(ID id) { GameObject go = GameObject.Instantiate(BuildingBase.GetBuildingPrefab(BuildingType.SHIP_FACTORY)); ShipFactory cc = go.GetComponent <ShipFactory>(); id.Init(); cc.id = id; SaveManager.Instance.Load(cc, id); return((T)(System.Object)cc); }
public override T Create <T>(ID id) { GameObject go = GameObject.Instantiate(BuildingBase.GetBuildingPrefab(BuildingType.TECH_LAB)); TechLab cc = go.GetComponent <TechLab>(); id.Init(); cc.id = id; SaveManager.Instance.Load(cc, id); return((T)(System.Object)cc); }
public override T Create <T>(ID id) { Debug.Log("控制中心从存档创建!!"); GameObject go = GameObject.Instantiate(BuildingBase.GetBuildingPrefab(BuildingType.CONTROL_CENTER)); ControlCenter cc = go.GetComponent <ControlCenter>(); id.Init(); cc.id = id; SaveManager.Instance.Load(cc, id); return((T)(System.Object)cc); }
public void ExitPlanet() { watchState = WatchState.LOOK; currentBuildingName = "NULL"; currentBuilding = null; CameraController.Instance.SetSize(currentPlanet.Radius * 3); CameraController.Instance.LookAt(currentPlanet.transform); CameraController.Instance.SetRotation(Vector3.zero); EventManager.Instance.PostEvent(GameEvent.SHIP_RESTART_INPUT, this); EventManager.Instance.PostEvent(GameEvent.EXIT_PLANET, CurrentPlanet); }
/// <summary> /// 获得指定下标位置的建筑名及建筑 /// </summary> public string GetBuildingAtIndex(int index, out BuildingBase buildingToGet) { buildingToGet = null; index = momPlanet.GetValidIndex(index); if (buildings != null) { buildings.TryGetValue(index, out buildingToGet); } if (buildingToGet == null) { Planet.LandType t; return(momPlanet.GetIndexLandType(index, out t)); } return(buildingToGet.Type.ToString()); }
public void Open(BuildingBase building) { Debug.Log("Open" + building.Type); if (building.Type == BuildingType.CONTROL_CENTER) { ShowContainer.Instance.Show(building.momColony.container, 7, 7); } else if (building.Type == BuildingType.RESOURCE_COLLECTOR) { resourceCollectUI.SetActive(true); } else if (building.Type == BuildingType.SHIP_FACTORY) { EventManager.Instance.PostEvent(GameEvent.ENTER_SHIP_FACTORY, this, building); } }
public void Recycle(BuildingBase building) { Debug.Log("Recycle" + building.Type); }
public void Upgrade(BuildingBase building) { Debug.Log("Upgrade" + building.Type); }
/// <summary> /// 建筑新的建筑, TEST /// </summary> public void New(BuildingType type) { BuildingBase building = Instantiate <GameObject>(BuildingBase.GetBuildingPrefab(type)).GetComponent <BuildingBase>(); Build(building, LookLandIndex, currentPlanet); }
public void Open(BuildingBase building) { Debug.Log("Open" + building.Type); }