Example #1
0
    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);
    }
Example #2
0
    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);
        }
    }