Exemplo n.º 1
0
        // -------------------------------------------

        public static void ChooseUrlFromPickedPrefab(SimpleUI instance)
        {
            //return;
            var path = GetOpenedAssetPath();

            var urls = instance.prefabs.Where(p => p.AssetPath.Equals(path));

            if (!urls.Any())
            {
                //BoldPrint("NO URLS MATCHING PATH " + path);
                instance.newUrl = "";
            }

            if (urls.Count() == 1)
            {
                instance.newUrl = urls.First().Url;
                instance.isConcreteUrlChosen = true;
            }

            if (urls.Count() > 1)
            {
                // pick first automatically or do nothing?
                instance.isConcreteUrlChosen = false;
            }
        }
Exemplo n.º 2
0
        void DrawAsset(string url, bool show)
        {
            var asset = prefabs.Find(p => p.Url.Equals(url));

            if (Urls.Contains(url))
            {
                if (!show)
                {
                }
            }
            else
            {
                if (show)
                {
                    // needs to show
                }
            }

            try
            {
                if (SimpleUI.isPrefabAsset(asset.AssetPath))
                {
                    DrawPrefab(show, asset.Url);
                }

                if (SimpleUI.isSceneAsset(asset.AssetPath))
                {
                    DrawScene(show, asset);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 3
0
        void RenderAddingNewRouteFromDraggedPrefab()
        {
            Space();
            GUILayout.Label("Add DRAGGED prefab", EditorStyles.boldLabel);

            draggedName = EditorGUILayout.TextField("Name", draggedName);
            draggedUrl  = EditorGUILayout.TextField("Url", draggedUrl);

            var dataCorrect = draggedUrl.Length > 0 && draggedName.Length > 0;

            if (dataCorrect && GUILayout.Button("Add DRAGGED prefab!"))
            {
                Space();

                draggedUrl = SimpleUI.GetValidatedUrl(draggedUrl);

                AddAsset(draggedUrl, draggedPath, draggedName);

                isDraggedPrefabMode = false;

                SaveData();

                Debug.Log("Added DRAGGED prefab");

                DestroyImmediate(PossiblePrefab);

                PossiblePrefab = null;

                Debug.Log("Removed object too");
            }
        }
Exemplo n.º 4
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var instance = SimpleUI.GetInstance();
            var prefabs  = SimpleUI.GetPrefabsFromFile();

            for (var i = 0; i < movedFromAssetPaths.Count(); i++) // importedAssets
            {
                string oldFilePath = movedFromAssetPaths[i];
                string newPath     = movedAssets[i];

                Debug.Log("Checking path: " + oldFilePath);

                string filename = Path.GetFileName(oldFilePath);

                Debug.Log(string.Format("Moving asset ({0}) from {2} to path: {1}", filename, newPath, oldFilePath));

                MovingUsedPrefab(oldFilePath, newPath, prefabs, instance);
            }

            for (var i = 0; i < importedAssets.Count(); i++)
            {
                var path = importedAssets[i];

                var index    = path.LastIndexOf('/');
                var fileName = path.Substring(index);

                Debug.Log("Imported asset: " + fileName);
            }
        }
Exemplo n.º 5
0
 void OnValidate()
 {
     if (SimpleUI.IsUrlExist(CurrentUrl))
     {
         Print("Open Url " + CurrentUrl);
         OpenUrl(CurrentUrl, true);
     }
 }
Exemplo n.º 6
0
        // = { "foo", "foobar" };

        public void SetOpenUrl(OpenUrl openUrl)
        {
            OpenUrl = openUrl;

            prefabs  = SimpleUI.GetPrefabsFromFile();
            _choices = prefabs.Select(p => MakeProperUrl(p.Url)).ToArray();

            previousUrl = openUrl.Url;
        }
Exemplo n.º 7
0
        void RenderAddingNewRoute()
        {
            if (!isUrlAddingMode)
            {
                SetAddingRouteMode();
            }

            Space();

            var assetType = isPrefabMode ? "prefab" : "SCENE";

            if (!isPrefabMode)
            {
                return;
            }

            var assetPath = SimpleUI.GetOpenedAssetPath();

            GUILayout.Label($"Add current asset ({assetType})", EditorStyles.boldLabel);

            SetNewUrl(EditorGUILayout.TextField("Url", newUrl));

            var url = newUrl;

            if (url == null)
            {
                return;
            }

            bool urlOK     = url.StartsWith("/");
            bool newNameOK = newName.Length > 0;

            if (urlOK)
            {
                SetNewName(EditorGUILayout.TextField("Name", newName));
            }
            else
            {
                EditorGUILayout.HelpBox("Url needs to start with /", MessageType.Error);
            }

            if (urlOK && newNameOK)
            {
                Space();
                if (GUILayout.Button("Add asset!")) //  <" + newName + ">
                {
                    Debug.Log("Added asset");

                    AddAsset(url, assetPath, newName);

                    SaveData();
                }
            }
        }
Exemplo n.º 8
0
        public static void TryToIncreaseCurrentPrefabCounter(SimpleUI instance)
        {
            if (instance.hasChosenPrefab)
            {
                var pref = instance.prefabs[instance.ChosenIndex];

                pref.Usages++;
                pref.LastOpened = DateTime.Now.Ticks;

                instance.UpdatePrefab(pref);
            }
        }
Exemplo n.º 9
0
        void PickRecentUrls(OpenUrl openUrl)
        {
            GUIStyle style = GUI.skin.FindStyle("Button");

            style.richText = true;

            scroll = EditorGUILayout.BeginScrollView(scroll);

            var sortedByOpenings = prefabs.OrderByDescending(pp => pp.LastOpened);
            var recent           = sortedByOpenings.Take(10);

            //var recent = prefabs.OrderByDescending(pp => pp.LastOpened).Take(15);

            GUILayout.Space(15);
            GUILayout.Label("Recent prefabs", EditorStyles.boldLabel);
            searchUrl = EditorGUILayout.TextField("Search", searchUrl);
            GUILayout.Space(15);

            if (searchUrl.Length == 0)
            {
                foreach (var r in recent)
                {
                    if (GUILayout.Button($"<b>{r.Name}</b>\n{r.Url}", style))
                    {
                        ChangeUrl(r.Url);
                    }
                }
            }

            if (searchUrl.Length != 0)
            {
                if (GUILayout.Button("Clear"))
                {
                    searchUrl = "";
                    Repaint();
                }

                GUILayout.Space(15);
                foreach (var r in sortedByOpenings.Where(p => SimpleUI.Contains(p.Url, searchUrl) || SimpleUI.Contains(p.Name, searchUrl)))
                {
                    if (GUILayout.Button($"<b>{r.Name}</b>\n{r.Url}", style))
                    {
                        ChangeUrl(r.Url);
                    }
                }
            }

            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 10
0
        void ShowCurrentPrefab()
        {
            if (SimpleUIEventHandler == null)
            {
                SimpleUIEventHandler = GetComponent <SimpleUIEventHandler>();
            }


            if (SimpleUIEventHandler != null)
            {
                var url = SimpleUI.GetInstance().GetCurrentUrl();

                SimpleUIEventHandler.PreviewUrlInEditor(url);
            }
        }
Exemplo n.º 11
0
        public void Execute()
        {
            var newUrl = "";

            if (Url.StartsWith("/"))
            {
                newUrl = Url;
            }
            else
            {
                newUrl = "/" + Url;
            }

            SimpleUI.OpenUrl_static(newUrl);
        }
Exemplo n.º 12
0
        void OnSceneGUI()
        {
            Handles.BeginGUI();

            var openUrl = target as OpenUrl;
            var pos     = openUrl.transform.position - new Vector3(0, -250, 0);

            Handles.Label(pos, SimpleUI.GetPrettyNameForExistingUrl("/" + openUrl.Url, prefabs)); // transform.position - new Vector3(0, -250, 0)

            if (GUILayout.Button(openUrl.Url))
            {
                OpenCurrentUrl();
            }

            Handles.EndGUI();
        }
Exemplo n.º 13
0
        string GetPrettyNameForAsset(CountableAsset m)
        {
            string assetPath = m.AssetPath;

            var trimmedName = assetPath.Substring(assetPath.LastIndexOf('/') + 1).Replace(".prefab", "").Replace(".unity", "");

            bool isOpened = assetPath.Equals(SimpleUI.GetOpenedAssetPath());

            if (isOpened)
            {
                return($"<b>{trimmedName}</b>");
            }
            else
            {
                return(trimmedName);
            }
        }
Exemplo n.º 14
0
        void HandleDraggedPrefab(GameObject go)
        {
            isDraggedPrefabMode = true;
            PossiblePrefab      = go;

            var    parent     = PrefabUtility.GetCorrespondingObjectFromSource(go);
            string prefabPath = AssetDatabase.GetAssetPath(parent);

            Debug.Log("route = " + prefabPath);

            // try to attach this prefab
            // to current prefab

            draggedName = SimpleUI.GetPrettyNameFromAssetPath(prefabPath);
            draggedPath = prefabPath;
            draggedUrl  = newUrl.TrimEnd('/') + "/" + draggedName.TrimStart('/');
        }
Exemplo n.º 15
0
        void ChangeUrl(string newUrl, bool forceDirty = true)
        {
            OpenUrl.Url = MakeProperUrl(newUrl);
            var validatedUrl = SimpleUI.GetValidatedUrl(newUrl);

            OpenUrl.Url_ID = prefabs.First(p => p.Url.Equals(validatedUrl)).ID;

            // Save the changes back to the object
            if (forceDirty)
            {
                EditorUtility.SetDirty(OpenUrl);
            }
            else
            {
                EditorUtility.ClearDirty(OpenUrl);
            }
        }
Exemplo n.º 16
0
        void FillRoutes(List <string> names, List <string> routes, string url, bool recursive)
        {
            var matches = SimpleUI.WhatUsesComponent(url, GetAllAssetsWithOpenUrl());

            Label($"References to {url}");

            names  = new List <string>();
            routes = new List <string>();

            // references from code
            foreach (var occurence in WhichScriptReferencesConcreteUrl(url))
            {
                names.Add($"<b>Code</b> {SimpleUI.GetTrimmedPath(occurence.ScriptName)}");
                routes.Add(occurence.ScriptName);
            }

            // references from assets
            names.AddRange(matches.Select(m => $"<b>{SimpleUI.GetPrettyAssetType(m.PrefabAssetPath)}</b> " + SimpleUI.GetTrimmedPath(m.PrefabAssetPath)));
            routes.AddRange(matches.Select(m => m.PrefabAssetPath));

            removingUrlObstacles += names.Count;

            // navigate to one of these assets
            var selected = GUILayout.SelectionGrid(-1, names.ToArray(), 1);

            if (selected != -1)
            {
                GUILayout.EndScrollView();
                isEndedRemoveUrlScrollView = true;

                OpenPrefabByAssetPath(routes[selected]);
            }

            if (!recursive)
            {
                return;
            }

            foreach (var r in GetSubUrls(url, false))
            {
                FillRoutes(names, routes, r.Url, recursive);
            }
        }
Exemplo n.º 17
0
        void SetAddingRouteMode()
        {
            var path = SimpleUI.GetOpenedAssetPath();

            // pick values from asset path
            var name = SimpleUI.GetPrettyNameFromAssetPath(path);

            SetNewName(name);

            var url = newUrl;

            if (!newUrl.EndsWith("/"))
            {
                url += "/";
            }

            url += newName;
            SetNewUrl(url);

            isUrlAddingMode = true;
        }
Exemplo n.º 18
0
        // called both from game and editor
        public void OpenUrl(string NextUrl, bool forceExecution = false)
        {
            LoadPrefabs();

            counter++;

            Print("Check counter threshold");
            if (counter > counterThreshold)
            {
                Debug.LogError($"INFINITE LOOP: {NextUrl} => {CurrentUrl}");

                return;
            }

            Print("Check infinite loops");
            if (NextUrl.Equals(CurrentUrl) && !forceExecution)
            {
                sameUrlCounter++;

                if (sameUrlCounter > counterThreshold / 2)
                {
                    Debug.LogError($"SAME URL INFINITE LOOP: {CurrentUrl}");
                }

                return;
            }

            sameUrlCounter = 0;

            Print("Check url existance");
            if (!SimpleUI.IsUrlExist(NextUrl))
            {
                SimpleUI.AddMissingUrl(NextUrl, CurrentUrl);
            }

            Print("preRENDER URLS");
            RenderUrls(NextUrl);

            CurrentUrl = NextUrl;
        }
Exemplo n.º 19
0
        void RenderMakeGuidButton()
        {
            bool hasNoGuidAssets = prefabs.Any(p => p.ID == null || p.ID.Length == 0) || GetAllAssetsWithOpenUrl().Any(a => a.URL_ID == null || a.URL_ID.Length == 0);

            if (hasNoGuidAssets)
            {
                Space();
            }

            if (hasNoGuidAssets && Button("Make GUIDS for SimpleUI.txt!"))
            {
                var prefs = SimpleUI.GetPrefabsFromFile();
                for (var i = 0; i < prefs.Count; i++)
                {
                    var pref = prefs[i];

                    pref.SetGUID();
                    BoldPrint($"Setting GUID for {pref.Name} {pref.ID}");

                    UpdatePrefab(pref, i);
                }
            }
        }
Exemplo n.º 20
0
        void DrawProperUrls()
        {
            var openUrl = target as OpenUrl;

            var validatedUrl = SimpleUI.GetValidatedUrl(openUrl.Url);

            // url is obsolete
            if (!prefabs.Exists(p => p.Url.Equals(validatedUrl)) && HasValidGuid(openUrl))
            {
                var index = prefabs.FindIndex(p => p.ID.Equals(openUrl.Url_ID));

                if (index == -1)
                {
                    Debug.LogError("Guid doesnot exist " + openUrl.Url_ID);
                }
                else
                {
                    var prefab = prefabs[index];

                    openUrl.Url = prefab.Url;
                    EditorUtility.SetDirty(openUrl);
                }
            }
        }
Exemplo n.º 21
0
        void FillEmptyGUID()
        {
            var openUrl = target as OpenUrl;

            if (!HasValidGuid(openUrl))
            {
                var url = SimpleUI.GetValidatedUrl(openUrl.Url);

                var index = prefabs.FindIndex(p => p.Url.Equals(url));

                if (index == -1)
                {
                    Debug.LogError($"Prefab for url {url} not found!!");
                }
                else
                {
                    var prefab = prefabs[index];

                    openUrl.Url_ID = prefab.ID;
                    openUrl.Url    = prefab.Url;
                    EditorUtility.SetDirty(openUrl);
                }
            }
        }
Exemplo n.º 22
0
 private void OnEnable()
 {
     prefabs = SimpleUI.GetPrefabsFromFile();
 }
Exemplo n.º 23
0
        void HandleDragAndDrop()
        {
            if (Event.current.type == EventType.DragUpdated)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Event.current.Use();
            }
            else if (Event.current.type == EventType.DragPerform)
            {
                // To consume drag data.
                DragAndDrop.AcceptDrag();

                // GameObjects from hierarchy.
                if (DragAndDrop.paths.Length == 0 && DragAndDrop.objectReferences.Length > 0)
                {
                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        var  go       = obj as GameObject;
                        bool isPrefab = PrefabUtility.GetPrefabAssetType(obj) != PrefabAssetType.NotAPrefab;

                        if (isPrefab)
                        {
                            Debug.Log("prefab - " + obj);

                            HandleDraggedPrefab(go);
                        }
                        else
                        {
                            Debug.Log("GameObject - " + obj);

                            HandleDraggedGameObject(go);
                        }
                    }
                }
                // Object outside project. It mays from File Explorer (Finder in OSX).
                else if (DragAndDrop.paths.Length > 0 && DragAndDrop.objectReferences.Length == 0)
                {
                    Debug.Log("File");
                    foreach (string path in DragAndDrop.paths)
                    {
                        if (SimpleUI.isSceneAsset(path))
                        {
                            Debug.Log("- Dragging Scene! " + path);

                            HandleDraggedScene(path);
                        }
                        else
                        {
                            Debug.Log("- " + path);
                        }
                    }
                }
                // Unity Assets including folder.
                else if (DragAndDrop.paths.Length == DragAndDrop.objectReferences.Length)
                {
                    Debug.Log("UnityAsset");
                    for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
                    {
                        var    obj  = DragAndDrop.objectReferences[i];
                        string path = DragAndDrop.paths[i];
                        Debug.Log(obj.GetType().Name);

                        // Folder.
                        if (obj is DefaultAsset)
                        {
                            Debug.Log(path);
                        }
                        // C# or JavaScript.
                        else if (obj is MonoScript)
                        {
                            Debug.Log(path + "\n" + obj);
                        }
                        else if (obj is Texture2D)
                        {
                        }
                    }
                }
                // Log to make sure we cover all cases.
                else
                {
                    Debug.Log("Out of reach");
                    Debug.Log("Paths:");
                    foreach (string path in DragAndDrop.paths)
                    {
                        Debug.Log("- " + path);
                    }

                    Debug.Log("ObjectReferences:");
                    foreach (var obj in DragAndDrop.objectReferences)
                    {
                        Debug.Log("- " + obj);
                    }
                }
            }
        }
Exemplo n.º 24
0
 void HandleDraggedScene(string path)
 {
     draggedName = SimpleUI.GetPrettyNameFromAssetPath(path);
     draggedPath = path;
     draggedUrl  = newUrl.TrimEnd('/') + "/" + draggedName.TrimStart('/');
 }
Exemplo n.º 25
0
 void OpenCurrentUrl()
 {
     SimpleUI.GetInstance().OpenPrefabByUrl((target as OpenUrl).Url);
 }
Exemplo n.º 26
0
        //SimpleUI _instance = null;
        //SimpleUI Instance
        //{
        //    get
        //    {
        //        if (_instance == null)
        //            _instance = SimpleUI.GetInstance();

        //        return _instance;
        //    }
        //}

        private void LoadPrefabs()
        {
            //if (prefabs == null)
            prefabs = SimpleUI.GetPrefabsFromFile();
        }
Exemplo n.º 27
0
        //void UpdatePrefab(SimpleUISceneType pref)
        //{
        //    SimpleUI.UpdatePrefab(pref);
        //}

        void RenderRenameUrlButton(SimpleUISceneType prefab)
        {
            Space();

            renameUrlRecursively = EditorGUILayout.ToggleLeft("Rename subroutes too", renameUrlRecursively);

            Space();
            if (renameUrlRecursively)
            {
                EditorGUILayout.HelpBox("Renaming this url will lead to renaming these urls too...", MessageType.Warning);
            }
            else
            {
                EditorGUILayout.HelpBox("Will only rename THIS url", MessageType.Warning);
            }

            List <string> RenamingUrls     = new List <string>();
            List <string> RenamingCodeUrls = new List <string>();

            RenamingUrls.Add(prefab.Url);

            if (renameUrlRecursively)
            {
                Space();
                var subroutes = GetSubUrls(prefab.Url, true);

                foreach (var route in subroutes)
                {
                    RenamingUrls.Add(route.Url);
                }

                // render
                foreach (var route in RenamingUrls)
                {
                    BoldLabel(route);
                }
            }

            var phrase = renameUrlRecursively ? "Rename url & subUrls" : "Rename THIS url";

            var matches            = WhatUsesComponent(newUrl, GetAllAssetsWithOpenUrl());
            var referencesFromCode = WhichScriptReferencesConcreteUrl(prefab.Url);

            // references from prefabs & scenes
            var names  = matches.Select(m => $"<b>{SimpleUI.GetPrettyAssetType(m.PrefabAssetPath)}</b> " + SimpleUI.GetTrimmedPath(m.PrefabAssetPath)).ToList();
            var routes = matches.Select(m => m.PrefabAssetPath).ToList();

            // references from code
            foreach (var occurence in referencesFromCode)
            {
                names.Add($"<b>Code</b> {SimpleUI.GetTrimmedPath(occurence.ScriptName)}");
                routes.Add(occurence.ScriptName);
            }

            Space();
            if (Button(phrase))
            {
                if (EditorUtility.DisplayDialog("Do you want to rename url " + prefab.Url, "This action will rename url and subUrls in X prefabs, Y scenes and Z script files.\n\nPRESS CANCEL IF YOU HAVE UNSAVED PREFAB OR SCENE OR CODE CHANGES", "Rename", "Cancel"))
                {
                    Print("Rename starts now!");
                    var prevUrl = newUrl;

                    var changedScripts = new List <string>();

                    // start from grandchilds first
                    foreach (var url in RenamingUrls.OrderByDescending(u => u.Count(c => c.Equals('/'))))
                    {
                        Print("Rename URL " + url);

                        var finalURL = url.Replace(newUrl, newEditingUrl);
                        RenameUrl(url, newUrl, newEditingUrl, finalURL, changedScripts);

                        Print("----------------");
                    }

                    OpenPrefabByUrl(newEditingUrl);
                    if (changedScripts.Any())
                    {
                        OpenAsset(changedScripts.First());
                    }

                    //newUrl = newEditingUrl;
                    //newUrl = prevUrl.Replace(newUrl, newEditingUrl);
                }
            }

            //EditorUtility.DisplayProgressBar("Renaming url", "Info", UnityEngine.Random.Range(0, 1f));
        }
Exemplo n.º 28
0
        static void MovingUsedPrefab(string oldPath, string newPath, List <SimpleUISceneType> prefabs, SimpleUI instance)
        {
            for (var i = 0; i < prefabs.Count; i++)
            {
                var p = prefabs[i];

                //Debug.Log("Checking prefab: " + p.AssetPath);

                if (p.AssetPath.Equals(oldPath))
                {
                    p.AssetPath = newPath;

                    instance.UpdatePrefab(p, i);
                }
            }

            instance.FindMissingAssets();
        }