-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Started adding basic gameplay example for demo.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace EcsRx.Attributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class PriorityAttribute : Attribute | ||
{ | ||
public int Priority { get; set; } | ||
|
||
public PriorityAttribute(int priority) | ||
{ | ||
Priority = priority; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using EcsRx.Entities; | ||
|
||
namespace EcsRx.Blueprints | ||
{ | ||
public interface IBlueprint | ||
{ | ||
void Apply(IEntity entity); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace EcsRx.Components | ||
{ | ||
public interface IComponent | ||
{ | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using EcsRx.Events; | ||
|
||
namespace EcsRx.Entities | ||
{ | ||
public class DefaultEntityFactory : IEntityFactory | ||
{ | ||
private readonly IEventSystem _eventSystem; | ||
|
||
public DefaultEntityFactory(IEventSystem eventSystem) | ||
{ | ||
_eventSystem = eventSystem; | ||
} | ||
|
||
public IEntity Create(Guid? id = null) | ||
{ | ||
if (!id.HasValue) | ||
{ id = Guid.NewGuid(); } | ||
|
||
return new Entity(id.Value, _eventSystem); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using EcsRx.Components; | ||
using EcsRx.Events; | ||
using EcsRx.Extensions; | ||
using UniRx; | ||
|
||
namespace EcsRx.Entities | ||
{ | ||
public class Entity : IEntity | ||
{ | ||
private readonly Dictionary<Type, IComponent> _components; | ||
|
||
public IEventSystem EventSystem { get; private set; } | ||
|
||
public Guid Id { get; private set; } | ||
public IEnumerable<IComponent> Components { get { return _components.Values; } } | ||
|
||
public Entity(Guid id, IEventSystem eventSystem) | ||
{ | ||
Id = id; | ||
EventSystem = eventSystem; | ||
_components = new Dictionary<Type, IComponent>(); | ||
} | ||
|
||
public IComponent AddComponent(IComponent component) | ||
{ | ||
_components.Add(component.GetType(), component); | ||
EventSystem.Publish(new ComponentAddedEvent(this, component)); | ||
return component; | ||
} | ||
|
||
public T AddComponent<T>() where T : class, IComponent, new() | ||
{ return (T)AddComponent(new T()); } | ||
|
||
public void RemoveComponent(IComponent component) | ||
{ | ||
if(!_components.ContainsKey(component.GetType())) { return; } | ||
|
||
var disposable = component as IDisposable; | ||
if (disposable != null) | ||
{ disposable.Dispose(); } | ||
|
||
_components.Remove(component.GetType()); | ||
EventSystem.Publish(new ComponentRemovedEvent(this, component)); | ||
} | ||
|
||
public void RemoveComponent<T>() where T : class, IComponent | ||
{ | ||
if(!HasComponent<T>()) { return; } | ||
|
||
var component = GetComponent<T>(); | ||
RemoveComponent(component); | ||
} | ||
|
||
public void RemoveAllComponents() | ||
{ | ||
var components = Components.ToArray(); | ||
components.ForEachRun(RemoveComponent); | ||
} | ||
|
||
public bool HasComponent<T>() where T : class, IComponent | ||
{ return _components.ContainsKey(typeof(T)); } | ||
|
||
public bool HasComponents(params Type[] componentTypes) | ||
{ | ||
if(_components.Count == 0) | ||
{ return false; } | ||
|
||
return componentTypes.All(x => _components.ContainsKey(x)); | ||
} | ||
|
||
public T GetComponent<T>() where T : class, IComponent | ||
{ return _components[typeof(T)] as T; } | ||
|
||
public void Dispose() | ||
{ RemoveAllComponents(); } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using EcsRx.Components; | ||
|
||
namespace EcsRx.Entities | ||
{ | ||
public interface IEntity : IDisposable | ||
{ | ||
Guid Id { get; } | ||
IEnumerable<IComponent> Components { get; } | ||
|
||
IComponent AddComponent(IComponent component); | ||
T AddComponent<T>() where T : class, IComponent, new(); | ||
void RemoveComponent(IComponent component); | ||
void RemoveComponent<T>() where T : class, IComponent; | ||
void RemoveAllComponents(); | ||
T GetComponent<T>() where T : class, IComponent; | ||
|
||
bool HasComponent<T>() where T : class, IComponent; | ||
bool HasComponents(params Type[] component); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System; | ||
using EcsRx.Factories; | ||
|
||
namespace EcsRx.Entities | ||
{ | ||
public interface IEntityFactory : IFactory<Guid?, IEntity> {} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using EcsRx.Components; | ||
using EcsRx.Entities; | ||
|
||
namespace EcsRx.Events | ||
{ | ||
public class ComponentAddedEvent | ||
{ | ||
public IEntity Entity { get; private set; } | ||
public IComponent Component { get; private set; } | ||
|
||
public ComponentAddedEvent(IEntity entity, IComponent component) | ||
{ | ||
Entity = entity; | ||
Component = component; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using EcsRx.Components; | ||
using EcsRx.Entities; | ||
|
||
namespace EcsRx.Events | ||
{ | ||
public class ComponentRemovedEvent | ||
{ | ||
public IEntity Entity { get; private set; } | ||
public IComponent Component { get; private set; } | ||
|
||
public ComponentRemovedEvent(IEntity entity, IComponent component) | ||
{ | ||
Entity = entity; | ||
Component = component; | ||
} | ||
} | ||
} |