private void Start() { GlobalData.CurrentDisplayObjects .ObserveEveryValueChanged(displayObjects => displayObjects.Count) .Subscribe(_ => RefreshDisplayObjectItem()); UlEventSystem.GetSubject <DataEventType, SelectedChangeData>(DataEventType.SelectedChange) .SampleFrame(1) .Subscribe(_ => RefreshModuleItem()); UlEventSystem.GetTriggerSubject <UIEventType>(UIEventType.UpdateHierarchy) .Sample(TimeSpan.FromMilliseconds(100)) .Subscribe(_ => RefreshDisplayObjectItem()); searchInputField.OnValueChangedAsObservable() .Where(txt => !txt.Equals(_searchText)) .Sample(TimeSpan.FromMilliseconds(500)) .Subscribe(txt => { if (_isGlobalSearchFlag) { UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(null)); } _searchText = txt; RefreshModuleItem(); }); UlEventSystem.GetTriggerSubject <DataEventType>(DataEventType.ChangeModule) .Sample(TimeSpan.FromMilliseconds(100)) .Subscribe(_ => RefreshModuleItem()); UlEventSystem.GetTriggerSubject <UIEventType>(UIEventType.RefreshModuleItem) .Subscribe(_ => RefreshModuleItem()); StartObserveSwapImage(); }
public static bool CreateModuleBehavior(string moduleName, List <Element> elements = null, bool selectModule = true, bool needCheckCache = false) { if (string.IsNullOrWhiteSpace(moduleName)) { return(false); } if (GlobalData.ModuleDic.ContainsKey(moduleName)) { return(false); } // 还原 module 时尝试取回删除时保存的数据 if (needCheckCache && elements == null) { GlobalData.CacheModuleDic.TryGetValue(moduleName, out elements); } if (elements == null) { elements = new List <Element>(); } GlobalData.ModuleDic[moduleName] = elements; GlobalData.Modules.Add(moduleName); if (selectModule) { UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(moduleName)); } UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo); UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem); return(true); }
public static void UpdateSelectDisplayObjectDicBehavior(string moduleName, List <string> addElements = null, List <string> removeElements = null) { if (string.IsNullOrWhiteSpace(moduleName) || !moduleName.Equals(GlobalData.CurrentModule)) { return; } if (addElements?.Count > 0) { foreach (string elementName in addElements) { GlobalData.CurrentSelectDisplayObjectDic[elementName] = GlobalData.CurrentDisplayObjectDic[elementName]; } } if (removeElements?.Count > 0) { foreach (string elementName in removeElements) { GlobalData.CurrentSelectDisplayObjectDic.Remove(elementName); } } UlEventSystem.Dispatch <DataEventType, SelectedChangeData>(DataEventType.SelectedChange, new SelectedChangeData(moduleName, addElements, removeElements)); // MessageBroker.SendUpdateSelectDisplayObjectDic(addElements, removeElements); }
public static Behavior GetUpdateSwapImageBehavior(string moduleName, string elementName, bool isSwap) { return(new Behavior(isReDo => UlEventSystem.Dispatch <UIEventType, SwapImageEventData>(UIEventType.SwapImage, new SwapImageEventData(moduleName, elementName, isSwap)), isReUndo => UlEventSystem.Dispatch <UIEventType, SwapImageEventData>(UIEventType.SwapImage, new SwapImageEventData(moduleName, elementName, !isSwap)), BehaviorType.UpdateSwapImage)); }
public static bool RemoveModuleBehavior(string moduleName, string targetModule = null) { if (string.IsNullOrWhiteSpace(moduleName)) { return(false); } if (!GlobalData.ModuleDic.ContainsKey(moduleName)) { return(false); } // 删除时将数据保存起来, 避免还原时没有数据 GlobalData.CacheModuleDic[moduleName] = GlobalData.ModuleDic[moduleName]; GlobalData.Modules.Remove(moduleName); GlobalData.ModuleDic.Remove(moduleName); if (moduleName.Equals(GlobalData.CurrentModule)) { UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(targetModule)); } UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo); UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem); return(true); }
public static Behavior GetRemoveSelectedDisplayObjectBehavior(string moduleName) { List <Element> elements = GlobalData.CurrentSelectDisplayObjectDic.Select(pair => GlobalData.GetElement(pair.Key)).ToList(); int length = elements.Count; List <string> elementNames = new List <string>(); for (int idx = 0; idx < length; ++idx) { elementNames.Add(elements[idx].Name); } return(new Behavior(isReDo => DisplayObjectUtil.RemoveDisplayObjectsBehavior(moduleName, elementNames), isReUndo => { DisplayObjectUtil.AddDisplayObjectsBehavior(moduleName, elements); foreach (string elementName in elementNames) { Transform displayObject = GlobalData.CurrentDisplayObjectDic[elementName]; GlobalData.CurrentSelectDisplayObjectDic.Add(elementName, displayObject); } UlEventSystem.Dispatch <DataEventType, SelectedChangeData>(DataEventType.SelectedChange, new SelectedChangeData(moduleName, elementNames)); // MessageBroker.SendUpdateSelectDisplayObjectDic(elementNames); }, BehaviorType.RemoveSelectedDisplayObject)); }
public static void OpenModule(string moduleName) { UlEventSystem.Dispatch <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule, new ChangeModuleEventData(moduleName)); UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo); UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem); }