private static int AddCallback(ComponentSystem sys, Entity uiControl, TypeManager.FieldInfo field, bool watchNegative, EventCallback callback) { if (!sys.World.EntityManager.Exists(uiControl)) { return(-1); } var watchers = sys.World.GetExistingSystem <UIControlsWatchersSystem>(); return(watchers.WatchChanged(uiControl, field, (Entity e, bool oldValue, bool value, Watcher source) => { if (value ^ watchNegative) { callback?.Invoke(e); } return true; })); }
/// <summary> /// Watches an entity for changes to a bool component. /// </summary> /// <seealso cref="WatchChanged(Unity.Entities.Entity,Unity.Entities.TypeManager.FieldInfo,Unity.Tiny.Watchers.WatchersSystem.WatchValueDelegateFloat)"/> public int WatchChanged(Entity e, TypeManager.FieldInfo fieldInfo, WatchValueDelegateBool callback) { Watcher w = new Watcher { watchedEntity = e, field = fieldInfo, id = nextId++, system = this }; if (fieldInfo.primitiveType != PrimitiveFieldTypes.Bool) { throw new ArgumentException("A bool field must be watched by a bool delegate."); } var v = new WatcherValueEntryBool { fn = callback, target = w, value = false }; if (!GetValueBool(e, fieldInfo, ref v.value)) { throw new ArgumentException("Could not get initial value to watch. Entity or component is missing."); } watchers.Add(v); return(w.id); }
internal bool GetValueFloat(Entity e, TypeManager.FieldInfo field, ref float value) { if (!EntityManager.Exists(e)) { return(false); } if (!EntityManager.HasComponentRaw(e, field.componentTypeIndex)) { return(false); } float temp; unsafe { byte *ptrDest = (byte *)&temp; byte *ptrSrc = EntityManager.GetComponentDataWithTypeRO(e, field.componentTypeIndex) + field.byteOffsetInComponent; for (int i = 0; i < sizeof(float); i++) { ptrDest[i] = ptrSrc[i]; } } value = temp; return(true); }