feat: added list of buttons to select recently placed props

This commit is contained in:
FreezeDriedMangoes 2022-05-13 11:01:06 -04:00
parent c126f52123
commit 87c61f4189
2 changed files with 50 additions and 4 deletions

View File

@ -19,6 +19,9 @@ namespace NewHorizons.Utility
DebugPropPlacer _dpp;
DebugRaycaster _drc;
// menu params
private Vector2 recentPropsScrollPosition = Vector2.zero;
private void Awake()
{
_dpp = this.GetRequiredComponent<DebugPropPlacer>();
@ -47,9 +50,31 @@ namespace NewHorizons.Utility
// https://docs.unity3d.com/ScriptReference/GUI.TextField.html
GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle);
_dpp.currentObject = GUILayout.TextArea(_dpp.currentObject);
//
// DebugPropPlacer
//
GUILayout.Label("Recently placed objects");
_dpp.SetCurrentObject(GUILayout.TextArea(_dpp.currentObject));
GUILayout.Space(5);
// TODO: maintain list of objects here
// List of recently placed objects
GUILayout.Label("Recently placed objects");
recentPropsScrollPosition = GUILayout.BeginScrollView(recentPropsScrollPosition, GUILayout.Width(EditorMenuSize.x), GUILayout.Height(100));
foreach (string propPath in _dpp.RecentlyPlacedProps)
{
var propPathElements = propPath.Split('/');
if (GUILayout.Button(propPathElements[propPathElements.Length-1]))
{
_dpp.SetCurrentObject(propPath);
}
}
GUILayout.EndScrollView();
// TODO: maintain list of recently placed objects here
// TODO: field to provide name of mod to load configs from, plus button to load those into the PropPlaecr (make sure not to load more than once, once the button has been pushed, disable it)
// TODO: add a warning that the button cannot be pushed more than once

View File

@ -24,16 +24,21 @@ namespace NewHorizons.Utility
public Vector3 rotation { get { return gameObject.transform.localEulerAngles; } }
}
// DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_1/Props_DreamZone_1/OtherComponentsGroup/Trees_Z1/DreamHouseIsland/Tree_DW_M_Var
public static readonly string DEFAULT_OBJECT = "BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District1/Props_HangingCity_District1/OtherComponentsGroup/Props_HangingCity_Building_10/Prefab_NOM_VaseThin";
public string currentObject = DEFAULT_OBJECT;
public string currentObject { get; private set; }
private bool hasAddedCurrentObjectToRecentsList = false;
private List<PropPlacementData> props = new List<PropPlacementData>();
private List<PropPlacementData> deletedProps = new List<PropPlacementData>();
private DebugRaycaster _rc;
public List<string> RecentlyPlacedProps = new List<string>();
private void Awake()
{
_rc = this.GetRequiredComponent<DebugRaycaster>();
currentObject = DEFAULT_OBJECT;
}
private void Update()
@ -61,10 +66,26 @@ namespace NewHorizons.Utility
}
}
public void SetCurrentObject(string s)
{
currentObject = s;
hasAddedCurrentObjectToRecentsList = false;
}
internal void PlaceObject()
{
DebugRaycastData data = _rc.Raycast();
PlaceObject(data, this.gameObject.transform.position);
if (!hasAddedCurrentObjectToRecentsList)
{
hasAddedCurrentObjectToRecentsList = true;
if (!RecentlyPlacedProps.Contains(currentObject))
{
RecentlyPlacedProps.Add(currentObject);
}
}
}
public void PlaceObject(DebugRaycastData data, Vector3 playerAbsolutePosition)
@ -80,7 +101,7 @@ namespace NewHorizons.Utility
if (currentObject == "" || currentObject == null)
{
currentObject = DEFAULT_OBJECT;
SetCurrentObject(DEFAULT_OBJECT);
}
GameObject prop = DetailBuilder.MakeDetail(data.hitObject, data.hitObject.GetComponentInChildren<Sector>(), currentObject, data.pos, data.norm, 1, false);