feat: expand editor scripting asset and viewport flow

This commit is contained in:
2026-04-03 13:22:30 +08:00
parent ed8c27fde2
commit a05d0b80a2
124 changed files with 10397 additions and 1737 deletions

View File

@@ -37,6 +37,31 @@ set(XCENGINE_MONO_MSCORLIB_PATH "${XCENGINE_MONO_CORLIB_DIR}/mscorlib.dll")
set(XCENGINE_SCRIPT_CORE_DLL "${XCENGINE_MANAGED_OUTPUT_DIR}/XCEngine.ScriptCore.dll" CACHE FILEPATH "Generated XCEngine.ScriptCore assembly")
set(XCENGINE_GAME_SCRIPTS_DLL "${XCENGINE_MANAGED_OUTPUT_DIR}/GameScripts.dll" CACHE FILEPATH "Generated GameScripts assembly")
set(
XCENGINE_PROJECT_ASSETS_DIR
"${CMAKE_SOURCE_DIR}/project/Assets"
CACHE PATH
"Project asset root scanned for user C# scripts")
set(
XCENGINE_PROJECT_MANAGED_OUTPUT_DIR
"${CMAKE_SOURCE_DIR}/project/Library/ScriptAssemblies"
CACHE PATH
"Output directory for project managed assemblies")
set(
XCENGINE_PROJECT_SCRIPT_CORE_DLL
"${XCENGINE_PROJECT_MANAGED_OUTPUT_DIR}/XCEngine.ScriptCore.dll"
CACHE FILEPATH
"Generated script core assembly copied into the project script assembly directory")
set(
XCENGINE_PROJECT_GAME_SCRIPTS_DLL
"${XCENGINE_PROJECT_MANAGED_OUTPUT_DIR}/GameScripts.dll"
CACHE FILEPATH
"Generated project game scripts assembly")
set(
XCENGINE_PROJECT_MONO_MSCORLIB_PATH
"${XCENGINE_PROJECT_MANAGED_OUTPUT_DIR}/mscorlib.dll"
CACHE FILEPATH
"Mono corlib copied into the project script assembly directory")
foreach(XCENGINE_REQUIRED_PATH
"${XCENGINE_CSC_DLL}"
@@ -55,7 +80,9 @@ set(XCENGINE_SCRIPT_CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/Component.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/Debug.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/GameObject.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/Input.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/InternalCalls.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/KeyCode.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/Light.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/MeshFilter.cs
${CMAKE_CURRENT_SOURCE_DIR}/XCEngine.ScriptCore/MeshRenderer.cs
@@ -76,15 +103,33 @@ set(XCENGINE_GAME_SCRIPT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/ScriptComponentApiProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/RuntimeGameObjectProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/HierarchyProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/InputProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/LifecycleProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/MeshComponentProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/MeshRendererEdgeCaseProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/TickLogProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/TransformConversionProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/TransformMotionProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/TransformOrientationProbe.cs
${CMAKE_CURRENT_SOURCE_DIR}/GameScripts/TransformSpaceProbe.cs
)
file(
GLOB_RECURSE
XCENGINE_PROJECT_GAME_SCRIPT_SOURCES
CONFIGURE_DEPENDS
LIST_DIRECTORIES FALSE
"${XCENGINE_PROJECT_ASSETS_DIR}/*.cs")
list(SORT XCENGINE_PROJECT_GAME_SCRIPT_SOURCES)
if(NOT XCENGINE_PROJECT_GAME_SCRIPT_SOURCES)
set(XCENGINE_PROJECT_SCRIPT_PLACEHOLDER "${CMAKE_CURRENT_BINARY_DIR}/Generated/EmptyProjectGameScripts.cs")
file(GENERATE
OUTPUT "${XCENGINE_PROJECT_SCRIPT_PLACEHOLDER}"
CONTENT "namespace XCEngine.Generated { public static class EmptyProjectGameScriptsMarker {} }\n")
set(XCENGINE_PROJECT_GAME_SCRIPT_SOURCES "${XCENGINE_PROJECT_SCRIPT_PLACEHOLDER}")
endif()
set(XCENGINE_MANAGED_FRAMEWORK_REFERENCES
/reference:${XCENGINE_NET472_REFERENCE_DIR}/mscorlib.dll
/reference:${XCENGINE_NET472_REFERENCE_DIR}/System.dll
@@ -140,3 +185,47 @@ add_custom_target(
${XCENGINE_MANAGED_OUTPUT_DIR}/mscorlib.dll
)
add_custom_command(
OUTPUT ${XCENGINE_PROJECT_SCRIPT_CORE_DLL}
COMMAND ${CMAKE_COMMAND} -E make_directory ${XCENGINE_PROJECT_MANAGED_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${XCENGINE_SCRIPT_CORE_DLL}
${XCENGINE_PROJECT_SCRIPT_CORE_DLL}
DEPENDS ${XCENGINE_SCRIPT_CORE_DLL}
VERBATIM
COMMENT "Copying XCEngine.ScriptCore.dll into the project script assembly directory")
add_custom_command(
OUTPUT ${XCENGINE_PROJECT_GAME_SCRIPTS_DLL}
COMMAND ${CMAKE_COMMAND} -E make_directory ${XCENGINE_PROJECT_MANAGED_OUTPUT_DIR}
COMMAND ${XCENGINE_DOTNET_EXECUTABLE} ${XCENGINE_CSC_DLL}
/nologo
/target:library
/langversion:latest
/nostdlib+
/out:${XCENGINE_PROJECT_GAME_SCRIPTS_DLL}
${XCENGINE_MANAGED_FRAMEWORK_REFERENCES}
/reference:${XCENGINE_PROJECT_SCRIPT_CORE_DLL}
${XCENGINE_PROJECT_GAME_SCRIPT_SOURCES}
DEPENDS ${XCENGINE_PROJECT_GAME_SCRIPT_SOURCES} ${XCENGINE_PROJECT_SCRIPT_CORE_DLL}
VERBATIM
COMMENT "Building project GameScripts.dll from project asset scripts")
add_custom_command(
OUTPUT ${XCENGINE_PROJECT_MONO_MSCORLIB_PATH}
COMMAND ${CMAKE_COMMAND} -E make_directory ${XCENGINE_PROJECT_MANAGED_OUTPUT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${XCENGINE_MONO_MSCORLIB_PATH}
${XCENGINE_PROJECT_MONO_MSCORLIB_PATH}
DEPENDS ${XCENGINE_MONO_MSCORLIB_PATH}
VERBATIM
COMMENT "Copying mscorlib.dll into the project script assembly directory")
add_custom_target(
xcengine_project_managed_assemblies ALL
DEPENDS
${XCENGINE_PROJECT_SCRIPT_CORE_DLL}
${XCENGINE_PROJECT_GAME_SCRIPTS_DLL}
${XCENGINE_PROJECT_MONO_MSCORLIB_PATH}
)

View File

@@ -0,0 +1,52 @@
using XCEngine;
namespace Gameplay
{
public sealed class InputProbe : MonoBehaviour
{
public int UpdateCount;
public bool ObservedKeyA;
public bool ObservedKeyADown;
public bool ObservedKeyAUp;
public bool ObservedKeySpace;
public bool ObservedJump;
public bool ObservedJumpDown;
public bool ObservedJumpUp;
public bool ObservedFire1;
public bool ObservedFire1Down;
public bool ObservedFire1Up;
public bool ObservedAnyKey;
public bool ObservedAnyKeyDown;
public bool ObservedLeftMouse;
public bool ObservedLeftMouseDown;
public bool ObservedLeftMouseUp;
public float ObservedHorizontal;
public float ObservedHorizontalRaw;
public Vector3 ObservedMousePosition;
public Vector2 ObservedMouseScrollDelta;
public void Update()
{
UpdateCount += 1;
ObservedKeyA = Input.GetKey(KeyCode.A);
ObservedKeyADown = Input.GetKeyDown(KeyCode.A);
ObservedKeyAUp = Input.GetKeyUp(KeyCode.A);
ObservedKeySpace = Input.GetKey(KeyCode.Space);
ObservedJump = Input.GetButton("Jump");
ObservedJumpDown = Input.GetButtonDown("Jump");
ObservedJumpUp = Input.GetButtonUp("Jump");
ObservedFire1 = Input.GetButton("Fire1");
ObservedFire1Down = Input.GetButtonDown("Fire1");
ObservedFire1Up = Input.GetButtonUp("Fire1");
ObservedAnyKey = Input.anyKey;
ObservedAnyKeyDown = Input.anyKeyDown;
ObservedLeftMouse = Input.GetMouseButton(0);
ObservedLeftMouseDown = Input.GetMouseButtonDown(0);
ObservedLeftMouseUp = Input.GetMouseButtonUp(0);
ObservedHorizontal = Input.GetAxis("Horizontal");
ObservedHorizontalRaw = Input.GetAxisRaw("Horizontal");
ObservedMousePosition = Input.mousePosition;
ObservedMouseScrollDelta = Input.mouseScrollDelta;
}
}
}

View File

@@ -27,6 +27,8 @@ namespace Gameplay
public float Speed;
public float ObservedFixedDeltaTime;
public float ObservedConfiguredFixedDeltaTime;
public float ObservedConfiguredFixedDeltaTimeInUpdate;
public float ObservedUpdateDeltaTime;
public float ObservedLateDeltaTime;
public string Label = string.Empty;
@@ -103,6 +105,7 @@ namespace Gameplay
{
FixedUpdateCount += 1;
ObservedFixedDeltaTime = Time.deltaTime;
ObservedConfiguredFixedDeltaTime = Time.fixedDeltaTime;
}
public void Update()
@@ -110,6 +113,7 @@ namespace Gameplay
UpdateCount += 1;
Speed += 1.0f;
ObservedUpdateDeltaTime = Time.deltaTime;
ObservedConfiguredFixedDeltaTimeInUpdate = Time.fixedDeltaTime;
ObservedLocalPosition = transform.localPosition;
Quaternion rotation = transform.localRotation;
ObservedLocalRotation = new Vector4(rotation.x, rotation.y, rotation.z, rotation.w);

View File

@@ -0,0 +1,48 @@
using XCEngine;
namespace Gameplay
{
public sealed class TickLogProbe : MonoBehaviour
{
public int FixedUpdateCount;
public int UpdateCount;
public int LateUpdateCount;
public void Awake()
{
Debug.Log("[TickLogProbe] Awake");
}
public void Start()
{
Debug.Log("[TickLogProbe] Start");
}
public void FixedUpdate()
{
FixedUpdateCount += 1;
if (FixedUpdateCount <= 3)
{
Debug.Log("[TickLogProbe] FixedUpdate " + FixedUpdateCount);
}
}
public void Update()
{
UpdateCount += 1;
if (UpdateCount <= 3)
{
Debug.Log("[TickLogProbe] Update " + UpdateCount);
}
}
public void LateUpdate()
{
LateUpdateCount += 1;
if (LateUpdateCount <= 3)
{
Debug.Log("[TickLogProbe] LateUpdate " + LateUpdateCount);
}
}
}
}

View File

@@ -0,0 +1,94 @@
namespace XCEngine
{
public static class Input
{
public static bool GetKey(KeyCode key)
{
return InternalCalls.Input_GetKey((int)key);
}
public static bool GetKeyDown(KeyCode key)
{
return InternalCalls.Input_GetKeyDown((int)key);
}
public static bool GetKeyUp(KeyCode key)
{
return InternalCalls.Input_GetKeyUp((int)key);
}
public static bool GetMouseButton(int button)
{
return InternalCalls.Input_GetMouseButton(button);
}
public static bool GetMouseButtonDown(int button)
{
return InternalCalls.Input_GetMouseButtonDown(button);
}
public static bool GetMouseButtonUp(int button)
{
return InternalCalls.Input_GetMouseButtonUp(button);
}
public static bool GetButton(string buttonName)
{
return InternalCalls.Input_GetButton(buttonName);
}
public static bool GetButtonDown(string buttonName)
{
return InternalCalls.Input_GetButtonDown(buttonName);
}
public static bool GetButtonUp(string buttonName)
{
return InternalCalls.Input_GetButtonUp(buttonName);
}
public static float GetAxis(string axisName)
{
return InternalCalls.Input_GetAxis(axisName);
}
public static float GetAxisRaw(string axisName)
{
return InternalCalls.Input_GetAxisRaw(axisName);
}
public static bool anyKey
{
get
{
return InternalCalls.Input_GetAnyKey();
}
}
public static bool anyKeyDown
{
get
{
return InternalCalls.Input_GetAnyKeyDown();
}
}
public static Vector3 mousePosition
{
get
{
InternalCalls.Input_GetMousePosition(out Vector3 position);
return position;
}
}
public static Vector2 mouseScrollDelta
{
get
{
InternalCalls.Input_GetMouseScrollDelta(out Vector2 delta);
return delta;
}
}
}
}

View File

@@ -17,6 +17,54 @@ namespace XCEngine
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern float Time_GetDeltaTime();
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern float Time_GetFixedDeltaTime();
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetKey(int keyCode);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetKeyDown(int keyCode);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetKeyUp(int keyCode);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetMouseButton(int button);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetMouseButtonDown(int button);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetMouseButtonUp(int button);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetButton(string buttonName);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetButtonDown(string buttonName);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetButtonUp(string buttonName);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern float Input_GetAxis(string axisName);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern float Input_GetAxisRaw(string axisName);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetAnyKey();
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool Input_GetAnyKeyDown();
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Input_GetMousePosition(out Vector3 position);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Input_GetMouseScrollDelta(out Vector2 delta);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern string GameObject_GetName(ulong gameObjectUUID);

View File

@@ -0,0 +1,93 @@
namespace XCEngine
{
public enum KeyCode
{
None = 0,
A = 4,
B = 5,
C = 6,
D = 7,
E = 8,
F = 9,
G = 10,
H = 11,
I = 12,
J = 13,
K = 14,
L = 15,
M = 16,
N = 17,
O = 18,
P = 19,
Q = 20,
R = 21,
S = 22,
T = 23,
U = 24,
V = 25,
W = 26,
X = 27,
Y = 28,
Z = 29,
F1 = 58,
F2 = 59,
F3 = 60,
F4 = 61,
F5 = 62,
F6 = 63,
F7 = 64,
F8 = 65,
F9 = 66,
F10 = 67,
F11 = 68,
F12 = 69,
Space = 49,
Tab = 48,
Return = 36,
Escape = 53,
LeftShift = 56,
RightShift = 60,
LeftControl = 59,
RightControl = 62,
LeftAlt = 58,
RightAlt = 61,
UpArrow = 126,
DownArrow = 125,
LeftArrow = 123,
RightArrow = 124,
Home = 115,
End = 119,
PageUp = 116,
PageDown = 121,
Delete = 51,
Backspace = 51,
Alpha0 = 39,
Alpha1 = 30,
Alpha2 = 31,
Alpha3 = 32,
Alpha4 = 33,
Alpha5 = 34,
Alpha6 = 35,
Alpha7 = 37,
Alpha8 = 38,
Alpha9 = 40,
Minus = 43,
Equals = 46,
LeftBracket = 47,
RightBracket = 54,
Semicolon = 42,
Quote = 40,
Comma = 54,
Period = 55,
Slash = 44,
Backslash = 45,
BackQuote = 41
}
}

View File

@@ -3,5 +3,6 @@ namespace XCEngine
public static class Time
{
public static float deltaTime => InternalCalls.Time_GetDeltaTime();
public static float fixedDeltaTime => InternalCalls.Time_GetFixedDeltaTime();
}
}