Exemple #1
0
    // connId, owner id.
    public GameObject spawnReplicatedGameObject(int connId, string path)
    {
        int[]      goid;
        GameObject pcgo = spawnPrefabOnServer(connId, path, out goid);

        // replicate this to all clients.
        serializeGameObjectReplication(goid, path, -1);

        ReplicatedProperties[] repComponents = pcgo.GetComponents <ReplicatedProperties>();
        for (int i = 0; i < repComponents.Length; ++i)
        {
            repComponents[i].replicateAllStates(SerializedBuffer.RPCMode_ToTarget | SerializedBuffer.RPCMode_ExceptTarget);
            repComponents[i].clientSetRole();
        }

        int idx = getIndexByConnectionId(connId);

        if (idx >= 0)
        {
            GameObjectSpawnInfo gosi = new GameObjectSpawnInfo();
            gosi.path = path;
            gosi.obj  = pcgo;
            playerOwned[idx].gameObjectsOwned.Add(gosi);
        }

        return(pcgo);
    }
Exemple #2
0
    public GameObject createServerGameObject(string path)
    {
        int[]      goid;
        GameObject pcgo = spawnPrefabOnServer(ServerPSId, path, out goid);

        ReplicatedProperties[] repComponents = pcgo.GetComponents <ReplicatedProperties>();
        for (int i = 0; i < repComponents.Length; ++i)
        {
            repComponents[i].isHost = 1;
            repComponents[i].role   = GameObjectRoles.Authority;
            repComponents[i].initialReplicationComplete();
        }
        playerOwned.Add(new PlayerOwnedInfo(ServerPSId));
        int idx = getIndexByConnectionId(ServerPSId);

        if (idx >= 0)
        {
            GameObjectSpawnInfo gosi = new GameObjectSpawnInfo();
            gosi.path = path;
            gosi.obj  = pcgo;
            playerOwned[idx].gameObjectsOwned.Add(gosi);
        }
        return(pcgo);
    }