Beispiel #1
0
        public override void CognitiveVR_Init(Error initError)
        {
            base.CognitiveVR_Init(initError);

            SteamVR_TrackedController controller;

            for (int i = 0; i < 2; i++)
            {
                //TODO run this when a controller becomes active, not just on Init
                if (CognitiveVR_Manager.GetController(i) == null)
                {
                    continue;
                }
                controller = CognitiveVR_Manager.GetController(i).GetComponent <SteamVR_TrackedController>();

                if (controller == null)
                {
                    controller = CognitiveVR_Manager.GetController(i).gameObject.AddComponent <SteamVR_TrackedController>();
                }

                controller.TriggerClicked   += new ClickedEventHandler(OnTriggerClicked);
                controller.TriggerUnclicked += new ClickedEventHandler(OnTriggerUnclicked);
                controller.Gripped          += new ClickedEventHandler(OnGripped);
                controller.Ungripped        += new ClickedEventHandler(OnUngripped);
                controller.PadClicked       += new ClickedEventHandler(OnPadClicked);
            }
        }
Beispiel #2
0
        void Start()
        {
            if (instance != null && instance != this)
            {
                Destroy(gameObject); return;
            }
            instance = this;

            CognitiveVR.InitParams initParams = CognitiveVR.InitParams.create
                                                (
                customerId: CognitiveVR_Preferences.Instance.CustomerID,
                logEnabled: false,
                userInfo: GetUniqueEntityID()
                                                );
            CognitiveVR.Core.init(initParams, InitEvent);

            GameObject.DontDestroyOnLoad(gameObject);

            playerSnapshotInverval = new WaitForSeconds(CognitiveVR.CognitiveVR_Preferences.Instance.SnapshotInterval);
            StartCoroutine(Tick());

            GetController(0);

#if CVR_STEAMVR
            SteamVR_Utils.Event.Listen("new_poses", PoseUpdateEvent);
#endif

#if UNITY_5_4
            UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_SceneLoaded;
#endif
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            CognitiveVR_Manager m = (CognitiveVR_Manager)target;

            EditorGUILayout.HelpBox("Persists between scenes\nInitializes cognitiveVR Analytics\nGathers basic device info", MessageType.Info);
        }
Beispiel #4
0
        /// <summary>
        /// sets instance of CognitiveVR_Manager
        /// </summary>
        private void OnEnable()
        {
            if (instance != null && instance != this)
            {
                Destroy(gameObject);
                return;
            }
            if (instance == this)
            {
                return;
            }
            instance = this;

            CognitiveVR.NetworkManager.InitLocalStorage(System.Environment.NewLine);
        }
        private void OnEnable()
        {
            if (instance != null && instance != this)
            {
                Destroy(gameObject);
                return;
            }

            instance = this;

            //TODO expose this value to initialize a pool when writing lots of dynamic objects
            for (int i = 0; i < 100; i++)
            {
                DynamicObjectSnapshot.snapshotQueue.Enqueue(new DynamicObjectSnapshot());
            }
        }
 /// <summary>
 /// sets instance of CognitiveVR_Manager
 /// </summary>
 private void OnEnable()
 {
     if (instance != null && instance != this)
     {
         Destroy(gameObject);
         return;
     }
     if (instance == this)
     {
         return;
     }
     instance = this;
     if (InitializeOnStart && StartupDelayTime == 0)
     {
         GameObject.DontDestroyOnLoad(gameObject);
         Initialize("");
     }
 }
Beispiel #7
0
        private void CognitiveVR_Manager_OnTick()
        {
            if (CognitiveVR_Manager.GetController(0) == null)
            {
                return;
            }

            if (samples < sampleCount)
            {
                maxSqrDistance = Mathf.Max(Vector3.SqrMagnitude(CognitiveVR_Manager.GetController(0).position - CognitiveVR_Manager.HMD.position));

                samples++;
                if (samples >= sampleCount)
                {
                    Util.logDebug("arm length " + maxSqrDistance);
                    Instrumentation.updateUserState(new Dictionary <string, object> {
                        { "armlength", Mathf.Sqrt(maxSqrDistance) }
                    });
                    CognitiveVR_Manager.OnTick -= CognitiveVR_Manager_OnTick;
                }
            }
        }
        private void CognitiveVR_Manager_OnTick()
        {
            bool hit;

            if (CognitiveVR_Manager.GetController(0) != null)
            {
                hit = Physics.CheckSphere(CognitiveVR_Manager.GetController(0).position, 0.25f, CognitiveVR_Preferences.Instance.CollisionLayerMask);
                if (hit && string.IsNullOrEmpty(controller0GUID))
                {
                    Util.logDebug("controller collision");
                    controller0GUID = System.Guid.NewGuid().ToString();
                    Instrumentation.Transaction("collision", controller0GUID).setProperty("device", "controller 0").begin();
                }
                else if (!hit && !string.IsNullOrEmpty(controller0GUID))
                {
                    Instrumentation.Transaction("collision", controller0GUID).end();
                    controller0GUID = string.Empty;
                }
            }

            if (CognitiveVR_Manager.GetController(1) != null)
            {
                hit = Physics.CheckSphere(CognitiveVR_Manager.GetController(1).position, 0.25f, CognitiveVR_Preferences.Instance.CollisionLayerMask);
                if (hit && string.IsNullOrEmpty(controller1GUID))
                {
                    Util.logDebug("controller collision");
                    controller1GUID = System.Guid.NewGuid().ToString();
                    Instrumentation.Transaction("collision", controller1GUID).setProperty("device", "controller 1").begin();
                }
                else if (!hit && !string.IsNullOrEmpty(controller1GUID))
                {
                    Instrumentation.Transaction("collision", controller1GUID).end();
                    controller1GUID = string.Empty;
                }
            }
        }
        public void OnGUI()
        {
            GUI.skin.label.wordWrap  = true;
            GUI.skin.label.alignment = TextAnchor.UpperLeft;

            CognitiveVR_Manager manager = FindObjectOfType <CognitiveVR_Manager>();

            //==============
            //component list
            //==============

            GetAnalyticsComponentTypes();

            canvasPos = GUILayout.BeginScrollView(canvasPos, false, true);
            EditorGUI.BeginDisabledGroup(manager == null);

            if (manager == null)
            {
                GUI.color = new Color(0.5f, 0.5f, 0.5f);
                GUI.Box(new Rect(canvasPos.x, canvasPos.y, position.width, position.height), "");
                GUI.color = new Color(0.7f, 0.7f, 0.7f);
            }

            bool displayedFirstComponent = false;

            foreach (var v in childTypes)
            {
                GUILayout.Space(10);
                if (displayedFirstComponent)
                {
                    GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
                }
                else
                {
                    displayedFirstComponent = true;
                }
                TogglableComponent(manager, v);
            }
            GUI.color = Color.white;
            EditorGUI.EndDisabledGroup();
            GUILayout.EndScrollView();



            //==============
            //footer
            //==============

            GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });

            //add/select manager
            if (manager == null)
            {
                if (GUILayout.Button(new GUIContent("Add CognitiveVR Manager", "Does not Destroy on Load\nInitializes analytics system with basic device info"), GUILayout.Height(40)))
                {
                    string             sampleResourcePath = GetSamplesResourcePath();
                    UnityEngine.Object basicInit          = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(sampleResourcePath + "CognitiveVR/Resources/CognitiveVR_Manager.prefab");
                    if (basicInit)
                    {
                        Selection.activeGameObject = PrefabUtility.InstantiatePrefab(basicInit) as GameObject;
                    }
                    else
                    {
                        Debug.LogWarning("Couldn't find CognitiveVR_Manager.prefab");
                        GameObject go = new GameObject("CognitiveVR_Manager");
                        manager = go.AddComponent <CognitiveVR_Manager>();
                        Selection.activeGameObject = go;
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Select CognitiveVR Manager", GUILayout.Height(40)))
                {
                    Selection.activeGameObject = manager.gameObject;
                }
            }

            //add/remove all
            EditorGUI.BeginDisabledGroup(manager == null);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Add All", GUILayout.MaxWidth(position.width / 2)))
            {
                foreach (var component in childTypes)
                {
                    if (!manager.GetComponent(component))
                    {
                        manager.gameObject.AddComponent(component);
                    }
                }
            }

            if (GUILayout.Button("Remove All", GUILayout.MaxWidth(position.width / 2)))
            {
                foreach (var component in childTypes)
                {
                    if (manager.GetComponent(component))
                    {
                        DestroyImmediate(manager.GetComponent(component));
                    }
                }
            }

            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            //close

            GUILayout.Space(20);

            if (GUILayout.Button("Close"))
            {
                Close();
            }
        }
        void TogglableComponent(CognitiveVR_Manager manager, System.Type componentType)
        {
            Component component = null;

            if (manager != null)
            {
                component = manager.GetComponent(componentType);
            }

            GUILayout.BeginHorizontal();

            string prettyName = componentType.Name;

            if (prettyName.Contains("Tracker"))
            {
                prettyName = prettyName.Replace("Tracker", "");
            }
            GUI.skin.toggle.richText = true;

            /*string supportedPlatforms = "";
             * MethodInfo getPlatforms = componentType.GetMethod("GetPlatforms");
             * if (getPlatforms != null)
             * {
             *  var platforms = getPlatforms.Invoke(null, null) as string[];
             *  if (platforms != null)
             *  {
             *      for(int i = 0; i<platforms.Length; i++)
             *      {
             *          supportedPlatforms += platforms[i] + ", ";
             *      }
             *      if (supportedPlatforms.Length > 0)
             *      {
             *          supportedPlatforms = supportedPlatforms.Remove(supportedPlatforms.Length - 2);
             *      }
             *  }
             * }*/

            bool b = GUILayout.Toggle(component != null, "<size=14><b>" + prettyName + "</b></size>");

            if (b != (component != null))
            {
                if (component == null)
                {
                    manager.gameObject.AddComponent(componentType);
                }
                else
                {
                    DestroyImmediate(component);
                }
            }

            if (GUILayout.Button("Open Script", GUILayout.Width(100)))
            {
                //temporarily add script, open from component, remove component
                var tempComponent = manager.gameObject.AddComponent(componentType);
                AssetDatabase.OpenAsset(MonoScript.FromMonoBehaviour(tempComponent as MonoBehaviour));
                DestroyImmediate(tempComponent);
            }

            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();

            if (component != null)
            {
                GUI.backgroundColor = Green;
                MethodInfo warningInfo = componentType.GetMethod("GetWarning");
                if (warningInfo != null)
                {
                    var v = warningInfo.Invoke(null, null);
                    if (v != null && (bool)v == true)
                    {
                        GUI.backgroundColor = Orange;
                    }
                }
            }

            MethodInfo info = componentType.GetMethod("GetDescription");

            if (info == null)
            {
                GUILayout.Box("No description\nAdd a description by implementing 'public static string GetDescription()'", new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
            }
            else
            {
                var v = info.Invoke(null, null);
                GUILayout.Box((string)v, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
            }

            GUI.backgroundColor = Color.white;

            GUILayout.EndHorizontal();
        }