Added a script to test Transform modifications

This commit is contained in:
Kah Wei 2022-09-27 01:57:23 +08:00
parent e42283a553
commit 085ab50ec7
2 changed files with 23 additions and 11 deletions

View File

@ -35,14 +35,14 @@ namespace Sandbox
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
// Create temp meshes
const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem);
//graphicsSystem->BuildMeshBuffers();
//Test Racoon mesh
auto meshes = SHADE::SHAssetManager::GetAllMeshes();
std::vector<Handle<SHMesh>> handles;
for (auto const& mesh : meshes)
{
handles.push_back(graphicsSystem->AddMesh(
handles.push_back(graphicsSystem->AddMesh
(
mesh.header.vertexCount,
mesh.vertexPosition.data(),
mesh.texCoords.data(),
@ -80,19 +80,23 @@ namespace Sandbox
// stressTestObjects.emplace_back(entity);
//}
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
renderable.Mesh = handles.front();
renderable.SetMaterial(matInst);
renderable.Mesh = handles.front();
renderable.SetMaterial(matInst);
//transform.SetLocalScale(TEST_OBJ_SCALE);
//transform.SetLocalScale(TEST_OBJ_SCALE);
stressTestObjects.emplace_back(entity);
stressTestObjects.emplace_back(entity);
// Create blank entity with a script
testObj = SHADE::SHEntityManager::CreateEntity();
testObj = SHADE::SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderableTestObj = *SHComponentManager::GetComponent_s<SHRenderable>(testObj);
renderableTestObj.Mesh = CUBE_MESH;
renderableTestObj.SetMaterial(matInst);
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
scriptEngine->AddScript(testObj, "TestScript");
}

View File

@ -2,11 +2,18 @@ using SHADE;
public class TestScript : Script
{
private Transform Transform;
private double time = 0.0;
public TestScript(GameObject gameObj) : base(gameObj) {}
protected override void awake()
{
Debug.Log("TestScript.Awake()");
Transform = GetComponent<Transform>();
if (Transform == null)
{
Debug.LogError("Transform is NULL!");
}
}
protected override void start()
{
@ -14,7 +21,8 @@ public class TestScript : Script
}
protected override void update()
{
Debug.Log("TestScript.Update()");
time += 0.16;
Transform.GlobalPosition = new Vector3(System.Math.Sin(time), System.Math.Cos(time), 0.0f);
}
protected override void onDestroy()
{