重构项目src框架,添加c#脚本功能

This commit is contained in:
2025-07-13 00:38:11 +08:00
parent 02c7e0fcf9
commit e0bfdd9c4e
573 changed files with 13094 additions and 191 deletions

View File

@ -0,0 +1,51 @@
using System;
using Hazel;
namespace Sandbox {
public class Player : Entity
{
private TransformComponent m_Transform;
private RigidBody2DComponent m_Rigidbody;
public float Speed = 1.0f;
void OnCreate()
{
Console.WriteLine($"Player.OnCreate - {ID}");
m_Transform = GetComponent<TransformComponent>();
m_Rigidbody = GetComponent<RigidBody2DComponent>();
}
void OnUpdate(float ts)
{
// Console.WriteLine($"Player.OnUpdate: {ts}");
float speed = Speed;
Vector3 velocity = Vector3.Zero;
if(Input.IsKeyDown(KeyCode.W))
velocity.Y = 1.0f;
else if(Input.IsKeyDown(KeyCode.S))
velocity.Y = -1.0f;
if(Input.IsKeyDown(KeyCode.A))
velocity.X = -1.0f;
else if(Input.IsKeyDown(KeyCode.D))
velocity.X = 1.0f;
m_Rigidbody.ApplyLinearImpulseToCenter(velocity.XY * speed, true);
/*
velocity *= speed;
Vector3 translation = m_Transform.Translation;
translation += velocity * ts;
m_Transform.Translation = translation;
*/
}
}
}