重构项目src框架,添加c#脚本功能
@ -15,16 +15,11 @@ if(MSVC)
|
||||
endif ()
|
||||
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
|
||||
file(GLOB ASSETS Sandbox/assets/*)
|
||||
file(COPY ${ASSETS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
|
||||
|
||||
file(GLOB RESOURCES Sandbox/Resources/*)
|
||||
file(COPY ${RESOURCES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
|
||||
|
||||
add_subdirectory(Hazel)
|
||||
add_subdirectory(Sandbox)
|
||||
add_subdirectory(Editor)
|
||||
add_subdirectory(Hazel-ScriptCore)
|
||||
add_subdirectory(Editor/SandboxProject)
|
||||
|
||||
#add_subdirectory(Sandbox)
|
||||
37
Editor/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# Hazel-Editor
|
||||
set(PROJECT_NAME "${PROJECT_NAME}-Editor")
|
||||
project(${PROJECT_NAME})
|
||||
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# set MSVC output directory
|
||||
if(MSVC)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
endif ()
|
||||
|
||||
file(GLOB ASSETS assets/*)
|
||||
file(COPY ${ASSETS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
|
||||
|
||||
file(GLOB RESOURCES Resources/*)
|
||||
file(COPY ${RESOURCES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
|
||||
|
||||
# TODO: remove it later
|
||||
file(GLOB MONO_DEP lib)
|
||||
file(COPY ${MONO_DEP} DESTINATION ${CMAKE_BINARY_DIR})
|
||||
|
||||
file(GLOB_RECURSE SOURCES
|
||||
src/**.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Hazel)
|
||||
|
||||
# add Hazel-ScriptCore.dll dependence to auto build
|
||||
#add_dependencies(${PROJECT_NAME} Hazel-ScriptCore)
|
||||
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 119 B After Width: | Height: | Size: 119 B |
|
Before Width: | Height: | Size: 357 B After Width: | Height: | Size: 357 B |
|
Before Width: | Height: | Size: 667 B After Width: | Height: | Size: 667 B |
|
Before Width: | Height: | Size: 438 B After Width: | Height: | Size: 438 B |
|
Before Width: | Height: | Size: 115 B After Width: | Height: | Size: 115 B |
29
Editor/SandboxProject/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
set(CSPROJECT_NAME Sandbox)
|
||||
|
||||
# set MSVC output directory
|
||||
if(MSVC)
|
||||
set(SCRIPT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin/Resources/Scripts")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${SCRIPT_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SCRIPT_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${SCRIPT_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${SCRIPT_OUTPUT_DIR})
|
||||
endif ()
|
||||
|
||||
enable_language(CSharp)
|
||||
|
||||
project(${CSPROJECT_NAME} LANGUAGES CSharp)
|
||||
|
||||
file(GLOB_RECURSE CS_SOURCES
|
||||
Source/**
|
||||
Properties/
|
||||
)
|
||||
|
||||
add_library(${CSPROJECT_NAME} SHARED ${CS_SOURCES})
|
||||
|
||||
add_dependencies(${CSPROJECT_NAME} Hazel-ScriptCore)
|
||||
|
||||
set_property(TARGET ${CSPROJECT_NAME} PROPERTY VS_DOTNET_REFERENCE_Hazel-ScriptCore
|
||||
Hazel-ScriptCore
|
||||
)
|
||||
|
||||
target_link_libraries(${CSPROJECT_NAME} PRIVATE Hazel-ScriptCore)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
51
Editor/SandboxProject/Source/Player.cs
Normal 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;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 435 KiB After Width: | Height: | Size: 435 KiB |
|
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 328 KiB After Width: | Height: | Size: 328 KiB |