public void DataDrivenMethod(Entity entity, NormalComponent com) { if (entity == null) { return; } int sharedId = com.SharedId; SharedComponent sharedComponent = null; if (sharedId > 0) { sharedComponent = _sharedComponentDic[sharedId]; } int count = _systemReactiveDic.Count; for (int i = 0; i < count; i++) { ReactiveSystemDto dto = _systemReactiveDic[i]; ComponentFlag executeCondition = dto.CurrentSystem.ExecuteCondition; ComponentFlag reactiveCondition = dto.CurrentSystem.ReactiveCondition; ComponentFlag reactiveIgnoreCondition = dto.CurrentSystem.ReactiveIgnoreCondition; if (!reactiveCondition.HasFlag(com.OperatorId)) { continue; } if (sharedId > 0) { foreach (Entity setEntity in sharedComponent.SharedEntityHashSet) { if (setEntity.GetComponentFlag().HasFlag(reactiveIgnoreCondition)) { continue; } if (setEntity.GetComponentFlag().HasFlag(executeCondition)) { dto.EntityHashSet.Add(setEntity); } } } else { if (entity.GetComponentFlag().HasFlag(reactiveIgnoreCondition)) { continue; } if (entity.GetComponentFlag().HasFlag(executeCondition)) { dto.EntityHashSet.Add(entity); } } } }
/// <summary> /// 创建共享组件 /// </summary> /// <param name="componentId"></param>Int64 componentId /// <returns></returns> public SharedComponent CreateSharedComponent(int componentId) { NormalComponent component = GetComponent(componentId); if ((component.CurrentComponent as ISharedComponent) != null) { SharedComponent shared = new SharedComponent(component, Utils.GetSharedId()); _sharedComponentDic.Add(shared.SharedId, shared); return(shared); } else { throw new Exception("创建共享组件失败,这不是共享组件!!!"); } }
/// <summary> /// 添加共享组件 /// </summary> /// <param name="component"></param> /// <returns></returns> public Entity AddSharedCompoennt(SharedComponent shared) { int componentId = shared.ComponentId; if (ComponentIds.COMPONENT_MAX_COUNT > componentId) { if (_allComponenArray[componentId] != null) { throw new Exception("增加组件失败,组件已存在,组件类型:" + shared.OperatorId.ToString()); } _allComponenArray[componentId] = shared.CurrentComponent; this._currentFlag.SetFlag(shared.OperatorId); if (_changeComponentCallBack != null) { _changeComponentCallBack.Invoke(this, shared.CurrentComponent); } } return(this); }