1
0
mirror of https://github.com/originalnicodr/CinematicUnityExplorer.git synced 2026-10-10 04:53:15 +08:00

Added option to make the camera follow an in-game object. Also made a toggle to block the freecam from moving with user input.

This commit is contained in:
originalnicodr
2024-01-10 23:24:44 -03:00
parent ac7024bf74
commit b3580e69b3
6 changed files with 51 additions and 12 deletions
+1
View File
@@ -351,3 +351,4 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
build-bep5mono.ps1
+9 -6
View File
@@ -44,6 +44,7 @@ namespace UnityExplorer.Inspectors
public override Vector2 DefaultAnchorMax => Vector2.zero;
public override bool CanDragAndResize => false;
private Action<GameObject> inspectorAction = null;
internal Text objNameLabel;
internal Text objPathLabel;
@@ -61,13 +62,13 @@ namespace UnityExplorer.Inspectors
switch (index)
{
case 0: return;
case 1: Instance.StartInspect(MouseInspectMode.World); break;
case 2: Instance.StartInspect(MouseInspectMode.UI); break;
case 1: Instance.StartInspect(MouseInspectMode.World, (obj) => InspectorManager.Inspect(obj, null)); break;
case 2: Instance.StartInspect(MouseInspectMode.UI, (obj) => InspectorManager.Inspect(obj, null)); break;
}
InspectorPanel.Instance.MouseInspectDropdown.value = 0;
}
public void StartInspect(MouseInspectMode mode)
public void StartInspect(MouseInspectMode mode, Action<GameObject> newInspectorAction)
{
Mode = mode;
Inspecting = true;
@@ -80,6 +81,8 @@ namespace UnityExplorer.Inspectors
UIManager.UiBase.SetOnTop();
SetActive(true);
inspectorAction = newInspectorAction;
}
internal void ClearHitData()
@@ -111,10 +114,10 @@ namespace UnityExplorer.Inspectors
public bool TryUpdate()
{
if (InputManager.GetKeyDown(ConfigManager.World_MouseInspect_Keybind.Value))
Instance.StartInspect(MouseInspectMode.World);
Instance.StartInspect(MouseInspectMode.World, inspectorAction);
if (InputManager.GetKeyDown(ConfigManager.UI_MouseInspect_Keybind.Value))
Instance.StartInspect(MouseInspectMode.UI);
Instance.StartInspect(MouseInspectMode.UI, inspectorAction);
if (Inspecting)
UpdateInspect();
@@ -132,7 +135,7 @@ namespace UnityExplorer.Inspectors
if (InputManager.GetMouseButtonDown(0))
{
CurrentInspector.OnSelectMouseInspect();
CurrentInspector.OnSelectMouseInspect(inspectorAction);
StopInspect();
return;
}
@@ -6,7 +6,7 @@
public abstract void UpdateMouseInspect(Vector2 mousePos);
public abstract void OnSelectMouseInspect();
public abstract void OnSelectMouseInspect(Action<GameObject> inspectorAction);
public abstract void ClearHitData();
@@ -28,8 +28,9 @@ namespace UnityExplorer.Inspectors.MouseInspectors
currentHitObjects.Clear();
}
public override void OnSelectMouseInspect()
public override void OnSelectMouseInspect(Action<GameObject> inspectorAction)
{
// need to properly handle inspectorAction here
LastHitObjects.Clear();
LastHitObjects.AddRange(currentHitObjects);
RuntimeHelper.StartCoroutine(SetPanelActiveCoro());
@@ -21,9 +21,9 @@
lastHitObject = null;
}
public override void OnSelectMouseInspect()
public override void OnSelectMouseInspect(Action<GameObject> inspectorAction)
{
InspectorManager.Inspect(lastHitObject);
inspectorAction(lastHitObject);
}
public override void UpdateMouseInspect(Vector2 mousePos)
+36 -2
View File
@@ -1,4 +1,5 @@
using UniverseLib.Input;
using UnityExplorer.Inspectors;
using UniverseLib.UI;
using UniverseLib.UI.Models;
#if UNHOLLOWER
@@ -45,6 +46,7 @@ namespace UnityExplorer.UI.Panels
static ButtonRef startStopButton;
static Toggle useGameCameraToggle;
public static Toggle blockFreecamMovementToggle;
static InputFieldRef positionInput;
static InputFieldRef moveSpeedInput;
static ButtonRef inspectButton;
@@ -184,11 +186,11 @@ namespace UnityExplorer.UI.Panels
AddSpacer(5);
GameObject toggleObj = UIFactory.CreateToggle(ContentRoot, "UseGameCameraToggle", out useGameCameraToggle, out Text toggleText);
GameObject toggleObj = UIFactory.CreateToggle(ContentRoot, "UseGameCameraToggle", out useGameCameraToggle, out Text useGameCameraText);
UIFactory.SetLayoutElement(toggleObj, minHeight: 25, flexibleWidth: 9999);
useGameCameraToggle.onValueChanged.AddListener(OnUseGameCameraToggled);
useGameCameraToggle.isOn = false;
toggleText.text = "Use Game Camera?";
useGameCameraText.text = "Use Game Camera?";
AddSpacer(5);
@@ -205,6 +207,21 @@ namespace UnityExplorer.UI.Panels
AddSpacer(5);
ButtonRef followButton = UIFactory.CreateButton(ContentRoot, "FollowButton", "Make camera Follow Gameobject");
UIFactory.SetLayoutElement(followButton.GameObject, minWidth: 150, minHeight: 25, flexibleWidth: 9999);
followButton.OnClick += FollowButton_OnClick;
AddSpacer(5);
GameObject blockFreecamMovement = UIFactory.CreateToggle(ContentRoot, "blockFreecamMovement", out blockFreecamMovementToggle, out Text blockFreecamMovementText);
UIFactory.SetLayoutElement(blockFreecamMovement, minHeight: 25, flexibleWidth: 9999);
blockFreecamMovementToggle.onValueChanged.AddListener(OnUseGameCameraToggled);
blockFreecamMovementToggle.isOn = false;
blockFreecamMovementText.text = "Block Freecam movement";
AddSpacer(5);
string instructions = @"Controls:
- WASD / Arrows: Movement
- Space / PgUp: Move up
@@ -260,6 +277,19 @@ namespace UnityExplorer.UI.Panels
SetToggleButtonState();
}
void temporalAction(GameObject obj){
if(!ourCamera){
ExplorerCore.LogWarning("Error: Start the freecam at least once before setting a follow object.");
return;
}
ourCamera.transform.SetParent(obj.transform, true);
}
void FollowButton_OnClick()
{
MouseInspector.Instance.StartInspect(MouseInspectMode.World, temporalAction);
}
void SetToggleButtonState()
{
if (inFreeCamMode)
@@ -349,6 +379,10 @@ namespace UnityExplorer.UI.Panels
return;
}
if (FreeCamPanel.blockFreecamMovementToggle.isOn){
return;
}
Transform transform = FreeCamPanel.ourCamera.transform;
FreeCamPanel.currentUserCameraPosition = transform.position;