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

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

            base.SetupHelperRpcs(networkObject);

            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(() =>
            {
                gameObject.SetActive(true);
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }