public void Validate() { if (this.tabs == null || this.tabs.Count == 0) { this.tabs.Add(new GeneralTab()); this.tabs.Add(new UserTab()); this.tabs.Add(new PlayerPrefsTab()); this.activeTabIndex = 0; } for (int i = 0; i < this.tabs.Count; ++i) { this.tabs[i].selectedItem = this.selectedItem; } }
public override void OnGUI() { if (ABTesting.styles == null) { ABTesting.styles = new Styles(); } if (this.opened == true) { var data = FlowSystem.GetData(); if (data == null) { return; } const float closeSize = 50f; var screenRect = new Rect(0f, 0f, Screen.width, Screen.height); var settingsSize = new Vector2(350f, 500f); var settingsRect = new Rect(screenRect.width * 0.5f - settingsSize.x * 0.5f, screenRect.height * 0.5f - settingsSize.y * 0.5f, settingsSize.x, settingsSize.y).PixelPerfect(); var settingsBackRect = new Rect(settingsRect.x - MARGIN, settingsRect.y - MARGIN, settingsRect.width + MARGIN * 2f, settingsRect.height + MARGIN * 2f).PixelPerfect(); var rectCloseButton = new Rect(settingsRect.x + settingsRect.width, settingsRect.y - closeSize * 0.5f, closeSize, closeSize).PixelPerfect(); GUI.Box(screenRect, string.Empty, ABTesting.styles.backLock); GUI.Box(settingsBackRect, string.Empty, ABTesting.styles.dropShadow); GUI.Box(settingsBackRect, string.Empty, ABTesting.styles.contentScreen); GUI.Box(settingsRect, string.Empty, ABTesting.styles.layoutBack); GUILayout.BeginArea(settingsRect.PixelPerfect()); this.tabs.selectedItem = this.selectedItem; this.tabs.OnGUI(); GUILayout.EndArea(); if (GUI.Button(rectCloseButton, string.Empty, ABTesting.styles.closeButton) == true) { this.flowEditor.SetEnabled(); this.opened = false; } } }
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(); } } }
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(); } } }
public override void OnGUI() { if (ABTesting.styles == null) ABTesting.styles = new Styles(); if (this.opened == true) { var data = FlowSystem.GetData(); if (data == null) return; const float closeSize = 50f; var screenRect = new Rect(0f, 0f, Screen.width, Screen.height); var settingsSize = new Vector2(350f, 500f); var settingsRect = new Rect(screenRect.width * 0.5f - settingsSize.x * 0.5f, screenRect.height * 0.5f - settingsSize.y * 0.5f, settingsSize.x, settingsSize.y).PixelPerfect(); var settingsBackRect = new Rect(settingsRect.x - MARGIN, settingsRect.y - MARGIN, settingsRect.width + MARGIN * 2f, settingsRect.height + MARGIN * 2f).PixelPerfect(); var rectCloseButton = new Rect(settingsRect.x + settingsRect.width, settingsRect.y - closeSize * 0.5f, closeSize, closeSize).PixelPerfect(); GUI.Box(screenRect, string.Empty, ABTesting.styles.backLock); GUI.Box(settingsBackRect, string.Empty, ABTesting.styles.dropShadow); GUI.Box(settingsBackRect, string.Empty, ABTesting.styles.contentScreen); GUI.Box(settingsRect, string.Empty, ABTesting.styles.layoutBack); GUILayout.BeginArea(settingsRect.PixelPerfect()); this.tabs.selectedItem = this.selectedItem; this.tabs.OnGUI(); GUILayout.EndArea(); if (GUI.Button(rectCloseButton, string.Empty, ABTesting.styles.closeButton) == true) { this.flowEditor.SetEnabled(); this.opened = false; } } }