// Collisions
        private void OnCollisionEnter(Collision collision)
        {
            // If we're using extrapolation, start simulating locally in order to make the bounce smoother.
            if (_extrapolation)
            {
                _stopExtrapolatingAtRoomTime = realtime.room.time;
            }

            // If we are currently the authoritative owner of this rigidbody and we've collided with a rigidbody that isn't owned by anyone, let's take over ownership and start simulating it.
            if (isOwnedLocally)
            {
                Rigidbody rigidbody = collision.rigidbody;
                if (rigidbody != null)
                {
                    RealtimeTransform otherRealtimeTransform = rigidbody.GetComponent <RealtimeTransform>();
                    if (otherRealtimeTransform != null)
                    {
                        // If the other realtime rigidbody isn't owned by anyone and it's not kinematic, take it over.
                        if (otherRealtimeTransform.isOwnedByWorld && !otherRealtimeTransform.model.isKinematic)
                        {
                            otherRealtimeTransform.RequestOwnership();
                        }
                    }
                }
            }
        }
Example #2
0
    void Start()
    {
        _rt = GetComponentInParent <Normal.Realtime.RealtimeTransform>();
        _rv = GetComponentInParent <Normal.Realtime.RealtimeView>();
        //_rv.RequestOwnership();

        //Debug.Log("realtime.clientID is " + _rt.ownerID);
        objMats = this.gameObject.GetComponent <Renderer>().materials;

        if (_rt != null)
        {
            //set the player number to the matching material number
            if (_rt.ownerID < avatarMats.Length && _rt.ownerID >= -1)
            {
                //Debug.Log(_rt.ownerID + 1);
                objMats[matSlot] = avatarMats[_rt.ownerID + 1];
            }
            //but if we have more players than materials, than cycle back around
            else
            {
                objMats[matSlot] = avatarMats[_rt.ownerID % avatarMats.Length];
            }
            //don't forget to tell this object to now use our new materials
            this.gameObject.GetComponent <Renderer>().materials = objMats;

            //Debug.Log("clientID is " + _rv.realtime.clientID);
        }
        if (_rt == null && _rv != null)
        {
            //set the player number to the matching material number
            if (_rv.ownerID < avatarMats.Length && _rv.ownerID >= -1)
            {
                //Debug.Log(_rt.ownerID + 1);
                objMats[matSlot] = avatarMats[_rv.ownerID + 1];
            }
            //but if we have more players than materials, than cycle back around
            else
            {
                objMats[matSlot] = avatarMats[_rv.ownerID % avatarMats.Length];
            }
            //don't forget to tell this object to now use our new materials
            this.gameObject.GetComponent <Renderer>().materials = objMats;

            //Debug.Log("clientID is " + _rv.realtime.clientID);
        }

        /*
         * if (_rt == null && _rv == null)
         * {
         *
         * } */
    }
Example #3
0
        void SetLocalPlayer(LocalPlayer localPlayer)
        {
            if (localPlayer == _localPlayer)
            {
                return;
            }

            _localPlayer = localPlayer;

            if (_localPlayer != null)
            {
                // TODO: Technically this shouldn't be needed. The RealtimeViewModel is created and locked to a user. The owner of that should progagate to children...
                RealtimeTransform rootRealtimeTransform = GetComponent <RealtimeTransform>();
                RealtimeTransform headRealtimeTransform = _head != null?_head.GetComponent <RealtimeTransform>() : null;

                RealtimeTransform leftHandRealtimeTransform = _leftHand != null?_leftHand.GetComponent <RealtimeTransform>() : null;

                RealtimeTransform rightHandRealtimeTransform = _rightHand != null?_rightHand.GetComponent <RealtimeTransform>() : null;

                if (rootRealtimeTransform != null)
                {
                    rootRealtimeTransform.RequestOwnership();
                }
                if (headRealtimeTransform != null)
                {
                    headRealtimeTransform.RequestOwnership();
                }
                if (leftHandRealtimeTransform != null)
                {
                    leftHandRealtimeTransform.RequestOwnership();
                }
                if (rightHandRealtimeTransform != null)
                {
                    rightHandRealtimeTransform.RequestOwnership();
                }
            }
        }
        static RealtimeTransform AddRealtimeTransformComponentIfNeeded(GameObject gameObject, bool syncScale)
        {
            // Check for existing RealtimeTransform
            RealtimeTransform realtimeTransform = gameObject.GetComponent <RealtimeTransform>();

            // Create one if needed
            if (realtimeTransform == null)
            {
                realtimeTransform = gameObject.AddComponent <RealtimeTransform>();

                // Set syncScale
                SerializedObject realtimeTransformSerializedObject = new SerializedObject(realtimeTransform);
                realtimeTransformSerializedObject.Update();
                SerializedProperty syncScaleProperty = realtimeTransformSerializedObject.FindProperty("_syncScale");
                syncScaleProperty.boolValue = syncScale;
                realtimeTransformSerializedObject.ApplyModifiedProperties();

                // Collapse inspector
                SetComponentInspectorExpanded(realtimeTransform, false);
            }

            // Return
            return(realtimeTransform);
        }
        void CreateAvatarPrefab()
        {
            GameObject gameObject = realtimeAvatar.gameObject;

            //// Root
            // RealtimeView
            RealtimeView rootRealtimeView = AddRealtimeViewComponentIfNeeded(gameObject);

            // RealtimeAvatar
            AddComponentToRealtimeViewIfNeeded(rootRealtimeView, realtimeAvatar);

            // RealtimeTransform
            RealtimeTransform rootRealtimeTransform = AddRealtimeTransformComponentIfNeeded(gameObject, true);

            AddComponentToRealtimeViewIfNeeded(rootRealtimeView, rootRealtimeTransform);


            //// Head
            Transform head = CreateGameObjectForPropertyIfNeeded(headProperty, gameObject.transform, "Head", new Type[] { typeof(Examples.VoiceScale) });

            // RealtimeView
            RealtimeView headRealtimeView = AddRealtimeViewComponentIfNeeded(head.gameObject);

            // RealtimeTransform
            RealtimeTransform headRealtimeTransform = AddRealtimeTransformComponentIfNeeded(head.gameObject, false);

            AddComponentToRealtimeViewIfNeeded(headRealtimeView, headRealtimeTransform);

            // RealtimeAvatarVoice
            RealtimeAvatarVoice headRealtimeAvatarVoice = head.gameObject.GetComponent <RealtimeAvatarVoice>();

            if (headRealtimeAvatarVoice == null)
            {
                headRealtimeAvatarVoice = head.gameObject.AddComponent <RealtimeAvatarVoice>();

                // Collapse inspector
                SetComponentInspectorExpanded(headRealtimeAvatarVoice, false);
            }
            AddComponentToRealtimeViewIfNeeded(headRealtimeView, headRealtimeAvatarVoice);


            //// Left Hand
            Transform leftHand = CreateGameObjectForPropertyIfNeeded(leftHandProperty, gameObject.transform, "Left Hand");

            // RealtimeView
            RealtimeView leftHandRealtimeView = AddRealtimeViewComponentIfNeeded(leftHand.gameObject);

            // RealtimeTransform
            RealtimeTransform leftHandRealtimeTransform = AddRealtimeTransformComponentIfNeeded(leftHand.gameObject, false);

            AddComponentToRealtimeViewIfNeeded(leftHandRealtimeView, leftHandRealtimeTransform);


            //// Right Hand
            Transform rightHand = CreateGameObjectForPropertyIfNeeded(rightHandProperty, gameObject.transform, "Right Hand");

            // RealtimeView
            RealtimeView rightHandRealtimeView = AddRealtimeViewComponentIfNeeded(rightHand.gameObject);

            // RealtimeTransform
            RealtimeTransform rightHandRealtimeTransform = AddRealtimeTransformComponentIfNeeded(rightHand.gameObject, false);

            AddComponentToRealtimeViewIfNeeded(rightHandRealtimeView, rightHandRealtimeTransform);
        }