// =================================================================================== // UNITY METHODS --------------------------------------------------------------------- void Update() { if (_requiresDataRefresh) { RefreshData(); } if (_Buttons.Count == 0) { return; } bool isMouseDown = Input.GetMouseButtonDown(0); bool isMousePressed = Input.GetMouseButton(0); bool isMouseUp = Input.GetMouseButtonUp(0); MouseState mouseState = isMouseDown ? MouseState.JustPressed : isMousePressed ? MouseState.Pressed : isMouseUp ? MouseState.Released : MouseState.Up; if (rolloversEnabled || isMouseDown || isMouseUp) { List <HOtk2dButton> hitButtons = GetOverButtons(Input.mousePosition); int len = _Buttons.Count - 1; for (int i = len; i > -1; --i) { if (i > _Buttons.Count - 1) { continue; } HOtk2dButton button = _Buttons[i]; button.Refresh(hitButtons.IndexOf(button) != -1, mouseState, isMousePressed); } } }
public void SetFocus(ContentGroup focusContentGroup, int focusRowId, int focusColumnId) { if (rolloverEffects && uiElement != null) { uiElement.SimulateRollOut(); } contentGroup = focusContentGroup; rowId = focusRowId; columnId = focusColumnId; uiElement = contentGroup.uiElements[focusRowId][focusColumnId]; if (rolloverEffects) { uiElement.SimulateRollOver(); } if (_evidenceSprite != null) { // Set evidence sprite Vector3 evidencePos = uiElement.bounds.center; evidencePos.z -= 1; _evidenceSprite.transform.position = evidencePos; Vector2 size = uiElement.bounds.size; size.x += evidenceBorder * 2; size.y += evidenceBorder * 2; _evidenceSprite.dimensions = size; _evidenceSprite.gameObject.SetActive(true); if (_evidenceTween != null) { _evidenceTween.Restart(); } } }
static void DispatchEvent(HOtk2dButton button, HOTk2dButtonDelegate e, HOTk2dButtonDelegate eManager, HOtk2dButtonEventType type) { if (e != null) { e(new HOtk2dButtonEvent(type, button)); } eManager(new HOtk2dButtonEvent(type, button)); }
static internal void RemoveButton(HOtk2dButton button) { int ind = _Buttons.IndexOf(button); if (ind == -1) { return; } _Buttons.RemoveAt(ind); _ButtonsByTrans.Remove(button.trans); _requiresDataRefresh = true; }
// =================================================================================== // METHODS --------------------------------------------------------------------------- static internal void AddButton(HOtk2dButton button) { int ind = _Buttons.IndexOf(button); if (ind != -1) { return; } _Buttons.Add(button); _ButtonsByTrans.Add(button.trans, button); _requiresDataRefresh = true; }
public void Clear() { if (_evidenceSprite != null) { _evidenceSprite.gameObject.SetActive(false); if (_evidenceTween != null) { _evidenceTween.Pause(); } } if (rolloverEffects && uiElement != null) { uiElement.SimulateRollOut(); } rowId = columnId = -1; contentGroup = null; uiElement = null; }
// =================================================================================== // METHODS --------------------------------------------------------------------------- static void DoActivate(Transform parent, bool setFocus, string focusElementName, bool forceRefresh, bool addAsNewGroup) { forceRefresh = forceRefresh || focusElementName != null || !addAsNewGroup && _ContentGroups.Count > 1; if (_ContentGroups.ContainsContentGroupParent(parent) && !forceRefresh) { return; } if (!addAsNewGroup) { DeactivateAll(); } HOtk2dButton[] buttons = parent.GetComponentsInChildren <HOtk2dButton>(); if (buttons.Length == 0) { return; } // Sort content by Y List <HOtk2dButton> contentByY = new List <HOtk2dButton>(); foreach (HOtk2dButton bt in buttons) { if (bt.enabled && bt.id != IgnoreId) { contentByY.Add(bt); } } if (contentByY.Count == 0) { return; } // contentByY.Sort((a, b) => { if (a.trans.position.y < b.trans.position.y) { return(1); } if (a.trans.position.y > b.trans.position.y) { return(-1); } return(0); }); // Fill uiElements List <List <HOtk2dButton> > uiElements = new List <List <HOtk2dButton> >(); HOtk2dButton prevBt = null; foreach (HOtk2dButton bt in contentByY) { if (prevBt == null || !Mathf.Approximately(bt.trans.position.y, prevBt.trans.position.y)) { // New row uiElements.Add(new List <HOtk2dButton>()); } uiElements[uiElements.Count - 1].Add(bt); prevBt = bt; } // Sort uiElements columns by X foreach (List <HOtk2dButton> row in uiElements) { row.Sort((a, b) => { if (a.trans.position.x > b.trans.position.x) { return(1); } if (a.trans.position.x < b.trans.position.x) { return(-1); } return(0); }); } // Create contentGroup _ContentGroups.Add(new ContentGroup(parent, uiElements)); // Focus if (setFocus) { if (focusElementName != null) { FocusByName(focusElementName); } else { _FocusManager.SetFocus(_ContentGroups[_ContentGroups.Count - 1], 0, 0); } } active = true; }
static internal void RemoveButton(HOtk2dButton button) { int ind = _Buttons.IndexOf(button); if (ind == -1) return; _Buttons.RemoveAt(ind); _ButtonsByTrans.Remove(button.trans); _requiresDataRefresh = true; }
// =================================================================================== // METHODS --------------------------------------------------------------------------- static internal void AddButton(HOtk2dButton button) { int ind = _Buttons.IndexOf(button); if (ind != -1) return; _Buttons.Add(button); _ButtonsByTrans.Add(button.trans, button); _requiresDataRefresh = true; }
public void Clear() { if (_evidenceSprite != null) { _evidenceSprite.gameObject.SetActive(false); if (_evidenceTween != null) _evidenceTween.Pause(); } if (rolloverEffects && uiElement != null) uiElement.SimulateRollOut(); rowId = columnId = -1; contentGroup = null; uiElement = null; }
public void SetFocus(ContentGroup focusContentGroup, int focusRowId, int focusColumnId) { if (rolloverEffects && uiElement != null) uiElement.SimulateRollOut(); contentGroup = focusContentGroup; rowId = focusRowId; columnId = focusColumnId; uiElement = contentGroup.uiElements[focusRowId][focusColumnId]; if (rolloverEffects) uiElement.SimulateRollOver(); if (_evidenceSprite != null) { // Set evidence sprite Vector3 evidencePos = uiElement.bounds.center; evidencePos.z -= 1; _evidenceSprite.transform.position = evidencePos; Vector2 size = uiElement.bounds.size; size.x += evidenceBorder * 2; size.y += evidenceBorder * 2; _evidenceSprite.dimensions = size; _evidenceSprite.gameObject.SetActive(true); if (_evidenceTween != null) _evidenceTween.Restart(); } }
static void DispatchEvent(HOtk2dButton button, HOTk2dButtonDelegate e, HOTk2dButtonDelegate eManager, HOtk2dButtonEventType type) { if (e != null) e(new HOtk2dButtonEvent(type, button)); eManager(new HOtk2dButtonEvent(type, button)); }