Beispiel #1
0
        // = { "foo", "foobar" };

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

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

            previousUrl = openUrl.Url;
        }
Beispiel #2
0
        void RenameUrlInScene(OpenUrl component, string newFormattedUrl, GameObject asset)
        {
            // https://forum.unity.com/threads/scripted-scene-changes-not-being-saved.526453/

            component.Url = newFormattedUrl;

            EditorUtility.SetDirty(component);
            EditorSceneManager.SaveScene(asset.scene);
        }
Beispiel #3
0
        void RenameUrlInPrefab(OpenUrl component, string newFormattedUrl, PrefabMatchInfo match)
        {
            // https://forum.unity.com/threads/how-do-i-edit-prefabs-from-scripts.685711/#post-4591885
            using (var editingScope = new PrefabUtility.EditPrefabContentsScope(match.PrefabAssetPath))
            {
                var prefabRoot = editingScope.prefabContentsRoot;

                var prefabbedComponent = prefabRoot.GetComponentsInChildren <OpenUrl>(true)[match.ComponentID];
                prefabbedComponent.Url = newFormattedUrl;

                // https://forum.unity.com/threads/remove-all-missing-components-in-prefabs.897761/
                GameObjectUtility.RemoveMonoBehavioursWithMissingScript(prefabRoot);
            }
        }
Beispiel #4
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();
        }
Beispiel #5
0
        void PickFromDropdown(OpenUrl openUrl)
        {
            _choiceIndex = Array.IndexOf(_choices, openUrl.Url);

            // If the choice is not in the array then the _choiceIndex will be -1 so set back to 0
            if (_choiceIndex < 0)
            {
                _choiceIndex = 0;
            }

            var prevIndex = _choiceIndex;

            _choiceIndex = EditorGUILayout.Popup(_choiceIndex, _choices);

            if (prevIndex != _choiceIndex)
            {
                ChangeUrl(_choices[_choiceIndex]);
            }
        }
Beispiel #6
0
        string GetUrlFormattedToOpenUrl(OpenUrl component, string from, string to)
        {
            bool addedSlash   = false;
            var  formattedUrl = component.Url;

            if (!formattedUrl.StartsWith("/"))
            {
                addedSlash   = true;
                formattedUrl = "/" + formattedUrl;
            }

            var newUrl2 = formattedUrl.Replace(from, to);

            if (addedSlash)
            {
                newUrl2 = newUrl2.TrimStart('/');
            }

            return(newUrl2);
        }
Beispiel #7
0
 bool HasValidGuid(OpenUrl openUrl)
 {
     // openUrl.Url_ID == null || openUrl.Url_ID.Length == 0
     return(openUrl.Url_ID != null && openUrl.Url_ID.Length != 0);
 }