feat(scripting): add mono csharp runtime foundation
This commit is contained in:
60
managed/GameScripts/BuiltinComponentProbe.cs
Normal file
60
managed/GameScripts/BuiltinComponentProbe.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class BuiltinComponentProbe : MonoBehaviour
|
||||
{
|
||||
public bool HasCamera;
|
||||
public bool HasLight;
|
||||
public bool CameraLookupSucceeded;
|
||||
public bool LightLookupSucceeded;
|
||||
|
||||
public float ObservedFieldOfView;
|
||||
public float ObservedNearClipPlane;
|
||||
public float ObservedFarClipPlane;
|
||||
public float ObservedDepth;
|
||||
public bool ObservedPrimary;
|
||||
|
||||
public float ObservedIntensity;
|
||||
public float ObservedRange;
|
||||
public float ObservedSpotAngle;
|
||||
public bool ObservedCastsShadows;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
HasCamera = HasComponent<Camera>();
|
||||
HasLight = HasComponent<Light>();
|
||||
|
||||
CameraLookupSucceeded = TryGetComponent(out Camera camera);
|
||||
LightLookupSucceeded = TryGetComponent(out Light light);
|
||||
|
||||
if (camera != null)
|
||||
{
|
||||
ObservedFieldOfView = camera.fieldOfView;
|
||||
ObservedNearClipPlane = camera.nearClipPlane;
|
||||
ObservedFarClipPlane = camera.farClipPlane;
|
||||
ObservedDepth = camera.depth;
|
||||
ObservedPrimary = camera.primary;
|
||||
|
||||
camera.fieldOfView = 75.0f;
|
||||
camera.nearClipPlane = 0.3f;
|
||||
camera.farClipPlane = 500.0f;
|
||||
camera.depth = 3.0f;
|
||||
camera.primary = false;
|
||||
}
|
||||
|
||||
if (light != null)
|
||||
{
|
||||
ObservedIntensity = light.intensity;
|
||||
ObservedRange = light.range;
|
||||
ObservedSpotAngle = light.spotAngle;
|
||||
ObservedCastsShadows = light.castsShadows;
|
||||
|
||||
light.intensity = 2.5f;
|
||||
light.range = 42.0f;
|
||||
light.spotAngle = 55.0f;
|
||||
light.castsShadows = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
managed/GameScripts/HierarchyProbe.cs
Normal file
45
managed/GameScripts/HierarchyProbe.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class HierarchyProbe : MonoBehaviour
|
||||
{
|
||||
public GameObject ReparentTarget;
|
||||
public string ObservedParentName = string.Empty;
|
||||
public string ObservedFirstChildName = string.Empty;
|
||||
public string ReparentedChildParentName = string.Empty;
|
||||
public bool ParentLookupSucceeded;
|
||||
public bool ChildLookupSucceeded;
|
||||
public int ObservedChildCount;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Transform currentParent = transform.parent;
|
||||
ParentLookupSucceeded = currentParent != null;
|
||||
if (currentParent != null)
|
||||
{
|
||||
ObservedParentName = currentParent.gameObject.name;
|
||||
}
|
||||
|
||||
ObservedChildCount = transform.childCount;
|
||||
|
||||
Transform firstChild = transform.GetChild(0);
|
||||
ChildLookupSucceeded = firstChild != null;
|
||||
if (firstChild != null)
|
||||
{
|
||||
ObservedFirstChildName = firstChild.gameObject.name;
|
||||
|
||||
if (ReparentTarget != null)
|
||||
{
|
||||
firstChild.SetParent(ReparentTarget.transform, true);
|
||||
|
||||
Transform newParent = firstChild.parent;
|
||||
if (newParent != null)
|
||||
{
|
||||
ReparentedChildParentName = newParent.gameObject.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,14 @@ namespace Gameplay
|
||||
{
|
||||
}
|
||||
|
||||
public sealed class UnsupportedManagedComponent : Component
|
||||
{
|
||||
private UnsupportedManagedComponent(ulong gameObjectUUID)
|
||||
: base(gameObjectUUID)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LifecycleProbe : MonoBehaviour
|
||||
{
|
||||
public int AwakeCount;
|
||||
@@ -18,14 +26,47 @@ namespace Gameplay
|
||||
public int DestroyCount;
|
||||
|
||||
public float Speed;
|
||||
public float ObservedFixedDeltaTime;
|
||||
public float ObservedUpdateDeltaTime;
|
||||
public float ObservedLateDeltaTime;
|
||||
public string Label = string.Empty;
|
||||
public string ObservedGameObjectName = string.Empty;
|
||||
public string ObservedTargetName = string.Empty;
|
||||
public bool WasAwakened;
|
||||
public bool WarningLogged;
|
||||
public bool ErrorLogged;
|
||||
public bool HasTransform;
|
||||
public bool TransformLookupSucceeded;
|
||||
public bool HasUnsupportedComponent;
|
||||
public bool UnsupportedComponentLookupReturnedNull;
|
||||
public bool TargetResolved;
|
||||
public bool RotationAccessed;
|
||||
public bool ScaleAccessed;
|
||||
public bool TransformAccessed;
|
||||
public bool ObservedEnabled;
|
||||
public bool ObservedActiveSelf;
|
||||
public bool ObservedActiveInHierarchy;
|
||||
public bool ObservedIsActiveAndEnabled;
|
||||
public bool DisableSelfOnFirstUpdate;
|
||||
public bool DeactivateGameObjectOnFirstUpdate;
|
||||
public GameObject Target;
|
||||
public GameObject SelfReference;
|
||||
public Vector4 ObservedLocalRotation;
|
||||
public Vector3 ObservedLocalPosition;
|
||||
public Vector3 ObservedLocalScale;
|
||||
public Vector3 SpawnPoint;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
AwakeCount += 1;
|
||||
WasAwakened = true;
|
||||
gameObject.name = gameObject.name + "_Managed";
|
||||
ObservedGameObjectName = gameObject.name;
|
||||
Debug.Log(ObservedGameObjectName);
|
||||
Debug.LogWarning(ObservedGameObjectName);
|
||||
WarningLogged = true;
|
||||
Debug.LogError(ObservedGameObjectName);
|
||||
ErrorLogged = true;
|
||||
Label = Label + "|Awake";
|
||||
}
|
||||
|
||||
@@ -37,23 +78,80 @@ namespace Gameplay
|
||||
public void Start()
|
||||
{
|
||||
StartCount += 1;
|
||||
HasTransform = HasComponent<Transform>();
|
||||
HasUnsupportedComponent = HasComponent<UnsupportedManagedComponent>();
|
||||
|
||||
SelfReference = gameObject;
|
||||
TargetResolved = Target != null;
|
||||
if (Target != null)
|
||||
{
|
||||
ObservedTargetName = Target.name;
|
||||
}
|
||||
|
||||
TransformLookupSucceeded = TryGetComponent(out Transform resolvedTransform);
|
||||
UnsupportedComponentLookupReturnedNull = !gameObject.TryGetComponent(out UnsupportedManagedComponent unsupportedComponent);
|
||||
|
||||
if (resolvedTransform != null)
|
||||
{
|
||||
resolvedTransform.localPosition = new Vector3(7.0f, 8.0f, 9.0f);
|
||||
resolvedTransform.localRotation = new Quaternion(0.0f, 0.5f, 0.0f, 0.8660254f);
|
||||
resolvedTransform.localScale = new Vector3(2.0f, 3.0f, 4.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
FixedUpdateCount += 1;
|
||||
ObservedFixedDeltaTime = Time.deltaTime;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
UpdateCount += 1;
|
||||
Speed += 1.0f;
|
||||
ObservedUpdateDeltaTime = Time.deltaTime;
|
||||
ObservedLocalPosition = transform.localPosition;
|
||||
Quaternion rotation = transform.localRotation;
|
||||
ObservedLocalRotation = new Vector4(rotation.x, rotation.y, rotation.z, rotation.w);
|
||||
ObservedLocalScale = transform.localScale;
|
||||
ObservedEnabled = enabled;
|
||||
ObservedActiveSelf = gameObject.activeSelf;
|
||||
ObservedActiveInHierarchy = gameObject.activeInHierarchy;
|
||||
ObservedIsActiveAndEnabled = isActiveAndEnabled;
|
||||
RotationAccessed = true;
|
||||
ScaleAccessed = true;
|
||||
TransformAccessed = true;
|
||||
|
||||
if (UpdateCount == 1)
|
||||
{
|
||||
if (DisableSelfOnFirstUpdate)
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
if (DeactivateGameObjectOnFirstUpdate)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
LateUpdateCount += 1;
|
||||
SpawnPoint = new Vector3(SpawnPoint.X + 1.0f, SpawnPoint.Y, SpawnPoint.Z);
|
||||
ObservedLateDeltaTime = Time.deltaTime;
|
||||
|
||||
Vector3 position = transform.localPosition;
|
||||
position.x = position.x + 1.0f;
|
||||
transform.localPosition = position;
|
||||
ObservedLocalPosition = transform.localPosition;
|
||||
|
||||
Vector3 scale = transform.localScale;
|
||||
scale.x = scale.x + 1.0f;
|
||||
transform.localScale = scale;
|
||||
ObservedLocalScale = transform.localScale;
|
||||
|
||||
SpawnPoint.x = SpawnPoint.x + 1.0f;
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
|
||||
23
managed/GameScripts/TransformConversionProbe.cs
Normal file
23
managed/GameScripts/TransformConversionProbe.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class TransformConversionProbe : MonoBehaviour
|
||||
{
|
||||
public Vector3 ObservedWorldPoint;
|
||||
public Vector3 ObservedLocalPoint;
|
||||
public Vector3 ObservedWorldDirection;
|
||||
public Vector3 ObservedLocalDirection;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
transform.localPosition = new Vector3(5.0f, 0.0f, 1.0f);
|
||||
transform.localEulerAngles = new Vector3(0.0f, 90.0f, 0.0f);
|
||||
|
||||
ObservedWorldPoint = transform.TransformPoint(new Vector3(0.0f, 0.0f, 2.0f));
|
||||
ObservedLocalPoint = transform.InverseTransformPoint(new Vector3(7.0f, 0.0f, 1.0f));
|
||||
ObservedWorldDirection = transform.TransformDirection(new Vector3(0.0f, 0.0f, 1.0f));
|
||||
ObservedLocalDirection = transform.InverseTransformDirection(new Vector3(1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
41
managed/GameScripts/TransformMotionProbe.cs
Normal file
41
managed/GameScripts/TransformMotionProbe.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class TransformMotionProbe : MonoBehaviour
|
||||
{
|
||||
public Vector3 ObservedForward;
|
||||
public Vector3 ObservedRight;
|
||||
public Vector3 ObservedUp;
|
||||
public Vector3 ObservedPositionAfterSelfTranslate;
|
||||
public Vector3 ObservedPositionAfterWorldTranslate;
|
||||
public Vector3 ObservedForwardAfterWorldRotate;
|
||||
public Vector3 ObservedForwardAfterSelfRotate;
|
||||
public Vector3 ObservedForwardAfterLookAt;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
transform.localEulerAngles = new Vector3(0.0f, 90.0f, 0.0f);
|
||||
|
||||
ObservedForward = transform.forward;
|
||||
ObservedRight = transform.right;
|
||||
ObservedUp = transform.up;
|
||||
|
||||
transform.Translate(new Vector3(0.0f, 0.0f, 2.0f));
|
||||
ObservedPositionAfterSelfTranslate = transform.position;
|
||||
|
||||
transform.Translate(new Vector3(0.0f, 0.0f, 3.0f), Space.World);
|
||||
ObservedPositionAfterWorldTranslate = transform.position;
|
||||
|
||||
transform.Rotate(new Vector3(0.0f, -90.0f, 0.0f), Space.World);
|
||||
ObservedForwardAfterWorldRotate = transform.forward;
|
||||
|
||||
transform.Rotate(new Vector3(0.0f, 90.0f, 0.0f));
|
||||
ObservedForwardAfterSelfRotate = transform.forward;
|
||||
|
||||
transform.LookAt(new Vector3(2.0f, 0.0f, 8.0f));
|
||||
ObservedForwardAfterLookAt = transform.forward;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
managed/GameScripts/TransformSpaceProbe.cs
Normal file
33
managed/GameScripts/TransformSpaceProbe.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class TransformSpaceProbe : MonoBehaviour
|
||||
{
|
||||
public Vector3 ObservedInitialWorldPosition;
|
||||
public Vector3 ObservedInitialWorldScale;
|
||||
public Vector3 ObservedInitialLocalEulerAngles;
|
||||
public Vector3 ObservedEulerAfterSet;
|
||||
public Vector3 ObservedWorldPositionAfterSet;
|
||||
public Vector3 ObservedWorldScaleAfterSet;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ObservedInitialWorldPosition = transform.position;
|
||||
ObservedInitialWorldScale = transform.scale;
|
||||
ObservedInitialLocalEulerAngles = transform.localEulerAngles;
|
||||
|
||||
transform.localEulerAngles = new Vector3(0.0f, 45.0f, 0.0f);
|
||||
ObservedEulerAfterSet = transform.localEulerAngles;
|
||||
|
||||
transform.position = new Vector3(20.0f, 6.0f, 10.0f);
|
||||
ObservedWorldPositionAfterSet = transform.position;
|
||||
|
||||
Quaternion targetRotation = new Quaternion(0.0f, 0.5f, 0.0f, 0.8660254f);
|
||||
transform.rotation = targetRotation;
|
||||
|
||||
transform.scale = new Vector3(6.0f, 8.0f, 10.0f);
|
||||
ObservedWorldScaleAfterSet = transform.scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user