feat(scripting): support managed script component api
This commit is contained in:
74
managed/GameScripts/ScriptComponentApiProbe.cs
Normal file
74
managed/GameScripts/ScriptComponentApiProbe.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using XCEngine;
|
||||
|
||||
namespace Gameplay
|
||||
{
|
||||
public sealed class ScriptComponentTargetProbe : MonoBehaviour
|
||||
{
|
||||
public int AwakeCount;
|
||||
public int StartCount;
|
||||
public int HostCallCount;
|
||||
public string HostName = string.Empty;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
AwakeCount++;
|
||||
HostName = gameObject.Name;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
StartCount++;
|
||||
}
|
||||
|
||||
public void IncrementFromHost()
|
||||
{
|
||||
HostCallCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ScriptComponentApiProbe : MonoBehaviour
|
||||
{
|
||||
public bool InitialHasTarget;
|
||||
public bool InitialLookupReturnedNull;
|
||||
public bool AddedTarget;
|
||||
public bool HasTargetAfterAdd;
|
||||
public bool LookupSucceededAfterAdd;
|
||||
public bool TryGetSucceededAfterAdd;
|
||||
public bool ReturnedSameInstance;
|
||||
public bool TargetEnabledAfterAdd;
|
||||
public int ObservedTargetAwakeCount;
|
||||
public int ObservedTargetStartCount;
|
||||
public int ObservedTargetHostCallCount;
|
||||
public string ObservedTargetHostName = string.Empty;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
InitialHasTarget = HasComponent<ScriptComponentTargetProbe>();
|
||||
InitialLookupReturnedNull = GetComponent<ScriptComponentTargetProbe>() == null;
|
||||
|
||||
ScriptComponentTargetProbe added = AddComponent<ScriptComponentTargetProbe>();
|
||||
AddedTarget = added != null;
|
||||
HasTargetAfterAdd = HasComponent<ScriptComponentTargetProbe>();
|
||||
|
||||
ScriptComponentTargetProbe resolved = GetComponent<ScriptComponentTargetProbe>();
|
||||
TryGetSucceededAfterAdd = TryGetComponent(out ScriptComponentTargetProbe tried);
|
||||
LookupSucceededAfterAdd = resolved != null;
|
||||
ReturnedSameInstance = added != null
|
||||
&& ReferenceEquals(added, resolved)
|
||||
&& ReferenceEquals(added, tried);
|
||||
|
||||
if (added == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
added.IncrementFromHost();
|
||||
TargetEnabledAfterAdd = added.enabled;
|
||||
ObservedTargetAwakeCount = added.AwakeCount;
|
||||
ObservedTargetStartCount = added.StartCount;
|
||||
ObservedTargetHostCallCount = added.HostCallCount;
|
||||
ObservedTargetHostName = added.HostName ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user