Exemple #1
0
    void blinkCurrentPointAnimation(bool fromOnCompleteAnimateAdd = false)
    {
        graph.Refresh();         // Ensures gamobject list of series points is up to date based on pointValues
        WMG_Node lastPoint           = series1.getLastPoint().GetComponent <WMG_Node>();
        string   blinkingPointAnimId = series1.GetHashCode() + "blinkingPointAnim";

        DOTween.Kill(blinkingPointAnimId);
        blinkingTween = lastPoint.objectToScale.transform.DOScale(new Vector3(blinkScale, blinkScale, blinkScale), blinkAnimDuration).SetEase(plotEaseType)
                        .SetUpdate(false).SetId(blinkingPointAnimId).SetLoops(-1, LoopType.Yoyo);
        if (series1.pointValues.Count > 1)           // ensure previous point scale reset
        {
            WMG_Node blinkingNode = series1.getPoints()[series1.getPoints().Count - 2].GetComponent <WMG_Node>();
            if (fromOnCompleteAnimateAdd)               // removing a pointValues index deletes the gameobject at the end, so need to set the timeline from the previous tween
            {
                blinkingTween.Goto(blinkAnimDuration * blinkingNode.objectToScale.transform.localScale.x / blinkScale, true);
            }
            blinkingNode.objectToScale.transform.localScale = Vector3.one;
        }
    }
    private void SeriesDataChangedMethod(WMG_Series aSeries)
    {
        // Animate the points, links, and bars
        List <GameObject> objects = aSeries.getPoints();

        for (int i = 0; i < objects.Count; i++)
        {
            if (aSeries.seriesIsLine)
            {
                // For line graphs, need to animate links as well via callback functions
                GameObject go = objects[i];                 // otherwise causes warnings when used in lambda expression for DOTween callback

                string tweenID = aSeries.GetHashCode() + "autoAnim" + i;
//				if (aSeries.name == "Series1") {
//					if (i == objects.Count-1) {
//						GlobalVariableBackground.Instance.conManager.WriteLog("curX: " + go.transform.localPosition.x + " curY: " + go.transform.localPosition.y);
//						GlobalVariableBackground.Instance.conManager.WriteLog("x: " + aSeries.AfterPositions()[i].x + " y: " + aSeries.AfterPositions()[i].y);
//						StartCoroutine(test (go));
//					}
//				}
                bool isLast = (i == objects.Count - 1);
                if (aSeries.currentlyAnimating)
                {
                    DOTween.Kill(tweenID);
                    animateLinkCallback(aSeries, go, isLast);
                }
                WMG_Anim.animPositionCallbacks(go, theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                               new Vector3(aSeries.AfterPositions()[i].x, aSeries.AfterPositions()[i].y),
                                               () => animateLinkCallback(aSeries, go, isLast), () => animateLinkCallbackEnd(aSeries, isLast), tweenID);
            }
            else
            {
                // For bar graphs, animate widths and heights in addition to position. Depending on pivot / GUI system, animating width / height also affects position
                Vector2 newPos = theGraph.getChangeSpritePositionTo(objects[i], new Vector2(aSeries.AfterPositions()[i].x, aSeries.AfterPositions()[i].y));

                WMG_Anim.animPosition(objects[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                      new Vector3(newPos.x, newPos.y));

                WMG_Anim.animSize(objects[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                  new Vector2(aSeries.AfterWidths()[i], aSeries.AfterHeights()[i]));
            }
        }
        // Animate the data point labels
        List <GameObject> dataLabels = aSeries.getDataLabels();

        for (int i = 0; i < dataLabels.Count; i++)
        {
            if (aSeries.seriesIsLine)
            {
                float   newX   = aSeries.dataLabelsOffset.x;
                float   newY   = aSeries.dataLabelsOffset.y;
                Vector2 newPos = theGraph.getChangeSpritePositionTo(dataLabels[i], new Vector2(newX, newY));
                newPos = new Vector2(newPos.x + aSeries.AfterPositions()[i].x, newPos.y + aSeries.AfterPositions()[i].y);
                WMG_Anim.animPosition(dataLabels[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                      new Vector3(newPos.x, newPos.y));
            }
            else
            {
                float newY = aSeries.dataLabelsOffset.y + aSeries.AfterPositions()[i].y + theGraph.barWidth / 2;
                float newX = aSeries.dataLabelsOffset.x + aSeries.AfterPositions()[i].x + aSeries.AfterWidths()[i];
                if (aSeries.getBarIsNegative(i))
                {
                    newX = -aSeries.dataLabelsOffset.x - aSeries.AfterWidths()[i] + Mathf.RoundToInt((theGraph.barAxisValue - theGraph.xAxis.AxisMinValue) / (theGraph.xAxis.AxisMaxValue - theGraph.xAxis.AxisMinValue) * theGraph.xAxisLength);
                }
                if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                {
                    newY = aSeries.dataLabelsOffset.y + aSeries.AfterPositions()[i].y + aSeries.AfterHeights()[i];
                    newX = aSeries.dataLabelsOffset.x + aSeries.AfterPositions()[i].x + theGraph.barWidth / 2;
                    if (aSeries.getBarIsNegative(i))
                    {
                        newY = -aSeries.dataLabelsOffset.y - aSeries.AfterHeights()[i] + Mathf.RoundToInt((theGraph.barAxisValue - theGraph.yAxis.AxisMinValue) / (theGraph.yAxis.AxisMaxValue - theGraph.yAxis.AxisMinValue) * theGraph.yAxisLength);
                    }
                }
                Vector2 newPos = theGraph.getChangeSpritePositionTo(dataLabels[i], new Vector2(newX, newY));
                WMG_Anim.animPosition(dataLabels[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                      new Vector3(newPos.x, newPos.y));
            }
        }

        if (!aSeries.currentlyAnimating)
        {
            aSeries.currentlyAnimating = true;
        }
    }
    private void SeriesDataChangedMethod(WMG_Series aSeries)
    {
        // Animate the points, links, and bars
        List<GameObject> objects = aSeries.getPoints();
        for (int i = 0; i < objects.Count; i++) {
            if (aSeries.seriesIsLine) {

                // For line graphs, need to animate links as well via callback functions
                GameObject go = objects[i]; // otherwise causes warnings when used in lambda expression for DOTween callback

                string tweenID = aSeries.GetHashCode() + "autoAnim" + i;
        //				if (aSeries.name == "Series1") {
        //					if (i == objects.Count-1) {
        //						Debug.Log("curX: " + go.transform.localPosition.x + " curY: " + go.transform.localPosition.y);
        //						Debug.Log("x: " + aSeries.AfterPositions()[i].x + " y: " + aSeries.AfterPositions()[i].y);
        //						StartCoroutine(test (go));
        //					}
        //				}
                if (aSeries.currentlyAnimating) {
                    DOTween.Kill(tweenID);
                    animateLinkCallback(aSeries, go);
                }
                WMG_Anim.animPositionCallbacks(go, theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                               new Vector3(aSeries.AfterPositions()[i].x, aSeries.AfterPositions()[i].y),
                                               ()=> animateLinkCallback(aSeries, go), ()=> animateLinkCallbackEnd(aSeries), tweenID);
            }
            else {
                // For bar graphs, animate widths and heights in addition to position. Depending on pivot / GUI system, animating width / height also affects position
                Vector2 newPos = theGraph.getChangeSpritePositionTo(objects[i], new Vector2(aSeries.AfterPositions()[i].x, aSeries.AfterPositions()[i].y));

                WMG_Anim.animPosition(objects[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                      new Vector3(newPos.x, newPos.y));

                WMG_Anim.animSize(objects[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                  new Vector2(aSeries.AfterWidths()[i], aSeries.AfterHeights()[i]));
            }
        }
        // Animate the data point labels
        List<GameObject> dataLabels = aSeries.getDataLabels();
        for (int i = 0; i < dataLabels.Count; i++) {
            if (aSeries.seriesIsLine) {
                float newX = aSeries.dataLabelsOffset.x;
                float newY = aSeries.dataLabelsOffset.y;
                Vector2 newPos = theGraph.getChangeSpritePositionTo(dataLabels[i], new Vector2(newX, newY));
                newPos = new Vector2(newPos.x + aSeries.AfterPositions()[i].x, newPos.y + aSeries.AfterPositions()[i].y);
                WMG_Anim.animPosition(dataLabels[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                      new Vector3(newPos.x, newPos.y));
            }
            else {
                float newY = aSeries.dataLabelsOffset.y + aSeries.AfterPositions()[i].y + theGraph.barWidth / 2;
                float newX = aSeries.dataLabelsOffset.x + aSeries.AfterPositions()[i].x + aSeries.AfterWidths()[i];
                if (aSeries.getBarIsNegative(i)) {
                    newX = -aSeries.dataLabelsOffset.x - aSeries.AfterWidths()[i] + Mathf.RoundToInt((theGraph.barAxisValue - theGraph.xAxis.AxisMinValue) / (theGraph.xAxis.AxisMaxValue - theGraph.xAxis.AxisMinValue) * theGraph.xAxisLength);
                }
                if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical) {
                    newY = aSeries.dataLabelsOffset.y + aSeries.AfterPositions()[i].y + aSeries.AfterHeights()[i];
                    newX = aSeries.dataLabelsOffset.x + aSeries.AfterPositions()[i].x + theGraph.barWidth / 2;
                    if (aSeries.getBarIsNegative(i)) {
                        newY = -aSeries.dataLabelsOffset.y - aSeries.AfterHeights()[i] + Mathf.RoundToInt((theGraph.barAxisValue - theGraph.yAxis.AxisMinValue) / (theGraph.yAxis.AxisMaxValue - theGraph.yAxis.AxisMinValue) * theGraph.yAxisLength);
                    }
                }
                Vector2 newPos = theGraph.getChangeSpritePositionTo(dataLabels[i], new Vector2(newX, newY));
                WMG_Anim.animPosition(dataLabels[i], theGraph.autoAnimationsDuration, theGraph.autoAnimationsEasetype,
                                      new Vector3(newPos.x, newPos.y));
            }
        }

        if (!aSeries.currentlyAnimating) {
            aSeries.currentlyAnimating = true;
        }
    }