private void ExtendTabCollider(UIButton tabButton) { UIWidget w = tabButton.GetComponent <UIWidget>(); w.autoResizeBoxCollider = false; NGUITools.AddWidgetCollider(tabButton.gameObject); BoxCollider2D collider = tabButton.GetComponent <BoxCollider2D>(); Vector2 offset = collider.offset; offset.y += 15; Vector2 size = collider.size; size.y += 40; size.x += 8; collider.size = size; collider.offset = offset; EditorUtil.SetDirty(tabButton.gameObject); }
private void SetupSymbol() { Monster monster = (Monster)MyController; UISprite uisprite = (UISprite)MyUIWidget; if (monster.StaticData.Grade >= EMonsterGrade.CHAMPION) { uisprite.spriteName = m_SpriteBoss; m_TooltipLocaKey = m_TooltipLocaKeyBoss; } else { uisprite.spriteName = m_SpriteNormal; m_TooltipLocaKey = m_TooltipLocaKeyNormal; } uisprite.MakePixelPerfect(); NGUITools.AddWidgetCollider(gameObject); }
public static BoxCollider UpdateWidgetCollider(GameObject obj, bool ret = false) { BoxCollider box = obj.GetComponent <Collider>() as BoxCollider; if (null == box) { NGUITools.AddWidgetCollider(obj); if (ret) { box = obj.GetComponent <Collider>() as BoxCollider; } } else { NGUITools.UpdateWidgetCollider(box, false); } return(box); }
public override void OnInspectorGUI() { #pragma warning disable 0618 EditorGUIUtility.LookLikeControls(80f); #pragma warning restore 0618 mButton = target as UIImageButton; UISprite sprite = EditorGUILayout.ObjectField("Sprite", mButton.target, typeof(UISprite), true) as UISprite; if (mButton.target != sprite) { NGUIEditorTools.RegisterUndo("Image Button Change", mButton); mButton.target = sprite; if (sprite != null) { sprite.spriteName = mButton.normalSprite; } } if (mButton.target != null) { ComponentSelector.Draw <UIAtlas>(sprite.atlas as UIAtlas, OnSelectAtlas); if (sprite.atlas != null) { string normal = UISpriteInspector.SpriteField(sprite.atlas as UIAtlas, "Normal", mButton.normalSprite); string hover = UISpriteInspector.SpriteField(sprite.atlas as UIAtlas, "Hover", mButton.hoverSprite); string press = UISpriteInspector.SpriteField(sprite.atlas as UIAtlas, "Pressed", mButton.pressedSprite); if (mButton.normalSprite != normal || mButton.hoverSprite != hover || mButton.pressedSprite != press) { NGUIEditorTools.RegisterUndo("Image Button Change", mButton, mButton.gameObject, sprite); mButton.normalSprite = normal; mButton.hoverSprite = hover; mButton.pressedSprite = press; sprite.spriteName = normal; sprite.MakePixelPerfect(); NGUITools.AddWidgetCollider(mButton.gameObject); } } } }
/// <summary> /// 给目标添加Collider背景 /// </summary> public static void AddColliderBgTotarget(GameObject target, string maskName, UIAtlas altas, bool isTransparent) { Transform uiBg = GameUtility.FindDeepChild(target, "UIBg"); if (uiBg == null) { GameObject targetParent = GetPanelDepthMaxMin(target, false, true); if (targetParent == null) { targetParent = target; } uiBg = (new GameObject("UIBg")).transform; AddChildToTarget(targetParent.transform, uiBg); } Transform bg = GameUtility.FindDeepChild(target, "UIColliderBg"); if (bg == null) { UIWidget widget = null; if (!isTransparent) { widget = NGUITools.AddSprite(uiBg.gameObject, altas, maskName); } else { widget = NGUITools.AddWidget <UIWidget>(uiBg.gameObject); } widget.name = "UIColliderBg"; bg = widget.transform; UIStretch stretch = bg.gameObject.AddComponent <UIStretch>(); stretch.style = UIStretch.Style.Both; stretch.relativeSize = new Vector2(1.5f, 1.5f); widget.depth = -5; widget.alpha = 0.6f; NGUITools.AddWidgetCollider(bg.gameObject); } }
void Awake() { accountView = transform.Find("Account").gameObject; Common.AddClickListener(transform.Find("BG/WX").gameObject, () => EventManage.Instance.Broadcast <string>(EventEnum.login, "wx")); Common.AddClickListener(transform.Find("BG/Test").gameObject, () => EventManage.Instance.Broadcast <string>(EventEnum.login, "user")); NGUITools.AddWidgetCollider(transform.Find("Account/Mask").gameObject); Common.AddClickListener(transform.Find("Account/BG/Close").gameObject, () => accountView.SetActive(false)); Common.AddClickListener(transform.Find("Account/BG/RegisterBtn").gameObject, () => EventManage.Instance.Broadcast <string>(EventEnum.login, "register")); Common.AddClickListener(transform.Find("Account/BG/LoginBtn").gameObject, () => EventManage.Instance.Broadcast <string>(EventEnum.login, "login")); accountInput = transform.Find("Account/BG/AccountInput/Text").GetComponent <UIInput>(); passwordInput = transform.Find("Account/BG/PasswordInput/Text").GetComponent <UIInput>(); }
private void GeEquipStrengthArr() { playerData.GetInstance().selectHeroDetail.RefreshAttr();; float[] basepropertys = playerData.GetInstance().selectHeroDetail.charAttrs; if (basepropertys == null) { return; } string name = ""; string currentattrstr = ""; for (int i = 0; i < basepropertys.Length; i++) { if (basepropertys[i] > 0) { name += propertyname[i] + "\n"; currentattrstr += ((int)basepropertys[i]).ToString() + "\n"; } } attrValue = transform.Find("obj/HeroPreview/AttrValue").GetComponent <UILabel>(); attrName = transform.Find("obj/HeroPreview/AttrName").GetComponent <UILabel>(); if (attrValue != null) { attrValue.text = currentattrstr; } if (attrName != null) { attrName.text = name; UIWidget widget = attrName.GetComponent <UIWidget>(); if (widget != null) { bool vis = widget.isVisible; if (!vis) { this.gameObject.SetActive(true); } this.gameObject.SetActive(vis); } NGUITools.AddWidgetCollider(attrName.gameObject, true); } }
/// <summary> /// Upgrading labels is a bit different. /// </summary> protected override void UpgradeFrom265() { ProcessText(true, true); if (mShrinkToFit) { overflowMethod = Overflow.ShrinkContent; mMaxLineCount = 0; } if (mMaxLineWidth != 0) { width = mMaxLineWidth; overflowMethod = mMaxLineCount > 0 ? Overflow.ResizeHeight : Overflow.ShrinkContent; } else { overflowMethod = Overflow.ResizeFreely; } if (mMaxLineHeight != 0) { height = mMaxLineHeight; } if (mFont != null) { int min = mFont.defaultSize; if (height < min) { height = min; } } mMaxLineWidth = 0; mMaxLineHeight = 0; mShrinkToFit = false; if (GetComponent <BoxCollider>() != null) { NGUITools.AddWidgetCollider(gameObject, true); } }
static public void AddClickListener(GameObject go, EventDelegate.Callback e, bool isPlayAnimation = true) { if (go.GetComponent <Collider>() == null) { NGUITools.AddWidgetCollider(go); } UIEventListener _UIEventListener = UIEventListener.Get(go); if (!isPlayAnimation) { _UIEventListener.onPress = (_go, _b) => { if (_b) { e(); //播放音效 AudioManage.Instance.Play(AudioClipEnum.button); } }; return; } var _Scale = go.transform.localScale; _UIEventListener.onPress = (_go, _b) => { if (_b) { TweenScale.Begin(go, 0.2f, _Scale * 0.8f).method = UITweener.Method.EaseInOut; } else { var _tw = TweenScale.Begin(go, 0.2f, _Scale); _tw.method = UITweener.Method.EaseInOut; if (UICamera.IsHighlighted(go)) { _tw.SetOnFinished(() => e()); //播放音效 AudioManage.Instance.Play(AudioClipEnum.button); } } }; }
/// <summary> /// Scroll bar template. /// </summary> public static void CreateScrollBar(GameObject go) { if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = 0; //NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Scroll Bar"; UISprite bg = NGUITools.AddWidget <UISprite>(go); bg.type = UISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mScrollBG; Vector4 border = bg.border; bg.width = Mathf.RoundToInt(400f + border.x + border.z); bg.height = Mathf.RoundToInt(14f + border.y + border.w); bg.MakePixelPerfect(); UISprite fg = NGUITools.AddWidget <UISprite>(go); fg.type = UISprite.Type.Sliced; fg.name = "Foreground"; fg.atlas = NGUISettings.atlas; fg.spriteName = mScrollFG; UIScrollBar sb = go.AddComponent <UIScrollBar>(); sb.foregroundWidget = fg; sb.backgroundWidget = bg; sb.fillDirection = mFillDir; sb.barSize = 0.3f; sb.value = 0.3f; sb.ForceUpdate(); if (mScrollCL) { NGUITools.AddWidgetCollider(bg.gameObject); NGUITools.AddWidgetCollider(fg.gameObject); } Selection.activeGameObject = go; } }
/// <summary> /// Button creation function. /// </summary> void CreateButton(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Background", "Sliced Sprite for the background", NGUISettings.atlas, mButton, OnButton); } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; NGUISprite bg = NGUITools.AddWidget <NGUISprite>(go); bg.type = NGUISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mButton; bg.transform.localScale = new Vector3(150f, 40f, 1f); bg.MakePixelPerfect(); if (NGUISettings.font != null) { NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <NGUIButton>().tweenTarget = bg.gameObject; go.AddComponent <NGUIButtonScale>(); go.AddComponent <NGUIButtonOffset>(); go.AddComponent <NGUIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Button creation function. /// </summary> void CreateButton(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Background", "Sliced Sprite for the background", NGUISettings.atlas, mButton, OnButton); } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; UISprite bg = NGUITools.AddWidget <UISprite>(go); bg.type = UISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mButton; bg.width = 200; bg.height = 50; bg.MakePixelPerfect(); if (NGUISettings.font != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.AssumeNaturalSize(); Debug.Log(lbl.height); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIPlaySound>(); Selection.activeGameObject = go; } }
public override void Reposition() { base.Reposition(); if (collider != null) { NGUITools.AddWidgetCollider(gameObject, true); } if (orderZ) { float depth = -0.01f; foreach (GameObject cell in GetSortedCells()) { Transform t = cell.transform; t.localPosition = new Vector3(t.localPosition.x, t.localPosition.y, depth); depth -= 0.01f; } } }
private void UpdateLocationCards() { int currentIndex = 0; CleanUpPreviousCards(); foreach (string location in previousSearches) { GameObject locationCard = (GameObject)Resources.Load("Prefabs/Production/PreviousLocationCard"); GameObject childLocation = NGUITools.AddChild(previousLocationView.transform.gameObject, locationCard); NGUITools.AddWidgetCollider(childLocation); UIDragScrollView dragScrollView = childLocation.AddComponent <UIDragScrollView>(); dragScrollView.scrollView = previousLocationView; childLocation.transform.localPosition = new Vector3(3.0f, _locationCardStart + (_locationCardPadding * currentIndex++), 0.0f); var plvc = childLocation.GetComponent <PreviousLocationViewController>(); plvc._previousLocationLabel.text = location; plvc._locationView = this; } }
public static GameObject CreateUITextureButton_NULL( GameObject panel, string text = null, UIFont font = null, float fontSize = 16 ) { // refer to CreateButton at UICreateWidgetWizard int depth = NGUITools.CalculateNextDepth(panel); var go = NGUITools.AddChild(panel); go.name = "Button"; var bg = NGUITools.AddWidget <UITexture>(go); bg.name = "Background"; bg.depth = depth; if (text != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = font; lbl.text = go.name; lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>(); //go.AddComponent<UIButtonOffset>(); go.AddComponent <UIButtonSound>(); var ubm = go.AddComponent <UIButtonMessage>(); ubm.target = panel.GetComponentInChildren <xmlTags_html>().gameObject; ubm.functionName = "OnButtonClick"; return(go); }
/// <summary> /// 给目标添加Collider背景 /// </summary> public static void AddColliderBgToTarget(GameObject target) { // 添加UIPaneldepth最小上面 // 保证添加的Collider放置在屏幕中间 Transform windowBg = GameUtility.FindDeepChild(target, "WindowBg"); if (windowBg == null) { GameObject targetParent = GetPanelDepthMaxMin(target, false, true); if (targetParent == null) { targetParent = target; } windowBg = (GameObject.Instantiate(Resources.Load("Test/UI/WindowBg")) as GameObject).transform; AddChildToTarget(targetParent.transform, windowBg); } Transform bg = GameUtility.FindDeepChild(target, "Mask"); if (bg != null) { // add sprite or widget to ColliderBg gameobject UIWidget widget = bg.GetComponent <UIWidget>(); // fill the screen UIStretch stretch = bg.gameObject.AddComponent <UIStretch>(); stretch.style = UIStretch.Style.Both; // set relative size bigger stretch.relativeSize = new Vector2(1.5f, 1.5f); // set a lower depth widget.depth = -5; // set alpha widget.alpha = 0.6f; // add collider NGUITools.AddWidgetCollider(bg.gameObject); } }
public override void UpdateView(params object[] objs) { uint skillId = (uint)objs[1]; ActiveSkillData newSkillData; if (SkillLogic.GetInstance().ActiveSkillDict.TryGetValue(skillId, out newSkillData) == false) { return; } ActiveSkillData skill = null; int firstNull = -1; for (int i = 0; i < SKILL_ITEM_COUNT; i++) { skill = items[i].SkillData; if (skill != null && skill.SkillID == newSkillData.SkillID) { items[i].SkillData = newSkillData; if (currentItem != null && currentItem == items[i]) { UpdateSkillDesc(newSkillData); firstNull = -1; break; } } if (skill == null && firstNull < 0) { firstNull = i; } } if (firstNull >= 0)//学习技能 { items[firstNull].SkillData = newSkillData; if (items[firstNull].gameObject.collider == null) { NGUITools.AddWidgetCollider(items[firstNull].gameObject); } UIEventListener.Get(items[firstNull].gameObject).onClick += OnClickItem; OnClickItem(items[firstNull].gameObject); } }
/// <summary> /// Button creation function. /// </summary> public static void CreateImageButton(GameObject go) { if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = 0; //NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Image Button"; UISpriteData sp = NGUISettings.atlas.GetSprite(mImage0); UISprite sprite = NGUITools.AddWidget <UISprite>(go); sprite.type = sp.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple; sprite.name = "Background"; sprite.depth = depth; sprite.atlas = NGUISettings.atlas; sprite.spriteName = mImage0; sprite.transform.localScale = new Vector3(150f, 40f, 1f); sprite.MakePixelPerfect(); if (NGUISettings.ambigiousFont != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.ambigiousFont = NGUISettings.ambigiousFont; lbl.text = go.name; lbl.AssumeNaturalSize(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts UIImageButton ib = go.AddComponent <UIImageButton>(); ib.target = sprite; ib.normalSprite = mImage0; ib.hoverSprite = mImage1; ib.pressedSprite = mImage2; ib.disabledSprite = mImage3; go.AddComponent <UIPlaySound>(); Selection.activeGameObject = go; } }
private void PickupItem(GridItem item) { //find out who's the item's container GameObject container = item.transform.parent.gameObject; if (container.GetComponent <InventoryGrid>() != null) { _selectedItemLastList = container.GetComponent <InventoryGrid>().Items; //if it's not owned by player, don't let player pick up rubles if (!container.GetComponent <InventoryGrid>().IsPlayerOwned&& item.Item.ID == "rubles") { return; } } else if (container.GetComponent <BodySlot>() != null) { _selectedItemLastList = container.GetComponent <BodySlot>().Items; } else if (container.GetComponent <TempSlot>() != null) { _selectedItemLastList = container.GetComponent <TempSlot>().Items; } SelectedItem = item; item.Boundary.alpha = 0; NormalizeItemSpriteSize(item); item.Sprite.pivot = UIWidget.Pivot.Center; item.Sprite.transform.parent = _windowPanel.SelectedItemPanel.transform; item.Sprite.depth = (int)InventoryItemDepth.Selected; item.Quantity.depth = item.Sprite.depth + 1; item.Quantity.transform.parent = item.Sprite.transform.parent; //item.Sprite.panel = GameManager.Inst.UIManager.WindowPanel.SelectedItemPanel; NGUITools.MarkParentAsChanged(_windowPanel.gameObject); NGUITools.AddWidgetCollider(item.gameObject); item.State = GridItemState.Selected; FocusedBodySlot = null; GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("SelectItem"), 0.1f); }
public void Activate() { NGUITools.AddWidgetCollider(base.get_gameObject()); try { this.cog.GetComponent <UISprite>().alpha = 1f; } catch (NullReferenceException) { Debug.Log("UISprite.cs is not attached to /Cog"); } try { base.get_transform().GetChild(1).GetComponent <UISprite>().alpha = 1f; } catch (NullReferenceException) { Debug.Log("UISprite.cs is not attached to /Inner"); } this.active = true; }
private void UpdateVisibility() { NpcContainer npcContainer = MyController as NpcContainer; if (npcContainer != null) { UISprite uisprite = (UISprite)MyUIWidget; NGUITools.SetActiveSelf(uisprite.gameObject, npcContainer.IsEnabled && npcContainer.Enabled); if (uisprite.enabled) { switch (npcContainer.MinimapSymbol) { case ENpcMinimapSymbol.HOUSE: uisprite.spriteName = m_SpriteHouse; m_asymmetricSymbol = m_SpriteHouseAsymmetric; goto IL_104; case ENpcMinimapSymbol.INN: uisprite.spriteName = m_SpriteInn; m_asymmetricSymbol = m_SpriteInnAsymmetric; goto IL_104; case ENpcMinimapSymbol.SMITH: uisprite.spriteName = m_SpriteSmith; m_asymmetricSymbol = m_SpriteSmithAsymmetric; goto IL_104; case ENpcMinimapSymbol.SHRINE: uisprite.spriteName = m_SpriteShrine; m_asymmetricSymbol = m_SpriteShrineAsymmetric; goto IL_104; } uisprite.spriteName = m_SpriteNormal; m_asymmetricSymbol = m_SpriteNormalAsymmetric; IL_104: uisprite.MakePixelPerfect(); NGUITools.AddWidgetCollider(gameObject); } } }
private void InitTypeItem() { typeItems = new PassiveSkillTypeItem[SKILL_TYPE_COUNT]; for (int i = 0; i < REQ_ITEM_COUNT; i++) { typeItems[i] = NGUITools.AddChild <PassiveSkillTypeItem>(gameObject); typeItems[i].Data = SKILL_TYPE[i]; if (typeItems[i].gameObject.collider == null) { NGUITools.AddWidgetCollider(typeItems[i].gameObject); } UIEventListener.Get(typeItems[i].gameObject).onClick += OnClickTypeItem; if (i == 2) { typeItems[i].gameObject.transform.localPosition = new Vector3(166.909f, 86.071f, 0f); } else { typeItems[i].gameObject.transform.localPosition = new Vector3(-138.2f + i * 155.4f, 84.2f, 0f); } } }
public override void StartBinding(GameObject mainObj, string args, string layerName) { try { UISprite bgTrans = LayerWordBinder.findChildComponent <UISprite>(mainObj, "background", "bg"); bgTrans.type = UIBasicSprite.Type.Sliced; UILabel text = LayerWordBinder.findChildComponent <UILabel>(mainObj, "holder", "ho"); text.transform.localPosition -= bgTrans.transform.localPosition; text.pivot = UIWidget.Pivot.Left; LayerWordBinder.NGUICopySprite(bgTrans.gameObject, mainObj, true); NGUITools.AddWidgetCollider(mainObj); UIInput inputField = LayerWordBinder.swapComponent <UIInput>(mainObj); inputField.label = text; } catch (Exception) { Debug.LogError(string.Format("[异常InputField:{0}] 请检查是否存在(被隐藏)background和holder组! ", layerName)); } }
public static void UpdateWidgetCollider(Component com, out BoxCollider box, out BoxCollider2D box2D, bool ret = false) { box = null; box2D = null; UICamera ui = UICamera.FindCameraForLayer(com.gameObject.layer); if (ui != null && (ui.eventType == UICamera.EventType.World_2D || ui.eventType == UICamera.EventType.UI_2D)) { box2D = com.GetComponent <BoxCollider2D>(); if (null == box2D) { NGUITools.AddWidgetCollider(com.gameObject); if (ret) { box2D = com.GetComponent <BoxCollider2D>(); } } else { NGUITools.UpdateWidgetCollider(box2D.gameObject, false); } } else { box = com.GetComponent <BoxCollider>(); if (null == box) { NGUITools.AddWidgetCollider(com.gameObject); if (ret) { box = com.GetComponent <BoxCollider>(); } } else { NGUITools.UpdateWidgetCollider(box.gameObject, false); } } }
public void CreateItems() { int count = 0; Bounds b = new Bounds(); for (int y = 0; y < maxRows; ++y) { for (int x = 0; x < maxColumns; ++x) { BagItem slot = NGUITools.AddChild <BagItem>(gameObject); GameObject go = slot.gameObject; NGUITools.AddWidgetCollider(go); Transform t = go.transform; t.localPosition = new Vector3(padding + (x + 0.5f) * spacing, -padding - (y + 0.5f) * spacing, 0f); UIEventListener.Get(slot.gameObject).onDoubleClick += OnDoubleClickItem; //增加一个单击消息处理 UIEventListener.Get(slot.gameObject).onClick += OnClickItem; slot.slot = count; bagItems[count] = slot; b.Encapsulate(new Vector3(padding * 2f + (x + 1) * spacing, -padding * 2f - (y + 1) * spacing, 0f)); if (++count >= maxItemCount) { if (background != null) { background.transform.localScale = b.size; } return; } } } if (background != null) { background.transform.localScale = b.size; } }
protected override void OnStart() { if (NJGMap.instance == null) { return; } if (mInst == null) { mInst = this; } base.OnStart(); if (planeRenderer == null) { return; } BoxCollider col = planeRenderer.GetComponent <BoxCollider>(); if (col == null) { NGUITools.AddWidgetCollider(planeRenderer.gameObject); } UIForwardEvents fe = planeRenderer.GetComponent <UIForwardEvents>(); if (fe == null) { fe = planeRenderer.gameObject.AddComponent <UIForwardEvents>(); } fe.onClick = true; fe.onHover = true; fe.target = gameObject; }
public override void Awake() { base.Awake(); var t = mDMono.transform; m_ClickTarget = t.GetComponent <UIWidget>("Bg"); m_Anchor = t.GetComponent <Transform>("Anchor"); if (m_ClickTarget.GetComponent <Collider>() == null) { NGUITools.AddWidgetCollider(m_ClickTarget.gameObject); } UIEventTrigger trigger = m_ClickTarget.GetComponent <UIEventTrigger>(); if (trigger == null) { trigger = m_ClickTarget.gameObject.AddComponent <UIEventTrigger>(); } trigger.onClick.Add(new EventDelegate(OnResourceClick)); }
public GameObject CreateText(string text, string style, Action clickHandler) { var textGOPrefab = GetTextPrefab(style); if (textGOPrefab) { var textPool = GetTextPool(style); var textGO = textPool.Spawn(textGOPrefab); var textComp = textGO.GetComponent <UILabel>(); if (!textComp) { Debug.LogError("[NGUIGameObjectManager]Error to get UILabel component : " + style); textPool.Release(textGO); return(null); } textComp.text = text; // add collider to widget first NGUITools.AddWidgetCollider(textGO); // handler click handler var nguiClickHandler = RichTextUtil.GetOrAddComponent <NGUIClickHandler>(textGO); Debug.Assert(nguiClickHandler != null); // first clear nguiClickHandler.ClearHandlers(); // then add handler if (clickHandler != null) { nguiClickHandler.AddHandler(clickHandler); } return(textGO); } return(null); }
protected override void UpgradeFrom265() { this.ProcessText(true, true); if (this.mShrinkToFit) { this.overflowMethod = UILabel.Overflow.ShrinkContent; this.mMaxLineCount = 0; } if (this.mMaxLineWidth != 0) { base.width = this.mMaxLineWidth; this.overflowMethod = ((this.mMaxLineCount <= 0) ? UILabel.Overflow.ShrinkContent : UILabel.Overflow.ResizeHeight); } else { this.overflowMethod = UILabel.Overflow.ResizeFreely; } if (this.mMaxLineHeight != 0) { base.height = this.mMaxLineHeight; } if (this.mFont != null) { int defaultSize = this.mFont.defaultSize; if (base.height < defaultSize) { base.height = defaultSize; } } this.mMaxLineWidth = 0; this.mMaxLineHeight = 0; this.mShrinkToFit = false; if (base.GetComponent <BoxCollider>() != null) { NGUITools.AddWidgetCollider(base.gameObject, true); } }
static int AddWidgetCollider(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 1) { GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject)); NGUITools.AddWidgetCollider(arg0); return(0); } else if (count == 2) { GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject)); bool arg1 = LuaScriptMgr.GetBoolean(L, 2); NGUITools.AddWidgetCollider(arg0, arg1); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: NGUITools.AddWidgetCollider"); } return(0); }