Ejemplo n.º 1
0
 public virtual void setupGraphHierarchy()
 {
     if (mMeshesContainer == null)
     {
         mMeshesContainer = NGraphUtils.AddGameObject(gameObject, 0, "MeshesContainer");
     }
 }
    static public bool ShouldCreate(GameObject go, bool isValid)
    {
        GUI.color = isValid ? Color.green : Color.grey;

        GUILayout.BeginHorizontal();
        bool retVal = GUILayout.Button("Add To", GUILayout.Width(76f));

        GUI.color = Color.white;
        GameObject sel = EditorGUILayout.ObjectField(go, typeof(GameObject), true, GUILayout.Width(140f)) as GameObject;

        GUILayout.Label("Select the parent in the Hierarchy View", GUILayout.MinWidth(10000f));
        GUILayout.EndHorizontal();

        if (sel != go)
        {
            Selection.activeGameObject = sel;
        }

        if (go == null || go.GetComponent <NGraph>())
        {
            return(false);
        }

        if (retVal && isValid)
        {
            NGraphUtils.RegisterUndo("Add Graph");
            return(true);
        }
        return(false);
    }
Ejemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        NGraphUtils.DrawSeparator();

        UINgraph pGraph = (UINgraph)target;

        GUILayout.BeginHorizontal();
        if (NGUIEditorTools.DrawPrefixButton("Font"))
        {
            if (mType == UILabelInspector.FontType.NGUI)
            {
                ComponentSelector.Show <UIFont>(OnBitmapFont);
            }
            else
            {
                ComponentSelector.Show <Font>(OnDynamicFont);
            }
        }

#if DYNAMIC_FONT
        GUI.changed = false;

        if (mType == UILabelInspector.FontType.Unity)
        {
            Font fnt = (Font)EditorGUILayout.ObjectField(pGraph.AxisLabelDynamicFont, typeof(Font), false, GUILayout.Width(140f));
            if (fnt != pGraph.AxisLabelDynamicFont)
            {
                UndoableAction <UINgraph>(gr => gr.AxisLabelDynamicFont = fnt);
            }
        }
        else
        {
            UIFont fnt = (UIFont)EditorGUILayout.ObjectField(pGraph.AxisLabelBitmapFont, typeof(UIFont), false, GUILayout.Width(140f));
            if (fnt != pGraph.AxisLabelBitmapFont)
            {
                UndoableAction <UINgraph>(gr => gr.AxisLabelBitmapFont = fnt);
            }
        }
        mType = (UILabelInspector.FontType)EditorGUILayout.EnumPopup(mType, GUILayout.Width(62f));
#else
        UIFont fnt = (UIFont)EditorGUILayout.ObjectField(pGraph.AxisLabelBitmapFont, typeof(UIFont), false, GUILayout.Width(140f));
        if (fnt != pGraph.AxisLabelBitmapFont)
        {
            UndoableAction <UINgraph>(gr => gr.AxisLabelBitmapFont = fnt);
        }
        mType = UILabelInspector.FontType.NGUI;
#endif

        GUILayout.Label("size", GUILayout.Width(30f));
        EditorGUI.BeginDisabledGroup(mType == UILabelInspector.FontType.NGUI);
        int i = EditorGUILayout.IntField(pGraph.fontSize, GUILayout.Width(30f));
        if (i != pGraph.fontSize)
        {
            UndoableAction <UINgraph>(gr => gr.fontSize = i);
        }
        EditorGUI.EndDisabledGroup();
        GUILayout.Label("font used by the labels");
        GUILayout.EndHorizontal();
    }
Ejemplo n.º 4
0
    protected override void _drawAxisBackground(List <UIVertex> pVertexList)
    {
        Material pMat = new Material(AxisMaterial);

        pMat.SetColor("_TintColor", MarginBackgroundColor);

        CanvasRenderer pCanvasRenderer = NGraphUtils.AddCanvasRenderer(mAxesBackgroundGo);

        pCanvasRenderer.Clear();
        pCanvasRenderer.SetMaterial(pMat, null);
        pCanvasRenderer.SetVertices(pVertexList);
    }
Ejemplo n.º 5
0
    public override void setupGraphHierarchy()
    {
        base.setupGraphHierarchy();
        CanvasRenderer pCanvasRenderer = NGraphUtils.AddCanvasRenderer(mMeshesContainer);


        Material pMat = new Material(AxisMaterial);

        pMat.SetColor("_TintColor", GridLinesColorMajor);
        pCanvasRenderer.Clear();
        pCanvasRenderer.SetMaterial(pMat, null);

        NGraphUtils.DrawRect(new Rect(adjustPointX(-5) - (GridLinesThicknesMajor / 2f), adjustPointY(YRange.y), GridLinesThicknesMajor, adjustPointY(YRange.x) * 2), pCanvasRenderer);
    }
Ejemplo n.º 6
0
    /* ---------- */
    /* BACKGROUND */
    /* ---------- */

    protected override void _drawPlotBackground(List <UIVertex> pVertexList)
    {
        if (mPlotBackgroundMesh == null)
        {
            NGraphUtils.AddMesh(mPlotBackgroundGo, out mPlotBackgroundMeshRenderer, out mPlotBackgroundMesh);
        }

        mPlotBackgroundMesh.Clear();
        mPlotBackgroundMeshRenderer.material = PlotBackgroundMaterial;
        mPlotBackgroundMeshRenderer.material.SetColor("_TintColor", PlotBackgroundColor);

        List <Vector3> pVertices  = new List <Vector3>();
        List <Vector2> pUvs       = new List <Vector2>();
        List <int>     pTriangles = new List <int>();

        UIVertex a = pVertexList [1];
        UIVertex b = pVertexList [2];
        UIVertex c = pVertexList [0];
        UIVertex d = pVertexList [3];

        pVertices.Add(c.position);
        pVertices.Add(a.position);
        pVertices.Add(b.position);
        pVertices.Add(d.position);
        pUvs.Add(c.uv0);
        pUvs.Add(a.uv0);
        pUvs.Add(b.uv0);
        pUvs.Add(d.uv0);

        /*
         * 1a       2b
         *
         *
         *
         * 0c       3d
         *
         */
        pTriangles.Add(0);
        pTriangles.Add(1);
        pTriangles.Add(2);

        pTriangles.Add(0);
        pTriangles.Add(2);
        pTriangles.Add(3);

        mPlotBackgroundMesh.vertices  = pVertices.ToArray();
        mPlotBackgroundMesh.uv        = pUvs.ToArray();
        mPlotBackgroundMesh.triangles = pTriangles.ToArray();
    }
Ejemplo n.º 7
0
    protected void DrawAxes()
    {
        if (!Application.isPlaying || mMeshesContainer == null)
        {
            return;
        }

        if (mXRange == Vector2.zero)
        {
            return;
        }

        if (mYRange == Vector2.zero)
        {
            return;
        }

        AxesDrawAt.x = Mathf.Clamp(AxesDrawAt.x, XRange.x, XRange.y);
        AxesDrawAt.y = Mathf.Clamp(AxesDrawAt.y, YRange.x, YRange.y);

        Vector2 pTop    = adjustPoint(new Vector2(AxesDrawAt.x, YRange.y));
        Vector2 pBottom = adjustPoint(new Vector2(AxesDrawAt.x, YRange.x));
        Vector2 pLeft   = adjustPoint(new Vector2(XRange.x, AxesDrawAt.y));
        Vector2 pRight  = adjustPoint(new Vector2(XRange.y, AxesDrawAt.y));

        if (mAxesGo == null)
        {
            mAxesGo = NGraphUtils.AddGameObject(mMeshesContainer, AXES_LEVEL * LEVEL_STEP, "Axes");
            _addedAxesGameObject(mAxesGo);
            mXAxesGo = NGraphUtils.AddGameObject(mAxesGo, 0, "X Axes");
            _addedXAxisGameObject(mXAxesGo);
            mYAxesGo = NGraphUtils.AddGameObject(mAxesGo, 0, "Y Axes");
            _addedYAxisGameObject(mYAxesGo);
        }

        Rect x = new Rect(pLeft.x, AxesThickness / 2 + pLeft.y, pRight.x - pLeft.x, -AxesThickness);
        Rect y = new Rect(pTop.x - AxesThickness / 2, pTop.y, AxesThickness, -(pTop.y - pBottom.y));


        float z1 = mAxesGo.transform.localPosition.z;
        float z2 = mXAxesGo.transform.localPosition.z;
        float z3 = mYAxesGo.transform.localPosition.z;

        this._drawAxes(x, y);

        mAxesGo.transform.localPosition  = new Vector3(0, 0, z1);
        mXAxesGo.transform.localPosition = new Vector3(0, 0, z2);
        mYAxesGo.transform.localPosition = new Vector3(0, 0, z3);
    }
Ejemplo n.º 8
0
    public int addDataLabel(float xValue, string label = null)
    {
        GameObject      pLabelGo = NGraphUtils.AddGameObject(mDataLabelContainerGo, 0, "Plot Label - " + mDataLabels.Count);
        dataLabelStruct str;

        str.xValue  = xValue;
        str.gameObj = pLabelGo;
        str.text    = label;

        mDataLabels.Add(str);
        int pos = mDataLabels.Count - 1;

        drawDataLabel(mDataLabels[pos]);
        return(pos);
    }
Ejemplo n.º 9
0
    /** \brief  Add a data series type to the graph.
     *
     *  T must be a child of NGraphDataSeries.
     * \param name Name of this plot.
     * \param pPlotColor Default color for this plot.
     * \param pMaterial Optional default material override for this plot.  Pass null for NGraph default.
     */
    public T addDataSeries <T>(string name, Color pPlotColor, Material pMaterial = null) where T : NGraphDataSeries
    {
        setupGraphHierarchy();
        GameObject pGameObject = NGraphUtils.AddGameObject(mMeshesContainer, PLOT_START_LEVEL * LEVEL_STEP, "Data Series - " + name);

        newDataSeriesGameObject(pGameObject);

        T pNGraphDataSeries = pGameObject.AddComponent <T>();

        if (pMaterial == null)
        {
            pNGraphDataSeries.PlotMaterial = DefaultPlotMaterial;
        }
        else
        {
            pNGraphDataSeries.PlotMaterial = pMaterial;
        }
        pNGraphDataSeries.PlotColor = pPlotColor;

        mDataSeries.Add(pNGraphDataSeries);

        GameObject pDataLabelContainer = NGraphUtils.AddGameObject(DataLabelTopContainer, -1, "\"" + name + "\"");

        newDataSeriesDataLabelContainerGameObject(pDataLabelContainer);

        List <GameObject> pChildGos = pNGraphDataSeries.setup(
            this,
            pGameObject,
            (GameObject pLabelGo, Vector3 pValue, string text) =>
        {
            if (text == null)
            {
                text = pValue.y.ToString();
            }
            Vector3 pDataLabelPosition = adjustPoint(new Vector2(pValue.x, pValue.y));
            AddDataSeriesLabel(pLabelGo, pDataLabelPosition, pValue, text);
        },
            pDataLabelContainer
            );

        newDataSeriesChildGameObjects(pChildGos);
        pNGraphDataSeries.DrawSeries();

        return(pNGraphDataSeries);
    }
Ejemplo n.º 10
0
    protected override void _drawAxes(Rect xAxis, Rect yAxis)
    {
        if (mAxisMeshRendererX == null)
        {
            NGraphUtils.AddMesh(mXAxesGo, out mAxisMeshRendererX, out mXAxisMesh);
        }
        if (mAxisMeshRendererY == null)
        {
            NGraphUtils.AddMesh(mYAxesGo, out mAxisMeshRendererY, out mYAxisMesh);
        }

        mAxisMeshRendererX.material = AxisMaterial;
        mAxisMeshRendererX.material.SetColor("_TintColor", AxisColor);
        mAxisMeshRendererY.material = AxisMaterial;
        mAxisMeshRendererY.material.SetColor("_TintColor", AxisColor);
        NGraphUtils.DrawRect(xAxis, mXAxisMesh);
        NGraphUtils.DrawRect(yAxis, mYAxisMesh);
    }
Ejemplo n.º 11
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        NGraphUtils.DrawSeparator();

        UIUnityGraph pGraph = (UIUnityGraph)target;

        GUILayout.BeginHorizontal();
        Font fnt = (Font)EditorGUILayout.ObjectField(pGraph.AxisLabelDynamicFont, typeof(Font), false, GUILayout.Width(140f));

        if (fnt != pGraph.AxisLabelDynamicFont)
        {
            UndoableAction <UIUnityGraph>(gr => gr.AxisLabelDynamicFont = fnt);
        }

        GUILayout.Label("font used by the labels");
        GUILayout.EndHorizontal();
    }
Ejemplo n.º 12
0
    protected override void _drawAxisTick(Axis axis, int index, GameObject pTickGameObject)
    {
        Material pMat = new Material(AxisMaterial);

        pMat.SetColor("_TintColor", AxisColor);
        CanvasRenderer pCanvasRenderer = NGraphUtils.AddCanvasRenderer(pTickGameObject);

        pCanvasRenderer.SetMaterial(pMat, null);

        mXAxisTicks.Add(pCanvasRenderer);
        if (axis == Axis.X)
        {
            NGraphUtils.DrawRect(new Rect(-AxesThickness / 2, AxesThickness / 2 + 4, AxesThickness, -AxesThickness - 8), pCanvasRenderer);
        }
        else if (axis == Axis.Y)
        {
            NGraphUtils.DrawRect(new Rect((-AxesThickness / 2) - 4, AxesThickness / 2, AxesThickness + 8, -AxesThickness), pCanvasRenderer);
        }
    }
    public override void OnGUI()
    {
        base.OnGUI();

        GUILayout.BeginHorizontal();

        mTrueTypeFont = (Font)EditorGUILayout.ObjectField(mTrueTypeFont, typeof(Font), false, GUILayout.Width(140f));

        GUILayout.Label("font used by the labels");
        GUILayout.EndHorizontal();
        NGraphUtils.DrawSeparator();

        GameObject go = NGraphUtils.SelectedRoot <Canvas>();

        if (ShouldCreate(go, go != null && mTrueTypeFont != null))
        {
            UIUnityGraph pGraph = CreateGraphGo <UIUnityGraph>(go);
            pGraph.AxisLabelDynamicFont = mTrueTypeFont;
        }
    }
Ejemplo n.º 14
0
    protected override void _drawMajorGridLine(Axis axis, int index, float r, GameObject pGridLineGameObject)
    {
        MeshRenderer pMeshRenderer;
        Mesh         pMesh;

        NGraphUtils.AddMesh(pGridLineGameObject, out pMeshRenderer, out pMesh);
        mXAxisTicks.Add(pMeshRenderer);

        pMeshRenderer.material = AxisMaterial;
        pMeshRenderer.material.SetColor("_TintColor", GridLinesColorMajor);

        if (axis == Axis.X)
        {
            NGraphUtils.DrawRect(new Rect(adjustPointX(r) - (GridLinesThicknesMajor / 2f), adjustPointY(YRange.y), GridLinesThicknesMajor, adjustPointY(YRange.x) - adjustPointY(YRange.y)), pMesh);
        }
        else if (axis == Axis.Y)
        {
            NGraphUtils.DrawRect(new Rect(adjustPointX(XRange.x), adjustPointY(r) + (GridLinesThicknesMajor / 2f), adjustPointX(XRange.y) - adjustPointX(XRange.x), -GridLinesThicknesMajor), pMesh);
        }
    }
Ejemplo n.º 15
0
    protected override void _drawMajorGridLine(Axis axis, int index, float r, GameObject pGridLineGameObject)
    {
        Material pMat = new Material(AxisMaterial);

        pMat.SetColor("_TintColor", GridLinesColorMajor);
        CanvasRenderer pCanvasRenderer = NGraphUtils.AddCanvasRenderer(pGridLineGameObject);

        pCanvasRenderer.Clear();
        pCanvasRenderer.SetMaterial(pMat, null);

        mXAxisTicks.Add(pCanvasRenderer);

        if (axis == Axis.X)
        {
            NGraphUtils.DrawRect(new Rect(adjustPointX(r) - (GridLinesThicknesMajor / 2f), adjustPointY(YRange.y), GridLinesThicknesMajor, adjustPointY(YRange.x) - adjustPointY(YRange.y)), pCanvasRenderer);
        }
        else if (axis == Axis.Y)
        {
            NGraphUtils.DrawRect(new Rect(adjustPointX(XRange.x), adjustPointY(r) + (GridLinesThicknesMajor / 2f), adjustPointX(XRange.y) - adjustPointX(XRange.x), -GridLinesThicknesMajor), pCanvasRenderer);
        }
    }
Ejemplo n.º 16
0
    protected override void _drawAxisTick(Axis axis, int index, GameObject pTickGameObject)
    {
        MeshRenderer pMeshRenderer;
        Mesh         pMesh;

        NGraphUtils.AddMesh(pTickGameObject, out pMeshRenderer, out pMesh);
        mXAxisTicks.Add(pMeshRenderer);

        pMesh.Clear();
        pMeshRenderer.material = AxisMaterial;
        pMeshRenderer.material.SetColor("_TintColor", AxisColor);

        if (axis == Axis.X)
        {
            NGraphUtils.DrawRect(new Rect(-AxesThickness / 2, AxesThickness / 2 + 4, AxesThickness, -AxesThickness - 8), pMesh);
        }
        else if (axis == Axis.Y)
        {
            NGraphUtils.DrawRect(new Rect(-AxesThickness / 2 - 4, -AxesThickness / 2, AxesThickness + 8, AxesThickness), pMesh);
        }
    }
Ejemplo n.º 17
0
    protected void DrawGrid()
    {
        // Make sure it exists
        if (mGridContainer == null)
        {
            mGridContainer = NGraphUtils.AddGameObject(mMeshesContainer, LEVEL_STEP * 2, "GridContainer");
            _addedGridContainer(mGridContainer);
        }

        // Clear the children
        for (int i = 0; i < mGridContainer.transform.childCount; i++)
        {
            Destroy(mGridContainer.transform.GetChild(i).gameObject);
        }

        int index = 0;

        if (GridLinesSeparationMajor.x > 0)
        {
            for (float r = XRange.x; r <= XRange.y; r += GridLinesSeparationMajor.x)
            {
                GameObject pGridLineGo = NGraphUtils.AddGameObject(mGridContainer, 0, "Major X Grid Line - " + r);
                this._drawMajorGridLine(Axis.X, index++, r, pGridLineGo);
            }
        }

        index = 0;
        if (GridLinesSeparationMajor.y > 0)
        {
            for (float r = YRange.x; r <= YRange.y; r += GridLinesSeparationMajor.y)
            {
                GameObject pGridLineGo = NGraphUtils.AddGameObject(mGridContainer, 0, "Major Y Grid Line - " + r);
                this._drawMajorGridLine(Axis.Y, index++, r, pGridLineGo);
            }
        }

        float z = mGridContainer.transform.localPosition.z;

        mGridContainer.transform.localPosition = new Vector3(0, 0, z);
    }
    public virtual void OnGUI()
    {
        /*
         * GUILayout.BeginHorizontal();
         * sGeneralMaterial = EditorGUILayout.ObjectField(sGeneralMaterial, typeof(Material), GUILayout.MinWidth(150f)) as Material;
         * GUILayout.Label("Material used by NGraph to draw meshes", GUILayout.MinWidth(10000f));
         * GUILayout.EndHorizontal();
         *
         * GUILayout.BeginHorizontal();
         * sDefaultPlotMaterial = EditorGUILayout.ObjectField(sDefaultPlotMaterial, typeof(Material), GUILayout.MinWidth(150f)) as Material;
         * GUILayout.Label("Default material used by NGraph to draw plots", GUILayout.MinWidth(10000f));
         * GUILayout.EndHorizontal();
         */
        EditorGUILayout.FloatField("Width", sWidth);
        EditorGUILayout.FloatField("Height", sHeight);

        sLabelColor          = EditorGUILayout.ColorField("Color of any labels", sLabelColor);
        sMarginColor         = EditorGUILayout.ColorField("Color of the margin area", sMarginColor);
        sPlotBackgroundColor = EditorGUILayout.ColorField("Color of plot area", sPlotBackgroundColor);
        sAxesColor           = EditorGUILayout.ColorField("Color of X and Y Axes", sAxesColor);
        NGraphUtils.DrawSeparator();
    }
Ejemplo n.º 19
0
    protected override void _drawAxes(Rect xAxis, Rect yAxis)
    {
        if (mAxisCanvasRendererX == null)
        {
            mAxisCanvasRendererX = NGraphUtils.AddCanvasRenderer(mXAxesGo);
        }
        if (mAxisCanvasRendererY == null)
        {
            mAxisCanvasRendererY = NGraphUtils.AddCanvasRenderer(mYAxesGo);
        }

        Material pMat = new Material(AxisMaterial);

        mAxisCanvasRendererX.SetMaterial(pMat, null);
        pMat.SetColor("_TintColor", AxisColor);

        pMat = new Material(AxisMaterial);
        mAxisCanvasRendererY.SetMaterial(pMat, null);
        pMat.SetColor("_TintColor", AxisColor);

        NGraphUtils.DrawRect(xAxis, mAxisCanvasRendererX);
        NGraphUtils.DrawRect(yAxis, mAxisCanvasRendererY);
    }
Ejemplo n.º 20
0
    protected virtual void DrawAxisTicks()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (mAxesGo == null)
        {
            return;
        }

        AxesDrawAt.x = Mathf.Clamp(AxesDrawAt.x, XRange.x, XRange.y);
        AxesDrawAt.y = Mathf.Clamp(AxesDrawAt.y, YRange.x, YRange.y);

        if (mAxesLabelContainerGo == null)
        {
            mAxesLabelContainerGo = NGraphUtils.AddGameObject(gameObject, 0, "Axes Label Container");
            addedAxesLabelContainer();
        }

        int numTicks = XNumberOfTicks;

        if (XTickStyle == TickStyle.EvenSpaceLowAndHigh)
        {
            numTicks--;
        }
        float step = (mXRange.y - mXRange.x) / numTicks;

        if (XTickStyle == TickStyle.EvenSpaceLowAndHigh)
        {
            numTicks++;
        }
        for (int i = 0; i < numTicks; i++)
        {
            GameObject pTickGo = NGraphUtils.AddGameObject(mXAxesGo, AXES_LEVEL * LEVEL_STEP, "Tick X - " + i);

            float val = step * (i + 1);
            if (XTickStyle == TickStyle.EvenSpace)
            {
                val -= step / 2;
            }
            else if (XTickStyle == TickStyle.EvenSpaceLow || XTickStyle == TickStyle.EvenSpaceLowAndHigh)
            {
                val -= step;
            }
            Vector2 pPoint = new Vector2(val + XRange.x, AxesDrawAt.y);
            pPoint = adjustPoint(pPoint);

            Vector3 pPosition = pTickGo.transform.localPosition;
            pPosition.x += pPoint.x;
            pPosition.y += pPoint.y;
            pTickGo.transform.localPosition = pPosition;

            if (DrawXLabel)
            {
                GameObject pTickLabelGo = NGraphUtils.AddGameObject(mAxesLabelContainerGo.gameObject, AXES_LEVEL * LEVEL_STEP, "Tick Label X - " + i);
                pPosition.y -= 4;

                AddAxisLabel(Axis.X, pTickLabelGo, pPosition, val + XRange.x);
            }
            this._drawAxisTick(Axis.X, i, pTickGo);
        }

        numTicks = YNumberOfTicks;
        if (YTickStyle == TickStyle.EvenSpaceLowAndHigh)
        {
            numTicks--;
        }
        step = (mYRange.y - mYRange.x) / numTicks;
        if (YTickStyle == TickStyle.EvenSpaceLowAndHigh)
        {
            numTicks++;
        }
        for (int i = 0; i < numTicks; i++)
        {
            GameObject pTickGo = NGraphUtils.AddGameObject(mYAxesGo, AXES_LEVEL * LEVEL_STEP, "Tick Y - " + i);

            float val = step * (i + 1);
            if (YTickStyle == TickStyle.EvenSpace)
            {
                val -= step / 2;
            }
            else if (YTickStyle == TickStyle.EvenSpaceLow || YTickStyle == TickStyle.EvenSpaceLowAndHigh)
            {
                val -= step;
            }
            Vector2 pPoint = new Vector2(AxesDrawAt.x, val + YRange.x);
            pPoint = adjustPoint(pPoint);

            Vector3 pPosition = pTickGo.transform.localPosition;
            pPosition.x += pPoint.x;
            pPosition.y += pPoint.y;
            pTickGo.transform.localPosition = pPosition;

            if (DrawYLabel)
            {
                GameObject pTickLabelGo = NGraphUtils.AddGameObject(mAxesLabelContainerGo.gameObject, 0, "Tick Label Y - " + i);
                pPosition.x -= 6;

                AddAxisLabel(Axis.Y, pTickLabelGo, pPosition, val + YRange.x);
            }

            this._drawAxisTick(Axis.Y, i, pTickGo);
        }
    }
Ejemplo n.º 21
0
 protected override void newDataSeriesGameObject(GameObject pGameObject)
 {
     pGameObject.AddComponent <RectTransform>();
     NGraphUtils.AddCanvasRenderer(pGameObject);
 }
Ejemplo n.º 22
0
 protected override void addedAxesLabelContainer()
 {
     mAxesLabelContainerGo.AddComponent <RectTransform>();
     NGraphUtils.AddCanvasRenderer(mAxesLabelContainerGo);
 }
Ejemplo n.º 23
0
 protected override void _addedYAxisGameObject(GameObject pAxisGameObject)
 {
     pAxisGameObject.AddComponent <RectTransform>();
     NGraphUtils.AddCanvasRenderer(pAxisGameObject);
 }
Ejemplo n.º 24
0
 protected override void _addedGridContainer(GameObject pGridContainer)
 {
     NGraphUtils.AddCanvasRenderer(pGridContainer);
 }
Ejemplo n.º 25
0
    protected void DrawAxisBackground()
    {
        if (mAxesBackgroundGo == null)
        {
            mAxesBackgroundGo = NGraphUtils.AddGameObject(mMeshesContainer, BACKGROUND_LEVEL * LEVEL_STEP, "Axes Background");
        }

        /*
         * a  b&m       n&i j
         *    p          o
         *
         *
         *
         *               l  k
         *     e            f
         * c  d&g           h
         *
         */
        Rect    pRect = mRectTransform.rect;
        Vector3 a     = new Vector3(pRect.xMin, pRect.yMax, 0);
        Vector3 b     = new Vector3(pRect.xMin + Margin.x, pRect.yMax, 0);
        Vector3 c     = new Vector3(pRect.xMin, pRect.yMin, 0);
        Vector3 d     = new Vector3(pRect.xMin + Margin.x, pRect.yMin, 0);

        Vector3 e = new Vector3(pRect.xMin + Margin.x, pRect.yMin + Margin.y, 0);
        Vector3 f = new Vector3(pRect.xMax, pRect.yMin + Margin.y, 0);
        Vector3 g = new Vector3(pRect.xMin + Margin.x, pRect.yMin, 0);
        Vector3 h = new Vector3(pRect.xMax, pRect.yMin, 0);

        Vector3 i = new Vector3(pRect.xMax - Margin.z, pRect.yMax, 0);
        Vector3 j = new Vector3(pRect.xMax, pRect.yMax, 0);
        Vector3 k = new Vector3(pRect.xMax, pRect.yMin + Margin.y, 0);
        Vector3 l = new Vector3(pRect.xMax - Margin.z, pRect.yMin + Margin.y, 0);

        Vector3 m = new Vector3(pRect.xMin + Margin.x, pRect.yMax, 0);
        Vector3 n = new Vector3(pRect.xMax - Margin.z, pRect.yMax, 0);
        Vector3 o = new Vector3(pRect.xMax - Margin.z, pRect.yMax - Margin.w, 0);
        Vector3 p = new Vector3(pRect.xMin + Margin.x, pRect.yMax - Margin.w, 0);

        List <UIVertex> pList     = new List <UIVertex>(6);
        UIVertex        pUIVertex = new UIVertex();


        pUIVertex.position = a;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = b;
        pUIVertex.uv0      = new Vector2(0.5f, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = d;
        pUIVertex.uv0      = new Vector2(0.5f, 0.5f);
        pList.Add(pUIVertex);

        pUIVertex.position = c;
        pUIVertex.uv0      = new Vector2(0, 0);
        pList.Add(pUIVertex);


        pUIVertex.position = e;
        pUIVertex.uv0      = new Vector2(1, 0.5f);
        pList.Add(pUIVertex);

        pUIVertex.position = f;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = h;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = g;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);


        pUIVertex.position = i;
        pUIVertex.uv0      = new Vector2(1, 0.5f);
        pList.Add(pUIVertex);

        pUIVertex.position = j;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = k;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = l;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);


        pUIVertex.position = m;
        pUIVertex.uv0      = new Vector2(1, 0.5f);
        pList.Add(pUIVertex);

        pUIVertex.position = n;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = o;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);

        pUIVertex.position = p;
        pUIVertex.uv0      = new Vector2(0, 1);
        pList.Add(pUIVertex);


        float z = mAxesBackgroundGo.transform.localPosition.z;

        this._drawAxisBackground(pList);
        mAxesBackgroundGo.transform.localPosition = new Vector3(0, 0, z);
    }
Ejemplo n.º 26
0
 protected override void newDataSeriesGameObject(GameObject pGameObject)
 {
     NGraphUtils.AddCanvasRenderer(pGameObject);
 }
Ejemplo n.º 27
0
 protected override void addedAxesLabelContainer()
 {
     NGraphUtils.AddCanvasRenderer(mAxesLabelContainerGo);
 }
Ejemplo n.º 28
0
    public override void DrawSeries()
    {
        if (mGameObject == null || mData == null)
        {
            return;
        }

        base.DrawSeries();
        clearMarkers();
        int meshCount = mData.Count;

        if (mPlotStyle == Style.Line)
        {
            meshCount = 1;
        }
        clearMeshes(meshCount);
        clearCanvasRenderers(meshCount);

        List <Vector3> pVertices  = new List <Vector3>();
        List <Vector2> pUvs       = new List <Vector2>();
        List <int>     pTriangles = new List <int>();

        Mesh           pMesh;
        CanvasRenderer pCanvasRenderer;

        if (!mGraph.UnityGui && mMeshes == null)
        {
            mMeshes = new List <KeyValuePair <GameObject, Mesh> >();
        }
        else if (mGraph.UnityGui && mCanvasRenderers == null)
        {
            mCanvasRenderers = new List <KeyValuePair <GameObject, CanvasRenderer> >();
        }

        Vector2 pZero = mGraph.adjustPoint(Vector2.zero);

        for (int i = 0; i < mData.Count; ++i)
        {
            Vector2 pDataPoint = mData[i];
            pDataPoint = mGraph.adjustPoint(pDataPoint);

            if (MarkersStyle != MarkerStyle.None)
            {
                drawMarker(pDataPoint, i);
            }

            if (mPlotStyle == Style.Line && i == 0)
            {
                continue;
            }

            if (mPlotStyle == Style.Line)
            {
                Vector2 pPrevDataPoint = mData[i - 1];
                NGraphUtils.addSegment(mGraph.adjustPoint(pPrevDataPoint), pDataPoint, PlotThickness, pVertices, pUvs, pTriangles, mGraph.UnityGui);
            }
            else if (mPlotStyle == Style.Bar)
            {
                if (mGraph.UnityGui)
                {
                    if (i >= mCanvasRenderers.Count)
                    {
                        GameObject pChildBarGo = NGraphUtils.AddGameObject(mGameObject, 0, "Bar - " + i);
                        pCanvasRenderer = NGraphUtils.AddCanvasRenderer(pChildBarGo);
                        mCanvasRenderers.Add(new KeyValuePair <GameObject, CanvasRenderer>(pChildBarGo, pCanvasRenderer));
                    }
                    else
                    {
                        pCanvasRenderer = mCanvasRenderers[i].Value;
                    }

                    Material pMat = new Material(PlotMaterial);
                    pMat.SetColor("_TintColor", PlotColor);
                    pMat.SetVector("_Clipping", new Vector4(mClipping.x, mClipping.y, mClipping.z, mClipping.w));

                    pCanvasRenderer.SetMaterial(pMat, null);

                    float h   = pDataPoint.y - pZero.y;
                    float top = pZero.y;
                    NGraphUtils.DrawRect(new Rect(-mPlotThickness / 2 + pDataPoint.x, top, mPlotThickness, h), pCanvasRenderer);
                }
                else
                {
                    if (i >= mMeshes.Count)
                    {
                        GameObject pChildBarGo = NGraphUtils.AddGameObject(mGameObject, 0, "Bar - " + i);
                        NGraphUtils.AddMesh(pChildBarGo, out mMeshRenderer, out pMesh);
                        mMeshes.Add(new KeyValuePair <GameObject, Mesh>(pChildBarGo, pMesh));
                        mMeshRenderer.material = new Material(PlotMaterial);
                        mMeshRenderer.material.SetColor("_TintColor", PlotColor);
                        mMeshRenderer.material.SetVector("_Clipping", new Vector4(mClipping.x, mClipping.y, mClipping.z, mClipping.w));
                    }
                    else
                    {
                        pMesh = mMeshes[i].Value;
                    }

                    pMesh.Clear();
                    NGraphUtils.DrawRect(new Rect(-mPlotThickness / 2 + pDataPoint.x, pZero.y, mPlotThickness, pDataPoint.y - pZero.y), pMesh);
                }
            }
        }

        if (mPlotStyle == Style.Line)
        {
            if (mGraph.UnityGui)
            {
                if (mCanvasRenderers.Count == 0)
                {
                    GameObject pChildBarGo = NGraphUtils.AddGameObject(mGameObject, 0, "Line");
                    pCanvasRenderer = NGraphUtils.AddCanvasRenderer(pChildBarGo);
                    mCanvasRenderers.Add(new KeyValuePair <GameObject, CanvasRenderer>(pChildBarGo, pCanvasRenderer));
                }
                else
                {
                    pCanvasRenderer = mCanvasRenderers[0].Value;
                }

                Vector3[] e = new Vector3[4];
                mGraph.GetComponent <RectTransform>().GetWorldCorners(e);

                Material pMat = new Material(PlotMaterial);
                pMat.SetColor("_TintColor", PlotColor);
                pMat.SetVector("_Clipping", new Vector4(mClipping.x, mClipping.y, mClipping.z, mClipping.w));

                pCanvasRenderer.SetMaterial(pMat, null);
                List <UIVertex> vertices = new List <UIVertex>(pVertices.Count);
                for (int i = 0; i < pVertices.Count; i++)
                {
                    UIVertex pVertex = new UIVertex();
                    pVertex.position = pVertices[i];
                    pVertex.uv0      = pUvs[i];
                    vertices.Add(pVertex);
                }
                pCanvasRenderer.SetVertices(vertices);
            }
            else
            {
                if (mMeshes.Count == 0)
                {
                    GameObject pChildBarGo = NGraphUtils.AddGameObject(mGameObject, 0, "Line");
                    NGraphUtils.AddMesh(pChildBarGo, out mMeshRenderer, out pMesh);
                    mMeshes.Add(new KeyValuePair <GameObject, Mesh>(pChildBarGo, pMesh));
                    mMeshRenderer.material = new Material(PlotMaterial);
                    mMeshRenderer.material.SetColor("_TintColor", PlotColor);
                    mMeshRenderer.material.SetVector("_Clipping", new Vector4(mClipping.x, mClipping.y, mClipping.z, mClipping.w));
                }
                else
                {
                    pMesh = mMeshes[0].Value;
                }

                pMesh.Clear();
                pMesh.vertices  = pVertices.ToArray();
                pMesh.uv        = pUvs.ToArray();
                pMesh.triangles = pTriangles.ToArray();
            }
        }

        // Draw data labels if available
        foreach (dataLabelStruct labelInfo in mDataLabels)
        {
            drawDataLabel(labelInfo);
        }
    }
Ejemplo n.º 29
0
    protected void drawMarker(Vector2 pDataPoint, int dataPointIndex)
    {
        Mesh           pMesh           = null;
        GameObject     pMarkerGo       = NGraphUtils.AddGameObject(mGameObject, NGraph.LEVEL_STEP, "Marker - " + dataPointIndex);
        CanvasRenderer pCanvasRenderer = null;

        if (mGraph.UnityGui)
        {
            pCanvasRenderer = NGraphUtils.AddCanvasRenderer(pMarkerGo);
            Material pMat = new Material(PlotMaterial);
            pMat.SetColor("_TintColor", mMarkerColor);
            pMat.SetVector("_Clipping", new Vector4(mClipping.x, mClipping.y, mClipping.z, mClipping.w));

            pCanvasRenderer.SetMaterial(pMat, null);
        }
        else
        {
            NGraphUtils.AddMesh(pMarkerGo, out mMeshRenderer, out pMesh);
            mMeshRenderer.material = PlotMaterial;
            mMeshRenderer.material.SetColor("_TintColor", mMarkerColor);
            mMeshRenderer.material.SetVector("_Clipping", new Vector4(mClipping.x, mClipping.y, mClipping.z, mClipping.w));
        }
        mMarkerGos.Add(pMarkerGo);

        List <Vector3> pVertices  = new List <Vector3>();
        List <Vector2> pUvs       = new List <Vector2>();
        List <int>     pTriangles = new List <int>();

        switch (MarkersStyle)
        {
        case MarkerStyle.Box:
        {
            /*
             * c      d
             *
             *
             * b      a
             */

            pVertices.Add(new Vector3(mMarkerWeight / 2 + pDataPoint.x, -mMarkerWeight / 2 + pDataPoint.y, 0));
            pVertices.Add(new Vector3(-mMarkerWeight / 2 + pDataPoint.x, -mMarkerWeight / 2 + pDataPoint.y, 0));
            pVertices.Add(new Vector3(-mMarkerWeight / 2 + pDataPoint.x, mMarkerWeight / 2 + pDataPoint.y, 0));
            pVertices.Add(new Vector3(mMarkerWeight / 2 + pDataPoint.x, mMarkerWeight / 2 + pDataPoint.y, 0));
            pUvs.Add(new Vector2(0, 0));
            pUvs.Add(new Vector2(1, 0));
            pUvs.Add(new Vector2(0, 1));
            pUvs.Add(new Vector2(1, 1));

            pTriangles.Add(0);
            pTriangles.Add(1);
            pTriangles.Add(2);

            pTriangles.Add(2);
            pTriangles.Add(3);
            pTriangles.Add(0);

            break;
        }

        case MarkerStyle.Triangle:
        {
            /*
             *    c
             *
             *
             * a      b
             */

            pVertices.Add(new Vector3(pDataPoint.x, pDataPoint.y + mMarkerWeight / 2, 0));
            pVertices.Add(new Vector3(mMarkerWeight / 2 + pDataPoint.x, -mMarkerWeight / 2 + pDataPoint.y, 0));
            pVertices.Add(new Vector3(-mMarkerWeight / 2 + pDataPoint.x, -mMarkerWeight / 2 + pDataPoint.y, 0));
            pUvs.Add(new Vector2(0, 0));
            pUvs.Add(new Vector2(1, 0));
            pUvs.Add(new Vector2(0.5f, 1));
            if (mGraph.UnityGui)
            {
                pVertices.Add(new Vector3(-mMarkerWeight / 2 + pDataPoint.x, -mMarkerWeight / 2 + pDataPoint.y, 0));
                pUvs.Add(new Vector2(0.5f, 1));
            }

            pTriangles.Add(0);
            pTriangles.Add(1);
            pTriangles.Add(2);

            break;
        }
        }

        if (mGraph.UnityGui)
        {
            List <UIVertex> vertices = new List <UIVertex>(pVertices.Count);
            for (int i = 0; i < pVertices.Count; i++)
            {
                UIVertex pVertex = new UIVertex();
                pVertex.position = pVertices[i];
                pVertex.uv0      = pUvs[i];
                vertices.Add(pVertex);
            }
            pCanvasRenderer.SetVertices(vertices);
        }
        else
        {
            pMesh.vertices  = pVertices.ToArray();
            pMesh.uv        = pUvs.ToArray();
            pMesh.triangles = pTriangles.ToArray();
        }
    }
Ejemplo n.º 30
0
 protected override void _addedYAxisGameObject(GameObject pAxisGameObject)
 {
     NGraphUtils.AddCanvasRenderer(pAxisGameObject);
 }