Exemple #1
0
        private static void SaveField(object fieldObj, XmlElement node)
        {
            if (fieldObj == null)
            {
                node.AddElement("value").SetValue("");
                return;
            }

            Type fieldType = fieldObj.GetType();

            if (IsPrimitiveType(fieldType))
            {
                node.AddElement("value").SetValue(fieldObj);
            }
            else if (fieldType == typeof(Vector2))
            {
                SaveField(ToFloatArray((Vector2)fieldObj), node);
            }
            else if (fieldType == typeof(Vector3))
            {
                SaveField(ToFloatArray((Vector3)fieldObj), node);
            }
            else if (fieldType == typeof(Vector4))
            {
                SaveField(ToFloatArray((Vector4)fieldObj), node);
            }
            else if (fieldType == typeof(Quaternion))
            {
                SaveField(ToFloatArray((Quaternion)fieldObj), node);
            }
            else if (fieldType == typeof(Color))
            {
                SaveField(ToFloatArray((Color)fieldObj), node);
            }
            else if (fieldType.IsArray || (fieldObj is IList && fieldType.IsGenericType))
            {
                IList arrayObjects = (IList)fieldObj;
                foreach (var o in arrayObjects)
                {
                    SaveField(o, node.AddElement("ArrayElement"));
                }
            }
            else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)))
            {
#if UNITY_EDITOR
                string assetPath = UnityEditor.AssetDatabase.GetAssetPath(((UnityEngine.Object)fieldObj).GetInstanceID());
                node.AddElement("value").SetValue(UnityEditor.AssetDatabase.AssetPathToGUID(assetPath));
#endif
            }
            else
            {
                List <FieldInfo> fields = QuickUtils.GetAllFieldsConfigurable(fieldObj.GetType());
                foreach (FieldInfo f in fields)
                {
                    XmlElement e = node.AddElement("Field");
                    e.SetAttribute("name", f.Name);
                    SaveField(f.GetValue(fieldObj), e);
                }
            }
        }
Exemple #2
0
        protected virtual void OnDestroy()
        {
            //ResetTPose();

            QuickUtils.Destroy(transform.Find(IK_SOLVERS_ROOT_NAME));

            QuickUtils.Destroy(m_ikTargetsRoot);
        }
Exemple #3
0
        public override string[] GetVibratorCodes()
        {
            List <string> result = new List <string>(base.GetVibratorCodes());

            result.AddRange(QuickUtils.GetEnumValuesToString <VibratorCodes>());

            return(result.ToArray());
        }
Exemple #4
0
        public static QuickHumanFingers[] GetHumanFingers()
        {
            if (_fingers == null)
            {
                _fingers = QuickUtils.GetEnumValues <QuickHumanFingers>().ToArray();
            }

            return(_fingers);
        }
Exemple #5
0
        public static HumanBodyBones[] GetHumanBodyBones()
        {
            if (_humanBodyBones == null)
            {
                List <HumanBodyBones> tmp = QuickUtils.GetEnumValues <HumanBodyBones>();
                tmp.RemoveAt(tmp.Count - 1);  //Remove the LastBone, which is not a valid HumanBodyBone ID
                _humanBodyBones = tmp.ToArray();
            }

            return(_humanBodyBones);
        }
Exemple #6
0
        public static HumanBodyBones ToHumanBodyBones(IKBone ikBone)
        {
            if (_toHumanBodyBones.Count == 0)
            {
                for (IKBone b = 0; b < IKBone.LastBone; b++)
                {
                    _toHumanBodyBones.Add(QuickUtils.ParseEnum <HumanBodyBones>(b.ToString()));
                }
            }

            return(_toHumanBodyBones[(int)ikBone]);
        }
Exemple #7
0
        public static IKBone ToIKBone(HumanBodyBones boneID)
        {
            if (_toIKBone.Count == 0)
            {
                for (IKBone b = 0; b < IKBone.LastBone; b++)
                {
                    _toIKBone[QuickUtils.ParseEnum <HumanBodyBones>(b.ToString())] = b;
                }
            }

            return(_toIKBone[boneID]);
        }
Exemple #8
0
        public static Dictionary <HumanBodyBones, Vector3> GetLocalPositions(this Animator animator)
        {
            List <HumanBodyBones> bones = QuickUtils.GetEnumValues <HumanBodyBones>();
            Dictionary <HumanBodyBones, Vector3> result = new Dictionary <HumanBodyBones, Vector3>();

            foreach (HumanBodyBones boneID in bones)
            {
                Transform b = animator.GetBoneTransform(boneID);
                result[boneID] = b ? b.localPosition : Vector3.zero;
            }
            return(result);
        }
Exemple #9
0
        protected override void Awake()
        {
            foreach (U u in QuickUtils.GetEnumValues <U>())
            {
                _stringToAxis[u.ToString()] = u;
            }

            foreach (V v in QuickUtils.GetEnumValues <V>())
            {
                _stringToButton[v.ToString()] = v;
            }

            base.Awake();
        }
Exemple #10
0
        private static void Init()
        {
            _allJoints = QuickUtils.ParseEnum <QuickHumanBodyBones, TrackedJointBody>();
            foreach (QuickHumanFingers f in QuickHumanTrait.GetHumanFingers())
            {
                _allJoints.AddRange(QuickHumanTrait.GetBonesFromFinger(f, true));
                _allJoints.AddRange(QuickHumanTrait.GetBonesFromFinger(f, false));
            }

            foreach (TrackedJointBody j in QuickUtils.GetEnumValues <TrackedJointBody>())
            {
                _toTrackedJointBody[QuickUtils.ParseEnum <QuickHumanBodyBones>(j.ToString())] = j;
            }
        }
Exemple #11
0
        protected override IEnumerator CoUpdate()
        {
            if (!QuickUtils.IsInternetConnection())
            {
                _guiCalibration.SetCalibrationInstructions(QuickUserGUICalibration.CalibrationStep.InternetConnectionRequired);

                while (!InputManager.GetButtonDown(InputManager.DEFAULT_BUTTON_CONTINUE))
                {
                    yield return(null);
                }

                QuickUtils.CloseApplication();
            }
        }
        protected virtual void Start()
        {
            StartPlayer();

            if (_hTracking)
            {
                QuickSingletonManager.GetInstance <CameraFade>().SetColor(Color.black);
                StartCoroutine(CoUpdate());
            }
            else
            {
                QuickVRManager.LogError("NO HEAD TRACKING FOUND!!! APPLICATION IS CLOSED");
                QuickUtils.CloseApplication();
            }
        }
Exemple #13
0
        public override string[] GetButtonCodes()
        {
            string[]      sufix = { "Left", "Right" };
            List <string> codes = new List <string>();

            foreach (string s in sufix)
            {
                foreach (ButtonCodes b in QuickUtils.GetEnumValues <ButtonCodes>())
                {
                    codes.Add(b.ToString() + s);
                }
            }

            return(GetCodes(codes));
        }
Exemple #14
0
        protected virtual bool IsSettingBase(string key)
        {
            bool          isBase = false;
            List <string> values = QuickUtils.GetEnumValuesToString <SettingsBase.Key>();

            foreach (string s in values)
            {
                if (s == key)
                {
                    isBase = true;
                    break;
                }
            }

            return(isBase);
        }
        public static T EnumPopup <T>(string label, T value) where T : struct
        {
            string[] values        = QuickUtils.GetEnumValuesToString <T>().ToArray();
            int      selectedIndex = 0;

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] == value.ToString())
                {
                    selectedIndex = i;
                    break;
                }
            }

            return(QuickUtils.ParseEnum <T>(values[EditorGUILayout.Popup(label, selectedIndex, values)]));
        }
        protected virtual void Awake()
        {
            _ovrHandsInitializer = QuickSingletonManager.GetInstance <QuickOVRHandsInitializer>();

            _collider           = transform.GetOrCreateComponent <SphereCollider>();
            _collider.radius    = 0.5f;
            _collider.isTrigger = true;

            _rigidBody             = transform.GetOrCreateComponent <Rigidbody>();
            _rigidBody.isKinematic = true;

            _debugger = transform.CreateChild("__Debugger__");
            _debugger.GetOrCreateComponent <MeshRenderer>().material = Resources.Load <Material>("Materials/QuickDiffuseRed");
            _debugger.GetOrCreateComponent <MeshFilter>().mesh       = QuickUtils.GetUnityPrimitiveMesh(PrimitiveType.Sphere);
            _debugger.gameObject.SetActive(false);
        }
 protected virtual void DrawMethodButtons()
 {
     MethodInfo[] methods = target.GetType().GetMethods();
     if (methods.Length > 0)
     {
         EditorGUILayout.Space();
         foreach (MethodInfo m in methods)
         {
             ButtonMethodAttribute attribute = QuickUtils.GetCustomAttribute <ButtonMethodAttribute>(m);
             if ((attribute != null) && DrawButton(m.Name))
             {
                 QuickUtils.Invoke(target, m.Name);
                 OnButtonMethod(m.Name);
             }
         }
     }
 }
Exemple #18
0
        private static Dictionary <QuickHumanFingers, List <QuickHumanBodyBones> > InitHumanFingers(bool isLeft)
        {
            Dictionary <QuickHumanFingers, List <QuickHumanBodyBones> > result = new Dictionary <QuickHumanFingers, List <QuickHumanBodyBones> >();
            string prefix = isLeft ? "Left" : "Right";

            string[] phalanges = { "Proximal", "Intermediate", "Distal", "Tip" };
            foreach (QuickHumanFingers f in GetHumanFingers())
            {
                result[f] = new List <QuickHumanBodyBones>();
                foreach (string p in phalanges)
                {
                    QuickHumanBodyBones fingerBone = QuickUtils.ParseEnum <QuickHumanBodyBones>(prefix + f.ToString() + p);
                    result[f].Add(fingerBone);
                    _fingerFromBone[fingerBone] = f;
                }
            }

            return(result);
        }
        protected virtual IEnumerator CoUpdate()
        {
            //Check if the game has expired
            bool gameExpired = false;

            if (_useExpirationDate)
            {
                if (!QuickUtils.IsInternetConnection())
                {
                    _guiCalibration.SetCalibrationInstructions(QuickUserGUICalibration.CalibrationStep.InternetConnectionRequired);
                    gameExpired = true;
                }
                else
                {
                    int day, month, year;
                    QuickUtils.GetDateOnline(out day, out month, out year);
                    DateTime timeNow = new DateTime(year, month, day);
                    DateTime timeExp = new DateTime(_expirationYear, _expirationMonth, _expirationDay);
                    if (timeNow >= timeExp)
                    {
                        _guiCalibration.SetCalibrationInstructions(QuickUserGUICalibration.CalibrationStep.TimeExpired);
                        gameExpired = true;
                        QuickVRManager.Log("GAME DATE EXPIRED!!!");
                    }
                }
            }

            if (gameExpired)
            {
                while (!InputManager.GetButtonDown(InputManager.DEFAULT_BUTTON_CONTINUE))
                {
                    yield return(null);
                }

                QuickUtils.CloseApplication();
            }
            else
            {
                //Execute the stagesPre
                _state = State.StagesPre;
                _stagesPre.Init();
            }
        }
Exemple #20
0
        protected virtual void OnControllerUpdate(
            string id,
            int index,
            string handValue,
            bool hasOrientation,
            bool hasPosition,
            Quaternion orientation,
            Vector3 position,
            Vector3 linearAcceleration,
            Vector3 linearVelocity,
            WebXRControllerButton[] buttonValues,
            float[] axesValues)
        {
            object hValue = QuickUtils.ParseEnum(typeof(WebXRControllerHand), handValue.ToUpper());

            if (hValue != null && (WebXRControllerHand)hValue == _controller.hand)
            {
                _buttonValues = buttonValues;
                _axesValues   = axesValues;
            }
        }
Exemple #21
0
        protected virtual void Awake()
        {
            //Create the mesh filter
            MeshFilter mFilter = gameObject.GetOrCreateComponent <MeshFilter>();

            mFilter.mesh        = QuickUtils.CreateFullScreenQuad();
            mFilter.mesh.bounds = new Bounds(Vector3.zero, new Vector3(1000000, 1000000, 1000000));

            //Create the mesh renderer
            MeshRenderer r = gameObject.GetOrCreateComponent <MeshRenderer>();

            r.shadowCastingMode = ShadowCastingMode.Off;
            r.receiveShadows    = false;

            _material  = new Material(Shader.Find("QuickVR/CalibrationScreen"));
            r.material = _material;

            gameObject.layer = LayerMask.NameToLayer("UI");

            SetColor(Color.clear);
        }
Exemple #22
0
        public static void SaveToXml(this ScriptableObject obj, string path)
        {
            if (path.Length == 0)
            {
                return;
            }

            XmlDocument doc        = new XmlDocument();
            XmlElement  nodeFields = doc.AddElement("ClassFields");

            List <FieldInfo> fields = QuickUtils.GetAllFieldsConfigurable(obj.GetType());

            foreach (FieldInfo f in fields)
            {
                XmlElement e = nodeFields.AddElement("Field");
                e.SetAttribute("name", f.Name);
                SaveField(f.GetValue(obj), e);
            }

            doc.Save(path);
        }
Exemple #23
0
        private static object LoadNodeValue(Type valueType, XmlElement nodeField)
        {
            if (valueType == typeof(int))
            {
                return(QuickUtils.ParseInt(nodeField.FirstChild.InnerText));
            }
            else if (valueType == typeof(float))
            {
                return(QuickUtils.ParseFloat(nodeField.FirstChild.InnerText));
            }
            else if (valueType == typeof(string))
            {
                return(nodeField.FirstChild.InnerText);
            }
            else if (valueType == typeof(bool))
            {
                return(QuickUtils.ParseBool(nodeField.FirstChild.InnerText));
            }
            else if (valueType.IsEnum)
            {
                return(QuickUtils.ParseEnum(valueType, nodeField.FirstChild.InnerText));
            }
            else if (IsUnityFloatContainer(valueType))
            {
                return(LoadUnityFloatContainer(valueType, nodeField));
            }
            else if (valueType.IsSubclassOf(typeof(UnityEngine.Object)))
            {
#if UNITY_EDITOR
                string guid      = nodeField.FirstChild.InnerText;
                string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
                return(UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, valueType));
#endif
            }
            //else if (valueType.IsClass) return Activator.CreateInstance(valueType);

            return(null);
        }
Exemple #24
0
        protected virtual void OnEnable()
        {
            //Create the mesh filter
            _mFilter = gameObject.GetOrCreateComponent <MeshFilter>();
            if (!_mFilter.sharedMesh)
            {
                _mFilter.sharedMesh = QuickUtils.CreateFullScreenQuad();
            }

            //Create the mesh renderer
            _renderer = gameObject.GetOrCreateComponent <MeshRenderer>();
            _renderer.receiveShadows = false;

            //Ensure that the renderer has the reflection material.
            string shaderName = GetShaderName();

            if (!_renderer.sharedMaterial || _renderer.sharedMaterial.shader.name != shaderName)
            {
                _renderer.sharedMaterial = new Material(Shader.Find(shaderName));
            }

            QuickMirrorReflectionManager.AddMirror(this);
        }
Exemple #25
0
        protected virtual void Awake()
        {
            Reset();
            CheckPrefabs();
            CheckEventSystem();

            _vrManager            = QuickSingletonManager.GetInstance <QuickVRManager>();
            _xrInteractionManager = QuickSingletonManager.GetInstance <XRInteractionManager>();

            _interactorHandLeft         = transform.CreateChild("__InteractorHandLeft__").GetOrCreateComponent <QuickVRInteractor>();
            _interactorHandLeft._xrNode = XRNode.LeftHand;

            _interactorHandRight         = transform.CreateChild("__InteractorHandRight__").GetOrCreateComponent <QuickVRInteractor>();
            _interactorHandRight._xrNode = XRNode.RightHand;

            //By default, disable all the locomotion providers
            foreach (DefaultLocomotionProvider lProvider in QuickUtils.GetEnumValues <DefaultLocomotionProvider>())
            {
                EnableLocomotionSystem(lProvider, false);
            }

            BaseTeleportationInteractable[] teleportationInteractables = FindObjectsOfType <BaseTeleportationInteractable>();
            foreach (BaseTeleportationInteractable t in teleportationInteractables)
            {
                t.teleportationProvider = _teleportProvider;
            }

            _grabInteractables = new List <XRGrabInteractable>(FindObjectsOfType <XRGrabInteractable>());
            foreach (XRGrabInteractable g in _grabInteractables)
            {
                if (!g.attachTransform)
                {
                    //Try to find the default attach transform
                    g.attachTransform = g.transform.Find(GRAB_PIVOT_NAME);
                }
            }
        }
 public static T GetEnum <T>(string key, T defaultValue = default(T)) where T : struct
 {
     return(QuickUtils.ParseEnum <T>(GetString(key, defaultValue.ToString())));
 }
Exemple #27
0
        protected virtual void WriteGettersAndSetters(List <string> keys, IndentedTextWriter outFile)
        {
            outFile.Indent++;
            outFile.WriteLine("#region GET AND SET");
            outFile.WriteLine();

            foreach (string k in keys)
            {
                System.Type type = System.Type.GetType(QuickPlayerPrefs.GetSetting(k).GetTypeName());
                if (type == null)
                {
                    type = typeof(string);
                }

                string typeName;
                if (type == typeof(string))
                {
                    typeName = "string";
                }
                else if (type == typeof(int))
                {
                    typeName = "int";
                }
                else if (type == typeof(float))
                {
                    typeName = "float";
                }
                else if (type == typeof(bool))
                {
                    typeName = "bool";
                }
                else
                {
                    typeName = QuickUtils.GetTypeFullName(type);
                }

                //The getter
                outFile.WriteLine("public static " + typeName + " Get" + k + "()");
                outFile.WriteLine("{");
                outFile.Indent++;
                if (type == typeof(string))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetString(\"" + k + "\");");
                }
                else if (type == typeof(int))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetInt(\"" + k + "\");");
                }
                else if (type == typeof(float))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetFloat(\"" + k + "\");");
                }
                else if (type == typeof(bool))
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetBool(\"" + k + "\");");
                }
                else if (type.IsEnum)
                {
                    outFile.WriteLine("return QuickPlayerPrefs.GetEnum<" + typeName + ">(\"" + k + "\");");
                }
                outFile.Indent--;
                outFile.WriteLine("}");

                outFile.WriteLine();

                //The setter
                outFile.WriteLine("public static void Set" + k + "(" + typeName + " value)");
                outFile.WriteLine("{");
                outFile.Indent++;
                outFile.WriteLine("QuickPlayerPrefs.SetValue(\"" + k + "\", value);");
                outFile.Indent--;
                outFile.WriteLine("}");

                outFile.WriteLine();
            }

            outFile.WriteLine("#endregion");
            outFile.Indent--;
        }
Exemple #28
0
 protected virtual void LoadRecordFromXML()
 {
     _ikRecord.LoadFromXml(QuickUtils.GetUserFolder() + @"\IkRecording.xml");
 }
Exemple #29
0
 protected virtual void SaveRecordToXML()
 {
     _ikRecord.SaveToXml(QuickUtils.GetUserFolder() + @"\IkRecording.xml");
 }
Exemple #30
0
 protected static void Init()
 {
     _typeList = QuickUtils.ParseEnum <QuickHumanBodyBones, Type>(QuickUtils.GetEnumValues <Type>());
 }