Example #1
0
        public virtual IEnumerator Start()
        {
            // In standalone play-mode usage, attempt to get the TrackedObjectInput
            if (trackedObjectInput == null && m_PlayerInput)
            {
                trackedObjectInput = m_PlayerInput.GetActions <TrackedObject>();
            }

            List <Renderer> renderers = new List <Renderer>();

            while (renderers.Count == 0)
            {
                yield return(null);

                foreach (var meshRoot in m_ProxyMeshRoots)
                {
                    // Only add models of the device and not anything else that is spawned underneath the hand (e.g. menu button, cone/ray)
                    renderers.AddRange(meshRoot.GetComponentsInChildren <Renderer>());
                }
            }

            foreach (var r in renderers)
            {
                m_Materials.AddRange(MaterialUtils.CloneMaterials(r));
            }

            // Move controllers up into EVR range, so they render properly over our UI (e.g. manipulators)
            foreach (var m in m_Materials)
            {
                m.renderQueue = k_RendererQueue;
            }
        }
        void Awake()
        {
            m_ScaleBumps[typeof(LinearHandle)] = m_LinearHandleScaleBump;
            m_ScaleBumps[typeof(PlaneHandle)]  = m_PlaneHandleScaleBump;
            m_ScaleBumps[typeof(SphereHandle)] = m_SphereHandleScaleBump;

            foreach (var handle in m_AllHandles)
            {
                MaterialUtils.CloneMaterials(handle.GetComponent <Renderer>());

                handle.hoverStarted += OnHandleHoverStarted;
                handle.hovering     += OnHandleHovering;
                handle.hoverEnded   += OnHandleHoverEnded;

                handle.dragStarted += OnHandleDragStarted;
                handle.dragging    += OnHandleDragging;
                handle.dragEnded   += OnHandleDragEnded;
            }
        }
Example #3
0
        internal static Material AssignShader(GameObject go, AssetData data)
        {
            var renderer = go.GetComponent <Renderer>();

            if (renderer != null)
            {
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(go, k_AssignMaterialUndo);
#endif

                // copy the material before applying shader to the instance
                // this prevents the warning about leaking materials
                var materialCopy = MaterialUtils.CloneMaterials(renderer)[0];
                var shader       = (Shader)data.asset;
                materialCopy.shader     = shader;
                renderer.sharedMaterial = materialCopy;

                activeMaterialClones.Add(materialCopy);
                return(materialCopy);
            }

            return(null);
        }
Example #4
0
        void Awake()
        {
            // Don't allow setup if affordances are invalid
            if (m_Affordances == null || m_Affordances.Length == 0)
            {
                Debug.LogError("Affordances invalid when attempting to setup ProxyUI on : " + gameObject.name);
                return;
            }

            // Prevent further setup if affordance map isn't assigned
            if (m_AffordanceMap == null)
            {
                Debug.LogError("A valid Affordance Map must be present when setting up ProxyUI on : " + gameObject.name);
                return;
            }

            var affordanceDefinitions    = new AffordanceDefinition[m_Affordances.Length];
            var affordanceMapDefinitions = m_AffordanceMap.AffordanceDefinitions;
            var defaultAffordanceVisibilityDefinition = m_AffordanceMap.defaultAffordanceVisibilityDefinition;
            var defaultAffordanceAnimationDefinition  = m_AffordanceMap.defaultAnimationDefinition;

            for (var i = 0; i < m_Affordances.Length; i++)
            {
                var            affordance      = m_Affordances[i];
                var            renderer        = affordance.renderer;
                var            sharedMaterials = renderer.sharedMaterials;
                AffordanceData affordanceData;
                if (!m_AffordanceData.TryGetValue(renderer, out affordanceData))
                {
                    MaterialUtils.CloneMaterials(renderer); // Clone all materials associated with each renderer once
                    affordanceData             = new AffordanceData();
                    m_AffordanceData[renderer] = affordanceData;

                    // Clones that utilize the standard shader can lose their enabled ZWrite value (1), if it was enabled on the material
                    foreach (var material in sharedMaterials)
                    {
                        material.SetFloat(k_ZWritePropertyName, 1);
                    }
                }

                var control    = affordance.control;
                var definition = affordanceMapDefinitions.FirstOrDefault(x => x.control == control);
                if (definition == null)
                {
                    definition = new AffordanceDefinition
                    {
                        control = control,
                        visibilityDefinition = defaultAffordanceVisibilityDefinition,
                        animationDefinition  = defaultAffordanceAnimationDefinition
                    };
                }

                affordanceDefinitions[i] = definition;
                affordanceData.AddAffordance(affordance, definition.visibilityDefinition);
            }

            foreach (var kvp in m_AffordanceData)
            {
                kvp.Key.AddMaterial(m_ProxyBackgroundMaterial);
            }

            var bodyRenderers = GetComponentsInChildren <Renderer>(true)
                                .Where(x => !m_AffordanceData.ContainsKey(x) && !IsChildOfProxyOrigin(x.transform)).ToList();

            var bodyAffordanceDefinition = new AffordanceDefinition
            {
                visibilityDefinition = m_AffordanceMap.bodyVisibilityDefinition
            };

            foreach (var renderer in bodyRenderers)
            {
                MaterialUtils.CloneMaterials(renderer);
                var affordanceData = new AffordanceData();
                m_BodyData.Add(new Tuple <Renderer, AffordanceData>(renderer, affordanceData));
                affordanceData.AddRenderer(renderer, bodyAffordanceDefinition.visibilityDefinition);
                renderer.AddMaterial(m_ProxyBackgroundMaterial);
            }

            if (m_ProxyAnimator)
            {
                m_ProxyAnimator.Setup(affordanceDefinitions, m_Affordances);
            }
        }