public void StartOnGUI(SGUIRoot root) { if (CurrentRoot != null) { throw new InvalidOperationException("StartOnGUI already called! Call EndOnGUI first!"); } CurrentRoot = root; _Reason = Event.current; if (IsOnGUIRepainting) { if (_GlobalComponentSemaphore == 0) { _ComponentElements.Clear(); } _Elements.Clear(); _OPs.Clear(); _OPComponentIDs.Clear(); _OPElementIDs.Clear(); _OPComponents.Clear(); _OPBounds.Clear(); _OPData.Clear(); } // Console.WriteLine("SGUI-IM: Starting new render with following reason: " + _Reason); }
public void Awake() { Main = this; Children.ListChanged += HandleChange; Foreground = new Color(1f, 1f, 1f, 1f); Background = new Color(0f, 0f, 0f, 0.85f); TextFieldBackground = new Texture2D[] { White, White, White, White }; }
public void Update() { if (!Visible) { return; } Main = this; if (!Backend.Initialized) { return; } for (int i = 0; i < Children.Count; i++) { SElement child = Children[i]; child.Root = this; child.Parent = null; if (child.Enabled) { child.Update(); } } if (AdoptedChildren.Count != 0) { for (int i = 0; i < AdoptedChildren.Count; i++) { SElement child = AdoptedChildren[i]; if (child.Parent == null && !Children.Contains(child)) { // Child had no memory who its parents were, so let's just adopt it. Children.Add(child); } else if (child.Parent != null && !child.Parent.Children.Contains(child)) { // Child remembers about its parents, but parents not about child. Let's force parents to care. child.Parent.Children.Add(child); } } AdoptedChildren.Clear(); } if (DisposingChildren.Count != 0 && !Backend.RenderOnGUI) { for (int i = 0; i < DisposingChildren.Count; i++) { DisposingChildren[i].Dispose(); } DisposingChildren.Clear(); } }
public void EndOnGUI(SGUIRoot root) { if (CurrentRoot == null) { throw new InvalidOperationException("EndOnGUI already called! Call StartOnGUI first!"); } // Console.WriteLine("SGUI-IM: Ending render with " + _GlobalComponentSemaphore + " components, of which " + _ComponentSemaphore + " are local."); _GlobalComponentSemaphore -= _ComponentSemaphore; _ComponentSemaphore = 0; CurrentRoot = null; }
public void Start() { Main = this; if (!Backend.RenderOnGUI) { Backend.Init(); } else { _ScheduledBackendInit = true; } }
public void OnGUI() { SGUIRoot root = CurrentRoot; if (_Reason.isMouse || _Reason.type == EventType.ScrollWheel) { LastMouseEventConsumed = HandleMouseEvent(Event.current) != -1; return; } // Your normal rendering run. for (int i = 0; i < root.Children.Count; i++) { SElement child = root.Children[i]; child.Root = root; child.Parent = null; if (!child.Visible) { continue; } child.Render(); } // After the normal (possibly) repaint run, check for any mouse movement. if (IsOnGUIRepainting) { Vector2 mousePosition = Input.mousePosition; mousePosition = new Vector2( mousePosition.x, root.Size.y - mousePosition.y - 1f ); if (_LastMousePosition.x <= -1f && _LastMousePosition.y <= -1f) { _LastMousePosition = mousePosition; } else { HandleMouseEvent(new Event(Event.current.displayIndex) { type = EventType.MouseMove, mousePosition = mousePosition, delta = mousePosition - _LastMousePosition }); _LastMousePosition = mousePosition; } } }
public void UpdateStyle() { if (Backend.UpdateStyleOnGUI && Backend.CurrentRoot == null) { _ScheduledUpdateStyle = true; return; } Main = this; for (int i = 0; i < Children.Count; i++) { SElement child = Children[i]; child.Root = this; child.Parent = null; if (child.Enabled) { child.UpdateStyle(); } } }
public void OnGUI() { if (!Visible) { return; } Main = this; if (!Backend.RenderOnGUI) { return; } if (_ScheduledBackendInit) { _ScheduledBackendInit = false; Backend.Init(); } CheckForResize(); Backend.StartOnGUI(this); if (_ScheduledUpdateStyle) { _ScheduledUpdateStyle = false; UpdateStyle(); } Backend.OnGUI(); if (DisposingChildren.Count != 0) { for (int i = 0; i < DisposingChildren.Count; i++) { DisposingChildren[i].Dispose(); } DisposingChildren.Clear(); } Backend.EndOnGUI(this); }
public void StartOnGUI(SGUIRoot root) { if (CurrentRoot != null) { throw new InvalidOperationException("StartOnGUI already called! Call EndOnGUI first!"); } CurrentRoot = root; _Reason = Event.current; _OldSkin = GUI.skin; GUI.skin = Skin; Skin.textField.normal.background = CurrentRoot.TextFieldBackground[0]; Skin.textField.active.background = CurrentRoot.TextFieldBackground[1]; Skin.textField.hover.background = CurrentRoot.TextFieldBackground[2]; Skin.textField.focused.background = CurrentRoot.TextFieldBackground[3]; Skin.settings.selectionColor = new Color(0.3f, 0.6f, 0.9f, 1f); GUI.depth = Depth; if (IsOnGUIRepainting) { if (_GlobalComponentSemaphore == 0) { _ComponentElements.Clear(); } _Elements.Clear(); _OPs.Clear(); _OPComponentIDs.Clear(); _OPElementIDs.Clear(); _OPComponents.Clear(); _OPBounds.Clear(); _OPData.Clear(); } // Console.WriteLine("SGUI-IM: Starting new render with following reason: " + _Reason); }
public static SGUIRoot SetupEditor() { return(Main = new SGUIRoot(true)); }
public static SGUIRoot Setup() { return(Main = new GameObject("SGUI Root").AddComponent <SGUIRootBehaviour>().Root); }
public static void Setup() { Main = new GameObject("WTFGUI Root").AddComponent <SGUIRoot>(); Main.Backend = new SGUIIMBackend(); }