示例#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 FightManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new FightManagerNetworkObject(networker, id, frame);
                    break;

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

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

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

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

                if (!availableCallback)
                {
                    base.NetworkCreateObject(networker, identity, id, frame, callback);
                }
                else if (callback != null)
                {
                    callback(obj);
                }
            });
        }
示例#2
0
        public override void NetworkCreateObject(NetWorker networker, int identity, uint id, FrameStream frame, Action <NetworkObject> callback)
        {
            if (NetworkManager.Instance.IsMaster)
            {
                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 GameModeNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new GameModeNetworkObject(networker, id, frame);
                    break;

                case PlayerNetworkObject.IDENTITY:
                    availableCallback = true;
                    ///obj = new PlayerNetworkObject(networker, id, frame);
                    obj = new PlayerNetworkObject();
                    PlayerNetworkObject playerObj = (PlayerNetworkObject)obj;
                    playerObj.SetupUID((int)id, true);
                    break;

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

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

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

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("LocalPlayerSpawned", LocalPlayerSpawned);
            networkObject.RegisterRpc("Damage", Damage, typeof(int));
            networkObject.RegisterRpc("Knockback", Knockback, typeof(Vector2));
            networkObject.RegisterRpc("Shoot", Shoot, typeof(uint), typeof(Vector2), typeof(Vector2));
            networkObject.RegisterRpc("DestroyBullet", DestroyBullet, typeof(uint));
            networkObject.RegisterRpc("OnDeath", OnDeath);
            networkObject.RegisterRpc("OnRespawn", OnRespawn);
            networkObject.RegisterRpc("SetWeapon", SetWeapon, typeof(int));

            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);
            });
        }
        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 GameManagerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new GameManagerNetworkObject(networker, id, frame);
                    break;

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

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

                case PlayerNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new PlayerNetworkObject(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);
                }
            });
        }
示例#5
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

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

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SetupPlayer", SetupPlayer, typeof(ulong));

            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);

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

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
示例#6
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 AetherNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new AetherNetworkObject(networker, id, frame);
                    break;

                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 DamageNetworkObject.IDENTITY:
                    availableCallback = true;
                    obj = new DamageNetworkObject(networker, id, frame);
                    break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("Server_TakeDamage", Server_TakeDamage, typeof(int));
            networkObject.RegisterRpc("Server_AddHealth", Server_AddHealth, typeof(int));
            networkObject.RegisterRpc("Server_SetHealth", Server_SetHealth, typeof(int));
            networkObject.RegisterRpc("Die", Die);
            networkObject.RegisterRpc("FireAnim", FireAnim);
            networkObject.RegisterRpc("TriggerWalkAnim", TriggerWalkAnim, typeof(float), typeof(float), typeof(float), typeof(bool), typeof(bool), typeof(int), typeof(int), typeof(int));
            networkObject.RegisterRpc("Server_AnnounceDeath", Server_AnnounceDeath, typeof(string), typeof(string));
            networkObject.RegisterRpc("Server_AnnouncePlayerName", Server_AnnouncePlayerName, typeof(string));

            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);
            });
        }
示例#8
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

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

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("UpdateName", UpdateName, typeof(string));
            networkObject.RegisterRpc("UpdatePing", UpdatePing, typeof(int));
            networkObject.RegisterRpc("UpdateKills", UpdateKills, typeof(int));
            networkObject.RegisterRpc("Shoot", Shoot, typeof(Vector3), typeof(Vector3));
            networkObject.RegisterRpc("TakeDamage", TakeDamage, typeof(int), typeof(uint), typeof(Vector3), typeof(Vector3));
            networkObject.RegisterRpc("UpdateId", UpdateId, typeof(uint));
            networkObject.RegisterRpc("Spawn", Spawn, typeof(Vector3), typeof(Quaternion));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                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);
            });
        }
示例#9
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

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

            base.SetupHelperRpcs(networkObject);

            networkObject.onDestroy += DestroyGameObject;

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

            if (obj.Metadata == null)
            {
                return;
            }

            byte transformFlags = obj.Metadata[0];

            if (transformFlags == 0)
            {
                return;
            }

            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);
            });
        }
示例#10
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

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

            /*
             *          base.SetupHelperRpcs(networkObject);
             *          networkObject.RegisterRpc("Shoot", Shoot, typeof(Vector3), typeof(Vector3));
             *          networkObject.RegisterRpc("Die", Die, typeof(string));
             *          networkObject.RegisterRpc("SwitchWeapon", SwitchWeapon, typeof(int));
             *          networkObject.RegisterRpc("TakeDamage", TakeDamage, typeof(int), typeof(Vector3), typeof(Vector3));
             *          networkObject.RegisterRpc("SetupPlayer", SetupPlayer, typeof(int), typeof(string));
             */

            networkObject.onDestroy += DestroyGameObject;

            ///if (!obj.IsOwner)
            if (networkObject.IsRemote)
            {
                if (!skipAttachIds.ContainsKey((uint)networkObject.frameSender.UID))
                {
                    ProcessOthers(gameObject.transform, (uint)networkObject.frameSender.UID + 1);
                }
                else
                {
                    skipAttachIds.Remove((uint)networkObject.frameSender.UID);
                }
            }

            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();
                if (!networkObject.IsRemote)
                {
                    networkObject.Networker.FlushCreateActions(networkObject);
                }
            });
        }