2021-09-06 17:10:01 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
2021-12-02 18:35:46 +11:00
|
|
|
|
using UniverseLib;
|
2022-01-31 21:24:01 +11:00
|
|
|
|
using UniverseLib.Utility;
|
2021-09-06 17:10:01 +10:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.MouseInspectors
|
|
|
|
|
{
|
|
|
|
|
public class WorldInspector : MouseInspectorBase
|
|
|
|
|
{
|
|
|
|
|
private static Camera MainCamera;
|
|
|
|
|
private static GameObject lastHitObject;
|
|
|
|
|
|
|
|
|
|
public override void OnBeginMouseInspect()
|
|
|
|
|
{
|
|
|
|
|
MainCamera = Camera.main;
|
|
|
|
|
|
|
|
|
|
if (!MainCamera)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("No MainCamera found! Cannot inspect world!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ClearHitData()
|
|
|
|
|
{
|
|
|
|
|
lastHitObject = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnSelectMouseInspect()
|
|
|
|
|
{
|
|
|
|
|
InspectorManager.Inspect(lastHitObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateMouseInspect(Vector2 mousePos)
|
|
|
|
|
{
|
2022-01-09 19:20:17 +11:00
|
|
|
|
if (!MainCamera)
|
|
|
|
|
MainCamera = Camera.main;
|
|
|
|
|
if (!MainCamera)
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("No Main Camera was found, unable to inspect world!");
|
|
|
|
|
InspectUnderMouse.Instance.StopInspect();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 17:10:01 +10:00
|
|
|
|
var ray = MainCamera.ScreenPointToRay(mousePos);
|
|
|
|
|
Physics.Raycast(ray, out RaycastHit hit, 1000f);
|
|
|
|
|
|
|
|
|
|
if (hit.transform)
|
|
|
|
|
OnHitGameObject(hit.transform.gameObject);
|
|
|
|
|
else if (lastHitObject)
|
|
|
|
|
InspectUnderMouse.Instance.ClearHitData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void OnHitGameObject(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj != lastHitObject)
|
|
|
|
|
{
|
|
|
|
|
lastHitObject = obj;
|
|
|
|
|
InspectUnderMouse.Instance.objNameLabel.text = $"<b>Click to Inspect:</b> <color=cyan>{obj.name}</color>";
|
|
|
|
|
InspectUnderMouse.Instance.objPathLabel.text = $"Path: {obj.transform.GetTransformPath(true)}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnEndInspect()
|
|
|
|
|
{
|
|
|
|
|
// not needed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|