internal ActionResult InvokeWithCachedArgs(IRSRuntimeEntity inTarget, ExecutionScope inContext) { if (CheckEntityActive && !inTarget.IsActive()) { inContext.Logger?.Warn("Unable to perform action {0} on Entity \"{1}\" ({2}) - entity is inactive", Id, inTarget.Name, inTarget.Id); return(ActionResult.Inactive()); } object thisArg; bool bValid = PrepContext(inTarget, inContext, out thisArg); if (!bValid) { if (m_MethodSettings.ComponentType != null) { inContext.Logger?.Error("Unable to perform action {0} on Entity \"{1}\" ({2}) - missing component type {3}", Id, inTarget?.Name, inTarget != null ? inTarget.Id : RSEntityId.Null, m_MethodSettings.ComponentType); return(ActionResult.NoComponent(m_MethodSettings.ComponentType)); } else { inContext.Logger?.Error("Unable to perform action {0} on Entity \"{1}\" ({2})", Id, inTarget?.Name, inTarget != null ? inTarget.Id : RSEntityId.Null); return(ActionResult.NoEntity()); } } object result = m_MethodInfo.Invoke(thisArg, m_CachedArguments); return(new ActionResult(result)); }
static private void ToggleActive(this IRSRuntimeEntity inEntity) { inEntity.SetActive(!inEntity.IsActive()); }
static private bool IsActive(this IRSRuntimeEntity inEntity) { return(inEntity.IsActive()); }
/// <summary> /// Generates persistent data from the given runtime entity and its components. /// </summary> static public bool Persist(RSLibrary inLibrary, IRSRuntimeEntity inEntity, IReadOnlyList <IRSRuntimeComponent> inComponents, int inFlags, ref RSPersistEntityData outData) { if (inEntity == null) { return(false); } if (outData == null) { outData = new RSPersistEntityData(); } outData.EntityId = inEntity.Id; outData.Active = inEntity.IsActive(); inEntity.RuleTable?.Persist(ref outData.TableData); using (PooledList <IRSPersistListener> persistListeners = PooledList <IRSPersistListener> .Alloc()) { IRSPersistListener entityPersistListener = inEntity as IRSPersistListener; if (entityPersistListener != null) { entityPersistListener.OnPrePersist(); persistListeners.Add(entityPersistListener); } using (PooledList <RSPersistComponentData> persistedComponentData = PooledList <RSPersistComponentData> .Alloc()) { for (int i = 0, length = inComponents.Count; i < length; ++i) { IRSRuntimeComponent component = inComponents[i]; if (component == null) { continue; } IRSPersistListener componentListener = component as IRSPersistListener; if (componentListener != null) { componentListener.OnPrePersist(); persistListeners.Add(componentListener); } RSComponentInfo componentInfo = inLibrary.GetComponent(component.GetType()); if (componentInfo == null) { continue; } RSPersistComponentData compData = outData.FindComponentData(componentInfo.IdHash); componentInfo.Persist(component, inFlags, ref compData); persistedComponentData.Add(compData); } Array.Resize(ref outData.ComponentData, persistedComponentData.Count); for (int i = 0; i < outData.ComponentData.Length; ++i) { outData.ComponentData[i] = persistedComponentData[i]; } } IRSCustomPersistDataProvider customDataProvider = inEntity as IRSCustomPersistDataProvider; if (customDataProvider != null) { customDataProvider.GetCustomPersistData(ref outData.CustomData, inFlags); } foreach (var listener in persistListeners) { listener.OnPostPersist(); } } return(true); }