Files
XCEngine/managed/GameScripts/RuntimeGameObjectProbe.cs

98 lines
3.8 KiB
C#

using XCEngine;
namespace Gameplay
{
public sealed class RuntimeGameObjectProbe : MonoBehaviour
{
public bool MissingBeforeCreate;
public bool CreatedRootSucceeded;
public bool CreatedChildSucceeded;
public bool FoundRootSucceeded;
public bool FoundChildSucceeded;
public string ObservedFoundRootName = string.Empty;
public string ObservedFoundChildParentName = string.Empty;
public int ObservedRootChildCountBeforeDestroy;
public bool CameraLookupSucceeded;
public bool MeshFilterLookupSucceeded;
public bool MeshRendererLookupSucceeded;
public float ObservedCameraFieldOfView;
public string ObservedMeshPath = string.Empty;
public int ObservedMaterialCount;
public string ObservedMaterial0Path = string.Empty;
public int ObservedRenderLayer;
public bool MissingChildAfterDestroy;
public bool FoundRootAfterDestroySucceeded;
public int ObservedRootChildCountAfterDestroy = -1;
public void Start()
{
MissingBeforeCreate = GameObject.Find("RuntimeCreatedRoot") == null;
GameObject root = GameObject.Create("RuntimeCreatedRoot");
GameObject child = GameObject.Create("RuntimeCreatedChild", root);
CreatedRootSucceeded = root != null;
CreatedChildSucceeded = child != null;
GameObject foundRoot = GameObject.Find("RuntimeCreatedRoot");
GameObject foundChild = GameObject.Find("RuntimeCreatedChild");
FoundRootSucceeded = foundRoot != null;
FoundChildSucceeded = foundChild != null;
if (foundRoot != null)
{
ObservedFoundRootName = foundRoot.name;
ObservedRootChildCountBeforeDestroy = foundRoot.transform.childCount;
Camera camera = foundRoot.AddComponent<Camera>();
MeshFilter meshFilter = foundRoot.AddComponent<MeshFilter>();
MeshRenderer meshRenderer = foundRoot.AddComponent<MeshRenderer>();
CameraLookupSucceeded = camera != null;
MeshFilterLookupSucceeded = meshFilter != null;
MeshRendererLookupSucceeded = meshRenderer != null;
if (camera != null)
{
camera.fieldOfView = 68.0f;
ObservedCameraFieldOfView = camera.fieldOfView;
}
if (meshFilter != null)
{
meshFilter.meshPath = "Meshes/runtime_created.mesh";
ObservedMeshPath = meshFilter.meshPath;
}
if (meshRenderer != null)
{
meshRenderer.SetMaterialPath(0, "Materials/runtime_created.mat");
meshRenderer.renderLayer = 4;
ObservedMaterialCount = meshRenderer.materialCount;
ObservedMaterial0Path = meshRenderer.GetMaterialPath(0);
ObservedRenderLayer = meshRenderer.renderLayer;
}
}
if (foundChild != null && foundChild.transform.parent != null)
{
ObservedFoundChildParentName = foundChild.transform.parent.gameObject.name;
}
if (child != null)
{
child.Destroy();
}
MissingChildAfterDestroy = GameObject.Find("RuntimeCreatedChild") == null;
GameObject foundRootAfterDestroy = GameObject.Find("RuntimeCreatedRoot");
FoundRootAfterDestroySucceeded = foundRootAfterDestroy != null;
if (foundRootAfterDestroy != null)
{
ObservedRootChildCountAfterDestroy = foundRootAfterDestroy.transform.childCount;
}
}
}
}