Browse Source

First commit

tags/Rel1
sebas77 9 years ago
parent
commit
91031c094a
43 changed files with 778 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +9
    -0
      Context.meta
  3. +61
    -0
      Context/ContextNotifier.cs
  4. +12
    -0
      Context/ContextNotifier.cs.meta
  5. +9
    -0
      Context/Factories.meta
  6. +84
    -0
      Context/Factories/GameObjectFactory.cs
  7. +12
    -0
      Context/Factories/GameObjectFactory.cs.meta
  8. +34
    -0
      Context/Factories/MonoBehaviourFactory.cs
  9. +12
    -0
      Context/Factories/MonoBehaviourFactory.cs.meta
  10. +12
    -0
      Context/ICompositionRoot.cs
  11. +7
    -0
      Context/ICompositionRoot.cs.meta
  12. +11
    -0
      Context/IContextNotifer.cs
  13. +8
    -0
      Context/IContextNotifer.cs.meta
  14. +13
    -0
      Context/IUnityContextHierarchyChangedListener.cs
  15. +8
    -0
      Context/IUnityContextHierarchyChangedListener.cs.meta
  16. +10
    -0
      Context/IWaitForFrameworkDestruction.cs
  17. +8
    -0
      Context/IWaitForFrameworkDestruction.cs.meta
  18. +10
    -0
      Context/IWaitForFrameworkInitialization.cs
  19. +8
    -0
      Context/IWaitForFrameworkInitialization.cs.meta
  20. +9
    -0
      Context/Legacy.meta
  21. +9
    -0
      Context/Unity.meta
  22. +28
    -0
      Context/Unity/NotifyComponentsRemoved.cs
  23. +8
    -0
      Context/Unity/NotifyComponentsRemoved.cs.meta
  24. +64
    -0
      Context/UnityContext.cs
  25. +7
    -0
      Context/UnityContext.cs.meta
  26. +9
    -0
      EntitySystem.meta
  27. +2
    -0
      EntitySystem/Engine.meta
  28. +14
    -0
      EntitySystem/Engine/IEngine.cs
  29. +7
    -0
      EntitySystem/Engine/IEngine.cs.meta
  30. +69
    -0
      EntitySystem/EnginesRoot.cs
  31. +7
    -0
      EntitySystem/EnginesRoot.cs.meta
  32. +13
    -0
      EntitySystem/IEnginesRoot.cs
  33. +8
    -0
      EntitySystem/IEnginesRoot.cs.meta
  34. +9
    -0
      EntitySystem/Node.meta
  35. +16
    -0
      EntitySystem/Node/INode.cs
  36. +12
    -0
      EntitySystem/Node/INode.cs.meta
  37. +8
    -0
      EntitySystem/Node/INodeHolder.cs
  38. +12
    -0
      EntitySystem/Node/INodeHolder.cs.meta
  39. +9
    -0
      EntitySystem/Unity.meta
  40. +64
    -0
      EntitySystem/Unity/UnityNodeHolder.cs
  41. +12
    -0
      EntitySystem/Unity/UnityNodeHolder.cs.meta
  42. +40
    -0
      EntitySystem/UnityEnginesRoot.cs
  43. +12
    -0
      EntitySystem/UnityEnginesRoot.cs.meta

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
/EntitySystem/note.txt
/EntitySystem/note.txt.meta

+ 9
- 0
Context.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9e37272d8aa8b6e4cb7b1fc15f1e57a8
folderAsset: yes
timeCreated: 1431201025
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 61
- 0
Context/ContextNotifier.cs View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;

namespace Svelto.Context
{
class ContextNotifier: IContextNotifer
{
public ContextNotifier()
{
_toInitialize = new List<WeakReference<IWaitForFrameworkInitialization>>();
_toDeinitialize = new List<WeakReference<IWaitForFrameworkDestruction>> ();
}

/// <summary>
/// A Context is meant to be initialized only once in its timelife
/// </summary>
public void NotifyFrameworkInitialized()
{
foreach (WeakReference<IWaitForFrameworkInitialization> obj in _toInitialize)
{
if (obj.IsAlive == true)
obj.Target.OnFrameworkInitialized();
}

_toInitialize = null;
}

/// <summary>
/// A Context is meant to be deinitialized only once in its timelife
/// </summary>
public void NotifyFrameworkDeinitialized()
{
foreach (WeakReference<IWaitForFrameworkDestruction> obj in _toDeinitialize)
{
if (obj.IsAlive == true)
obj.Target.OnFrameworkDestroyed();
}

_toDeinitialize = null;
}

public void AddFrameworkInitializationListener(IWaitForFrameworkInitialization obj)
{
if (_toInitialize != null)
_toInitialize.Add(new WeakReference<IWaitForFrameworkInitialization>(obj));
else
throw new Exception("An object is expected to be initialized after the framework has been initialized. Type: " + obj.GetType());
}

public void AddFrameworkDestructionListener(IWaitForFrameworkDestruction obj)
{
if (_toDeinitialize != null)
_toDeinitialize.Add(new WeakReference<IWaitForFrameworkDestruction>(obj));
else
throw new Exception("An object is expected to be initialized after the framework has been deinitialized. Type: " + obj.GetType());
}

List<WeakReference<IWaitForFrameworkInitialization>> _toInitialize;
List<WeakReference<IWaitForFrameworkDestruction>> _toDeinitialize;
}
}

+ 12
- 0
Context/ContextNotifier.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d74bed1689bb4114aa8a1f95cd95c788
timeCreated: 1431300049
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 9
- 0
Context/Factories.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 88190f2317429cb49bfdf63e448efa52
folderAsset: yes
timeCreated: 1431630831
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 84
- 0
Context/Factories/GameObjectFactory.cs View File

@@ -0,0 +1,84 @@
#region

using System.Collections.Generic;
using UnityEngine;

#endregion

namespace Svelto.Context
{
public class GameObjectFactory: Factories.IGameObjectFactory
{
public GameObjectFactory(IUnityContextHierarchyChangedListener root)
{
_unityContext = root;

_prefabs = new Dictionary<string, GameObject[]>();
}
/// <summary>
/// Register a prefab to be built later using a string ID.
/// </summary>
/// <param name="prefab">original prefab</param>
/// <param name="prefabName">prefab name</param>
/// <param name="parent">optional gameobject to specify as parent later</param>

public void RegisterPrefab(GameObject prefab, string prefabName, GameObject parent = null)
{
var objects = new GameObject[2];
objects[0] = prefab; objects[1] = parent;
_prefabs.Add(prefabName, objects);
}
public GameObject Build(string prefabName)
{
DesignByContract.Check.Require(_prefabs.ContainsKey(prefabName), "Svelto.Factories.IGameObjectFactory - Invalid Prefab Type");
var go = Build(_prefabs[prefabName][0]);
GameObject parent = _prefabs[prefabName][1];

if (parent != null)
{
Transform transform = go.transform;

var scale = transform.localScale;
var rotation = transform.localRotation;
var position = transform.localPosition;

parent.SetActive(true);

transform.parent = parent.transform;

transform.localPosition = position;
transform.localRotation = rotation;
transform.localScale = scale;
}
return go;
}

public GameObject Build(GameObject go)
{
var copy = Object.Instantiate(go) as GameObject;
var components = copy.GetComponentsInChildren<MonoBehaviour>(true);

for (var i = 0; i < components.Length; ++i)
if (components[i] != null)
_unityContext.OnMonobehaviourAdded(components[i]);

_unityContext.OnGameObjectAdded(copy);

copy.AddComponent<NotifyComponentsRemoved>().unityContext = _unityContext;
copy.AddComponent<NotifyEntityRemoved>().unityContext = _unityContext;

return copy;
}

IUnityContextHierarchyChangedListener _unityContext;
Dictionary<string, GameObject[]> _prefabs;
}
}


+ 12
- 0
Context/Factories/GameObjectFactory.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 613a705e128b35e4f9361e29f4661191
timeCreated: 1431630831
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 34
- 0
Context/Factories/MonoBehaviourFactory.cs View File

@@ -0,0 +1,34 @@
#region

using System;
using UnityEngine;

#endregion

namespace Svelto.Context
{
public class MonoBehaviourFactory: Factories.IMonoBehaviourFactory
{
IUnityContextHierarchyChangedListener _unityContext;

public MonoBehaviourFactory(IUnityContextHierarchyChangedListener unityContext)
{
_unityContext = unityContext;
}
public M Build<M>(Func<M> constructor) where M:MonoBehaviour
{
var mb = constructor();
_unityContext.OnMonobehaviourAdded(mb);

GameObject go = mb.gameObject;

if (go.GetComponent<NotifyComponentsRemoved>() == null)
go.AddComponent<NotifyComponentsRemoved>().unityContext = _unityContext;

return mb;
}
}
}


+ 12
- 0
Context/Factories/MonoBehaviourFactory.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 369e3378b91069c4aadba2af5aa8882b
timeCreated: 1431630831
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 12
- 0
Context/ICompositionRoot.cs View File

@@ -0,0 +1,12 @@
using UnityEngine;

namespace Svelto.Context
{
public interface ICompositionRoot
{
void OnContextInitialized();
void OnContextDestroyed();
}
}



+ 7
- 0
Context/ICompositionRoot.cs.meta View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 48c80cc65bea8254ba8082043f53405e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

+ 11
- 0
Context/IContextNotifer.cs View File

@@ -0,0 +1,11 @@
namespace Svelto.Context
{
public interface IContextNotifer
{
void NotifyFrameworkInitialized();
void NotifyFrameworkDeinitialized();

void AddFrameworkInitializationListener(IWaitForFrameworkInitialization obj);
void AddFrameworkDestructionListener(IWaitForFrameworkDestruction obj);
}
}

+ 8
- 0
Context/IContextNotifer.cs.meta View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a28c8df5741efe54ea588a1bcea92f0f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 13
- 0
Context/IUnityContextHierarchyChangedListener.cs View File

@@ -0,0 +1,13 @@
using UnityEngine;

namespace Svelto.Context
{
public interface IUnityContextHierarchyChangedListener
{
void OnMonobehaviourAdded(MonoBehaviour component);
void OnMonobehaviourRemoved(MonoBehaviour component);

void OnGameObjectAdded(GameObject entity);
void OnGameObjectRemoved(GameObject entity);
}
}

+ 8
- 0
Context/IUnityContextHierarchyChangedListener.cs.meta View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 905bfd795bede6d448694b23dd88e0be
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 10
- 0
Context/IWaitForFrameworkDestruction.cs View File

@@ -0,0 +1,10 @@
using System;

namespace Svelto.Context
{
public interface IWaitForFrameworkDestruction
{
void OnFrameworkDestroyed();
}
}


+ 8
- 0
Context/IWaitForFrameworkDestruction.cs.meta View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 36b1da25aaa515e4bad98fa0f61bc662
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 10
- 0
Context/IWaitForFrameworkInitialization.cs View File

@@ -0,0 +1,10 @@
using System;

namespace Svelto.Context
{
public interface IWaitForFrameworkInitialization
{
void OnFrameworkInitialized();
}
}


+ 8
- 0
Context/IWaitForFrameworkInitialization.cs.meta View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93cf465dd97f6144390620250c362485
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 9
- 0
Context/Legacy.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 026077faae4dc884ebe1eb4b427ed1e4
folderAsset: yes
timeCreated: 1434754873
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 9
- 0
Context/Unity.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 403de662aab64bb4e917559caa6b7946
folderAsset: yes
timeCreated: 1434752394
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 28
- 0
Context/Unity/NotifyComponentsRemoved.cs View File

@@ -0,0 +1,28 @@
using UnityEngine;

namespace Svelto.Context
{
public class NotifyComponentsRemoved : MonoBehaviour
{
public IUnityContextHierarchyChangedListener unityContext { private get; set; }

void OnDestroy()
{
MonoBehaviour[] components = gameObject.GetComponentsInChildren<MonoBehaviour>(true);

for (int i = 0; i < components.Length; ++i)
if (components[i] != null)
unityContext.OnMonobehaviourRemoved(components[i]);
}
}

public class NotifyEntityRemoved : MonoBehaviour
{
public IUnityContextHierarchyChangedListener unityContext { private get; set; }

void OnDestroy()
{
unityContext.OnGameObjectRemoved(gameObject);
}
}
}

+ 8
- 0
Context/Unity/NotifyComponentsRemoved.cs.meta View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 13278f0cd187d8d43acc6a02479e459b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 64
- 0
Context/UnityContext.cs View File

@@ -0,0 +1,64 @@
using UnityEngine;
using Svelto.Context;
using System.Collections;

public class UnityContext:MonoBehaviour
{}

public class UnityContext<T>: UnityContext where T:class, ICompositionRoot, IUnityContextHierarchyChangedListener, new()
{
virtual protected void Awake()
{
Init();
}

void Init()
{
_applicationRoot = new T();
MonoBehaviour[] behaviours = transform.GetComponentsInChildren<MonoBehaviour>(true);

for (int i = 0; i < behaviours.Length; i++)
{
var component = behaviours[i];

if (component != null)
_applicationRoot.OnMonobehaviourAdded(component);
}

Transform[] children = transform.GetComponentsInChildren<Transform>(true);

for (int i = 0; i < children.Length; i++)
{
var child = children[i];

if (child != null)
_applicationRoot.OnGameObjectAdded(child.gameObject);
}
}
void OnDestroy()
{
FrameworkDestroyed();
}

void Start()
{
if (Application.isPlaying == true)
StartCoroutine(WaitForFrameworkInitialization());
}

IEnumerator WaitForFrameworkInitialization()
{
yield return new WaitForEndOfFrame(); //let's wait until next frame, so we are sure that all the awake and starts are called
_applicationRoot.OnContextInitialized();
}
void FrameworkDestroyed()
{
_applicationRoot.OnContextDestroyed();
}
private T _applicationRoot = null;
}

+ 7
- 0
Context/UnityContext.cs.meta View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 54e46daa2d2d723499a114d6d8de9dc2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

+ 9
- 0
EntitySystem.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8c3236edfa0d4cb43afb277ef6aea664
folderAsset: yes
timeCreated: 1431201025
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 0
EntitySystem/Engine.meta View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 89495a852d57f3d4893d89a74065ee39

+ 14
- 0
EntitySystem/Engine/IEngine.cs View File

@@ -0,0 +1,14 @@
namespace Svelto.ES
{
public interface IEngine
{}
public interface INodeEngine : IEngine
{
System.Type[] AcceptedNodes();

void Add(INode obj);
void Remove(INode obj);
}

}

+ 7
- 0
EntitySystem/Engine/IEngine.cs.meta View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0b5d886dff6d02148ab73bdb3f0ca4f7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

+ 69
- 0
EntitySystem/EnginesRoot.cs View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;


namespace Svelto.ES
{
public sealed class EnginesRoot: INodeEnginesRoot
{
public EnginesRoot()
{
_nodeEngines = new Dictionary<Type, List<INodeEngine>>();
}

public void AddEngine(IEngine engine)
{
if (engine is INodeEngine)
AddNodeEngine(engine as INodeEngine);
}

public void Add(INode node)
{
Type nodeType = node.GetType();
List<INodeEngine> value;
if (_nodeEngines.TryGetValue(nodeType, out value))
for (int j = 0; j < value.Count; j++)
value[j].Add(node);
}

public void Remove(INode node)
{
Type nodeType = node.GetType();

List<INodeEngine> value;
if (_nodeEngines.TryGetValue(nodeType, out value))
for (int j = 0; j < value.Count; j++)
value[j].Remove(node);
}

void AddNodeEngine(INodeEngine engine)
{
AddEngine(engine, engine.AcceptedNodes(), _nodeEngines);
}

void AddEngine<T>(T engine, Type[] types, Dictionary<Type, List<T>> engines)
{
for (int i = 0; i < types.Length; i++)
{
List<T> value;

var type = types[i];

if (engines.TryGetValue(type, out value) == false)
{
List<T> list = new List<T>();

list.Add(engine);

engines.Add(type, list);
}
else
value.Add(engine);
}
}

Dictionary<Type, List<INodeEngine>> _nodeEngines;
}
}


+ 7
- 0
EntitySystem/EnginesRoot.cs.meta View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 93350fd2ba4f60f4f88599169e8d31cb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

+ 13
- 0
EntitySystem/IEnginesRoot.cs View File

@@ -0,0 +1,13 @@
namespace Svelto.ES
{
public interface IEnginesRoot
{
void AddEngine(IEngine engine);
}

public interface INodeEnginesRoot: IEnginesRoot
{
void Add(INode node);
void Remove(INode node);
}
}

+ 8
- 0
EntitySystem/IEnginesRoot.cs.meta View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2253f20f6b4d9b14eb0e79fbd135eff1
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 9
- 0
EntitySystem/Node.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8e3c19ee9185a664aa837e567c4db122
folderAsset: yes
timeCreated: 1434900315
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 16
- 0
EntitySystem/Node/INode.cs View File

@@ -0,0 +1,16 @@
namespace Svelto.ES
{
public interface INode
{
}

public interface INodeWithReferenceID<out T> : INode where T : class
{
T ID { get; }
}

public interface INodeWithValueID<out T> : INode where T : struct
{
T ID { get; }
}
}

+ 12
- 0
EntitySystem/Node/INode.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fc6bea8c56bd7284693db26502c6b65b
timeCreated: 1434900316
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 8
- 0
EntitySystem/Node/INodeHolder.cs View File

@@ -0,0 +1,8 @@
namespace Svelto.ES
{
interface INodeHolder
{
INode node { get; }
INodeEnginesRoot engineRoot { set; }
}
}

+ 12
- 0
EntitySystem/Node/INodeHolder.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a4c0061442f32644cb1e434b6544d56c
timeCreated: 1434900315
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 9
- 0
EntitySystem/Unity.meta View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e369cc976007e884d92f906e4d1054d7
folderAsset: yes
timeCreated: 1438460466
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 64
- 0
EntitySystem/Unity/UnityNodeHolder.cs View File

@@ -0,0 +1,64 @@
using System;
using System.Reflection;
using UnityEngine;

namespace Svelto.ES
{
public abstract class BaseNodeHolder<NodeType>:MonoBehaviour, INodeHolder where NodeType : INode
{
public INode node { get { if (_node != null) return _node; else return _node = ReturnNode(); } }

public INodeEnginesRoot engineRoot { set { _engineRoot = value; } }

protected abstract NodeType ReturnNode();

void Start()
{
if (_engineRoot != null)
_engineRoot.Add(node);
}

NodeType _node;
INodeEnginesRoot _engineRoot;
}

public abstract class UnityNodeHolder<NodeType>:BaseNodeHolder<NodeType> where NodeType : INode
{
protected abstract NodeType GenerateNode();

override protected NodeType ReturnNode()
{
NodeType node = GenerateNode();

FieldInfo[] fields = typeof(NodeType).GetFields(BindingFlags.Public | BindingFlags.Instance);

for (int i = fields.Length - 1; i >=0 ; --i)
{
var field = fields[i];

var component = transform.GetComponentsInChildren(field.FieldType, true); //can't use inactive components

if (component.Length == 0)
{
Exception e = new Exception("Svelto.ES: An Entity must hold all the components needed for a Node. Type: " + field.FieldType.Name + "Entity name: " + name);

Debug.LogException(e, gameObject);

throw e;
}
if (component.Length > 1)
{
Exception e = new Exception("Svelto.ES: An Entity can hold only one component of the same type. Type: " + field.FieldType.Name + "Entity name: " + name);

Debug.LogException(e, gameObject);

throw e;
}

field.SetValue(node, component[0]);
}

return node;
}
}
}

+ 12
- 0
EntitySystem/Unity/UnityNodeHolder.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 50ed7d1adb836dd4786fef832cb4e808
timeCreated: 1438011258
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 40
- 0
EntitySystem/UnityEnginesRoot.cs View File

@@ -0,0 +1,40 @@
using UnityEngine;

namespace Svelto.ES
{
public class UnityEnginesRoot : INodeEnginesRoot
{
public void AddEngine(IEngine engine)
{
_engineRoot.AddEngine(engine);
}

public void Add(INode node)
{
_engineRoot.Add(node);
}

public void Remove(INode node)
{
_engineRoot.Remove(node);
}

public void AddGameObjectEntity(GameObject entity)
{
INodeHolder[] nodeHolders = entity.GetComponents<INodeHolder>();

for (int i = 0; i < nodeHolders.Length; i++)
nodeHolders[i].engineRoot = this;
}

public void RemoveGameObjectEntity(GameObject entity)
{
INodeHolder[] nodeHolders = entity.GetComponents<INodeHolder>();

for (int i = 0; i < nodeHolders.Length; i++)
Remove(nodeHolders[i].node);
}

EnginesRoot _engineRoot = new EnginesRoot();
}
}

+ 12
- 0
EntitySystem/UnityEnginesRoot.cs.meta View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6e4e1cde52e768148a0aaf8effbb9ba3
timeCreated: 1439726868
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save