From cdfcd2f1c34d156144fbbb5dd6c6407a364c12e4 Mon Sep 17 00:00:00 2001 From: Chris Gregan Date: Fri, 21 Oct 2016 12:53:53 +0100 Subject: [PATCH] Fixes for compile errors on .NET Core Still has problems running Lua though. --- Assets/Fungus/Scripts/Components/Character.cs | 5 ++ .../Scripts/Components/LuaEnvironment.cs | 9 ++- .../Scripts/Utils/StringSubstituter.cs | 9 ++- .../FungusLua/Thirdparty/JSON/JSONObject.cs | 55 +++++++++++-------- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/Assets/Fungus/Scripts/Components/Character.cs b/Assets/Fungus/Scripts/Components/Character.cs index 18e57682..f0743fae 100644 --- a/Assets/Fungus/Scripts/Components/Character.cs +++ b/Assets/Fungus/Scripts/Components/Character.cs @@ -113,8 +113,13 @@ namespace Fungus /// public virtual bool NameStartsWith(string matchString) { +#if NETFX_CORE + return name.StartsWith(matchString, StringComparison.CurrentCultureIgnoreCase) + || nameText.StartsWith(matchString, StringComparison.CurrentCultureIgnoreCase); +#else return name.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture) || nameText.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture); +#endif } /// diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs index 353babe8..ab041213 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs @@ -179,7 +179,14 @@ namespace Fungus /// public static void RegisterType(string typeName, bool extensionType = false) { - System.Type t = System.Type.GetType(typeName); + System.Type t = null; + try + { + t = System.Type.GetType(typeName); + } + catch + {} + if (t == null) { UnityEngine.Debug.LogWarning("Type not found: " + typeName); diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/StringSubstituter.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/StringSubstituter.cs index b9a2644a..e87ef5eb 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/StringSubstituter.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/StringSubstituter.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using MarkerMetro.Unity.WinLegacy.Reflection; namespace Fungus { @@ -43,9 +44,15 @@ namespace Fungus public virtual void CacheSubstitutionHandlers() { // Use reflection to find all components in the scene that implement ISubstitutionHandler +#if NETFX_CORE + var types = this.GetType().GetAssembly().GetTypes().Where(type => type.IsClass() && + !type.IsAbstract() && + typeof(ISubstitutionHandler).IsAssignableFrom(type)); +#else var types = this.GetType().Assembly.GetTypes().Where(type => type.IsClass && - !type.IsAbstract && + !type.IsAbstract && typeof(ISubstitutionHandler).IsAssignableFrom(type)); +#endif substitutionHandlers.Clear(); foreach (System.Type t in types) diff --git a/Assets/Fungus/Thirdparty/FungusLua/Thirdparty/JSON/JSONObject.cs b/Assets/Fungus/Thirdparty/FungusLua/Thirdparty/JSON/JSONObject.cs index 6a509359..fcdd0f92 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Thirdparty/JSON/JSONObject.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Thirdparty/JSON/JSONObject.cs @@ -14,6 +14,7 @@ using System.Diagnostics; using System.Collections; using System.Collections.Generic; using System.Text; +using MoonSharp.Interpreter.Diagnostics.PerformanceCounters; /* * http://www.opensource.org/licenses/lgpl-2.1.php * JSONObject class v.1.4.1 @@ -732,9 +733,11 @@ public class JSONObject { } public IEnumerable PrintAsync(bool pretty = false) { StringBuilder builder = new StringBuilder(); - printWatch.Reset(); +#if !NETFX_CORE + printWatch.Reset(); printWatch.Start(); - foreach(IEnumerable e in StringifyAsync(0, builder, pretty)) { +#endif + foreach(IEnumerable e in StringifyAsync(0, builder, pretty)) { yield return null; } yield return builder.ToString(); @@ -754,12 +757,16 @@ public class JSONObject { ("reached max depth!"); yield break; } + +#if !NETFX_CORE if(printWatch.Elapsed.TotalSeconds > maxFrameTime) { printWatch.Reset(); yield return null; printWatch.Start(); } - switch(type) { +#endif + + switch(type) { case Type.BAKED: builder.Append(str); break; @@ -792,7 +799,7 @@ public class JSONObject { case Type.OBJECT: builder.Append("{"); if(list.Count > 0) { -#if(PRETTY) //for a bit more readability, comment the define above to disable system-wide +#if (PRETTY) //for a bit more readability, comment the define above to disable system-wide if(pretty) builder.Append(NEWLINE); #endif @@ -800,7 +807,7 @@ public class JSONObject { string key = keys[i]; JSONObject obj = list[i]; if(obj) { -#if(PRETTY) +#if (PRETTY) if(pretty) for(int j = 0; j < depth; j++) builder.Append("\t"); //for a bit more readability @@ -809,20 +816,20 @@ public class JSONObject { foreach(IEnumerable e in obj.StringifyAsync(depth, builder, pretty)) yield return e; builder.Append(","); -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Append(NEWLINE); #endif } } -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Length -= 2; else #endif builder.Length--; } -#if(PRETTY) +#if (PRETTY) if(pretty && list.Count > 0) { builder.Append(NEWLINE); for(int j = 0; j < depth - 1; j++) @@ -834,13 +841,13 @@ public class JSONObject { case Type.ARRAY: builder.Append("["); if(list.Count > 0) { -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Append(NEWLINE); //for a bit more readability #endif for(int i = 0; i < list.Count; i++) { if(list[i]) { -#if(PRETTY) +#if (PRETTY) if(pretty) for(int j = 0; j < depth; j++) builder.Append("\t"); //for a bit more readability @@ -848,20 +855,20 @@ public class JSONObject { foreach(IEnumerable e in list[i].StringifyAsync(depth, builder, pretty)) yield return e; builder.Append(","); -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Append(NEWLINE); //for a bit more readability #endif } } -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Length -= 2; else #endif builder.Length--; } -#if(PRETTY) +#if (PRETTY) if(pretty && list.Count > 0) { builder.Append(NEWLINE); for(int j = 0; j < depth - 1; j++) @@ -933,7 +940,7 @@ public class JSONObject { case Type.OBJECT: builder.Append("{"); if(list.Count > 0) { -#if(PRETTY) //for a bit more readability, comment the define above to disable system-wide +#if (PRETTY) //for a bit more readability, comment the define above to disable system-wide if(pretty) builder.Append("\n"); #endif @@ -941,7 +948,7 @@ public class JSONObject { string key = keys[i]; JSONObject obj = list[i]; if(obj) { -#if(PRETTY) +#if (PRETTY) if(pretty) for(int j = 0; j < depth; j++) builder.Append("\t"); //for a bit more readability @@ -949,20 +956,20 @@ public class JSONObject { builder.AppendFormat("\"{0}\":", key); obj.Stringify(depth, builder, pretty); builder.Append(","); -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Append("\n"); #endif } } -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Length -= 2; else #endif builder.Length--; } -#if(PRETTY) +#if (PRETTY) if(pretty && list.Count > 0) { builder.Append("\n"); for(int j = 0; j < depth - 1; j++) @@ -974,33 +981,33 @@ public class JSONObject { case Type.ARRAY: builder.Append("["); if(list.Count > 0) { -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Append("\n"); //for a bit more readability #endif for(int i = 0; i < list.Count; i++) { if(list[i]) { -#if(PRETTY) +#if (PRETTY) if(pretty) for(int j = 0; j < depth; j++) builder.Append("\t"); //for a bit more readability #endif list[i].Stringify(depth, builder, pretty); builder.Append(","); -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Append("\n"); //for a bit more readability #endif } } -#if(PRETTY) +#if (PRETTY) if(pretty) builder.Length -= 2; else #endif builder.Length--; } -#if(PRETTY) +#if (PRETTY) if(pretty && list.Count > 0) { builder.Append("\n"); for(int j = 0; j < depth - 1; j++) @@ -1021,7 +1028,7 @@ public class JSONObject { } //Profiler.EndSample(); } - #endregion +#endregion #if UNITY_2 || UNITY_3 || UNITY_4 || UNITY_5 public static implicit operator WWWForm(JSONObject obj) { WWWForm form = new WWWForm();