Weiß ich nicht, ist Monate her...

This commit is contained in:
Simon Lübeß
2023-05-30 16:54:57 +02:00
parent 5855b13873
commit 6a59deb9e2
20 changed files with 1021 additions and 234 deletions
+3
View File
@@ -5,3 +5,6 @@ Dependencies = {corlib = "*", GlitchLog = "*", GlitchyEngine = "*"}
Name = "GlitchyEditor"
TargetType = "BeefGUIApplication"
StartupObject = "GlitchyEngine.Program"
[Configs.Debug.Win64]
PreBuildCmds = ["dotnet build \"$(ProjectDir)/SandboxProject/Assets/Scripts/Sandbox.csproj\" -c Debug"]
@@ -0,0 +1,106 @@
using System;
using GlitchyEngine;
using GlitchyEngine.Editor;
using GlitchyEngine.Math;
namespace Sandbox;
public enum MyEnum
{
Yes,
No,
Maybe
}
public struct MyStruct
{
public float TheFloat;
public Vector2 TheVector;
public MyEnum TheEnum;
}
class MyTestEntity : Entity
{
//[ShowInEditor]
RigidBody2D _rigidBody;
public bool Bo;
public byte By;
public ushort Us;
public uint Ui;
public ulong Ul;
public sbyte Sb;
public short Sh;
public int In;
public long Lo;
public float Fl;
public double Do;
public Vector2 V2;
public Vector3 V3;
public Vector4 V4;
public Entity TheEntity;
public float JumpForce = 2000;
[ShowInEditor]
float MoveForce = 1000;
[ShowInEditor]
private int MyNumber = 1337;
[ShowInEditor]
public double MyDouble = 1000.0f;
public MyStruct AStruct;
/// <summary>
/// Called after the script component was created. (The entity might not be fully created yet)
/// </summary>
void OnCreate()
{
Log.Info($"Create! {UUID}");
_rigidBody ??= GetComponent<RigidBody2D>() ?? AddComponent<RigidBody2D>();
}
/// <summary>
/// Called every frame.
/// </summary>
/// <param name="deltaTime"></param>
void OnUpdate(float deltaTime)
{
Vector2 force = Vector2.Zero;
if (Input.IsKeyPressed(Key.A))
{
force.X -= MoveForce * deltaTime;
}
if (Input.IsKeyPressed(Key.D))
{
force.X += MoveForce * deltaTime;
}
if (Input.IsKeyPressing(Key.Space))
{
force.Y += JumpForce;
}
_rigidBody.ApplyForceToCenter(force);
if (Input.IsMouseButtonReleasing(MouseButton.MiddleButton))
{
Log.Info($"Ouha! {MyNumber}");
Physics2D.Gravity *= new Vector2(1, -1);
}
}
/// <summary>
/// Called before the component is being destroyed.
/// </summary>
void OnDestroy()
{
Log.Trace("Destroy");
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("Sanbox")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Sanbox")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("7a70819c-5317-402a-8553-95c5a001e370")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
//
// Hauptversion
// Nebenversion
// Buildnummer
// Revision
//
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7A70819C-5317-402A-8553-95C5A001E370}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sandbox</RootNamespace>
<AssemblyName>Sandbox</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyTestEntity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\ScriptCore\ScriptCore.csproj">
<Project>{6222c226-fc78-498c-80ba-5cf10ac9123c}</Project>
<Name>ScriptCore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Sandbox.csproj", "{7A70819C-5317-402A-8553-95C5A001E370}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptCore", "..\..\..\..\ScriptCore\ScriptCore.csproj", "{6222C226-FC78-498C-80BA-5CF10AC9123C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7A70819C-5317-402A-8553-95C5A001E370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A70819C-5317-402A-8553-95C5A001E370}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A70819C-5317-402A-8553-95C5A001E370}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A70819C-5317-402A-8553-95C5A001E370}.Release|Any CPU.Build.0 = Release|Any CPU
{6222C226-FC78-498C-80BA-5CF10AC9123C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6222C226-FC78-498C-80BA-5CF10AC9123C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6222C226-FC78-498C-80BA-5CF10AC9123C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6222C226-FC78-498C-80BA-5CF10AC9123C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B5D43D8D-D80B-41AA-BE40-1DC507D87148}
EndGlobalSection
EndGlobal
@@ -1,20 +1,16 @@
{
AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_generateMipMaps = false,
_isSrgb = false,
_samplerStateDescription = {
MinFilter = .Linear,
MagFilter = .Linear,
MipFilter = .Linear,
FilterMode = .Default,
MinFilter = .Anisotropic,
MagFilter = .Anisotropic,
MipFilter = .Anisotropic,
ComparisonFunction = .Never,
AddressModeU = .Wrap,
AddressModeV = .Wrap,
AddressModeW = .Clamp,
MipLODBias = 0,
MipMinLOD = -3.40282347e+38,
MipMaxLOD = 3.40282347e+38,
MipMinLOD = -Infinity,
MipMaxLOD = Infinity,
MaxAnisotropy = 1,
BorderColor = {
R = 1,
@@ -1,10 +1,10 @@
{
Effect = "Shaders\\myEffect.hlsl",
Effect = "Shaders/myEffect.hlsl",
Textures = [
"AlbedoTexture": "Textures\\TestMat\\rustediron2_albedo.png",
"NormalTexture": "Textures\\TestMat\\rustediron2_normal.png",
"MetallicTexture": "Textures\\TestMat\\rustediron2_metallic.png",
"RoughnessTexture": "Textures\\TestMat\\rustediron2_roughness.png"
"AlbedoTexture": "Textures/TestMat/rustediron2_albedo.png",
"NormalTexture": "Textures/TestMat/rustediron2_normal.png",
"MetallicTexture": "Textures/TestMat/rustediron2_metallic.png",
"RoughnessTexture": "Textures/TestMat/rustediron2_roughness.png"
],
Variables = [
"AlbedoColor": .ColorRGBA{
@@ -454,19 +454,174 @@ namespace GlitchyEditor.EditWindows
{
scriptComponent.Instance = new ScriptInstance(script);
scriptComponent.Instance.ReleaseRef();
ScriptEngine.InitializeInstance(entity, scriptComponent);
}
}
ImGui.EndCombo();
}
if (scriptComponent.Instance?.ScriptClass != null)
/*T GetFieldValue<T>()
{
for (let (fieldName, scriptField) in scriptComponent.Instance?.ScriptClass.Fields)
return scriptComponent.Instance.GetFieldValue<T>(monoField);
}
void SetFieldValue<T>(in T value)
{
scriptComponent.Instance.SetFieldValue<T>(monoField, value);
}*/
T GetFieldValue<T>(ScriptInstance scriptInstance, in ScriptField scriptField)
{
return scriptInstance.GetFieldValue<T>(scriptField.[Friend]_monoField);
}
void GetFieldValue<T>(ScriptInstance scriptInstance, in ScriptField scriptField, out T value)
{
value = scriptInstance.GetFieldValue<T>(scriptField.[Friend]_monoField);
}
void SetFieldValue<T>(ScriptInstance scriptInstance, in ScriptField scriptField, in T value)
{
scriptInstance.SetFieldValue<T>(scriptField.[Friend]_monoField, value);
}
void ShowClassFields(SharpClass sharpClass, ScriptInstance scriptInstance)
{
for (let (fieldName, scriptField) in sharpClass.Fields)
{
ImGui.TextUnformatted(fieldName);
var monoField = scriptField.[Friend]_monoField;
switch (scriptField.FieldType)
{
case .Bool:
var value = GetFieldValue<bool>(scriptInstance, scriptField);
if (ImGui.Checkbox(fieldName.ToScopeCStr!(), &value))
SetFieldValue(scriptInstance, scriptField, value);
case .SByte:
var value = GetFieldValue<int8>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S8, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Short:
var value = GetFieldValue<int16>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S16, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Int:
var value = GetFieldValue<int32>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S32, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Long:
var value = GetFieldValue<int64>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S64, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Byte:
var value = GetFieldValue<uint8>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U8, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .UShort:
var value = GetFieldValue<uint16>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U16, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .UInt:
var value = GetFieldValue<uint32>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U32, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .ULong:
var value = GetFieldValue<uint64>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U64, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Float:
var value = GetFieldValue<float>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Float, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Vector2:
GetFieldValue<Vector2>(scriptInstance, scriptField, var value);
if (ImGui.EditVector2(fieldName, ref value))
SetFieldValue(scriptInstance, scriptField, value);
case .Vector3:
GetFieldValue<Vector3>(scriptInstance, scriptField, var value);
if (ImGui.EditVector3(fieldName, ref value))
SetFieldValue(scriptInstance, scriptField, value);
case .Vector4:
GetFieldValue<Vector4>(scriptInstance, scriptField, var value);
if (ImGui.EditVector4(fieldName, ref value))
SetFieldValue(scriptInstance, scriptField, value);
case .Double:
var value = GetFieldValue<double>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Double, &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Entity:
// TODO!
case .Class:
// TODO!
case .Enum:
// TODO!
case .Struct:
// TODO!
/*case .Struct:
ShowStructFields();
{
uint8[128] bla = ?;
GetFieldValue<uint8[128]>(scriptInstance, scriptField);
Mono.MonoObject* dings = (Mono.MonoObject*)&bla;
//ShowFields
}*/
default:
Log.EngineLogger.Error($"Unhandled field type {scriptField.FieldType}");
}
}
}
/*void ShowStructFields(SharpClass sharpClass, ScriptInstance scriptInstance)
{
for (let (fieldName, scriptField) in sharpClass.Fields)
{
var monoField = scriptField.[Friend]_monoField;
switch (scriptField.FieldType)
{
case .Int:
int32 value = GetFieldValue<int32>(scriptInstance, scriptField);
if (ImGui.DragInt(fieldName.ToScopeCStr!(), &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Float:
float value = GetFieldValue<int32>(scriptInstance, scriptField);
if (ImGui.DragFloat(fieldName.ToScopeCStr!(), &value))
SetFieldValue(scriptInstance, scriptField, value);
case .Double:
double value = GetFieldValue<double>(scriptInstance, scriptField);
if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Double, &value))
SetFieldValue(scriptInstance, scriptField, value);
/*case .Struct:
{
uint8[128] bla = ?;
GetFieldValue<uint8[128]>(scriptInstance, scriptField);
Mono.MonoObject* dings = (Mono.MonoObject*)&bla;
//ShowFields
}*/
default:
Log.EngineLogger.Error($"Unhandled field type {scriptField.FieldType}");
}
}
}*/
if (scriptComponent.Instance?.IsInstatiated == true)
{
ShowClassFields(scriptComponent.Instance.ScriptClass, scriptComponent.Instance);
}
}
private static void LabelColumn(StringView label)