Ejemplo n.º 1
0
            public void     Reference()
            {
                this.referenced = true;

                for (int i = 0; i < this.folders.Count; i++)
                {
                    this.folders[i].Reference();
                }

                for (int i = 0; i < this.files.Count; i++)
                {
                    if (this.files[i].isValid == true && EmbedAssetsBrowserWindow.CheckEmbeddableFile(this.files[i]) == true)
                    {
                        this.files[i].referenced = true;
                    }
                }

                if (this.parent != null)
                {
                    this.parent.Update();
                }
            }
Ejemplo n.º 2
0
        private void    ReferenceAssets()
        {
            List <ListingAssets.AssetReferences> list = new List <ListingAssets.AssetReferences>();

            foreach (Folder.File file in this.root.EachFileReferenced())
            {
                if (file.isValid == false)
                {
                    continue;
                }

                Object[] references;
                Object   mainAsset;

                if (EmbedAssetsBrowserWindow.CheckEmbeddableFile(file, out references, out mainAsset) == false)
                {
                    file.referenced = false;
                    continue;
                }

                ListingAssets.AssetReferences newReference = new ListingAssets.AssetReferences()
                {
                    asset          = file.path,
                    mainAssetIndex = -1,
                    references     = references
                };
                list.Add(newReference);

                for (int i = 0; i < references.Length; i++)
                {
                    if (references[i] == null)
                    {
                        continue;
                    }

                    if (AssetDatabase.IsMainAsset(references[i]) == true)
                    {
                        newReference.mainAssetIndex = i;
                    }
                }

                // Manually embed the main asset, for simplification sake.
                if (newReference.mainAssetIndex == -1)
                {
                    Array.Resize <Object>(ref newReference.references, newReference.references.Length + 1);
                    newReference.mainAssetIndex = newReference.references.Length - 1;
                    newReference.references[newReference.references.Length - 1] = mainAsset;
                }
            }

            try
            {
                Undo.RecordObject(this.serializedObject.targetObject, "Embed assets");
                this.origin.assets = list.ToArray();
                this.serializedObject.Update();
                EditorUtility.SetDirty(this.serializedObject.targetObject);
            }
            catch (NullReferenceException)
            {
                this.Close();
            }
        }
Ejemplo n.º 3
0
            public void     Draw(Rect r, float viewYMin, float viewYMax)
            {
                float x    = r.x;
                float xMax = r.xMax;

                r.height = Constants.SingleLineHeight;
                r.width  = r.height;

                if (r.yMax > viewYMin)
                {
                    EditorGUI.showMixedValue = this.HasMixedRefs();
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.ToggleLeft(r, string.Empty, this.referenced);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        if (this.referenced == true)
                        {
                            this.Unreference();
                        }
                        else
                        {
                            this.Reference();
                        }
                    }
                    r.x += r.width + r.width;

                    EditorGUI.showMixedValue = false;

                    GUI.DrawTexture(r, Folder.folderIcon);
                    r.x    += r.width;
                    r.xMax  = xMax;
                    r.xMin -= r.height + r.height;

                    EditorGUI.BeginChangeCheck();
                    EditorGUI.Foldout(r, this.Open, "     " + this.name, true);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        this.Open = !this.open;

                        if (Event.current.alt == true)
                        {
                            Queue <Folder> queue = new Queue <Folder>(128);

                            queue.Enqueue(this);

                            while (queue.Count > 0)
                            {
                                Folder current = queue.Dequeue();

                                for (int i = 0; i < current.folders.Count; i++)
                                {
                                    queue.Enqueue(current.folders[i]);
                                }

                                current.open   = this.open;
                                current.height = -1F;
                                EditorPrefs.SetBool(EmbedAssetsBrowserWindow.Folder.EnableFolderPrefKey + current.GetHierarchyPath(), this.open);
                            }
                        }
                    }
                }
                else
                {
                    r.xMax = xMax;
                }

                if (this.open == true)
                {
                    r.x  = x + 16F;
                    r.y += r.height;

                    for (int i = 0; i < this.folders.Count; i++)
                    {
                        if (this.folders[i].folders.Count == 0 && this.folders[i].files.Count == 0)
                        {
                            continue;
                        }

                        r.height = this.folders[i].GetHeight();
                        this.folders[i].Draw(r, viewYMin, viewYMax);
                        r.y += r.height;
                    }

                    if (r.yMin > viewYMax)
                    {
                        return;
                    }

                    r.height = Constants.SingleLineHeight;

                    for (int i = 0; i < this.files.Count; i++)
                    {
                        if (r.yMax > viewYMin)
                        {
                            EditorGUI.BeginChangeCheck();

                            Texture2D icon = Utility.GetIcon(AssetDatabase.LoadMainAssetAtPath(this.files[i].path));
                            if (icon == null)
                            {
                                icon = InternalEditorUtility.GetIconForFile(this.files[i].path);
                            }
                            r.width = r.height;
                            r.x    += r.width;
                            GUI.DrawTexture(r, icon);
                            r.x -= r.width;

                            EditorGUI.BeginDisabledGroup(!this.files[i].isValid);
                            {
                                r.xMax = xMax;
                                this.files[i].referenced = EditorGUI.ToggleLeft(r, "     " + this.files[i].name, this.files[i].referenced);
                                if (EditorGUI.EndChangeCheck() == true)
                                {
                                    EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(this.files[i].path));

                                    if (this.files[i].referenced == false || EmbedAssetsBrowserWindow.CheckEmbeddableFile(this.files[i]) == true)
                                    {
                                        this.Update();
                                    }
                                    else
                                    {
                                        if (NGEditorPrefs.GetBool(Folder.AlertNullAssetPrefKey) == false &&
                                            EditorUtility.DisplayDialog(Constants.PackageTitle, "Asset at \"" + this.files[i].path + "\" contains null assets.\nFix them and reference again.", "OK", "Don't show again") == false)
                                        {
                                            NGEditorPrefs.SetBool(Folder.AlertNullAssetPrefKey, true);
                                        }

                                        this.files[i].referenced = false;
                                    }
                                }
                            }
                            EditorGUI.EndDisabledGroup();
                        }

                        r.y += r.height;

                        if (r.yMin > viewYMax)
                        {
                            return;
                        }
                    }
                }
            }