Align Unity-style object and hierarchy scripting APIs
This commit is contained in:
111
managed/GameScripts/ObjectApiProbe.cs
Normal file
111
managed/GameScripts/ObjectApiProbe.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class ObjectApiMarkerProbe : MonoBehaviour
|
||||
{
|
||||
}
|
||||
|
||||
public sealed class ObjectApiDestroyTargetProbe : MonoBehaviour
|
||||
{
|
||||
public int DisableCount;
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
DisableCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ObjectApiProbe : MonoBehaviour
|
||||
{
|
||||
public bool FoundSelfScriptViaParentLookup;
|
||||
public bool FoundSelfScriptViaGameObjectParentLookup;
|
||||
public bool FoundSelfTransformViaChildrenLookup;
|
||||
public bool FoundSelfTransformViaGameObjectChildrenLookup;
|
||||
public bool FoundCameraInParent;
|
||||
public bool FoundCameraInParentViaGameObject;
|
||||
public bool FoundMarkerInParent;
|
||||
public bool FoundMeshRendererInChildren;
|
||||
public bool FoundMeshRendererInChildrenViaGameObject;
|
||||
public bool FoundTargetScriptInChildren;
|
||||
public string ObservedParentCameraHostName = string.Empty;
|
||||
public string ObservedChildMeshRendererHostName = string.Empty;
|
||||
public string ObservedChildScriptHostName = string.Empty;
|
||||
public bool ChildCameraMissingAfterDestroy;
|
||||
public bool ChildScriptMissingAfterDestroy;
|
||||
public bool ChildGameObjectMissingAfterDestroy;
|
||||
public int ObservedChildScriptDisableCount = -1;
|
||||
public int ObservedChildCountAfterDestroy = -1;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ObjectApiProbe selfViaParent = GetComponentInParent<ObjectApiProbe>();
|
||||
ObjectApiProbe selfViaGameObjectParent = gameObject.GetComponentInParent<ObjectApiProbe>();
|
||||
Transform selfViaChildren = GetComponentInChildren<Transform>();
|
||||
Transform selfViaGameObjectChildren = gameObject.GetComponentInChildren<Transform>();
|
||||
|
||||
FoundSelfScriptViaParentLookup = selfViaParent == this;
|
||||
FoundSelfScriptViaGameObjectParentLookup = selfViaGameObjectParent == this;
|
||||
FoundSelfTransformViaChildrenLookup = selfViaChildren != null
|
||||
&& selfViaChildren.GameObjectUUID == GameObjectUUID;
|
||||
FoundSelfTransformViaGameObjectChildrenLookup = selfViaGameObjectChildren != null
|
||||
&& selfViaGameObjectChildren.GameObjectUUID == GameObjectUUID;
|
||||
|
||||
Camera parentCamera = GetComponentInParent<Camera>();
|
||||
Camera parentCameraViaGameObject = gameObject.GetComponentInParent<Camera>();
|
||||
ObjectApiMarkerProbe parentMarker = GetComponentInParent<ObjectApiMarkerProbe>();
|
||||
MeshRenderer childMeshRenderer = GetComponentInChildren<MeshRenderer>();
|
||||
MeshRenderer childMeshRendererViaGameObject = gameObject.GetComponentInChildren<MeshRenderer>();
|
||||
ObjectApiDestroyTargetProbe childScript = GetComponentInChildren<ObjectApiDestroyTargetProbe>();
|
||||
|
||||
FoundCameraInParent = parentCamera != null;
|
||||
FoundCameraInParentViaGameObject = parentCameraViaGameObject != null;
|
||||
FoundMarkerInParent = parentMarker != null;
|
||||
FoundMeshRendererInChildren = childMeshRenderer != null;
|
||||
FoundMeshRendererInChildrenViaGameObject = childMeshRendererViaGameObject != null;
|
||||
FoundTargetScriptInChildren = childScript != null;
|
||||
|
||||
if (parentCamera != null)
|
||||
{
|
||||
ObservedParentCameraHostName = parentCamera.gameObject.name;
|
||||
}
|
||||
|
||||
if (childMeshRenderer != null)
|
||||
{
|
||||
ObservedChildMeshRendererHostName = childMeshRenderer.gameObject.name;
|
||||
}
|
||||
|
||||
if (childScript != null)
|
||||
{
|
||||
ObservedChildScriptHostName = childScript.gameObject.name;
|
||||
}
|
||||
|
||||
Transform firstChild = transform.childCount > 0 ? transform.GetChild(0) : null;
|
||||
GameObject child = firstChild != null ? firstChild.gameObject : null;
|
||||
if (child == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Camera childCamera = child.GetComponent<Camera>();
|
||||
if (childCamera != null)
|
||||
{
|
||||
Destroy(childCamera);
|
||||
}
|
||||
|
||||
ChildCameraMissingAfterDestroy = child.GetComponent<Camera>() == null;
|
||||
|
||||
if (childScript != null)
|
||||
{
|
||||
Destroy(childScript);
|
||||
ObservedChildScriptDisableCount = childScript.DisableCount;
|
||||
}
|
||||
|
||||
ChildScriptMissingAfterDestroy = child.GetComponent<ObjectApiDestroyTargetProbe>() == null;
|
||||
|
||||
Destroy(child);
|
||||
ChildGameObjectMissingAfterDestroy = GameObject.Find("Child") == null;
|
||||
ObservedChildCountAfterDestroy = transform.childCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user