重构项目src框架,添加c#脚本功能
This commit is contained in:
51
Editor/SandboxProject/Source/Camera.cs
Normal file
51
Editor/SandboxProject/Source/Camera.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Hazel;
|
||||
|
||||
namespace Sandbox {
|
||||
|
||||
public class Camera : Entity
|
||||
{
|
||||
// private TransformComponent m_Transform;
|
||||
// private RigidBody2DComponent m_Rigidbody;
|
||||
|
||||
|
||||
/*
|
||||
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 = 1.0f;
|
||||
Vector3 velocity = Vector3.Zero;
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.UP))
|
||||
velocity.Y = 1.0f;
|
||||
else if(Input.IsKeyDown(KeyCode.DOWN))
|
||||
velocity.Y = -1.0f;
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.LEFT))
|
||||
velocity.X = -1.0f;
|
||||
else if(Input.IsKeyDown(KeyCode.RIGHT))
|
||||
velocity.X = 1.0f;
|
||||
|
||||
// m_Rigidbody.ApplyLinearImpulse(velocity.XY * speed, Vector2.Zero, true);
|
||||
|
||||
velocity *= speed;
|
||||
|
||||
Vector3 translation = Translation;
|
||||
translation += velocity * ts;
|
||||
Translation = translation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user