public InputTextField() { gameObject.name = "InputTextField"; onFocusIn = new EventListener(this, "onFocusIn"); onFocusOut = new EventListener(this, "onFocusOut"); onChanged = new EventListener(this, "onChanged"); maxLength = int.MaxValue; editable = true; /* 因为InputTextField定义了ClipRect,而ClipRect是四周缩进了2个像素的(GUTTER),默认的点击测试 * 是使用ClipRect的,那会造成无法点击四周的空白区域。所以这里自定义了一个HitArea */ this.hitArea = new RectHitTest(); this.touchChildren = false; _touchMoveDelegate = __touchMove; onFocusIn.Add(__focusIn); onFocusOut.AddCapture(__focusOut); onKeyDown.AddCapture(__keydown); onTouchBegin.AddCapture(__touchBegin); onTouchEnd.AddCapture(__touchEnd); }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void Add(EventCallback1 callback) { if (_bridge == null) _bridge = this.owner.GetEventBridge(_type); _bridge.Add(callback); }
public GSlider() { _value = 50; _max = 100; onChanged = new EventListener(this, "onChanged"); onGripTouchEnd = new EventListener(this, "onGripTouchEnd"); _touchMoveDelegate = __gripTouchMove; }
public void AddCapture(EventCallback1 callback) { _captureCallback -= callback; _captureCallback += callback; if (!_regsiter) { _regsiter = true; this.owner.RegisterListener(this); } }
public GButton AddItem(string caption, EventCallback1 callback) { GButton item = _list.AddItemFromPool().asButton; item.title = caption; item.data = callback; item.menuItemGrayed = false; Controller c = item.GetController("checked"); if (c != null) c.selectedIndex = 0; return item; }
public HtmlButton() { if (resource != null) { button = UIPackage.CreateObjectFromURL(resource).asCom; _clickHandler = (EventContext context) => { _owner.DispatchEvent(CLICK_EVENT, context.data, this); }; } else Debug.LogWarning("FairyGUI: Set HtmlButton.resource first"); }
public void AddEventListener(string strType, EventCallback1 callback) { if (strType == null) throw new Exception("event type cant be null"); if (_dic == null) _dic = new Dictionary<string, EventListener>(); EventListener listener = null; if (!_dic.TryGetValue(strType, out listener)) listener = new EventListener(this, strType); listener.Add(callback); }
/// <summary> /// /// </summary> /// <param name="strType"></param> /// <param name="callback"></param> public void AddEventListener(string strType, EventCallback1 callback) { if (strType == null) throw new Exception("event type cant be null"); if (_dic == null) _dic = new Dictionary<string, EventBridge>(); EventBridge bridge = null; if (!_dic.TryGetValue(strType, out bridge)) { bridge = new EventBridge(this); _dic[strType] = bridge; } bridge.Add(callback); }
public HtmlLink() { shape = new Shape(); _clickHandler = (EventContext context) => { _owner.onClickLink.Call(_element.GetString("href")); }; _rolloverHandler = (EventContext context) => { context.CaptureTouch(); if (_owner.htmlParseOptions.linkHoverBgColor.a > 0) shape.graphics.Tint(_owner.htmlParseOptions.linkHoverBgColor); }; _rolloutHandler = () => { if (_owner.htmlParseOptions.linkBgColor.a > 0) shape.graphics.Tint(_owner.htmlParseOptions.linkBgColor); }; }
public HtmlLink() { _shape = new SelectionShape(); _shape.gameObject.name = "HtmlLink"; _clickHandler = (EventContext context) => { _owner.onClickLink.BubbleCall(_element.GetString("href")); }; _rolloverHandler = (EventContext context) => { context.CaptureTouch(); if (_owner.htmlParseOptions.linkHoverBgColor.a > 0) _shape.color = _owner.htmlParseOptions.linkHoverBgColor; }; _rolloutHandler = () => { if (_owner.htmlParseOptions.linkHoverBgColor.a > 0) _shape.color = _owner.htmlParseOptions.linkBgColor; }; }
public void OnTouchEnd(EventCallback1 func) { _obj.onTouchEnd.Add(func); }
public void SetFocusOut(EventCallback1 func) { _obj.asTextInput.onFocusOut.Set(func); }
public void RemoveEventListener(string strType, EventCallback1 callback) { if (_dic == null) return; EventListener listener = null; if (_dic.TryGetValue(strType, out listener)) listener.Remove(callback); }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void Remove(EventCallback1 callback) { _bridge.Remove(callback); }
public void SetChanged(EventCallback1 func) { _obj.asTextInput.onChanged.Set(func); }
public void Remove1(EventCallback1 callback) { _callback1 -= callback; }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void AddCapture(EventCallback1 callback) { _bridge.AddCapture(callback); }
public GScrollBar() { _scrollPerc = 0; _touchMoveDelegate = __stageTouchMove; }
public void RemoveCapture(EventCallback1 callback) { _captureCallback -= callback; }
public void OnTouchMove(EventCallback1 func) { _obj.onTouchMove.Add(func); }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void Set(EventCallback1 callback) { if (_bridge == null) _bridge = this.owner.GetEventBridge(_type); _bridge.Clear(); if (callback != null) _bridge.Add(callback); }
// //---------- 触摸 ----------- public void OnTouchBegin(EventCallback1 func) { _obj.onTouchBegin.Add(func); }
public void OnClickLink(EventCallback1 func) { _obj.onClickLink.Add(func); }
public void RemoveClick(EventCallback1 func) { _obj.onClick.Remove(func); }
public void AddClick(EventCallback1 func) { _obj.onClick.Add(func); }
public void OnClick(EventCallback1 func) { _obj.onClick.Set(func); }
public void OnChanged(EventCallback1 func) { _obj.asButton.onChanged.Add(func); }
//---------- 拖拽 ----------- public void OnDragStart(EventCallback1 func) { _obj.onDragStart.Set(func); }
public void AddCapture(EventCallback1 callback) { _captureCallback -= callback; _captureCallback += callback; }
public void OnDragMove(EventCallback1 func) { _obj.onDragMove.Add(func); }
public void Add1(EventCallback1 callback) { _callback1 -= callback; _callback1 += callback; }
public void OnDragEnd(EventCallback1 func) { _obj.onDragEnd.Add(func); }
//---------- enter - exit ----------- public void OnAddedToStage(EventCallback1 func) { _obj.onAddedToStage.Add(func); }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void Add(EventCallback1 callback) { _bridge.Add(callback); }
public void OnRemovedFromStage(EventCallback1 func) { _obj.onRemovedFromStage.Add(func); }
public void AddBt(string caption, EventCallback1 callback) { base.AddItemWithUrl("ui://BlueSkin/Button_choise_w", caption, callback); }
//---------- 改变事件 ----------- public void OnSizeChanged(EventCallback1 func) { _obj.onSizeChanged.Add(func); }
/// <summary> /// /// </summary> public Stage() : base() { _inst = this; soundVolume = 1; _updateContext = new UpdateContext(); stageWidth = Screen.width; stageHeight = Screen.height; _frameGotHitTarget = -1; if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor) { touchScreen = false; } else { touchScreen = Input.touchSupported; } _touches = new TouchInfo[5]; for (int i = 0; i < _touches.Length; i++) { _touches[i] = new TouchInfo(); } if (!touchScreen) { _touches[0].touchId = 0; } _rollOutChain = new List <DisplayObject>(); _rollOverChain = new List <DisplayObject>(); onStageResized = new EventListener(this, "onStageResized"); onTouchMove = new EventListener(this, "onTouchMove"); StageEngine engine = GameObject.FindObjectOfType <StageEngine>(); if (engine != null) { this.gameObject = engine.gameObject; } else { int layer = LayerMask.NameToLayer(StageCamera.LayerName); this.gameObject = new GameObject("Stage"); this.gameObject.hideFlags = HideFlags.None; this.gameObject.layer = layer; this.gameObject.AddComponent <StageEngine>(); this.gameObject.AddComponent <UIContentScaler>(); } this.cachedTransform = gameObject.transform; this.cachedTransform.localScale = new Vector3(StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel); this.gameObject.SetActive(true); UnityEngine.Object.DontDestroyOnLoad(this.gameObject); EnableSound(); if (touchScreen) { #if !(UNITY_WEBPLAYER || UNITY_WEBGL || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR) _keyboard = new FairyGUI.TouchScreenKeyboard(); keyboardInput = true; #endif } Timers.inst.Add(5, 0, RunTextureCollector); #if UNITY_5_4_OR_NEWER SceneManager.sceneLoaded += SceneManager_sceneLoaded; #endif _focusRemovedDelegate = OnFocusRemoved; }
public void OnPositionChanged(EventCallback1 func) { _obj.onPositionChanged.Add(func); }
/// <summary> /// /// </summary> /// <param name="strType"></param> /// <param name="callback"></param> public void RemoveEventListener(string strType, EventCallback1 callback) { if (_dic == null) return; EventBridge bridge = null; if (_dic.TryGetValue(strType, out bridge)) bridge.Remove(callback); }
public void Clear() { _callback1 = null; _callback0 = null; _captureCallback = null; }
/// <summary> /// /// </summary> /// <param name="caption"></param> /// <param name="index"></param> /// <param name="callback"></param> /// <returns></returns> public GButton AddItemAt(string caption, int index, EventCallback1 callback) { GObject obj = _list.GetFromPool(_list.defaultItem); _list.AddChildAt(obj, index); GButton item = (GButton)obj; item.title = caption; item.data = callback; item.grayed = false; Controller c = item.GetController("checked"); if (c != null) c.selectedIndex = 0; return item; }
/// <summary> /// /// </summary> /// <param name="callback"></param> public void RemoveCapture(EventCallback1 callback) { if (_bridge == null) _bridge = this.owner.GetEventBridge(_type); _bridge.RemoveCapture(callback); }
public void OnChanged(EventCallback1 func) { _obj.asSlider.onChanged.Add(func); }
public void Remove(EventCallback1 callback) { _callback1 -= callback; }
protected void SetEventListener(string objname, EventListenerType listenerType, EventCallback1 callback) { GButton button = FindChildren <GButton>(objname); if (button == null) { return; } switch (listenerType) { case EventListenerType.onClick: button.onClick.Add(callback); break; case EventListenerType.onRightClick: button.onRightClick.Add(callback); break; case EventListenerType.onTouchBegin: button.onTouchBegin.Add(callback); break; case EventListenerType.onTouchMove: button.onTouchMove.Add(callback); break; case EventListenerType.onTouchEnd: button.onTouchEnd.Add(callback); break; case EventListenerType.onRollOver: button.onRollOver.Add(callback); break; case EventListenerType.onRollOut: button.onRollOut.Add(callback); break; case EventListenerType.onAddedToStage: button.onAddedToStage.Add(callback); break; case EventListenerType.onRemovedFromStage: button.onRemovedFromStage.Add(callback); break; case EventListenerType.onKeyDown: button.onKeyDown.Add(callback); break; case EventListenerType.onClickLink: button.onClickLink.Add(callback); break; case EventListenerType.onPositionChanged: button.onPositionChanged.Add(callback); break; case EventListenerType.onSizeChanged: button.onSizeChanged.Add(callback); break; case EventListenerType.onDragStart: button.onDragStart.Add(callback); break; case EventListenerType.onDragMove: button.onDragMove.Add(callback); break; case EventListenerType.onDragEnd: button.onDragEnd.Add(callback); break; case EventListenerType.OnGearStop: button.OnGearStop.Add(callback); break; default: button.onClick.Add(callback); break; } }
public void Add(EventCallback1 callback) { _callback1 -= callback; _callback1 += callback; }
public ScrollPane(GComponent owner, ScrollType scrollType, Margin scrollBarMargin, ScrollBarDisplayType scrollBarDisplay, int flags, string vtScrollBarRes, string hzScrollBarRes) { onScroll = new EventListener(this, "onScroll"); onScrollEnd = new EventListener(this, "onScrollEnd"); _refreshDelegate = Refresh; _touchEndDelegate = __touchEnd; _touchMoveDelegate = __touchMove; _throwTween = new ThrowTween(); _owner = owner; _container = _owner.rootContainer; _maskHolder = new Container(); _container.AddChild(_maskHolder); _maskContentHolder = _owner.container; _maskContentHolder.x = 0; _maskContentHolder.y = 0; _maskHolder.AddChild(_maskContentHolder); _scrollBarMargin = scrollBarMargin; _scrollType = scrollType; _scrollSpeed = UIConfig.defaultScrollSpeed; _mouseWheelSpeed = _scrollSpeed * 2; _softnessOnTopOrLeftSide = UIConfig.allowSoftnessOnTopOrLeftSide; _displayOnLeft = (flags & 1) != 0; _snapToItem = (flags & 2) != 0; _displayInDemand = (flags & 4) != 0; _pageMode = (flags & 8) != 0; if ((flags & 16) != 0) _touchEffect = true; else if ((flags & 32) != 0) _touchEffect = false; else _touchEffect = UIConfig.defaultScrollTouchEffect; if ((flags & 64) != 0) _bouncebackEffect = true; else if ((flags & 128) != 0) _bouncebackEffect = false; else _bouncebackEffect = UIConfig.defaultScrollBounceEffect; _inertiaDisabled = (flags & 256) != 0; _scrollBarVisible = true; _mouseWheelEnabled = true; _holdAreaPoint = new Vector2(); _pageSize = Vector2.one; if (scrollBarDisplay == ScrollBarDisplayType.Default) { if (Application.isMobilePlatform) scrollBarDisplay = ScrollBarDisplayType.Auto; else scrollBarDisplay = UIConfig.defaultScrollBarDisplay; } if (scrollBarDisplay != ScrollBarDisplayType.Hidden) { if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical) { string res = string.IsNullOrEmpty(vtScrollBarRes) ? UIConfig.verticalScrollBar : vtScrollBarRes; if (!string.IsNullOrEmpty(res)) { _vtScrollBar = UIPackage.CreateObjectFromURL(res) as GScrollBar; if (_vtScrollBar == null) Debug.LogWarning("FairyGUI: cannot create scrollbar from " + res); else { _vtScrollBar.SetScrollPane(this, true); _container.AddChild(_vtScrollBar.displayObject); } } } if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal) { string res = string.IsNullOrEmpty(hzScrollBarRes) ? UIConfig.horizontalScrollBar : hzScrollBarRes; if (!string.IsNullOrEmpty(res)) { _hzScrollBar = UIPackage.CreateObjectFromURL(res) as GScrollBar; if (_hzScrollBar == null) Debug.LogWarning("FairyGUI: cannot create scrollbar from " + res); else { _hzScrollBar.SetScrollPane(this, false); _container.AddChild(_hzScrollBar.displayObject); } } } _scrollBarDisplayAuto = scrollBarDisplay == ScrollBarDisplayType.Auto; if (_scrollBarDisplayAuto) { if (_vtScrollBar != null) _vtScrollBar.displayObject.visible = false; if (_hzScrollBar != null) _hzScrollBar.displayObject.visible = false; _scrollBarVisible = false; _container.onRollOver.Add(__rollOver); _container.onRollOut.Add(__rollOut); } } else _mouseWheelEnabled = false; SetSize(owner.width, owner.height); _container.onMouseWheel.Add(__mouseWheel); _container.onTouchBegin.Add(__touchBegin); }
public TextField() { _optimizeNotTouchable = true; _textFormat = new TextFormat(); _textFormat.size = 12; _textFormat.lineSpacing = 3; _strokeColor = new Color(0, 0, 0, 1); _wordWrap = true; _displayAsPassword = false; _maxLength = int.MaxValue; _text = string.Empty; _elements = new List<HtmlElement>(1); _lines = new List<LineInfo>(1); CreateGameObject("TextField"); graphics = new NGraphics(gameObject); onFocusIn = new EventListener(this, "onFocusIn"); onFocusOut = new EventListener(this, "onFocusOut"); onChanged = new EventListener(this, "onChanged"); _touchMoveDelegate = __touchMove; _onChangedDelegate = OnChanged; }
/// <summary> /// /// </summary> public Stage() : base() { _inst = this; soundVolume = 1; _updateContext = new UpdateContext(); stageWidth = Screen.width; stageHeight = Screen.height; _frameGotHitTarget = -1; if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor) touchScreen = false; else touchScreen = Input.touchSupported; _touches = new TouchInfo[5]; for (int i = 0; i < _touches.Length; i++) _touches[i] = new TouchInfo(); if (!touchScreen) _touches[0].touchId = 0; _rollOutChain = new List<DisplayObject>(); _rollOverChain = new List<DisplayObject>(); onStageResized = new EventListener(this, "onStageResized"); onTouchMove = new EventListener(this, "onTouchMove"); StageEngine engine = GameObject.FindObjectOfType<StageEngine>(); if (engine != null) Object.Destroy(engine.gameObject); this.gameObject.name = "Stage"; this.gameObject.layer = LayerMask.NameToLayer(StageCamera.LayerName); this.gameObject.AddComponent<StageEngine>(); this.gameObject.AddComponent<UIContentScaler>(); this.gameObject.SetActive(true); Object.DontDestroyOnLoad(this.gameObject); this.cachedTransform.localScale = new Vector3(StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel); EnableSound(); if (touchScreen) { #if !(UNITY_WEBPLAYER || UNITY_WEBGL || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR) _keyboard = new FairyGUI.TouchScreenKeyboard(); keyboardInput = true; #endif } Timers.inst.Add(5, 0, RunTextureCollector); #if UNITY_5_4_OR_NEWER SceneManager.sceneLoaded += SceneManager_sceneLoaded; #endif _focusRemovedDelegate = OnFocusRemoved; }