UnityEditor.ShaderUtil.MaterialsUseInstancingShader C# (CSharp) Method

MaterialsUseInstancingShader() static private method

static private MaterialsUseInstancingShader ( UnityEditor.SerializedProperty materialsArray ) : bool
materialsArray UnityEditor.SerializedProperty
return bool
        internal static bool MaterialsUseInstancingShader(SerializedProperty materialsArray)
        {
            if (!materialsArray.hasMultipleDifferentValues)
            {
                for (int i = 0; i < materialsArray.arraySize; i++)
                {
                    Material objectReferenceValue = materialsArray.GetArrayElementAtIndex(i).objectReferenceValue as Material;
                    if (((objectReferenceValue != null) && (objectReferenceValue.shader != null)) && HasInstancing(objectReferenceValue.shader))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

Usage Example

        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            bool flag = false;
            SerializedProperty serializedProperty = base.serializedObject.FindProperty("m_Materials");

            if (!serializedProperty.hasMultipleDifferentValues)
            {
                MeshFilter component = ((MeshRenderer)base.serializedObject.targetObject).GetComponent <MeshFilter>();
                flag = (component != null && component.sharedMesh != null && serializedProperty.arraySize > component.sharedMesh.subMeshCount);
            }
            EditorGUILayout.PropertyField(this.m_CastShadows, true, new GUILayoutOption[0]);
            bool disabled = SceneView.IsUsingDeferredRenderingPath();

            using (new EditorGUI.DisabledScope(disabled))
            {
                EditorGUILayout.PropertyField(this.m_ReceiveShadows, true, new GUILayoutOption[0]);
            }
            EditorGUILayout.PropertyField(this.m_MotionVectors, true, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Materials, true, new GUILayoutOption[0]);
            if (!this.m_Materials.hasMultipleDifferentValues && flag)
            {
                EditorGUILayout.HelpBox("This renderer has more materials than the Mesh has submeshes. Multiple materials will be applied to the same submesh, which costs performance. Consider using multiple shader passes.", MessageType.Warning, true);
            }
            if (ShaderUtil.MaterialsUseInstancingShader(serializedProperty))
            {
                this.m_GameObjectsSerializedObject.Update();
                if (!this.m_GameObjectStaticFlags.hasMultipleDifferentValues && (this.m_GameObjectStaticFlags.intValue & 4) != 0)
                {
                    EditorGUILayout.HelpBox("This renderer is statically batched and uses an instanced shader at the same time. Instancing will be disabled in such a case. Consider disabling static batching if you want it to be instanced.", MessageType.Warning, true);
                }
            }
            base.RenderProbeFields();
            base.serializedObject.ApplyModifiedProperties();
        }
All Usage Examples Of UnityEditor.ShaderUtil::MaterialsUseInstancingShader