mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
rolled back the 3 section prop placer changes and added spherical positioning
This commit is contained in:
parent
da907bea78
commit
756a08d342
@ -13,7 +13,6 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
class DebugMenuPropPlacer : DebugSubmenu
|
class DebugMenuPropPlacer : DebugSubmenu
|
||||||
{
|
{
|
||||||
private HashSet<string> favoriteProps = new HashSet<string>();
|
private HashSet<string> favoriteProps = new HashSet<string>();
|
||||||
private List<string> favoritePropsList = new List<string>();
|
|
||||||
private List<string> propsLoadedFromConfig = new List<string>();
|
private List<string> propsLoadedFromConfig = new List<string>();
|
||||||
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
|
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";
|
private static readonly string favoritePropsPlayerPrefKey = "FavoriteProps";
|
||||||
@ -21,13 +20,16 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
internal DebugPropPlacer _dpp;
|
internal DebugPropPlacer _dpp;
|
||||||
internal DebugRaycaster _drc;
|
internal DebugRaycaster _drc;
|
||||||
|
|
||||||
|
// misc
|
||||||
|
private GameObject sphericalPlacer;
|
||||||
|
private GameObject mostRecentlyPlacedProp;
|
||||||
|
private Vector3 mostRecentlyPlacedPropSphericalPos;
|
||||||
|
|
||||||
// menu params
|
// menu params
|
||||||
private Vector2 favoritePropsScrollPosition = Vector2.zero;
|
|
||||||
private bool favoritePropsCollapsed = false;
|
|
||||||
private Vector2 recentPropsScrollPosition = Vector2.zero;
|
private Vector2 recentPropsScrollPosition = Vector2.zero;
|
||||||
private bool recentPropsCollapsed = false;
|
private bool propsCollapsed = false;
|
||||||
private Vector2 configPropsScrollPosition = Vector2.zero;
|
private Vector3 propPosDelta = new Vector3(0.1f, 0.1f, 0.1f);
|
||||||
private bool configPropsCollapsed = true;
|
private Vector3 propSphericalPosDelta = new Vector3(0.1f, 0.1f, 0.1f);
|
||||||
|
|
||||||
internal override string SubmenuName()
|
internal override string SubmenuName()
|
||||||
{
|
{
|
||||||
@ -38,6 +40,8 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
{
|
{
|
||||||
_dpp = menu.GetComponent<DebugPropPlacer>();
|
_dpp = menu.GetComponent<DebugPropPlacer>();
|
||||||
_drc = menu.GetComponent<DebugRaycaster>();
|
_drc = menu.GetComponent<DebugRaycaster>();
|
||||||
|
|
||||||
|
sphericalPlacer = new GameObject("Prop Placer Spherical Coords Helper");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void OnAwake(DebugMenu menu)
|
internal override void OnAwake(DebugMenu menu)
|
||||||
@ -76,11 +80,9 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
var favoritePropPaths = favoritePropsPlayerPref.Split(separatorCharacter);
|
var favoritePropPaths = favoritePropsPlayerPref.Split(separatorCharacter);
|
||||||
foreach (string favoriteProp in favoritePropPaths)
|
foreach (string favoriteProp in favoritePropPaths)
|
||||||
{
|
{
|
||||||
// DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp);
|
DebugPropPlacer.RecentlyPlacedProps.Add(favoriteProp);
|
||||||
this.favoriteProps.Add(favoriteProp);
|
this.favoriteProps.Add(favoriteProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
favoritePropsList = favoriteProps.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void OnGUI(DebugMenu menu)
|
internal override void OnGUI(DebugMenu menu)
|
||||||
@ -92,36 +94,103 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
_dpp.SetCurrentObject(GUILayout.TextArea(_dpp.currentObject));
|
_dpp.SetCurrentObject(GUILayout.TextArea(_dpp.currentObject));
|
||||||
|
|
||||||
GUILayout.Space(5);
|
GUILayout.Space(5);
|
||||||
|
|
||||||
var favoriteMenu = PropsList(menu, favoritePropsList, favoritePropsCollapsed, favoritePropsScrollPosition, "Favorite Props");
|
|
||||||
favoritePropsCollapsed = favoriteMenu.collapsed;
|
|
||||||
favoritePropsScrollPosition = favoriteMenu.scroll;
|
|
||||||
GUILayout.Space(5);
|
|
||||||
|
|
||||||
var recentMenu = PropsList(menu, DebugPropPlacer.RecentlyPlacedProps, recentPropsCollapsed, recentPropsScrollPosition, "Recently Placed Props");
|
|
||||||
recentPropsCollapsed= recentMenu.collapsed;
|
|
||||||
recentPropsScrollPosition = recentMenu.scroll;
|
|
||||||
GUILayout.Space(5);
|
|
||||||
|
|
||||||
var configMenu = PropsList(menu, propsLoadedFromConfig, configPropsCollapsed, configPropsScrollPosition, "Props Loaded From Configs");
|
|
||||||
configPropsCollapsed = configMenu.collapsed;
|
|
||||||
configPropsScrollPosition = configMenu.scroll;
|
|
||||||
GUILayout.Space(5);
|
GUILayout.Space(5);
|
||||||
|
|
||||||
|
|
||||||
|
var arrow = propsCollapsed ? " > " : " v ";
|
||||||
|
if (GUILayout.Button(arrow + "Recently placed objects", menu._tabBarStyle)) propsCollapsed = !propsCollapsed;
|
||||||
|
if (!propsCollapsed) DrawPropsList(menu);
|
||||||
|
GUILayout.Space(5);
|
||||||
|
|
||||||
|
if (_dpp.mostRecentlyPlacedPropGO != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
var propPath = _dpp.mostRecentlyPlacedPropPath;
|
||||||
|
var propPathElements = propPath[propPath.Length-1] == '/'
|
||||||
|
? propPath.Substring(0, propPath.Length-1).Split('/')
|
||||||
|
: propPath.Split('/');
|
||||||
|
string propName = propPathElements[propPathElements.Length - 1];
|
||||||
|
GUILayout.Label($"Reposition {propName}: ");
|
||||||
|
|
||||||
|
Vector3 latestPropPosDelta = VectorInput(_dpp.mostRecentlyPlacedPropGO.transform.localPosition, propPosDelta, out propPosDelta, "x", "y", "z");
|
||||||
|
_dpp.mostRecentlyPlacedPropGO.transform.localPosition += latestPropPosDelta;
|
||||||
|
|
||||||
|
GUILayout.Space(5);
|
||||||
|
|
||||||
|
|
||||||
|
if (mostRecentlyPlacedProp != _dpp.mostRecentlyPlacedPropGO)
|
||||||
|
{
|
||||||
|
mostRecentlyPlacedProp = _dpp.mostRecentlyPlacedPropGO;
|
||||||
|
mostRecentlyPlacedPropSphericalPos = DeltaSphericalPosition(mostRecentlyPlacedProp, Vector3.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct PropsListReturn { public bool collapsed; public Vector2 scroll; }
|
Vector3 latestPropSphericalPosDelta = VectorInput(mostRecentlyPlacedPropSphericalPos, propSphericalPosDelta, out propSphericalPosDelta, "lat ", "lon ", "height");
|
||||||
private PropsListReturn PropsList(DebugMenu menu, IEnumerable<string> props, bool collapsed, Vector2 scroll, string title)
|
if (latestPropPosDelta != Vector3.zero)
|
||||||
{
|
{
|
||||||
GUILayout.BeginVertical(menu._editorMenuStyle);
|
mostRecentlyPlacedPropSphericalPos = DeltaSphericalPosition(mostRecentlyPlacedProp, latestPropSphericalPosDelta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var arrow = collapsed ? " > " : " v ";
|
private Vector3 DeltaSphericalPosition(GameObject go, Vector3 deltaSpherical)
|
||||||
if (GUILayout.Button(arrow + title, menu._submenuStyle)) collapsed = !collapsed;
|
{
|
||||||
if (collapsed) return new PropsListReturn() { collapsed=collapsed, scroll=scroll };
|
sphericalPlacer.transform.parent = _dpp.mostRecentlyPlacedPropGO.transform.parent;
|
||||||
|
sphericalPlacer.transform.localPosition = Vector3.zero;
|
||||||
|
sphericalPlacer.transform.LookAt(_dpp.mostRecentlyPlacedPropGO.transform.localPosition);
|
||||||
|
sphericalPlacer.transform.localEulerAngles = new Vector3(sphericalPlacer.transform.localEulerAngles.x, sphericalPlacer.transform.localEulerAngles.y, 0);
|
||||||
|
|
||||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(menu.EditorMenuSize.x), GUILayout.Height(500));
|
go.transform.parent = sphericalPlacer.transform;
|
||||||
foreach (string propPath in props)
|
|
||||||
|
Vector3 currentSpherical = sphericalPlacer.transform.localEulerAngles + new Vector3(0,0, go.transform.localPosition.z); // lat, lon, height
|
||||||
|
|
||||||
|
sphericalPlacer.transform.localEulerAngles += new Vector3(deltaSpherical.x, deltaSpherical.y, 0);
|
||||||
|
_dpp.mostRecentlyPlacedPropGO.transform.localPosition += new Vector3(0, 0, deltaSpherical.z);
|
||||||
|
|
||||||
|
_dpp.mostRecentlyPlacedPropGO.transform.parent = sphericalPlacer.transform.parent;
|
||||||
|
|
||||||
|
return currentSpherical+deltaSpherical;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector3 VectorInput(Vector3 input, Vector3 deltaControls, out Vector3 deltaControlsOut, string labelX, string labelY, string labelZ)
|
||||||
|
{
|
||||||
|
var dx = deltaControls.x;
|
||||||
|
var dy = deltaControls.y;
|
||||||
|
var dz = deltaControls.z;
|
||||||
|
|
||||||
|
// x
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
GUILayout.Label(labelX+": ", GUILayout.Width(50));
|
||||||
|
float deltaX = float.Parse(GUILayout.TextField(input.x+"", GUILayout.Width(50))) - input.x;
|
||||||
|
if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) deltaX += dx;
|
||||||
|
if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaX -= dx;
|
||||||
|
dx = float.Parse(GUILayout.TextField(dx+"", GUILayout.Width(100)));
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
// y
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
GUILayout.Label(labelY+": ", GUILayout.Width(50));
|
||||||
|
float deltaY = float.Parse(GUILayout.TextField(input.y+"", GUILayout.Width(50))) - input.y;
|
||||||
|
if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) deltaY += dy;
|
||||||
|
if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaY -= dy;
|
||||||
|
dy = float.Parse(GUILayout.TextField(dy+"", GUILayout.Width(100)));
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
// z
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
GUILayout.Label(labelZ+": ", GUILayout.Width(50));
|
||||||
|
float deltaZ = float.Parse(GUILayout.TextField(input.z+"", GUILayout.Width(50))) - input.z;
|
||||||
|
if (GUILayout.Button("+", GUILayout.ExpandWidth(false))) deltaZ += dz;
|
||||||
|
if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) deltaZ -= dz;
|
||||||
|
dz = float.Parse(GUILayout.TextField(dz+"", GUILayout.Width(100)));
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
deltaControlsOut = new Vector3(dx, dy, dz);
|
||||||
|
return new Vector3(deltaX, deltaY, deltaZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawPropsList(DebugMenu menu)
|
||||||
|
{
|
||||||
|
// List of recently placed objects
|
||||||
|
recentPropsScrollPosition = GUILayout.BeginScrollView(recentPropsScrollPosition, GUILayout.Width(menu.EditorMenuSize.x), GUILayout.Height(500));
|
||||||
|
foreach (string propPath in DebugPropPlacer.RecentlyPlacedProps)
|
||||||
{
|
{
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
@ -146,7 +215,7 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
PlayerPrefs.SetString(favoritePropsPlayerPrefKey, string.Join(separatorCharacter + "", favoritePropsArray));
|
PlayerPrefs.SetString(favoritePropsPlayerPrefKey, string.Join(separatorCharacter + "", favoritePropsArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GUILayout.Button(propName, GUILayout.ExpandWidth(true)))
|
if (GUILayout.Button(propName))
|
||||||
{
|
{
|
||||||
_dpp.SetCurrentObject(propPath);
|
_dpp.SetCurrentObject(propPath);
|
||||||
}
|
}
|
||||||
@ -154,9 +223,6 @@ namespace NewHorizons.Utility.DebugMenu
|
|||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
GUILayout.EndScrollView();
|
GUILayout.EndScrollView();
|
||||||
GUILayout.EndVertical();
|
|
||||||
|
|
||||||
return new PropsListReturn() { collapsed=collapsed, scroll=scroll };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void PreSave(DebugMenu menu)
|
internal override void PreSave(DebugMenu menu)
|
||||||
|
|||||||
@ -39,6 +39,8 @@ namespace NewHorizons.Utility.DebugUtilities
|
|||||||
public static HashSet<string> RecentlyPlacedProps = new HashSet<string>();
|
public static HashSet<string> RecentlyPlacedProps = new HashSet<string>();
|
||||||
|
|
||||||
public static bool active = false;
|
public static bool active = false;
|
||||||
|
public GameObject mostRecentlyPlacedPropGO { get { return props.Count() <= 0 ? null : props[props.Count()-1].gameObject; } }
|
||||||
|
public string mostRecentlyPlacedPropPath { get { return props.Count() <= 0 ? "" : props[props.Count()-1].detailInfo.path; } }
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user