diff --git a/.gitignore b/.gitignore index eaec275..9f04053 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ .idea # Unity upgrade logs -Unity/Logs \ No newline at end of file +Unity/Logs + +# MacOS +.DS_Store \ No newline at end of file diff --git a/Unity/Assets/CppSource/CMakeLists.txt b/Unity/Assets/CppSource/CMakeLists.txt index 2baa025..8beb953 100644 --- a/Unity/Assets/CppSource/CMakeLists.txt +++ b/Unity/Assets/CppSource/CMakeLists.txt @@ -55,10 +55,6 @@ elseif (WIN32 OR (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") OR (${CMAKE_SYSTEM_NAME endif() endif() -# Set the directories for NativeScript and game C++ as include directories -include_directories( - ${CMAKE_SOURCE_DIR}/NativeScript - ${CMAKE_SOURCE_DIR}/Game) # Set all .cpp files for NativeScript and the game as sources file(GLOB GAMESOURCEFILES ${CMAKE_SOURCE_DIR}/Game/*.cpp) @@ -74,6 +70,14 @@ set( # Build a library. If on an Apple platform, build it in a bundle. add_library(${PROJECT_NAME} MODULE ${SOURCES}) + +# Set the directories for NativeScript and game C++ as include directories +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_SOURCE_DIR}/NativeScript + ${CMAKE_SOURCE_DIR}/Game +) + set_target_properties(${PROJECT_NAME} PROPERTIES BUNDLE TRUE) if (IOS) set_xcode_property(${PROJECT_NAME} ENABLE_BITCODE "NO") diff --git a/Unity/Assets/CppSource/NativeScript/Bindings.cpp b/Unity/Assets/CppSource/NativeScript/Bindings.cpp index 8cb2e2e..124def7 100644 --- a/Unity/Assets/CppSource/NativeScript/Bindings.cpp +++ b/Unity/Assets/CppSource/NativeScript/Bindings.cpp @@ -1267,6 +1267,87 @@ namespace System } } +namespace System +{ + ISpanFormattable::ISpanFormattable(decltype(nullptr)) + { + } + + ISpanFormattable::ISpanFormattable(Plugin::InternalUse, int32_t handle) + { + Handle = handle; + if (handle) + { + Plugin::ReferenceManagedClass(handle); + } + } + + ISpanFormattable::ISpanFormattable(const ISpanFormattable& other) + : ISpanFormattable(Plugin::InternalUse::Only, other.Handle) + { + } + + ISpanFormattable::ISpanFormattable(ISpanFormattable&& other) + : ISpanFormattable(Plugin::InternalUse::Only, other.Handle) + { + other.Handle = 0; + } + + ISpanFormattable::~ISpanFormattable() + { + if (Handle) + { + Plugin::DereferenceManagedClass(Handle); + Handle = 0; + } + } + + ISpanFormattable& ISpanFormattable::operator=(const ISpanFormattable& other) + { + if (this->Handle) + { + Plugin::DereferenceManagedClass(this->Handle); + } + this->Handle = other.Handle; + if (this->Handle) + { + Plugin::ReferenceManagedClass(this->Handle); + } + return *this; + } + + ISpanFormattable& ISpanFormattable::operator=(decltype(nullptr)) + { + if (Handle) + { + Plugin::DereferenceManagedClass(Handle); + Handle = 0; + } + return *this; + } + + ISpanFormattable& ISpanFormattable::operator=(ISpanFormattable&& other) + { + if (Handle) + { + Plugin::DereferenceManagedClass(Handle); + } + Handle = other.Handle; + other.Handle = 0; + return *this; + } + + bool ISpanFormattable::operator==(const ISpanFormattable& other) const + { + return Handle == other.Handle; + } + + bool ISpanFormattable::operator!=(const ISpanFormattable& other) const + { + return Handle != other.Handle; + } +} + namespace System { IConvertible::IConvertible(decltype(nullptr)) @@ -3853,7 +3934,7 @@ namespace System return nullptr; } - System::Decimal::operator System::IComparable() + System::Decimal::operator System::IEquatable_1() { int32_t handle = Plugin::BoxDecimal(Handle); if (Plugin::unhandledCsharpException) @@ -3866,12 +3947,12 @@ namespace System if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IComparable(Plugin::InternalUse::Only, handle); + return System::IEquatable_1(Plugin::InternalUse::Only, handle); } return nullptr; } - System::Decimal::operator System::IComparable_1() + System::Decimal::operator System::IFormattable() { int32_t handle = Plugin::BoxDecimal(Handle); if (Plugin::unhandledCsharpException) @@ -3884,12 +3965,12 @@ namespace System if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IComparable_1(Plugin::InternalUse::Only, handle); + return System::IFormattable(Plugin::InternalUse::Only, handle); } return nullptr; } - System::Decimal::operator System::IConvertible() + System::Decimal::operator System::ISpanFormattable() { int32_t handle = Plugin::BoxDecimal(Handle); if (Plugin::unhandledCsharpException) @@ -3902,12 +3983,12 @@ namespace System if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IConvertible(Plugin::InternalUse::Only, handle); + return System::ISpanFormattable(Plugin::InternalUse::Only, handle); } return nullptr; } - System::Decimal::operator System::IEquatable_1() + System::Decimal::operator System::IComparable() { int32_t handle = Plugin::BoxDecimal(Handle); if (Plugin::unhandledCsharpException) @@ -3920,7 +4001,7 @@ namespace System if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IEquatable_1(Plugin::InternalUse::Only, handle); + return System::IComparable(Plugin::InternalUse::Only, handle); } return nullptr; } @@ -3943,7 +4024,7 @@ namespace System return nullptr; } - System::Decimal::operator System::IFormattable() + System::Decimal::operator System::IComparable_1() { int32_t handle = Plugin::BoxDecimal(Handle); if (Plugin::unhandledCsharpException) @@ -3956,7 +4037,25 @@ namespace System if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IFormattable(Plugin::InternalUse::Only, handle); + return System::IComparable_1(Plugin::InternalUse::Only, handle); + } + return nullptr; + } + + System::Decimal::operator System::IConvertible() + { + int32_t handle = Plugin::BoxDecimal(Handle); + if (Plugin::unhandledCsharpException) + { + System::Exception* ex = Plugin::unhandledCsharpException; + Plugin::unhandledCsharpException = nullptr; + ex->ThrowReferenceToThis(); + delete ex; + } + if (handle) + { + Plugin::ReferenceManagedClass(handle); + return System::IConvertible(Plugin::InternalUse::Only, handle); } return nullptr; } @@ -4063,6 +4162,24 @@ namespace UnityEngine } return nullptr; } + + UnityEngine::Vector3::operator System::IFormattable() + { + int32_t handle = Plugin::BoxVector3(*this); + if (Plugin::unhandledCsharpException) + { + System::Exception* ex = Plugin::unhandledCsharpException; + Plugin::unhandledCsharpException = nullptr; + ex->ThrowReferenceToThis(); + delete ex; + } + if (handle) + { + Plugin::ReferenceManagedClass(handle); + return System::IFormattable(Plugin::InternalUse::Only, handle); + } + return nullptr; + } } namespace System @@ -5422,7 +5539,7 @@ namespace UnityEngine return nullptr; } - UnityEngine::PrimitiveType::operator System::IComparable() + UnityEngine::PrimitiveType::operator System::IFormattable() { int32_t handle = Plugin::BoxPrimitiveType(*this); if (Plugin::unhandledCsharpException) @@ -5435,12 +5552,12 @@ namespace UnityEngine if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IComparable(Plugin::InternalUse::Only, handle); + return System::IFormattable(Plugin::InternalUse::Only, handle); } return nullptr; } - UnityEngine::PrimitiveType::operator System::IConvertible() + UnityEngine::PrimitiveType::operator System::IComparable() { int32_t handle = Plugin::BoxPrimitiveType(*this); if (Plugin::unhandledCsharpException) @@ -5453,12 +5570,12 @@ namespace UnityEngine if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IConvertible(Plugin::InternalUse::Only, handle); + return System::IComparable(Plugin::InternalUse::Only, handle); } return nullptr; } - UnityEngine::PrimitiveType::operator System::IFormattable() + UnityEngine::PrimitiveType::operator System::IConvertible() { int32_t handle = Plugin::BoxPrimitiveType(*this); if (Plugin::unhandledCsharpException) @@ -5471,7 +5588,7 @@ namespace UnityEngine if (handle) { Plugin::ReferenceManagedClass(handle); - return System::IFormattable(Plugin::InternalUse::Only, handle); + return System::IConvertible(Plugin::InternalUse::Only, handle); } return nullptr; } diff --git a/Unity/Assets/CppSource/NativeScript/Bindings.h b/Unity/Assets/CppSource/NativeScript/Bindings.h index 4da12a4..b83ab11 100644 --- a/Unity/Assets/CppSource/NativeScript/Bindings.h +++ b/Unity/Assets/CppSource/NativeScript/Bindings.h @@ -305,6 +305,11 @@ namespace System struct IFormattable; } +namespace System +{ + struct ISpanFormattable; +} + namespace System { struct IConvertible; @@ -698,6 +703,23 @@ namespace System }; } +namespace System +{ + struct ISpanFormattable : virtual System::Object + { + ISpanFormattable(decltype(nullptr)); + ISpanFormattable(Plugin::InternalUse, int32_t handle); + ISpanFormattable(const ISpanFormattable& other); + ISpanFormattable(ISpanFormattable&& other); + virtual ~ISpanFormattable(); + ISpanFormattable& operator=(const ISpanFormattable& other); + ISpanFormattable& operator=(decltype(nullptr)); + ISpanFormattable& operator=(ISpanFormattable&& other); + bool operator==(const ISpanFormattable& other) const; + bool operator!=(const ISpanFormattable& other) const; + }; +} + namespace System { struct IConvertible : virtual System::Object @@ -1232,12 +1254,13 @@ namespace System Decimal(System::UInt64 value); explicit operator System::ValueType(); explicit operator System::Object(); + explicit operator System::IEquatable_1(); + explicit operator System::IFormattable(); + explicit operator System::ISpanFormattable(); explicit operator System::IComparable(); + explicit operator System::Runtime::Serialization::IDeserializationCallback(); explicit operator System::IComparable_1(); explicit operator System::IConvertible(); - explicit operator System::IEquatable_1(); - explicit operator System::Runtime::Serialization::IDeserializationCallback(); - explicit operator System::IFormattable(); }; } @@ -1254,6 +1277,7 @@ namespace UnityEngine explicit operator System::ValueType(); explicit operator System::Object(); explicit operator System::IEquatable_1(); + explicit operator System::IFormattable(); }; } @@ -1330,7 +1354,7 @@ namespace System bool operator==(const IEnumerator& other) const; bool operator!=(const IEnumerator& other) const; System::Object GetCurrent(); - System::Boolean MoveNext(); + virtual System::Boolean MoveNext(); }; } } @@ -1523,9 +1547,9 @@ namespace UnityEngine explicit operator System::Enum(); explicit operator System::ValueType(); explicit operator System::Object(); + explicit operator System::IFormattable(); explicit operator System::IComparable(); explicit operator System::IConvertible(); - explicit operator System::IFormattable(); }; } diff --git a/Unity/Assets/NativeScript/Bindings.cs b/Unity/Assets/NativeScript/Bindings.cs index 3ae570d..1b17f83 100644 --- a/Unity/Assets/NativeScript/Bindings.cs +++ b/Unity/Assets/NativeScript/Bindings.cs @@ -266,14 +266,15 @@ public DestroyEntry(DestroyFunction function, int cppHandle) const string PLUGIN_NAME = "NativeScript"; #endif - // Path to load the plugin from when running inside the editor + // Path to load the plugin from when running inside the editor + const string BASE_PATH = "/" + NativeScriptConstants.BASE_PATH; #if UNITY_EDITOR_OSX - const string PLUGIN_PATH = "/Plugins/Editor/NativeScript.bundle/Contents/MacOS/NativeScript"; + const string PLUGIN_PATH = BASE_PATH + "/Plugins/Editor/NativeScript.bundle/Contents/MacOS/NativeScript"; #elif UNITY_EDITOR_LINUX - const string PLUGIN_PATH = "/Plugins/Editor/libNativeScript.so"; + const string PLUGIN_PATH = BASE_PATH + "/Plugins/Editor/libNativeScript.so"; #elif UNITY_EDITOR_WIN - const string PLUGIN_PATH = "/Plugins/Editor/NativeScript.dll"; - const string PLUGIN_TEMP_PATH = "/Plugins/Editor/NativeScript_temp.dll"; + const string PLUGIN_PATH = BASE_PATH + "/Plugins/Editor/NativeScript.dll"; + const string PLUGIN_TEMP_PATH = BASE_PATH + "/Plugins/Editor/NativeScript_temp.dll"; #endif enum InitMode : byte diff --git a/Unity/Assets/NativeScript/Editor/GenerateBindings.cs b/Unity/Assets/NativeScript/Editor/GenerateBindings.cs index be815bc..c512131 100644 --- a/Unity/Assets/NativeScript/Editor/GenerateBindings.cs +++ b/Unity/Assets/NativeScript/Editor/GenerateBindings.cs @@ -292,17 +292,15 @@ struct TypeName static readonly string ProjectDirPath = ProjectDir.FullName; static readonly string CppDirPath = Path.Combine( - Path.Combine( - Path.Combine( - ProjectDirPath, - "Assets"), - "CppSource"), + AssetsDirPath, + NativeScriptConstants.BASE_PATH, + "CppSource", "NativeScript"); static readonly string CsharpPath = Path.Combine( AssetsDirPath, - Path.Combine( - "NativeScript", - "Bindings.cs")); + NativeScriptConstants.BASE_PATH, + "NativeScript", + "Bindings.cs"); static readonly string CppHeaderPath = Path.Combine( CppDirPath, "Bindings.h"); @@ -636,6 +634,7 @@ static JsonDocument LoadJson() { string jsonPath = Path.Combine( Application.dataPath, + NativeScriptConstants.BASE_PATH, NativeScriptConstants.JSON_CONFIG_PATH); string json = File.ReadAllText(jsonPath); return JsonUtility.FromJson(json); @@ -716,7 +715,7 @@ static Assembly[] GetAssemblies(string[] assemblyNames) #endif assemblies[31] = typeof(Canvas).Assembly; // Unity UI module #if UNITY_2020_1_OR_NEWER - assemblies[32] = typeof(UnityEngine.Networking.Utility).Assembly; // Unity network module + // assemblies[32] = typeof(UnityEngine.Networking.Utility).Assembly; // Unity network module #else assemblies[32] = typeof(UnityEngine.Networking.NetworkTransport).Assembly; // Unity network module #endif @@ -781,7 +780,7 @@ static Type TryGetType( // Search all assemblies for the type foreach (Assembly assembly in assemblies) { - Type type = assembly.GetType(typeName); + Type type = assembly?.GetType(typeName); if (type != null) { return type; @@ -4164,7 +4163,7 @@ static void AppendMethod( cppMethodName, enclosingTypeIsStatic, // Mark as virtual if method/class is not static or generic - cppMethodIsStatic || enclosingTypeIsStatic || methodTypeParams != null? false : true, + (enclosingTypeKind == TypeKind.FullStruct || cppMethodIsStatic || enclosingTypeIsStatic || methodTypeParams != null)? false : true, cppMethodIsStatic, cppReturnType, methodTypeParams, diff --git a/Unity/Assets/NativeScriptConstants.cs b/Unity/Assets/NativeScriptConstants.cs index 54e6923..f3d7863 100644 --- a/Unity/Assets/NativeScriptConstants.cs +++ b/Unity/Assets/NativeScriptConstants.cs @@ -13,5 +13,6 @@ public static class NativeScriptConstants /// /// Path within the Unity project to the exposed types JSON file /// + public const string BASE_PATH = "Libraries/NativeScripting"; public const string JSON_CONFIG_PATH = "NativeScriptTypes.json"; } \ No newline at end of file diff --git a/Unity/Assets/NativeScriptTypes.json b/Unity/Assets/NativeScriptTypes.json index c507547..2a01c70 100644 --- a/Unity/Assets/NativeScriptTypes.json +++ b/Unity/Assets/NativeScriptTypes.json @@ -5,6 +5,9 @@ { "Name": " System.IFormattable" }, + { + "Name": " System.ISpanFormattable" + }, { "Name": " System.IConvertible" },