Added C# Assets System and Serialization of Script Enabled State #247

Merged
Pycorax merged 11 commits from SP3-6-c-scripting into main 2022-11-22 18:59:32 +08:00
8 changed files with 113 additions and 6 deletions
Showing only changes of commit 4478b6db62 - Show all commits

View File

@ -23,7 +23,9 @@ public class RaccoonShowcase : Script
[Range(-5, 5)]
public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 });
public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient });
public FontAsset fontAsset;
public MeshAsset mesh;
public MaterialAsset matAsset;
protected override void awake()
{
Transform = GetComponent<Transform>();

View File

@ -15,8 +15,10 @@ of DigiPen Institute of Technology is prohibited.
#include "SHEditorUI.h"
// External Dependencies
#include <imgui.h>
// Project Includes
#include "SHEditorWidgets.hpp"
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Assets/SHAssetManager.h"
namespace SHADE
{
@ -351,6 +353,53 @@ namespace SHADE
return changed;
}
bool SHEditorUI::InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered, bool alwaysNull)
{
// Label
if (!label.empty())
{
ImGui::Text(label.c_str());
ImGui::SameLine();
}
// Hover tracking
if (isHovered)
*isHovered = ImGui::IsItemHovered();
ImGui::SameLine();
// Attempt to get the asset's data for rendering editor
auto asset = SHAssetManager::GetAsset(value);
std::string assetName;
if (asset.has_value())
{
assetName = asset.value().name;
}
// Editor
bool changed = ImGui::InputText("##", &assetName, ImGuiInputTextFlags_ReadOnly);
if (SHDragDrop::BeginTarget())
{
if (AssetID* payload = SHDragDrop::AcceptPayload<AssetID>(SHDragDrop::DRAG_RESOURCE))
{
// Check if type matches
auto draggedAsset = SHAssetManager::GetAsset(*payload);
if (draggedAsset.has_value() && draggedAsset.value().type == type)
{
value = draggedAsset.value().id;
changed = true;
}
SHDragDrop::EndTarget();
}
}
ImGui::SameLine();
if (ImGui::Button("Clear"))
{
value = INVALID_ASSET_ID;
changed = true;
}
return changed;
}
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered)
{
// Clamp input value

View File

@ -19,6 +19,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Math/Vector/SHVec3.h"
#include "Math/Vector/SHVec4.h"
#include "Math/SHMatrix.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE
{
@ -310,6 +311,16 @@ namespace SHADE
/// <returns>True if the value was changed.</returns>
static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false);
/// <summary>
///
/// </summary>
/// <param name="label"></param>
/// <param name="value"></param>
/// <param name="type"></param>
/// <param name="isHovered"></param>
/// <param name="alwaysNull"></param>
/// <returns></returns>
static bool InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered = nullptr, bool alwaysNull = false);
/// <summary>
/// Creates a combo box for enumeration input.
/// </summary>
/// <typeparam name="Enum">The type of enum to input.</typeparam>

View File

@ -51,7 +51,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
FontAsset::operator bool(FontAsset asset)
{
return asset;
return asset.asset;
}
/*---------------------------------------------------------------------------------*/

View File

@ -52,7 +52,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
MaterialAsset::operator bool(MaterialAsset asset)
{
return asset;
return asset.asset;
}
/*---------------------------------------------------------------------------------*/

View File

@ -51,7 +51,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
MeshAsset::operator bool(MeshAsset asset)
{
return asset;
return asset.asset;
}
/*---------------------------------------------------------------------------------*/

View File

@ -176,7 +176,10 @@ namespace SHADE
renderSpecificField<SHVec3 , Vector3 >(field, object, SHEditorUI::InputVec3 , &isHovered) ||
renderSpecificField<uint32_t , GameObject >(field, object, nullptr , &isHovered) ||
renderSpecificField<std::string, System::String^>(field, object, nullptr , &isHovered) ||
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered);
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , FontAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , MeshAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , MaterialAsset >(field, object, nullptr , &isHovered);
if (!MODIFIED_PRIMITIVE)
{
@ -319,7 +322,10 @@ namespace SHADE
renderFieldEditor<SHVec3 , Vector3 >(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib, modified) ||
renderFieldEditor<uint32_t , GameObject >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<std::string, System::String^>(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , FontAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , MeshAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , MaterialAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
return modified;
}

View File

@ -20,6 +20,9 @@ of DigiPen Institute of Technology is prohibited.
#include "Editor/SHEditorUI.h"
// Project Includes
#include "Utility/Convert.hxx"
#include "Assets/FontAsset.hxx"
#include "Assets/MeshAsset.hxx"
#include "Assets/MaterialAsset.hxx"
namespace SHADE
{
@ -198,6 +201,42 @@ namespace SHADE
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, FontAsset>(const std::string& fieldName, interior_ptr<FontAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered, !(*managedValPtr)))
{
*managedValPtr = FontAsset(assetId);
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, MeshAsset>(const std::string& fieldName, interior_ptr<MeshAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered, !(*managedValPtr)))
{
*managedValPtr = MeshAsset(assetId);
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, MaterialAsset>(const std::string& fieldName, interior_ptr<MaterialAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered, !(*managedValPtr)))
{
*managedValPtr = MaterialAsset(assetId);
return true;
}
return false;
}
}