void Start() { // Ensure a type is defined if (m_ModuleType == EType.INVALID) { Debug.LogError(string.Format("This module has not been given a module type. GameObjectName({0})", gameObject.name)); } // Ensure a category is defined if (m_ModuleCategory == ECategory.INVALID) { Debug.LogError(string.Format("This module has not been given a module category. GameObjectName({0})", gameObject.name)); } // Ensure a size is defined if (m_ModuleSize == ESize.INVALID) { Debug.LogError(string.Format("This module has not been given a module size. GameObjectName({0})", gameObject.name)); } // Register self with parent facility CFacilityInterface fi = CUtility.FindInParents <CFacilityInterface>(gameObject); if (fi != null) { fi.RegisterModule(this); m_cParentFacility = fi.gameObject; } else { Debug.LogError("Could not find facility to register to"); } }
public GameObject CreateFacility(CFacilityInterface.EType _eType, uint _uiFacilityId = uint.MaxValue, uint _uiExpansionPortId = uint.MaxValue, uint _uiAttachToId = uint.MaxValue) { CExpansionPortInterface cExpansionPort = null; if (_uiExpansionPortId != uint.MaxValue && _uiAttachToId != uint.MaxValue) { cExpansionPort = m_mFacilities[_uiFacilityId].GetComponent <CFacilityExpansion>().GetExpansionPort(_uiExpansionPortId).GetComponent <CExpansionPortInterface>(); if (cExpansionPort.HasAttachedFacility == true) { Debug.LogWarning("Failed to create new room. Port is already in use."); return(null); } } // Generate facility identifier uint uiFacilityId = m_uiFacilityIdCount; // Retrieve the facility prefab CGameRegistrator.ENetworkPrefab eRegisteredPrefab = CFacilityInterface.GetPrefabType(_eType); // Create facility GameObject cNewFacilityObject = CNetwork.Factory.CreateObject(eRegisteredPrefab); // Set facility properties CFacilityInterface cFacilityInterface = cNewFacilityObject.GetComponent <CFacilityInterface>(); cFacilityInterface.FacilityId = uiFacilityId; cFacilityInterface.FacilityType = _eType; m_uiFacilityIdCount++; // Set facility parent cNewFacilityObject.GetComponent <CNetworkView>().SetParent(GetComponent <CNetworkView>().ViewId); // Attach facility expansion port to parent expansion port if (cExpansionPort != null) { cExpansionPort.Attach(_uiAttachToId, cNewFacilityObject); } // Initialise the facility expansion ports cNewFacilityObject.GetComponent <CFacilityExpansion>().InitialiseExpansionPorts(); // Sync position & rotation cNewFacilityObject.GetComponent <CNetworkView>().SyncTransformPosition(); cNewFacilityObject.GetComponent <CNetworkView>().SyncTransformRotation(); // Server adds the facility instantaniously AddNewlyCreatedFacility(cNewFacilityObject, uiFacilityId, _eType); // Notify facility creation observers if (EventOnFaciltiyCreate != null) { EventOnFaciltiyCreate(cNewFacilityObject); } return(cNewFacilityObject); }
public GameObject CreateFacility(CFacilityInterface.EType _eType, uint _uiFacilityId = uint.MaxValue, uint _uiExpansionPortId = uint.MaxValue, uint _uiAttachToId = uint.MaxValue) { CExpansionPortInterface cExpansionPort = null; if (_uiExpansionPortId != uint.MaxValue && _uiAttachToId != uint.MaxValue) { cExpansionPort = m_mFacilities[_uiFacilityId].GetComponent<CFacilityExpansion>().GetExpansionPort(_uiExpansionPortId).GetComponent<CExpansionPortInterface>(); if(cExpansionPort.HasAttachedFacility == true) { Debug.LogWarning("Failed to create new room. Port is already in use."); return(null); } } // Generate facility identifier uint uiFacilityId = m_uiFacilityIdCount; // Retrieve the facility prefab CGameRegistrator.ENetworkPrefab eRegisteredPrefab = CFacilityInterface.GetPrefabType(_eType); // Create facility GameObject cNewFacilityObject = CNetwork.Factory.CreateObject(eRegisteredPrefab); // Set facility properties CFacilityInterface cFacilityInterface = cNewFacilityObject.GetComponent<CFacilityInterface>(); cFacilityInterface.FacilityId = uiFacilityId; cFacilityInterface.FacilityType = _eType; m_uiFacilityIdCount++; // Set facility parent cNewFacilityObject.GetComponent<CNetworkView>().SetParent(GetComponent<CNetworkView>().ViewId); // Attach facility expansion port to parent expansion port if (cExpansionPort != null) { cExpansionPort.Attach(_uiAttachToId, cNewFacilityObject); } // Initialise the facility expansion ports cNewFacilityObject.GetComponent<CFacilityExpansion>().InitialiseExpansionPorts(); // Sync position & rotation cNewFacilityObject.GetComponent<CNetworkView>().SyncTransformPosition(); cNewFacilityObject.GetComponent<CNetworkView>().SyncTransformRotation(); // Server adds the facility instantaniously AddNewlyCreatedFacility(cNewFacilityObject, uiFacilityId, _eType); // Notify facility creation observers if (EventOnFaciltiyCreate != null) { EventOnFaciltiyCreate(cNewFacilityObject); } return (cNewFacilityObject); }
void RegisterFacilities() { CFacilityInterface.RegisterPrefab(CFacilityInterface.EType.Bridge, CGameRegistrator.ENetworkPrefab.FacilityBridge); CFacilityInterface.RegisterPrefab(CFacilityInterface.EType.HallwayStraight, CGameRegistrator.ENetworkPrefab.HallwayStraight); CFacilityInterface.RegisterPrefab(CFacilityInterface.EType.HallwayCorner, CGameRegistrator.ENetworkPrefab.HallwayCorner); CFacilityInterface.RegisterPrefab(CFacilityInterface.EType.HallwayTSection, CGameRegistrator.ENetworkPrefab.HallwayTSection); CFacilityInterface.RegisterPrefab(CFacilityInterface.EType.HallwayXSection, CGameRegistrator.ENetworkPrefab.HallwayXSection); CFacilityInterface.RegistMiniaturePrefab(CFacilityInterface.EType.Bridge, CGameRegistrator.ENetworkPrefab.MiniFacilityBridge); CFacilityInterface.RegistMiniaturePrefab(CFacilityInterface.EType.HallwayStraight, CGameRegistrator.ENetworkPrefab.MiniHallwayStraight); CFacilityInterface.RegistMiniaturePrefab(CFacilityInterface.EType.HallwayCorner, CGameRegistrator.ENetworkPrefab.MiniHallwayCorner); CFacilityInterface.RegistMiniaturePrefab(CFacilityInterface.EType.HallwayTSection, CGameRegistrator.ENetworkPrefab.MiniHallwayTSection); CFacilityInterface.RegistMiniaturePrefab(CFacilityInterface.EType.HallwayXSection, CGameRegistrator.ENetworkPrefab.MiniHallwayXSection); }
public void UpdateChildFacilityPresentation() { // Create a temp miniature facility string faciltyPrefabFile = CNetwork.Factory.GetRegisteredPrefabFile(CFacilityInterface.GetMiniaturePrefabType(CurrentFacilityType)); GameObject tempFacilityObject = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/" + faciltyPrefabFile)); // Destroy the old facility if (m_FacilityObject.transform.childCount != 0) { Destroy(m_FacilityObject.transform.GetChild(0).gameObject); } // Add it to the child object tempFacilityObject.transform.parent = m_FacilityObject.transform; // Reset some values tempFacilityObject.layer = LayerMask.NameToLayer("UI 3D"); tempFacilityObject.transform.localPosition = Vector3.zero; tempFacilityObject.transform.localRotation = Quaternion.identity; }
public void OnGUI() { return; string shipLifeSupportOutput = "ShipLifeSupportInfo\n"; shipLifeSupportOutput += string.Format("\tQuality: [{0}%]\n", Math.Round(ShipAtmosphericQuality * 100.0f, 1)); string generatorOutput = "GeneratorInfo\n"; foreach (GameObject generator in m_AtmosphereGenerators) { CFacilityInterface fi = CUtility.FindInParents <CFacilityInterface>(generator); CAtmosphereGeneratorBehaviour agb = generator.GetComponent <CAtmosphereGeneratorBehaviour>(); generatorOutput += string.Format("\t[{0}] Within Facility [{1}] Type [{2}] \n\t\tIsGenerationActive: [{3}] GenRate: [{4}]\n", generator.name, fi.FacilityId, fi.FacilityType, agb.IsAtmosphereGenerationActive, Math.Round(agb.AtmosphereGenerationRate, 2)); } string conditionerOutput = "ConditionerInfo\n"; foreach (GameObject conditioner in m_AtmosphereConditioners) { CFacilityInterface fi = CUtility.FindInParents <CFacilityInterface>(conditioner); CAtmosphereConditioningBehaviour acb = conditioner.GetComponent <CAtmosphereConditioningBehaviour>(); conditionerOutput += string.Format("\t[{0}] Within Facility [{1}] Type [{2}] \n\t\tIsConditioningActive: [{3}] SupportCap: [{4}]\n", conditioner.name, fi.FacilityId, fi.FacilityType, acb.IsAtmosphereConditioningActive, Math.Round(acb.AtmosphereCapacitySupport, 2)); } string facilitiesOutput = "FacilityAtmosphereInfo\n"; foreach (GameObject facility in gameObject.GetComponent <CShipFacilities>().Facilities) { CFacilityInterface fi = facility.GetComponent <CFacilityInterface>(); CFacilityAtmosphere fa = facility.GetComponent <CFacilityAtmosphere>(); facilitiesOutput += string.Format("\tFacility [{0}] Type [{1}] \n\t\tTotalVol: [{2}] Quantity: [{3}] RefilRate: [{4}] ConsRate: [{5}]\n", fi.FacilityId, fi.FacilityType, Math.Round(fa.AtmosphereVolume, 2), Math.Round(fa.AtmosphereQuantity, 2), Math.Round(fa.AtmosphereRefillRate, 2), Math.Round(fa.AtmosphereConsumeRate, 2)); } float boxWidth = 500; float boxHeight = 600; GUI.Label(new Rect(Screen.width / 2, 0.0f, boxWidth, boxHeight), "Atmosphere Status'\n" + shipLifeSupportOutput + generatorOutput + conditionerOutput + facilitiesOutput); }
public void ChangeFacilityType(CFacilityInterface.EType _FacilityType) { m_CurrentFacilityType.Set(_FacilityType); }
void Start() { // Attach the collider for the facility to the galaxy ship CGalaxyShipCollider galaxyShipCollider = CGameShips.GalaxyShip.GetComponent <CGalaxyShipCollider>(); galaxyShipCollider.AttachNewCollider("Prefabs/" + CNetwork.Factory.GetRegisteredPrefabFile(CFacilityInterface.GetPrefabType(FacilityType)) + "Ext", transform.localPosition, transform.localRotation); // Add self to the ship facilities if (!CNetwork.IsServer) { CGameShips.Ship.GetComponent <CShipFacilities>().AddNewlyCreatedFacility(gameObject, FacilityId, FacilityType); } }
///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// //float fModulePowerConsumption; //[AServerOnly] //void UpdateModulePowerConsumption() //{ // fModulePowerConsumption = (float)CModuleInterface.GetAllModules().Sum((m) => // { // CModulePower mp = m.GetComponent<CModulePower>(); // return (mp.IsPowerActive ? mp.PowerConsumption * Time.deltaTime : 0.0); // }); // float TOTAL = combinedConsumption + fModulePowerConsumption; // Debug.Log("TOTAL: " + TOTAL.ToString()); //} ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// public void OnGUI() { return; string shipPowerOutput = "ShipPowerInfo\n"; shipPowerOutput += string.Format("\tBatteryChargePool: [{0}]\n", Math.Round(m_ShipCurrentCharge, 2)); string generatorOutput = "GeneratorInfo\n"; foreach (GameObject generator in m_PowerGenerators) { CFacilityInterface fi = CUtility.FindInParents <CFacilityInterface>(generator); CPowerGenerationBehaviour pgb = generator.GetComponent <CPowerGenerationBehaviour>(); generatorOutput += string.Format("\t[{0}] Within Facility [{1}] Type [{2}] \n\t\tIsGenerationActive: [{3}] GenRate: [{4}]\n", generator.name, fi.FacilityId, fi.FacilityType, pgb.IsPowerGenerationActive, Math.Round(pgb.PowerGenerationRate, 2)); } string storageOutput = "StorageInfo\n"; foreach (GameObject storage in m_PowerStorages) { CFacilityInterface fi = CUtility.FindInParents <CFacilityInterface>(storage); CPowerStorageBehaviour psb = storage.GetComponent <CPowerStorageBehaviour>(); storageOutput += string.Format("\t[{0}] Within Facility [{1}] Type [{2}] \n\t\tIsChargeAvailable: [{3}] Capacity: [{4}] Charge: [{5}]\n", storage.name, fi.FacilityId, fi.FacilityType, psb.IsBatteryChargeAvailable, Math.Round(psb.BatteryCapacity, 2), Math.Round(psb.BatteryCharge, 2)); } string facilitiesOutput = "FacilityPowerInfo\n"; foreach (GameObject facility in gameObject.GetComponent <CShipFacilities>().Facilities) { CFacilityInterface fi = facility.GetComponent <CFacilityInterface>(); CFacilityPower fp = facility.GetComponent <CFacilityPower>(); facilitiesOutput += string.Format("\tFacility [{0}] Type [{1}] \n\t\tIsActive: [{2}] ConsRate: [{3}]\n", fi.FacilityId, fi.FacilityType, fp.IsPowerActive, Math.Round(fp.PowerConsumption, 2)); } float boxWidth = 500; float boxHeight = 600; GUI.Label(new Rect(Screen.width / 2 - boxWidth, 0.0f, boxWidth, boxHeight), "Power Status'\n" + shipPowerOutput + generatorOutput + storageOutput + facilitiesOutput); }
public List<GameObject> FindFacilities(CFacilityInterface.EType _eType) { if (m_mFacilityObjects.ContainsKey(_eType)) { return (m_mFacilityObjects[_eType]); } else { return (null); } }
public void AddNewlyCreatedFacility(GameObject _Facility, uint _FacilityId, CFacilityInterface.EType _FacilityType) { // Index facility against its Facility Id m_mFacilities.Add(_FacilityId, _Facility); // Index facility against its Facility Type if (!m_mFacilityObjects.ContainsKey(_FacilityType)) { m_mFacilityObjects.Add(_FacilityType, new List<GameObject>()); } m_mFacilityObjects[_FacilityType].Add(_Facility); }