Skip to content

Commit

Permalink
Adding basic gameplay example
Browse files Browse the repository at this point in the history
Started adding basic gameplay example for demo.
  • Loading branch information
grofit committed Feb 21, 2017
1 parent 4a77c88 commit 1f64bd7
Show file tree
Hide file tree
Showing 1,400 changed files with 84,527 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bin
obj
Temp
/src/Library
/src/Assets/Plugins/Editor/Atom.cs
/src/src.userprefs
/*.unitypackage
Library
Assets/Plugins/Editor/Atom.cs
src/src.userprefs
*.unitypackage
9 changes: 9 additions & 0 deletions Assets/EcsRx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework/Attributes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/EcsRx/Framework/Attributes/PriorityAttribute.cs
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;
}
}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Attributes/PriorityAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework/Blueprints.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework/Blueprints/IBlueprint.cs
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);
}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Blueprints/IBlueprint.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework/Components.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Assets/EcsRx/Framework/Components/IComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EcsRx.Components
{
public interface IComponent
{

}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Components/IComponent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework/Entities.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/EcsRx/Framework/Entities/DefaultEntityFactory.cs
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);
}
}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Entities/DefaultEntityFactory.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions Assets/EcsRx/Framework/Entities/Entity.cs
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(); }
}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Entities/Entity.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Assets/EcsRx/Framework/Entities/IEntity.cs
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);
}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Entities/IEntity.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Assets/EcsRx/Framework/Entities/IEntityFactory.cs
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> {}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Entities/IEntityFactory.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/EcsRx/Framework/Events.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Assets/EcsRx/Framework/Events/ComponentAddedEvent.cs
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;
}
}
}
12 changes: 12 additions & 0 deletions Assets/EcsRx/Framework/Events/ComponentAddedEvent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Assets/EcsRx/Framework/Events/ComponentRemovedEvent.cs
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;
}
}
}
Loading

0 comments on commit 1f64bd7

Please sign in to comment.