void _ShowRule() { GameObject.Destroy(m_goDrawGameMsg); m_uiOverTime = UIManager.Instance.CreateUI("UIOvertime"); NGUITools.BringForward(m_uiOverTime); }
void InitSquadItem() { squadItems[0] = CommonFunction.InstantiateObject(prefabRoleItem, squadGrid.transform).GetComponent <RoleItem>(); squadItems[0].gameObject.name += "0(Captain)"; NGUITools.BringForward(squadItems[0].gameObject); squadItems[0].status = RoleItem.Status.Captain; squadItems[0].role_id = MainPlayer.Instance.CaptainID; if (!single) { for (int i = 1; i <= 2; ++i) { squadItems[i] = CommonFunction.InstantiateObject(prefabRoleItem, squadGrid.transform).GetComponent <RoleItem>(); squadItems[i].gameObject.name += i + "(Assistant)"; NGUITools.BringForward(squadItems[i].gameObject); if (assistantsID[i - 1] != 0) { squadItems[i].status = RoleItem.Status.Selected; squadItems[i].role_id = assistantsID[i - 1]; } else { squadItems[i].status = RoleItem.Status.None; } squadItems[i].onReplace += OnReplace; } } }
/// <summary> /// Show the overlay. /// </summary> public void Show() { if (this.panel == null || this.IsVisible) { return; } // Bring the overlay panel behind the window if (UIWindow.current != null) { NGUITools.BringForward(this.gameObject); NGUITools.BringForward(UIWindow.current.gameObject); } // If this was invoked by a window event and that window uses fading if (UIWindow.current != null && UIWindow.current.fading) { // Use the same fade effect as the window TweenAlpha.Begin(this.panel.gameObject, UIWindow.current.fadeDuration, 1f); } else { this.panel.alpha = 1f; } }
public static void ShowUpdateTip(string message, Transform parent = null, UIEventListener.VoidDelegate onOKClick = null, UIEventListener.VoidDelegate onCancelClick = null, string okLabel = null, string cancelLabel = null) { if (parent == null) { UIManager.Instance.CreateUIRoot(); parent = UIManager.Instance.m_uiRootBasePanel.transform; } GameObject popup_message_prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/PopupUpdateTip") as GameObject; GameObject popup_message_obj = CommonFunction.InstantiateObject(popup_message_prefab, parent); Vector3 position = popup_message_obj.transform.localPosition; position.z = -500; popup_message_obj.transform.localPosition = position; NGUITools.BringForward(popup_message_obj); popup_message_obj.transform.FindChild("Window/Message").GetComponent <UILabel>().text = message; GameObject buttonOK = popup_message_obj.transform.FindChild("Window/ButtonOK").gameObject; GameObject buttonCancel = popup_message_obj.transform.FindChild("Window/ButtonCancel").gameObject; UIEventListener.Get(buttonOK).onClick += (go) => NGUITools.Destroy(popup_message_obj); UIEventListener.Get(buttonCancel).onClick += (go) => NGUITools.Destroy(popup_message_obj); if (onOKClick != null) { UIEventListener.Get(buttonOK).onClick += onOKClick; } if (onCancelClick != null) { UIEventListener.Get(buttonCancel).onClick += onCancelClick; } }
void _OnPlayTrack() { foreach (Player player in GameSystem.Instance.mClient.mPlayerManager) { player.Show(!(m_match is GameMatch_PVP)); player.model.EnableGrey(false); player.m_enableAction = false; if (player.m_catchHelper != null) { player.m_catchHelper.enabled = false; } player.m_enablePickupDetector = false; player.m_enableMovement = false; player.m_enableAction = false; if (player.m_InfoVisualizer != null) { player.m_InfoVisualizer.SetActive(false); } if (player.m_AOD != null) { player.m_AOD.visible = false; } player.HideIndicator(); if (player.m_aiMgr != null) { player.m_aiMgr.m_enable = false; } } if (m_match.m_uiMatch != null) { m_match.m_gameMatchCountStop = true; m_match.m_count24TimeStop = true; } GameObject resOverTime = ResourceLoadManager.Instance.LoadPrefab("Prefab/Camera/OverTime"); GameObject goOverTime = GameObject.Instantiate(resOverTime) as GameObject; if (goOverTime == null) { Debug.LogError("can not find goOverTime prefab."); } m_goDrawGameMsg.SetActive(true); NGUITools.BringForward(m_goDrawGameMsg); m_trackPlayer.LoadTrack(goOverTime); m_trackPlayer.Play(m_match.mainRole.m_team.m_side == Team.Side.eHome ? 0 : 1); PlaySoundManager.Instance.PlaySound(MatchSoundEvent.MatchOverTime); GameObject.Destroy(m_uiOverTime); }
static int BringForward(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject)); NGUITools.BringForward(arg0); return(0); }
void OnEnable() { NGUITools.BringForward(this.gameObject); avatar = Avatar.Create(table.TableAvatar.Where(MainRole.ServerInfo.userdata.profession, MainRole.ServerInfo.userdata.sexman)); avatar.name = "RoleInfoAvatar.avatar"; avatar.transform.position = new Vector3(-10, 0, 0); avatar.transform.Rotate(0, 0, 0); avatar.transform.localScale = new Vector3(5, 5, 5); }
/// <summary> /// 界面加到最上层 /// </summary> /// <returns>为界面新创建的父Panel,界面销毁时需要销毁这个父panel</returns> /// <param name="gogui">界面</param> /// <param name="bModal">If set to <c>true</c> b modal.</param> public static GameObject AddGuiToTop(GameObject gogui, bool bModal = true) { var root = GameObject.Find("UI Root"); // 创建一个depth最大的panel var panels = root.GetComponentsInChildren <UIPanel>(); var maxdepth = 0; foreach (var t in panels) { if (t.depth > maxdepth) { maxdepth = t.depth; } } maxdepth += 1; var gopanel = new GameObject("Panel" + maxdepth); var panel = gopanel.AddComponent <UIPanel>(); panel.depth = maxdepth; gopanel.layer = root.layer; gopanel.transform.parent = root.transform; gopanel.transform.localScale = Vector3.one; gopanel.transform.position = Vector3.zero; // 为当前界面创建一个接收所有输入的UISprite,模拟模态窗口 if (bModal == true) { var gosprite = new GameObject("SpriteLayer"); var sprite = gosprite.AddComponent <UISprite>(); sprite.SetDimensions(0, 0); sprite.GetComponent <UIWidget>().depth = -1000; var col = gosprite.AddComponent <BoxCollider>(); col.size = new Vector3(panel.width, panel.height, 0); gosprite.layer = gogui.layer; gosprite.transform.parent = gogui.transform; gosprite.transform.position = Vector3.zero; } // 界面加入之前创建的panel gogui.layer = gopanel.layer; gogui.transform.parent = gopanel.transform; gogui.transform.localScale = Vector3.one; gogui.transform.position = Vector3.zero; var widget = gogui.GetComponent <UIWidget>(); if (widget != null) { widget.SetAnchor(gopanel, 0, 0, 0, 0); } NGUITools.BringForward(gogui); return(gopanel); }
static public int BringForward_s(IntPtr l) { try { UnityEngine.GameObject a1; checkType(l,1,out a1); NGUITools.BringForward(a1); pushValue(l,true); return 1; } catch(Exception e) { return error(l,e); } }
public static void Show(GameObject go) { if (!GlobalConst.IS_GUIDE) { return; } GameObject panel = UIManager.Instance.CreateUI("Prefab/GUI/DebugStartGuide"); NGUITools.BringForward(panel); UIEventListener.Get(panel.transform.FindChild("Start").gameObject).onClick += OnStartGuide; UIEventListener.Get(panel.transform.FindChild("Close").gameObject).onClick += OnClose; }
public void AdjustDepths() { /* Frame buttons et al should be in front of all else * Backgrounds behind * Body and scrolling contents somewhere between */ NGUITools.PushBack(backPanel.gameObject); NGUITools.BringForward(forePanel.gameObject); if (parentPage != null) { parentPage.AdjustDepths(); } }
protected override void OnDragDropStart() { onRelease = transform.parent.FindChild("Icon").GetComponent <ItemAssistRoleDrag>().onRelease; base.OnDragDropStart(); //UICamera.currentTouch.dragged.transform.FindChild("GetInfo").gameObject.SetActive(false); //UICamera.currentTouch.dragged.transform.FindChild("Name").gameObject.SetActive(false); //UICamera.currentTouch.dragged.transform.FindChild("Position").gameObject.SetActive(false); //UICamera.currentTouch.dragged.transform.GetComponent<UISprite>().enabled = false; UICamera.currentTouch.dragged.transform.FindChild("Side").gameObject.SetActive(false); NGUITools.BringForward(UICamera.currentTouch.dragged); }
override public void OnEnter(MatchState lastState) { base.OnEnter(lastState); InputReader.Instance.enabled = false; NGUITools.SetActive(match.slotMachine.gameObject, true); NGUITools.BringForward(match.slotMachine.gameObject); match.slotMachine.onCreateItem += OnCreateSlotMachineItem; match.slotMachine.onEnd += OnSlotMachineEnd; timerBegin = new GameUtils.Timer(IM.Number.one, BeginSlotMachine); timerBegin.stop = false; }
static int BringForward(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.GameObject)); NGUITools.BringForward(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private LuaComponent PopPauseDlg(Transform parent, UIEventListener.VoidDelegate outClick, UIEventListener.VoidDelegate continueClick) { GameObject go = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/UIPause") as GameObject; GameObject go_clone = CommonFunction.InstantiateObject(go, parent); go_clone.transform.localPosition = go_clone.transform.localPosition; LuaComponent popup_message = go_clone.GetComponent <LuaComponent>(); popup_message.table.Set("outClicked", outClick); popup_message.table.Set("continueClicked", continueClick); NGUITools.BringForward(go_clone); return(popup_message); }
/// <summary> /// Focuses this window. /// </summary> public void Focus() { if (this.isFocused) { return; } // Prevent focus spamm this.isFocused = true; // Call the static on focused window OnFocusedWindow(this.WindowId); // Bring the window forward NGUITools.BringForward(this.gameObject); }
void Replace() { if (!isReplaced) { GameObject obj = GameObject.Instantiate(prefab) as GameObject; obj.name = gameObject.name; obj.transform.parent = transform.parent; obj.transform.localPosition = transform.localPosition; obj.transform.localRotation = transform.localRotation; obj.transform.localScale = transform.localScale; NGUITools.Destroy(gameObject); NGUITools.BringForward(obj); spawnedObj = obj; isReplaced = true; } }
/// <summary> /// 切换给定的SelectTargetX类型展示器可见,并返回其实例 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T Toggle <T>() where T : MonoBehaviour { var present = default(T); foreach (var c in this.transform.GetAllChildren()) { var p = c.gameObject.GetComponent <T>(); c.gameObject.SetActive(p != null); if (p != null) { present = p; } } NGUITools.BringForward(present.gameObject); Debug.Log(string.Format("SelectTarget: <color=green>{0}</color>", typeof(T).Name)); return(present); }
void InitListItem() { listGrid.cellHeight = prefabRoleItem.GetComponent <UIWidget>().height; int index = 0; foreach (Player player in MainPlayer.Instance.PlayerList) { RoleItem item = CommonFunction.InstantiateObject(prefabRoleItem, listGrid.transform).GetComponent <RoleItem>(); item.gameObject.name += (index++).ToString(); listItems.Add(item); NGUITools.BringForward(item.gameObject); item.GetComponent <UIWidget>().width = roleList.width; item.status = RoleItem.Status.Candidate; item.role_id = player.m_roleInfo.id; item.onJoin += OnJoin; } }
private static int BringForward(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 1); GameObject go = (GameObject)ToLua.CheckUnityObject(L, 1, typeof(GameObject)); NGUITools.BringForward(go); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
public static MessageBox Show(string title, string message, UIEventListener.VoidDelegate onOK = null, UIEventListener.VoidDelegate onCancel = null) { var root = GameObject.Find("UI Root"); var my = NGUITools.AddChild(root, (GameObject)Resources.Load("Prefabs/Gui/MessageBox")).GetComponent <MessageBox>(); my.GetComponent <UIWidget>().SetAnchor(root, 0, 0, 0, 0); NGUITools.BringForward(my.gameObject); my.messageBoxTitle.text = title ?? string.Empty; my.messageBoxText.text = message; onCancel = onCancel ?? my.Close; onOK = onOK ?? onCancel; UIEventListener.Get(my.messageBoxOK).onClick = onOK; UIEventListener.Get(my.messageBoxCancel).onClick = onCancel; return(my); }
protected void _DoShowUI(ShowHideDirection dir) { StopAllCoroutines(); NGUITools.SetActive(gameObject, true); gameObject.AddMissingComponent <UIManagedPanel>(); NGUITools.BringForward(gameObject); if (GetComponent <Animation>() && GetComponent <Animation>().enabled) { GetComponent <Animation>().Rewind(); if (dir == ShowHideDirection.left) { GetComponent <Animation>().Play("UIRollInL"); } else if (dir == ShowHideDirection.right) { GetComponent <Animation>().Play("UIRollInR"); } } }
override public void OnEnter(MatchState lastState) { base.OnEnter(lastState); foreach (Player player in GameSystem.Instance.mClient.mPlayerManager) { player.m_enableAction = false; player.m_enableMovement = false; player.m_enablePickupDetector = false; player.Hide(); } InputReader.Instance.enabled = false; NGUITools.SetActive(match.slotMachine.gameObject, true); NGUITools.BringForward(match.slotMachine.gameObject); match.slotMachine.onCreateItem += OnCreateSlotMachineItem; match.slotMachine.onEnd += OnSlotMachineEnd; timerBegin = new GameUtils.Timer(IM.Number.one, BeginSlotMachine); timerBegin.stop = false; }
//void Update() //{ //UIPanel panel = _widget.parent.GetComponent<UIPanel>(); //panel.clipping = UIDrawCall.Clipping.SoftClip; //panel.baseClipRegion = new Vector4(_widget.width / 2, -_widget.height / 2 - _widget.height % 2, _widget.width, _widget.height); //panel.clipSoftness = new Vector2(0, 0); //} //private void OnTeamBarClick(GameObject go) //{ // ToggleRoleItem(); //} //private void ToggleRoleItem() //{ // if (_role_item == null) // { // CreateRoleItem(); // } // if (_role_item.gameObject.activeSelf) // { // TweenHeight tween_height = _widget.GetComponent<TweenHeight>(); // tween_height.from = _team_bar.height + _role_item.height; // tween_height.to = _team_bar.height; // tween_height.ResetToBeginning(); // tween_height.PlayForward(); // tween_height.AddOnFinished(OnFinished); // } // else // { // _role_item.gameObject.SetActive(true); // TweenHeight tween_height = _widget.GetComponent<TweenHeight>(); // tween_height.from = _team_bar.height; // tween_height.to = _team_bar.height + _role_item.height; // tween_height.ResetToBeginning(); // tween_height.PlayForward(); // tween_height.onFinished.Clear(); // } //} //private void OnFinished() //{ // _role_item.gameObject.SetActive(false); //} private void CreateRoleItem(uint index) { GameObject role_item_obj = GameSystem.Instance.mClient.mUIManager.CreateUI("Prefab/GUI/RoleItemPVPSelf", _widget.transform); NGUITools.BringForward(role_item_obj); UIWidget role_item_widget = role_item_obj.GetComponent <UIWidget>(); _role_item_widget[index] = role_item_widget; role_item_widget.leftAnchor.target = _widget.transform; role_item_widget.leftAnchor.Set(0f, 0); role_item_widget.rightAnchor.target = _widget.transform; role_item_widget.rightAnchor.Set(1f, 0); role_item_widget.topAnchor.target = _widget.transform; role_item_widget.topAnchor.Set(0f, role_item_widget.height * (_role_count - index)); role_item_widget.bottomAnchor.target = _widget.transform; role_item_widget.bottomAnchor.Set(0f, role_item_widget.height * (_role_count - index - 1)); role_item_obj.SetActive(true); role_item_widget.ResetAnchors(); role_item_widget.UpdateAnchors(); _role_item[index] = role_item_obj.GetComponent <RoleItemReady>(); }
override public void OnEnter(MatchState lastState) { base.OnEnter(lastState); GuideStep step = GameSystem.Instance.GuideConfig.GetStep(guideStepID); GameObject prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/GuideMask") as GameObject; maskPanel = NGUITools.AddChild <UIPanel>(GameSystem.Instance.mClient.mUIManager.m_uiRootBasePanel); maskPanel.gameObject.AddComponent <UIManagedPanel>(); NGUITools.BringForward(maskPanel.gameObject); GameObject obj = CommonFunction.InstantiateObject(prefab, maskPanel.transform); obj.GetComponent <UIWidget>().alpha = 0f; UIEventListener.Get(obj).onClick += OnClick; GuideSystem.Instance.ShowTip(GuideSystem.Instance.curStep); GameObject areaPrefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/Indicator/pre_SkillGuideArea") as GameObject; indicator = GameObject.Instantiate(areaPrefab) as GameObject; timer.stop = false; }
/// <summary> /// 渐变提示框 /// </summary> /// <param name="message"></param> /// <param name="parent"></param> /// <returns></returns> public static LuaComponent ShowTip(string message, Transform parent = null) { //if (parent == null) // parent = GameSystem.Instance.mClient.mUIManager.m_uiRootBasePanel.transform; //GameObject tipWithTweenObj = UIManager.Instance.CreateUI("Prefab/GUI/TipWithTween", parent); //TipWithTween tipWithTween = tipWithTweenObj.GetComponent<TipWithTween>(); //tipWithTween.message = message; //Vector3 pos = tipWithTweenObj.transform.localPosition; //tipWithTweenObj.transform.localPosition = new Vector3(pos.x, pos.y, -450.0f); //tipWithTweenObj.GetComponent<UIPanel>().depth = 5000; //return tipWithTween; if (parent == null) { UIManager.Instance.CreateUIRoot(); parent = UIManager.Instance.m_uiRootBasePanel.transform; } GameObject popup_message_prefab; if (message.Contains("[-]")) { popup_message_prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/TipWithTween") as GameObject; } else { popup_message_prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/PopupMessage") as GameObject; } GameObject popup_message_obj = CommonFunction.InstantiateObject(popup_message_prefab, parent); Vector3 position = popup_message_obj.transform.localPosition; position.z = -500; popup_message_obj.transform.localPosition = position; LuaComponent popup_message = popup_message_obj.GetComponent <LuaComponent>(); //popup_message.table.Set("message", message); LuaInterface.LuaFunction func = popup_message.table["SetMessage"] as LuaInterface.LuaFunction; func.Call(new object[] { popup_message.table, message }); NGUITools.BringForward(popup_message_obj); return(popup_message); }
private T ShowRightPanel <T>() where T : MonoBehaviour { T show = null; foreach (var t in new System.Type[] { typeof(RoleInfoPackage), typeof(RoleInfoValue) }) { if (t == typeof(T)) { show = BattleScene.Instance.Gui(t) as T; show.gameObject.SetActive(true); NGUITools.BringForward(show.gameObject); } else { var hide = BattleScene.Instance.Gui(t); hide.gameObject.SetActive(false); } } NGUITools.BringForward(this.GetComponent <Closeable>().closeButton.gameObject); return(show); }
public static LuaComponent ShowPopupMsg(string message, Transform parent = null, UIEventListener.VoidDelegate onOKClick = null, UIEventListener.VoidDelegate onCancelClick = null, string okLabel = null, string cancelLabel = null) { if (parent == null) { UIManager.Instance.CreateUIRoot(); parent = UIManager.Instance.m_uiRootBasePanel.transform; } if (onCancelClick == null) { if (okLabel == null) { okLabel = GetConstString("BUTTON_OK"); } if (cancelLabel == null) { cancelLabel = ""; } } else { if (okLabel == null) { okLabel = GetConstString("BUTTON_CONFIRM"); } if (cancelLabel == null) { cancelLabel = GetConstString("BUTTON_CANCEL"); } } GameObject popup_message_prefab; if (message.Contains("[-]")) { popup_message_prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/TipWithTween") as GameObject; } else { if (onCancelClick == null) { popup_message_prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/PopupMessage") as GameObject; } else { popup_message_prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/PopupMessage1") as GameObject; } } GameObject popup_message_obj = CommonFunction.InstantiateObject(popup_message_prefab, parent); Vector3 position = popup_message_obj.transform.localPosition; position.z = -500; popup_message_obj.transform.localPosition = position; LuaComponent popup_message = popup_message_obj.GetComponent <LuaComponent>(); //popup_message.table.Set("message", message); LuaInterface.LuaFunction func = popup_message.table["SetMessage"] as LuaInterface.LuaFunction; func.Call(new object[] { popup_message.table, message, message.Length > 12 }); popup_message.table.Set("onOKClick", onOKClick); popup_message.table.Set("onCancelClick", onCancelClick); popup_message.table.Set("okLabel", okLabel); popup_message.table.Set("cancelLabel", cancelLabel); NGUITools.BringForward(popup_message_obj); return(popup_message); }
/// <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) { NGUITools.BringForward(Selection.activeGameObject); }, null); AddItem(myName + "/Push to Back", false, delegate(object obj) { NGUITools.PushBack(Selection.activeGameObject); }, null); AddItem(myName + "/Nudge Forward", false, delegate(object obj) { NGUITools.AdjustDepth(Selection.activeGameObject, 1); }, null); AddItem(myName + "/Nudge Back", false, delegate(object obj) { NGUITools.AdjustDepth(Selection.activeGameObject, -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); #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2 AddChildWidget("Create/Unity 2D Sprite/Child", false, NGUISettings.Add2DSprite); #endif 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); #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2 AddSiblingWidget("Create/Unity 2D Sprite/Sibling", false, NGUISettings.Add2DSprite); #endif } 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); #if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2 AddChildWidget("Create/Unity 2D Sprite", false, NGUISettings.Add2DSprite); #endif } 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, delegate(object obj) { target.AddComponent <UIScrollView>(); }, null); NGUIContextMenu.AddSeparator("Attach/"); } } else if (target.collider == null) { AddItem("Attach/Box Collider", false, delegate(object obj) { NGUITools.AddWidgetCollider(target); }, null); NGUIContextMenu.AddSeparator("Attach/"); } if (target.collider != null) { if (target.GetComponent <UIDragScrollView>() == null) { for (int i = 0; i < UIPanel.list.size; ++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); NGUIContextMenu.AddSeparator("Attach/"); break; } } AddItem("Attach/Button Script", false, delegate(object obj) { target.AddComponent <UIButton>(); }, null); AddItem("Attach/Toggle Script", false, delegate(object obj) { target.AddComponent <UIToggle>(); }, null); AddItem("Attach/Slider Script", false, delegate(object obj) { target.AddComponent <UISlider>(); }, null); AddItem("Attach/Scroll Bar Script", false, delegate(object obj) { target.AddComponent <UIScrollBar>(); }, null); AddItem("Attach/Progress Bar Script", false, delegate(object obj) { target.AddComponent <UISlider>(); }, null); AddItem("Attach/Popup List Script", false, delegate(object obj) { target.AddComponent <UIPopupList>(); }, null); AddItem("Attach/Input Field Script", false, delegate(object obj) { target.AddComponent <UIInput>(); }, null); NGUIContextMenu.AddSeparator("Attach/"); if (target.GetComponent <UIAnchor>() == null) { AddItem("Attach/Anchor Script", false, delegate(object obj) { target.AddComponent <UIAnchor>(); }, null); } if (target.GetComponent <UIStretch>() == null) { AddItem("Attach/Stretch Script", false, delegate(object obj) { target.AddComponent <UIStretch>(); }, null); } AddItem("Attach/Key Binding Script", false, delegate(object obj) { target.AddComponent <UIKeyBinding>(); }, null); NGUIContextMenu.AddSeparator("Attach/"); AddItem("Attach/Play Tween Script", false, delegate(object obj) { target.AddComponent <UIPlayTween>(); }, null); AddItem("Attach/Play Animation Script", false, delegate(object obj) { target.AddComponent <UIPlayAnimation>(); }, null); AddItem("Attach/Play Sound Script", false, delegate(object obj) { target.AddComponent <UIPlaySound>(); }, null); } 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"); } } }
/// <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/"); } } else if (target.GetComponent <Collider>() == null && target.GetComponent <Collider2D>() == null) { 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 (target.GetComponent <Collider>() != null || target.GetComponent <Collider2D>() != null) { 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(UIProgressBar)); 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"); } } }