public bool InFavorites(FavoriteObject @object) { var res = myList.Any(x => x.ID == @object.ID); Debug.Log(res ? "Var" : "Yok"); return(res); }
static FavoriteObject ObjectInQuestion(Object selected) { var instID = selected.GetInstanceID(); var Fav = new FavoriteObject(); Fav.ID = instID; var prefab = PrefabUtility.GetCorrespondingObjectFromSource(selected); Fav.AssetPath = AssetDatabase.GetAssetPath(prefab); var isPrefab = prefab != null; if (isPrefab) { Fav.Type = FavoriteObject.AssetType.Prefab; Fav.ObjectName = Path.GetFileName(Fav.AssetPath); } else { Fav.Type = FavoriteObject.AssetType.SceneObject; Fav.ObjectName = selected.name; } //Fav.Type = FavoriteObject.AssetType.ProjectAsset; Fav.Project = FavoritesWindow.GetProjectName(); return(Fav); }
public void AddToFavorite(FavoriteObject @object) { Repaint(); myList.Add(@object); var jsonstring = JsonUtility.ToJson(myList.ToArray()); System.IO.File.WriteAllText(PersDatPat + "/Dev-Favorites.json", jsonstring); }
public void RemoveFromFavorite(FavoriteObject @object) { var i = myList.FindIndex(x => x.ID == @object.ID); myList.RemoveAt(i); var jsonstring = JsonUtility.ToJson(myList.ToArray()); System.IO.File.WriteAllText(PersDatPat + "/Dev-Favorites.json", jsonstring); }
private void OnGUI() { var color_default = GUI.backgroundColor; var color_selected = Color.gray; var e = Event.current; if (contextOpen) { var menu = CreateMenu(); menu.ShowAsContext(); contextOpen = false; } scroll = EditorGUILayout.BeginScrollView(scroll); for (int i = 0; i < myList.Count; i++) { FavoriteObject item = myList[i]; if (item.Project != GetProjectName()) { continue; } GUI.backgroundColor = (selectedIndex == i) ? color_selected : Color.clear; var r = EditorGUILayout.BeginHorizontal(GetWrapperItemStyle()); GUI.Label(r, GUIContent.none); if (GUI.Button(r, GUIContent.none, GetWrapperItemStyle())) { selectedIndex = i; if (e.clickCount == 1) { EditorGUIUtility.PingObject(item.ID); } if ((EditorApplication.timeSinceStartup - clickTime) < doubleClickTime) { OpenFile(item); } if (r.Contains(e.mousePosition) && e.type == EventType.Used && e.button == 1) { contextOpen = true; e.Use(); } clickTime = EditorApplication.timeSinceStartup; } //Favori tipine göre icon bul Texture2D texture = UnityEditorInternal.InternalEditorUtility.GetIconForFile(item.ObjectName); var textureContent = new GUIContent(texture); GUILayout.Box(textureContent, GetIconStyle()); GUILayout.Label(myList[i].ObjectName, GetLabelStyle()); EditorGUILayout.EndHorizontal(); GUI.backgroundColor = color_default; //this is to avoid affecting other GUIs outside of the list } EditorGUILayout.EndScrollView(); }
static FavoriteObject ObjectInQuestion(Object selected) { var instID = selected.GetInstanceID(); var Fav = new FavoriteObject(); Fav.ID = instID; Fav.Type = FavoriteObject.AssetType.ProjectAsset; Fav.AssetPath = AssetDatabase.GetAssetPath(selected); Fav.Project = FavoritesWindow.GetProjectName(); Fav.ObjectName = Path.GetFileName(Fav.AssetPath); return(Fav); }
void OpenFile(FavoriteObject item) { var x = item.ObjectName.Split('.'); var ext = x[x.Length - 1]; switch (ext) { case "prefab": AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath(item.AssetPath, typeof(GameObject))); break; case "cs": AssetDatabase.OpenAsset(item.ID, 0, 0); break; case "unity": EditorSceneManager.OpenScene(item.AssetPath); break; default: break; } }