/// Use when an entity contains an observer and you want to stop the observer without releasing entity. public static void StopObserver(this ent entity) { if (entity.exist) { entity.ComponentObserver().length = 0; } }
/// Use when an entity is an observer and you want to release this entity. public static void ReleaseObserver(this ent entity) { if (entity.exist) { entity.ComponentObserver().length = 0; entity.Release(); } }
public static void ValueChange <TSource, TProp>(this TSource source, Func <TSource, TProp> propertySelector, Action <TProp> callback, ref ent e) { var w = new Wrap <TSource, TProp>(); w.source = source; w.prop = propertySelector; w.callback = callback; #if UNITY_EDITOR if (Comparers.storage.TryGetValue(typeof(TProp).GetHashCode(), out object comparer)) { w.comparer = comparer as IEqualityComparer <TProp>; } else { Debug.LogError($"Comparer for {typeof(TProp)} not found."); } #else w.comparer = Comparers.storage[typeof(TProp).GetHashCode()] as IEqualityComparer <TProp>; #endif var cObserver = default(ComponentObserver); if (!e.exist) { e = Entity.Create(); cObserver = e.Set <ComponentObserver>(); } else { cObserver = e.ComponentObserver(); } #if ACTORS_COMPONENTS_STRUCTS if (cObserver.wrappers == null) { cObserver.wrappers = new IWrap[2]; } Debug.Log(cObserver.wrappers.Length); #endif if (cObserver.length >= cObserver.wrappers.Length) { Array.Resize(ref cObserver.wrappers, cObserver.length << 1); } cObserver.wrappers[cObserver.length++] = w; }