mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
feat: made PropPlacer its own component
This commit is contained in:
parent
671f0910bf
commit
2ecad16acc
@ -5,11 +5,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
namespace NewHorizons.Utility
|
namespace NewHorizons.Utility
|
||||||
{
|
{
|
||||||
|
|
||||||
class DebugPropPlacer
|
[RequireComponent(typeof(DebugRaycaster))]
|
||||||
|
class DebugPropPlacer : MonoBehaviour
|
||||||
{
|
{
|
||||||
private struct PropPlacementData
|
private struct PropPlacementData
|
||||||
{
|
{
|
||||||
@ -22,16 +24,50 @@ namespace NewHorizons.Utility
|
|||||||
public Vector3 rotation { get { return gameObject.transform.localEulerAngles; } }
|
public Vector3 rotation { get { return gameObject.transform.localEulerAngles; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly string DEFAULT_OBJECT = currentObject = "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 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 static string currentObject = DEFAULT_OBJECT;
|
public string currentObject = DEFAULT_OBJECT;
|
||||||
private static List<PropPlacementData> props = new List<PropPlacementData>();
|
private List<PropPlacementData> props = new List<PropPlacementData>();
|
||||||
private static List<PropPlacementData> deletedProps = new List<PropPlacementData>();
|
private List<PropPlacementData> deletedProps = new List<PropPlacementData>();
|
||||||
|
private DebugRaycaster _rc;
|
||||||
|
|
||||||
// TODO: RegisterProp function, call it in DetailBuilder.MakeDetail
|
private void Awake()
|
||||||
// TODO: Add default rotation and position offsets
|
{
|
||||||
|
_rc = this.GetRequiredComponent<DebugRaycaster>();
|
||||||
|
}
|
||||||
|
|
||||||
public static void PlaceObject(DebugRaycastData data, Vector3 playerAbsolutePosition)
|
private void Update()
|
||||||
|
{
|
||||||
|
if (!Main.Debug) return;
|
||||||
|
|
||||||
|
if (Keyboard.current[Key.Q].wasReleasedThisFrame)
|
||||||
|
{
|
||||||
|
PlaceObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Keyboard.current[Key.Semicolon].wasReleasedThisFrame)
|
||||||
|
{
|
||||||
|
PrintConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Keyboard.current[Key.Minus].wasReleasedThisFrame)
|
||||||
|
{
|
||||||
|
DeleteLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Keyboard.current[Key.Equals].wasReleasedThisFrame)
|
||||||
|
{
|
||||||
|
UndoDelete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void PlaceObject()
|
||||||
|
{
|
||||||
|
DebugRaycastData data = _rc.Raycast();
|
||||||
|
PlaceObject(data, this.gameObject.transform.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlaceObject(DebugRaycastData data, Vector3 playerAbsolutePosition)
|
||||||
{
|
{
|
||||||
if (!data.hitObject.name.EndsWith("_Body"))
|
if (!data.hitObject.name.EndsWith("_Body"))
|
||||||
{
|
{
|
||||||
@ -74,19 +110,6 @@ namespace NewHorizons.Utility
|
|||||||
|
|
||||||
prop.transform.parent = g.transform.parent;
|
prop.transform.parent = g.transform.parent;
|
||||||
GameObject.Destroy(g);
|
GameObject.Destroy(g);
|
||||||
|
|
||||||
//// rotate to face player
|
|
||||||
//var dirTowardsPlayer = prop.transform.parent.transform.InverseTransformPoint(playerAbsolutePosition) - prop.transform.localPosition;
|
|
||||||
//dirTowardsPlayer.z = 0;
|
|
||||||
//float rotation = Quaternion.LookRotation(dirTowardsPlayer).eulerAngles.z;
|
|
||||||
|
|
||||||
//Logger.Log("===");
|
|
||||||
//Logger.Log(dirTowardsPlayer.ToString());
|
|
||||||
//Logger.Log(Quaternion.LookRotation(dirTowardsPlayer).eulerAngles.ToString());
|
|
||||||
//Logger.Log(alignToSurface.ToString());
|
|
||||||
//prop.transform.localEulerAngles = new Vector3(0, alignToSurface.y, alignToSurface.z);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -94,12 +117,12 @@ namespace NewHorizons.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterProp(string bodyGameObjectName, GameObject prop)
|
public void RegisterProp(string bodyGameObjectName, GameObject prop)
|
||||||
{
|
{
|
||||||
RegisterProp_WithReturn(bodyGameObjectName, prop);
|
RegisterProp_WithReturn(bodyGameObjectName, prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PropPlacementData RegisterProp_WithReturn(string bodyGameObjectName, GameObject prop)
|
private PropPlacementData RegisterProp_WithReturn(string bodyGameObjectName, GameObject prop)
|
||||||
{
|
{
|
||||||
if (Main.Debug)
|
if (Main.Debug)
|
||||||
{
|
{
|
||||||
@ -118,7 +141,7 @@ namespace NewHorizons.Utility
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PrintConfig()
|
public void PrintConfig()
|
||||||
{
|
{
|
||||||
var groupedProps = props
|
var groupedProps = props
|
||||||
.GroupBy(p => p.body)
|
.GroupBy(p => p.body)
|
||||||
@ -156,7 +179,7 @@ namespace NewHorizons.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteLast()
|
public void DeleteLast()
|
||||||
{
|
{
|
||||||
if (props.Count <= 0) return;
|
if (props.Count <= 0) return;
|
||||||
|
|
||||||
@ -168,7 +191,7 @@ namespace NewHorizons.Utility
|
|||||||
deletedProps.Add(last);
|
deletedProps.Add(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UndoDelete()
|
public void UndoDelete()
|
||||||
{
|
{
|
||||||
if (deletedProps.Count <= 0) return;
|
if (deletedProps.Count <= 0) return;
|
||||||
|
|
||||||
|
|||||||
@ -18,19 +18,11 @@ namespace NewHorizons.Utility
|
|||||||
private GameObject _normalSphere1;
|
private GameObject _normalSphere1;
|
||||||
private GameObject _normalSphere2;
|
private GameObject _normalSphere2;
|
||||||
|
|
||||||
public string PropToPlace = "BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District1/Props_HangingCity_District1/OtherComponentsGroup/Props_HangingCity_Building_10/Prefab_NOM_VaseThin";
|
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
_rb = this.GetRequiredComponent<OWRigidbody>();
|
_rb = this.GetRequiredComponent<OWRigidbody>();
|
||||||
}
|
}
|
||||||
|
|
||||||
//private void OnGui()
|
|
||||||
//{
|
|
||||||
// //TODO: add gui for stuff https://github.com/Bwc9876/OW-SaveEditor/blob/master/SaveEditor/SaveEditor.cs
|
|
||||||
// // https://docs.unity3d.com/ScriptReference/GUI.TextField.html
|
|
||||||
// GUILayout.BeginArea(new Rect(menuPosition.x, menuPosition.y, EditorMenuSize.x, EditorMenuSize.y), _editorMenuStyle);
|
|
||||||
//}
|
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
@ -41,33 +33,6 @@ namespace NewHorizons.Utility
|
|||||||
{
|
{
|
||||||
PrintRaycast();
|
PrintRaycast();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.current[Key.L].wasReleasedThisFrame)
|
|
||||||
{
|
|
||||||
DebugPropPlacer.currentObject = PropToPlace;
|
|
||||||
PlaceObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Keyboard.current[Key.Semicolon].wasReleasedThisFrame)
|
|
||||||
{
|
|
||||||
DebugPropPlacer.PrintConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Keyboard.current[Key.Minus].wasReleasedThisFrame)
|
|
||||||
{
|
|
||||||
DebugPropPlacer.DeleteLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Keyboard.current[Key.Equals].wasReleasedThisFrame)
|
|
||||||
{
|
|
||||||
DebugPropPlacer.UndoDelete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void PlaceObject()
|
|
||||||
{
|
|
||||||
DebugRaycastData data = Raycast();
|
|
||||||
DebugPropPlacer.PlaceObject(data, this.gameObject.transform.position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void PrintRaycast()
|
internal void PrintRaycast()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user