void SaveData()
        {
            var preferences = SerializedPreferencesModule.DeserializePreferences(Core.EditorVR.serializedPreferences);

            if (preferences == null)
            {
                return;
            }

            var items = preferences.items;

            foreach (var kvp in m_SerializedFeedback)
            {
                items[kvp.Key].payload = JsonUtility.ToJson(kvp.Value);
            }

            Core.EditorVR.serializedPreferences = JsonUtility.ToJson(preferences);
        }
        static void ClearData()
        {
            var preferences = SerializedPreferencesModule.DeserializePreferences(Core.EditorVR.serializedPreferences);

            if (preferences == null)
            {
                return;
            }

            foreach (var kvp in new Dictionary <Type, SerializedPreferencesModule.SerializedPreferenceItem>(preferences.items))
            {
                var type = kvp.Key;
                if (typeof(TwoHandedProxyBase).IsAssignableFrom(type))
                {
                    preferences.Remove(type);
                }
            }

            Core.EditorVR.serializedPreferences = JsonUtility.ToJson(preferences);
        }
        void Refresh()
        {
            m_SerializedFeedback.Clear();
            var preferences = SerializedPreferencesModule.DeserializePreferences(Core.EditorVR.serializedPreferences);

            if (preferences == null)
            {
                return;
            }

            foreach (var kvp in preferences.items)
            {
                var type = kvp.Key;
                if (typeof(TwoHandedProxyBase).IsAssignableFrom(type))
                {
                    var  item        = kvp.Value;
                    Type payloadType = null;
                    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        payloadType = assembly.GetType(item.payloadType);
                        if (payloadType != null)
                        {
                            break;
                        }
                    }

                    if (payloadType == null)
                    {
                        continue;
                    }

                    var payload = (SerializedProxyFeedback)JsonUtility.FromJson(item.payload, payloadType);
                    m_SerializedFeedback[kvp.Key] = payload;
                }
            }
        }
Exemple #4
0
        void OnProxyActiveChanged(IProxy proxy)
        {
            proxy.hidden = !proxy.active;

            if (proxy.active)
            {
                var deviceData = m_ToolModule.deviceData;
                if (!deviceData.Any(dd => dd.proxy == proxy))
                {
                    var moduleLoaderCore = ModuleLoaderCore.instance;
                    var keyboardModule   = moduleLoaderCore.GetModule <KeyboardModule>();
                    var highlightModule  = moduleLoaderCore.GetModule <HighlightModule>();
                    foreach (var rayOriginPair in proxy.rayOrigins)
                    {
                        var node      = rayOriginPair.Key;
                        var rayOrigin = rayOriginPair.Value;

                        var systemDevices = m_DeviceInputModule.GetSystemDevices();
                        for (int j = 0; j < systemDevices.Count; j++)
                        {
                            var device = systemDevices[j];

                            // Find device tagged with the node that matches this RayOrigin node
                            var deviceNode = m_DeviceInputModule.GetDeviceNode(device);
                            if (deviceNode == node)
                            {
                                var newDeviceData = new DeviceData();
                                deviceData.Add(newDeviceData);
                                newDeviceData.proxy       = proxy;
                                newDeviceData.node        = node;
                                newDeviceData.rayOrigin   = rayOrigin;
                                newDeviceData.inputDevice = device;

                                if (!this.HasProvider <IProvidesAddRaycastSource>())
                                {
                                    continue;
                                }

                                // Add RayOrigin transform, proxy and ActionMapInput references to input module list of sources
                                this.AddRaycastSource(proxy, node, rayOrigin, source =>
                                {
                                    // Do not invalidate UI raycasts in the middle of a drag operation
                                    var eventData = source.eventData;
                                    if (!eventData.pointerDrag)
                                    {
                                        var sourceRayOrigin = source.rayOrigin;
                                        if (m_DirectSelectionModule != null && m_DirectSelectionModule.IsHovering(sourceRayOrigin))
                                        {
                                            return(false);
                                        }

                                        var currentRaycast = eventData.pointerCurrentRaycast;
                                        var hoveredObject  = currentRaycast.gameObject;

                                        // The manipulator needs rays to go through scene objects in order to work
                                        var isManipulator = hoveredObject && hoveredObject.GetComponentInParent <IManipulator>() != null;
                                        float sceneObjectDistance;
                                        var raycastObject = m_IntersectionModule.GetFirstGameObject(sourceRayOrigin, out sceneObjectDistance);
                                        var uiDistance    = currentRaycast.distance;

                                        // If the distance to a scene object is less than the distance to the hovered UI, invalidate the UI raycast
                                        if (!isManipulator && raycastObject && sceneObjectDistance < uiDistance && !ignoreList.Contains(raycastObject))
                                        {
                                            return(false);
                                        }
                                    }

                                    if (m_MenuModule != null && !m_MenuModule.IsValidHover(source))
                                    {
                                        return(false);
                                    }

                                    // Proceed only for raycast sources that haven't been blocked via IBlockUIInteraction
                                    if (source.blocked)
                                    {
                                        return(false);
                                    }

                                    return(true);
                                });
                            }
                        }

                        rayOrigin.name = string.Format("{0} Ray Origin", node);
                        var rayTransform = EditorXRUtils.Instantiate(m_ProxyRayPrefab.gameObject, rayOrigin, false).transform;
                        rayTransform.position = rayOrigin.position;
                        rayTransform.rotation = rayOrigin.rotation;
                        var dpr = rayTransform.GetComponent <DefaultProxyRay>();
                        this.InjectFunctionalitySingle(dpr);
                        m_DefaultRays.Add(rayOrigin, dpr);
                        if (highlightModule != null)
                        {
                            dpr.SetColor(highlightModule.highlightColor);
                            highlightModule.AddRayOriginForNode(node, rayOrigin);
                        }

                        if (keyboardModule != null)
                        {
                            keyboardModule.SpawnKeyboardMallet(rayOrigin);
                        }

                        var proxyExtras = m_ProxyExtras;
                        if (proxyExtras)
                        {
                            var extraData = proxyExtras.data;
                            List <GameObject> prefabs;
                            if (extraData.TryGetValue(rayOriginPair.Key, out prefabs))
                            {
                                foreach (var prefab in prefabs)
                                {
                                    var go = this.InstantiateUI(prefab);
                                    go.transform.SetParent(rayOriginPair.Value, false);
                                }
                            }
                        }

                        var tester = rayOriginPair.Value.GetComponentInChildren <IntersectionTester>();
                        tester.active = proxy.active;
                        m_IntersectionModule.AddTester(tester);

                        if (m_WorkspaceModule != null)
                        {
                            switch (node)
                            {
                            case Node.LeftHand:
                                m_WorkspaceModule.leftRayOrigin = rayOrigin;
                                break;

                            case Node.RightHand:
                                m_WorkspaceModule.rightRayOrigin = rayOrigin;
                                break;
                            }
                        }
                    }

                    if (m_ToolModule != null)
                    {
                        m_ToolModule.SpawnDefaultTools(proxy);
                    }

                    if (m_SerializedPreferences != null)
                    {
                        m_SerializedPreferences.DeserializePreferences();
                    }

                    if (m_WorkspaceModule != null)
                    {
                        m_WorkspaceModule.CreateSerializedWorkspaces();
                    }
                }
            }
        }