Exemplo n.º 1
0
 public static IEnumerable <string> GetPathWithMeta(string path)
 {
     if (path.EndsWith(".meta"))
     {
         if (Path.HasExtension(path))
         {
             yield return(path);
         }
         string assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(path);
         if (!string.IsNullOrEmpty(assetPath))
         {
             yield return(assetPath);
         }
     }
     else
     {
         if (Path.HasExtension(path))
         {
             yield return(path);
         }
         string metaPath = AssetDatabase.GetTextMetaFilePathFromAssetPath(path);
         if (!string.IsNullOrEmpty(metaPath))
         {
             yield return(metaPath);
         }
     }
 }
Exemplo n.º 2
0
        private void Execute(StrippingStep step)
        {
            // First, verify...
            foreach (var srcPath in step.files)
            {
                if (!File.Exists(srcPath) && !Directory.Exists(srcPath))
                {
                    throw new InvalidOperationException("The file or directory at path " + srcPath + " is in the worklist but missing on disk.");
                }
            }

            // Now execute
            foreach (var srcPath in step.files)
            {
                var targetPath = Path.Combine(_backupAreaRoot, srcPath);
                var parentPath = Path.GetDirectoryName(targetPath);
                Directory.CreateDirectory(parentPath);
                FileUtil.MoveFileOrDirectory(srcPath, targetPath);

                // Remove moved directories
                if (srcPath.EndsWith(".meta"))
                {
                    var dataPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(srcPath);
                    if (Directory.Exists(dataPath))
                    {
                        Directory.Delete(dataPath);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void OnWillCreateAsset(string path)
        {
            if (!UnityExtensionsSettings.instance.cSharpSettings.addNamespaceToCSharpFiles)
            {
                return;
            }
            path = AssetDatabase.GetAssetPathFromTextMetaFilePath(path);
            var file = new FileInfo(path);

            if (file.Extension == CSHARP_EXTENSION)
            {
                var script   = AssetDatabase.LoadAssetAtPath <MonoScript>(path);
                var assembly = PrefabUtils.GetAssembly(script, path);
                if (assembly)
                {
                    string contents = File.ReadAllText(file.FullName);
                    if (!contents.Contains("namespace ") && contents.Contains("public class "))
                    {
                        contents = contents.Replace("public class ", $"namespace {PrefabUtils.GetNamespace(assembly, path)} {{\r\npublic class ") + "}";
                        File.WriteAllText(file.FullName, contents);
                        AssetDatabase.Refresh();
                    }
                }
            }
        }
Exemplo n.º 4
0
    private bool IsFirstImport(AudioImporter importer)
    {
        //(int width, int height) = GetTextureImporterSize(importer);
        AudioClip asset   = AssetDatabase.LoadAssetAtPath <AudioClip>(assetPath);
        bool      hasMeta = File.Exists(AssetDatabase.GetAssetPathFromTextMetaFilePath(assetPath));

        return(asset == null || !hasMeta);//|| (tex.width != width && tex.height != height);
    }
        private void PingAsset(RansackQuery.ResultEntry item)
        {
            string assetPath = item.AssetPath;

            if (assetPath.EndsWith(".meta"))
            {
                assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(assetPath);
            }

            var asset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetPath);

            if (asset != null)
            {
                EditorGUIUtility.PingObject(asset);
                Selection.SetActiveObjectWithContext(asset, null);
            }
        }
Exemplo n.º 6
0
        public override void OnGUI(Rect rect)
        {
            EditorGUILayout.Space();
            float msgHeight = commitMessageStyle.CalcHeight(GitGUI.GetTempContent(commit.Message), rect.width);

            scroll = EditorGUILayout.BeginScrollView(scroll);
            EditorGUILayout.LabelField(GitGUI.GetTempContent(commit.Message), commitMessageStyle, GUILayout.Height(msgHeight));
            if (changes != null)
            {
                foreach (var change in changes)
                {
                    //EditorGUILayout.BeginHorizontal();
                    //GUILayout.Label(change.Status.ToString(), "AssetLabel");
                    EditorGUILayout.BeginHorizontal("ProjectBrowserHeaderBgTop");
                    GUILayout.Label(new GUIContent(GitOverlay.GetDiffTypeIcon(change.Status, true))
                    {
                        tooltip = change.Status.ToString()
                    }, GUILayout.Width(16));
                    GUILayout.Space(8);
                    string[] pathChunks = change.Path.Split(Path.DirectorySeparatorChar);
                    for (int i = 0; i < pathChunks.Length; i++)
                    {
                        string chunk = pathChunks[i];
                        if (GUILayout.Button(GitGUI.GetTempContent(chunk), GitGUI.Styles.BreadcrumMid))
                        {
                            string assetPath = string.Join("/", pathChunks, 0, i + 1);
                            if (assetPath.EndsWith(".meta"))
                            {
                                assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(assetPath);
                            }
                            ShowContextMenuForElement(change.Path, assetPath);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                DrawTreeEntry(commitTree, 0);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 7
0
        private void Unexecute(StrippingStep step)
        {
            foreach (var srcPath in step.files)
            {
                var targetPath = Path.Combine(_backupAreaRoot, srcPath);
                var parentPath = Path.GetDirectoryName(srcPath);
                Directory.CreateDirectory(parentPath);
                FileUtil.MoveFileOrDirectory(targetPath, srcPath);

                // Deal with empty directories
                if (srcPath.EndsWith(".meta"))
                {
                    var dataPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(srcPath);
                    if (!File.Exists(dataPath) && !Directory.Exists(dataPath))
                    {
                        Directory.CreateDirectory(dataPath);
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Returns true if the meta file at the given path is orphaned.
        /// </summary>
        /// <returns><c>true</c> if orphaned; otherwise, <c>false</c>.</returns>
        /// <param name="path">Path.</param>
        public static bool IsOrphanedMeta(string path)
        {
            if (!IsMeta(path))
            {
                return(false);
            }

            string assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(path);

            if (File.Exists(assetPath))
            {
                return(false);
            }

            if (Directory.Exists(assetPath))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
        private void DoFileDiff(Rect rect, StatusListEntry info)
        {
            Event current = Event.current;


            if (rect.y > DiffRect.height + diffScroll.y || rect.y + rect.height < diffScroll.y)
            {
                return;
            }

            Rect stageToggleRect = new Rect(rect.x + rect.width - rect.height, rect.y + 14, rect.height, rect.height);

            if (current.type == EventType.Repaint)
            {
                string filePath = info.Path;
                string fileName = Path.GetFileName(filePath);

                Object asset = null;
                if (filePath.EndsWith(".meta"))
                {
                    asset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPathFromTextMetaFilePath(filePath), typeof(Object));
                }
                else
                {
                    asset = AssetDatabase.LoadAssetAtPath(filePath, typeof(Object));
                }

                GUI.SetNextControlName(info.Path);
                GUI.Box(rect, GUIContent.none, info.Selected ? "TL LogicBar 1" : styles.diffElement);

                bool canUnstage = GitManager.CanUnstage(info.State);
                bool canStage   = GitManager.CanStage(info.State);
                if (canUnstage)
                {
                    GUIContent content = EditorGUIUtility.IconContent("toggle on act@2x");
                    GUI.Box(new Rect(rect.x + rect.width - rect.height, rect.y + 14, rect.height, rect.height), content, GUIStyle.none);
                }
                else if (canStage)
                {
                    GUIContent content = EditorGUIUtility.IconContent("toggle act@2x");
                    GUI.Box(stageToggleRect, content, GUIStyle.none);
                }

                GUIContent iconContent = null;
                string     extension   = Path.GetExtension(filePath);
                if (string.IsNullOrEmpty(extension))
                {
                    iconContent = EditorGUIUtility.IconContent("Folder Icon");
                }

                if (iconContent == null)
                {
                    if (asset != null)
                    {
                        iconContent         = new GUIContent(AssetPreview.GetMiniThumbnail(asset));
                        iconContent.tooltip = asset.GetType().Name;
                    }
                    else
                    {
                        iconContent         = EditorGUIUtility.IconContent("DefaultAsset Icon");
                        iconContent.tooltip = "Unknown Type";
                    }
                }

                float x = rect.x + elementSideMargin;
                GUI.Box(new Rect(x, rect.y + elementTopBottomMargin, iconSize, iconSize), iconContent, styles.assetIcon);
                x += iconSize + 8;


                styles.diffElementName.Draw(new Rect(x, rect.y + elementTopBottomMargin + 2, rect.width - elementSideMargin - iconSize - rect.height, EditorGUIUtility.singleLineHeight), new GUIContent(fileName), false, info.Selected, info.Selected, false);

                x = rect.x + elementSideMargin + iconSize + 8;
                GUI.Box(new Rect(x, rect.y + elementTopBottomMargin + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitManager.GetDiffTypeIcon(info.State, false), GUIStyle.none);
                x += 25;
                if (info.MetaChange.IsFlagSet(MetaChangeEnum.Meta))
                {
                    GUIContent metaIconContent = EditorGUIUtility.IconContent("UniGit/meta");
                    metaIconContent.tooltip = ".meta file changed";
                    GUI.Box(new Rect(x, rect.y + elementTopBottomMargin + EditorGUIUtility.singleLineHeight + 4, 21, 21), metaIconContent, GUIStyle.none);
                    x += 25;
                }

                styles.diffElementPath.Draw(new Rect(x, rect.y + elementTopBottomMargin + EditorGUIUtility.singleLineHeight + 7, rect.width - elementSideMargin - iconSize - rect.height * 2, EditorGUIUtility.singleLineHeight), new GUIContent(filePath), false, info.Selected, info.Selected, false);
            }
            else if (current.type == EventType.MouseDown)
            {
                if (current.button == 0 && stageToggleRect.Contains(current.mousePosition))
                {
                    bool updateFlag = false;
                    if (GitManager.CanStage(info.State))
                    {
                        GitManager.Repository.Stage(info.Path);
                        updateFlag = true;
                    }
                    else if (GitManager.CanUnstage(info.State))
                    {
                        GitManager.Repository.Unstage(info.Path);
                        updateFlag = true;
                    }

                    if (updateFlag)
                    {
                        Repaint();
                        current.Use();
                        UpdateStatusList();
                    }
                }
            }
        }
Exemplo n.º 10
0
        public override void OnGUI(Rect rect)
        {
            EditorGUILayout.Space();
            float msgHeight = commitMessageStyle.CalcHeight(GitGUI.GetTempContent(commit.Message), rect.width);

            scroll = EditorGUILayout.BeginScrollView(scroll);
            EditorGUILayout.LabelField(GitGUI.GetTempContent(commit.Message), commitMessageStyle, GUILayout.Height(msgHeight));
            if (changes != null)
            {
                foreach (var change in changes)
                {
                    //EditorGUILayout.BeginHorizontal();
                    //GUILayout.Label(change.Status.ToString(), "AssetLabel");
                    EditorGUILayout.BeginHorizontal("ProjectBrowserHeaderBgTop");
                    GUILayout.Label(new GUIContent(GitOverlay.GetDiffTypeIcon(change.Status, true))
                    {
                        tooltip = change.Status.ToString()
                    }, GUILayout.Width(16));
                    GUILayout.Space(8);
                    string[] pathChunks = change.Path.Split('\\');
                    for (int i = 0; i < pathChunks.Length; i++)
                    {
                        string chunk = pathChunks[i];
                        if (GUILayout.Button(GitGUI.GetTempContent(chunk), "GUIEditor.BreadcrumbMid"))
                        {
                            string assetPath = string.Join("/", pathChunks, 0, i + 1);
                            if (assetPath.EndsWith(".meta"))
                            {
                                assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(assetPath);
                            }
                            var asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));
                            if (asset != null)
                            {
                                Selection.activeObject = asset;
                            }
                        }
                    }
                    //GUILayout.Label(new GUIContent(" (" + change.Status + ") " + change.Path));
                    EditorGUILayout.EndHorizontal();
                    Rect r = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.ContextClick && r.Contains(Event.current.mousePosition))
                    {
                        string      path = change.Path;
                        GenericMenu menu = new GenericMenu();
                        if (commit.Parents.Count() == 1)
                        {
                            menu.AddItem(new GUIContent("Difference with previous commit"), false, () =>
                            {
                                Commit parent = commit.Parents.Single();
                                GitManager.ShowDiff(path, parent, commit);
                            });
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent(new GUIContent("Difference with previous commit")));
                        }
                        menu.AddItem(new GUIContent("Difference with HEAD"), false, () =>
                        {
                            GitManager.ShowDiff(path, commit, GitManager.Repository.Head.Tip);
                        });
                        menu.ShowAsContext();
                    }
                    //EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                DrawTreeEntry(commitTree, 0);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 11
0
        private static void FindSpriteReferenceInternal()
        {
            if (Selection.activeObject == null)
            {
                return;
            }

            var target = Selection.activeObject;

            var sprite = target as Sprite;

            if (sprite == null)
            {
                return;
            }

            var texture = sprite.texture;

            var textureAssetPath    = AssetDatabase.GetAssetPath(texture);
            var textureMetaFilePath = AssetDatabase.GetAssetPathFromTextMetaFilePath(textureAssetPath);

            if (string.IsNullOrEmpty(textureMetaFilePath))
            {
                return;
            }

            textureMetaFilePath += ".meta";

            var textureGuid = UnityEditorUtility.GetAssetGUID(sprite.texture);

            var spriteFileId = string.Empty;

            var spriteName = sprite.name;

            using (var sr = new StreamReader(textureMetaFilePath, Encoding.UTF8, false, 256 * 1024))
            {
                var skip = true;

                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    var str = line.Replace(" ", string.Empty);

                    if (str.StartsWith("fileIDToRecycleName"))
                    {
                        skip = false;
                    }

                    if (skip)
                    {
                        continue;
                    }

                    var findFormat = string.Format(":{0}", spriteName);

                    if (!str.Contains(findFormat))
                    {
                        continue;
                    }

                    spriteFileId = str.Replace(findFormat, string.Empty);

                    break;
                }
            }

            var assetPath = Application.dataPath;

            var scenes    = FindAllFiles(assetPath, "*.unity");
            var prefabs   = FindAllFiles(assetPath, "*.prefab");
            var materials = FindAllFiles(assetPath, "*.mat");
            var assets    = FindAllFiles(assetPath, "*.asset");

            var scenesReference    = new HashSet <string>();
            var prefabsReference   = new HashSet <string>();
            var materialsReference = new HashSet <string>();
            var assetsReference    = new HashSet <string>();

            Action <int, int> reportProgress = (c, t) =>
            {
                var title = "Find Sprite References In Project";
                var info  = string.Format("Find Dependencies ({0}/{1})", c, t);

                EditorUtility.DisplayProgressBar(title, info, c / (float)t);
            };

            var total = scenes.Length + prefabs.Length + materials.Length + assets.Length;

            reportProgress(0, total);

            var progressCounter = new ProgressCounter();

            var events = new WaitHandle[]
            {
                StartResolveReferencesWorker(scenes, spriteFileId, textureGuid, (metadata) => scenesReference       = metadata, progressCounter),
                StartResolveReferencesWorker(prefabs, spriteFileId, textureGuid, (metadata) => prefabsReference     = metadata, progressCounter),
                StartResolveReferencesWorker(materials, spriteFileId, textureGuid, (metadata) => materialsReference = metadata, progressCounter),
                StartResolveReferencesWorker(assets, spriteFileId, textureGuid, (metadata) => assetsReference       = metadata, progressCounter),
            };

            while (!WaitHandle.WaitAll(events, 100))
            {
                reportProgress(progressCounter.Count, total);
            }

            reportProgress(progressCounter.Count, total);

            var builder = new StringBuilder();

            if (scenesReference.Any())
            {
                builder.AppendLine("ScenesReference:");
                scenesReference.ForEach(x => builder.AppendLine(x));
                Debug.Log(builder.ToString());
                builder.Clear();
            }

            if (prefabsReference.Any())
            {
                builder.AppendLine("PrefabsReference:");
                prefabsReference.ForEach(x => builder.AppendLine(x));
                Debug.Log(builder.ToString());
                builder.Clear();
            }

            if (materialsReference.Any())
            {
                builder.AppendLine("MaterialsReference:");
                materialsReference.ForEach(x => builder.AppendLine(x));
                Debug.Log(builder.ToString());
                builder.Clear();
            }

            if (assetsReference.Any())
            {
                builder.AppendLine("AssetsReference:");
                assetsReference.ForEach(x => builder.AppendLine(x));
                Debug.Log(builder.ToString());
                builder.Clear();
            }

            if (scenesReference.IsEmpty() && prefabsReference.IsEmpty() && materialsReference.IsEmpty() && assetsReference.IsEmpty())
            {
                Debug.Log("This asset no reference in project.");
            }

            EditorUtility.ClearProgressBar();
        }