コード例 #1
0
        internal MaterialHierarchyPopup(Object[] targets, bool enabled, MaterialEditor materialEditor, Rect activatorRect)
        {
            this.enabled        = enabled;
            this.materialEditor = materialEditor;
            target     = targets[0] as Material;
            targetGUID = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(target));

            targetPositionY = singleLinePositionY = GUIUtility.GUIToScreenRect(activatorRect).yMax;
            if (target.isVariant || materialEditor.convertState == ConvertAction.Convert)
            {
                singleLinePositionY -= k_PositionShiftY;
            }

            k_MinNameWidth = k_MinWindowWidth - (k_TitleWidth + k_SplitWidth + k_OverridesWidth + k_LocksWidth);

            searchFilter = new SearchFilter()
            {
                classNames = new string[] { "Material" },
                searchArea = SearchFilter.SearchArea.AllAssets
            };
            debounce = Delayer.Debounce(_ =>
            {
                SearchFilterChanged();
                editorWindow.Repaint();
            });

            Init();
        }
コード例 #2
0
        static bool AnyTargetMaterialHasChildren(string[] targetPaths)
        {
            GUID[] guids = targetPaths.Select(path => AssetDatabase.GUIDFromAssetPath(path)).ToArray();

            Func <string, bool> HasChildrenInPath = (string rootPath) => {
                var property = new HierarchyProperty(rootPath, false);
                property.SetSearchFilter(new SearchFilter {
                    classNames = new string[] { "Material" }, searchArea = SearchFilter.SearchArea.AllAssets
                });
                while (property.Next(null))
                {
                    GUID parent;
                    var  child = InternalEditorUtility.GetLoadedObjectFromInstanceID(property.GetInstanceIDIfImported()) as Material;
                    if (child)
                    {
                        if (AssetDatabase.IsForeignAsset(child))
                        {
                            continue;
                        }
                        parent = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(child.parent));
                    }
                    else
                    {
                        var path = AssetDatabase.GUIDToAssetPath(property.guid);
                        if (!path.EndsWith(".mat", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        parent = EditorMaterialUtility.GetMaterialParentFromFile(path);
                    }

                    for (int i = 0; i < guids.Length; i++)
                    {
                        if (guids[i] == parent)
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            };

            if (HasChildrenInPath("Assets"))
            {
                return(true);
            }
            foreach (var package in PackageManagerUtilityInternal.GetAllVisiblePackages(false))
            {
                if (package.source == PackageManager.PackageSource.Local && HasChildrenInPath(package.assetPath))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        static void ReparentMaterialChildren(string assetPath)
        {
            var toDelete     = AssetDatabase.LoadAssetAtPath <Material>(assetPath);
            var toDeleteGUID = AssetDatabase.GUIDFromAssetPath(assetPath);
            var newParent    = toDelete.parent;

            Action <string> ReparentInPath = (string rootPath) => {
                var property = new HierarchyProperty(rootPath, false);
                property.SetSearchFilter(new SearchFilter {
                    classNames = new string[] { "Material" }, searchArea = SearchFilter.SearchArea.AllAssets
                });
                while (property.Next(null))
                {
                    var child = InternalEditorUtility.GetLoadedObjectFromInstanceID(property.GetInstanceIDIfImported()) as Material;
                    if (!child)
                    {
                        // First check guid from file to avoid loading all materials in memory
                        string path = AssetDatabase.GUIDToAssetPath(property.guid);
                        if (EditorMaterialUtility.GetMaterialParentFromFile(path) != toDeleteGUID)
                        {
                            continue;
                        }
                        child = AssetDatabase.LoadAssetAtPath <Material>(path);
                    }
                    if (child != null && child.parent == toDelete && !AssetDatabase.IsForeignAsset(child))
                    {
                        child.parent = newParent;
                    }
                }
            };

            ReparentInPath("Assets");
            foreach (var package in PackageManagerUtilityInternal.GetAllVisiblePackages(false))
            {
                if (package.source == PackageManager.PackageSource.Local)
                {
                    ReparentInPath(package.assetPath);
                }
            }
        }
コード例 #4
0
        internal MaterialHierarchyPopup(Material target, bool enabled, MaterialEditor materialEditor, Rect activatorRect)
        {
            this.enabled        = enabled;
            this.materialEditor = materialEditor;
            this.target         = target;
            targetGUID          = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(target));

            k_MinNameWidth = k_MinWindowWidth - (k_TitleWidth + k_SplitWidth + k_OverridesWidth + k_LocksWidth);

            searchFilter = new SearchFilter()
            {
                classNames = new string[] { "Material" },
                searchArea = SearchFilter.SearchArea.AllAssets
            };
            debounce = Delayer.Debounce(_ =>
            {
                SearchFilterChanged();
                editorWindow.Repaint();
            });

            Init();
        }
コード例 #5
0
        internal MaterialHierarchyPopup(Object[] targets)
        {
            this.targets = targets;
            target       = targets[0] as Material;
            targetGUID   = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(target));

            k_MinNameWidth = k_MinWindowWidth - (k_TitleWidth + k_SplitWidth + k_OverridesWidth + k_LocksWidth);
            k_MaxNameWidth = k_MaxWindowWidth - (k_TitleWidth + k_SplitWidth + k_OverridesWidth + k_LocksWidth);

            convertState = ConvertAction.None;
            searchFilter = new SearchFilter()
            {
                classNames = new string[] { "Material" },
                searchArea = SearchFilter.SearchArea.AllAssets
            };
            debounce = Delayer.Debounce(_ =>
            {
                SearchFilterChanged();
                editorWindow.Repaint();
            });

            Init();
        }
コード例 #6
0
        /*
         * Returns the list of actual dynamic postprocessor methods for a particular asset.
         * Note: That where the asset is not yet imported, this list will be empty.
         */
        internal static SortedSet <AssetPostprocessor.PostprocessorInfo> GetSortedDynamicPostprocessorsForAsset(string path)
        {
            var list = new SortedSet <AssetPostprocessor.PostprocessorInfo>(new CompareAssetImportPriority());

            var guid = AssetDatabase.GUIDFromAssetPath(path);

            if (guid.Empty())
            {
                return(list);
            }

            //Artifact Infos may contains multiple artifacts, associated with different version of the object (E.g. Main, Preview etc.)
            var artifactInfos = AssetDatabase.GetArtifactInfos(guid);

            var allMethodsNames = new List <string>();

            foreach (var info in artifactInfos)
            {
                if (!info.isCurrentArtifact)
                {
                    continue;
                }

                foreach (var kvp in info.dependencies)
                {
                    if (kvp.Value.type == ArtifactInfoDependencyType.Dynamic)
                    {
                        //Try to retrieve Postprocessor Methods associated with the supplied Dependency keys
                        string dependencyName = kvp.Key.Replace(ArtifactDifferenceReporter.kEnvironment_CustomDependency + "/", "");
                        if (s_PostprocessorMethodsByDependencyKey.TryGetValue(dependencyName, out var methodNames))
                        {
                            allMethodsNames.AddRange(methodNames);
                        }
                    }
                }
            }

            if (allMethodsNames.Count == 0)
            {
                return(list);
            }

            /*
             * The asset has dynamic dependencies to an Asset Postprocessor, so let's find any Postprocessors which
             * implements those methods.
             */
            var distinctMethodNames = allMethodsNames.Distinct();

            foreach (Type assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
            {
                if (ImplementsAnyOfTheses(assetPostprocessorClass, distinctMethodNames, out var methods))
                {
                    if (assetPostprocessorClass.GetConstructors().Any(t => t.GetParameters().Count() == 0))
                    {
                        list.Add(new AssetPostprocessor.PostprocessorInfo(assetPostprocessorClass, methods.ToArray()));
                    }
                    else
                    {
                        LogPostProcessorMissingDefaultConstructor(assetPostprocessorClass);
                    }
                }
            }

            return(list);
        }
コード例 #7
0
            static void GetCopyPasteAction(MaterialProperty prop, out GenericMenu.MenuFunction copyAction, out GenericMenu.MenuFunction pasteAction)
            {
                bool canCopy  = !capturedProperties[0].hasMixedValue;
                bool canPaste = GUI.enabled;

                copyAction  = null;
                pasteAction = null;
                switch (prop.type)
                {
                case PropType.Float:
                case PropType.Range:
                    if (canCopy)
                    {
                        copyAction = () => Clipboard.floatValue = prop.floatValue;
                    }
                    if (canPaste && Clipboard.hasFloat)
                    {
                        pasteAction = () => prop.floatValue = Clipboard.floatValue;
                    }
                    break;

                case PropType.Int:
                    if (canCopy)
                    {
                        copyAction = () => Clipboard.integerValue = prop.intValue;
                    }
                    if (canPaste && Clipboard.hasInteger)
                    {
                        pasteAction = () => prop.intValue = Clipboard.integerValue;
                    }
                    break;

                case PropType.Color:
                    if (canCopy)
                    {
                        copyAction = () => Clipboard.colorValue = prop.colorValue;
                    }
                    if (canPaste && Clipboard.hasColor)
                    {
                        pasteAction = () => prop.colorValue = Clipboard.colorValue;
                    }
                    break;

                case PropType.Vector:
                    if (canCopy)
                    {
                        copyAction = () => Clipboard.vector4Value = prop.vectorValue;
                    }
                    if (canPaste && Clipboard.hasVector4)
                    {
                        pasteAction = () => prop.vectorValue = Clipboard.vector4Value;
                    }
                    break;

                case PropType.Texture:
                    if (canCopy)
                    {
                        copyAction = () => Clipboard.guidValue = AssetDatabase.GUIDFromAssetPath(AssetDatabase.GetAssetPath(prop.textureValue));
                    }
                    if (canPaste && Clipboard.hasGuid)
                    {
                        pasteAction = () => prop.textureValue = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(Clipboard.guidValue)) as Texture;
                    }
                    break;
                }
            }