コード例 #1
0
    /// <summary>
    /// Backwards compatibility.
    /// </summary>
    void Awake()
    {
        // Legacy functionality support for backwards compatibility
        if (panel != null)
        {
            if (draggablePanel == null)
            {
                draggablePanel = panel.GetComponent<NGUIDraggablePanel>();

                if (draggablePanel == null)
                {
                    draggablePanel = panel.gameObject.AddComponent<NGUIDraggablePanel>();
                }
            }
            panel = null;
        }
    }
コード例 #2
0
    void Start()
    {
        m_pShooterRoot      = GameObject.Find("thePlayerRoot(body)").GetComponent <shooterRoot>();
        m_pItemRockOnPanel  = GameObject.Find("Panel_TitleMenuA/Left/ItemRockOn").GetComponent <NGUIPanel>();
        m_pOpeningNemo      = GameObject.Find("Panel_TitleMenuA/Left/OpeningNemo").GetComponent <NGUIPanel>();
        m_pTitleBMenu       = GameObject.Find("Panel_TitleMenuB").GetComponent <JATitleMenuBMainScript>();
        m_pCharSelectScript = GameObject.Find("CharacterSelect").GetComponent <JACharacterSelectScript>();


// 140615jtj {
        if (PlayerPrefs.HasKey("lastStageIndex") == false)
        {
            PlayerPrefs.SetInt("lastStageIndex", 0);
        }
        m_nTitleBStageIndex = PlayerPrefs.GetInt("lastStageIndex");
        // } 140615jtj ;

        for (int i = 0; i < m_bItemUse.Length; i++)
        {
            m_bItemUse[i] = false;
        }

        m_bInvenState = false;

        LoadData();
        //! 메뉴 UI생성
        StartCoroutine(DelayUI(5f));

        //! PVP 대전에서 친구이름과 적이름을 랜덤으로 뽑아줍니다.
        m_nPvpFriendSelectInfo = NGUITools.RandomRange(2, 17);
        m_nPvpEnemyRand1       = NGUITools.RandomRange(0, 25);
        m_nPvpEnemyRand2       = NGUITools.RandomRange(0, 25);

        SaveData();

        //! 소환진 시간을위해..
        //SetManaTime();

        DontDestroyOnLoad(this);
    }
コード例 #3
0
    /// <summary>
    /// Raycast into the specified panel, returning a list of widgets.
    /// </summary>

    static public NGUIWidget[] Raycast(NGUIPanel panel, Vector2 mousePos)
    {
        List <NGUIWidget> list = new List <NGUIWidget>();

        NGUIWidget[] widgets = panel.gameObject.GetComponentsInChildren <NGUIWidget>();

        for (int i = 0; i < widgets.Length; ++i)
        {
            NGUIWidget w = widgets[i];

            if (w.panel == panel)
            {
                Vector3[] corners = NGUIMath.CalculateWidgetCorners(w);
                if (DistanceToRectangle(corners, mousePos) == 0f)
                {
                    list.Add(w);
                }
            }
        }

        list.Sort(delegate(NGUIWidget w1, NGUIWidget w2) { return(w2.depth.CompareTo(w1.depth)); });
        return(list.ToArray());
    }
コード例 #4
0
 /// <summary>
 /// Cache the transform and the panel.
 /// </summary>
 void Awake()
 {
     mTrans = transform;
     mPanel = GetComponent<NGUIPanel>();
 }
コード例 #5
0
    /// <summary>
    /// Helper function used to print things in columns.
    /// </summary>

    bool DrawRow(Entry ent, NGUIPanel selected, bool isChecked)
    {
        bool   retVal = false;
        string panelName, layer, widgetCount, drawCalls, clipping;

        if (ent != null)
        {
            panelName   = ent.panel.name;
            layer       = LayerMask.LayerToName(ent.panel.gameObject.layer);
            widgetCount = ent.widgets.Count.ToString();
            drawCalls   = ent.panel.drawCalls.size.ToString();
            clipping    = (ent.panel.clipping != NGUIDrawCall.Clipping.None) ? "Yes" : "";
        }
        else
        {
            panelName   = "Panel's Name";
            layer       = "Layer";
            widgetCount = "WG";
            drawCalls   = "DC";
            clipping    = "Clip";
        }

        if (ent != null)
        {
            NGUIEditorTools.HighlightLine(ent.isEnabled ? new Color(0.6f, 0.6f, 0.6f) : Color.black);
        }

        GUILayout.BeginHorizontal();
        {
            GUI.color = Color.white;

            if (isChecked != EditorGUILayout.Toggle(isChecked, GUILayout.Width(20f)))
            {
                retVal = true;
            }

            if (ent == null)
            {
                GUI.contentColor = Color.white;
            }
            else if (ent.isEnabled)
            {
                GUI.contentColor = (ent.panel == selected) ? new Color(0f, 0.8f, 1f) : Color.white;
            }
            else
            {
                GUI.contentColor = (ent.panel == selected) ? new Color(0f, 0.5f, 0.8f) : Color.grey;
            }

#if UNITY_3_4
            if (GUILayout.Button(panelName, EditorStyles.structHeadingLabel, GUILayout.MinWidth(100f)))
#else
            if (GUILayout.Button(panelName, EditorStyles.label, GUILayout.MinWidth(100f)))
#endif
            {
                if (ent != null)
                {
                    Selection.activeGameObject = ent.panel.gameObject;
                    EditorUtility.SetDirty(ent.panel.gameObject);
                }
            }

            GUILayout.Label(layer, GUILayout.Width(ent == null ? 65f : 70f));
            GUILayout.Label(widgetCount, GUILayout.Width(30f));
            GUILayout.Label(drawCalls, GUILayout.Width(30f));
            GUILayout.Label(clipping, GUILayout.Width(30f));

            if (ent == null)
            {
                GUILayout.Label("Giz", GUILayout.Width(24f));
            }
            else
            {
                GUI.contentColor = ent.isEnabled ? Color.white : new Color(0.7f, 0.7f, 0.7f);
                bool debug = (ent.panel.debugInfo == NGUIPanel.DebugInfo.Gizmos);

                if (debug != EditorGUILayout.Toggle(debug, GUILayout.Width(20f)))
                {
                    // debug != value, so it's currently inverse
                    ent.panel.debugInfo = debug ? NGUIPanel.DebugInfo.None : NGUIPanel.DebugInfo.Gizmos;
                    EditorUtility.SetDirty(ent.panel.gameObject);
                }
            }
        }
        GUILayout.EndHorizontal();
        return(retVal);
    }
コード例 #6
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        List <NGUIPanel> panels = GetListOfPanels();

        if (panels != null && panels.Count > 0)
        {
            NGUIPanel selectedPanel = NGUITools.FindInParents <NGUIPanel>(Selection.activeGameObject);

            // First, collect a list of panels with their associated widgets
            List <Entry> entries       = new List <Entry>();
            Entry        selectedEntry = null;
            bool         allEnabled    = true;

            foreach (NGUIPanel panel in panels)
            {
                Entry ent = new Entry();
                ent.panel          = panel;
                ent.widgets        = GetWidgets(panel);
                ent.isEnabled      = panel.enabled && NGUITools.GetActive(panel.gameObject);
                ent.widgetsEnabled = ent.isEnabled;

                if (ent.widgetsEnabled)
                {
                    foreach (NGUIWidget w in ent.widgets)
                    {
                        if (!NGUITools.GetActive(w.gameObject))
                        {
                            allEnabled         = false;
                            ent.widgetsEnabled = false;
                            break;
                        }
                    }
                }
                else
                {
                    allEnabled = false;
                }
                entries.Add(ent);
            }

            // Sort the list alphabetically
            entries.Sort(Compare);

            EditorGUIUtility.LookLikeControls(80f);
            bool showAll = DrawRow(null, null, allEnabled);
            NGUIEditorTools.DrawSeparator();

            mScroll = GUILayout.BeginScrollView(mScroll);

            foreach (Entry ent in entries)
            {
                if (DrawRow(ent, selectedPanel, ent.widgetsEnabled))
                {
                    selectedEntry = ent;
                }
            }
            GUILayout.EndScrollView();

            if (showAll)
            {
                foreach (Entry ent in entries)
                {
                    SetActiveState(ent.panel, !allEnabled);
                }
            }
            else if (selectedEntry != null)
            {
                SetActiveState(selectedEntry.panel, !selectedEntry.widgetsEnabled);
            }
        }
        else
        {
            GUILayout.Label("No UI Panels found in the scene");
        }
    }
コード例 #7
0
    /// <summary>
    /// Cache the transform and the panel.
    /// </summary>

    void Awake()
    {
        mTrans = transform;
        mPanel = GetComponent <NGUIPanel>();
    }
コード例 #8
0
ファイル: TweenAlpha.cs プロジェクト: ancongsheng/vu_paradox
 /// <summary>
 /// Find all needed components.
 /// </summary>
 void Awake()
 {
     mPanel = GetComponent<NGUIPanel>();
     if (mPanel == null) mWidget = GetComponentInChildren<NGUIWidget>();
 }
コード例 #9
0
 void Awake()
 {
     mWidget = GetComponent <NGUIWidget>();
     mPanel  = GetComponent <NGUIPanel>();
     Update();
 }
コード例 #10
0
    /// <summary>
    /// Create a brand-new UI hierarchy.
    /// </summary>

    static public GameObject CreateNewUI()
    {
        NGUIEditorTools.RegisterUndo("Create New UI");

        // Root for the UI
        GameObject root = null;

        if (camType == CameraType.Simple2D)
        {
            root = new GameObject("UI Root (2D)");
            root.AddComponent <NGUIRoot>().scalingStyle = NGUIRoot.Scaling.PixelPerfect;
        }
        else
        {
            root = new GameObject((camType == CameraType.Advanced3D) ? "UI Root (3D)" : "UI Root");
            root.transform.localScale = new Vector3(0.0025f, 0.0025f, 0.0025f);
            root.AddComponent <NGUIRoot>().scalingStyle = NGUIRoot.Scaling.FixedSize;
        }

        // Assign the layer to be used by everything
        root.layer = NGUISettings.layer;

        // Figure out the depth of the highest camera
        if (camType == CameraType.None)
        {
            // No camera requested -- simply add a panel
            NGUIPanel panel = NGUITools.AddChild <NGUIPanel>(root.gameObject);
            Selection.activeGameObject = panel.gameObject;
        }
        else
        {
            int   mask          = 1 << NGUISettings.layer;
            float depth         = -1f;
            bool  clearColor    = true;
            bool  audioListener = true;

            List <Camera> cameras = NGUIEditorTools.FindInScene <Camera>();

            foreach (Camera c in cameras)
            {
                // Choose the maximum depth
                depth = Mathf.Max(depth, c.depth);

                // Automatically exclude the specified layer mask from the camera if it can see more than that layer
                if (NGUISettings.layer != 0 && c.cullingMask != mask)
                {
                    c.cullingMask = (c.cullingMask & (~mask));
                }

                // Only consider this object if it's active
                if (c.enabled && NGUITools.GetActive(c.gameObject))
                {
                    clearColor = false;
                }

                // If this camera has an audio listener, we won't need to add one
                if (c.GetComponent <AudioListener>() != null)
                {
                    audioListener = false;
                }
            }

            // Camera and NGUICamera for this UI
            Camera cam = NGUITools.AddChild <Camera>(root);
            cam.depth           = depth + 1;
            cam.backgroundColor = Color.grey;
            cam.cullingMask     = mask;

            if (camType == CameraType.Simple2D)
            {
                cam.orthographicSize = 1f;
                cam.orthographic     = true;
                cam.nearClipPlane    = -2f;
                cam.farClipPlane     = 2f;
            }
            else
            {
                cam.nearClipPlane           = 0.1f;
                cam.farClipPlane            = 4f;
                cam.transform.localPosition = new Vector3(0f, 0f, -700f);
            }

            // We don't want to clear color if this is not the first camera
            if (cameras.Count > 0)
            {
                cam.clearFlags = clearColor ? CameraClearFlags.Skybox : CameraClearFlags.Depth;
            }

            // Add an audio listener if we need one
            if (audioListener)
            {
                cam.gameObject.AddComponent <AudioListener>();
            }

            // Add a UI Camera for event handling
            cam.gameObject.AddComponent <NGUICamera>();

            if (camType == CameraType.Simple2D)
            {
                // Anchor is useful to have
                NGUIAnchor anchor = NGUITools.AddChild <NGUIAnchor>(cam.gameObject);
                anchor.uiCamera = cam;

                // And finally -- the first UI panel
                NGUIPanel panel = NGUITools.AddChild <NGUIPanel>(anchor.gameObject);
                Selection.activeGameObject = panel.gameObject;
            }
            else
            {
                NGUIPanel panel = NGUITools.AddChild <NGUIPanel>(root);
                Selection.activeGameObject = panel.gameObject;
            }
        }
        return(Selection.activeGameObject);
    }
コード例 #11
0
ファイル: NGUITable.cs プロジェクト: ancongsheng/vu_paradox
    /// <summary>
    /// Position the grid's contents when the script starts.
    /// </summary>
    void Start()
    {
        mStarted = true;

        if (keepWithinPanel)
        {
            mPanel = NGUITools.FindInParents<NGUIPanel>(gameObject);
            mDrag = NGUITools.FindInParents<NGUIDraggablePanel>(gameObject);
        }
        Reposition();
    }
コード例 #12
0
 void Awake()
 {
     mWidget = GetComponent<NGUIWidget>();
     mPanel = GetComponent<NGUIPanel>();
     Update();
 }
コード例 #13
0
    /// <summary>
    /// Display the drop-down list when the game object gets clicked on.
    /// </summary>

    void OnClick()
    {
        if (mChild == null && atlas != null && font != null && items.Count > 0)
        {
            mLabelList.Clear();

            // Disable the navigation script
            handleEvents = true;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = NGUIPanel.Find(transform, true);
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds    bounds  = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            Transform t = mChild.transform;
            t.parent        = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = NGUIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;

            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = NGUIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            NGUIAtlas.Sprite hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float            hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin;
            float            fontScale = font.size * font.pixelSize * textScale;
            float            x = 0f, y = -padding.y;
            List <NGUILabel> labels = new List <NGUILabel>();

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(mChild);
                lbl.pivot = NGUIWidget.Pivot.TopLeft;
                lbl.font  = font;
                lbl.text  = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
                lbl.color = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f);
                lbl.MakePixelPerfect();

                if (textScale != 1f)
                {
                    Vector3 scale = lbl.cachedTransform.localScale;
                    lbl.cachedTransform.localScale = scale * textScale;
                }
                labels.Add(lbl);

                y -= fontScale;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.relativeSize.x * fontScale);

                // Add an event listener
                NGUIEventListener listener = NGUIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s)
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);

            Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f);
            Vector3 bcSize   = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                NGUILabel   lbl = labels[i];
                BoxCollider bc  = NGUITools.AddWidgetCollider(lbl.gameObject);
                bcCenter.z = bc.center.z;
                bc.center  = bcCenter;
                bc.size    = bcSize;
            }

            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.cachedTransform.localScale = new Vector3(x, -y + bgPadding.y, 1f);

            // Scale the highlight sprite to envelop a single item
            mHighlight.cachedTransform.localScale = new Vector3(
                x - (bgPadding.x + padding.x) * 2f + (hlsp.inner.xMin - hlsp.outer.xMin) * 2f,
                fontScale + hlspHeight * 2f, 1f);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                NGUICamera cam = NGUICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + fontScale;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i)
                {
                    Animate(labels[i], placeAbove, bottom);
                }
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else
        {
            OnSelect(false);
        }
    }
コード例 #14
0
ファイル: SpringPanel.cs プロジェクト: ancongsheng/vu_paradox
    /// <summary>
    /// Cache the transform.
    /// </summary>

    void Start()
    {
        mPanel = GetComponent <NGUIPanel>();
        mDrag  = GetComponent <NGUIDraggablePanel>();
        mTrans = transform;
    }
コード例 #15
0
 /// <summary>
 /// Find the panel responsible for this object.
 /// </summary>
 void FindPanel()
 {
     mPanel = (target != null) ? NGUIPanel.Find(target.transform, false) : null;
     if (mPanel == null) restrictWithinPanel = false;
 }
コード例 #16
0
 void Awake()
 {
     animator       = GetComponent <Animator>();
     gameController = GameObject.FindWithTag(Tags.GameController).GetComponent <GameController>();
     panel          = GetComponent <NGUIPanel>();
 }
コード例 #17
0
    /// <summary>
    /// Helper function that returns the selected root object.
    /// </summary>

    static public GameObject SelectedRoot(bool createIfMissing)
    {
        GameObject go = Selection.activeGameObject;

        // Only use active objects
        if (go != null && !NGUITools.GetActive(go))
        {
            go = null;
        }

        // Try to find a panel
        NGUIPanel p = (go != null) ? NGUITools.FindInParents <NGUIPanel>(go) : null;

        // No selection? Try to find the root automatically
        if (p == null)
        {
            NGUIPanel[] panels = NGUITools.FindActive <NGUIPanel>();
            if (panels.Length > 0)
            {
                go = panels[0].gameObject;
            }
        }

        // Now find the first uniformly scaled object
        if (go != null)
        {
            Transform t = go.transform;

            // Find the first uniformly scaled object
            while (!Mathf.Approximately(t.localScale.x, t.localScale.y) ||
                   !Mathf.Approximately(t.localScale.x, t.localScale.z))
            {
                t = t.parent;
                if (t == null)
                {
                    return((p != null) ? p.gameObject : null);
                }
                else
                {
                    go = t.gameObject;
                }
            }
        }

        if (createIfMissing && go == null)
        {
            // No object specified -- find the first panel
            if (go == null)
            {
                NGUIPanel panel = GameObject.FindObjectOfType(typeof(NGUIPanel)) as NGUIPanel;
                if (panel != null)
                {
                    go = panel.gameObject;
                }
            }

            // No UI present -- create a new one
            if (go == null)
            {
                go = NGUICreateNewUIWizard.CreateNewUI();
            }
        }
        return(go);
    }
コード例 #18
0
ファイル: SpringPanel.cs プロジェクト: ancongsheng/vu_paradox
 /// <summary>
 /// Cache the transform.
 /// </summary>
 void Start()
 {
     mPanel = GetComponent<NGUIPanel>();
     mDrag = GetComponent<NGUIDraggablePanel>();
     mTrans = transform;
 }
コード例 #19
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIPanel panel = target as NGUIPanel;
        BetterList <NGUIDrawCall> drawcalls = panel.drawCalls;

        EditorGUIUtility.LookLikeControls(80f);

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

        float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f);

        if (alpha != panel.alpha)
        {
            NGUIEditorTools.RegisterUndo("Panel Alpha", panel);
            panel.alpha = alpha;
        }

        if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
        {
            panel.showInPanelTool = !panel.showInPanelTool;
            EditorUtility.SetDirty(panel);
            EditorWindow.FocusWindowIfItsOpen <NGUIPanelTool>();
        }

        GUILayout.BeginHorizontal();
        bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f));

        GUILayout.Label("Needed for lit shaders");
        GUILayout.EndHorizontal();

        if (panel.generateNormals != norms)
        {
            panel.generateNormals = norms;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        GUILayout.BeginHorizontal();
        bool depth = EditorGUILayout.Toggle("Depth Pass", panel.depthPass, GUILayout.Width(100f));

        GUILayout.Label("Doubles draw calls, saves fillrate");
        GUILayout.EndHorizontal();

        if (panel.depthPass != depth)
        {
            panel.depthPass = depth;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        if (depth)
        {
            NGUICamera cam = NGUICamera.FindCameraForLayer(panel.gameObject.layer);

            if (cam == null || cam.camera.isOrthoGraphic)
            {
                EditorGUILayout.HelpBox("Please note that depth pass will only save fillrate when used with 3D NGUIs, and only NGUIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
            }
        }

        GUILayout.BeginHorizontal();
        bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f));

        GUILayout.Label("Check if widgets won't move");
        GUILayout.EndHorizontal();

        if (panel.widgetsAreStatic != stat)
        {
            panel.widgetsAreStatic = stat;
            panel.UpdateDrawcalls();
            EditorUtility.SetDirty(panel);
        }

        EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
        EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

        NGUIPanel.DebugInfo di = (NGUIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

        if (panel.debugInfo != di)
        {
            panel.debugInfo = di;
            EditorUtility.SetDirty(panel);
        }

        NGUIDrawCall.Clipping clipping = (NGUIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping);

        if (panel.clipping != clipping)
        {
            panel.clipping = clipping;
            EditorUtility.SetDirty(panel);
        }

        if (panel.clipping != NGUIDrawCall.Clipping.None)
        {
            Vector4 range = panel.clipRange;

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80f);
            Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
            GUILayout.EndHorizontal();

            if (size.x < 0f)
            {
                size.x = 0f;
            }
            if (size.y < 0f)
            {
                size.y = 0f;
            }

            range.x = pos.x;
            range.y = pos.y;
            range.z = size.x;
            range.w = size.y;

            if (panel.clipRange != range)
            {
                NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                panel.clipRange = range;
                EditorUtility.SetDirty(panel);
            }

            if (panel.clipping == NGUIDrawCall.Clipping.SoftClip)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness);
                GUILayout.EndHorizontal();

                if (soft.x < 1f)
                {
                    soft.x = 1f;
                }
                if (soft.y < 1f)
                {
                    soft.y = 1f;
                }

                if (panel.clipSoftness != soft)
                {
                    NGUIEditorTools.RegisterUndo("Clipping Change", panel);
                    panel.clipSoftness = soft;
                    EditorUtility.SetDirty(panel);
                }
            }

#if !UNITY_3_5 && (UNITY_ANDROID || UNITY_IPHONE)
            if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x)
            {
                EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
            }
#endif
        }

        if (clipping == NGUIDrawCall.Clipping.HardClip)
        {
            EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
        }

        if (clipping != NGUIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
        {
            EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);

            if (GUILayout.Button("Auto-fix"))
            {
                NGUIEditorTools.FixUniform(panel.gameObject);
            }
        }

        foreach (NGUIDrawCall dc in drawcalls)
        {
            NGUIEditorTools.DrawSeparator();
            EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
            EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

            if (clipping != NGUIDrawCall.Clipping.None && !dc.isClipped)
            {
                EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
                                        MessageType.Warning);
            }
        }
    }
コード例 #20
0
 /// <summary>
 /// Activate or deactivate the specified panel and all of its children.
 /// </summary>
 static void SetActiveState(NGUIPanel panel, bool state)
 {
     if (state)
     {
         NGUITools.SetActiveSelf(panel.gameObject, true);
         SetActiveState(panel.transform, true);
     }
     else
     {
         SetActiveState(panel.transform, false);
         NGUITools.SetActiveSelf(panel.gameObject, false);
     }
     EditorUtility.SetDirty(panel.gameObject);
 }
コード例 #21
0
    /// <summary>
    /// Helper function used to print things in columns.
    /// </summary>
    bool DrawRow(Entry ent, NGUIPanel selected, bool isChecked)
    {
        bool retVal = false;
        string panelName, layer, widgetCount, drawCalls, clipping;

        if (ent != null)
        {
            panelName = ent.panel.name;
            layer = LayerMask.LayerToName(ent.panel.gameObject.layer);
            widgetCount = ent.widgets.Count.ToString();
            drawCalls = ent.panel.drawCalls.size.ToString();
            clipping = (ent.panel.clipping != NGUIDrawCall.Clipping.None) ? "Yes" : "";
        }
        else
        {
            panelName = "Panel's Name";
            layer = "Layer";
            widgetCount = "WG";
            drawCalls = "DC";
            clipping = "Clip";
        }

        if (ent != null) NGUIEditorTools.HighlightLine(ent.isEnabled ? new Color(0.6f, 0.6f, 0.6f) : Color.black);

        GUILayout.BeginHorizontal();
        {
            GUI.color = Color.white;

            if (isChecked != EditorGUILayout.Toggle(isChecked, GUILayout.Width(20f))) retVal = true;

            if (ent == null)
            {
                GUI.contentColor = Color.white;
            }
            else if (ent.isEnabled)
            {
                GUI.contentColor = (ent.panel == selected) ? new Color(0f, 0.8f, 1f) : Color.white;
            }
            else
            {
                GUI.contentColor = (ent.panel == selected) ? new Color(0f, 0.5f, 0.8f) : Color.grey;
            }

        #if UNITY_3_4
            if (GUILayout.Button(panelName, EditorStyles.structHeadingLabel, GUILayout.MinWidth(100f)))
        #else
            if (GUILayout.Button(panelName, EditorStyles.label, GUILayout.MinWidth(100f)))
        #endif
            {
                if (ent != null)
                {
                    Selection.activeGameObject = ent.panel.gameObject;
                    EditorUtility.SetDirty(ent.panel.gameObject);
                }
            }

            GUILayout.Label(layer, GUILayout.Width(ent == null ? 65f : 70f));
            GUILayout.Label(widgetCount, GUILayout.Width(30f));
            GUILayout.Label(drawCalls, GUILayout.Width(30f));
            GUILayout.Label(clipping, GUILayout.Width(30f));

            if (ent == null)
            {
                GUILayout.Label("Giz", GUILayout.Width(24f));
            }
            else
            {
                GUI.contentColor = ent.isEnabled ? Color.white : new Color(0.7f, 0.7f, 0.7f);
                bool debug = (ent.panel.debugInfo == NGUIPanel.DebugInfo.Gizmos);

                if (debug != EditorGUILayout.Toggle(debug, GUILayout.Width(20f)))
                {
                    // debug != value, so it's currently inverse
                    ent.panel.debugInfo = debug ? NGUIPanel.DebugInfo.None : NGUIPanel.DebugInfo.Gizmos;
                    EditorUtility.SetDirty(ent.panel.gameObject);
                }
            }
        }
        GUILayout.EndHorizontal();
        return retVal;
    }
コード例 #22
0
 /// <summary>
 /// Get a list of widgets managed by the specified panel.
 /// </summary>
 static List<NGUIWidget> GetWidgets(NGUIPanel panel)
 {
     List<NGUIWidget> widgets = new List<NGUIWidget>();
     if (panel != null) GetWidgets(panel.transform, widgets);
     return widgets;
 }
コード例 #23
0
    /// <summary>
    /// All widgets have depth, color and make pixel-perfect options
    /// </summary>

    protected void DrawCommonProperties()
    {
#if UNITY_3_4
        PrefabType type = EditorUtility.GetPrefabType(mWidget.gameObject);
#else
        PrefabType type = PrefabUtility.GetPrefabType(mWidget.gameObject);
#endif

        NGUIEditorTools.DrawSeparator();

#if UNITY_3_5
        // Pivot point -- old school drop-down style
        NGUIWidget.Pivot pivot = (NGUIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", mWidget.pivot);

        if (mWidget.pivot != pivot)
        {
            NGUIEditorTools.RegisterUndo("Pivot Change", mWidget);
            mWidget.pivot = pivot;
        }
#else
        // Pivot point -- the new, more visual style
        GUILayout.BeginHorizontal();
        GUILayout.Label("Pivot", GUILayout.Width(76f));
        Toggle("◄", "ButtonLeft", NGUIWidget.Pivot.Left, true);
        Toggle("▬", "ButtonMid", NGUIWidget.Pivot.Center, true);
        Toggle("►", "ButtonRight", NGUIWidget.Pivot.Right, true);
        Toggle("▲", "ButtonLeft", NGUIWidget.Pivot.Top, false);
        Toggle("▌", "ButtonMid", NGUIWidget.Pivot.Center, false);
        Toggle("▼", "ButtonRight", NGUIWidget.Pivot.Bottom, false);
        GUILayout.EndHorizontal();
#endif

        // Depth navigation
        if (type != PrefabType.Prefab)
        {
            GUILayout.Space(2f);
            GUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Depth");

                int depth = mWidget.depth;
                if (GUILayout.Button("Back", GUILayout.Width(60f)))
                {
                    --depth;
                }
                depth = EditorGUILayout.IntField(depth);
                if (GUILayout.Button("Forward", GUILayout.Width(60f)))
                {
                    ++depth;
                }

                if (mWidget.depth != depth)
                {
                    NGUIEditorTools.RegisterUndo("Depth Change", mWidget);
                    mWidget.depth = depth;
                    mDepthCheck   = true;
                }
            }
            GUILayout.EndHorizontal();

            NGUIPanel panel = mWidget.panel;

            if (panel != null)
            {
                int count = 0;

                for (int i = 0; i < panel.widgets.size; ++i)
                {
                    NGUIWidget w = panel.widgets[i];
                    if (w != null && w.depth == mWidget.depth && w.material == mWidget.material)
                    {
                        ++count;
                    }
                }

                if (count > 1)
                {
                    EditorGUILayout.HelpBox(count + " widgets are using the depth value of " + mWidget.depth +
                                            ". It may not be clear what should be in front of what.", MessageType.Warning);
                }

                if (mDepthCheck)
                {
                    if (panel.drawCalls.size > 1)
                    {
                        EditorGUILayout.HelpBox("The widgets underneath this panel are using more than one atlas. You may need to adjust transform position's Z value instead. When adjusting the Z, lower value means closer to the camera.", MessageType.Warning);
                    }
                }
            }
        }

        // Pixel-correctness
        if (type != PrefabType.Prefab)
        {
            GUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Correction");

                if (GUILayout.Button("Make Pixel-Perfect"))
                {
                    NGUIEditorTools.RegisterUndo("Make Pixel-Perfect", mWidget.transform);
                    mWidget.MakePixelPerfect();
                }
            }
            GUILayout.EndHorizontal();
        }

        //NGUIEditorTools.DrawSeparator();
        EditorGUILayout.Space();

        // Color tint
        GUILayout.BeginHorizontal();
        Color color = EditorGUILayout.ColorField("Color Tint", mWidget.color);
        if (GUILayout.Button("Copy", GUILayout.Width(50f)))
        {
            NGUISettings.color = color;
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        NGUISettings.color = EditorGUILayout.ColorField("Clipboard", NGUISettings.color);
        if (GUILayout.Button("Paste", GUILayout.Width(50f)))
        {
            color = NGUISettings.color;
        }
        GUILayout.EndHorizontal();

        if (mWidget.color != color)
        {
            NGUIEditorTools.RegisterUndo("Color Change", mWidget);
            mWidget.color = color;
        }
    }
コード例 #24
0
    /// <summary>
    /// Display the drop-down list when the game object gets clicked on.
    /// </summary>
    void OnClick()
    {
        if (mChild == null && atlas != null && font != null && items.Count > 0)
        {
            mLabelList.Clear();

            // Disable the navigation script
            handleEvents = true;

            // Automatically locate the panel responsible for this object
            if (mPanel == null) mPanel = NGUIPanel.Find(transform, true);

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Transform myTrans = transform;
            Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans);

            // Create the root object for the list
            mChild = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            Transform t = mChild.transform;
            t.parent = myTrans.parent;
            t.localPosition = bounds.min;
            t.localRotation = Quaternion.identity;
            t.localScale = Vector3.one;

            // Add a sprite for the background
            mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = NGUIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;

            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = NGUIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            NGUIAtlas.Sprite hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null) return;

            float hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin;
            float fontScale = font.size * font.pixelSize * textScale;
            float x = 0f, y = -padding.y;
            List<NGUILabel> labels = new List<NGUILabel>();

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                NGUILabel lbl = NGUITools.AddWidget<NGUILabel>(mChild);
                lbl.pivot = NGUIWidget.Pivot.TopLeft;
                lbl.font = font;
                lbl.text = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s;
                lbl.color = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f);
                lbl.MakePixelPerfect();

                if (textScale != 1f)
                {
                    Vector3 scale = lbl.cachedTransform.localScale;
                    lbl.cachedTransform.localScale = scale * textScale;
                }
                labels.Add(lbl);

                y -= fontScale;
                y -= padding.y;
                x = Mathf.Max(x, lbl.relativeSize.x * fontScale);

                // Add an event listener
                NGUIEventListener listener = NGUIEventListener.Get(lbl.gameObject);
                listener.onHover = OnItemHover;
                listener.onPress = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s) Highlight(lbl, true);

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f);

            Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f);
            Vector3 bcSize = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                NGUILabel lbl = labels[i];
                BoxCollider bc = NGUITools.AddWidgetCollider(lbl.gameObject);
                bcCenter.z = bc.center.z;
                bc.center = bcCenter;
                bc.size = bcSize;
            }

            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.cachedTransform.localScale = new Vector3(x, -y + bgPadding.y, 1f);

            // Scale the highlight sprite to envelop a single item
            mHighlight.cachedTransform.localScale = new Vector3(
                x - (bgPadding.x + padding.x) * 2f + (hlsp.inner.xMin - hlsp.outer.xMin) * 2f,
                fontScale + hlspHeight * 2f, 1f);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                NGUICamera cam = NGUICamera.FindCameraForLayer(gameObject.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                float bottom = y + fontScale;
                Animate(mHighlight, placeAbove, bottom);
                for (int i = 0, imax = labels.Count; i < imax; ++i) Animate(labels[i], placeAbove, bottom);
                AnimateColor(mBackground);
                AnimateScale(mBackground, placeAbove, bottom);
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z);
            }
        }
        else OnSelect(false);
    }