Init
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
|
||||
|
||||
NOTICE:All information contained herein is, and remains the property of
|
||||
PICO Technology Co., Ltd. The intellectual and technical concepts
|
||||
contained herein are proprietary to PICO Technology Co., Ltd. and may be
|
||||
covered by patents, patents in process, and are protected by trade secret or
|
||||
copyright law. Dissemination of this information or reproduction of this
|
||||
material is strictly forbidden unless prior written permission is obtained from
|
||||
PICO Technology Co., Ltd.
|
||||
*******************************************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
namespace Unity.XR.PXR.Debugger
|
||||
{
|
||||
public class PXR_InspectorItem : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
public Text text;
|
||||
private bool isShowChildren = false;
|
||||
private bool hasChild = false;
|
||||
private string icon => hasChild?(isShowChildren?"- ":"+ "):"";
|
||||
private string nodeName;
|
||||
private GameObject target;
|
||||
public void SetTitle(){
|
||||
text.text = icon + nodeName;
|
||||
}
|
||||
public void Init(Transform item)
|
||||
{
|
||||
target = item.gameObject;
|
||||
nodeName = item.name;
|
||||
if(item.childCount > 0){
|
||||
hasChild = true;
|
||||
TraverseChild(item);
|
||||
}
|
||||
SetTitle();
|
||||
}
|
||||
public void AddItem(Transform item)
|
||||
{
|
||||
var go = Instantiate(PXR_InspectorManager.Instance.inspectItem, transform);
|
||||
if (go.TryGetComponent(out PXR_InspectorItem inspectItem))
|
||||
{
|
||||
inspectItem.Init(item);
|
||||
inspectItem.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
public void TraverseChild(Transform current)
|
||||
{
|
||||
for (int i = 0; i < current.childCount; i++)
|
||||
{
|
||||
// Debug.Log($"TraverseChild: {current.GetChild(i).name}");
|
||||
AddItem(current.GetChild(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
isShowChildren = !isShowChildren;
|
||||
// LayoutRebuilder.ForceRebuildLayoutImmediate(gameObject.GetComponent<RectTransform>());
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
// Debug.Log($"TraverseChild: {transform.GetChild(i).name}");
|
||||
transform.GetChild(i).gameObject.SetActive(isShowChildren);
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(transform.GetChild(i).GetComponent<RectTransform>());
|
||||
}
|
||||
var root = transform;
|
||||
while(root.TryGetComponent(out PXR_InspectorItem _)){
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(root.GetComponent<RectTransform>());
|
||||
root = root.parent;
|
||||
}
|
||||
SetTitle();
|
||||
PXR_InspectorManager.Instance.SetTransformInfo(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb8065e0c6c0d426490ad712bc1ce594
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,90 @@
|
||||
/*******************************************************************************
|
||||
Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
|
||||
|
||||
NOTICE:All information contained herein is, and remains the property of
|
||||
PICO Technology Co., Ltd. The intellectual and technical concepts
|
||||
contained herein are proprietary to PICO Technology Co., Ltd. and may be
|
||||
covered by patents, patents in process, and are protected by trade secret or
|
||||
copyright law. Dissemination of this information or reproduction of this
|
||||
material is strictly forbidden unless prior written permission is obtained from
|
||||
PICO Technology Co., Ltd.
|
||||
*******************************************************************************/
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
namespace Unity.XR.PXR.Debugger
|
||||
{
|
||||
public class PXR_InspectorManager : MonoBehaviour, IPXR_PanelManager
|
||||
{
|
||||
public static PXR_InspectorManager Instance;
|
||||
private void Awake(){
|
||||
if(Instance == null){
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
public GameObject inspectItem;
|
||||
public Transform content;
|
||||
public Text positionText;
|
||||
public Text rotationText;
|
||||
public Text scaleText;
|
||||
public GameObject transformInfoNode;
|
||||
private Transform target;
|
||||
void Update(){
|
||||
ShowTransformInfo();
|
||||
}
|
||||
private void ClearAllChildren(){
|
||||
int childCount = content.childCount;
|
||||
for (int i = childCount - 1; i >= 0; i--)
|
||||
{
|
||||
DestroyImmediate(content.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
public void CreateInspector()
|
||||
{
|
||||
GenerateInspectorTree();
|
||||
}
|
||||
public void Init(){
|
||||
CreateInspector();
|
||||
}
|
||||
public void Reset(){
|
||||
for (int i = 0; i < content.childCount; i++)
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(content.GetChild(i).GetComponent<RectTransform>());
|
||||
}
|
||||
}
|
||||
public void SetTransformInfo(GameObject target){
|
||||
this.target = target.transform;
|
||||
transformInfoNode.SetActive(true);
|
||||
ShowTransformInfo();
|
||||
}
|
||||
public void Refresh(){
|
||||
ClearAllChildren();
|
||||
GenerateInspectorTree();
|
||||
}
|
||||
private void GenerateInspectorTree(){
|
||||
GameObject[] rootObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
// 遍历所有根GameObject
|
||||
foreach (GameObject obj in rootObjects)
|
||||
{
|
||||
if(!obj.TryGetComponent<PXR_UIController>(out _) && !obj.TryGetComponent<PXR_UIManager>(out _) && obj.activeSelf){
|
||||
var go = Instantiate(inspectItem, content);
|
||||
if(go.TryGetComponent(out PXR_InspectorItem item)){
|
||||
item.Init(obj.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
private void ShowTransformInfo(){
|
||||
if(target != null){
|
||||
positionText.text = $"x:{target.position.x} y:{target.position.y} z:{target.position.z}";
|
||||
rotationText.text = $"x:{target.eulerAngles.x} y:{target.eulerAngles.y} z:{target.eulerAngles.z} ";
|
||||
scaleText.text = $"x:{target.localScale.x} y:{target.localScale.y} z:{target.localScale.z}";
|
||||
}else{
|
||||
transformInfoNode.SetActive(false);
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c28c50e274e400ababdc4ef40ca441
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user