├── .gitignore ├── Assets ├── Main.unity ├── Plugins │ └── NSubstitute │ │ └── NSubstitute.dll └── Unity-Ash │ ├── Source │ ├── Core │ │ ├── ComponentMatchingFamily.cs │ │ ├── ComponentMatchingFamilyFactory.cs │ │ ├── Engine.cs │ │ ├── Entity.cs │ │ ├── Events.cs │ │ ├── Exceptions.cs │ │ ├── FamiliesContainer.cs │ │ ├── IEngine.cs │ │ ├── IEntity.cs │ │ ├── IFamily.cs │ │ ├── IFamilyFactory.cs │ │ ├── INodePool.cs │ │ ├── INodelist.cs │ │ ├── ISystem.cs │ │ ├── NodeList.cs │ │ ├── NodePool.cs │ │ ├── Nodes.cs │ │ └── SystemPriorityPair.cs │ └── Helpers │ │ ├── AshExtensions.cs │ │ ├── Maybe.cs │ │ └── NodelssSystems.cs │ └── Tests │ ├── Helpers │ ├── FakeEntity.cs │ ├── MockComponents.cs │ ├── MockEntities.cs │ └── MockSystem.cs │ ├── Integration │ ├── TestAddedEntityRemoved.cs │ ├── TestAddingAndRemovingEntitiesDispatchesEvents.cs │ ├── TestCanRemoveComponentDuringNodeAdded.cs │ ├── TestDestroyingAnEntityMidUpdateUpdatesOthers.cs │ ├── TestEntity.cs │ ├── TestMatchingEntityAdded.cs │ ├── TestNewFamilyCanBeCreatedDuringNodeAdd.cs │ ├── TestNewFamilyCanBeCreatedDuringNodeRemove.cs │ ├── TestNonMatchingEntityNotAdded.cs │ └── TestRemovingMatchingComponent.cs │ └── Unit │ └── Editor │ ├── ComponentMatchingFamilyTests.cs │ ├── EngineTests.cs │ ├── FamiliesContainerTests.cs │ └── NodeListTests.cs ├── LICENSE ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAnalyticsManager.asset └── UnityConnectSettings.asset ├── README.md └── UnityPackageManager └── manifest.json /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | /.vs 10 | 11 | # Build results 12 | [Dd]ebug/ 13 | [Dd]ebugPublic/ 14 | [Rr]elease/ 15 | [Rr]eleases/ 16 | x64/ 17 | x86/ 18 | build/ 19 | bld/ 20 | [Bb]in/ 21 | [Oo]bj/ 22 | 23 | # Roslyn cache directories 24 | *.ide/ 25 | 26 | # MSTest test Results 27 | [Tt]est[Rr]esult*/ 28 | [Bb]uild[Ll]og.* 29 | 30 | #NUNIT 31 | *.VisualState.xml 32 | TestResult.xml 33 | 34 | # Build Results of an ATL Project 35 | [Dd]ebugPS/ 36 | [Rr]eleasePS/ 37 | dlldata.c 38 | 39 | *_i.c 40 | *_p.c 41 | *_i.h 42 | *.ilk 43 | *.meta 44 | *.obj 45 | *.pch 46 | *.pdb 47 | *.pgc 48 | *.pgd 49 | *.rsp 50 | *.sbr 51 | *.tlb 52 | *.tli 53 | *.tlh 54 | *.tmp 55 | *.tmp_proj 56 | *.log 57 | *.vspscc 58 | *.vssscc 59 | .builds 60 | *.pidb 61 | *.svclog 62 | *.scc 63 | 64 | # Chutzpah Test files 65 | _Chutzpah* 66 | 67 | # Visual C++ cache files 68 | ipch/ 69 | *.aps 70 | *.ncb 71 | *.opensdf 72 | *.sdf 73 | *.cachefile 74 | 75 | # Visual Studio profiler 76 | *.psess 77 | *.vsp 78 | *.vspx 79 | 80 | # TFS 2012 Local Workspace 81 | $tf/ 82 | 83 | # Guidance Automation Toolkit 84 | *.gpState 85 | 86 | # ReSharper is a .NET coding add-in 87 | _ReSharper*/ 88 | *.[Rr]e[Ss]harper 89 | *.DotSettings.user 90 | 91 | # JustCode is a .NET coding addin-in 92 | .JustCode 93 | 94 | # TeamCity is a build add-in 95 | _TeamCity* 96 | 97 | # DotCover is a Code Coverage Tool 98 | *.dotCover 99 | 100 | # NCrunch 101 | _NCrunch_* 102 | .*crunch*.local.xml 103 | 104 | # MightyMoose 105 | *.mm.* 106 | AutoTest.Net/ 107 | 108 | # Web workbench (sass) 109 | .sass-cache/ 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.[Pp]ublish.xml 129 | *.azurePubxml 130 | # TODO: Comment the next line if you want to checkin your web deploy settings 131 | # but database connection strings (with potential passwords) will be unencrypted 132 | *.pubxml 133 | *.publishproj 134 | 135 | # NuGet Packages 136 | *.nupkg 137 | # The packages folder can be ignored because of Package Restore 138 | **/packages/* 139 | # except build/, which is used as an MSBuild target. 140 | !**/packages/build/ 141 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 142 | #!**/packages/repositories.config 143 | 144 | # Windows Azure Build Output 145 | csx/ 146 | *.build.csdef 147 | 148 | # Windows Store app package directory 149 | AppPackages/ 150 | 151 | # Others 152 | sql/ 153 | *.Cache 154 | ClientBin/ 155 | [Ss]tyle[Cc]op.* 156 | ~$* 157 | *~ 158 | *.dbmdl 159 | *.dbproj.schemaview 160 | *.pfx 161 | *.publishsettings 162 | node_modules/ 163 | 164 | # RIA/Silverlight projects 165 | Generated_Code/ 166 | 167 | # Backup & report files from converting an old project file 168 | # to a newer Visual Studio version. Backup files are not needed, 169 | # because we have git ;-) 170 | _UpgradeReport_Files/ 171 | Backup*/ 172 | UpgradeLog*.XML 173 | UpgradeLog*.htm 174 | 175 | # SQL Server files 176 | *.mdf 177 | *.ldf 178 | 179 | # Business Intelligence projects 180 | *.rdl.data 181 | *.bim.layout 182 | *.bim_*.settings 183 | 184 | # Microsoft Fakes 185 | FakesAssemblies/ 186 | 187 | # Unity Files 188 | /[Ll]ibrary/ 189 | /[Tt]emp/ 190 | /[Oo]bj/ 191 | /[Bb]uild/ 192 | 193 | # Autogenerated VS/MD solution and project files 194 | *.csproj 195 | *.unityproj 196 | *.sln 197 | *.suo 198 | *.tmp 199 | *.user 200 | *.userprefs 201 | *.pidb 202 | *.booproj 203 | 204 | # Unity3D generated meta files 205 | *.pidb.meta 206 | 207 | # Unity3D Generated File On Crash Reports 208 | sysinfo.txt -------------------------------------------------------------------------------- /Assets/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/Assets/Main.unity -------------------------------------------------------------------------------- /Assets/Plugins/NSubstitute/NSubstitute.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/Assets/Plugins/NSubstitute/NSubstitute.dll -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/ComponentMatchingFamily.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace Ash.Core 8 | { 9 | public class ComponentMatchingFamily : IFamily 10 | { 11 | private Dictionary _entities; 12 | private NodeList _nodes; 13 | private Dictionary _components; 14 | private INodePool _pool; 15 | 16 | public ComponentMatchingFamily(INodePool pool = null) 17 | { 18 | _entities = new Dictionary(); 19 | _nodes = new NodeList(); 20 | _pool = pool ?? new NodePool(); 21 | Init(); 22 | } 23 | 24 | private void Init() 25 | { 26 | var type = typeof (T); 27 | _components = type.GetProperties() 28 | .ToDictionary(i => i.PropertyType, i => i); 29 | } 30 | 31 | public void ComponentAdded(IEntity entity, Type componentType) 32 | { 33 | if (_entities.ContainsKey(entity)) 34 | return; 35 | 36 | AddIfMatch(entity); 37 | } 38 | 39 | public void ComponentRemoved(IEntity entity, Type componentType) 40 | { 41 | if (!_entities.ContainsKey(entity)) 42 | return; 43 | 44 | if (!_components.ContainsKey(componentType)) 45 | return; 46 | 47 | RemoveEntity(entity); 48 | } 49 | 50 | public void EntityAdded(IEntity entity) 51 | { 52 | if (_entities.ContainsKey(entity)) 53 | throw new ComponentMatchingFamilyException("Entity already added to family."); 54 | 55 | AddIfMatch(entity); 56 | } 57 | 58 | public void EntityRemoved(IEntity entity) 59 | { 60 | if (!_entities.ContainsKey(entity)) 61 | return; 62 | 63 | RemoveEntity(entity); 64 | } 65 | 66 | public void BeforeUpdate() 67 | { 68 | _nodes.Lock(); 69 | } 70 | 71 | public void AfterUpdate() 72 | { 73 | _nodes.Unlock(); 74 | } 75 | 76 | private void RemoveEntity(IEntity entity) 77 | { 78 | var node = _entities[entity]; 79 | _pool.Pool(node); 80 | _entities.Remove(entity); 81 | _nodes.Remove(node); 82 | } 83 | 84 | private void AddIfMatch(IEntity entity) 85 | { 86 | foreach (var pair in _components) 87 | if (!entity.Has(pair.Key)) 88 | return; 89 | 90 | var node = _pool.UnPool(); 91 | _entities[entity] = node; 92 | 93 | foreach (var pair in _components) 94 | pair.Value.SetValue(node, entity.Get(pair.Key), null); 95 | 96 | _nodes.Add(node); 97 | } 98 | 99 | public INodeList Nodes 100 | { 101 | get { return _nodes; } 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/ComponentMatchingFamilyFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public class ComponentMatchingFamilyFactory : IFamilyFactory 9 | { 10 | public IFamily Produce() 11 | { 12 | return new ComponentMatchingFamily(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/Engine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace Ash.Core 8 | { 9 | public class Engine : IEngine 10 | { 11 | private List _systems; 12 | private FamiliesContainer _families; 13 | private IFamilyFactory _familyFactory; 14 | private List _entities; 15 | 16 | public Engine(IFamilyFactory familyFactory = null) 17 | { 18 | Current = this; 19 | _familyFactory = familyFactory ?? new ComponentMatchingFamilyFactory(); 20 | _systems = new List(); 21 | _families = new FamiliesContainer(); 22 | _entities = new List(); 23 | } 24 | 25 | public void AddEntity(IEntity entity) 26 | { 27 | foreach (var pair in _families) 28 | pair.EntityAdded(entity); 29 | 30 | entity.ComponentAdded.AddListener(OnComponentAdded); 31 | entity.ComponentRemoved.AddListener(OnComponentRemoved); 32 | 33 | _entities.Add(entity); 34 | } 35 | 36 | private void OnComponentRemoved(IEntity entity, Type component) 37 | { 38 | _families.Lock(); 39 | foreach (var pair in _families) 40 | pair.ComponentRemoved(entity, component); 41 | _families.UnLock(); 42 | } 43 | 44 | private void OnComponentAdded(IEntity entity, Type component) 45 | { 46 | _families.Lock(); 47 | foreach (var pair in _families) 48 | pair.ComponentAdded(entity, component); 49 | _families.UnLock(); 50 | } 51 | 52 | public void RemoveEntity(IEntity entity) 53 | { 54 | foreach (var pair in _families) 55 | pair.EntityRemoved(entity); 56 | 57 | entity.ComponentAdded.RemoveListener(OnComponentAdded); 58 | entity.ComponentRemoved.RemoveListener(OnComponentRemoved); 59 | 60 | _entities.Remove(entity); 61 | } 62 | 63 | public void AddSystem(ISystem system, int priority) 64 | { 65 | _systems.Add(new SystemPriorityPair(system, priority)); 66 | _systems = _systems.OrderBy(s => s.Priority).ToList(); 67 | system.AddedToEngine(this); 68 | } 69 | 70 | public void RemoveSystem(ISystem system) 71 | { 72 | _systems.RemoveAll(s => s.System == system); 73 | system.RemovedFromEngine(this); 74 | } 75 | 76 | public INodeList GetNodes() where T : Node 77 | { 78 | var type = typeof (T); 79 | IFamily family; 80 | 81 | if (_families.Contains(type)) 82 | family = _families.Get(type) as IFamily; 83 | else 84 | { 85 | family = _familyFactory.Produce(); 86 | _families.Add(type, family); 87 | 88 | foreach (var entity in _entities) 89 | family.EntityAdded(entity); 90 | } 91 | 92 | return family.Nodes; 93 | } 94 | 95 | public void ReleaseNodes(INodeList nodes) 96 | { 97 | var type = typeof(T); 98 | if (!_families.Contains(type)) 99 | return; 100 | 101 | _families.Remove(type); 102 | } 103 | 104 | public void Update(float delta) 105 | { 106 | foreach (var family in _families) 107 | family.BeforeUpdate(); 108 | 109 | foreach (var prioritizedSystem in _systems) 110 | prioritizedSystem.System.Update(delta); 111 | 112 | _families.Lock(); 113 | 114 | foreach (var family in _families) 115 | family.AfterUpdate(); 116 | 117 | _families.UnLock(); 118 | } 119 | 120 | public static IEngine Current { get; set; } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/Entity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace Ash.Core 7 | { 8 | public class Entity : MonoBehaviour, IEntity 9 | { 10 | private readonly ComponentAdded _componentAdded = new ComponentAdded(); 11 | private readonly ComponentRemoved _componentRemoved = new ComponentRemoved(); 12 | private IEngine _engine; 13 | 14 | protected void Awake() 15 | { 16 | _engine = FindEngine(); 17 | if (_engine == null) 18 | throw new EntityException("Canont find Engine!"); 19 | 20 | _engine.AddEntity(this); 21 | } 22 | 23 | protected virtual IEngine FindEngine() 24 | { 25 | return Engine.Current; 26 | } 27 | 28 | public bool Has(Type type) 29 | { 30 | return GetComponent(type) != null; 31 | } 32 | 33 | public object Get(Type type) 34 | { 35 | return gameObject.GetComponent(type); 36 | } 37 | 38 | public void Destroy() 39 | { 40 | if (Application.isPlaying) 41 | Destroy(gameObject); 42 | } 43 | 44 | public T Add() where T : Component 45 | { 46 | var component = gameObject.AddComponent(); 47 | ComponentAdded.Invoke(this, typeof(T)); 48 | return component; 49 | } 50 | 51 | public void Remove(Component component) 52 | { 53 | DestroyComponent(component); 54 | ComponentRemoved.Invoke(this, component.GetType()); 55 | } 56 | 57 | protected virtual void DestroyComponent(Component component) 58 | { 59 | DestroyImmediate(component); 60 | } 61 | 62 | private void OnDestroy() 63 | { 64 | if (_engine != null) 65 | _engine.RemoveEntity(this); 66 | } 67 | 68 | public ComponentAdded ComponentAdded 69 | { 70 | get { return _componentAdded; } 71 | } 72 | 73 | public ComponentRemoved ComponentRemoved 74 | { 75 | get { return _componentRemoved; } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/Events.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ash.Core; 6 | using UnityEngine.Events; 7 | 8 | namespace Ash.Core 9 | { 10 | public class ComponentAdded : UnityEvent 11 | { 12 | } 13 | 14 | public class ComponentRemoved : UnityEvent 15 | { 16 | } 17 | 18 | public class NodeAdded : UnityEvent 19 | { 20 | } 21 | 22 | public class NodeRemoved : UnityEvent 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public class ComponentMatchingFamilyException : Exception 9 | { 10 | public ComponentMatchingFamilyException(string message) : base(message) 11 | { 12 | } 13 | } 14 | 15 | public class EntityException : Exception 16 | { 17 | public EntityException(string message) : base(message) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/FamiliesContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | enum PendingChange 11 | { 12 | Add, 13 | Remove 14 | } 15 | 16 | class PendingChangeFamilyPair 17 | { 18 | public IFamily Family { get; set; } 19 | public PendingChange Change { get; set; } 20 | } 21 | 22 | public class FamiliesContainer : IEnumerable 23 | { 24 | private Dictionary _families; 25 | private Dictionary _pending; 26 | private bool _isLocked; 27 | 28 | public FamiliesContainer() 29 | { 30 | _families = new Dictionary(); 31 | _pending = new Dictionary(); 32 | } 33 | 34 | public void Add(Type nodeType, IFamily family) 35 | { 36 | if (_isLocked) 37 | { 38 | _pending[nodeType] = new PendingChangeFamilyPair 39 | { 40 | Change = PendingChange.Add, 41 | Family = family 42 | }; 43 | } 44 | else 45 | { 46 | _families[nodeType] = family; 47 | } 48 | } 49 | 50 | public IFamily Get(Type nodeType) 51 | { 52 | if (_isLocked) 53 | { 54 | if (_pending.ContainsKey(nodeType) && _pending[nodeType].Change == PendingChange.Add) 55 | return _pending[nodeType].Family; 56 | } 57 | 58 | if (!_families.ContainsKey(nodeType)) 59 | throw new Exception("Cannot get Family, is not within container"); 60 | 61 | return _families[nodeType]; 62 | } 63 | 64 | public bool Contains(Type nodeType) 65 | { 66 | if (_pending.ContainsKey(nodeType)) 67 | return _pending[nodeType].Change == PendingChange.Add; 68 | 69 | return _families.ContainsKey(nodeType); 70 | } 71 | 72 | public void Remove(Type type) 73 | { 74 | if (_isLocked) 75 | { 76 | _pending[type] = new PendingChangeFamilyPair 77 | { 78 | Change = PendingChange.Remove 79 | }; 80 | } 81 | else 82 | _families.Remove(type); 83 | } 84 | 85 | public IEnumerator GetEnumerator() 86 | { 87 | return _families.Values.GetEnumerator(); 88 | } 89 | 90 | IEnumerator IEnumerable.GetEnumerator() 91 | { 92 | return GetEnumerator(); 93 | } 94 | 95 | public void Lock() 96 | { 97 | _isLocked = true; 98 | } 99 | 100 | public void UnLock() 101 | { 102 | _isLocked = false; 103 | 104 | foreach (var pair in _pending) 105 | { 106 | if (pair.Value.Change == PendingChange.Add) 107 | Add(pair.Key, pair.Value.Family); 108 | if (pair.Value.Change == PendingChange.Remove) 109 | Remove(pair.Key); 110 | } 111 | 112 | _pending.Clear(); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/IEngine.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public interface IEngine 9 | { 10 | void AddEntity(IEntity entity); 11 | void RemoveEntity(IEntity entity); 12 | void AddSystem(ISystem system, int priority); 13 | void RemoveSystem(ISystem system); 14 | INodeList GetNodes() where T : Node; 15 | void ReleaseNodes(INodeList nodes); 16 | void Update(float delta); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace Ash.Core 8 | { 9 | public interface IEntity 10 | { 11 | bool Has(Type type); 12 | object Get(Type type); 13 | T Add() where T : Component; 14 | void Remove(Component component); 15 | ComponentAdded ComponentAdded { get; } 16 | ComponentRemoved ComponentRemoved { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/IFamily.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public interface IFamily 9 | { 10 | void ComponentAdded(IEntity entity, Type componentType); 11 | void ComponentRemoved(IEntity entity, Type componentType); 12 | void EntityAdded(IEntity entity); 13 | void EntityRemoved(IEntity entity); 14 | void BeforeUpdate(); 15 | void AfterUpdate(); 16 | } 17 | 18 | public interface IFamily : IFamily 19 | { 20 | INodeList Nodes { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/IFamilyFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public interface IFamilyFactory 9 | { 10 | IFamily Produce(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/INodePool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public interface INodePool 9 | { 10 | T UnPool(); 11 | void Pool(T node); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/INodelist.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine.Events; 6 | 7 | namespace Ash.Core 8 | { 9 | public interface INodeList : IEnumerable 10 | { 11 | NodeAdded NodeAddedEvent { get; } 12 | NodeRemoved NodeRemovedEvent { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/ISystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ash.Core; 6 | 7 | namespace Ash.Core 8 | { 9 | public interface ISystem 10 | { 11 | void AddedToEngine(IEngine engine); 12 | void RemovedFromEngine(IEngine engine); 13 | void Update(float delta); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/NodeList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using Ash.Core; 7 | 8 | namespace Ash.Core 9 | { 10 | public class NodeList : INodeList 11 | { 12 | enum PendingChange 13 | { 14 | Add, 15 | Remove 16 | } 17 | 18 | public bool IsLocked { get; private set; } 19 | 20 | private HashSet _nodes; 21 | private List> _pending; 22 | 23 | public NodeList() 24 | { 25 | _nodes = new HashSet(); 26 | NodeAddedEvent = new NodeAdded(); 27 | NodeRemovedEvent = new NodeRemoved(); 28 | _pending = new List>(); 29 | } 30 | 31 | public void Add(T node) 32 | { 33 | if (IsLocked) 34 | { 35 | _pending.Add(new KeyValuePair(node, PendingChange.Add)); 36 | } 37 | else 38 | { 39 | _nodes.Add(node); 40 | NodeAddedEvent.Invoke(node); 41 | } 42 | } 43 | 44 | public void Remove(T node) 45 | { 46 | if (IsLocked) 47 | { 48 | _pending.Add(new KeyValuePair(node, PendingChange.Remove)); 49 | } 50 | else 51 | { 52 | _nodes.Remove(node); 53 | NodeRemovedEvent.Invoke(node); 54 | } 55 | } 56 | 57 | public void Lock() 58 | { 59 | IsLocked = true; 60 | } 61 | 62 | public void Unlock() 63 | { 64 | IsLocked = false; 65 | ApplyPending(); 66 | _pending.Clear(); 67 | } 68 | 69 | private void ApplyPending() 70 | { 71 | foreach (var pair in _pending) 72 | { 73 | if (pair.Value == PendingChange.Add) 74 | Add(pair.Key); 75 | else 76 | Remove(pair.Key); 77 | } 78 | } 79 | 80 | public IEnumerator GetEnumerator() 81 | { 82 | return _nodes.GetEnumerator(); 83 | } 84 | 85 | IEnumerator IEnumerable.GetEnumerator() 86 | { 87 | return GetEnumerator(); 88 | } 89 | 90 | public NodeAdded NodeAddedEvent { get; private set; } 91 | public NodeRemoved NodeRemovedEvent { get; private set; } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/NodePool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public class NodePool : INodePool 9 | { 10 | public T UnPool() 11 | { 12 | return Activator.CreateInstance(); 13 | } 14 | 15 | public void Pool(T node) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/Nodes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | public class Node 9 | { 10 | } 11 | 12 | public class Node : Node 13 | { 14 | public T Component1 { get; set; } 15 | } 16 | 17 | public class Node : Node 18 | { 19 | public T2 Component2 { get; set; } 20 | } 21 | 22 | public class Node : Node 23 | { 24 | public T3 Component3 { get; set; } 25 | } 26 | 27 | public class Node : Node 28 | { 29 | public T4 Component4 { get; set; } 30 | } 31 | 32 | public class Node : Node 33 | { 34 | public T5 Component5 { get; set; } 35 | } 36 | 37 | public class Node : Node 38 | { 39 | public T6 Component6 { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Core/SystemPriorityPair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Ash.Core 7 | { 8 | internal class SystemPriorityPair 9 | { 10 | public ISystem System { get; private set; } 11 | public int Priority { get; private set; } 12 | 13 | public SystemPriorityPair(ISystem system, int priority) 14 | { 15 | System = system; 16 | Priority = priority; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Helpers/AshExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ash.Core; 6 | using Ash.Helpers; 7 | using UnityEngine; 8 | 9 | public static class AshEngineExtensions 10 | { 11 | public static void First(this IEngine engine, Action callback) where T : Component 12 | { 13 | var nodes = engine.GetNodes>(); 14 | if (nodes.Any()) 15 | callback(nodes.First().Component1); 16 | } 17 | 18 | public static Maybe First(this IEngine engine) where T : Component 19 | { 20 | var nodes = engine.GetNodes>(); 21 | if (nodes.Any()) 22 | return new Maybe(nodes.First().Component1); 23 | else 24 | return new Maybe(null); 25 | } 26 | 27 | public static void ForEach(this IEngine engine, Action callback) where T1 : Component 28 | { 29 | var nodes = engine.GetNodes>(); 30 | foreach (var n in nodes) 31 | callback(n.Component1); 32 | } 33 | 34 | public static void ForEach(this IEngine engine, Action callback) 35 | where T1 : Component where T2 : Component 36 | { 37 | var nodes = engine.GetNodes>(); 38 | foreach (var n in nodes) 39 | callback(n.Component1, n.Component2); 40 | } 41 | 42 | public static void ForEach(this IEngine engine, Action callback) 43 | where T1 : Component where T2 : Component where T3 : Component 44 | { 45 | var nodes = engine.GetNodes>(); 46 | foreach (var n in nodes) 47 | callback(n.Component1, n.Component2, n.Component3); 48 | } 49 | 50 | public static void ForEach(this IEngine engine, Action callback) 51 | where T1 : Component where T2 : Component where T3 : Component where T4 : Component 52 | { 53 | var nodes = engine.GetNodes>(); 54 | foreach (var n in nodes) 55 | callback(n.Component1, n.Component2, n.Component3, n.Component4); 56 | } 57 | 58 | public static void RemoveAll(this IEngine engine) where T1 : Component 59 | { 60 | var nodes = engine.GetNodes>(); 61 | while(nodes.Any()) 62 | nodes.Last().Component1.Remove(); 63 | } 64 | 65 | public static void Remove(this Entity entity) where T : Component 66 | { 67 | var component = entity.GetComponent(); 68 | if (component != null) 69 | entity.Remove(component); 70 | } 71 | 72 | public static T Add(this Component component) where T : Component 73 | { 74 | var entity = component.GetComponent(); 75 | if (entity == null) 76 | throw new Exception("Cant add component, this component doesnt have an Entity component attached to the GameObject"); 77 | 78 | return entity.Add(); 79 | } 80 | 81 | public static void Remove(this Component component) where T : Component 82 | { 83 | var entity = component.GetComponent(); 84 | if (entity == null) 85 | throw new Exception("Cant remove component, this component doesnt have an Entity component attached to the GameObject"); 86 | 87 | entity.Remove(); 88 | } 89 | 90 | public static void Remove(this Component component) 91 | { 92 | var entity = component.GetComponent(); 93 | if (entity == null) 94 | throw new Exception("Cant remove component, this component doesnt have an Entity component attached to the GameObject"); 95 | 96 | entity.Remove(component); 97 | } 98 | 99 | public static bool Has(this IEntity entity) 100 | { 101 | return entity.Has(typeof(T)); 102 | } 103 | 104 | public static T Get(this IEntity entity) where T : Component 105 | { 106 | return (T)entity.Get(typeof(T)); 107 | } 108 | } -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Helpers/Maybe.cs: -------------------------------------------------------------------------------- 1 | namespace Ash.Helpers 2 | { 3 | /// 4 | /// Represents a potentially null return 5 | /// Borrowed from https://lostechies.com/derickbailey/2010/09/30/monads-in-c-which-part-is-the-monad/ 6 | /// 7 | /// 8 | public sealed class Maybe 9 | { 10 | public static Maybe None = new Maybe(default(T)); 11 | 12 | public T Value { get; set; } 13 | 14 | public bool HasValue 15 | { 16 | get 17 | { 18 | var hasValue = Value != null && !Value.Equals(default(T)); 19 | return hasValue; 20 | } 21 | } 22 | 23 | public Maybe(T value) 24 | { 25 | Value = value; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Source/Helpers/NodelssSystems.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ash.Core; 6 | 7 | namespace Ash.Helpers 8 | { 9 | public class NodelessSystem : ISystem 10 | { 11 | protected Action _addedToEngineCallback; 12 | 13 | public virtual void AddedToEngine(IEngine engine) 14 | { 15 | if (_addedToEngineCallback != null) 16 | _addedToEngineCallback(engine); 17 | } 18 | 19 | public virtual void RemovedFromEngine(IEngine engine) 20 | { 21 | } 22 | 23 | public virtual void Update(float delta) 24 | { 25 | } 26 | } 27 | 28 | public class NodelessSystem : NodelessSystem 29 | { 30 | protected Action _updateCallback; 31 | protected Action _nodeAddedCallback; 32 | protected Action _nodeRemovedCallback; 33 | 34 | private INodeList> _nodes; 35 | 36 | override public void AddedToEngine(IEngine engine) 37 | { 38 | _nodes = engine.GetNodes>(); 39 | _nodes.NodeAddedEvent.AddListener(OnNodeAdded); 40 | _nodes.NodeRemovedEvent.AddListener(OnNodeRemoved); 41 | base.AddedToEngine(engine); 42 | } 43 | 44 | private void OnNodeRemoved(Node node) 45 | { 46 | if (_nodeRemovedCallback != null) 47 | _nodeRemovedCallback(node.Component1); 48 | } 49 | 50 | private void OnNodeAdded(Node node) 51 | { 52 | if (_nodeAddedCallback != null) 53 | _nodeAddedCallback(node.Component1); 54 | } 55 | 56 | override public void RemovedFromEngine(IEngine engine) 57 | { 58 | _nodes.NodeAddedEvent.RemoveListener(OnNodeAdded); 59 | _nodes.NodeRemovedEvent.RemoveListener(OnNodeRemoved); 60 | } 61 | 62 | override public void Update(float delta) 63 | { 64 | if (_updateCallback != null) 65 | foreach (var node in _nodes) 66 | _updateCallback(delta, node.Component1); 67 | } 68 | } 69 | 70 | public class NodelessSystem : NodelessSystem 71 | { 72 | protected Action _updateCallback; 73 | protected Action _nodeAddedCallback; 74 | protected Action _nodeRemovedCallback; 75 | 76 | private INodeList> _nodes; 77 | 78 | override public void AddedToEngine(IEngine engine) 79 | { 80 | _nodes = engine.GetNodes>(); 81 | _nodes.NodeAddedEvent.AddListener(OnNodeAdded); 82 | _nodes.NodeRemovedEvent.AddListener(OnNodeRemoved); 83 | base.AddedToEngine(engine); 84 | } 85 | 86 | private void OnNodeRemoved(Node node) 87 | { 88 | if (_nodeRemovedCallback != null) 89 | _nodeRemovedCallback(node.Component1, node.Component2); 90 | } 91 | 92 | private void OnNodeAdded(Node node) 93 | { 94 | if (_nodeAddedCallback != null) 95 | _nodeAddedCallback(node.Component1, node.Component2); 96 | } 97 | 98 | override public void RemovedFromEngine(IEngine engine) 99 | { 100 | _nodes.NodeAddedEvent.RemoveListener(OnNodeAdded); 101 | _nodes.NodeRemovedEvent.RemoveListener(OnNodeRemoved); 102 | } 103 | 104 | override public void Update(float delta) 105 | { 106 | if (_updateCallback != null) 107 | foreach (var node in _nodes) 108 | _updateCallback(delta, node.Component1, node.Component2); 109 | } 110 | } 111 | 112 | public class NodelessSystem : NodelessSystem 113 | { 114 | protected Action _updateCallback; 115 | protected Action _nodeAddedCallback; 116 | protected Action _nodeRemovedCallback; 117 | 118 | private INodeList> _nodes; 119 | 120 | override public void AddedToEngine(IEngine engine) 121 | { 122 | _nodes = engine.GetNodes>(); 123 | _nodes.NodeAddedEvent.AddListener(OnNodeAdded); 124 | _nodes.NodeRemovedEvent.AddListener(OnNodeRemoved); 125 | base.AddedToEngine(engine); 126 | } 127 | 128 | private void OnNodeRemoved(Node node) 129 | { 130 | if (_nodeRemovedCallback != null) 131 | _nodeRemovedCallback(node.Component1, node.Component2, node.Component3); 132 | } 133 | 134 | private void OnNodeAdded(Node node) 135 | { 136 | if (_nodeAddedCallback != null) 137 | _nodeAddedCallback(node.Component1, node.Component2, node.Component3); 138 | } 139 | 140 | override public void RemovedFromEngine(IEngine engine) 141 | { 142 | _nodes.NodeAddedEvent.RemoveListener(OnNodeAdded); 143 | _nodes.NodeRemovedEvent.RemoveListener(OnNodeRemoved); 144 | } 145 | 146 | override public void Update(float delta) 147 | { 148 | if (_updateCallback != null) 149 | foreach (var node in _nodes) 150 | _updateCallback(delta, node.Component1, node.Component2, node.Component3); 151 | } 152 | } 153 | 154 | public class NodelessSystem : NodelessSystem 155 | { 156 | protected Action _updateCallback; 157 | protected Action _nodeAddedCallback; 158 | protected Action _nodeRemovedCallback; 159 | 160 | private INodeList> _nodes; 161 | 162 | override public void AddedToEngine(IEngine engine) 163 | { 164 | _nodes = engine.GetNodes>(); 165 | _nodes.NodeAddedEvent.AddListener(OnNodeAdded); 166 | _nodes.NodeRemovedEvent.AddListener(OnNodeRemoved); 167 | base.AddedToEngine(engine); 168 | } 169 | 170 | private void OnNodeRemoved(Node node) 171 | { 172 | if (_nodeRemovedCallback != null) 173 | _nodeRemovedCallback(node.Component1, node.Component2, node.Component3, node.Component4); 174 | } 175 | 176 | private void OnNodeAdded(Node node) 177 | { 178 | if (_nodeAddedCallback != null) 179 | _nodeAddedCallback(node.Component1, node.Component2, node.Component3, node.Component4); 180 | } 181 | 182 | override public void RemovedFromEngine(IEngine engine) 183 | { 184 | } 185 | 186 | override public void Update(float delta) 187 | { 188 | if (_updateCallback != null) 189 | foreach (var node in _nodes) 190 | _updateCallback(delta, node.Component1, node.Component2, node.Component3, 191 | node.Component4); 192 | } 193 | } 194 | 195 | public class NodelessSystem : NodelessSystem 196 | { 197 | protected Action _updateCallback; 198 | protected Action _nodeAddedCallback; 199 | protected Action _nodeRemovedCallback; 200 | 201 | private INodeList> _nodes; 202 | 203 | override public void AddedToEngine(IEngine engine) 204 | { 205 | _nodes = engine.GetNodes>(); 206 | _nodes.NodeAddedEvent.AddListener(OnNodeAdded); 207 | _nodes.NodeRemovedEvent.AddListener(OnNodeRemoved); 208 | base.AddedToEngine(engine); 209 | } 210 | 211 | private void OnNodeRemoved(Node node) 212 | { 213 | if (_nodeRemovedCallback != null) 214 | _nodeRemovedCallback(node.Component1, node.Component2, node.Component3, 215 | node.Component4, node.Component5); 216 | } 217 | 218 | private void OnNodeAdded(Node node) 219 | { 220 | if (_nodeAddedCallback != null) 221 | _nodeAddedCallback(node.Component1, node.Component2, node.Component3, 222 | node.Component4, node.Component5); 223 | } 224 | 225 | override public void RemovedFromEngine(IEngine engine) 226 | { 227 | _nodes.NodeAddedEvent.RemoveListener(OnNodeAdded); 228 | _nodes.NodeRemovedEvent.RemoveListener(OnNodeRemoved); 229 | } 230 | 231 | override public void Update(float delta) 232 | { 233 | if (_updateCallback != null) 234 | foreach (var node in _nodes) 235 | _updateCallback(delta, node.Component1, node.Component2, node.Component3, 236 | node.Component4, node.Component5); 237 | } 238 | } 239 | 240 | public class NodelessSystem : NodelessSystem 241 | { 242 | protected Action _updateCallback; 243 | protected Action _nodeAddedCallback; 244 | protected Action _nodeRemovedCallback; 245 | 246 | private INodeList> _nodes; 247 | 248 | override public void AddedToEngine(IEngine engine) 249 | { 250 | _nodes = engine.GetNodes>(); 251 | _nodes.NodeAddedEvent.AddListener(OnNodeAdded); 252 | _nodes.NodeRemovedEvent.AddListener(OnNodeRemoved); 253 | base.AddedToEngine(engine); 254 | } 255 | 256 | private void OnNodeRemoved(Node node) 257 | { 258 | if (_nodeRemovedCallback != null) 259 | _nodeRemovedCallback(node.Component1, node.Component2, node.Component3, 260 | node.Component4, node.Component5, node.Component6); 261 | } 262 | 263 | private void OnNodeAdded(Node node) 264 | { 265 | if (_nodeAddedCallback != null) 266 | _nodeAddedCallback(node.Component1, node.Component2, node.Component3, 267 | node.Component4, node.Component5, node.Component6); 268 | } 269 | 270 | override public void RemovedFromEngine(IEngine engine) 271 | { 272 | _nodes.NodeAddedEvent.RemoveListener(OnNodeAdded); 273 | _nodes.NodeRemovedEvent.RemoveListener(OnNodeRemoved); 274 | } 275 | 276 | override public void Update(float delta) 277 | { 278 | if (_updateCallback != null) 279 | foreach (var node in _nodes) 280 | _updateCallback(delta, node.Component1, node.Component2, node.Component3, 281 | node.Component4, node.Component5, node.Component6); 282 | } 283 | } 284 | 285 | public delegate void Action(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5); 286 | public delegate void Action(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6); 287 | public delegate void Action(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7); 288 | } 289 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Helpers/FakeEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace Ash.Core 8 | { 9 | public class FakeEntity : Entity 10 | { 11 | public static IEngine engine; 12 | 13 | override protected IEngine FindEngine() 14 | { 15 | return engine; 16 | } 17 | 18 | override protected void DestroyComponent(Component component) 19 | { 20 | DestroyImmediate(component); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Helpers/MockComponents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace Ash.Core 8 | { 9 | public class MockComponentA 10 | { 11 | } 12 | 13 | public class MockComponentB 14 | { 15 | } 16 | 17 | public class MockComponentC 18 | { 19 | } 20 | 21 | public class MockUnityComponent : MonoBehaviour 22 | { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Helpers/MockEntities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace Ash.Core 8 | { 9 | public class MockEntity : IEntity 10 | { 11 | protected List _components; 12 | public List Components 13 | { 14 | get { return _components; } 15 | set { _components = value; } 16 | } 17 | 18 | public MockEntity() 19 | { 20 | ComponentAdded = new ComponentAdded(); 21 | ComponentRemoved = new ComponentRemoved(); 22 | _components = new List(); 23 | } 24 | 25 | public bool Has(Type type) 26 | { 27 | return _components.Any(c => type.IsAssignableFrom(c.GetType())); 28 | } 29 | 30 | public bool IsDestroyed { get; private set; } 31 | 32 | public object Get(Type type) 33 | { 34 | if (!Has(type)) 35 | throw new Exception("Invalid type"); 36 | 37 | return _components.FirstOrDefault(c => type.IsAssignableFrom(c.GetType())); 38 | } 39 | 40 | public T Add() where T : Component 41 | { 42 | var inst = Activator.CreateInstance(); 43 | _components.Add(inst); 44 | return inst; 45 | } 46 | 47 | public void Remove(Component component) 48 | { 49 | _components.Remove(component); 50 | } 51 | 52 | public ComponentAdded ComponentAdded { get; private set; } 53 | public ComponentRemoved ComponentRemoved { get; private set; } 54 | } 55 | 56 | public class MockEntity : MockEntity 57 | { 58 | public MockEntity() 59 | { 60 | _components.Add(Activator.CreateInstance()); 61 | } 62 | } 63 | 64 | public class MockEntity : MockEntity 65 | { 66 | public MockEntity() 67 | { 68 | _components.Add(Activator.CreateInstance()); 69 | _components.Add(Activator.CreateInstance()); 70 | } 71 | } 72 | 73 | public class MockEntity : MockEntity 74 | { 75 | public MockEntity() 76 | { 77 | _components.Add(Activator.CreateInstance()); 78 | _components.Add(Activator.CreateInstance()); 79 | _components.Add(Activator.CreateInstance()); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Helpers/MockSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ash.Core; 6 | 7 | namespace Ash.Core 8 | { 9 | public class MockSystem : ISystem 10 | { 11 | public Action AddedToEngineCallback { get; set; } 12 | public Action RemovedFromEngineCallback { get; set; } 13 | public Action UpdateCallback { get; set; } 14 | 15 | public void AddedToEngine(IEngine engine) 16 | { 17 | if (AddedToEngineCallback != null) 18 | AddedToEngineCallback(engine); 19 | } 20 | 21 | public void RemovedFromEngine(IEngine engine) 22 | { 23 | if (RemovedFromEngineCallback != null) 24 | RemovedFromEngineCallback(engine); 25 | } 26 | 27 | public void Update(float delta) 28 | { 29 | if (UpdateCallback != null) 30 | UpdateCallback(delta); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestAddedEntityRemoved.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using NUnit.Framework; 7 | using UnityEngine; 8 | using UnityEngine.TestTools; 9 | 10 | namespace Ash.Core 11 | { 12 | 13 | public class TestAddedEntityRemoved 14 | { 15 | [Test] 16 | public void Test() 17 | { 18 | var engine = new Engine(); 19 | 20 | var obj = new GameObject(); 21 | var entity = obj.AddComponent(); 22 | entity.Add(); 23 | 24 | var nodes = engine.GetNodes>(); 25 | 26 | GameObject.DestroyImmediate(obj); 27 | 28 | Assert.AreEqual(0, nodes.Count()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestAddingAndRemovingEntitiesDispatchesEvents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | public class TestAddingAndRemovingEntitiesDispatchesEvents 11 | { 12 | [Test] 13 | public void Test() 14 | { 15 | var engine = new Engine(); 16 | 17 | var obj = new GameObject(); 18 | var entity = obj.AddComponent(); 19 | 20 | var nodes = engine.GetNodes>(); 21 | var added = false; 22 | var removed = false; 23 | nodes.NodeAddedEvent.AddListener(node => added = true); 24 | nodes.NodeAddedEvent.AddListener(node => removed = true); 25 | 26 | var renderer = entity.Add(); 27 | entity.Remove(renderer); 28 | 29 | Assert.AreEqual(0, nodes.Count()); 30 | Assert.IsTrue(added); 31 | Assert.IsTrue(removed); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestCanRemoveComponentDuringNodeAdded.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NUnit.Framework; 3 | using UnityEngine; 4 | 5 | namespace Ash.Core 6 | { 7 | public class TestCanRemoveComponentDuringNodeAdded 8 | { 9 | [Test] 10 | public void Test() 11 | { 12 | var engine = new Engine(); 13 | 14 | var obj = new GameObject(); 15 | var entity = obj.AddComponent(); 16 | var nodes = engine.GetNodes>(); 17 | var nodeAddedCalled = false; 18 | 19 | // We should be able to remove a component during a node added event 20 | nodes.NodeAddedEvent.AddListener(node => 21 | { 22 | nodeAddedCalled = true; 23 | Assert.AreEqual(1, nodes.Count()); 24 | node.Component1.Remove(); 25 | Assert.AreEqual(0, nodes.Count()); 26 | }); 27 | 28 | // This should trigger the above node added event 29 | entity.Add(); 30 | 31 | Assert.AreEqual(0, nodes.Count()); 32 | Assert.IsTrue(nodeAddedCalled); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestDestroyingAnEntityMidUpdateUpdatesOthers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NSubstitute; 6 | using NUnit.Framework; 7 | using UnityEngine; 8 | 9 | namespace Ash.Core 10 | { 11 | public class TestDestroyingAnEntityMidUpdateUpdatesOthers 12 | { 13 | private Engine _engine; 14 | private Entity _entity1; 15 | private Entity _entity2; 16 | private Entity _entity3; 17 | private ISystem _system; 18 | private INodeList> _nodes; 19 | private int _calls; 20 | 21 | [SetUp] 22 | public void Setup() 23 | { 24 | _engine = new Engine(); 25 | 26 | _entity1 = new GameObject().AddComponent(); 27 | _entity2 = new GameObject().AddComponent(); 28 | _entity3 = new GameObject().AddComponent(); 29 | 30 | _system = Substitute.For(); 31 | _nodes = _engine.GetNodes>(); 32 | 33 | _engine.AddSystem(_system, 0); 34 | 35 | _calls = 0; 36 | } 37 | 38 | [Test] 39 | public void TestAssumption() 40 | { 41 | _system.When(s => s.Update(0)).Do(c => 42 | { 43 | foreach (var node in _nodes) 44 | _calls++; 45 | }); 46 | 47 | _engine.Update(0); 48 | 49 | Assert.AreEqual(3, _calls); 50 | } 51 | 52 | [Test] 53 | public void TestDestroyingThisOne() 54 | { 55 | _system.When(s => s.Update(0)).Do(c => 56 | { 57 | foreach (var node in _nodes) 58 | { 59 | _calls++; 60 | 61 | if (_calls==2) 62 | GameObject.DestroyImmediate(_entity2.gameObject); 63 | } 64 | }); 65 | 66 | _engine.Update(0); 67 | 68 | Assert.AreEqual(3, _calls); 69 | } 70 | 71 | [Test] 72 | public void TestDestroyingNextOne() 73 | { 74 | _system.When(s => s.Update(0)).Do(c => 75 | { 76 | foreach (var node in _nodes) 77 | { 78 | _calls++; 79 | 80 | if (_calls == 1) 81 | GameObject.DestroyImmediate(_entity2.gameObject); 82 | 83 | if (_calls == 2) 84 | Assert.IsTrue(node.Component1==null); 85 | } 86 | }); 87 | 88 | _engine.Update(0); 89 | 90 | Assert.AreEqual(3, _calls); 91 | } 92 | 93 | [Test] 94 | public void TestRemovingNextOne() 95 | { 96 | _system.When(s => s.Update(0)).Do(c => 97 | { 98 | foreach (var node in _nodes) 99 | { 100 | _calls++; 101 | 102 | if (_calls == 1) 103 | _engine.RemoveEntity(_entity2); 104 | } 105 | }); 106 | 107 | _engine.Update(0); 108 | 109 | Assert.AreEqual(3, _calls); 110 | } 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NSubstitute; 3 | using NUnit.Framework; 4 | using UnityEngine; 5 | 6 | namespace Ash.Core 7 | { 8 | public class TestEntity 9 | { 10 | private FakeEntity _entity; 11 | private IEngine _engine; 12 | 13 | [SetUp] 14 | public void Setup() 15 | { 16 | FakeEntity.engine = _engine = Substitute.For(); 17 | _entity = new GameObject().AddComponent(); 18 | } 19 | 20 | [Test] 21 | public void DuringAwake_EntityAddedToEngine() 22 | { 23 | _engine.Received(1).AddEntity(_entity); 24 | } 25 | 26 | [Test] 27 | public void AfterAwkening_EntityDetectsExistingComponents() 28 | { 29 | Assert.IsFalse(_entity.Has()); 30 | } 31 | 32 | [Test] 33 | public void AfterAddingComponentInternally_EntityHasComponent() 34 | { 35 | _entity.Add(); 36 | Assert.IsTrue(_entity.Has()); 37 | } 38 | 39 | [Test] 40 | public void AfterRemovingComponentInternally_EntityNoLongerHasComponent() 41 | { 42 | _entity.Add(); 43 | _entity.Remove(); 44 | Assert.IsFalse(_entity.Has()); 45 | } 46 | 47 | [Test] 48 | public void AddingComponentInternally_DispatchesAddedEvent() 49 | { 50 | var added = 0; 51 | _entity.ComponentAdded.AddListener((e, t) => added++); 52 | _entity.Add(); 53 | Assert.AreEqual(1, added); 54 | } 55 | 56 | [Test] 57 | public void RemovingComponentInternally_DispatchesRemovedEvent() 58 | { 59 | var removed = 0; 60 | _entity.ComponentAdded.AddListener((e, t) => removed++); 61 | _entity.Add(); 62 | _entity.Remove(); 63 | Assert.AreEqual(1, removed); 64 | } 65 | 66 | [Test] 67 | public void WhenEntityGameObjectDestroyed_EngineInformed() 68 | { 69 | GameObject.DestroyImmediate(_entity.gameObject); 70 | _engine.Received(1).RemoveEntity(Arg.Any()); 71 | } 72 | 73 | [Test] 74 | public void WhenEntityComponentRemoved_EngineInformed() 75 | { 76 | GameObject.DestroyImmediate(_entity); 77 | _engine.Received(1).RemoveEntity(_entity); 78 | } 79 | 80 | //[Test] 81 | //public void IfAComponentIsAddedExternally_EntityHasComponent() 82 | //{ 83 | // _entity.gameObject.AddComponent(); 84 | // Assert.IsTrue(_entity.Has()); 85 | //} 86 | 87 | //[Test] 88 | //public void IfAComponentIsRemovedExternally_EntityDoesNotHaveComponent() 89 | //{ 90 | // _entity.Add(); 91 | // GameObject.DestroyImmediate(_entity.gameObject.GetComponent()); 92 | // Assert.IsFalse(_entity.Has()); 93 | //} 94 | 95 | //[Test] 96 | //public void IfAComponentIsAddedInternally_ThenRemovedExternally_ComponentRemovedEventDispatchedWhenMissingComponentNoticed() 97 | //{ 98 | // var componentsRemoved = 0; 99 | // _entity.Add(); 100 | // _entity.ComponentRemoved.AddListener((e,t) => componentsRemoved++); 101 | // Assert.AreEqual(0, componentsRemoved); 102 | // GameObject.DestroyImmediate(_entity.gameObject.GetComponent()); 103 | // Assert.AreEqual(0, componentsRemoved); 104 | // Assert.IsFalse(_entity.Has()); 105 | // Assert.AreEqual(1, componentsRemoved); 106 | //} 107 | } 108 | } -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestMatchingEntityAdded.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | public class TestMatchingEntityAdded 11 | { 12 | [Test] 13 | public void Test() 14 | { 15 | var engine = new Engine(); 16 | 17 | var obj = new GameObject(); 18 | var entity = obj.AddComponent(); 19 | var renderer = entity.Add(); 20 | 21 | var nodes = engine.GetNodes>(); 22 | 23 | Assert.AreEqual(1, nodes.Count()); 24 | Assert.AreEqual(renderer, nodes.First().Component1); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestNewFamilyCanBeCreatedDuringNodeAdd.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | 11 | public class TestNewFamilyCanBeCreatedDuringNodeAdd 12 | { 13 | [Test] 14 | public void Test() 15 | { 16 | var engine = new Engine(); 17 | 18 | var nodes1 = engine.GetNodes>(); 19 | nodes1.NodeAddedEvent.AddListener(n => engine.GetNodes>()); 20 | 21 | var obj = new GameObject(); 22 | var entity = obj.AddComponent(); 23 | entity.Add(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestNewFamilyCanBeCreatedDuringNodeRemove.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | public class TestNewFamilyCanBeCreatedDuringNodeRemove 11 | { 12 | [Test] 13 | public void Test() 14 | { 15 | var engine = new Engine(); 16 | 17 | var nodes1 = engine.GetNodes>(); 18 | nodes1.NodeRemovedEvent.AddListener(n => engine.GetNodes>()); 19 | 20 | var obj = new GameObject(); 21 | var entity = obj.AddComponent(); 22 | entity.Add(); 23 | entity.Remove(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestNonMatchingEntityNotAdded.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | public class TestNonMatchingEntityNotAdded 11 | { 12 | [Test] 13 | public void Test() 14 | { 15 | var engine = new Engine(); 16 | 17 | var obj = new GameObject(); 18 | var entity = obj.AddComponent(); 19 | entity.Add(); 20 | 21 | var nodes = engine.GetNodes>(); 22 | 23 | Assert.AreEqual(0, nodes.Count()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Integration/TestRemovingMatchingComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using UnityEngine; 7 | 8 | namespace Ash.Core 9 | { 10 | public class TestRemovingMatchingComponent 11 | { 12 | [Test] 13 | public void Test() 14 | { 15 | var engine = new Engine(); 16 | 17 | var obj = new GameObject(); 18 | var entity = obj.AddComponent(); 19 | var renderer = entity.Add(); 20 | 21 | var nodes = engine.GetNodes>(); 22 | 23 | entity.Remove(renderer); 24 | 25 | Assert.AreEqual(0, nodes.Count()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Unit/Editor/ComponentMatchingFamilyTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using NSubstitute; 3 | using NUnit.Framework; 4 | 5 | namespace Ash.Core 6 | { 7 | [TestFixture] 8 | public class ComponentMatchingFamilyTests 9 | { 10 | 11 | [SetUp] 12 | public void Setup() 13 | { 14 | 15 | } 16 | 17 | [Test] 18 | public void AddingAnEntityWithMissingComponents_IsNotAddedToNodeList() 19 | { 20 | var family = new ComponentMatchingFamily>(); 21 | 22 | var entityA = new MockEntity(); 23 | family.EntityAdded(entityA); 24 | 25 | Assert.IsEmpty(family.Nodes); 26 | } 27 | 28 | [Test] 29 | public void AddingAnEntityWithMatchingComponent_IsAddedToNodeList() 30 | { 31 | var family = new ComponentMatchingFamily>(); 32 | 33 | var entityA = new MockEntity(); 34 | family.EntityAdded(entityA); 35 | 36 | Assert.AreEqual(family.Nodes.Count(), 1); 37 | Assert.AreEqual(family.Nodes.First().Component1, entityA.Components[0]); 38 | } 39 | 40 | [Test] 41 | public void AddingAnEntityWithMultipleMatchingComponents_IsAddedToNodeList() 42 | { 43 | var family = new ComponentMatchingFamily>(); 44 | 45 | var entityA = new MockEntity(); 46 | family.EntityAdded(entityA); 47 | 48 | Assert.AreEqual(family.Nodes.Count(), 1); 49 | Assert.AreEqual(family.Nodes.First().Component1, entityA.Components[0]); 50 | Assert.AreEqual(family.Nodes.First().Component2, entityA.Components[1]); 51 | } 52 | 53 | [Test] 54 | public void AddingAnEntityWithMultipleComponentsButNotMatching_IsNotAddedToNodeList() 55 | { 56 | var family = new ComponentMatchingFamily>(); 57 | 58 | var entityA = new MockEntity(); 59 | family.EntityAdded(entityA); 60 | 61 | Assert.IsEmpty(family.Nodes); 62 | } 63 | 64 | [Test] 65 | public void AddingDifferentEntitiesWithMatchingComponent_AllAreAddedToNodeList() 66 | { 67 | var family = new ComponentMatchingFamily>(); 68 | 69 | var entity1 = new MockEntity(); 70 | var entity2 = new MockEntity(); 71 | 72 | family.EntityAdded(entity1); 73 | 74 | Assert.AreEqual(family.Nodes.Count(), 1); 75 | Assert.AreEqual(family.Nodes.ToList()[0].Component1, entity1.Components[0]); 76 | 77 | family.EntityAdded(entity2); 78 | 79 | Assert.AreEqual(family.Nodes.Count(), 2); 80 | Assert.AreEqual(family.Nodes.ToList()[1].Component1, entity2.Components[0]); 81 | } 82 | 83 | [Test] 84 | public void IfAnEntityIsAddedTwice_ExceptionThrown() 85 | { 86 | var family = new ComponentMatchingFamily>(); 87 | 88 | var entityA = new MockEntity(); 89 | 90 | Assert.Throws(() => 91 | { 92 | family.EntityAdded(entityA); 93 | family.EntityAdded(entityA); 94 | }); 95 | } 96 | 97 | [Test] 98 | public void IfFamilyDoesntContainEntityWhenOneIsRemoved_NothingHappens() 99 | { 100 | var family = new ComponentMatchingFamily>(); 101 | 102 | var entity1 = new MockEntity(); 103 | family.EntityAdded(entity1); 104 | 105 | var entity2 = new MockEntity(); 106 | family.EntityAdded(entity2); 107 | 108 | Assert.IsTrue(family.Nodes.Count() == 1); 109 | Assert.IsTrue(family.Nodes.First().Component1 == entity1.Components[0]); 110 | } 111 | 112 | [Test] 113 | public void IfEntityMatches_RemovesNodeFromList() 114 | { 115 | var family = new ComponentMatchingFamily>(); 116 | 117 | var entity1 = new MockEntity(); 118 | family.EntityAdded(entity1); 119 | family.EntityRemoved(entity1); 120 | 121 | Assert.IsEmpty(family.Nodes); 122 | } 123 | 124 | [Test] 125 | public void IfEntityOfSameTypeButDifferentInstanceIsRemoved_CorrectInstanceIsRemoved() 126 | { 127 | var family = new ComponentMatchingFamily>(); 128 | 129 | var entity1 = new MockEntity(); 130 | family.EntityAdded(entity1); 131 | 132 | var entity2 = new MockEntity(); 133 | family.EntityAdded(entity2); 134 | 135 | Assert.IsTrue(family.Nodes.Count() == 2); 136 | 137 | family.EntityRemoved(entity1); 138 | 139 | Assert.IsTrue(family.Nodes.Count() == 1); 140 | Assert.IsTrue(family.Nodes.First().Component1 == entity2.Components[0]); 141 | } 142 | 143 | [Test] 144 | public void WhenEntityAdded_NodePoolUsed() 145 | { 146 | var pool = Substitute.For>>(); 147 | var family = new ComponentMatchingFamily>(pool); 148 | 149 | pool.UnPool().Returns(new Node()); 150 | 151 | var entity1 = new MockEntity(); 152 | family.EntityAdded(entity1); 153 | 154 | pool.Received().UnPool(); 155 | } 156 | 157 | [Test] 158 | public void WhenEntityRemoved_NodeReturnedToPool() 159 | { 160 | var pool = Substitute.For>>(); 161 | var family = new ComponentMatchingFamily>(pool); 162 | 163 | var node = new Node(); 164 | pool.UnPool().Returns(node); 165 | 166 | var entity1 = new MockEntity(); 167 | family.EntityAdded(entity1); 168 | family.EntityRemoved(entity1); 169 | 170 | pool.Received().UnPool(); 171 | pool.Received().Pool(node); 172 | } 173 | 174 | [Test] 175 | public void IfComponentAddedThatMakesThisEntityMatch_AddedToNodes() 176 | { 177 | var family = new ComponentMatchingFamily>(); 178 | 179 | var entityA = new MockEntity(); 180 | family.ComponentAdded(entityA, typeof(MockComponentA)); 181 | 182 | Assert.AreEqual(family.Nodes.Count(), 1); 183 | Assert.AreEqual(family.Nodes.First().Component1, entityA.Components[0]); 184 | } 185 | 186 | [Test] 187 | public void IfComponentAddedToEntityThatAlreadyInList_NothingHappens() 188 | { 189 | var family = new ComponentMatchingFamily>(); 190 | 191 | var entityA = new MockEntity(); 192 | family.EntityAdded(entityA); 193 | family.ComponentAdded(entityA, typeof(MockComponentB)); 194 | 195 | Assert.AreEqual(family.Nodes.Count(), 1); 196 | Assert.AreEqual(family.Nodes.First().Component1, entityA.Components[0]); 197 | } 198 | 199 | [Test] 200 | public void IfComponentRemovedThatMakesThisEntityNoLongerMatch_RemovedFromNodes() 201 | { 202 | var family = new ComponentMatchingFamily>(); 203 | 204 | var entityA = new MockEntity(); 205 | family.EntityAdded(entityA); 206 | family.ComponentRemoved(entityA, typeof (MockComponentA)); 207 | 208 | Assert.IsEmpty(family.Nodes); 209 | } 210 | 211 | [Test] 212 | public void IfComponentRemovedFromAnEntityNotInTheList_NothingHappens() 213 | { 214 | var family = new ComponentMatchingFamily>(); 215 | 216 | var entity1 = new MockEntity(); 217 | var entity2 = new MockEntity(); 218 | 219 | family.EntityAdded(entity1); 220 | family.EntityAdded(entity2); 221 | 222 | Assert.AreEqual(family.Nodes.Count(), 1); 223 | Assert.AreEqual(family.Nodes.ToList()[0].Component1, entity1.Components[0]); 224 | 225 | family.ComponentRemoved(entity2, typeof(MockComponentA)); 226 | 227 | Assert.AreEqual(family.Nodes.Count(), 1); 228 | Assert.AreEqual(family.Nodes.ToList()[0].Component1, entity1.Components[0]); 229 | } 230 | 231 | [Test] 232 | public void IfComponentRemovedButTheEntityStillMatches_NothingHappens() 233 | { 234 | var family = new ComponentMatchingFamily>(); 235 | 236 | var entityA = new MockEntity(); 237 | family.EntityAdded(entityA); 238 | family.ComponentRemoved(entityA, typeof(MockComponentB)); 239 | 240 | Assert.AreEqual(family.Nodes.Count(), 1); 241 | Assert.AreEqual(family.Nodes.ToList()[0].Component1, entityA.Components[0]); 242 | } 243 | 244 | [Test] 245 | public void BeforeUpdating_NodesLocked() 246 | { 247 | var family = new ComponentMatchingFamily>(); 248 | var nodes = (NodeList>)family.Nodes; 249 | family.BeforeUpdate(); 250 | Assert.IsTrue(nodes.IsLocked); 251 | } 252 | 253 | [Test] 254 | public void BeforeUpdating_NodesUnLocked() 255 | { 256 | var family = new ComponentMatchingFamily>(); 257 | var nodes = (NodeList>)family.Nodes; 258 | family.BeforeUpdate(); 259 | family.AfterUpdate(); 260 | Assert.IsFalse(nodes.IsLocked); 261 | } 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Unit/Editor/EngineTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NSubstitute; 6 | using NUnit.Framework; 7 | 8 | namespace Ash.Core 9 | { 10 | [TestFixture] 11 | public class EngineTests 12 | { 13 | private Engine _engine; 14 | 15 | [SetUp] 16 | public void Setup() 17 | { 18 | _engine = new Engine(); 19 | } 20 | 21 | [Test] 22 | public void AddingASystem_InformsTheSystem() 23 | { 24 | var system = Substitute.For(); 25 | _engine.AddSystem(system, 12); 26 | system.Received().AddedToEngine(_engine); 27 | } 28 | 29 | [Test] 30 | public void RemovingASystem_InformsTheSystem() 31 | { 32 | var system = Substitute.For(); 33 | _engine.RemoveSystem(system); 34 | system.Received().RemovedFromEngine(_engine); 35 | } 36 | 37 | [Test] 38 | public void SystemsAreUpdatedInPriorityOrder() 39 | { 40 | var system1 = Substitute.For(); 41 | var system2 = Substitute.For(); 42 | var system3 = Substitute.For(); 43 | 44 | _engine.AddSystem(system1, 100); 45 | _engine.AddSystem(system2, -20); 46 | _engine.AddSystem(system3, 30); 47 | _engine.Update(23.45f); 48 | 49 | Received.InOrder(() => 50 | { 51 | system2.Update(23.45f); 52 | system3.Update(23.45f); 53 | system1.Update(23.45f); 54 | }); 55 | } 56 | 57 | [Test] 58 | public void RemovedSystemsAreNoLongerUpdated() 59 | { 60 | var system1 = Substitute.For(); 61 | var system2 = Substitute.For(); 62 | var system3 = Substitute.For(); 63 | 64 | _engine.AddSystem(system1, 100); 65 | _engine.AddSystem(system2, -20); 66 | _engine.AddSystem(system3, 30); 67 | _engine.RemoveSystem(system2); 68 | _engine.Update(23.45f); 69 | 70 | system1.Received().Update(23.45f); 71 | system2.DidNotReceive().Update(23.45f); 72 | system3.Received().Update(23.45f); 73 | } 74 | 75 | [Test] 76 | public void GetsNodesForAGivenType() 77 | { 78 | var nodes1 = _engine.GetNodes(); 79 | Assert.IsNotNull(nodes1); 80 | } 81 | 82 | [Test] 83 | public void IfTwoNodeTypesAreReturned_DifferentFamiliesAreReturned() 84 | { 85 | var nodes1 = _engine.GetNodes>(); 86 | var nodes2 = _engine.GetNodes>(); 87 | Assert.IsTrue(nodes1 != nodes2); 88 | } 89 | 90 | [Test] 91 | public void IfSameNodeIsRequestedTwice_SameNodesReturned() 92 | { 93 | var nodes1 = _engine.GetNodes>(); 94 | 95 | var entity = new MockEntity(); 96 | _engine.AddEntity(entity); 97 | 98 | var nodes2 = _engine.GetNodes>(); 99 | 100 | Assert.IsTrue(nodes1.Count() == nodes2.Count()); 101 | Assert.IsTrue(nodes1.ToList()[0] == nodes2.ToList()[0]); 102 | Assert.IsTrue(nodes1.ToList()[0].Component1 == nodes2.ToList()[0].Component1); 103 | } 104 | 105 | [Test] 106 | public void AddingAnEntity_InformsEachFamily() 107 | { 108 | var factory = Substitute.For(); 109 | var engine = new Engine(factory); 110 | 111 | var familyA = Substitute.For>>(); 112 | var familyB = Substitute.For>>(); 113 | 114 | factory.Produce>().Returns(familyA); 115 | factory.Produce>().Returns(familyB); 116 | 117 | engine.GetNodes>(); 118 | engine.GetNodes>(); 119 | 120 | var entityA = new MockEntity(); 121 | 122 | engine.AddEntity(entityA); 123 | 124 | familyA.Received().EntityAdded(entityA); 125 | familyB.Received().EntityAdded(entityA); 126 | } 127 | 128 | [Test] 129 | public void RemovingAnEntity_InformsEachFamily() 130 | { 131 | var factory = Substitute.For(); 132 | var engine = new Engine(factory); 133 | 134 | var familyA = Substitute.For>>(); 135 | var familyB = Substitute.For>>(); 136 | 137 | factory.Produce>().Returns(familyA); 138 | factory.Produce>().Returns(familyB); 139 | 140 | engine.GetNodes>(); 141 | engine.GetNodes>(); 142 | 143 | var entityA = new MockEntity(); 144 | 145 | engine.AddEntity(entityA); 146 | engine.RemoveEntity(entityA); 147 | 148 | familyA.Received().EntityRemoved(entityA); 149 | familyB.Received().EntityRemoved(entityA); 150 | } 151 | 152 | [Test] 153 | public void IfNodesAreReleased_FamilyNoLongerInformedWhenEntityAddedOrRemoved() 154 | { 155 | var factory = Substitute.For(); 156 | var engine = new Engine(factory); 157 | 158 | var familyA = Substitute.For>>(); 159 | var familyB = Substitute.For>>(); 160 | 161 | factory.Produce>().Returns(familyA); 162 | factory.Produce>().Returns(familyB); 163 | 164 | var nodes1 = engine.GetNodes>(); 165 | engine.GetNodes>(); 166 | 167 | engine.ReleaseNodes(nodes1); 168 | 169 | var entityA = new MockEntity(); 170 | 171 | engine.AddEntity(entityA); 172 | engine.RemoveEntity(entityA); 173 | 174 | familyA.DidNotReceive().EntityAdded(entityA); 175 | familyB.Received().EntityAdded(entityA); 176 | 177 | familyA.DidNotReceive().EntityRemoved(entityA); 178 | familyB.Received().EntityRemoved(entityA); 179 | } 180 | 181 | [Test] 182 | public void IfNodesAreReleasedThenRetrievedAgain_EntitiesReadded() 183 | { 184 | var factory = Substitute.For(); 185 | var engine = new Engine(factory); 186 | var entity = new MockEntity(); 187 | 188 | var family1 = Substitute.For>>(); 189 | var family2 = Substitute.For>>(); 190 | factory.Produce>().Returns(family1, family2); 191 | 192 | var nodes1 = engine.GetNodes>(); 193 | engine.AddEntity(entity); 194 | engine.ReleaseNodes(nodes1); 195 | engine.GetNodes>(); 196 | 197 | family1.Received().EntityAdded(entity); 198 | family2.Received().EntityAdded(entity); 199 | } 200 | 201 | [Test] 202 | public void IfNodesAreReleasedThenRetrievedAgain_RemovedEntitiesNotReadded() 203 | { 204 | var factory = Substitute.For(); 205 | var engine = new Engine(factory); 206 | var entity = new MockEntity(); 207 | 208 | var family1 = Substitute.For>>(); 209 | var family2 = Substitute.For>>(); 210 | factory.Produce>().Returns(family1, family2); 211 | 212 | var nodes1 = engine.GetNodes>(); 213 | engine.AddEntity(entity); 214 | engine.ReleaseNodes(nodes1); 215 | engine.RemoveEntity(entity); 216 | engine.GetNodes>(); 217 | 218 | family1.Received().EntityAdded(entity); 219 | family2.DidNotReceive().EntityAdded(entity); 220 | } 221 | 222 | [Test] 223 | public void IfComponentAddedAfterEntityAddedToEngine_FamiliesInformed() 224 | { 225 | var factory = Substitute.For(); 226 | var engine = new Engine(factory); 227 | var entity = new MockEntity(); 228 | 229 | var family1 = Substitute.For>>(); 230 | var family2 = Substitute.For>>(); 231 | factory.Produce>().Returns(family1); 232 | factory.Produce>().Returns(family2); 233 | 234 | engine.GetNodes>(); 235 | engine.GetNodes>(); 236 | engine.AddEntity(entity); 237 | 238 | entity.ComponentAdded.Invoke(entity, typeof (MockComponentC)); 239 | 240 | family1.Received().ComponentAdded(entity, typeof (MockComponentC)); 241 | family2.Received().ComponentAdded(entity, typeof (MockComponentC)); 242 | } 243 | 244 | [Test] 245 | public void IfComponentRemovedAfterEntityAddedToEngine_FamiliesInformed() 246 | { 247 | var factory = Substitute.For(); 248 | var engine = new Engine(factory); 249 | var entity = new MockEntity(); 250 | 251 | var family1 = Substitute.For>>(); 252 | var family2 = Substitute.For>>(); 253 | factory.Produce>().Returns(family1); 254 | factory.Produce>().Returns(family2); 255 | 256 | engine.GetNodes>(); 257 | engine.GetNodes>(); 258 | engine.AddEntity(entity); 259 | 260 | entity.ComponentRemoved.Invoke(entity, typeof (MockComponentC)); 261 | 262 | family1.Received().ComponentRemoved(entity, typeof (MockComponentC)); 263 | family2.Received().ComponentRemoved(entity, typeof (MockComponentC)); 264 | } 265 | 266 | [Test] 267 | public void IfComponentAddedOrRemovedAfterEntityRemovedFromEngine_FamiliesNotInformed() 268 | { 269 | var factory = Substitute.For(); 270 | var engine = new Engine(factory); 271 | var entity = new MockEntity(); 272 | 273 | var family1 = Substitute.For>>(); 274 | var family2 = Substitute.For>>(); 275 | factory.Produce>().Returns(family1); 276 | factory.Produce>().Returns(family2); 277 | 278 | engine.GetNodes>(); 279 | engine.GetNodes>(); 280 | engine.AddEntity(entity); 281 | engine.RemoveEntity(entity); 282 | 283 | entity.ComponentAdded.Invoke(entity, typeof (MockComponentC)); 284 | entity.ComponentRemoved.Invoke(entity, typeof (MockComponentC)); 285 | 286 | family1.DidNotReceive().ComponentAdded(entity, typeof (MockComponentC)); 287 | family2.DidNotReceive().ComponentAdded(entity, typeof (MockComponentC)); 288 | family1.DidNotReceive().ComponentRemoved(entity, typeof (MockComponentC)); 289 | family2.DidNotReceive().ComponentRemoved(entity, typeof (MockComponentC)); 290 | } 291 | 292 | [Test] 293 | public void WhenUpdating_FamiliesAreInformedBeforeAndAfter() 294 | { 295 | var factory = Substitute.For(); 296 | var engine = new Engine(factory); 297 | 298 | var family1 = Substitute.For>>(); 299 | var family2 = Substitute.For>>(); 300 | factory.Produce>().Returns(family1); 301 | factory.Produce>().Returns(family2); 302 | 303 | engine.GetNodes>(); 304 | engine.GetNodes>(); 305 | 306 | engine.Update(20); 307 | 308 | Received.InOrder(() => { 309 | family1.BeforeUpdate(); 310 | family1.AfterUpdate(); 311 | }); 312 | 313 | Received.InOrder(() => { 314 | family2.BeforeUpdate(); 315 | family2.AfterUpdate(); 316 | }); 317 | } 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Unit/Editor/FamiliesContainerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NSubstitute; 6 | using NUnit.Framework; 7 | using UnityEngine; 8 | 9 | namespace Ash.Core 10 | { 11 | [TestFixture] 12 | public class FamiliesContainerTests 13 | { 14 | private FamiliesContainer _container; 15 | 16 | [SetUp] 17 | public void Setup() 18 | { 19 | _container = new FamiliesContainer(); 20 | } 21 | 22 | [Test] 23 | public void AfterAdding_CanBeRetrieved() 24 | { 25 | var type = typeof (Node); 26 | var family = Substitute.For(); 27 | 28 | _container.Add(type, family); 29 | 30 | Assert.IsTrue(_container.Get(type) == family); 31 | } 32 | 33 | [Test] 34 | public void AfterAdding_IsContained() 35 | { 36 | var type = typeof(Node); 37 | var family = Substitute.For(); 38 | 39 | _container.Add(type, family); 40 | 41 | Assert.IsTrue(_container.Contains(type)); 42 | } 43 | 44 | [Test] 45 | public void AfterAddingWhileLocked_IsContained() 46 | { 47 | var type = typeof(Node); 48 | var family = Substitute.For(); 49 | 50 | _container.Lock(); 51 | _container.Add(type, family); 52 | 53 | Assert.IsTrue(_container.Contains(type)); 54 | } 55 | 56 | [Test] 57 | public void AfterAddingThenRemovingWhileLocked_IsNotContained() 58 | { 59 | var type = typeof(Node); 60 | var family = Substitute.For(); 61 | 62 | _container.Lock(); 63 | _container.Add(type, family); 64 | _container.Remove(type); 65 | 66 | Assert.IsFalse(_container.Contains(type)); 67 | } 68 | 69 | [Test] 70 | public void AfterRemovingWhileLocked_IsNotContained() 71 | { 72 | var type = typeof(Node); 73 | var family = Substitute.For(); 74 | 75 | _container.Add(type, family); 76 | _container.Lock(); 77 | _container.Remove(type); 78 | 79 | Assert.IsFalse(_container.Contains(type)); 80 | } 81 | 82 | [Test] 83 | public void AfterRemoving_RetrievalThrowsError() 84 | { 85 | var type = typeof (Node); 86 | var family = Substitute.For(); 87 | 88 | _container.Add(type, family); 89 | _container.Remove(type); 90 | 91 | Assert.Throws(() => _container.Get(type)); 92 | } 93 | 94 | [Test] 95 | public void AfterRemoving_DoesNotContain() 96 | { 97 | var type = typeof(Node); 98 | var family = Substitute.For(); 99 | 100 | _container.Add(type, family); 101 | _container.Remove(type); 102 | 103 | Assert.IsFalse(_container.Contains(type)); 104 | } 105 | 106 | [Test] 107 | public void CanBeIterated() 108 | { 109 | var type1 = typeof (Node); 110 | var family1 = Substitute.For(); 111 | var type2 = typeof (Node); 112 | var family2 = Substitute.For(); 113 | 114 | _container.Add(type1, family1); 115 | _container.Add(type2, family2); 116 | 117 | foreach (var family in _container) 118 | Assert.IsTrue(family == family1 || family == family2); 119 | } 120 | 121 | [Test] 122 | public void WhenLocked_FamiliesCanBeAddedWhileIterating() 123 | { 124 | _container.Add(typeof(Node), Substitute.For()); 125 | _container.Add(typeof(Node), Substitute.For()); 126 | 127 | _container.Lock(); 128 | 129 | foreach (var family in _container) 130 | _container.Add(typeof(Node), Substitute.For()); 131 | } 132 | 133 | [Test] 134 | public void AfterLocking_FamilyCanBeRetrieved() 135 | { 136 | _container.Add(typeof(Node), Substitute.For()); 137 | _container.Add(typeof(Node), Substitute.For()); 138 | 139 | _container.Lock(); 140 | 141 | foreach (var family in _container) 142 | _container.Add(typeof(Node), Substitute.For()); 143 | 144 | _container.UnLock(); 145 | 146 | _container.Get(typeof (Node)); 147 | } 148 | 149 | [Test] 150 | public void WhenLocked_AddedFamilyCanStillBeRetrieved() 151 | { 152 | _container.Add(typeof(Node), Substitute.For()); 153 | _container.Add(typeof(Node), Substitute.For()); 154 | 155 | _container.Lock(); 156 | 157 | foreach (var family in _container) 158 | _container.Add(typeof(Node), Substitute.For()); 159 | 160 | _container.Get(typeof(Node)); 161 | } 162 | 163 | [Test] 164 | public void PendingAreCleared() 165 | { 166 | _container.Lock(); 167 | _container.Add(typeof(Node), Substitute.For()); 168 | _container.UnLock(); 169 | 170 | _container.Remove(typeof(Node)); 171 | 172 | _container.Lock(); 173 | _container.UnLock(); 174 | 175 | Assert.Throws(() => _container.Get(typeof(Node))); 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /Assets/Unity-Ash/Tests/Unit/Editor/NodeListTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NSubstitute; 6 | using NUnit.Framework; 7 | 8 | namespace Ash.Core 9 | { 10 | [TestFixture] 11 | public class NodeListTests 12 | { 13 | [Test] 14 | public void AddingNode() 15 | { 16 | var list = new NodeList(); 17 | var node = new Node(); 18 | 19 | Node eventNode = null; 20 | list.NodeAddedEvent.AddListener(n => eventNode = n); 21 | 22 | list.Add(node); 23 | 24 | Assert.AreEqual(node, eventNode); 25 | Assert.AreEqual(1, list.Count()); 26 | } 27 | 28 | [Test] 29 | public void RemovingNode() 30 | { 31 | var list = new NodeList(); 32 | var node = new Node(); 33 | 34 | Node eventNode = null; 35 | list.NodeRemovedEvent.AddListener(n => eventNode = n); 36 | 37 | list.Add(node); 38 | list.Remove(node); 39 | 40 | Assert.AreEqual(node, eventNode); 41 | Assert.AreEqual(0, list.Count()); 42 | } 43 | 44 | [Test] 45 | public void WhenLocked_AdditionAndRemovalDoesntOccur() 46 | { 47 | var list = new NodeList(); 48 | var node = new Node(); 49 | 50 | Node addEventNode = null; 51 | list.NodeAddedEvent.AddListener(n => addEventNode = n); 52 | 53 | Node removeEventNode = null; 54 | list.NodeRemovedEvent.AddListener(n => removeEventNode = n); 55 | 56 | list.Lock(); 57 | list.Add(node); 58 | list.Remove(node); 59 | 60 | Assert.AreEqual(null, addEventNode); 61 | Assert.AreEqual(null, removeEventNode); 62 | Assert.AreEqual(0, list.Count()); 63 | } 64 | 65 | [Test] 66 | public void WhenUnlocked_AdditionApplied() 67 | { 68 | var list = new NodeList(); 69 | var node = new Node(); 70 | 71 | Node addEventNode = null; 72 | list.NodeAddedEvent.AddListener(n => addEventNode = n); 73 | 74 | list.Lock(); 75 | list.Add(node); 76 | list.Unlock(); 77 | 78 | Assert.AreEqual(node, addEventNode); 79 | Assert.AreEqual(1, list.Count()); 80 | } 81 | 82 | [Test] 83 | public void WhenUnlocked_RemovalApplied() 84 | { 85 | var list = new NodeList(); 86 | var node = new Node(); 87 | 88 | Node eventNode = null; 89 | list.NodeRemovedEvent.AddListener(n => eventNode = n); 90 | 91 | list.Add(node); 92 | list.Lock(); 93 | list.Remove(node); 94 | list.Unlock(); 95 | 96 | Assert.AreEqual(node, eventNode); 97 | Assert.AreEqual(0, list.Count()); 98 | } 99 | 100 | [Test] 101 | public void WhenNextUnlocked_ChangesNotApplied() 102 | { 103 | var list = new NodeList(); 104 | var node = new Node(); 105 | 106 | var count = 0; 107 | list.NodeAddedEvent.AddListener(n => count++); 108 | 109 | list.Lock(); 110 | list.Add(node); 111 | list.Unlock(); 112 | list.Unlock(); 113 | 114 | Assert.AreEqual(1, count); 115 | Assert.AreEqual(1, list.Count()); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Mike Cann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2017.3.1f1 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAnalyticsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/UnityAnalyticsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikecann/Unity-Ash/e5ec2a67496b720cdbfdbce86a099ccd11ec1524/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](http://i.imgur.com/Wpsk1fy.png) 2 | 3 | Unity-Ash 4 | ============= 5 | 6 | An Entity / Component framework for Unity heavily inspired by [Richard Lord's Ash Game Framework](https://github.com/richardlord/Ash). 7 | 8 | More information on Unity-Ash can be found in this blog post: https://mikecann.co.uk/programming/projects/unity/unity-ash/unityasteroids/unity-ash-a-different-way-of-thinking-about-making-games-in-unity/ 9 | 10 | Examples 11 | ----- 12 | 13 | [Unity Ashteroids](https://github.com/mikecann/UnityAshteroids) 14 | 15 | Download 16 | ---- 17 | 18 | Download the latest version: https://github.com/mikecann/Unity-Ash/releases/latest 19 | 20 | Usage 21 | ---- 22 | 23 | There currently isnt a .unitypackage while the framework in is in flux, instead just clone this repo and copy the contents of "Assets/Libraries/Unity-Ash/Source" to your project. 24 | 25 | Checkout [Ashteroids](https://github.com/mikecann/UnityAshteroids) for a full example but some quick tips: 26 | 27 | + Add the Entity Monobehaviour to any GameObject you wish to be detected by Ash. 28 | + Dont add or remove components from GameObject directly, instead use Entity.Add() and Remove(). 29 | 30 | Tests 31 | ----- 32 | 33 | The project uses Unity Test tools for unit and intergration tests. Open the test tools from the menu in Unity and run. 34 | 35 | Differences from Ash 36 | ---- 37 | 38 | There are a number of differences from Ash which is why this project is not a straight port and is instead inspired by the Ash Framework. 39 | 40 | + NodeList's are externally immutable 41 | + Explicit Node classes are optional, the generic Node class can be used instead. 42 | + Nodes can be of any type but the components must be exposed as Properties 43 | + For performance reasons Entities use a static lookup for the current Engine. 44 | + Systems dont contain the Priority property, instead it is supplied when added to the Engine. 45 | -------------------------------------------------------------------------------- /UnityPackageManager/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | } 4 | } 5 | --------------------------------------------------------------------------------