mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2025-07-19 01:57:56 +08:00
Enhanced the camera selection logic on the world mouse inspector. Also fixed the camera coordinates not being displayed properly.
Based on the work of @p1xel8ted on https://github.com/yukieiji/UnityExplorer/pull/35.
This commit is contained in:
@ -46,9 +46,10 @@ namespace UnityExplorer.Inspectors
|
||||
public override bool CanDragAndResize => false;
|
||||
private Action<GameObject> inspectorAction = null;
|
||||
|
||||
internal Text objNameLabel;
|
||||
internal Text objPathLabel;
|
||||
internal Text mousePosLabel;
|
||||
private Text inspectorLabelTitle;
|
||||
private Text objNameLabel;
|
||||
private Text objPathLabel;
|
||||
private Text mousePosLabel;
|
||||
|
||||
public MouseInspector(UIBase owner) : base(owner)
|
||||
{
|
||||
@ -125,6 +126,43 @@ namespace UnityExplorer.Inspectors
|
||||
return Inspecting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the title text in the inspector UI, if the inspector title label is assigned.
|
||||
/// </summary>
|
||||
/// <param name="title">The new title text to display in the inspector.</param>
|
||||
internal void UpdateInspectorTitle(string title)
|
||||
{
|
||||
// Unity null check - if inspectorLabelTitle is assigned, update its text.
|
||||
if (inspectorLabelTitle)
|
||||
{
|
||||
inspectorLabelTitle.text = title;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the object name label in the inspector UI, if the label is assigned.
|
||||
/// </summary>
|
||||
/// <param name="name">The new object name to display.</param>
|
||||
internal void UpdateObjectNameLabel(string name)
|
||||
{
|
||||
// Unity null check - if objNameLabel is assigned, update its text.
|
||||
if (objNameLabel)
|
||||
{
|
||||
objNameLabel.text = name;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Updates the object path label in the inspector UI, if the label is assigned.
|
||||
/// </summary>
|
||||
/// <param name="path">The new object path to display.</param>
|
||||
internal void UpdateObjectPathLabel(string path)
|
||||
{
|
||||
// Unity null check - if objPathLabel is assigned, update its text.
|
||||
if (objPathLabel)
|
||||
{
|
||||
objPathLabel.text = path;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateInspect()
|
||||
{
|
||||
if (IInputManager.GetKeyDown(KeyCode.Escape))
|
||||
@ -156,7 +194,7 @@ namespace UnityExplorer.Inspectors
|
||||
lastMousePos = mousePos;
|
||||
|
||||
// use the raw mouse pos for the label
|
||||
mousePosLabel.text = $"<color=grey>Mouse Position:</color> {mousePos.ToString()}";
|
||||
mousePosLabel.text = $"<color=grey>Mouse Position:</color> {mousePos.x}, {mousePos.y}";
|
||||
|
||||
// constrain the mouse pos we use within certain bounds
|
||||
if (mousePos.x < 350)
|
||||
@ -196,11 +234,11 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
// Title text
|
||||
|
||||
Text title = UIFactory.CreateLabel(inspectContent,
|
||||
inspectorLabelTitle = UIFactory.CreateLabel(inspectContent,
|
||||
"InspectLabel",
|
||||
"<b>Mouse Inspector</b> (press <b>ESC</b> to cancel)",
|
||||
"",
|
||||
TextAnchor.MiddleCenter);
|
||||
UIFactory.SetLayoutElement(title.gameObject, flexibleWidth: 9999);
|
||||
UIFactory.SetLayoutElement(inspectorLabelTitle.gameObject, flexibleWidth: 9999);
|
||||
|
||||
mousePosLabel = UIFactory.CreateLabel(inspectContent, "MousePosLabel", "Mouse Position:", TextAnchor.MiddleCenter);
|
||||
|
||||
|
@ -17,10 +17,13 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
||||
private static readonly List<CanvasGroup> wasDisabledCanvasGroups = new();
|
||||
private static readonly List<GameObject> objectsAddedCastersTo = new();
|
||||
|
||||
private const string DEFAULT_INSPECTOR_TITLE = "<b>UI Inspector</b> (press <b>ESC</b> to cancel)";
|
||||
|
||||
public override void OnBeginMouseInspect()
|
||||
{
|
||||
SetupUIRaycast();
|
||||
MouseInspector.Instance.objPathLabel.text = "";
|
||||
MouseInspector.Instance.UpdateInspectorTitle(DEFAULT_INSPECTOR_TITLE);
|
||||
MouseInspector.Instance.UpdateObjectPathLabel("");
|
||||
}
|
||||
|
||||
public override void ClearHitData()
|
||||
@ -71,9 +74,9 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
||||
}
|
||||
|
||||
if (currentHitObjects.Any())
|
||||
MouseInspector.Instance.objNameLabel.text = $"Click to view UI Objects under mouse: {currentHitObjects.Count}";
|
||||
MouseInspector.Instance.UpdateObjectNameLabel($"Click to view UI Objects under mouse: {currentHitObjects.Count}");
|
||||
else
|
||||
MouseInspector.Instance.objNameLabel.text = $"No UI objects under mouse.";
|
||||
MouseInspector.Instance.UpdateObjectNameLabel( $"No UI objects under mouse.");
|
||||
}
|
||||
|
||||
private static void SetupUIRaycast()
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace UnityExplorer.Inspectors.MouseInspectors
|
||||
using UnityExplorer.UI.Panels;
|
||||
|
||||
namespace UnityExplorer.Inspectors.MouseInspectors
|
||||
{
|
||||
public class WorldInspector : MouseInspectorBase
|
||||
{
|
||||
@ -7,15 +9,26 @@
|
||||
|
||||
public override void OnBeginMouseInspect()
|
||||
{
|
||||
MainCamera = Camera.main;
|
||||
|
||||
if (!MainCamera)
|
||||
if (!EnsureMainCamera())
|
||||
{
|
||||
ExplorerCore.LogWarning("No MainCamera found! Cannot inspect world!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assigns it as the MainCamera and updates the inspector title.
|
||||
/// </summary>
|
||||
/// <param name="cam">The camera to assign.</param>
|
||||
private static void AssignCamAndUpdateTitle(Camera cam)
|
||||
{
|
||||
MainCamera = cam;
|
||||
MouseInspector.Instance.UpdateInspectorTitle(
|
||||
$"<b>World Inspector ({MainCamera.name})</b> (press <b>ESC</b> to cancel)"
|
||||
);
|
||||
}
|
||||
|
||||
public override void ClearHitData()
|
||||
{
|
||||
lastHitObject = null;
|
||||
@ -26,11 +39,52 @@
|
||||
inspectorAction(lastHitObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to ensure that MainCamera is assigned. If not then attempts to find it.
|
||||
/// If no cameras are available, logs a warning and returns null.
|
||||
/// </summary>
|
||||
private static Camera EnsureMainCamera()
|
||||
{
|
||||
if (MainCamera){
|
||||
// We still call this in case the last title was from the UIInspector
|
||||
AssignCamAndUpdateTitle(MainCamera);
|
||||
return MainCamera;
|
||||
}
|
||||
|
||||
if (Camera.main){
|
||||
AssignCamAndUpdateTitle(Camera.main);
|
||||
return MainCamera;
|
||||
}
|
||||
|
||||
ExplorerCore.LogWarning("No Camera.main found, trying to find a camera named 'Main Camera' or 'MainCamera'...");
|
||||
Camera namedCam = Camera.allCameras.FirstOrDefault(c => c.name is "Main Camera" or "MainCamera");
|
||||
if (namedCam) {
|
||||
AssignCamAndUpdateTitle(namedCam);
|
||||
return MainCamera;
|
||||
}
|
||||
|
||||
if (FreeCamPanel.inFreeCamMode && FreeCamPanel.GetFreecam()){
|
||||
AssignCamAndUpdateTitle(FreeCamPanel.GetFreecam());
|
||||
return MainCamera;
|
||||
}
|
||||
|
||||
ExplorerCore.LogWarning("No camera named found, using the first camera created...");
|
||||
var fallbackCam = Camera.allCameras.FirstOrDefault();
|
||||
if (fallbackCam) {
|
||||
AssignCamAndUpdateTitle(fallbackCam);
|
||||
return MainCamera;
|
||||
}
|
||||
|
||||
// If we reach here, no cameras were found at all.
|
||||
ExplorerCore.LogWarning("No valid cameras found!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void UpdateMouseInspect(Vector2 mousePos)
|
||||
{
|
||||
if (!MainCamera)
|
||||
MainCamera = Camera.main;
|
||||
if (!MainCamera)
|
||||
// Attempt to ensure camera each time UpdateMouseInspect is called
|
||||
// in case something changed or wasn't set initially.
|
||||
if (!EnsureMainCamera())
|
||||
{
|
||||
ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!");
|
||||
MouseInspector.Instance.StopInspect();
|
||||
@ -51,8 +105,8 @@
|
||||
if (obj != lastHitObject)
|
||||
{
|
||||
lastHitObject = obj;
|
||||
MouseInspector.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
||||
MouseInspector.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
||||
MouseInspector.Instance.UpdateObjectNameLabel($"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>");
|
||||
MouseInspector.Instance.UpdateObjectPathLabel($"Path: {obj.transform.GetTransformPath(true)}");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user