Example #1
0
    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");
        }
    }
Example #2
0
    void Start()
    {
        // Ensure a type of defined
        if (m_eComponentType == EType.INVALID)
        {
            Debug.LogError(string.Format("This component has not been given a component type. GameObjectName({0})", gameObject.name));
        }

        // Register self with parent module
        CModuleInterface mi = CUtility.FindInParents <CModuleInterface>(gameObject);

        if (mi != null)
        {
            mi.RegisterAttachedComponent(this);
        }
        else
        {
            Debug.LogError("Could not find module to register to");
        }

        if (EventHealthChange != null)
        {
            EventHealthChange(this, GetComponent <CActorHealth>());
        }
    }
Example #3
0
    // Member Properties


    // Member Methods
    public void OnPress(bool _IsPressed)
    {
        if (CNetwork.IsServer)
        {
            // Find the Root2D script
            CDUIRoot2D r2d = CUtility.FindInParents <CDUIRoot2D>(gameObject);

            // Inform it to switch to this panel
            if (r2d != null)
            {
                r2d.SwitchToPanel(m_PanelToSwitchTo);
            }
            else
            {
                Debug.LogError("CDUIRoot2D was not found in hierarchy");
            }
        }
    }
Example #4
0
    private void OnTriggerExit(Collider _Other)
    {
        if (!CNetwork.IsServer)
        {
            return;
        }

        Rigidbody rb = _Other.rigidbody;

        if (rb == null)
        {
            rb = CUtility.FindInParents <Rigidbody>(_Other.gameObject);
        }

        if (rb != null)
        {
            m_CachedOnboardActors.OnActorExitedFacilityTrigger(rb.gameObject);
        }
    }
Example #5
0
    public void BoardActor()
    {
        // Check if this actor isnt a child of another boardable actor
        if (CUtility.FindInParents <CActorBoardable>(gameObject) == null)
        {
            // Set the boarding state
            m_BoardingState.Set(EBoardingState.Onboard);

            // Get the inverse of the relative velocity of the actor boarding
            Vector3 transferedVelocity = CGameShips.ShipGalaxySimulator.GetGalaxyVelocityRelativeToShip(transform.position) * -1.0f;

            // Add the current velocity of the actor transformed to simulation space
            Vector3 currentVelocity = CGameShips.ShipGalaxySimulator.GetGalaxyToSimulationRot(Quaternion.identity) * rigidbody.velocity;
            transferedVelocity += currentVelocity;

            // Transfer the actor to ship space
            CGameShips.ShipGalaxySimulator.TransferFromGalaxyToSimulation(transform.position, transform.rotation, transform);

            // Set the compensation velocity of the actor
            rigidbody.velocity = transferedVelocity;
        }
    }
Example #6
0
    public void DisembarkActor()
    {
        // Check if this actor isnt a child of another boardable actor
        if (CUtility.FindInParents <CActorBoardable>(gameObject) == null)
        {
            // Set the boarding state
            m_BoardingState.Set(EBoardingState.Offboard);

            // Transfer the actor to galaxy ship space
            CGameShips.ShipGalaxySimulator.TransferFromSimulationToGalaxy(transform.position, transform.rotation, transform);

            // Get the relative velocity of the actor disembarking and apply the compensation force to the actor
            Vector3 transferedVelocity = CGameShips.ShipGalaxySimulator.GetGalaxyVelocityRelativeToShip(transform.position);

            // Add the current velocity of the actor transformed to galaxy space
            Vector3 currentVelocity = CGameShips.ShipGalaxySimulator.GetSimulationToGalaxyRot(Quaternion.identity) * rigidbody.velocity;
            transferedVelocity += currentVelocity;

            // Set the compensation velocity of the actor
            rigidbody.velocity = transferedVelocity;
        }
    }
Example #7
0
    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);
    }
Example #8
0
    /////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////

    //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);
    }
Example #9
0
    void UpdateTarget()
    {
        GameObject cPlayerCamera         = CGameCameras.PlayersHeadCamera;
        Ray        cCameraRay            = new Ray(cPlayerCamera.transform.position, cPlayerCamera.transform.forward);
        GameObject cNewTargetActorObject = null;
        RaycastHit cTargetRaycastHit     = new RaycastHit();

        // Do the raycast against all objects in path
        RaycastHit[] cRaycastHits = Physics.RaycastAll(cCameraRay, k_fRayRange).OrderBy(_cRay => _cRay.distance).ToArray();

        // Check each one for an interactable objectg
        foreach (RaycastHit cRaycastHit in cRaycastHits)
        {
            // Iteractable objects must be non-trigger
            if (!cRaycastHit.collider.isTrigger)
            {
                // Get the game object which owns this mesh
                GameObject cHitObject = cRaycastHit.collider.gameObject;

                // Check the object itself for the interactable script
                CActorInteractable cActorInteractable = cHitObject.GetComponent <CActorInteractable>();

                // Check the parents until we find the one that has CActorInteractable on it
                if (cActorInteractable == null)
                {
                    cActorInteractable = CUtility.FindInParents <CActorInteractable>(cHitObject);
                }

                // If found an interactable select it
                if (cActorInteractable != null)
                {
                    cNewTargetActorObject = cActorInteractable.gameObject;
                    cTargetRaycastHit     = cRaycastHit;
                }

                // Break out - if the first propper collider wasn't interactable this is intentional
                break;
            }
        }

        if (cNewTargetActorObject != m_cTargetActorObject)
        {
            s_cSerializeStream.Write((byte)ENetworkAction.UpdateTarget);

            if (cNewTargetActorObject == null)
            {
                s_cSerializeStream.Write((CNetworkViewId)null);
            }
            else
            {
                s_cSerializeStream.Write(cNewTargetActorObject.GetComponent <CNetworkView>().ViewId);
            }

            m_cOldTargetActorObject = m_cTargetActorObject;
            m_cTargetActorObject    = cNewTargetActorObject;

            // Notify old target about loosing hover
            if (m_cOldTargetActorObject != null)
            {
                m_cOldTargetActorObject.GetComponent <CActorInteractable>().OnInteractionHover(gameObject, new RaycastHit(), false);
            }

            // Notify new target about hover
            if (m_cTargetActorObject != null)
            {
                m_cTargetActorObject.GetComponent <CActorInteractable>().OnInteractionHover(gameObject, m_cTargetRaycastHit, true);
            }

            // Notify observers about target change
            if (EventTargetChange != null)
            {
                EventTargetChange(m_cOldTargetActorObject, m_cTargetActorObject, m_cTargetRaycastHit);
            }
        }

        if (m_cTargetActorObject != null)
        {
            m_cTargetRaycastHit = cTargetRaycastHit;
        }
    }