Esempio n. 1
0
        public override void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, Action <NetworkObject> callback)
        {
            if (networker.IsServer)
            {
                if (frame.Sender != null && frame.Sender != networker.Me)
                {
                    if (!ValidateCreateRequest(networker, identity, id, frame))
                    {
                        return;
                    }
                }
            }

            bool          availableCallback = false;
            NetworkObject obj = null;

            MainThreadManager.Run(() =>
            {
                switch (identity)
                {
                case ChatManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new ChatManagerNetworkObject(networker, id, frame);
                    break;

                case CubeForgeGameNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new CubeForgeGameNetworkObject(networker, id, frame);
                    break;

                case ExampleProximityPlayerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new ExampleProximityPlayerNetworkObject(networker, id, frame);
                    break;

                case NetworkCameraNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new NetworkCameraNetworkObject(networker, id, frame);
                    break;

                case TestNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new TestNetworkObject(networker, id, frame);
                    break;
                }

                if (!availableCallback)
                {
                    base.NetworkCreateObject(networker, identity, id, frame, callback);
                }
                else if (callback != null)
                {
                    callback(obj);
                }
            });
        }
Esempio n. 2
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (TestNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("FuncBlank", FuncBlank);
            networkObject.RegisterRpc("FuncByte", FuncByte, typeof(byte));
            networkObject.RegisterRpc("FuncChar", FuncChar, typeof(char));
            networkObject.RegisterRpc("FuncShort", FuncShort, typeof(short));
            networkObject.RegisterRpc("FuncUShort", FuncUShort, typeof(ushort));
            networkObject.RegisterRpc("FuncBool", FuncBool, typeof(bool));
            networkObject.RegisterRpc("FuncInt", FuncInt, typeof(int));
            networkObject.RegisterRpc("FuncUInt", FuncUInt, typeof(uint));
            networkObject.RegisterRpc("FuncFloat", FuncFloat, typeof(float));
            networkObject.RegisterRpc("FuncLong", FuncLong, typeof(long));
            networkObject.RegisterRpc("FuncULong", FuncULong, typeof(ulong));
            networkObject.RegisterRpc("FuncDouble", FuncDouble, typeof(double));
            networkObject.RegisterRpc("FuncString", FuncString, typeof(string));
            networkObject.RegisterRpc("FuncByteArray", FuncByteArray, typeof(byte[]));
            networkObject.RegisterRpc("FuncAll", FuncAll, typeof(byte), typeof(char), typeof(short), typeof(ushort), typeof(bool), typeof(int), typeof(uint), typeof(float), typeof(long), typeof(ulong), typeof(double), typeof(string), typeof(byte[]));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Esempio n. 3
0
        public override void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, Action <NetworkObject> callback)
        {
            if (networker.IsServer)
            {
                if (frame.Sender != null && frame.Sender != networker.Me)
                {
                    if (!ValidateCreateRequest(networker, identity, id, frame))
                    {
                        return;
                    }
                }
            }

            bool          availableCallback = false;
            NetworkObject obj = null;

            MainThreadManager.Run(() =>
            {
                switch (identity)
                {
                case ChatManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new ChatManagerNetworkObject(networker, id, frame);
                    break;

                case DungeonGeneratorNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new DungeonGeneratorNetworkObject(networker, id, frame);
                    break;

                case GameManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new GameManagerNetworkObject(networker, id, frame);
                    break;

                case GameNetworkManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new GameNetworkManagerNetworkObject(networker, id, frame);
                    break;

                case PlayerControllerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new PlayerControllerNetworkObject(networker, id, frame);
                    break;

                case SpellManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new SpellManagerNetworkObject(networker, id, frame);
                    break;

                case SpellSpawnPointNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new SpellSpawnPointNetworkObject(networker, id, frame);
                    break;

                case TestNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new TestNetworkObject(networker, id, frame);
                    break;
                }

                if (!availableCallback)
                {
                    base.NetworkCreateObject(networker, identity, id, frame, callback);
                }
                else if (callback != null)
                {
                    callback(obj);
                }
            });
        }