diff --git a/Factories.meta b/Factories.meta new file mode 100644 index 0000000..5cf0144 --- /dev/null +++ b/Factories.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 354b7801c1d782b47b5d9ff9aba85e83 +folderAsset: yes +timeCreated: 1434752394 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Factories/IGameObjectFactory.cs b/Factories/IGameObjectFactory.cs new file mode 100644 index 0000000..f7231da --- /dev/null +++ b/Factories/IGameObjectFactory.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace Svelto.Factories +{ + public interface IGameObjectFactory + { + void RegisterPrefab(GameObject prefab, string type, GameObject parent = null); + + GameObject Build(string type); + GameObject Build(GameObject go); + } +} diff --git a/Factories/IGameObjectFactory.cs.meta b/Factories/IGameObjectFactory.cs.meta new file mode 100644 index 0000000..dc6c4b9 --- /dev/null +++ b/Factories/IGameObjectFactory.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f3720a403a14c51489b5250365b7185c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Factories/IMonoBehaviourFactory.cs b/Factories/IMonoBehaviourFactory.cs new file mode 100644 index 0000000..cbf5e05 --- /dev/null +++ b/Factories/IMonoBehaviourFactory.cs @@ -0,0 +1,11 @@ +using System; +using UnityEngine; + +namespace Svelto.Factories +{ + public interface IMonoBehaviourFactory + { + M Build(Func constructor) where M:MonoBehaviour; + } +} + diff --git a/Factories/IMonoBehaviourFactory.cs.meta b/Factories/IMonoBehaviourFactory.cs.meta new file mode 100644 index 0000000..1a2f1b4 --- /dev/null +++ b/Factories/IMonoBehaviourFactory.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 22ba598cf1fd5124dbb4b999af89a0c5 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/LICENSE.meta b/LICENSE.meta new file mode 100644 index 0000000..0999b4e --- /dev/null +++ b/LICENSE.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ab819523a7b1394499edac4ffa37556b +timeCreated: 1440946962 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..cabd763 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e772c63482a119748ba160ed807765a3 +timeCreated: 1440946962 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Utilities.meta b/Utilities.meta new file mode 100644 index 0000000..0f482d6 --- /dev/null +++ b/Utilities.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9581aacbfc73076489f471e3e83ba71d +folderAsset: yes +timeCreated: 1440947158 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Utilities/DesignByContract.cs b/Utilities/DesignByContract.cs new file mode 100644 index 0000000..f69b621 --- /dev/null +++ b/Utilities/DesignByContract.cs @@ -0,0 +1,543 @@ +// from: http://www.codeproject.com/Articles/1863/Design-by-Contract-Framework +// Provides support for Design By Contract +// as described by Bertrand Meyer in his seminal book, +// Object-Oriented Software Construction (2nd Ed) Prentice Hall 1997 +// (See chapters 11 and 12). +// +// See also Building Bug-free O-O Software: An Introduction to Design by Contract +// http://www.eiffel.com/doc/manuals/technology/contract/ +// +// The following conditional compilation symbols are supported: +// +// These suggestions are based on Bertrand Meyer's Object-Oriented Software Construction (2nd Ed) p393 +// +// DBC_CHECK_ALL - Check assertions - implies checking preconditions, postconditions and invariants +// DBC_CHECK_INVARIANT - Check invariants - implies checking preconditions and postconditions +// DBC_CHECK_POSTCONDITION - Check postconditions - implies checking preconditions +// DBC_CHECK_PRECONDITION - Check preconditions only, e.g., in Release build +// +// A suggested default usage scenario is the following: +// +// #if DEBUG +// #define DBC_CHECK_ALL +// #else +// #define DBC_CHECK_PRECONDITION +// #endif +// +// Alternatively, you can define these in the project properties dialog. + +#if UNITY_EDITOR || ROBO_TEST_BUILD +#define DBC_CHECK_ALL +#endif + +using System; +using System.Diagnostics; + +namespace DesignByContract +{ + /// + /// Design By Contract Checks. + /// + /// Each method generates an exception or + /// a trace assertion statement if the contract is broken. + /// + /// + /// This example shows how to call the Require method. + /// Assume DBC_CHECK_PRECONDITION is defined. + /// + /// public void Test(int x) + /// { + /// try + /// { + /// Check.Require(x > 1, "x must be > 1"); + /// } + /// catch (System.Exception ex) + /// { + /// Console.WriteLine(ex.ToString()); + /// } + /// } + /// + /// If you wish to use trace assertion statements, intended for Debug scenarios, + /// rather than exception handling then set + /// + /// Check.UseAssertions = true + /// + /// You can specify this in your application entry point and maybe make it + /// dependent on conditional compilation flags or configuration file settings, e.g., + /// + /// #if DBC_USE_ASSERTIONS + /// Check.UseAssertions = true; + /// #endif + /// + /// You can direct output to a Trace listener. For example, you could insert + /// + /// Trace.Listeners.Clear(); + /// Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); + /// + /// + /// or direct output to a file or the Event Log. + /// + /// (Note: For ASP.NET clients use the Listeners collection + /// of the Debug, not the Trace, object and, for a Release build, only exception-handling + /// is possible.) + /// + /// + public sealed class Check + { + #region Interface + + /// + /// Precondition check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION"), + Conditional("DBC_CHECK_PRECONDITION")] + public static void Require(bool assertion, string message) + { + if (UseExceptions) + { + if (!assertion) + throw new PreconditionException(message); + } + else + { + Trace.Assert(assertion, "Precondition: " + message); + } + } + + /// + /// Precondition check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION"), + Conditional("DBC_CHECK_PRECONDITION")] + public static void Require(bool assertion, string message, Exception inner) + { + if (UseExceptions) + { + if (!assertion) + throw new PreconditionException(message, inner); + } + else + { + Trace.Assert(assertion, "Precondition: " + message); + } + } + + /// + /// Precondition check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION"), + Conditional("DBC_CHECK_PRECONDITION")] + public static void Require(bool assertion) + { + if (UseExceptions) + { + if (!assertion) + throw new PreconditionException("Precondition failed."); + } + else + { + Trace.Assert(assertion, "Precondition failed."); + } + } + + /// + /// Postcondition check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION")] + public static void Ensure(bool assertion, string message) + { + if (UseExceptions) + { + if (!assertion) + throw new PostconditionException(message); + } + else + { + Trace.Assert(assertion, "Postcondition: " + message); + } + } + + /// + /// Postcondition check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION")] + public static void Ensure(bool assertion, string message, Exception inner) + { + if (UseExceptions) + { + if (!assertion) + throw new PostconditionException(message, inner); + } + else + { + Trace.Assert(assertion, "Postcondition: " + message); + } + } + + /// + /// Postcondition check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION")] + public static void Ensure(bool assertion) + { + if (UseExceptions) + { + if (!assertion) + throw new PostconditionException("Postcondition failed."); + } + else + { + Trace.Assert(assertion, "Postcondition failed."); + } + } + + /// + /// Invariant check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT")] + public static void Invariant(bool assertion, string message) + { + if (UseExceptions) + { + if (!assertion) + throw new InvariantException(message); + } + else + { + Trace.Assert(assertion, "Invariant: " + message); + } + } + + /// + /// Invariant check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT")] + public static void Invariant(bool assertion, string message, Exception inner) + { + if (UseExceptions) + { + if (!assertion) + throw new InvariantException(message, inner); + } + else + { + Trace.Assert(assertion, "Invariant: " + message); + } + } + + /// + /// Invariant check. + /// + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT")] + public static void Invariant(bool assertion) + { + if (UseExceptions) + { + if (!assertion) + throw new InvariantException("Invariant failed."); + } + else + { + Trace.Assert(assertion, "Invariant failed."); + } + } + + /// + /// Assertion check. + /// + [Conditional("DBC_CHECK_ALL")] + public static void Assert(bool assertion, string message) + { + if (UseExceptions) + { + if (!assertion) + throw new AssertionException(message); + } + else + { + Trace.Assert(assertion, "Assertion: " + message); + } + } + + /// + /// Assertion check. + /// + [Conditional("DBC_CHECK_ALL")] + public static void Assert(bool assertion, string message, Exception inner) + { + if (UseExceptions) + { + if (!assertion) + throw new AssertionException(message, inner); + } + else + { + Trace.Assert(assertion, "Assertion: " + message); + } + } + + /// + /// Assertion check. + /// + [Conditional("DBC_CHECK_ALL")] + public static void Assert(bool assertion) + { + if (UseExceptions) + { + if (!assertion) + throw new AssertionException("Assertion failed."); + } + else + { + Trace.Assert(assertion, "Assertion failed."); + } + } + + /// + /// Set this if you wish to use Trace Assert statements + /// instead of exception handling. + /// (The Check class uses exception handling by default.) + /// + public static bool UseAssertions + { + get + { + return useAssertions; + } + set + { + useAssertions = value; + } + } + + #endregion // Interface + + #region Implementation + + // No creation + private Check() {} + + /// + /// Is exception handling being used? + /// + private static bool UseExceptions + { + get + { + return !useAssertions; + } + } + + // Are trace assertion statements being used? + // Default is to use exception handling. + private static bool useAssertions = false; + + #endregion // Implementation + + #region Obsolete + + /// + /// Precondition check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Require")] + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION"), + Conditional("DBC_CHECK_PRECONDITION")] + public static void RequireTrace(bool assertion, string message) + { + Trace.Assert(assertion, "Precondition: " + message); + } + + + /// + /// Precondition check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Require")] + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION"), + Conditional("DBC_CHECK_PRECONDITION")] + public static void RequireTrace(bool assertion) + { + Trace.Assert(assertion, "Precondition failed."); + } + + /// + /// Postcondition check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Ensure")] + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION")] + public static void EnsureTrace(bool assertion, string message) + { + Trace.Assert(assertion, "Postcondition: " + message); + } + + /// + /// Postcondition check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Ensure")] + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT"), + Conditional("DBC_CHECK_POSTCONDITION")] + public static void EnsureTrace(bool assertion) + { + Trace.Assert(assertion, "Postcondition failed."); + } + + /// + /// Invariant check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Invariant")] + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT")] + public static void InvariantTrace(bool assertion, string message) + { + Trace.Assert(assertion, "Invariant: " + message); + } + + /// + /// Invariant check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Invariant")] + [Conditional("DBC_CHECK_ALL"), + Conditional("DBC_CHECK_INVARIANT")] + public static void InvariantTrace(bool assertion) + { + Trace.Assert(assertion, "Invariant failed."); + } + + /// + /// Assertion check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Assert")] + [Conditional("DBC_CHECK_ALL")] + public static void AssertTrace(bool assertion, string message) + { + Trace.Assert(assertion, "Assertion: " + message); + } + + /// + /// Assertion check. + /// + [Obsolete("Set Check.UseAssertions = true and then call Check.Assert")] + [Conditional("DBC_CHECK_ALL")] + public static void AssertTrace(bool assertion) + { + Trace.Assert(assertion, "Assertion failed."); + } + #endregion // Obsolete + + } // End Check + + #region Exceptions + + /// + /// Exception raised when a contract is broken. + /// Catch this exception type if you wish to differentiate between + /// any DesignByContract exception and other runtime exceptions. + /// + /// + public class DesignByContractException : ApplicationException + { + protected DesignByContractException() {} + protected DesignByContractException(string message) : base(message) {} + protected DesignByContractException(string message, Exception inner) : base(message, inner) {} + } + + /// + /// Exception raised when a precondition fails. + /// + public class PreconditionException : DesignByContractException + { + /// + /// Precondition Exception. + /// + public PreconditionException() {} + /// + /// Precondition Exception. + /// + public PreconditionException(string message) : base(message) {} + /// + /// Precondition Exception. + /// + public PreconditionException(string message, Exception inner) : base(message, inner) {} + } + + /// + /// Exception raised when a postcondition fails. + /// + public class PostconditionException : DesignByContractException + { + /// + /// Postcondition Exception. + /// + public PostconditionException() {} + /// + /// Postcondition Exception. + /// + public PostconditionException(string message) : base(message) {} + /// + /// Postcondition Exception. + /// + public PostconditionException(string message, Exception inner) : base(message, inner) {} + } + + /// + /// Exception raised when an invariant fails. + /// + public class InvariantException : DesignByContractException + { + /// + /// Invariant Exception. + /// + public InvariantException() {} + /// + /// Invariant Exception. + /// + public InvariantException(string message) : base(message) {} + /// + /// Invariant Exception. + /// + public InvariantException(string message, Exception inner) : base(message, inner) {} + } + + /// + /// Exception raised when an assertion fails. + /// + public class AssertionException : DesignByContractException + { + /// + /// Assertion Exception. + /// + public AssertionException() {} + /// + /// Assertion Exception. + /// + public AssertionException(string message) : base(message) {} + /// + /// Assertion Exception. + /// + public AssertionException(string message, Exception inner) : base(message, inner) {} + } + + #endregion // Exception classes + +} // End Design By Contract diff --git a/Utilities/DesignByContract.cs.meta b/Utilities/DesignByContract.cs.meta new file mode 100644 index 0000000..729468b --- /dev/null +++ b/Utilities/DesignByContract.cs.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 5a6942e14a8d33d46a05b33d50392652 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Utilities/Dispatcher.cs b/Utilities/Dispatcher.cs new file mode 100644 index 0000000..137ebdc --- /dev/null +++ b/Utilities/Dispatcher.cs @@ -0,0 +1,20 @@ +public class Dispatcher +{ + public event System.Action observers; + + private Dispatcher() { } + + public Dispatcher(S sender) + { + _sender = sender; + } + + virtual public void Dispatch(T value) + { + if (observers != null) + observers(_sender, value); + } + + S _sender; +} + diff --git a/Utilities/Dispatcher.cs.meta b/Utilities/Dispatcher.cs.meta new file mode 100644 index 0000000..8e801c6 --- /dev/null +++ b/Utilities/Dispatcher.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d8886d5d5f5929c479998a1316264c23 +timeCreated: 1436121137 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Utilities/DispatcherOnChange.cs b/Utilities/DispatcherOnChange.cs new file mode 100644 index 0000000..19599f8 --- /dev/null +++ b/Utilities/DispatcherOnChange.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +public class DispatcherOnChange: Dispatcher +{ + public DispatcherOnChange(S sender) : base(sender) { } + + public T value + { + set + { + if (EqualityComparer.Default.Equals(value, _value) == false) + { + _value = value; + + Dispatch(value); + } + } + } + + T _value; +} + diff --git a/Utilities/DispatcherOnChange.cs.meta b/Utilities/DispatcherOnChange.cs.meta new file mode 100644 index 0000000..54c805e --- /dev/null +++ b/Utilities/DispatcherOnChange.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 103dfa72bd2486d46ac7e6927c805778 +timeCreated: 1435956509 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Utilities/WeakReference.cs b/Utilities/WeakReference.cs new file mode 100644 index 0000000..5dae223 --- /dev/null +++ b/Utilities/WeakReference.cs @@ -0,0 +1,50 @@ +using System; +using System.Runtime.Serialization; +/// +/// Represents a weak reference, which references an object while still allowing +/// that object to be reclaimed by garbage collection. +/// +/// The type of the object that is referenced. +[Serializable] +public class WeakReference + : WeakReference where T : class +{ + /// + /// Initializes a new instance of the WeakReference{T} class, referencing + /// the specified object. + /// + /// The object to reference. + public WeakReference(T target) + : base(target) + { } + /// + /// Initializes a new instance of the WeakReference{T} class, referencing + /// the specified object and using the specified resurrection tracking. + /// + /// An object to track. + /// Indicates when to stop tracking the object. + /// If true, the object is tracked + /// after finalization; if false, the object is only tracked + /// until finalization. + public WeakReference(T target, bool trackResurrection) + : base(target, trackResurrection) + { } + protected WeakReference(SerializationInfo info, StreamingContext context) + : base(info, context) + { } + /// + /// Gets or sets the object (the target) referenced by the + /// current WeakReference{T} object. + /// + public new T Target + { + get + { + return (T)base.Target; + } + set + { + base.Target = value; + } + } +} diff --git a/Utilities/WeakReference.cs.meta b/Utilities/WeakReference.cs.meta new file mode 100644 index 0000000..951b563 --- /dev/null +++ b/Utilities/WeakReference.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2bf8d1cb161e6aa428300dba9323892e +timeCreated: 1434750269 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: