/// <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); }
/// <summary> /// 每个单位时间(可长可短)更新星球上的所有资源 /// </summary> public void UpdateOnce() { Debug.Log("资源更新!"); foreach (var kv in elementInLands) { Element curElement = kv.Key; float[] curAmounts = kv.Value; for (int i = 0; i < momPlanet.AreaCount; i++) { Planet.LandType curLand; momPlanet.GetIndexLandType(i, out curLand); int leftIndex = momPlanet.GetValidIndex(i - 1); int rightIndex = momPlanet.GetValidIndex(i + 1); curAmounts[i] = curElement.GrowedAmount(curLand, curAmounts[i], ref curAmounts[leftIndex], ref curAmounts[rightIndex]); } } }