/// <summary> /// 创建按钮 /// </summary> private void CreateButton() { GameObject goParent = null; if (Selection.activeTransform != null) { goParent = Selection.activeTransform.gameObject; } else { goParent = NGUIEditorTools.SelectedRoot(true); } if (goParent != null) { var btnSprite = NGUISettings.AddSprite(goParent); Selection.activeGameObject = btnSprite.gameObject; var btn = btnSprite.gameObject;; btn.name = "Btn"; btn.AddComponent <UIButton>(); BtnOtherSet(btn); btn.AddComponent <BoxCollider>(); btnSprite.autoResizeBoxCollider = true; var btnLbl = NGUISettings.AddLabel(goParent); btnLbl.name = "BtnLbl"; btnLbl.applyGradient = false; btnLbl.depth = LabelDefaultDepth; btnLbl.transform.SetParent(btn.transform); } }
static public void AddSprite() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { Selection.activeGameObject = NGUISettings.AddSprite(go).gameObject; } //else Debug.Log("You must select a game object first."); }
static public void AddSprite() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Sprite"); #endif Selection.activeGameObject = NGUISettings.AddSprite(go).gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// Sprite creation function. /// </summary> void CreateSprite(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.DrawSpriteField("Sprite", "Sprite that will be created", NGUISettings.atlas, NGUISettings.selectedSprite, OnSprite, GUILayout.Width(120f)); if (!string.IsNullOrEmpty(NGUISettings.selectedSprite)) { GUILayout.BeginHorizontal(); NGUISettings.pivot = (UIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", NGUISettings.pivot, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Initial pivot point used by the sprite"); GUILayout.EndHorizontal(); } } if (ShouldCreate(go, NGUISettings.atlas != null)) { Selection.activeGameObject = NGUISettings.AddSprite(go).gameObject; } }