/// <summary> /// Find all needed components. /// </summary> void Awake () { mWidget = GetComponentInChildren<UIWidget>(); Renderer ren = renderer; if (ren != null) mMat = ren.material; mLight = light; }
void initializeUI() { arrowUI = GameObject.Find ("Arrow").gameObject; speedUI = GameObject.Find ("speed").GetComponent<UILabel>(); gearstUI = GameObject.Find ("peredacha").GetComponent<UILabel> (); nitroUI = GameObject.Find ("indikator").GetComponent<UIWidget> (); }
public static XmlNodeList fromXML(XmlNode nd, out UIWidget ui, UIWidget p) { ui = new UIStub(); ui.fromXML(nd); ui.paresent = p; return nd.ChildNodes; }
private void Awake() { if (this.Widget == null) { this.Widget = this.GetComponent<UIWidget>(); } }
void Start () { btnClose = transform.FindInChildren("btnBack").GetComponent<UIButton>(); scrEvents = transform.FindInChildren("scrEvent").GetComponent<UIScrollView>(); tplEvent = transform.FindInChildren("itemEvent").GetComponent<UIWidget>(); tplEvent.gameObject.SetActive(false); tplEvent.transform.parent = null; }
public static XmlNodeList fromXML(XmlNode node, out UIWidget ui, UIWidget p) { string text = ""; float width = 128; int rows = 1; int fontSz = 10; uint color = 0xffffffff; EStyle style = EStyle.normal; var ret = node.Attributes.GetNamedItem("text"); if (ret != null) text = ret.Value; bool br = false; text = getProp<string>(node, "text", "template", out br); width = getProp(node, "width", 128, out br); rows = getProp(node, "rows", rows, out br); color = (uint)getProp<EColorUtil>(node, "color", (EColorUtil)schemes.textColor, out br); if (!br) { color = getProp(node, "color", (uint)(schemes.textColor), out br); } style = UILabel.getStyle(node); fontSz = getProp(node, "size", fontSz, out br); ui = new UIEdit(text, fontSz, (int)width, rows, color, style); ui.fromXML(node); ui.paresent = p; return node.ChildNodes; }
public static Bounds CalculateWidgetLocalBounds( UIWidget w, Transform relativeTo ) { float width = w.cachedTransform.localScale.x; float height = w.cachedTransform.localScale.y; Vector2 pivotOffset = w.pivotOffset; return new Bounds( GetLocalOffset( w.transform, relativeTo ) + new Vector3( 0.5f*pivotOffset.x*width, 0.5f*pivotOffset.y*height, 0f ), new Vector3( width, height, 0f ) ); }
public override void OnInit() { base.OnInit(); m_SpriteMyIcon = FindChildComponent<UISprite>("Sprite_Icon1"); m_SpriteOtherIcon = FindChildComponent<UISprite>("Sprite_Icon0"); m_ObjButtonRoot = FindChild("ButtonRoot"); m_ObjButtonOk = FindChild("Button_Ok"); m_ObjButtonCancle = FindChild("Button_Cancle"); m_LabelMyName = FindChildComponent<UILabel>("Label_Name1"); m_LabelOtherName = FindChildComponent<UILabel>("Label_Name2"); var obj = FindChild("Button_Talk"); UIEventListener.Get(obj).onPress = OnPressButton; AddChildElementClickEvent(OnClickBack, "Sprite_Exit"); m_DropPanel = FindChildComponent<UIWidget>("DrapPanel"); m_FireworkPlanList = new List<FireworkPlanElement>(); for (int i = 0; i < 7; ++i) { var objRoot = FindChild("Type_" + i); FireworkPlanElement elem = new FireworkPlanElement(objRoot); elem.SetStatus(true,ItemManager.Instance.IsExistItem(i)); m_FireworkPlanList.Add(elem); MyUIDragDropItem drag = objRoot.GetComponent<MyUIDragDropItem>(); drag.RegisterDragEndAction(OnDragEnd); //UIEventListener.Get(objRoot).onClick = OnClickItem;; } m_ObjButtonRoot.SetActive(false); m_SpriteMyIcon.gameObject.SetActive(false); m_SpriteOtherIcon.gameObject.SetActive(false); m_LabelOtherName.text = string.Empty; m_LabelMyName.text = PlayerManager.Instance.GetCharBaseData().CharName; }
void SetAlign(UIWidget widget, float posY) { Vector2 pos = widget.transform.localPosition; switch (m_align) { case Align.NONE: break; case Align.CENTER: pos.y = 0; break; case Align.TOP: pos.y = m_size.y / 2; break; case Align.BOTTOM: pos.y = m_size.y / 2 * -1; break; default: break; } pos.y -= posY; widget.transform.localPosition = pos; }
IEnumerator SetRank(){ //StartCoroutine("Wait", 5f); //yield return new WaitForSeconds (2f); GameObject.Find("Panel").transform.FindChild("Rank").gameObject.SetActive(true); GameObject.Find("Panel").transform.FindChild("RankText").gameObject.SetActive(true); wg2 = GameObject.Find("Panel").transform.FindChild("RankText").GetComponent<UIWidget>(); trueRankText = true; //StartCoroutine("Wait", 2f); yield return new WaitForSeconds(3f); if (num >= 60) { GameObject.Find ("Rank").transform.FindChild("DRank").gameObject.SetActive (true); wg = GameObject.Find ("Rank").transform.FindChild("DRank").GetComponent<UIWidget>(); } else if (num >= 40) { GameObject.Find ("Rank").transform.FindChild("CRank").gameObject.SetActive (true); wg = GameObject.Find ("Rank").transform.FindChild("CRank").GetComponent<UIWidget>(); } else if (num >= 20) { GameObject.Find ("Rank").transform.FindChild("BRank").gameObject.SetActive (true); wg = GameObject.Find ("Rank").transform.FindChild("BRank").GetComponent<UIWidget>(); }else if (num > 10) { GameObject.Find ("Rank").transform.FindChild("ARank").gameObject.SetActive (true); wg = GameObject.Find ("Rank").transform.FindChild("ARank").GetComponent<UIWidget>(); } else if (num > 0) { GameObject.Find ("Rank").transform.FindChild("SRank").gameObject.SetActive (true); wg = GameObject.Find ("Rank").transform.FindChild("SRank").GetComponent<UIWidget>(); } trueRank = true; }
public void FadeAlphaRank(UIWidget w){ Debug.Log ("wid"+fAlpha+"aa"+w.alpha); if(w.alpha < 255f){ w.alpha += fAlpha; Debug.Log ("wid"+fAlpha+"aa"+w.alpha); } }
// Update is called once per frame void Update () { #if UNITY_EDITOR if (host == null) { host = GetComponent<UIWidget>(); } if (processBar == null) { processBar = NGUITools.FindInParents<UIProgressBar>(gameObject); } #endif if(host == null) return; if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer); Rect mRect = uiCamera.pixelRect; Vector3 v = new Vector3(mRect.xMax, 0f, 0f); v = uiCamera.ScreenToWorldPoint(v); Vector3 lp = this.transform.InverseTransformPoint(v); int newWidth = (int)lp.x; if (newWidth != oldWidth) { oldWidth = newWidth; host.width = (int)lp.x; if (processBar != null) processBar.ForceUpdate(); } }
public static int CompareFunc(UIWidget left, UIWidget right) { int num = UIPanel.CompareFunc(left.mPanel, right.mPanel); if (num != 0) { return num; } if (left.mDepth < right.mDepth) { return -1; } if (left.mDepth > right.mDepth) { return 1; } Material material = left.material; Material material2 = right.material; if (material == material2) { return 0; } if (material != null) { return -1; } if (material2 != null) { return 1; } return ((material.GetInstanceID() >= material2.GetInstanceID()) ? 1 : -1); }
void Start() { m_widget = GetComponent<UIWidget>(); m_size = m_widget.localSize; SetAlignWidgets(); }
void Cache () { mCached = true; mWidget = GetComponent<UIWidget>(); if (mWidget != null) return; mSr = GetComponent<SpriteRenderer>(); if (mSr != null) return; #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 Renderer ren = renderer; #else Renderer ren = GetComponent<Renderer>(); #endif if (ren != null) { mMat = ren.material; return; } #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 mLight = light; #else mLight = GetComponent<Light>(); #endif if (mLight == null) mWidget = GetComponentInChildren<UIWidget>(); }
public static XmlNodeList fromXML(XmlNode node, out UIWidget ui, UIWidget p) { uint color = (uint)schemes.strokeColor; bool br = true; float lineWidth = (uint)getProp<float>(node, "lineWidth", 1, out br); color = (uint)getProp<EColorUtil>(node, "color", (EColorUtil)schemes.strokeColor, out br); string strBegin = tryGetProp("begin", node); PointF ptBegin = parsePt(strBegin); string strEnd = tryGetProp("end", node); PointF ptEnd = parsePt(strEnd); var uiLine = new UILine(); uiLine.setLineWidth(lineWidth);//must be under color uiLine.setBegin(ptBegin.X, ptBegin.Y); uiLine.setEnd(ptEnd.X, ptEnd.Y); uiLine.color = color; uiLine.fromXML(node); ui = uiLine; return node.ChildNodes; }
public void SetSpriteBySelection() { if (UIPopupList.current != null) { if (this.mWidget == null) { this.mWidget = base.GetComponent<UIWidget>(); } string key = UIPopupList.current.value; if (key != null) { int num; if (<>f__switch$map1 == null) { Dictionary<string, int> dictionary = new Dictionary<string, int>(7); dictionary.Add("White", 0); dictionary.Add("Red", 1); dictionary.Add("Green", 2); dictionary.Add("Blue", 3); dictionary.Add("Yellow", 4); dictionary.Add("Cyan", 5); dictionary.Add("Magenta", 6); <>f__switch$map1 = dictionary; } if (<>f__switch$map1.TryGetValue(key, out num)) { switch (num) { case 0: this.mWidget.color = Color.white; break; case 1: this.mWidget.color = Color.red; break; case 2: this.mWidget.color = Color.green; break; case 3: this.mWidget.color = Color.blue; break; case 4: this.mWidget.color = Color.yellow; break; case 5: this.mWidget.color = Color.cyan; break; case 6: this.mWidget.color = Color.magenta; break; } } } } }
private void AnimatePosition(UIWidget widget, bool placeAbove, float bottom) { Vector3 localPosition = widget.cachedTransform.localPosition; Vector3 vector2 = !placeAbove ? new Vector3(localPosition.x, 0f, localPosition.z) : new Vector3(localPosition.x, bottom, localPosition.z); widget.cachedTransform.localPosition = vector2; TweenPosition.Begin(widget.gameObject, 0.15f, localPosition).method = UITweener.Method.EaseOut; }
void Cache () { mCached = true; mWidget = GetComponentInChildren<UIWidget>(); Renderer ren = GetComponent<Renderer>(); if (ren != null) mMat = ren.material; mLight = GetComponent<Light>(); }
private void Awake() { this.mPanel = base.GetComponent<UIPanel>(); if (this.mPanel == null) { this.mWidget = base.GetComponentInChildren<UIWidget>(); } }
void Awake() { instance = this; turretSelectWidget = turretSelectMenu.GetComponent<UIWidget>(); destroyTurretTab = turretSelectMenu.GetComponentInChildren<AllyDestroyTurret>(); HideTurretSelectTab(); }
public static void ParserWidget(MyJson.JsonNode_Object json, UIWidget widget) { json["w_color"] = new MyJson.JsonNode_ValueString(ComponentTypeConvert.ColorToString(widget.color)); json["w_pivot"] = new MyJson.JsonNode_ValueString(widget.pivot.ToString()); json["w_depth"] = new MyJson.JsonNode_ValueNumber(widget.depth); json["w_dimensions"] = new MyJson.JsonNode_ValueString(ComponentTypeConvert.Vector2ToString(new Vector2(widget.width, widget.height))); json["w_keepasp"] = new MyJson.JsonNode_ValueString(widget.keepAspectRatio.ToString()); //json["w_asp"] = new MyJson.JsonNode_ValueNumber(widget.aspectRatio); }
void OnEnable() { widget = GetComponent<UIWidget>(); if (SystemInfo.deviceType == DeviceType.Handheld) { isKeyboardEmulation = false; } }
const int Rate = 1;//缩放频率 public void Init() { Transform mTran = transform; UIScrollView mScrollView = NGUITools.FindInParents<UIScrollView>(gameObject); panelTrans = mScrollView.panel.cachedTransform; Factor = MaxFactor - MinFactor; //获取中心点 Vector3[] corners = mScrollView.panel.worldCorners; panelCenter = (corners[2] + corners[0]) * 0.5f; //初始化子项集合 ItemCount = mTran.childCount; Items = new Transform[ItemCount]; SpriteList = new UIWidget[ItemCount][]; ItemsClick = new UICenterOnClick[ItemCount]; for (int i = 0; i < ItemCount; i++) { Transform tr = mTran.GetChild(i); Items[i] = tr; ItemsClick[i] = tr.GetComponent<UICenterOnClick>(); SpriteCount = tr.childCount; SpriteList[i] = new UIWidget[SpriteCount]; for (int j = 0; j < SpriteCount; j++) SpriteList[i][j] = tr.GetChild(j).GetComponent<UIWidget>(); } FirstItem = Items[0]; //获取宽度和高度偏移 Origin = new SpriteScale[SpriteCount]; for (int i = 0; i < SpriteCount; i++) { UIWidget sprite = SpriteList[0][i]; if (sprite == null) continue; float w = sprite.width; float h = sprite.height; int t = sprite.topAnchor.absolute; int b = sprite.bottomAnchor.absolute; int l = sprite.leftAnchor.absolute; int r = sprite.rightAnchor.absolute; Origin[i] = new SpriteScale(w, h, t, b, l, r); } //开启自动居中功能 UICenterOnChild UICenter = GetComponent<UICenterOnChild>(); UICenter.enabled = false; UICenter.enabled = true; //设置回调 UICenter.onCenter = onCenter; UICenter.onFinished = onFinished; //缩放 if (IsScale) Scale(); }
void Cache () { mCached = true; mWidget = GetComponent<UIWidget>(); Renderer ren = renderer; if (ren != null) mMat = ren.material; mLight = light; if (mWidget == null && mMat == null && mLight == null) mWidget = GetComponentInChildren<UIWidget>(); }
void Start() { mTrans = transform; mPanel = mTrans.parent.parent.GetComponent<UIPanel>(); mWidget = GetComponent<UIWidget>(); //초기값 입력. cellWidth = 300; downScale = 0.35f; }
private void Awake() { this.mWidget = base.GetComponentInChildren<UIWidget>(); Renderer renderer = base.renderer; if (renderer != null) { this.mMat = renderer.material; } this.mLight = base.light; }
protected override void SetValue(Vector3 value) { if (widget != null) { widget.width = (int) value.x; widget.height = (int) value.y; } else { widget = GetComponent<UIWidget>(); } }
private void Awake() { this.mAnim = base.animation; this.mRect = new Rect(); this.mTrans = base.transform; this.mWidget = base.GetComponent<UIWidget>(); this.mSprite = base.GetComponent<UISprite>(); this.mPanel = base.GetComponent<UIPanel>(); UICamera.onScreenResize = (UICamera.OnScreenResize) Delegate.Combine(UICamera.onScreenResize, new UICamera.OnScreenResize(this.ScreenSizeChanged)); }
private void OnEnable() { if (this.Target == null) { this.Target = this.GetComponent<UIWidget>(); } this.currentColor = 1; this.UpdateWidgetColor(); }
private void Update() { if (this.mAnim != null && this.mAnim.isPlaying) { return; } if (this.style != UIStretch.Style.None) { UIWidget uiwidget = (!(this.container == null)) ? this.container.GetComponent <UIWidget>() : null; UIPanel uipanel = (!(this.container == null) || !(uiwidget == null)) ? this.container.GetComponent <UIPanel>() : null; float num = 1f; if (uiwidget != null) { Bounds bounds = uiwidget.CalculateBounds(base.transform.parent); this.mRect.x = bounds.min.x; this.mRect.y = bounds.min.y; this.mRect.width = bounds.size.x; this.mRect.height = bounds.size.y; } else if (uipanel != null) { if (uipanel.clipping == UIDrawCall.Clipping.None) { float num2 = (!(this.mRoot != null)) ? 0.5f : ((float)this.mRoot.activeHeight / (float)Screen.height * 0.5f); this.mRect.xMin = (float)(-(float)Screen.width) * num2; this.mRect.yMin = (float)(-(float)Screen.height) * num2; this.mRect.xMax = -this.mRect.xMin; this.mRect.yMax = -this.mRect.yMin; } else { Vector4 finalClipRegion = uipanel.finalClipRegion; this.mRect.x = finalClipRegion.x - finalClipRegion.z * 0.5f; this.mRect.y = finalClipRegion.y - finalClipRegion.w * 0.5f; this.mRect.width = finalClipRegion.z; this.mRect.height = finalClipRegion.w; } } else if (this.container != null) { Transform parent = base.transform.parent; Bounds bounds2 = (!(parent != null)) ? NGUIMath.CalculateRelativeWidgetBounds(this.container.transform) : NGUIMath.CalculateRelativeWidgetBounds(parent, this.container.transform); this.mRect.x = bounds2.min.x; this.mRect.y = bounds2.min.y; this.mRect.width = bounds2.size.x; this.mRect.height = bounds2.size.y; } else { if (!(this.uiCamera != null)) { return; } this.mRect = this.uiCamera.pixelRect; if (this.mRoot != null) { num = this.mRoot.pixelSizeAdjustment; } } float num3 = this.mRect.width; float num4 = this.mRect.height; if (num != 1f && num4 > 1f) { float num5 = (float)this.mRoot.activeHeight / num4; num3 *= num5; num4 *= num5; } Vector3 vector = (!(this.mWidget != null)) ? this.mTrans.localScale : new Vector3((float)this.mWidget.width, (float)this.mWidget.height); if (this.style == UIStretch.Style.BasedOnHeight) { vector.x = this.relativeSize.x * num4; vector.y = this.relativeSize.y * num4; } else if (this.style == UIStretch.Style.FillKeepingRatio) { float num6 = num3 / num4; float num7 = this.initialSize.x / this.initialSize.y; if (num7 < num6) { float num8 = num3 / this.initialSize.x; vector.x = num3; vector.y = this.initialSize.y * num8; } else { float num9 = num4 / this.initialSize.y; vector.x = this.initialSize.x * num9; vector.y = num4; } } else if (this.style == UIStretch.Style.FitInternalKeepingRatio) { float num10 = num3 / num4; float num11 = this.initialSize.x / this.initialSize.y; if (num11 > num10) { float num12 = num3 / this.initialSize.x; vector.x = num3; vector.y = this.initialSize.y * num12; } else { float num13 = num4 / this.initialSize.y; vector.x = this.initialSize.x * num13; vector.y = num4; } } else { if (this.style != UIStretch.Style.Vertical) { vector.x = this.relativeSize.x * num3; } if (this.style != UIStretch.Style.Horizontal) { vector.y = this.relativeSize.y * num4; } } if (this.mSprite != null) { float num14 = (!(this.mSprite.atlas != null)) ? 1f : this.mSprite.atlas.pixelSize; vector.x -= this.borderPadding.x * num14; vector.y -= this.borderPadding.y * num14; if (this.style != UIStretch.Style.Vertical) { this.mSprite.width = Mathf.RoundToInt(vector.x); } if (this.style != UIStretch.Style.Horizontal) { this.mSprite.height = Mathf.RoundToInt(vector.y); } vector = Vector3.one; } else if (this.mWidget != null) { if (this.style != UIStretch.Style.Vertical) { this.mWidget.width = Mathf.RoundToInt(vector.x - this.borderPadding.x); } if (this.style != UIStretch.Style.Horizontal) { this.mWidget.height = Mathf.RoundToInt(vector.y - this.borderPadding.y); } vector = Vector3.one; } else if (this.mPanel != null) { Vector4 baseClipRegion = this.mPanel.baseClipRegion; if (this.style != UIStretch.Style.Vertical) { baseClipRegion.z = vector.x - this.borderPadding.x; } if (this.style != UIStretch.Style.Horizontal) { baseClipRegion.w = vector.y - this.borderPadding.y; } this.mPanel.baseClipRegion = baseClipRegion; vector = Vector3.one; } else { if (this.style != UIStretch.Style.Vertical) { vector.x -= this.borderPadding.x; } if (this.style != UIStretch.Style.Horizontal) { vector.y -= this.borderPadding.y; } } if (this.mTrans.localScale != vector) { this.mTrans.localScale = vector; } if (this.runOnlyOnce && Application.isPlaying) { base.enabled = false; } } }
/// <summary> /// Helper function used to animate widgets. /// </summary> void Animate(UIWidget widget, bool placeAbove, float bottom) { AnimateColor(widget); AnimatePosition(widget, placeAbove, bottom); }
void Awake() { this.name = this.JoystickName; root = this.GetComponent <UIWidget>(); Init(); }
/// <summary> /// Add commonly NGUI context menu options. /// </summary> static public void AddCommonItems(GameObject target) { if (target != null) { UIWidget widget = target.GetComponent <UIWidget>(); string myName = string.Format("Selected {0}", (widget != null) ? NGUITools.GetTypeName(widget) : "Object"); AddItem(myName + "/Bring to Front", false, delegate(object obj) { for (int i = 0; i < Selection.gameObjects.Length; ++i) { NGUITools.BringForward(Selection.gameObjects[i]); } }, null); AddItem(myName + "/Push to Back", false, delegate(object obj) { for (int i = 0; i < Selection.gameObjects.Length; ++i) { NGUITools.PushBack(Selection.gameObjects[i]); } }, null); AddItem(myName + "/Nudge Forward", false, delegate(object obj) { for (int i = 0; i < Selection.gameObjects.Length; ++i) { NGUITools.AdjustDepth(Selection.gameObjects[i], 1); } }, null); AddItem(myName + "/Nudge Back", false, delegate(object obj) { for (int i = 0; i < Selection.gameObjects.Length; ++i) { NGUITools.AdjustDepth(Selection.gameObjects[i], -1); } }, null); if (widget != null) { NGUIContextMenu.AddSeparator(myName + "/"); AddItem(myName + "/Make Pixel-Perfect", false, OnMakePixelPerfect, Selection.activeTransform); if (target.GetComponent <BoxCollider>() != null) { AddItem(myName + "/Reset Collider Size", false, OnBoxCollider, target); } } NGUIContextMenu.AddSeparator(myName + "/"); AddItem(myName + "/Delete", false, OnDelete, target); NGUIContextMenu.AddSeparator(""); if (Selection.activeTransform.parent != null && widget != null) { AddChildWidget("Create/Sprite/Child", false, NGUISettings.AddSprite); AddChildWidget("Create/Label/Child", false, NGUISettings.AddLabel); AddChildWidget("Create/Invisible Widget/Child", false, NGUISettings.AddWidget); AddChildWidget("Create/Simple Texture/Child", false, NGUISettings.AddTexture); AddChildWidget("Create/Unity 2D Sprite/Child", false, NGUISettings.Add2DSprite); AddSiblingWidget("Create/Sprite/Sibling", false, NGUISettings.AddSprite); AddSiblingWidget("Create/Label/Sibling", false, NGUISettings.AddLabel); AddSiblingWidget("Create/Invisible Widget/Sibling", false, NGUISettings.AddWidget); AddSiblingWidget("Create/Simple Texture/Sibling", false, NGUISettings.AddTexture); AddSiblingWidget("Create/Unity 2D Sprite/Sibling", false, NGUISettings.Add2DSprite); } else { AddChildWidget("Create/Sprite", false, NGUISettings.AddSprite); AddChildWidget("Create/Label", false, NGUISettings.AddLabel); AddChildWidget("Create/Invisible Widget", false, NGUISettings.AddWidget); AddChildWidget("Create/Simple Texture", false, NGUISettings.AddTexture); AddChildWidget("Create/Unity 2D Sprite", false, NGUISettings.Add2DSprite); } NGUIContextMenu.AddSeparator("Create/"); AddItem("Create/Panel", false, AddPanel, target); AddItem("Create/Scroll View", false, AddScrollView, target); AddItem("Create/Grid", false, AddChild <UIGrid>, target); AddItem("Create/Table", false, AddChild <UITable>, target); AddItem("Create/Anchor (Legacy)", false, AddChild <UIAnchor>, target); if (target.GetComponent <UIPanel>() != null) { if (target.GetComponent <UIScrollView>() == null) { AddItem("Attach/Scroll View", false, Attach, typeof(UIScrollView)); NGUIContextMenu.AddSeparator("Attach/"); } } #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 else if (target.collider == null && target.GetComponent <Collider2D>() == null) #else else if (target.GetComponent <Collider>() == null && target.GetComponent <Collider2D>() == null) #endif { AddItem("Attach/Box Collider", false, AttachCollider, null); NGUIContextMenu.AddSeparator("Attach/"); } bool header = false; UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(target); if (scrollView != null) { if (scrollView.GetComponentInChildren <UICenterOnChild>() == null) { AddItem("Attach/Center Scroll View on Child", false, Attach, typeof(UICenterOnChild)); header = true; } } #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 if (target.collider != null || target.GetComponent <Collider2D>() != null) #else if (target.GetComponent <Collider>() != null || target.GetComponent <Collider2D>() != null) #endif { if (scrollView != null) { if (target.GetComponent <UIDragScrollView>() == null) { AddItem("Attach/Drag Scroll View", false, Attach, typeof(UIDragScrollView)); header = true; } if (target.GetComponent <UICenterOnClick>() == null && NGUITools.FindInParents <UICenterOnChild>(target) != null) { AddItem("Attach/Center Scroll View on Click", false, Attach, typeof(UICenterOnClick)); header = true; } } if (header) { NGUIContextMenu.AddSeparator("Attach/"); } AddItem("Attach/Button Script", false, Attach, typeof(UIButton)); AddItem("Attach/Toggle Script", false, Attach, typeof(UIToggle)); AddItem("Attach/Slider Script", false, Attach, typeof(UISlider)); AddItem("Attach/Scroll Bar Script", false, Attach, typeof(UIScrollBar)); AddItem("Attach/Progress Bar Script", false, Attach, typeof(UISlider)); AddItem("Attach/Popup List Script", false, Attach, typeof(UIPopupList)); AddItem("Attach/Input Field Script", false, Attach, typeof(UIInput)); NGUIContextMenu.AddSeparator("Attach/"); if (target.GetComponent <UIDragResize>() == null) { AddItem("Attach/Drag Resize Script", false, Attach, typeof(UIDragResize)); } if (target.GetComponent <UIDragScrollView>() == null) { for (int i = 0; i < UIPanel.list.Count; ++i) { UIPanel pan = UIPanel.list[i]; if (pan.clipping == UIDrawCall.Clipping.None) { continue; } UIScrollView dr = pan.GetComponent <UIScrollView>(); if (dr == null) { continue; } AddItem("Attach/Drag Scroll View", false, delegate(object obj) { target.AddComponent <UIDragScrollView>().scrollView = dr; }, null); header = true; break; } } AddItem("Attach/Key Binding Script", false, Attach, typeof(UIKeyBinding)); if (target.GetComponent <UIKeyNavigation>() == null) { AddItem("Attach/Key Navigation Script", false, Attach, typeof(UIKeyNavigation)); } NGUIContextMenu.AddSeparator("Attach/"); AddItem("Attach/Play Tween Script", false, Attach, typeof(UIPlayTween)); AddItem("Attach/Play Animation Script", false, Attach, typeof(UIPlayAnimation)); AddItem("Attach/Play Sound Script", false, Attach, typeof(UIPlaySound)); } AddItem("Attach/Property Binding", false, Attach, typeof(PropertyBinding)); if (target.GetComponent <UILocalize>() == null) { AddItem("Attach/Localization Script", false, Attach, typeof(UILocalize)); } if (widget != null) { AddMissingItem <TweenAlpha>(target, "Tween/Alpha"); AddMissingItem <TweenColor>(target, "Tween/Color"); AddMissingItem <TweenWidth>(target, "Tween/Width"); AddMissingItem <TweenHeight>(target, "Tween/Height"); } else if (target.GetComponent <UIPanel>() != null) { AddMissingItem <TweenAlpha>(target, "Tween/Alpha"); } NGUIContextMenu.AddSeparator("Tween/"); AddMissingItem <TweenPosition>(target, "Tween/Position"); AddMissingItem <TweenRotation>(target, "Tween/Rotation"); AddMissingItem <TweenScale>(target, "Tween/Scale"); AddMissingItem <TweenTransform>(target, "Tween/Transform"); if (target.GetComponent <AudioSource>() != null) { AddMissingItem <TweenVolume>(target, "Tween/Volume"); } if (target.GetComponent <Camera>() != null) { AddMissingItem <TweenFOV>(target, "Tween/Field of View"); AddMissingItem <TweenOrthoSize>(target, "Tween/Orthographic Size"); } } }
static public int FullCompareFunc(UIWidget left, UIWidget right) { int val = UIPanel.CompareFunc(left.panel, right.panel); return((val == 0) ? PanelCompareFunc(left, right) : val); }
private void Awake() { mWidgetThis = GetComponent <UIWidget>(); }
//初始化控件变量 protected override void InitControls() { fastComponent = GetComponent <FastComponent>(); fastComponent.BuildFastComponents(); m_trans_LearnSkillContent = fastComponent.FastGetComponent <Transform>("LearnSkillContent"); if (null == m_trans_LearnSkillContent) { Engine.Utility.Log.Error("m_trans_LearnSkillContent 为空,请检查prefab是否缺乏组件"); } m_widget_currency = fastComponent.FastGetComponent <UIWidget>("currency"); if (null == m_widget_currency) { Engine.Utility.Log.Error("m_widget_currency 为空,请检查prefab是否缺乏组件"); } m_widget_state_1 = fastComponent.FastGetComponent <UIWidget>("state_1"); if (null == m_widget_state_1) { Engine.Utility.Log.Error("m_widget_state_1 为空,请检查prefab是否缺乏组件"); } m_label_StateOneLabel = fastComponent.FastGetComponent <UILabel>("StateOneLabel"); if (null == m_label_StateOneLabel) { Engine.Utility.Log.Error("m_label_StateOneLabel 为空,请检查prefab是否缺乏组件"); } m_widget_state_2 = fastComponent.FastGetComponent <UIWidget>("state_2"); if (null == m_widget_state_2) { Engine.Utility.Log.Error("m_widget_state_2 为空,请检查prefab是否缺乏组件"); } m_label_StateTwoLabel = fastComponent.FastGetComponent <UILabel>("StateTwoLabel"); if (null == m_label_StateTwoLabel) { Engine.Utility.Log.Error("m_label_StateTwoLabel 为空,请检查prefab是否缺乏组件"); } m_trans_up = fastComponent.FastGetComponent <Transform>("up"); if (null == m_trans_up) { Engine.Utility.Log.Error("m_trans_up 为空,请检查prefab是否缺乏组件"); } m_trans_skill_shengji = fastComponent.FastGetComponent <Transform>("skill_shengji"); if (null == m_trans_skill_shengji) { Engine.Utility.Log.Error("m_trans_skill_shengji 为空,请检查prefab是否缺乏组件"); } m_trans_skill_setting = fastComponent.FastGetComponent <Transform>("skill_setting"); if (null == m_trans_skill_setting) { Engine.Utility.Log.Error("m_trans_skill_setting 为空,请检查prefab是否缺乏组件"); } m_trans_skill_shengji_area = fastComponent.FastGetComponent <Transform>("skill_shengji_area"); if (null == m_trans_skill_shengji_area) { Engine.Utility.Log.Error("m_trans_skill_shengji_area 为空,请检查prefab是否缺乏组件"); } m_trans_WeiJieSuoContent = fastComponent.FastGetComponent <Transform>("WeiJieSuoContent"); if (null == m_trans_WeiJieSuoContent) { Engine.Utility.Log.Error("m_trans_WeiJieSuoContent 为空,请检查prefab是否缺乏组件"); } m_label_WeiJieSuoLocklevel = fastComponent.FastGetComponent <UILabel>("WeiJieSuoLocklevel"); if (null == m_label_WeiJieSuoLocklevel) { Engine.Utility.Log.Error("m_label_WeiJieSuoLocklevel 为空,请检查prefab是否缺乏组件"); } m_trans_JieSuoContent = fastComponent.FastGetComponent <Transform>("JieSuoContent"); if (null == m_trans_JieSuoContent) { Engine.Utility.Log.Error("m_trans_JieSuoContent 为空,请检查prefab是否缺乏组件"); } m_label_Gold_Cost = fastComponent.FastGetComponent <UILabel>("Gold_Cost"); if (null == m_label_Gold_Cost) { Engine.Utility.Log.Error("m_label_Gold_Cost 为空,请检查prefab是否缺乏组件"); } m_label_Exp_Now = fastComponent.FastGetComponent <UILabel>("Exp_Now"); if (null == m_label_Exp_Now) { Engine.Utility.Log.Error("m_label_Exp_Now 为空,请检查prefab是否缺乏组件"); } m_label_Exp_Cost = fastComponent.FastGetComponent <UILabel>("Exp_Cost"); if (null == m_label_Exp_Cost) { Engine.Utility.Log.Error("m_label_Exp_Cost 为空,请检查prefab是否缺乏组件"); } m_label_Locklevel = fastComponent.FastGetComponent <UILabel>("Locklevel"); if (null == m_label_Locklevel) { Engine.Utility.Log.Error("m_label_Locklevel 为空,请检查prefab是否缺乏组件"); } m_trans_MaxContent = fastComponent.FastGetComponent <Transform>("MaxContent"); if (null == m_trans_MaxContent) { Engine.Utility.Log.Error("m_trans_MaxContent 为空,请检查prefab是否缺乏组件"); } m_label_Formneed = fastComponent.FastGetComponent <UILabel>("Formneed"); if (null == m_label_Formneed) { Engine.Utility.Log.Error("m_label_Formneed 为空,请检查prefab是否缺乏组件"); } m_label_Mp = fastComponent.FastGetComponent <UILabel>("Mp"); if (null == m_label_Mp) { Engine.Utility.Log.Error("m_label_Mp 为空,请检查prefab是否缺乏组件"); } m_label_Name = fastComponent.FastGetComponent <UILabel>("Name"); if (null == m_label_Name) { Engine.Utility.Log.Error("m_label_Name 为空,请检查prefab是否缺乏组件"); } m_label_CD = fastComponent.FastGetComponent <UILabel>("CD"); if (null == m_label_CD) { Engine.Utility.Log.Error("m_label_CD 为空,请检查prefab是否缺乏组件"); } m_label_Level = fastComponent.FastGetComponent <UILabel>("Level"); if (null == m_label_Level) { Engine.Utility.Log.Error("m_label_Level 为空,请检查prefab是否缺乏组件"); } m_label_Describe = fastComponent.FastGetComponent <UILabel>("Describe"); if (null == m_label_Describe) { Engine.Utility.Log.Error("m_label_Describe 为空,请检查prefab是否缺乏组件"); } m_trans_MaxHideContent = fastComponent.FastGetComponent <Transform>("MaxHideContent"); if (null == m_trans_MaxHideContent) { Engine.Utility.Log.Error("m_trans_MaxHideContent 为空,请检查prefab是否缺乏组件"); } m_label_Describe_NextLevel = fastComponent.FastGetComponent <UILabel>("Describe_NextLevel"); if (null == m_label_Describe_NextLevel) { Engine.Utility.Log.Error("m_label_Describe_NextLevel 为空,请检查prefab是否缺乏组件"); } m_widget_skill_setting_area = fastComponent.FastGetComponent <UIWidget>("skill_setting_area"); if (null == m_widget_skill_setting_area) { Engine.Utility.Log.Error("m_widget_skill_setting_area 为空,请检查prefab是否缺乏组件"); } m_label_skill_setting_statename = fastComponent.FastGetComponent <UILabel>("skill_setting_statename"); if (null == m_label_skill_setting_statename) { Engine.Utility.Log.Error("m_label_skill_setting_statename 为空,请检查prefab是否缺乏组件"); } m_label_CurStateLabel = fastComponent.FastGetComponent <UILabel>("CurStateLabel"); if (null == m_label_CurStateLabel) { Engine.Utility.Log.Error("m_label_CurStateLabel 为空,请检查prefab是否缺乏组件"); } m__stateSpr = fastComponent.FastGetComponent <UITexture>("stateSpr"); if (null == m__stateSpr) { Engine.Utility.Log.Error("m__stateSpr 为空,请检查prefab是否缺乏组件"); } m_sprite_statelock = fastComponent.FastGetComponent <UISprite>("statelock"); if (null == m_sprite_statelock) { Engine.Utility.Log.Error("m_sprite_statelock 为空,请检查prefab是否缺乏组件"); } m_label_state_unlocklevel = fastComponent.FastGetComponent <UILabel>("state_unlocklevel"); if (null == m_label_state_unlocklevel) { Engine.Utility.Log.Error("m_label_state_unlocklevel 为空,请检查prefab是否缺乏组件"); } m_label_zhu_Label = fastComponent.FastGetComponent <UILabel>("zhu_Label"); if (null == m_label_zhu_Label) { Engine.Utility.Log.Error("m_label_zhu_Label 为空,请检查prefab是否缺乏组件"); } m_widget_SkillContainer = fastComponent.FastGetComponent <UIWidget>("SkillContainer"); if (null == m_widget_SkillContainer) { Engine.Utility.Log.Error("m_widget_SkillContainer 为空,请检查prefab是否缺乏组件"); } m_btn_btnStatus1 = fastComponent.FastGetComponent <UIButton>("btnStatus1"); if (null == m_btn_btnStatus1) { Engine.Utility.Log.Error("m_btn_btnStatus1 为空,请检查prefab是否缺乏组件"); } m_btn_btnStatus2 = fastComponent.FastGetComponent <UIButton>("btnStatus2"); if (null == m_btn_btnStatus2) { Engine.Utility.Log.Error("m_btn_btnStatus2 为空,请检查prefab是否缺乏组件"); } m_btn_btnClearSkillSet = fastComponent.FastGetComponent <UIButton>("btnClearSkillSet"); if (null == m_btn_btnClearSkillSet) { Engine.Utility.Log.Error("m_btn_btnClearSkillSet 为空,请检查prefab是否缺乏组件"); } if (null != fastComponent) { GameObject.Destroy(fastComponent); } }
/// <summary> /// Convenience function that figures out the panel's correct change flag by searching the parents. /// </summary> int GetChangeFlag(UINode start) { int flag = start.changeFlag; if (flag == -1) { Transform trans = start.trans.parent; UINode sub; // Keep going until we find a set flag for (;;) { // Check the parent's flag #if USE_SIMPLE_DICTIONARY if (trans != null && mChildren.TryGetValue(trans, out sub)) { #else if (trans != null && mChildren.Contains(trans)) { sub = (UINode)mChildren[trans]; #endif flag = sub.changeFlag; trans = trans.parent; // If the flag hasn't been set either, add this child to the hierarchy if (flag == -1) { mHierarchy.Add(sub); } else { break; } } else { flag = 0; break; } } // Update the parent flags for (int i = 0, imax = mHierarchy.size; i < imax; ++i) { UINode pc = mHierarchy.buffer[i]; pc.changeFlag = flag; } mHierarchy.Clear(); } return(flag); } /// <summary> /// Update the world-to-local transform matrix as well as clipping bounds. /// </summary> void UpdateTransformMatrix() { if (mUpdateTime == 0f || mMatrixTime != mUpdateTime) { mMatrixTime = mUpdateTime; mWorldToLocal = cachedTransform.worldToLocalMatrix; if (mClipping != UIDrawCall.Clipping.None) { Vector2 size = new Vector2(mClipRange.z, mClipRange.w); if (size.x == 0f) { size.x = (mCam == null) ? Screen.width : mCam.pixelWidth; } if (size.y == 0f) { size.y = (mCam == null) ? Screen.height : mCam.pixelHeight; } size *= 0.5f; mMin.x = mClipRange.x - size.x; mMin.y = mClipRange.y - size.y; mMax.x = mClipRange.x + size.x; mMax.y = mClipRange.y + size.y; } } } /// <summary> /// Run through all managed transforms and see if they've changed. /// </summary> void UpdateTransforms() { mChangedLastFrame = false; bool transformsChanged = false; bool shouldCull = false; #if UNITY_EDITOR shouldCull = (clipping != UIDrawCall.Clipping.None) && (!Application.isPlaying || mUpdateTime > mCullTime); if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled) #else shouldCull = (clipping != UIDrawCall.Clipping.None) && (mUpdateTime > mCullTime); if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled) #endif { #if USE_SIMPLE_DICTIONARY foreach (KeyValuePair <Transform, UINode> child in mChildren) { UINode node = child.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode node = (UINode)mChildren[i]; #endif if (node.trans == null) { mRemoved.Add(node.trans); continue; } if (node.HasChanged()) { node.changeFlag = 1; transformsChanged = true; #if UNITY_EDITOR Vector3 s = node.trans.lossyScale; float min = Mathf.Abs(Mathf.Min(s.x, s.y)); if (min == 0f) { Debug.LogError("Scale of 0 is invalid! Zero cannot be divided by, which causes problems. Use a small value instead, such as 0.01\n" + node.trans.lossyScale, node.trans); } #endif } else { node.changeFlag = -1; } } // Clean up the deleted transforms for (int i = 0, imax = mRemoved.Count; i < imax; ++i) { mChildren.Remove(mRemoved[i]); } mRemoved.Clear(); } // If the children weren't culled but should be, check their visibility if (!mCulled && shouldCull) { mCheckVisibility = true; } // If something has changed, propagate the changes *down* the tree hierarchy (to children). // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>() // in the loop above, and mark each one as dirty. if (mCheckVisibility || transformsChanged || mRebuildAll) { #if USE_SIMPLE_DICTIONARY foreach (KeyValuePair <Transform, UINode> child in mChildren) { UINode pc = child.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode pc = (UINode)mChildren[i]; #endif if (pc.widget != null) { int visibleFlag = 1; // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true') if (shouldCull || transformsChanged) { // If the change flag has not yet been determined... if (pc.changeFlag == -1) { pc.changeFlag = GetChangeFlag(pc); } // Is the widget visible? if (shouldCull) { visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag; } } // If visibility changed, mark the node as changed as well if (pc.visibleFlag != visibleFlag) { pc.changeFlag = 1; } // If the node has changed and the widget is visible (or was visible before) if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0)) { // Update the visibility flag pc.visibleFlag = visibleFlag; Material mat = pc.widget.material; // Add this material to the list of changed materials if (!mChanged.Contains(mat)) { mChanged.Add(mat); mChangedLastFrame = true; } } } } } mCulled = shouldCull; mCheckVisibility = false; mWidgetsAdded = false; } /// <summary> /// Update all widgets and rebuild their geometry if necessary. /// </summary> void UpdateWidgets() { #if USE_SIMPLE_DICTIONARY foreach (KeyValuePair <Transform, UINode> c in mChildren) { UINode pc = c.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode pc = (UINode)mChildren[i]; #endif UIWidget w = pc.widget; // If the widget is visible, update it if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(this, ref mWorldToLocal, (pc.changeFlag == 1), generateNormals)) { // We will need to refill this buffer if (!mChanged.Contains(w.material)) { mChanged.Add(w.material); mChangedLastFrame = true; } } pc.changeFlag = 0; } } /// <summary> /// Update the clipping rect in the shaders and draw calls' positions. /// </summary> public void UpdateDrawcalls() { Vector4 range = Vector4.zero; if (mClipping != UIDrawCall.Clipping.None) { range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f); } if (range.z == 0f) { range.z = Screen.width * 0.5f; } if (range.w == 0f) { range.w = Screen.height * 0.5f; } RuntimePlatform platform = Application.platform; if (platform == RuntimePlatform.WindowsPlayer || platform == RuntimePlatform.WindowsWebPlayer || platform == RuntimePlatform.WindowsEditor) { range.x -= 0.5f; range.y += 0.5f; } Transform t = cachedTransform; for (int i = 0, imax = mDrawCalls.size; i < imax; ++i) { UIDrawCall dc = mDrawCalls.buffer[i]; dc.clipping = mClipping; dc.clipRange = range; dc.clipSoftness = mClipSoftness; dc.depthPass = depthPass && mClipping == UIDrawCall.Clipping.None; // Set the draw call's transform to match the panel's. // Note that parenting directly to the panel causes unity to crash as soon as you hit Play. Transform dt = dc.transform; dt.position = t.position; dt.rotation = t.rotation; dt.localScale = t.lossyScale; } } /// <summary> /// Set the draw call's geometry responsible for the specified material. /// </summary> void Fill(Material mat) { // Cleanup deleted widgets for (int i = mWidgets.size; i > 0;) { if (mWidgets[--i] == null) { mWidgets.RemoveAt(i); } } // Fill the buffers for the specified material for (int i = 0, imax = mWidgets.size; i < imax; ++i) { UIWidget w = mWidgets.buffer[i]; if (w.visibleFlag == 1 && w.material == mat) { UINode node = GetNode(w.cachedTransform); if (node != null) { if (generateNormals) { w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans); } else { w.WriteToBuffers(mVerts, mUvs, mCols, null, null); } } else { Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this); } } } if (mVerts.size > 0) { // Rebuild the draw call's mesh UIDrawCall dc = GetDrawCall(mat, true); dc.depthPass = depthPass && mClipping == UIDrawCall.Clipping.None; dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols); } else { // There is nothing to draw for this material -- eliminate the draw call UIDrawCall dc = GetDrawCall(mat, false); if (dc != null) { mDrawCalls.Remove(dc); NGUITools.DestroyImmediate(dc.gameObject); } } // Cleanup mVerts.Clear(); mNorms.Clear(); mTans.Clear(); mUvs.Clear(); mCols.Clear(); } /// <summary> /// Main update function /// </summary> void LateUpdate() { mUpdateTime = Time.realtimeSinceStartup; UpdateTransformMatrix(); UpdateTransforms(); // Always move widgets to the panel's layer if (mLayer != gameObject.layer) { mLayer = gameObject.layer; UICamera uic = UICamera.FindCameraForLayer(mLayer); mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer); SetChildLayer(cachedTransform, mLayer); for (int i = 0, imax = drawCalls.size; i < imax; ++i) { mDrawCalls.buffer[i].gameObject.layer = mLayer; } } UpdateWidgets(); // If the depth has changed, we need to re-sort the widgets if (mDepthChanged) { mDepthChanged = false; mWidgets.Sort(UIWidget.CompareFunc); } // Fill the draw calls for all of the changed materials for (int i = 0, imax = mChanged.size; i < imax; ++i) { Fill(mChanged.buffer[i]); } // Update the clipping rects UpdateDrawcalls(); mChanged.Clear(); mRebuildAll = false; #if UNITY_EDITOR mScreenSize = new Vector2(Screen.width, Screen.height); #endif }