Beispiel #1
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

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

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SendColor", SendColor, typeof(Color));
            networkObject.RegistrationComplete();

            MainThreadManager.Run(NetworkStart);

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }
        }
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

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

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SendColor", SendColor, typeof(Color));

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(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)
            {
                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); });
            }
        }