Skip to content

Instantly share code, notes, and snippets.

@andoowhy
Last active June 11, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andoowhy/82b578b709ff6c57a1f947fa3f0443cb to your computer and use it in GitHub Desktop.
Save andoowhy/82b578b709ff6c57a1f947fa3f0443cb to your computer and use it in GitHub Desktop.
//DexStat.cs
using UnityEngine;
[DisallowMultipleComponent]
public class DexStat : MonoBehaviour
{
public float dexStat = 100f;
}
...
//DexStatModifyer.cs
using UnityEngine;
[DisallowMultipleComponent]
public class DexStatModifyer : MonoBehaviour
{
public float dexStatModifyer = 50f;
}
...
//DexStatSystem.cs
using UnityEngine;
public class DexStatSystem : EgoSystem<DexStat>
{
public override void Start()
{
EgoEvents<AddedComponent<DexStatModifyer>>.AddHandler( ( e ) =>
{
var dexStatModifyer = e.component;
ForEachGameObject( ( ego, dexStat ) =>
{
dexStat.dexStat += dexStatModifyer.dexStatModifyer;
});
});
EgoEvents<DestroyedComponent<DexStatModifyer>>.AddHandler( ( e ) =>
{
var dexStatModifyer = e.component;
ForEachGameObject( ( ego, dexStat ) =>
{
dexStat.dexStat -= dexStatModifyer.dexStatModifyer;
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment