// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected override void OnSceneGUI() { base.OnSceneGUI(); serializedObject.Update(); exUIButton curEdit = target as exUIButton; if (curEdit.font) { if (curEdit.font.text != textProp.stringValue) { curEdit.font.text = textProp.stringValue; EditorUtility.SetDirty(curEdit.font); HandleUtility.Repaint(); } } if (curEdit.background) { if (curEdit.background.anchor != curEdit.anchor) { curEdit.background.anchor = curEdit.anchor; EditorUtility.SetDirty(curEdit.background); HandleUtility.Repaint(); } } serializedObject.ApplyModifiedProperties(); }
/////////////////////////////////////////////////////////////////////////////// // Button /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ static void CreateButtonObject(bool _useSprite) { // create button object GameObject buttonGO = new GameObject("Button"); exUIButton button = buttonGO.AddComponent <exUIButton>(); // create Background if (_useSprite) { GameObject backgroundGO = new GameObject("Background"); exSprite background = backgroundGO.AddComponent <exSprite>(); button.background = background; backgroundGO.transform.parent = buttonGO.transform; } else { GameObject backgroundGO = new GameObject("Background"); exSpriteBorder background = backgroundGO.AddComponent <exSpriteBorder>(); button.background = background; backgroundGO.transform.parent = buttonGO.transform; } // create Font GameObject fontGO = new GameObject("Font"); exSpriteFont font = fontGO.AddComponent <exSpriteFont>(); font.text = ""; button.font = font; fontGO.transform.parent = buttonGO.transform; button.width = 50.0f; button.height = 20.0f; // Selection.activeObject = buttonGO; }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void HoverOut() { exUIButton button = GetComponent <exUIButton>(); button.font.topColor = Color.black; }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void HoverIn() { exUIButton button = GetComponent <exUIButton>(); button.font.topColor = Color.blue; }
/////////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ protected new void Awake() { base.Awake(); // handle scroll bar Transform transBar = transform.Find("__bar"); if (transBar) { bar = transBar.GetComponent <exSprite>(); if (bar) { bar.customSize = true; bar.anchor = Anchor.TopLeft; } // exUIButton btnBar = transBar.GetComponent <exUIButton>(); if (btnBar) { btnBar.grabMouseOrTouch = true; btnBar.AddEventListener("onPressDown", delegate(exUIEvent _event) { if (dragging) { return; } exUIPointEvent pointEvent = _event as exUIPointEvent; if (pointEvent.isTouch || pointEvent.GetMouseButton(0)) { dragging = true; draggingID = pointEvent.mainPoint.id; exUIMng.inst.SetFocus(this); } }); btnBar.AddEventListener("onPressUp", delegate(exUIEvent _event) { exUIPointEvent pointEvent = _event as exUIPointEvent; if ((pointEvent.isTouch || pointEvent.GetMouseButton(0)) && pointEvent.pointInfos[0].id == draggingID) { if (dragging) { dragging = false; draggingID = -1; } } }); btnBar.AddEventListener("onHoverMove", delegate(exUIEvent _event) { if (scrollView) { exUIPointEvent pointEvent = _event as exUIPointEvent; for (int i = 0; i < pointEvent.pointInfos.Length; ++i) { exUIPointInfo point = pointEvent.pointInfos[i]; if (dragging && (pointEvent.isTouch || pointEvent.GetMouseButton(0)) && point.id == draggingID) { Vector2 delta = point.worldDelta; delta.y = -delta.y; scrollView.Scroll(delta / ratio); } } } }); } } // handle background background = GetComponent <exSprite>(); if (background) { scrollStart = transBar ? transBar.localPosition : Vector3.zero; if (background.spriteType == exSpriteType.Sliced) { if (direction == Direction.Horizontal) { scrollStart.x = background.leftBorderSize; } else { scrollStart.y = background.topBorderSize; } } } // handle scroll view if (scrollView) { scrollView.AddEventListener("onContentResized", delegate(exUIEvent _event) { UpdateScrollBarRatio(); UpdateScrollBar(); }); scrollView.AddEventListener("onScroll", delegate(exUIEvent _event) { if (direction == Direction.Horizontal) { scrollOffset = scrollView.scrollOffset.x * ratio; } else { scrollOffset = scrollView.scrollOffset.y * ratio; } UpdateScrollBar(); // if (scrollView.showCondition == exUIScrollView.ShowCondition.WhenDragging) { activeSelf = true; } }); scrollView.AddEventListener("onScrollFinished", delegate(exUIEvent _event) { if (scrollView.showCondition == exUIScrollView.ShowCondition.WhenDragging) { cooldownTimer = cooldown; isCoolingDown = true; } }); UpdateScrollBarRatio(); UpdateScrollBar(); // handle scrollbar effect if (scrollView.showCondition == exUIScrollView.ShowCondition.WhenDragging) { // exUIEffect effect = GetComponent <exUIEffect>(); if (effect == null) { effect = gameObject.AddComponent <exUIEffect>(); if (background != null) { effect.AddEffect_Color(background, EffectEventType.Deactive, exEase.Type.Linear, new Color(background.color.r, background.color.g, background.color.b, 0.0f), 0.5f); } if (bar != null) { effect.AddEffect_Color(bar, EffectEventType.Deactive, exEase.Type.Linear, new Color(bar.color.r, bar.color.g, bar.color.b, 0.0f), 0.5f); } } // if (background) { Color tmpColor = background.color; tmpColor.a = 0.0f; background.color = tmpColor; } // if (bar) { Color tmpColor = bar.color; tmpColor.a = 0.0f; bar.color = tmpColor; } // active_ = false; } } }