Exemplo n.º 1
0
    public static GameObject InstantiateObject(GameObject prefab, Transform parent)
    {
        if (prefab == null)
        {
            return(null);
        }
        //Debug.Log("------------InstantiateObject() -- " + prefab.name);
        GameObject clone = GameObject.Instantiate(prefab) as GameObject;

        if (clone != null && parent != null)
        {
            clone.transform.parent        = parent;
            clone.transform.localPosition = Vector3.zero;
            clone.transform.localRotation = Quaternion.identity;
            clone.transform.localScale    = prefab.transform.localScale;
            if (clone.GetComponent <UIPanel>() == null)
            {
                UIWidget   widget       = NGUITools.FindInParents <UIWidget>(parent);
                UIWidget[] cloneWidgets = clone.GetComponentsInChildren <UIWidget>(true);
                if (cloneWidgets != null && cloneWidgets.Length > 0 && widget != null)
                {
                    NGUITools.AdjustDepth(clone, widget.depth + 1);
                }
            }
        }
        return(clone);
    }
Exemplo n.º 2
0
 static public void BringForward()
 {
     for (int i = 0; i < Selection.gameObjects.Length; ++i)
     {
         NGUITools.AdjustDepth(Selection.gameObjects[i], 1);
     }
 }
 public void OnDepthAdjust()
 {
     if (mTargetMenuButton != null)
     {
         NGUITools.AdjustDepth(mTargetMenuButton.gameObject, 10);
     }
 }
Exemplo n.º 4
0
    public T CreateLoadingDialog <T>() where T : View <ViewModelBase>, ILoadingDialog
    {
        if ((_loadingDialog as MonoBehaviour) != null && !(_loadingDialog is T))
        {
            CloseLoadingDialog();
        }

        if ((_loadingDialog as MonoBehaviour) == null)
        {
            var t    = typeof(T).GetCustomAttributes(typeof(ResourcePathAttribute), false);
            var attr = t.FirstOrDefault() as ResourcePathAttribute;

            if (attr == null)
            {
                throw new Exception("Can't create loading dialog: attribute resources not defined " +
                                    typeof(T).Name);
            }

            var prefab = attr.IsLocalResource
                ? Resources.Load <GameObject>(attr.Path)
                : ResourceStorage.Instance.Get <GameObject>(attr.Path);

            _loadingDialog = AddToDialog <T>(prefab);
            var go = ((Component)_loadingDialog).gameObject;
            NGUITools.AdjustDepth(go, GuiConstants.Depths.LoadingDialog);
            _dialogManager.SetCurrentDialog(_loadingDialog as IView);
        }

        return(_loadingDialog as T);
    }
Exemplo n.º 5
0
 static public void PushBack()
 {
     for (int i = 0; i < Selection.gameObjects.Length; ++i)
     {
         NGUITools.AdjustDepth(Selection.gameObjects[i], -1);
     }
 }
 public void OnDepthAdjust()
 {
     if (this.mTargetMenuButton != null)
     {
         NGUITools.AdjustDepth(this.mTargetMenuButton.get_gameObject(), 10);
     }
 }
Exemplo n.º 7
0
 static public void PushBack2()
 {
     for (int i = 0; i < Selection.gameObjects.Length; ++i)
     {
         NGUITools.AdjustDepth(Selection.gameObjects[i], -1000);
     }
     NGUITools.NormalizeDepths();
 }
Exemplo n.º 8
0
 static public void BringForward2()
 {
     for (int i = 0; i < Selection.gameObjects.Length; ++i)
     {
         NGUITools.AdjustDepth(Selection.gameObjects[i], 1000);
     }
     NGUITools.NormalizeDepths();
 }
 public void Initialize(UIPortMenuButton targetMenuButton)
 {
     if (mTargetMenuButton != null)
     {
         NGUITools.AdjustDepth(mTargetMenuButton.gameObject, -10);
         mTargetMenuButton = null;
     }
     mTargetMenuButton = targetMenuButton;
 }
 public void Initialize(UIPortMenuButton targetMenuButton)
 {
     if (this.mTargetMenuButton != null)
     {
         NGUITools.AdjustDepth(this.mTargetMenuButton.get_gameObject(), -10);
         this.mTargetMenuButton = null;
     }
     this.mTargetMenuButton = targetMenuButton;
 }
Exemplo n.º 11
0
 static public void BringForward()
 {
     for (int i = 0; i < Selection.gameObjects.Length; ++i)
     {
         GameObject go = Selection.gameObjects[i];
         NGUITools.AdjustDepth(go, 1);
         NGUITools.UpdateWidgetColliderDepth(go);
     }
 }
Exemplo n.º 12
0
    private static int AdjustDepth(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        GameObject go         = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject));
        int        adjustment = (int)LuaScriptMgr.GetNumber(L, 2);
        int        d          = NGUITools.AdjustDepth(go, adjustment);

        LuaScriptMgr.Push(L, d);
        return(1);
    }
Exemplo n.º 13
0
    static int AdjustDepth(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject));
        int        arg1 = (int)LuaScriptMgr.GetNumber(L, 2);
        int        o    = NGUITools.AdjustDepth(arg0, arg1);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemplo n.º 14
0
    public GameObject CreateUI(string strResPath, Transform parent = null)
    {
        Object res = null;

        if (m_uiRootBasePanel == null)
        {
            CreateUIRoot();
        }

        if (strResPath.Contains("Prefab/GUI/"))
        {
            strResPath = strResPath;
        }
        else if (strResPath.StartsWith("Items"))
        {
            strResPath = "Prefab/" + strResPath;
        }
        else if (!strResPath.Contains("Prefab/GUI/") &&
                 (!strResPath.Contains("Prefab/GUI/")))
        {
            strResPath = "Prefab/GUI/" + strResPath;
        }

        if (!m_UICache.TryGetValue(strResPath, out res))
        {
            //if (strResPath.Contains("UILogo"))
            //    res = ResourceLoadManager.Instance.GetResources(strResPath) as GameObject;
            //else
            res = ResourceLoadManager.Instance.LoadPrefab(strResPath) as GameObject;
            if (res == null)
            {
                return(null);
            }
            else
            {
                m_UICache.Add(strResPath, res);
            }
        }
        GameObject ui = GameObject.Instantiate(res) as GameObject;

        ui.transform.parent        = (parent != null ? parent : m_uiRootBasePanel.transform);
        ui.transform.localScale    = Vector3.one;
        ui.transform.localPosition = (res as GameObject).transform.localPosition;

        if (ui.GetComponent <UIPanel>() == null)
        {
            UIWidget widget = NGUITools.FindInParents <UIWidget>(ui.transform.parent);
            if (ui.GetComponentInChildren <UIWidget>() != null && widget != null)
            {
                NGUITools.AdjustDepth(ui, widget.depth + 1);
            }
        }
        return(ui);
    }
Exemplo n.º 15
0
    static public void PushBack()
    {
        var val = 0;

        for (var i = 0; i < Selection.gameObjects.Length; ++i)
        {
            val |= NGUITools.AdjustDepth(Selection.gameObjects[i], -1);
        }
        if (((val & 1) != 0) && UIPanelTool.instance != null)
        {
            UIPanelTool.instance.Repaint();
        }
    }
Exemplo n.º 16
0
    static public void BringForward()
    {
        int val = 0;

        for (int i = 0; i < Selection.gameObjects.Length; ++i)
        {
            val |= NGUITools.AdjustDepth(Selection.gameObjects[i], 1);
        }
        if (((val & 1) != 0) && UIPanelTool.instance != null)
        {
            UIPanelTool.instance.Repaint();
        }
    }
Exemplo n.º 17
0
    // Token: 0x060032C9 RID: 13001 RVA: 0x000FF5D8 File Offset: 0x000FD9D8
    public static void BringForward(GameObject go)
    {
        int num = NGUITools.AdjustDepth(go, 1000);

        if (num == 1)
        {
            NGUITools.NormalizePanelDepths();
        }
        else if (num == 2)
        {
            NGUITools.NormalizeWidgetDepths();
        }
    }
Exemplo n.º 18
0
    // Token: 0x060032CA RID: 13002 RVA: 0x000FF610 File Offset: 0x000FDA10
    public static void PushBack(GameObject go)
    {
        int num = NGUITools.AdjustDepth(go, -1000);

        if (num == 1)
        {
            NGUITools.NormalizePanelDepths();
        }
        else if (num == 2)
        {
            NGUITools.NormalizeWidgetDepths();
        }
    }
Exemplo n.º 19
0
	static public int AdjustDepth_s(IntPtr l) {
		try {
			UnityEngine.GameObject a1;
			checkType(l,1,out a1);
			System.Int32 a2;
			checkType(l,2,out a2);
			var ret=NGUITools.AdjustDepth(a1,a2);
			pushValue(l,true);
			pushValue(l,ret);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Exemplo n.º 20
0
 static int AdjustDepth(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.GameObject));
         int arg1 = (int)LuaDLL.luaL_checknumber(L, 2);
         int o    = NGUITools.AdjustDepth(arg0, arg1);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 21
0
    void Replace()
    {
        UIWidget widget = GetComponentInChildren <UIWidget>();

        if (widget == null)
        {
            Debug.LogError("Widget placeholder can not be used without widget.");
        }
        GameObject obj        = GameObject.Instantiate(prefab) as GameObject;
        UIWidget   new_widget = obj.GetComponentInChildren <UIWidget>();

        if (new_widget == null)
        {
            Debug.LogError("The prefab isn't a widget.");
        }
        obj.name                    = gameObject.name;
        obj.transform.parent        = transform.parent;
        obj.transform.localPosition = transform.localPosition;
        obj.transform.localRotation = transform.localRotation;
        obj.transform.localScale    = transform.localScale;
        new_widget.alpha            = widget.alpha;
        Bounds bounds = widget.CalculateBounds(transform.parent);

        new_widget.SetRect(bounds.min.x, bounds.min.y, bounds.size.x, bounds.size.y);
        new_widget.width           = widget.width;
        new_widget.height          = widget.height;
        new_widget.aspectRatio     = widget.aspectRatio;
        new_widget.keepAspectRatio = widget.keepAspectRatio;
        new_widget.leftAnchor      = widget.leftAnchor;
        new_widget.rightAnchor     = widget.rightAnchor;
        new_widget.topAnchor       = widget.topAnchor;
        new_widget.bottomAnchor    = widget.bottomAnchor;
        new_widget.ResetAnchors();
        new_widget.UpdateAnchors();
        NGUITools.AdjustDepth(new_widget.gameObject, widget.depth - new_widget.depth);
        UIPanel panel = GetComponent <UIPanel>();

        if (panel != null)
        {
            UIPanel new_panel = obj.GetComponent <UIPanel>();
            NGUITools.AdjustDepth(new_panel.gameObject, panel.depth - new_panel.depth);
        }
        NGUITools.Destroy(gameObject);
        gameObject.SetActive(false);            //TODO: Sometimes, it will not be destroyed.
        spawnedObj = obj;
    }
Exemplo n.º 22
0
    public bool CreateTopLayer(Transform topLayer)
    {
        if (camera2D == null)
        {
            return(false);
        }

        topLayer.parent     = camera2D.transform;
        topLayer.localScale = new Vector3(1, 1, 1);
        NGUITools.AdjustDepth(topLayer.gameObject, TOP_DEPTH);
        topLayer.GetComponent <UIPanel>().depth = TOP_DEPTH;

        Vector3 localPos = topLayer.localPosition;

        localPos.z             = currentZ;
        topLayer.localPosition = new Vector3(0, 0, currentZ);
        return(true);
    }
Exemplo n.º 23
0
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);

        HitTest = false;

        transform.DOMove(SlotPostion, 0.2f);
        NGUITools.AdjustDepth(gameObject, -100);

        if (mCardRole != null)
        {
            mCardRole.HideHighlighter();
        }
        PureMVC.Patterns.Facade.Instance.SendNotification(NotificationID.Fihgt_ShowOpPan, false);

        mCardRole = null;
        mUpdateHitTestCardRole = null;
    }
Exemplo n.º 24
0
    private static int AdjustDepth(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 2);
            GameObject go         = (GameObject)ToLua.CheckUnityObject(L, 1, typeof(GameObject));
            int        adjustment = (int)LuaDLL.luaL_checknumber(L, 2);
            int        n          = NGUITools.AdjustDepth(go, adjustment);
            LuaDLL.lua_pushinteger(L, n);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
Exemplo n.º 25
0
    public void BringPanelForward(GameObject go)
    {
        UIManagedPanel panel = go.GetComponent <UIManagedPanel>();

        if (panel == null)
        {
            Debug.LogError("BringPanelForward: Can not use BringPanelForward without UIManagedPanel. Name: " + go.name);
            return;
        }

        /*
         * if (!panelList.Contains(panel))
         * {
         *  Debug.LogError("BringPanelForward: The panel is not managed, check whether it's top level panel parent has component UIManagedPanel. Name: " + go.name);
         *  return;
         * }
         */
        NGUITools.AdjustDepth(go, 1000);
        NormalizePanelDepths();
    }
Exemplo n.º 26
0
    static public void PushBack2()
    {
        int val = 0;

        for (int i = 0; i < Selection.gameObjects.Length; ++i)
        {
            val |= NGUITools.AdjustDepth(Selection.gameObjects[i], -1000);
        }

        if ((val & 1) != 0)
        {
            NGUITools.NormalizePanelDepths();
            if (UIPanelTool.instance != null)
            {
                UIPanelTool.instance.Repaint();
            }
        }
        if ((val & 2) != 0)
        {
            NGUITools.NormalizeWidgetDepths();
        }
    }
Exemplo n.º 27
0
    private void OnDrag_Card(GameObject obj, Vector2 del)
    {
        if (IsDrag)
        {
            return;
        }

        if (!IsDrag)
        {
            PureMVC.Patterns.Facade.Instance.SendNotification(NotificationID.Fight_ShowExpPan, true);
        }


        IsDrag = true;

        if (IsCustomDrag)
        {
            base.OnDragDropStart();

            HitTest     = true;
            mOldPostion = transform.position;
            NGUITools.AdjustDepth(gameObject, 100);
        }
    }
Exemplo n.º 28
0
    /// <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");
            }
        }
    }
Exemplo n.º 29
0
    /// <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");
            }
        }
    }
Exemplo n.º 30
0
 /// <summary>
 ///     Bring all of the widgets on the specified object forward.
 /// </summary>
 public void BringForward(GameObject go)
 {
     NGUITools.AdjustDepth(go, GuiConstants.Depths.Forward);
 }