Example #1
0
        /// <summary>
        /// Called when you want to remove all network objects from the Networker list for a scene
        /// </summary>
        /// <param name="buildIndex"></param>
        void UnloadSceneNetworkObjects(int buildIndex)
        {
            if (buildIndex >= 0)
            {
                List <NetworkObject> networkObjectsToDestroy = new List <NetworkObject>();

                // Gets all networkObjects related to the scene we are destorying
                Networker.IterateNetworkObjects(networkObject =>
                {
                    NetworkBehavior networkBehavior = (NetworkBehavior)networkObject.AttachedBehavior;
                    if (networkBehavior && networkBehavior.gameObject)
                    {
                        if (networkBehavior.gameObject.scene.buildIndex == buildIndex)
                        {
                            networkObjectsToDestroy.Add(networkObject);
                        }
                    }
                });

                Networker.ManualRemove(networkObjectsToDestroy);

                foreach (NetworkObject networkObject in networkObjectsToDestroy)
                {
                    pendingNetworkObjects.Remove(networkObject.CreateCode);
                }
            }
        }
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is PlayerCardsNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerCardsNetworkObject.Length > 0 && PlayerCardsNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerCardsNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerCardsBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
        protected virtual void ProcessOthers(Transform obj, NetworkObject createTarget, ref uint idOffset,
                                             NetworkBehavior netBehavior = null)
        {
            int i;

            // Get the order of the components as they are in the inspector
            var components = obj.GetComponents <NetworkBehavior>();

            // Create each network object that is available
            for (i = 0; i < components.Length; i++)
            {
                if (components[i] == netBehavior)
                {
                    continue;
                }

                var no = components[i].CreateNetworkObject(Networker, 0);

                if (Networker.IsServer)
                {
                    FinalizeInitialization(obj.gameObject, components[i], no, obj.position, obj.rotation, false, true);
                }
                else
                {
                    components[i].AwaitNetworkBind(Networker, createTarget, idOffset++);
                }
            }

            for (i = 0; i < obj.transform.childCount; i++)
            {
                ProcessOthers(obj.transform.GetChild(i), createTarget, ref idOffset);
            }
        }
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is CubeForgeGameNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (CubeForgeGameNetworkObject.Length > 0 && CubeForgeGameNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(CubeForgeGameNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is DwarfNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (DwarfNetworkObject.Length > 0 && DwarfNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(DwarfNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ExampleProximityPlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ExampleProximityPlayerNetworkObject.Length > 0 && ExampleProximityPlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ExampleProximityPlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is NetworkCameraNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (NetworkCameraNetworkObject.Length > 0 && NetworkCameraNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(NetworkCameraNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is TestNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (TestNetworkObject.Length > 0 && TestNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(TestNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Example #5
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is CannonBallNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (CannonBallNetworkObject.Length > 0 && CannonBallNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(CannonBallNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <CannonBallBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ChatNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatNetworkObject.Length > 0 && ChatNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ChatBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is LeaderboardNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (LeaderboardNetworkObject.Length > 0 && LeaderboardNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(LeaderboardNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <LeaderboardBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Example #6
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ChatManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is DungeonGeneratorNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (DungeonGeneratorNetworkObject.Length > 0 && DungeonGeneratorNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(DungeonGeneratorNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <DungeonGeneratorBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameManagerNetworkObject.Length > 0 && GameManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameNetworkManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameNetworkManagerNetworkObject.Length > 0 && GameNetworkManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameNetworkManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameNetworkManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerControllerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerControllerNetworkObject.Length > 0 && PlayerControllerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerControllerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerControllerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is SpellManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (SpellManagerNetworkObject.Length > 0 && SpellManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(SpellManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <SpellManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is SpellSpawnPointNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (SpellSpawnPointNetworkObject.Length > 0 && SpellSpawnPointNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(SpellSpawnPointNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <SpellSpawnPointBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is TestNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (TestNetworkObject.Length > 0 && TestNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(TestNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <TestBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Example #7
0
        private void CaptureObjects(NetworkObject obj)
        {
            ///if (obj.CreateCode < 0)
            ///return;

            obj.CreateCode = 0;
            if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameModeNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameModeNetworkObject.Length > 0 && GameModeNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameModeNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is WeaponPickupNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (WeaponPickupNetworkObject.Length > 0 && WeaponPickupNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(WeaponPickupNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Example #8
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ChatManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameLogicNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameLogicNetworkObject.Length > 0 && GameLogicNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameLogicNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameLogicBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is NetworkCameraNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (NetworkCameraNetworkObject.Length > 0 && NetworkCameraNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(NetworkCameraNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <NetworkCameraBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameBallNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameBallNetworkObject.Length > 0 && GameBallNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameBallNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameBallBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Example #9
0
        private void ProcessOthers(Transform obj, NetworkObject createTarget, uint idOffset, NetworkBehavior netBehavior = null)
        {
            int i;

            var components = obj.GetComponents <NetworkBehavior>().OrderBy(n => n.GetType().ToString()).ToArray();

            // Create each network object that is available
            for (i = 0; i < components.Length; i++)
            {
                if (components[i] == netBehavior)
                {
                    continue;
                }

                var no = components[i].CreateNetworkObject(Networker, 0);

                if (Networker.IsServer)
                {
                    FinializeInitialization(obj.gameObject, components[i], no, obj.position, obj.rotation, false, true);
                }
                else
                {
                    components[i].AwaitNetworkBind(Networker, createTarget, idOffset++);
                }
            }

            for (i = 0; i < obj.transform.childCount; i++)
            {
                ProcessOthers(obj.transform.GetChild(i), createTarget, idOffset);
            }
        }
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is FightManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (FightManagerNetworkObject.Length > 0 && FightManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(FightManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <FightManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is LobbyNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (LobbyNetworkObject.Length > 0 && LobbyNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(LobbyNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <LobbyBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PickupNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PickupNetworkObject.Length > 0 && PickupNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PickupNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PickupBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is WorldObjectNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (WorldObjectNetworkObject.Length > 0 && WorldObjectNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(WorldObjectNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <WorldObjectBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }
Example #11
0
        private void CaptureObjects(NetworkObject obj)
        {
            if (obj.CreateCode < 0)
            {
                return;
            }

            if (obj is AnimTestObjNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (AnimTestObjNetworkObject.Length > 0 && AnimTestObjNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(AnimTestObjNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <AnimTestObjBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ChatManagerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ChatManagerNetworkObject.Length > 0 && ChatManagerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ChatManagerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ChatManagerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ExampleProximityPlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ExampleProximityPlayerNetworkObject.Length > 0 && ExampleProximityPlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ExampleProximityPlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ExampleProximityPlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is FlameAttacckNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (FlameAttacckNetworkObject.Length > 0 && FlameAttacckNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(FlameAttacckNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <FlameAttacckBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is GameModeNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (GameModeNetworkObject.Length > 0 && GameModeNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(GameModeNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <GameModeBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is PlayerNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (PlayerNetworkObject.Length > 0 && PlayerNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(PlayerNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <PlayerBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is TestNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (TestNetworkObject.Length > 0 && TestNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(TestNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <TestBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
            else if (obj is ThrowObjNetworkObject)
            {
                MainThreadManager.Run(() =>
                {
                    NetworkBehavior newObj = null;
                    if (!NetworkBehavior.skipAttachIds.TryGetValue(obj.NetworkId, out newObj))
                    {
                        if (ThrowObjNetworkObject.Length > 0 && ThrowObjNetworkObject[obj.CreateCode] != null)
                        {
                            var go = Instantiate(ThrowObjNetworkObject[obj.CreateCode]);
                            newObj = go.GetComponent <ThrowObjBehavior>();
                        }
                    }

                    if (newObj == null)
                    {
                        return;
                    }

                    newObj.Initialize(obj);

                    if (objectInitialized != null)
                    {
                        objectInitialized(newObj, obj);
                    }
                });
            }
        }