Пример #1
0
    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();
    }
Пример #2
0
    private void Start()
    {
        UlEventSystem.GetSubject <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule)
        .Subscribe(eventData => {
            if (eventData == null)
            {
                return;
            }
            string module = eventData.Module;
            if (string.IsNullOrWhiteSpace(module))
            {
                module = null;
            }
            if (GlobalData.CurrentModule == module)
            {
                return;
            }
            List <string> removeElements = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            if (removeElements != null)
            {
                HistoryManager.Do(BehaviorFactory.GetUpdateSelectDisplayObjectBehavior(GlobalData.CurrentModule,
                                                                                       null,
                                                                                       removeElements,
                                                                                       CombineType.Previous));
            }
            GlobalData.CurrentModule = module;
            DisplayObjectUtil.RemoveAllDisplayObjectBehavior();
            DisplayObjectUtil.AddAllDisplayObjectBehavior();
            UlEventSystem.DispatchTrigger <DataEventType>(DataEventType.CurrentModuleNameChanged);
            GetComponent <RectTransform>().localPosition = Vector2.zero;
            scaleSlider.value = 10f;
        });
        UlEventSystem.GetTriggerSubject <DataEventType>(DataEventType.CurrentModuleNameChanged)
        .Subscribe(_ => {
            UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateModuleTxtWidth);
            moduleNameText.text = string.IsNullOrWhiteSpace(GlobalData.CurrentModule) ? "null" : GlobalData.CurrentModule;
        });
        UlEventSystem.GetSubject <UIEventType, TriggerEventData>(UIEventType.UpdateModuleTxtWidth)
        .SampleFrame(1)
        .DelayFrame(0)
        .Subscribe(_ => {
            RectTransform rt     = moduleNameText.GetComponent <RectTransform>();
            RectTransform rt2    = selectedDisplayObjectText.GetComponent <RectTransform>();
            rt2.anchoredPosition = new Vector2(rt.anchoredPosition.x + rt.sizeDelta.x + 30, rt2.anchoredPosition.y);
        });
        UlEventSystem.GetSubject <DataEventType, SelectedChangeData>(DataEventType.SelectedChange)
        .Subscribe(eventData => {
            if (eventData == null ||
                string.IsNullOrWhiteSpace(eventData.ModuleName) ||
                !eventData.ModuleName.Equals(GlobalData.CurrentModule))
            {
                return;
            }
            if (eventData.RemoveElements != null)
            {
                foreach (Transform displayObject in eventData.RemoveElements
                         .Select(elementName => {
                    GlobalData.CurrentDisplayObjectDic.TryGetValue(elementName, out Transform displayObject);
                    return(displayObject);
                })
                         .Where(displayObject => displayObject))
                {
                    displayObject.GetComponent <FrameManager>().IsSelect = false;
                }
            }

            if (eventData.AddElements != null)
            {
                foreach (Transform displayObject in eventData.AddElements
                         .Select(elementName => GlobalData.CurrentDisplayObjectDic[elementName])
                         .Where(displayObject => displayObject))
                {
                    displayObject.GetComponent <FrameManager>().IsSelect = true;
                }
            }

            if (GlobalData.CurrentSelectDisplayObjectDic.Count < 1)
            {
                selectedDisplayObjectText.text = "null";
                return;
            }

            StringBuilder sb = new StringBuilder();
            foreach (var pair in GlobalData.CurrentSelectDisplayObjectDic)
            {
                sb.Append($"{pair.Value.name}, ");
                pair.Value.GetComponent <FrameManager>().IsSelect = true;
            }

            selectedDisplayObjectText.text = sb.ToString(0, sb.Length - 2);
        });
        GlobalData.GlobalObservable.ObserveEveryValueChanged(_ => GlobalData.ModifyDic)
        .SampleFrame(1)
        .Subscribe(modifyCount => UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle));
        GlobalData.GlobalObservable.ObserveEveryValueChanged(_ => GlobalData.CurrentFilePath)
        .SampleFrame(1)
        .Subscribe(_ => UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle));
        UlEventSystem.GetSubject <UIEventType, TriggerEventData>(UIEventType.UpdateTitle)
        .SampleFrame(1)
        .Subscribe(_ => {
            string title = GlobalData.ProductName;
            if (!string.IsNullOrWhiteSpace(GlobalData.CurrentFilePath))
            {
                title = GlobalData.CurrentFilePath;
            }
            Utils.ChangeTitle(GlobalData.ModifyCount != 0 ? $"* {title}" : title);
        });
    }
Пример #3
0
    private void Start()
    {
        // EventSystem.current.SetSelectedGameObject(NameInputField.gameObject);
        UlEventSystem.GetSubject <DataEventType, ChangeModuleEventData>(DataEventType.ChangeModule)
        .Subscribe(_ => ChangeModule = true);
        nameInputField.ObserveEveryValueChanged(element => element.isFocused)
        .Where(isFocus => !string.IsNullOrWhiteSpace(GlobalData.CurrentModule)
               // && _displayObject
               && !isFocus &&
               !string.IsNullOrWhiteSpace(nameInputField.text))
        .Subscribe(_ => {
            string newName = nameInputField.text.Trim();
            if (_displayObject == null)
            {
                if (newName.Equals(GlobalData.CurrentModule))
                {
                    return;
                }
                print($"35: {Time.frameCount}");
                if (!ChangeModule && GlobalData.ModuleDic.ContainsKey(newName))
                {
                    DialogManager.ShowError("该 Module 名称已存在", 0, 0);
                    nameInputField.text = GlobalData.CurrentModule;
                    return;
                }

                ChangeModule = false;
                HistoryManager.Do(BehaviorFactory.GetChangeModuleNameBehavior(GlobalData.CurrentModule, newName));
                return;
            }
            string originName = _displayObject.name;
            if (newName.Equals(originName))
            {
                return;
            }
            if (GlobalData.CurrentDisplayObjectDic.ContainsKey(newName))
            {
                DialogManager.ShowError("该名称已存在", 0, 0);
                nameInputField.text = originName;
                return;
            }
            HistoryManager.Do(BehaviorFactory.GetChangeNameBehavior(GlobalData.CurrentModule, originName, newName));
        });
        xInputField.ObserveEveryValueChanged(element => element.isFocused)
        .Where(isFocused => !isFocused && !string.IsNullOrEmpty(xInputField.text))
        .Select(_ => (float)xInputField.text.Calculate())
        .Where(x => !float.IsNaN(x))
        .Subscribe(x => {
            int length = GlobalData.CurrentSelectDisplayObjectDic.Count;
            if (_displayObject && length == 1)
            {
                Element element = GlobalData.GetElement(_displayObject.name);
                if (element == null || Utils.IsEqual(element.X, x))
                {
                    return;
                }
                HistoryManager.Do(BehaviorFactory.GetChangeXBehavior(GlobalData.CurrentModule, new List <string> {
                    element.Name
                }, element.X, x));
                return;
            }

            if (Utils.IsEqual(x, 0.0f) || length < 2)
            {
                return;
            }
            List <string> elementNames = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            HistoryManager.Do(BehaviorFactory.GetChangeXBehavior(GlobalData.CurrentModule, elementNames, -x, x, true));
            xInputField.text = "0";
        });

        yInputField.ObserveEveryValueChanged(element => element.isFocused)
        .Where(isFocused => !isFocused && !string.IsNullOrEmpty(yInputField.text))
        .Select(_ => (float)yInputField.text.Calculate())
        .Where(y => !float.IsNaN(y))
        .Subscribe(y => {
            int length = GlobalData.CurrentSelectDisplayObjectDic.Count;
            if (_displayObject && length == 1)
            {
                Element element = GlobalData.GetElement(_displayObject.name);
                if (element == null || Utils.IsEqual(element.Y, y))
                {
                    return;
                }
                HistoryManager.Do(BehaviorFactory.GetChangeYBehavior(GlobalData.CurrentModule, new List <string> {
                    element.Name
                }, element.Y, y));
                return;
            }

            if (Utils.IsEqual(y, 0.0f) || length < 2)
            {
                return;
            }
            List <string> elementNames = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            HistoryManager.Do(BehaviorFactory.GetChangeYBehavior(GlobalData.CurrentModule, elementNames, y, -y, true));
            yInputField.text = "0";
        });

        widthInputField.ObserveEveryValueChanged(element => element.isFocused)
        .Where(isFocused => !isFocused && !string.IsNullOrEmpty(widthInputField.text))
        .Select(_ => (float)widthInputField.text.Calculate())
        .Where(width => !float.IsNaN(width))
        .Subscribe(width => {
            int length = GlobalData.CurrentSelectDisplayObjectDic.Count;
            if (_displayObject && length == 1)
            {
                Element element = GlobalData.GetElement(_displayObject.name);
                if (element == null || Utils.IsEqual(element.Width, width))
                {
                    return;
                }
                HistoryManager.Do(BehaviorFactory.GetChangeWidthBehavior(GlobalData.CurrentModule,
                                                                         new List <string> {
                    element.Name
                },
                                                                         element.Width,
                                                                         width));
                return;
            }

            if (Utils.IsEqual(width, 0.0f) || length < 2)
            {
                return;
            }
            List <string> elementNames = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            HistoryManager.Do(BehaviorFactory.GetChangeWidthBehavior(GlobalData.CurrentModule, elementNames, -width, width, true));
            widthInputField.text = "0";
        });
        heightInputField.ObserveEveryValueChanged(element => element.isFocused)
        .Where(isFocused => !isFocused && !string.IsNullOrEmpty(heightInputField.text))
        .Select(_ => (float)heightInputField.text.Calculate())
        .Where(height => !float.IsNaN(height))
        .Subscribe(height => {
            int length = GlobalData.CurrentSelectDisplayObjectDic.Count;
            if (_displayObject && length == 1)
            {
                Element element = GlobalData.GetElement(_displayObject.name);
                if (element == null || Utils.IsEqual(element.Height, height))
                {
                    return;
                }
                HistoryManager.Do(BehaviorFactory.GetChangeHeightBehavior(GlobalData.CurrentModule,
                                                                          new List <string> {
                    element.Name
                },
                                                                          element.Height,
                                                                          height));
                return;
            }

            if (Utils.IsEqual(height, 0.0f) || length < 2)
            {
                return;
            }
            List <string> elementNames = GlobalData.CurrentSelectDisplayObjectDic.KeyList();
            HistoryManager.Do(BehaviorFactory.GetChangeHeightBehavior(GlobalData.CurrentModule, elementNames, -height, height, true));
            heightInputField.text = "0";
        });
        Observable.EveryUpdate()
        .Where(_ => EventSystem.current.currentSelectedGameObject != null && (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return)))
        .Subscribe(_ => {
            GameObject go = EventSystem.current.currentSelectedGameObject;

            bool isShiftDown = KeyboardEventManager.GetShift();
            if ((isShiftDown && go == yInputField.gameObject) || (!isShiftDown && go == nameInputField.gameObject))
            {
                EventSystem.current.SetSelectedGameObject(xInputField.gameObject);
            }
            else if ((isShiftDown && go == widthInputField.gameObject) || (!isShiftDown && go == xInputField.gameObject))
            {
                EventSystem.current.SetSelectedGameObject(yInputField.gameObject);
            }
            else if ((isShiftDown && go == heightInputField.gameObject) || (!isShiftDown && go == yInputField.gameObject))
            {
                EventSystem.current.SetSelectedGameObject(widthInputField.gameObject);
            }
            else if ((isShiftDown && go == nameInputField.gameObject) || (!isShiftDown && go == widthInputField.gameObject))
            {
                EventSystem.current.SetSelectedGameObject(heightInputField.gameObject);
            }
            else if ((isShiftDown && go == xInputField.gameObject) || (!isShiftDown && go == heightInputField.gameObject))
            {
                EventSystem.current.SetSelectedGameObject(nameInputField.gameObject);
            }
        });
        UlEventSystem.GetSubject <DataEventType, SelectedChangeData>(DataEventType.SelectedChange)
        .SampleFrame(1)
        .Subscribe(_ => {
            Transform displayObject = GlobalData.CurrentSelectDisplayObjectDic.OnlyValue();
            UpdateState(displayObject);
        });
        UlEventSystem.GetTriggerSubject <UIEventType>(UIEventType.UpdateInspectorInfo)
        .SampleFrame(1)
        .Subscribe(_ => UpdateState(_displayObject));
    }