Exemple #1
0
        protected virtual void Reset()
        {
            // get role from first found component
            var comp = GetComponentInChildren <IViveRoleComponent>();

            if (comp != null)
            {
                m_viveRole.Set(comp.viveRole);
            }
        }
        protected virtual void OnValidate()
        {
            // change old DeviceRole value to viveRole value
            var serializedObject = new UnityEditor.SerializedObject(this);

            var roleValueProp = serializedObject.FindProperty("role");
            var oldRoleValue  = roleValueProp.intValue;

            if (oldRoleValue != (int)DeviceRole.Invalid)
            {
                Type newRoleType;
                int  newRoleValue;

                if (oldRoleValue == -1)
                {
                    newRoleType  = typeof(DeviceRole);
                    newRoleValue = (int)DeviceRole.Hmd;
                }
                else
                {
                    newRoleType  = typeof(HandRole);
                    newRoleValue = oldRoleValue;
                }

                if (Application.isPlaying)
                {
                    roleValueProp.intValue = (int)DeviceRole.Invalid;
                    m_viveRole.Set(newRoleType, newRoleValue);
                }
                else
                {
                    roleValueProp.intValue = (int)DeviceRole.Invalid;
                    serializedObject.ApplyModifiedProperties();
                    m_viveRole.Set(newRoleType, newRoleValue);
                    serializedObject.Update();
                }
            }
            serializedObject.Dispose();
        }
 public void OnAfterModelCreated(RenderModelHook hook)
 {
     m_viveRole.Set(hook.viveRole);
 }