Esempio n. 1
0
        void OnVREvent(VREvent e)
        {
            // only respond to tracker move events
            if ((e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "TrackerMove"))
            {
                string trackerName = e.Name.Remove(e.Name.IndexOf("_Move"), 5);
                if (!trackersToIgnore.Contains(trackerName))
                {
                    float[]    data = e.GetFloatArrayData("Transform");
                    Matrix4x4  m    = VRConvert.ToMatrix4x4(data);
                    Vector3    pos  = m.GetTranslation();
                    Quaternion rot  = m.GetRotation();

                    if (!cursors.ContainsKey(trackerName))
                    {
                        GameObject newCursorObj = Instantiate(cursorPrefab);
                        TextMesh   label        = newCursorObj.GetComponentInChildren <TextMesh>();
                        if (label != null)
                        {
                            label.text = trackerName;
                        }
                        cursors[trackerName] = newCursorObj;
                    }
                    GameObject cursorObj = cursors[trackerName];
                    cursorObj.transform.position = pos;
                    cursorObj.transform.rotation = rot;
                }
            }
        }
Esempio n. 2
0
        private void ProcessCallbacks(VREvent e)
        {
            // These "unfiltered" callbacks are called for every event
            for (int ucb = 0; ucb < genericCallbacksUnfiltered.Count; ucb++)
            {
                genericCallbacksUnfiltered[ucb].Invoke(e);
            }


            // These callbacks are passed the enitre event data structure, which can really contain anything.
            if (genericCallbacks.ContainsKey(e.Name))
            {
                for (int cb = 0; cb < genericCallbacks[e.Name].Count; cb++)
                {
                    genericCallbacks[e.Name][cb].Invoke(e);
                }
            }


            // For these callbacks, we know the type of data, so we pull it out of the dataindex here to
            // make it a bit easier for the user.

            if ((analogCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "AnalogUpdate"))
            {
                for (int cb = 0; cb < analogCallbacks[e.Name].Count; cb++)
                {
                    analogCallbacks[e.Name][cb].Invoke(e.GetFloatData("AnalogValue"));
                }
            }

            if ((buttonDownCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                ((e.GetStringData("EventType") == "ButtonDown") || (e.GetStringData("EventType") == "ButtonTouch")))
            {
                for (int cb = 0; cb < buttonDownCallbacks[e.Name].Count; cb++)
                {
                    buttonDownCallbacks[e.Name][cb].Invoke();
                }
            }

            if ((buttonUpCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                ((e.GetStringData("EventType") == "ButtonUp") || (e.GetStringData("EventType") == "ButtonUntouch")))
            {
                for (int cb = 0; cb < buttonUpCallbacks[e.Name].Count; cb++)
                {
                    buttonUpCallbacks[e.Name][cb].Invoke();
                }
            }

            if ((cursorCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "CursorMove"))
            {
                float[] pos  = e.GetFloatArrayData("Position");
                float[] npos = e.GetFloatArrayData("NormalizedPosition");
                for (int cb = 0; cb < cursorCallbacks[e.Name].Count; cb++)
                {
                    cursorCallbacks[e.Name][cb].Invoke(new Vector3(pos[0], pos[1], pos[2]), new Vector3(npos[0], npos[1], npos[2]));
                }
            }

            if ((trackerCallbacks.ContainsKey(e.Name)) &&
                (e.ContainsStringField("EventType")) &&
                (e.GetStringData("EventType") == "TrackerMove"))
            {
                float[]    data = e.GetFloatArrayData("Transform");
                Matrix4x4  m    = VRConvert.ToMatrix4x4(data);
                Vector3    pos  = m.GetTranslation();
                Quaternion rot  = m.GetRotation();
                for (int cb = 0; cb < trackerCallbacks[e.Name].Count; cb++)
                {
                    trackerCallbacks[e.Name][cb].Invoke(pos, rot);
                }
            }
        }