예제 #1
0
        void MaterialPropertyGUI(MaterialCache materialCache, ExternalObjectCache externalObjectCache)
        {
            GUIContent nameLabel = EditorGUIUtility.TextContent(materialCache.name);

            nameLabel.tooltip = materialCache.name;

            EditorGUI.BeginChangeCheck();

            SerializedProperty property = externalObjectCache.property;

            EditorGUILayout.PropertyField(property, nameLabel, false);
            Material material = property.objectReferenceValue != null ? property.objectReferenceValue as Material : null;

            if (EditorGUI.EndChangeCheck())
            {
                if (material == null)
                {
                    m_ExternalObjects.DeleteArrayElementAtIndex(externalObjectCache.propertyIdx);
                }
                else
                {
                    var pair = m_ExternalObjects.GetArrayElementAtIndex(externalObjectCache.propertyIdx);
                    pair.FindPropertyRelative("second").objectReferenceValue = material;
                }

                BuildExternalObjectsCache();
            }
        }
        void MaterialPropertyGUI(MaterialCache materialCache, ExternalObjectCache externalObjectCache)
        {
            GUIContent nameLabel = EditorGUIUtility.TextContent(materialCache.name);

            nameLabel.tooltip = materialCache.name;

            EditorGUI.BeginChangeCheck();

            SerializedProperty property = externalObjectCache.property;
            var previousMaterial        = property.objectReferenceValue as Material;

            EditorGUILayout.ObjectField(property, typeof(Material), nameLabel);
            Material material = property.objectReferenceValue as Material;

            if (EditorGUI.EndChangeCheck())
            {
                if (material == null)
                {
                    m_ExternalObjects.DeleteArrayElementAtIndex(externalObjectCache.propertyIdx);
                    BuildExternalObjectsCache();
                }
                else
                {
                    var importer = target as ModelImporter;
                    if (AssetDatabase.GetAssetPath(material) == importer.assetPath)
                    {
                        Debug.LogError(string.Format("{0} is a sub-asset of {1} and cannot be used as an external material.", material.name, Path.GetFileName(importer.assetPath)));
                        property.objectReferenceValue = previousMaterial;
                    }
                    else
                    {
                        var pair = m_ExternalObjects.GetArrayElementAtIndex(externalObjectCache.propertyIdx);
                        pair.FindPropertyRelative("second").objectReferenceValue = material;
                        BuildExternalObjectsCache();
                    }
                }

                EvaluateMaterialExtractionState();
            }
        }
예제 #3
0
        private void BuildExternalObjectsCache()
        {
            // do not set if multiple selection.
            if (m_ExternalObjects.hasMultipleDifferentValues)
            {
                return;
            }

            m_ExternalObjectsCache.Clear();
            for (int externalObjectIdx = 0, count = m_ExternalObjects.arraySize; externalObjectIdx < count; ++externalObjectIdx)
            {
                var pair = m_ExternalObjects.GetArrayElementAtIndex(externalObjectIdx);

                var cachedObject = new ExternalObjectCache();
                cachedObject.property    = pair.FindPropertyRelative("second");
                cachedObject.propertyIdx = externalObjectIdx;

                var externalName = pair.FindPropertyRelative("first.name").stringValue;
                var externalType = pair.FindPropertyRelative("first.type").stringValue;

                m_ExternalObjectsCache.Add(new Tuple <string, string>(externalName, externalType), cachedObject);
            }
        }