using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace NewHorizons.Utility.DebugUtilities { class DebugMenuPropPlacer : DebugSubmenu { private Vector2 recentPropsScrollPosition = Vector2.zero; private HashSet favoriteProps = new HashSet(); public static readonly char separatorCharacter = '☧'; // since no chars are illegal in game object names, I picked one that's extremely unlikely to be used to be a separator private static readonly string favoritePropsPlayerPrefKey = "FavoriteProps"; internal override string SubmenuName() { return "Prop Placer"; } internal override void OnAwake(DebugMenu menu) { LoadFavoriteProps(); } private void LoadFavoriteProps() { string favoritePropsPlayerPref = PlayerPrefs.GetString(favoritePropsPlayerPrefKey); if (favoritePropsPlayerPref == null || favoritePropsPlayerPref == "") return; var favoritePropPaths = favoritePropsPlayerPref.Split(separatorCharacter); foreach (string favoriteProp in favoritePropPaths) { DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp); this.favoriteProps.Add(favoriteProp); } } internal override void OnGUI(DebugMenu menu) { // // DebugPropPlacer // GUILayout.Label("Currently placing: "); menu._dpp.SetCurrentObject(GUILayout.TextArea(menu._dpp.currentObject)); GUILayout.Space(5); // List of recently placed objects GUILayout.Label("Recently placed objects"); recentPropsScrollPosition = GUILayout.BeginScrollView(recentPropsScrollPosition, GUILayout.Width(menu.EditorMenuSize.x), GUILayout.Height(500)); foreach (string propPath in DebugPropPlacer.RecentlyPlacedProps) { GUILayout.BeginHorizontal(); var propPathElements = propPath[propPath.Length-1] == '/' ? propPath.Substring(0, propPath.Length-1).Split('/') : propPath.Split('/'); string propName = propPathElements[propPathElements.Length - 1]; string favoriteButtonIcon = favoriteProps.Contains(propPath) ? "★" : "☆"; if (GUILayout.Button(favoriteButtonIcon, GUILayout.ExpandWidth(false))) { if (favoriteProps.Contains(propPath)) { favoriteProps.Remove(propPath); } else { favoriteProps.Add(propPath); } string[] favoritePropsArray = favoriteProps.ToArray(); PlayerPrefs.SetString(favoritePropsPlayerPrefKey, string.Join(separatorCharacter + "", favoritePropsArray)); } if (GUILayout.Button(propName)) { menu._dpp.SetCurrentObject(propPath); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.Space(5); } } }