コード例 #1
0
ファイル: Temperature.cs プロジェクト: liangmbs/MarineScience
    void Animate()
    {
        if (animationTimer > animationSeconds && pickTimer > pickSeconds)
        {
            animating      = false;
            animationTimer = 0;
            flipTimer      = 0;
            PickTemperature();
            selectorDot.GetComponent <SpriteRenderer>().enabled = false;
            transform.position = homePos;
            return;
        }

        if (animationTimer <= animationSeconds)
        {
            float currentFlipLength = animationFlipMinSpeed +
                                      (1 - animationTimer / animationSeconds) *
                                      (animationFlipMaxSpeed - animationFlipMinSpeed);
            if (flipTimer > currentFlipLength)
            {
                //pick new dot and try to make sure it's not the same as the first one
                int lastIndex = currentDot.index;
                int newIndex  = lastIndex;
                for (int i = 0; i < 10; i++)
                {
                    if (lastIndex == newIndex)
                    {
                        newIndex = Random.Range(0, dots.Count);
                    }
                }
                currentDot = dots[newIndex];
                //color new dot
                selectorDot.GetComponent <SpriteRenderer>().enabled = true;
                selectorDot.transform.position = currentDot.spriteRender.transform.position;
                //increment
                flipTimer = 0;
            }

            animationTimer += Time.deltaTime;
            flipTimer      += Time.deltaTime;
        }
        else
        {
            pickFlicker += Time.deltaTime;
            if (pickFlicker > pickSeconds / 10)
            {
                selectorDot.GetComponent <SpriteRenderer>().enabled = !selectorDot.GetComponent <SpriteRenderer>().enabled;
                pickFlicker = 0;
            }
            pickTimer         += Time.deltaTime;
            transform.position = Vector3.Lerp(homePos, homePos + new Vector3(-segmentSpacing, 0, 0), pickTimer / pickSeconds);
            currentDot.lineRender.SetColors(Color.white, Color.white);
        }
    }
コード例 #2
0
ファイル: Temperature.cs プロジェクト: liangmbs/MarineScience
    // Use this for initialization
    void Start()
    {
        homePos = transform.position;
        //create our historical lines
        historyLine            = GetComponent <LineRenderer>();
        historicalTemperatures = new Queue <float>();
        for (int i = 0; i < historicalSegments; i++)
        {
            historicalTemperatures.Enqueue(20);
        }
        historicalLineRenders = new List <LineRenderer>();
        for (int i = 0; i < historicalSegments - 1; i++)
        {
#if UNITY_EDITOR
            GameObject lineObj = (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(linePrefab);
#else
            GameObject lineObj = GameObject.Instantiate(linePrefab);
#endif
            lineObj.transform.parent     = this.transform;
            lineObj.transform.position   = transform.position + new Vector3(0, 0, -1);
            lineObj.transform.localScale = new Vector3(1, 1, 1);
            historicalLineRenders.Add(lineObj.GetComponent <LineRenderer>());
        }

        //create our branching lines
        predictionLines = new List <LineRenderer>();
        for (int i = 0; i < numPredictions; i++)
        {
            //instantiate
#if UNITY_EDITOR
            GameObject lineObj = (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(linePrefab);
#else
            GameObject lineObj = GameObject.Instantiate(linePrefab);
#endif
            //make the lines children of this object
            lineObj.transform.parent     = this.transform;
            lineObj.transform.position   = transform.position + new Vector3(0, 0, -1);
            lineObj.transform.localScale = new Vector3(1, 1, 1);
            //and put them in a list
            predictionLines.Add(lineObj.GetComponent <LineRenderer>());
        }

        //create some dots
        dots = new List <TempDot>();
        for (int i = 0; i < numPredictions + maxChanceDots; i++)
        {
#if UNITY_EDITOR
            GameObject dotObj = (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(dotPrefab);
#else
            GameObject dotObj = GameObject.Instantiate(dotPrefab);
#endif
            dotObj.transform.parent = this.transform;
            //dotObj.transform.localScale *= transform.localScale;
            dots.Add(new TempDot(dotObj.GetComponent <SpriteRenderer>(), 0, null, i));
        }
        currentDot = dots[0];

        //disable our selector dot
        selectorDot.GetComponent <SpriteRenderer>().enabled = false;

        generatePossibilities();
        drawLines();
    }