@@ -1,3 +1,4 @@ | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
@@ -61,3 +62,4 @@ namespace Svelto.Context | |||
Dictionary<string, GameObject[]> _prefabs; | |||
} | |||
} | |||
#endif |
@@ -1,3 +1,4 @@ | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
#region | |||
using System; | |||
@@ -18,3 +19,4 @@ namespace Svelto.Context | |||
} | |||
} | |||
} | |||
#endif |
@@ -1,3 +1,4 @@ | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
namespace Svelto.Context | |||
{ | |||
public interface ICompositionRoot | |||
@@ -7,5 +8,4 @@ namespace Svelto.Context | |||
void OnContextDestroyed(); | |||
} | |||
} | |||
#endif |
@@ -1,3 +1,4 @@ | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
using System.Collections; | |||
using Svelto.Context; | |||
using UnityEngine; | |||
@@ -42,3 +43,4 @@ public class UnityContext<T>: UnityContext where T:class, ICompositionRoot, new( | |||
T _applicationRoot; | |||
} | |||
#endif |
@@ -2,7 +2,6 @@ using System; | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using System.Threading; | |||
using UnityEngine; | |||
namespace Svelto.DataStructures | |||
{ | |||
@@ -766,14 +765,14 @@ namespace Svelto.DataStructures | |||
void AllocateMore() | |||
{ | |||
var newList = new T[Mathf.Max(_buffer.Length << 1, MIN_SIZE)]; | |||
var newList = new T[Math.Max(_buffer.Length << 1, MIN_SIZE)]; | |||
if (_count > 0) _buffer.CopyTo(newList, 0); | |||
_buffer = newList; | |||
} | |||
void AllocateMore(int newSize) | |||
{ | |||
var oldLength = Mathf.Max(_buffer.Length, MIN_SIZE); | |||
var oldLength = Math.Max(_buffer.Length, MIN_SIZE); | |||
while (oldLength < newSize) | |||
oldLength <<= 1; | |||
@@ -1,5 +1,4 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Threading; | |||
@@ -11,7 +10,7 @@ namespace Svelto.DataStructures | |||
/// </summary> | |||
/// <typeparam name = "TKey"></typeparam> | |||
/// <typeparam name = "TValue"></typeparam> | |||
[Serializable] | |||
public class ThreadSafeDictionary<TKey, TValue> | |||
{ | |||
public ThreadSafeDictionary(int v) | |||
@@ -1,5 +1,4 @@ | |||
using System; | |||
using System.Runtime.Serialization; | |||
/// <span class="code-SummaryComment"><summary></span> | |||
/// Represents a weak reference, which references an object while still allowing | |||
/// that object to be reclaimed by garbage collection. | |||
@@ -8,7 +7,7 @@ using System.Runtime.Serialization; | |||
namespace Svelto.DataStructures | |||
{ | |||
[Serializable] | |||
#if !NETFX_CORE | |||
public class WeakReference<T> | |||
: WeakReference where T : class | |||
{ | |||
@@ -50,15 +49,31 @@ namespace Svelto.DataStructures | |||
public WeakReference(T target, bool trackResurrection) | |||
: base(target, trackResurrection) | |||
{ } | |||
#if !NETFX_CORE | |||
protected WeakReference(SerializationInfo info, StreamingContext context) | |||
: base(info, context) | |||
{ } | |||
#endif | |||
} | |||
public static class WeakReferenceUtility | |||
#else | |||
public class WeakReference<T> : System.WeakReference where T : class | |||
{ | |||
public static bool IsValid(this WeakReference obj) { return obj != null && obj.IsAlive == true && obj.Target != null; } | |||
public bool IsValid { get { return Target != null && IsAlive == true; } } | |||
public new T Target | |||
{ | |||
get | |||
{ | |||
return (T)base.Target; | |||
} | |||
set | |||
{ | |||
base.Target = value; | |||
} | |||
} | |||
public WeakReference(T target) | |||
: base(target) | |||
{ } | |||
public WeakReference(T target, bool trackResurrection) | |||
: base(target, trackResurrection) | |||
{ } | |||
} | |||
#endif | |||
} |
@@ -2,9 +2,6 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using Svelto.DataStructures; | |||
#if NETFX_CORE | |||
using BindingFlags = System.Reflection.BindingFlags; | |||
#endif | |||
namespace Svelto.ECS | |||
{ | |||
@@ -33,8 +30,11 @@ namespace Svelto.ECS | |||
{ | |||
var implementor = implementors[index]; | |||
if (implementor == null) | |||
{ | |||
Utility.Console.LogWarning( | |||
"Null implementor, are you using a wild GetComponents<Monobehaviour> to fetch it? ").FastConcat(ToString())); | |||
"Null implementor, are you using a wild GetComponents<Monobehaviour> to fetch it? " | |||
.FastConcat(ToString())); | |||
} | |||
else | |||
{ | |||
if (implementor is IRemoveEntityComponent) | |||
@@ -371,7 +371,7 @@ namespace DesignByContract | |||
/// any DesignByContract exception and other runtime exceptions. | |||
/// | |||
/// </summary> | |||
public class DesignByContractException : ApplicationException | |||
public class DesignByContractException : Exception | |||
{ | |||
protected DesignByContractException() {} | |||
protected DesignByContractException(string message) : base(message) {} | |||
@@ -1,7 +1,6 @@ | |||
using System; | |||
using System.Diagnostics; | |||
using System.Text; | |||
using UnityEngine; | |||
public static class FastConcatUtility | |||
{ | |||
@@ -101,8 +100,8 @@ namespace Utility | |||
{ | |||
void Log (string txt, string stack = null, LogType type = LogType.Log); | |||
} | |||
public class SlowLogger : ILogger | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
public class SlowLoggerUnity : ILogger | |||
{ | |||
public void Log(string txt, string stack = null, LogType type = LogType.Log) | |||
{ | |||
@@ -123,12 +122,45 @@ namespace Utility | |||
} | |||
} | |||
} | |||
#endif | |||
public class SimpleLogger : ILogger | |||
{ | |||
public void Log(string txt, string stack = null, LogType type = LogType.Log) | |||
{ | |||
switch (type) | |||
{ | |||
case LogType.Log: | |||
Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt); | |||
break; | |||
case LogType.Exception: | |||
Console.SystemLog("Log of exceptions not supported"); | |||
break; | |||
case LogType.Warning: | |||
Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt); | |||
break; | |||
case LogType.Error: | |||
Console.SystemLog(stack != null ? txt.FastConcat(stack) : txt); | |||
break; | |||
} | |||
} | |||
} | |||
public enum LogType | |||
{ | |||
Log, | |||
Exception, | |||
Warning, | |||
Error | |||
} | |||
public static class Console | |||
{ | |||
static StringBuilder _stringBuilder = new StringBuilder(256); | |||
public static ILogger logger = new SlowLogger(); | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
public static ILogger logger = new SlowLoggerUnity(); | |||
#else | |||
public static ILogger logger = new SimpleLogger(); | |||
#endif | |||
public static volatile bool BatchLog = false; | |||
public static void Log(string txt) | |||
@@ -167,17 +199,18 @@ namespace Utility | |||
logger.Log(toPrint, stack, LogType.Error); | |||
} | |||
public static void LogException(Exception e) | |||
{ | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
LogException(e, null); | |||
#endif | |||
} | |||
#if UNITY_5 || UNITY_5_3_OR_NEWER | |||
public static void LogException(Exception e, UnityEngine.Object obj) | |||
{ | |||
UnityEngine.Debug.LogException(e, obj); | |||
} | |||
#endif | |||
public static void LogWarning(string txt) | |||
{ | |||
string toPrint; | |||
@@ -217,13 +250,11 @@ namespace Utility | |||
toPrint = _stringBuilder.ToString(); | |||
} | |||
#if !UNITY_EDITOR | |||
#if !UNITY_EDITOR | |||
System.Console.WriteLine(toPrint); | |||
#else | |||
UnityEngine.Debug.Log(toPrint); | |||
#endif | |||
#else | |||
UnityEngine.Debug.Log(txt); | |||
#endif | |||
} | |||
} | |||