Exemplo n.º 1
0
 public void Update(Renderer renderer, float time, float fadeInDuration, float fadeOutDuration,
                    ProxyNode proxyNode, AffordanceVisibilityDefinition visibilityOverride = null)
 {
     foreach (var kvp in m_MaterialDictionary)
     {
         kvp.Value.Update(renderer, kvp.Key, time, fadeInDuration, fadeOutDuration, proxyNode, visibilityOverride);
     }
 }
Exemplo n.º 2
0
        protected virtual void Awake()
        {
            m_LeftHand  = EditorXRUtils.Instantiate(m_LeftHandProxyPrefab, transform).transform;
            m_RightHand = EditorXRUtils.Instantiate(m_RightHandProxyPrefab, transform).transform;

            m_LeftProxyNode  = m_LeftHand.GetComponent <ProxyNode>();
            m_RightProxyNode = m_RightHand.GetComponent <ProxyNode>();

            m_RayOrigins = new Dictionary <Node, Transform>
            {
                { Node.LeftHand, m_LeftProxyNode.rayOrigin },
                { Node.RightHand, m_RightProxyNode.rayOrigin }
            };

            menuOrigins = new Dictionary <Transform, Transform>()
            {
                { m_LeftProxyNode.rayOrigin, m_LeftProxyNode.menuOrigin },
                { m_RightProxyNode.rayOrigin, m_RightProxyNode.menuOrigin },
            };

            alternateMenuOrigins = new Dictionary <Transform, Transform>()
            {
                { m_LeftProxyNode.rayOrigin, m_LeftProxyNode.alternateMenuOrigin },
                { m_RightProxyNode.rayOrigin, m_RightProxyNode.alternateMenuOrigin },
            };

            previewOrigins = new Dictionary <Transform, Transform>
            {
                { m_LeftProxyNode.rayOrigin, m_LeftProxyNode.previewOrigin },
                { m_RightProxyNode.rayOrigin, m_RightProxyNode.previewOrigin }
            };

            fieldGrabOrigins = new Dictionary <Transform, Transform>
            {
                { m_LeftProxyNode.rayOrigin, m_LeftProxyNode.fieldGrabOrigin },
                { m_RightProxyNode.rayOrigin, m_RightProxyNode.fieldGrabOrigin }
            };

            hidden = true;
        }
Exemplo n.º 3
0
                public void Update(Renderer renderer, Material material, float time, float fadeInDuration, float fadeOutDuration,
                                   ProxyNode proxyNode, AffordanceVisibilityDefinition visibilityOverride)
                {
                    VisibilityState visibilityState = null;
                    var             definition      = visibilityOverride;
                    var             hideTime        = 0f;

                    if (definition == null)
                    {
                        foreach (var kvp in m_AffordanceVisibilityStates)
                        {
                            var state = kvp.Value;
                            if (state.visible)
                            {
                                if (state.hideTime > hideTime)
                                {
                                    definition      = state.definition;
                                    hideTime        = state.visibleDuration > 0 ? state.hideTime : 0;
                                    visibilityState = state;
                                }
                            }
                        }
                    }

                    var visible = definition != null;

                    if (!visible)
                    {
                        foreach (var kvp in m_AffordanceVisibilityStates)
                        {
                            visibilityState = kvp.Value;
                            definition      = visibilityState.definition;
                            break;
                        }
                    }

                    var fadeDuration = visible ? fadeInDuration : fadeOutDuration;

                    switch (definition.visibilityType)
                    {
                    case VisibilityControlType.AlphaProperty:
                        if (visibilityState == null)
                        {
                            var tuple = new Tuple <Material, string>(material, definition.alphaProperty);
                            if (!m_VisibilityStates.TryGetValue(tuple, out visibilityState))
                            {
                                visibilityState           = new VisibilityState(renderer, null, definition, material);
                                m_VisibilityStates[tuple] = visibilityState;
                            }
                        }

                        TransitionUtils.AnimateProperty(time, visible, ref m_WasVisible, ref m_VisibleChangeTime,
                                                        ref m_CurrentColor.a, ref m_StartColor.a, definition.hiddenColor.a, m_OriginalColor.a,
                                                        fadeDuration, Mathf.Approximately, TransitionUtils.GetPercentage, Mathf.Lerp,
                                                        visibilityState.setFloat, false);
                        break;

                    case VisibilityControlType.ColorProperty:
                        if (visibilityState == null)
                        {
                            var tuple = new Tuple <Material, string>(material, definition.alphaProperty);
                            if (!m_VisibilityStates.TryGetValue(tuple, out visibilityState))
                            {
                                visibilityState           = new VisibilityState(renderer, null, definition, material);
                                m_VisibilityStates[tuple] = visibilityState;
                            }
                        }

                        TransitionUtils.AnimateProperty(time, visible, ref m_WasVisible, ref m_VisibleChangeTime,
                                                        ref m_CurrentColor, ref m_StartColor, definition.hiddenColor, m_OriginalColor,
                                                        fadeDuration, TransitionUtils.Approximately, TransitionUtils.GetPercentage, Color.Lerp,
                                                        visibilityState.setColor, false);
                        break;
                    }

                    if (visible != m_WasVisible)
                    {
                        foreach (var kvp in m_AffordanceVisibilityStates)
                        {
                            visibilityState = kvp.Value;
                            if (visibilityState.definition.visibilityType == VisibilityControlType.MaterialSwap)
                            {
                                renderer.sharedMaterials[visibilityState.materialIndex] =
                                    visible ? material : visibilityState.definition.hiddenMaterial;
                            }
                        }
                    }

                    m_WasVisible = visible;

                    if (visible && hideTime > 0 && Time.time > hideTime)
                    {
                        foreach (var kvp in m_AffordanceVisibilityStates)
                        {
                            visibilityState = kvp.Value;
                            var tooltips = visibilityState.tooltips;
                            if (tooltips != null)
                            {
                                foreach (var tooltip in tooltips)
                                {
                                    if (tooltip)
                                    {
                                        proxyNode.HideTooltip(tooltip, true);
                                    }
                                }
                            }

                            proxyNode.SetHighlight(renderer.gameObject, false);

                            visibilityState.visible = false;
                        }
                    }
                }