コード例 #1
0
        public LiteNetLibIdentity NetworkSpawnScene(uint objectId, Vector3 position, Quaternion rotation)
        {
            if (!Manager.IsNetworkActive)
            {
                Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawnScene - Network is not active cannot spawn");
                return(null);
            }

            LiteNetLibIdentity sceneObject = null;

            if (SceneObjects.TryGetValue(objectId, out sceneObject))
            {
                sceneObject.gameObject.SetActive(true);
                sceneObject.transform.position = position;
                sceneObject.transform.rotation = rotation;
                sceneObject.Initial(Manager, true, objectId);
                SpawnedObjects[sceneObject.ObjectId] = sceneObject;
                return(sceneObject);
            }
            else if (Manager.LogWarn)
            {
                Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawnScene - Object Id: " + objectId + " is not registered.");
            }
            return(null);
        }
コード例 #2
0
        public LiteNetLibIdentity NetworkSpawn(LiteNetLibIdentity identity, uint objectId = 0, long connectionId = -1)
        {
            if (identity == null)
            {
                if (Manager.LogWarn)
                {
                    Logging.LogWarning(LogTag, "NetworkSpawn - identity is null.");
                }
                return(null);
            }

            identity.gameObject.SetActive(true);
            identity.Initial(Manager, false, objectId, connectionId);
            identity.InitTransform(identity.transform.position, identity.transform.rotation);
            identity.OnSetOwnerClient(connectionId >= 0 && connectionId == Manager.ClientConnectionId);
            if (Manager.IsServer)
            {
                identity.OnStartServer();
            }
            if (Manager.IsClient)
            {
                identity.OnStartClient();
            }
            if (connectionId >= 0 && connectionId == Manager.ClientConnectionId)
            {
                identity.OnStartOwnerClient();
            }
            if (onObjectSpawn != null)
            {
                onObjectSpawn.Invoke(identity);
            }

            return(identity);
        }
コード例 #3
0
        public LiteNetLibIdentity NetworkSpawn(GameObject gameObject, uint objectId = 0, long connectionId = -1)
        {
            if (gameObject == null)
            {
                if (Manager.LogWarn)
                {
                    Logging.LogWarning(LogTag, "NetworkSpawn - gameObject is null.");
                }
                return(null);
            }

            LiteNetLibIdentity identity = gameObject.GetComponent <LiteNetLibIdentity>();

            if (identity == null)
            {
                if (Manager.LogWarn)
                {
                    Logging.LogWarning(LogTag, "NetworkSpawn - identity is null.");
                }
                return(null);
            }

            identity.gameObject.SetActive(true);
            identity.Initial(Manager, false, objectId, connectionId);
            identity.InitTransform(gameObject.transform.position, gameObject.transform.rotation);
            identity.SetOwnerClient(connectionId >= 0 && connectionId == Manager.ClientConnectionId);
            if (onObjectSpawn != null)
            {
                onObjectSpawn.Invoke(identity);
            }
            if (Manager.IsServer)
            {
                identity.OnStartServer();
            }
            if (Manager.IsClient)
            {
                identity.OnStartClient();
            }
            if (connectionId >= 0 && connectionId == Manager.ClientConnectionId)
            {
                identity.OnStartOwnerClient();
            }
            SpawnedObjects[identity.ObjectId] = identity;

            // Add to player spawned objects dictionary
            LiteNetLibPlayer player;

            if (Manager.TryGetPlayer(connectionId, out player))
            {
                player.SpawnedObjects[identity.ObjectId] = identity;
            }

            return(identity);
        }
コード例 #4
0
        public LiteNetLibIdentity NetworkSpawn(GameObject gameObject, uint objectId = 0, long connectionId = -1)
        {
            if (gameObject == null)
            {
                if (Manager.LogWarn)
                {
                    Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawn - gameObject is null.");
                }
                return(null);
            }

            LiteNetLibIdentity identity = gameObject.GetComponent <LiteNetLibIdentity>();

            if (identity == null)
            {
                if (Manager.LogWarn)
                {
                    Debug.LogWarning("[" + name + "] LiteNetLibAssets::NetworkSpawn - identity is null.");
                }
                return(null);
            }

            identity.gameObject.SetActive(true);
            identity.Initial(Manager, false, objectId, connectionId);
            SpawnedObjects[identity.ObjectId] = identity;

            // Add to player spawned objects dictionary
            LiteNetLibPlayer player;

            if (Manager.TryGetPlayer(connectionId, out player))
            {
                player.SpawnedObjects[identity.ObjectId] = identity;
            }

            return(identity);
        }