Ejemplo n.º 1
0
        public SearchResult(NGAssetFinderWindow window)
        {
            this.window     = window;
            this.searchTime = Time.realtimeSinceStartup;

            this.targetAsset          = this.window.targetAsset;
            this.replaceAsset         = this.window.replaceAsset;
            this.searchOptions        = this.window.searchOptions;
            this.searchAssets         = this.window.searchAssets;
            this.searchExtensionsMask = this.window.searchExtensionsMask;
            this.useCache             = this.window.useCache;

            this.targetAssetName = this.targetAsset.name;
            this.targetAssetIcon = Utility.GetIcon(this.targetAsset);
        }
Ejemplo n.º 2
0
        public void     Draw(SearchResult result, NGAssetFinderWindow window, Rect r)
        {
            float width = r.width;

            r.width = 24F;
            if (GUI.Button(r, GUIContent.none) == true)
            {
                if (Event.current.button == 1 || this.lastClick + Constants.DoubleClickTime > EditorApplication.timeSinceStartup)
                {
                    Selection.activeObject = scene;
                }
                else
                {
                    EditorGUIUtility.PingObject(scene);
                    this.lastClick = EditorApplication.timeSinceStartup;
                }
            }
            GUI.DrawTexture(r, UtilityResources.UnityIcon, ScaleMode.ScaleToFit);
            r.x += r.width;

            r.width = width - r.x;
            if (window.canReplace == true)
            {
                r.width -= SceneMatch.ReplaceButtonWidth;
            }

            GUI.Label(r, this.label);
            r.x += r.width;

            if (window.canReplace == true)
            {
                EditorGUI.BeginDisabledGroup(this.count == 0 && this.prefabCount == 0 && this.prefabModificationCount == 0);
                {
                    Utility.content.text = "Replace";
                    r.width = SceneMatch.ReplaceButtonWidth;
                    if (GUI.Button(r, Utility.content) == true &&
                        ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 ||
                         EditorUtility.DisplayDialog(NGAssetFinderWindow.Title, "Replacing references in scene is undoable.\nAre you sure you want to replace " + this.GetLabel() + " from " + this.scene.name + "?", "Replace", "Cancel") == true))
                    {
                        this.ReplaceReferencesInScene(result, window);
                    }
                    r.x += r.width;
                }
                EditorGUI.EndDisabledGroup();
            }
        }
Ejemplo n.º 3
0
        public void     ReplaceReferencesInScene(SearchResult result, NGAssetFinderWindow window)
        {
            string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(window.targetAsset));
            string id   = Utility.GetLocalIdentifierFromObject(window.targetAsset) + ", guid: " + guid;

            if (string.IsNullOrEmpty(id) == true)
            {
                return;
            }

            string newGuid = string.Empty;
            string newID   = null;

            if (window.replaceAsset != null)
            {
                newGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(window.replaceAsset));
                newID   = Utility.GetLocalIdentifierFromObject(window.replaceAsset) + ", guid: " + newGuid;
            }

            if (this.prefabCount > 0 && newID == null)
            {
                if (EditorUtility.DisplayDialog(NGAssetFinderWindow.Title, "You are replacing prefabs with nothing.\nPrefabs will be destroyed and they will be replace with \"Missing Prefab\" in the scene.", "Continue", "Cancel") == false)
                {
                    return;
                }
            }

            string[] lines = File.ReadAllLines(this.scenePath);
            bool     searchingComponentType = (window.replaceAsset is Component || window.replaceAsset is MonoScript);

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];

                if (line.Length < 11 + 8 + 32 + 1)                 // {fileID: , guid: }
                {
                    continue;
                }

                int position = line.IndexOf(" {fileID: ");
                if (position == -1)
                {
                    continue;
                }

                // References of scripts.
                if (line.StartsWith("  m_Script: {fileID: ") == true)
                {
                    if (newID != null && searchingComponentType == true && line.IndexOf(id, "  m_Script: {fileID: ".Length) != -1)
                    {
                        lines[i] = line.Replace(id, newID);
                        --this.count;
                        ++result.updatedReferencesCount;
                        continue;
                    }
                }
                // References of prefabs.
                else if (line.StartsWith("  m_ParentPrefab: {fileID: ") == true)
                {
                    if (line.IndexOf(guid) != -1)
                    {
                        if (newID == null)
                        {
                            lines[i] = line.Substring(0, line.IndexOf("{fileID: ")) + "{fileID: 0}";
                        }
                        else
                        {
                            lines[i] = line.Replace(guid, newGuid);
                        }
                        --this.prefabCount;
                        ++result.updatedReferencesCount;
                        continue;
                    }
                }
                // Modifications of prefabs.
                else if (line.StartsWith("    - target: {fileID: ") == false)
                {
                    if (newID == null)
                    {
                        lines[i] = line.Substring(0, line.IndexOf("{fileID: ")) + "{fileID: 0}";
                    }
                    else
                    {
                        lines[i] = line.Replace(guid, newGuid);
                    }
                    --this.prefabModificationCount;
                    ++result.updatedReferencesCount;
                    continue;
                }
                // References in script.
                else if (line.IndexOf(id, 11) != -1)
                {
                    if (newID == null)
                    {
                        lines[i] = line.Substring(0, line.IndexOf("{fileID: ")) + "{fileID: 0}";
                    }
                    else
                    {
                        lines[i] = line.Replace(id, newID);
                    }
                    --this.count;
                    ++result.updatedReferencesCount;
                    continue;
                }
            }

            this.PrepareResults();

            AssetFinderCache.UpdateFile(this.scenePath);
            File.WriteAllLines(this.scenePath, lines);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
Ejemplo n.º 4
0
 public CSharpFinder(NGAssetFinderWindow window) : base(window)
 {
 }
Ejemplo n.º 5
0
 public GameObjectFinder(NGAssetFinderWindow window) : base(window)
 {
 }
Ejemplo n.º 6
0
        public void     Draw(NGAssetFinderWindow window, Rect r)
        {
            if (this.type == AssetMatches.Type.Reference &&
                this.matches.Count == 0 &&
                this.children.Count == 0)
            {
                return;
            }

            float w = r.width;

            r.height = Constants.SingleLineHeight;

            bool isNull = this.origin == null;

            if (Event.current.type == EventType.Repaint)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    EditorGUI.DrawRect(r, NGAssetFinderWindow.HighlightBackground);
                }
                else if (isNull == false && Selection.activeObject == this.origin)
                {
                    EditorGUI.DrawRect(r, NGAssetFinderWindow.SelectedAssetBackground);
                }
            }

            if (isNull == false && (this.origin is Component) == false)
            {
                r.width -= AssetMatches.PingButtonWidth;
            }

            EditorGUI.BeginDisabledGroup(isNull);
            {
                if (this.matches.Count > 0 ||
                    this.children.Count > 0)
                {
                    EditorGUI.BeginChangeCheck();
                    bool open = EditorGUI.Foldout(r, this.Open, this.content, true);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        this.Open = open;
                    }

                    if (string.IsNullOrEmpty(this.content.tooltip) == false)
                    {
                        if (r.Contains(Event.current.mousePosition) == true)
                        {
                            Rect r2 = r;
                            r2.y -= r2.height;
                            EditorGUI.DrawRect(r2, NGAssetFinderWindow.HighlightBackground);
                            GUI.Label(r2, this.content.tooltip);
                        }
                    }

                    r.xMin += ((EditorGUI.indentLevel + 1) * 15F) - 4F;
                }
                else
                {
                    r.xMin += (EditorGUI.indentLevel * 15F) - 4F;
                }

                if (this.image != null)
                {
                    Rect r2 = r;

                    r2.width = r2.height;
                    GUI.DrawTexture(r2, this.image);

                    r.xMin += r2.width;
                }

                if (this.matches.Count == 0 && this.children.Count == 0)
                {
                    r.xMin -= 16F;
                    GUI.Label(r, this.content);
                    r.xMin += 16F;
                }

                if (isNull == false && (this.origin is Component) == false)
                {
                    r.x    += r.width;
                    r.width = AssetMatches.PingButtonWidth;

                    if (GUI.Button(r, LC.G("Ping")) == true)
                    {
                        if (Event.current.button != 0 || AssetMatches.lastClick + Constants.DoubleClickTime > EditorApplication.timeSinceStartup)
                        {
                            Selection.activeObject = this.origin;
                        }
                        else
                        {
                            EditorGUIUtility.PingObject(this.origin.GetInstanceID());
                        }

                        AssetMatches.lastClick = EditorApplication.timeSinceStartup;
                    }
                }

                if (this.Open == true)
                {
                    r.x     = 0F;
                    r.y    += r.height;
                    r.width = w;

                    EditorGUI.BeginChangeCheck();

                    ++EditorGUI.indentLevel;
                    AssetMatches.workingAssetMatches = this;
                    for (int i = 0; i < this.matches.Count; i++)
                    {
                        r.height = this.matches[i].GetHeight();
                        this.matches[i].Draw(window, r);
                        r.y += r.height;
                    }

                    for (int i = 0; i < this.children.Count; i++)
                    {
                        r.height = this.children[i].GetHeight();
                        this.children[i].Draw(window, r);
                        r.y += r.height;
                    }
                    --EditorGUI.indentLevel;

                    if (EditorGUI.EndChangeCheck() == true && this.origin != null)
                    {
                        EditorUtility.SetDirty(this.origin);
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
        }
Ejemplo n.º 7
0
 protected TypeFinder(NGAssetFinderWindow window)
 {
     this.window = window;
 }
Ejemplo n.º 8
0
 public MaterialFinder(NGAssetFinderWindow window) : base(window)
 {
 }
Ejemplo n.º 9
0
 protected ObjectFinder(NGAssetFinderWindow window)
 {
     this.window = window;
 }
Ejemplo n.º 10
0
        public void     Draw(NGAssetFinderWindow window, Rect r)
        {
            r.height = Constants.SingleLineHeight;

            if (this.subMatches.Count > 0)
            {
                if (Event.current.type == EventType.Repaint &&
                    r.Contains(Event.current.mousePosition) == true)
                {
                    EditorGUI.DrawRect(r, NGAssetFinderWindow.HighlightBackground);
                }

                EditorGUI.BeginChangeCheck();
                bool open = EditorGUI.Foldout(r, this.Open, this.nicifiedPath, true);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    this.Open = open;
                }

                if (this.Open == true)
                {
                    r.y += r.height;

                    ++EditorGUI.indentLevel;
                    for (int i = 0; i < this.subMatches.Count; i++)
                    {
                        r.height = this.subMatches[i].GetHeight();
                        this.subMatches[i].Draw(window, r);
                        r.y += r.height;
                    }
                    --EditorGUI.indentLevel;
                }
                return;
            }

            if (this.arrayIndexes.Count > 0)
            {
                if (Event.current.type == EventType.Repaint &&
                    r.Contains(Event.current.mousePosition) == true)
                {
                    EditorGUI.DrawRect(r, NGAssetFinderWindow.HighlightBackground);
                }

                EditorGUI.BeginChangeCheck();
                bool open = EditorGUI.Foldout(r, this.Open, this.nicifiedPath, true);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    this.Open = open;
                }

                if (this.Open == true)
                {
                    r.y += r.height;

                    ++EditorGUI.indentLevel;

                    ICollectionModifier collectionModifier = null;
                    TypeFinder          finder             = null;

                    try
                    {
                        if (window.canReplace == true)
                        {
                            int j = 0;
                            for (; j < window.typeFinders.array.Length; j++)
                            {
                                if (window.typeFinders.array[j].CanFind(this.type) == true)
                                {
                                    finder = window.typeFinders.array[j];
                                    window.typeFinders.BringToTop(j);
                                    break;
                                }
                            }

                            if (finder == null)
                            {
                                object rawArray = this.Value;

                                if (rawArray != null)
                                {
                                    collectionModifier = NGTools.Utility.GetCollectionModifier(rawArray);
                                }
                            }
                        }

                        for (int j = 0; j < this.arrayIndexes.Count; j++)
                        {
                            if (Event.current.type == EventType.Repaint &&
                                r.Contains(Event.current.mousePosition) == true)
                            {
                                EditorGUI.DrawRect(r, NGAssetFinderWindow.HighlightBackground);
                            }

                            if (window.canReplace == false)
                            {
                                using (LabelWidthRestorer.Get(r.width))
                                {
                                    EditorGUI.LabelField(r, "#" + this.arrayIndexes[j].ToCachedString());
                                }
                            }
                            else
                            {
                                Object reference = null;

                                try
                                {
                                    if (finder != null)
                                    {
                                        reference = finder.Get(this.type, this, this.arrayIndexes[j]);
                                    }
                                    else
                                    {
                                        reference = collectionModifier.Get(this.arrayIndexes[j]) as Object;
                                    }

                                    Utility.content.text = "#" + this.arrayIndexes[j].ToCachedString();
                                    float w = GUI.skin.label.CalcSize(Utility.content).x;

                                    using (ColorContentRestorer.Get(window.replaceAsset != null && (collectionModifier != null && collectionModifier.SubType.IsAssignableFrom(window.replaceAsset.GetType()) == false), Color.red))
                                    {
                                        EditorGUI.PrefixLabel(r, Utility.content);

                                        r.x     += w;
                                        r.width -= w;
                                        try
                                        {
                                            EditorGUI.BeginChangeCheck();
                                            Object o = EditorGUI.ObjectField(r, reference, window.targetType, AssetMatches.workingAssetMatches.allowSceneObject);
                                            if (EditorGUI.EndChangeCheck() == true)
                                            {
                                                Undo.RecordObject(AssetMatches.workingAssetMatches.origin, "Match assignment");

                                                if (finder != null)
                                                {
                                                    finder.Set(this.type, o, this, this.arrayIndexes[j]);
                                                }
                                                else
                                                {
                                                    collectionModifier.Set(this.arrayIndexes[j], o);
                                                }

                                                AssetDatabase.SaveAssets();
                                            }
                                        }
                                        catch (ExitGUIException)
                                        {
                                        }
                                        r.x     -= w;
                                        r.width += w;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    window.errorPopup.exception = ex;
                                    EditorGUILayout.LabelField("Error " + this.nicifiedPath + "	" + AssetMatches.workingAssetMatches + " /" + reference + "-" + this.instance + "	"+ ex.Message + "	"+ ex.StackTrace);
                                }
                            }

                            r.y += r.height;
                        }
                    }
                    finally
                    {
                        if (collectionModifier != null)
                        {
                            NGTools.Utility.ReturnCollectionModifier(collectionModifier);
                        }
                    }

                    --EditorGUI.indentLevel;
                }
                return;
            }

            ++EditorGUI.indentLevel;

            if (window.canReplace == false)
            {
                using (LabelWidthRestorer.Get(r.width))
                {
                    r.xMin += (EditorGUI.indentLevel - 1) * 15F;

                    if (typeof(Object).IsAssignableFrom(this.type) == true)
                    {
                        Texture2D image = Utility.GetIcon(this.Value as Object);

                        if (image != null)
                        {
                            Rect r2 = r;
                            r2.width = r2.height;
                            GUI.DrawTexture(r2, image);

                            r.xMin += r2.width;
                        }
                    }

                    GUI.Label(r, this.nicifiedPath);
                }
            }
            else
            {
                Object reference = null;

                try
                {
                    Utility.content.text = this.nicifiedPath;
                    //Rect	r = EditorGUILayout.GetControlRect(false);
                    float w = GUI.skin.label.CalcSize(Utility.content).x;

                    if (typeof(Object).IsAssignableFrom(this.type) == true)
                    {
                        reference = this.Value as Object;

                        Texture2D image = Utility.GetIcon(reference);

                        if (image != null)
                        {
                            Rect r2 = r;
                            r2.xMin += (EditorGUI.indentLevel - 1) * 15F;
                            r2.width = r2.height;
                            GUI.DrawTexture(r2, image);
                        }
                    }
                    else
                    {
                        throw new Exception("Field \"" + this.Name + "\" not an Object.");
                    }

                    using (LabelWidthRestorer.Get(r.xMax))
                        EditorGUI.BeginDisabledGroup(this.instance is MonoScript || (window.replaceAsset != null && this.type.IsAssignableFrom(window.replaceAsset.GetType()) == false));
                    {
                        r.x += 1F;
                        EditorGUI.LabelField(r, Utility.content);

                        try
                        {
                            r.x     += w;
                            r.width -= w;
                            EditorGUI.BeginChangeCheck();
                            Object o = EditorGUI.ObjectField(r, reference, this.type, AssetMatches.workingAssetMatches.allowSceneObject);
                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                Undo.RecordObject(AssetMatches.workingAssetMatches.origin, "Match assignment");
                                this.Value = o;
                                AssetDatabase.SaveAssets();
                            }
                        }
                        catch (ExitGUIException)
                        {
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                catch (Exception ex)
                {
                    window.errorPopup.exception = ex;
                    EditorGUILayout.LabelField("Error " + this.nicifiedPath + "	" + AssetMatches.workingAssetMatches + " /" + reference + "-" + this.instance + "	"+ ex.Message + "	"+ ex.StackTrace);
                }
            }

            --EditorGUI.indentLevel;
        }
Ejemplo n.º 11
0
 public UnityEventBaseFinder(NGAssetFinderWindow window) : base(window)
 {
 }