Пример #1
0
    public static void ChangeModuleName(string moduleName, string newModuleName)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !moduleName.Equals(GlobalData.CurrentModule))
        {
            return;
        }
        // 正常确保了可以修改才调用该方法
        if (GlobalData.ModuleDic.ContainsKey(newModuleName))
        {
            return;
        }
        int idx = GlobalData.Modules.FindIndex(module => module.Equals(moduleName));

        if (idx == -1)
        {
            return;
        }
        GlobalData.CurrentModule = newModuleName;
        GlobalData.Modules[idx]  = newModuleName;
        List <Element> elements = GlobalData.ModuleDic[moduleName];

        GlobalData.ModuleDic.Remove(moduleName);
        GlobalData.ModuleDic[newModuleName] = elements;
        UlEventSystem.DispatchTrigger <DataEventType>(DataEventType.CurrentModuleNameChanged);
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.RefreshModuleItem);
    }
Пример #2
0
    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);
    }
Пример #3
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();
    }
Пример #4
0
 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);
 }
Пример #5
0
 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));
 }
Пример #6
0
 public static void Do(bool justAdd = false)
 {
     while (UnDoneBehaviors.Count > 0)
     {
         Behavior behavior = UnDoneBehaviors.Pop();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             Debug.Log($"[WARN] [HistoryManager] Do() - behavior: {behavior}, behavior.Type: {behavior?.Type}");
             break;
         }
         Debug.Log($"[INFO] [HistoryManager] {(behavior.IsDone ? "ReDo" : "Do")}() - behavior: {behavior}, behavior.Type: {behavior.Type}, behavior.CombineType: {behavior.CombineType}");
         string key = $"{behavior.Type}_{behavior.CreateFrameCount}";
         if (GlobalData.ModifyDic.ContainsKey(key) && GlobalData.ModifyDic[key])
         {
             Debug.Log($"[WARN] [HistoryManager] {(behavior.IsDone ? "ReDo" : "Do")}() - key: {key}, behavior.Type: {behavior.Type}");
         }
         GlobalData.ModifyDic[key] = behavior.IsModify;
         if (behavior.IsModify)
         {
             UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle);
         }
         if (!justAdd)
         {
             try {
                 behavior.Do(behavior.IsDone);
             } catch (Exception e) {
                 Debug.Log(e);
                 throw;
             }
         }
         behavior.IsDone = true;
         Behaviors.Push(behavior);
         if (behavior.CombineType == CombineType.Next)
         {
             continue;
         }
         if (UnDoneBehaviors.Count == 0)
         {
             break;
         }
         behavior = UnDoneBehaviors.Peek();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             break;
         }
         if (behavior.CombineType == CombineType.Previous)
         {
             continue;
         }
         break;
     }
 }
Пример #7
0
 public static void Undo()
 {
     while (Behaviors.Count > 0)
     {
         Behavior behavior = Behaviors.Pop();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             Debug.Log($"[WARN] [HistoryManager] Undo() - behavior: {behavior}, behavior.Type: {behavior?.Type}");
             break;
         }
         Debug.Log($"[INFO] [HistoryManager] {(behavior.IsUndone ? "ReUndo" : "Undo")}() - behavior: {behavior}, behavior.Type: {behavior.Type}");
         string key = $"{behavior.Type}_{behavior.CreateFrameCount}";
         if (!GlobalData.ModifyDic.ContainsKey(key))
         {
             Debug.Log($"[ERROR] [HistoryManager] {(behavior.IsUndone ? "ReUndo" : "Undo")}() - key: {key}, behavior.Type: {behavior.Type}");
             return;
         }
         behavior.Undo(behavior.IsUndone);
         if (GlobalData.ModifyDic[key])
         {
             UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateTitle);
         }
         GlobalData.ModifyDic[key] = false;
         behavior.IsUndone         = true;
         UnDoneBehaviors.Push(behavior);
         if (behavior.CombineType == CombineType.Previous)
         {
             continue;
         }
         if (Behaviors.Count == 0)
         {
             break;
         }
         behavior = Behaviors.Peek();
         if (behavior == null || behavior.Type == BehaviorType.Null)
         {
             break;
         }
         if (behavior.CombineType == CombineType.Next)
         {
             continue;
         }
         break;
     }
 }
Пример #8
0
    public static void ChangeHeightBehavior(string moduleName, List <string> elementNames, float height, bool isAdd = false)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !GlobalData.CurrentModule.Equals(moduleName))
        {
            return;
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return;
        }
        int length = elementNames.Count;

        for (int idx = 0; idx < length; ++idx)
        {
            ChangeHeightBehavior(elementNames[idx], height, isAdd);
        }
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
    }
Пример #9
0
    private static void StartObserveSwapImage()
    {
        Subject <SwapImageEventData> subject = UlEventSystem.TryToGetSubject <UIEventType, SwapImageEventData>(UIEventType.SwapImage);

        if (subject != null)
        {
            return;
        }
        UlEventSystem.GetSubject <UIEventType, SwapImageEventData>(UIEventType.SwapImage)
        .Subscribe(eventData => {
            if (eventData == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(eventData.ModuleName) || !eventData.ModuleName.Equals(GlobalData.CurrentModule))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(eventData.ElementName))
            {
                return;
            }
            Transform displayObject = GlobalData.CurrentDisplayObjectDic[eventData.ElementName];
            if (displayObject)
            {
                displayObject.gameObject.SetActive(!eventData.IsSwap);
            }
            Transform item = GetDisplayObjectItem(eventData.ModuleName, eventData.ElementName);
            if (item)
            {
                SwapImageManager sim = item.GetComponentInChildren <SwapImageManager>();
                if (sim)
                {
                    sim.UpdateSwapImage(eventData.IsSwap);
                }
            }
            Element element = GlobalData.GetElement(eventData.ElementName);
            if (element != null)
            {
                element.Visible = !eventData.IsSwap;
            }
        });
    }
Пример #10
0
 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);
 }
Пример #11
0
    public static void UpdateDisplayObjectsPosition(string moduleName, IReadOnlyList <string> elementNames, Vector2 targetPos)
    {
        if (string.IsNullOrWhiteSpace(GlobalData.CurrentModule) || !GlobalData.CurrentModule.Equals(moduleName))
        {
            return;
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return;
        }
        Transform baseDisplayObject = GlobalData.CurrentDisplayObjectDic[elementNames[0]];

        if (baseDisplayObject == null)
        {
            return;
        }
        RectTransform baseRect = baseDisplayObject.GetComponent <RectTransform>();

        if (baseRect == null)
        {
            return;
        }
        Vector2 offset = targetPos - baseRect.anchoredPosition;

        UpdateElementPosition(baseRect, elementNames[0], targetPos);
        int count = elementNames.Count;

        for (int idx = 1; idx < count; ++idx)
        {
            Transform displayObject = GlobalData.CurrentDisplayObjectDic[elementNames[idx]];
            if (displayObject == null)
            {
                continue;
            }
            RectTransform rt = displayObject.GetComponent <RectTransform>();
            UpdateElementPosition(rt, elementNames[idx], rt.anchoredPosition + offset);
        }
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
    }
Пример #12
0
    public static void MoveDisplayObjectsUpBehavior(string moduleName, List <string> elementNames)
    {
        if (string.IsNullOrWhiteSpace(moduleName) || !moduleName.Equals(GlobalData.CurrentModule))
        {
            return;
        }
        if (elementNames == null || elementNames.Count == 0)
        {
            return;
        }
        List <Transform> displayObjects = GlobalData.CurrentDisplayObjects;
        List <int>       elementIdxList = elementNames.Select(elementName => displayObjects.FindIndex(element => elementName.Equals(element.name)))
                                          .Where(idx => idx != -1)
                                          .ToList();

        if (elementIdxList.Count == 0)
        {
            return;
        }
        List <Element> elements = GlobalData.ModuleDic[moduleName];
        int            count    = elementIdxList.Count;

        elementIdxList.Sort();
        for (int idx = 0; idx < count; ++idx)
        {
            int       elementIdx = elementIdxList[idx];
            Transform tmp        = displayObjects[elementIdx];
            displayObjects[elementIdx]     = displayObjects[elementIdx - 1];
            displayObjects[elementIdx - 1] = tmp;
            Element tmpElement = elements[elementIdx];
            elements[elementIdx]     = elements[elementIdx - 1];
            elements[elementIdx - 1] = tmpElement;
            int siblingIndex = displayObjects[elementIdx].GetSiblingIndex();
            tmp.SetSiblingIndex(siblingIndex);
        }

        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateHierarchy);
    }
Пример #13
0
    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));
    }
Пример #14
0
 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);
 }
Пример #15
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);
        });
    }
Пример #16
0
    public void OnDrag(PointerEventData eventData)
    {
        if (Input.GetMouseButton(2))
        {
            return;
        }
        if (_selfElement == null)
        {
            _selfElement = GlobalData.GetElement(transform.name);
        }
        Vector2 pos    = Utils.GetAnchoredPositionInContainer(Input.mousePosition) - _offset;
        Vector2 offset = pos - selfRect.anchoredPosition;

        DisplayObjectUtil.UpdateElementPosition(selfRect, _selfElement, pos);
        UlEventSystem.DispatchTrigger <UIEventType>(UIEventType.UpdateInspectorInfo);
        _alignInfo = DisplayObjectUtil.GetAlignLine(_selfElement, _alignInfo);
        if (_alignInfo?.HorizontalAlignLine != null)
        {
            Rectangle horizontalAlignRect = _alignInfo.HorizontalAlignLine;
            print($"_alignInfo.HorizontalAlignType: {_alignInfo.HorizontalAlignType}, isCenter: {_alignInfo.HorizontalAlignType == AlignType.HorizontalCenter}");
            _horizontalAlignLineManager.gameObject.SetActive(true);
            _horizontalAlignLineManager.transform.SetAsLastSibling();
            AlignType leftType  = _alignInfo.HorizontalAlignType;
            AlignType rightType = _alignInfo.OtherHorizontalAlignType;
            if (Math.Abs(_alignInfo.HorizontalAlignLine.Right - _selfElement.Right) < Math.Abs(_alignInfo.HorizontalAlignLine.Left - _selfElement.Left))
            {
                leftType  = _alignInfo.OtherHorizontalAlignType;
                rightType = _alignInfo.HorizontalAlignType;
            }
            _horizontalAlignLineManager.UpdateHorizontal(leftType,
                                                         rightType,
                                                         Element.InvConvertTo(new Vector2(horizontalAlignRect.X - GlobalData.AlignExtensionValue, horizontalAlignRect.Y)),
                                                         new Vector2(horizontalAlignRect.Width + (GlobalData.AlignExtensionValue << 1), horizontalAlignRect.Height));
        }
        else
        {
            _horizontalAlignLineManager.gameObject.SetActive(false);
        }

        if (_alignInfo?.VerticalAlignLine != null)
        {
            Rectangle verticalAlignRect = _alignInfo.VerticalAlignLine;
            print($"_alignInfo.VerticalAlignType: {_alignInfo.VerticalAlignType}, isCenter: {_alignInfo.VerticalAlignType == AlignType.VerticalCenter}");
            _verticalAlignLineManager.gameObject.SetActive(true);
            _verticalAlignLineManager.transform.SetAsLastSibling();
            AlignType upType   = _alignInfo.VerticalAlignType;
            AlignType downType = _alignInfo.OtherVerticalAlignType;
            if (Math.Abs(_alignInfo.VerticalAlignLine.Top - _selfElement.Top) < Math.Abs(_alignInfo.VerticalAlignLine.Bottom - _selfElement.Bottom))
            {
                upType   = _alignInfo.OtherVerticalAlignType;
                downType = _alignInfo.VerticalAlignType;
            }
            _verticalAlignLineManager.UpdateVertical(upType,
                                                     downType,
                                                     Element.InvConvertTo(new Vector2(verticalAlignRect.X, verticalAlignRect.Y - GlobalData.AlignExtensionValue)),
                                                     new Vector2(verticalAlignRect.Width, verticalAlignRect.Height + (GlobalData.AlignExtensionValue << 1)));
        }
        else
        {
            _verticalAlignLineManager.gameObject.SetActive(false);
        }

        if (GlobalData.CurrentSelectDisplayObjectDic.Count == 1)
        {
            return;
        }
        foreach (var pair in GlobalData.CurrentSelectDisplayObjectDic)
        {
            if (pair.Value == transform)
            {
                continue;
            }
            RectTransform rt = pair.Value.GetComponent <RectTransform>();
            DisplayObjectUtil.UpdateElementPosition(rt, pair.Key, rt.anchoredPosition + offset);
        }
    }
Пример #17
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));
    }