예제 #1
0
        public override Vector2 OnFlowDrawNodeCurveOffset(UnityEngine.UI.Windows.AttachItem attachItem, FD.FlowWindow window, FD.FlowWindow toWindow, bool doubleSide)
        {
            var offset = Vector2.zero;

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(offset);
            }

            Vector2 dotOffset = new Vector2(5f, 0f);

            var flag = window.IsABTest();

            if (flag == true)
            {
                this.Validate(window);

                for (int i = 0; i < window.abTests.Count(); ++i)
                {
                    var abTest = window.abTests.items[i];
                    if (abTest.attachItem.targetId == attachItem.targetId && abTest.attachItem.index == attachItem.index)
                    {
                        var editorRect = abTest.editorRect;
                        var delta      = editorRect.center - window.rect.size * 0.5f + dotOffset;

                        offset = delta;
                    }
                }
            }

            return(offset);
        }
        public override void OnFlowWindowTransition(int index, FD.FlowWindow fromWindow, FD.FlowWindow toWindow, bool doubleSided, Vector2 centerOffset)
        {
            var factor = 0.5f;

            if (fromWindow.IsSmall() == true &&
                fromWindow.IsABTest() == true)
            {
                factor = 0.2f;
            }

            var point = Vector2.Lerp(fromWindow.rect.center, toWindow.rect.center, factor) + centerOffset;
            var rect  = new Rect(point, Vector2.zero);

            if (this.flowEditor.ContainsRect(rect) == false)
            {
                return;
            }

            if (doubleSided == true)
            {
                var q = Quaternion.LookRotation(toWindow.rect.center - fromWindow.rect.center, Vector3.back);

                this.DrawBubble(rect, index, fromWindow.id, toWindow.id, q * Vector2.left);

                this.DrawBubble(rect, index, toWindow.id, fromWindow.id, q * Vector2.right);
            }
            else
            {
                this.DrawBubble(rect, index, fromWindow.id, toWindow.id, Vector2.zero);
            }
        }
예제 #3
0
        public override string OnCompilerTransitionAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo, bool everyPlatformHasUniqueName)
        {
            if (windowTo.IsABTest() == true &&
                windowTo.IsSmall() == true)
            {
                return(FlowABTestingTemplateGenerator.GenerateTransitionMethod(this.flowEditor, windowFrom, windowTo));
            }

            return(base.OnCompilerTransitionAttachedGeneration(windowFrom, windowTo, everyPlatformHasUniqueName));
        }
예제 #4
0
        public override void OnFlowWindowGUI(FD.FlowWindow window)
        {
            var data = FlowSystem.GetData();

            if (data == null)
            {
                return;
            }

            var flag = window.IsABTest();

            if (flag == true)
            {
                this.Validate(window);

                var windowSize = window.rect;
                var repaint    = false;

                var connectorActive        = ME.Utilities.CacheStyle("UI.Windows.ABTesting", "flow shader out 2");
                var connectorInactive      = ME.Utilities.CacheStyle("UI.Windows.ABTesting", "flow shader out 5");
                var connectorOuterActive   = ME.Utilities.CacheStyle("UI.Windows.ABTesting", "flow shader in 2");
                var connectorOuterInactive = ME.Utilities.CacheStyle("UI.Windows.ABTesting", "flow shader in 5");
                var editButtonStyle        = ME.Utilities.CacheStyle("UI.Windows.ABTesting.EditButton", "LargeButtonRight", (name) => {
                    var _style          = new GUIStyle(name);
                    _style.fixedWidth   = 0f;
                    _style.stretchWidth = true;

                    return(_style);
                });
                var addButtonStyle = ME.Utilities.CacheStyle("UI.Windows.ABTesting.AddButtonStyle", "MiniButton", (name) => {
                    var _style          = new GUIStyle(name);
                    _style.fixedWidth   = 0f;
                    _style.stretchWidth = false;

                    return(_style);
                });
                var removeButtonStyle = ME.Utilities.CacheStyle("UI.Windows.ABTesting.RemoveButtonStyle", "LargeButtonLeft", (name) => {
                    var _style          = new GUIStyle(name);
                    _style.fixedWidth   = 0f;
                    _style.stretchWidth = false;

                    return(_style);
                });

                var buttonHeight = editButtonStyle.fixedHeight;

                var height = 0f;

                const float topOffset            = 5f;
                const float margin               = 2f;
                const float marginHorizontalLeft = 2f;
                const float bottomOffset         = 2f;

                Color oldColor;
                Color c;

                GUILayout.Space(topOffset);

                System.Action <int, ABTestingItem> onItem = (i, item) => {
                    var hasAttach           = (data.AlreadyAttached(window.id, item.attachItem.index, item.attachItem.targetId) == true);
                    var connectorStyle      = hasAttach ? connectorActive : connectorInactive;
                    var connectorOuterStyle = hasAttach ? connectorOuterActive : connectorOuterInactive;

                    var size          = Mathf.Max(connectorStyle.fixedHeight, buttonHeight);
                    var connectorSize = new Vector2(size, size);

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(marginHorizontalLeft);

                        var canEdit   = (i > 0);
                        var canRemove = canEdit && (window.abTests.Count() > 2);

                        oldColor  = GUI.color;
                        c         = (canRemove == true) ? Color.red : Color.grey;
                        GUI.color = c;
                        EditorGUI.BeginDisabledGroup(!canRemove);
                        {
                            if (GUILayout.Button("X", removeButtonStyle) == true)
                            {
                                window.abTests.RemoveAt(i);
                                EditorUtility.SetDirty(window);
                                repaint = true;
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        GUI.color = oldColor;

                        EditorGUI.BeginDisabledGroup(!canEdit);
                        {
                            if (GUILayout.Button(canEdit == true ? "Edit Condition" : "On Any Other", editButtonStyle) == true)
                            {
                                this.flowEditor.SetDisabled();
                                this.selectedItem = window.abTests.items[i];
                                this.opened       = true;
                            }
                        }
                        EditorGUI.EndDisabledGroup();

                        GUILayout.Space(connectorSize.x);
                    }
                    GUILayout.EndHorizontal();

                    var rect = GUILayoutUtility.GetLastRect();

                    rect.x    = window.rect.width - connectorSize.x;
                    rect.y   += 3f;
                    rect.size = connectorSize;
                    rect      = rect.PixelPerfect();

                    if (Event.current.type == EventType.Repaint)
                    {
                        window.abTests.items[i].editorRect = rect;
                    }

                    if (GUI.Button(rect, string.Empty, connectorStyle) == true)
                    {
                        var index = i;
                        this.flowEditor.WaitForAttach(window.id, index: i + 1, onAttach: (withId, attachIndex, isAttach) => {
                            window.abTests.Attach(index, withId, attachIndex);
                        });
                    }

                    rect.x += connectorSize.x - 3f;
                    rect    = rect.PixelPerfect();
                    if (GUI.Button(rect, string.Empty, connectorOuterStyle) == true)
                    {
                        var index = i;
                        this.flowEditor.WaitForAttach(window.id, index: i + 1, onAttach: (withId, attachIndex, isAttach) => {
                            window.abTests.Attach(index, withId, attachIndex);
                        });
                    }

                    var comment = item.comment;
                    if (string.IsNullOrEmpty(comment) == false)
                    {
                        GUILayout.Label(comment.Trim(), EditorStyles.helpBox);
                    }

                    GUILayout.Space(margin);
                };

                for (int i = 1; i < window.abTests.Count(); ++i)
                {
                    onItem(i, window.abTests.items[i]);
                }

                oldColor  = GUI.color;
                c         = Color.green;
                GUI.color = c;
                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("+ Add", addButtonStyle) == true)
                    {
                        window.abTests.AddNew();
                        EditorUtility.SetDirty(window);
                        repaint = true;
                    }

                    GUILayout.FlexibleSpace();
                }
                GUILayout.EndHorizontal();
                GUI.color = oldColor;

                onItem(0, window.abTests.items[0]);

                if (Event.current.type == EventType.Repaint)
                {
                    var lastRect = GUILayoutUtility.GetLastRect();
                    height += lastRect.y;
                    height += lastRect.height;
                    height += bottomOffset;

                    windowSize.height = height;

                    if (windowSize != window.rect)
                    {
                        window.rect = windowSize.PixelPerfect();
                        EditorUtility.SetDirty(window);
                    }
                }

                if (repaint == true)
                {
                    this.flowEditor.Repaint();
                }
            }
        }
예제 #5
0
 public override bool IsCompilerTransitionAttachedGeneration(FD.FlowWindow windowFrom, FD.FlowWindow windowTo)
 {
     return(windowTo.IsABTest() == true);
 }
예제 #6
0
        public static string GenerateTransitionMethod(FlowSystemEditorWindow flowEditor, FD.FlowWindow windowFrom, FD.FlowWindow windowTo)
        {
            var file = UnityEngine.Resources.Load("UI.Windows/ABTesting/Templates/TemplateTransitionMethod") as TextAsset;

            if (file == null)
            {
                if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                {
                    UnityEngine.Debug.LogError("ABTesting Template Loading Error: Could not load template 'TemplateTransitionMethod'");
                }

                return(string.Empty);
            }

            var data = FlowSystem.GetData();

            if (data == null)
            {
                return(string.Empty);
            }

            if (windowTo.IsABTest() == false)
            {
                return(string.Empty);
            }

            var result = string.Empty;
            var part   = file.text;

            var methodPatternDefault = "(item, h, wh) => WindowSystemFlow.DoFlow<{0}>(this, item, h, wh, false, null)";
            var methods    = string.Empty;
            var methodList = new List <string>();

            foreach (var item in windowTo.abTests.items)
            {
                var window = FlowSystem.GetWindow(item.attachItem.targetId);

                if (window.IsFunction() == true)
                {
                    var winFunc = FlowSystem.GetWindow(window.functionId);
                    if (winFunc != null)
                    {
                        window = FlowSystem.GetWindow(winFunc.functionRootId);
                    }
                    else
                    {
                        window = null;
                    }
                }

                if (window == null)
                {
                    methodList.Add("null");
                }
                else
                {
                    var classNameWithNamespace = Tpl.GetClassNameWithNamespace(window);
                    methodList.Add(string.Format(methodPatternDefault, classNameWithNamespace));
                }
            }

            methods = string.Join(", ", methodList.ToArray());

            result +=
                part.Replace("{METHOD_NAMES}", methods)
                .Replace("{FLOW_FROM_ID}", windowFrom.id.ToString())
                .Replace("{FLOW_TO_ID}", windowTo.id.ToString());

            return(result);
        }