示例#1
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="loser"></param>
    /// <param name="loseTime"></param>
    /// <param name="loseRate"></param>
    IEnumerator ScreenLoseRoutine(DynamicScreen loser, float loseTime, AnimationCurve loseRate)
    {
        // TODO remove this, probs different just for tug of war
        if (sideCount <= 2) { yield break; }

        // default rate is linear
        if (loseRate == null)
        {
            loseRate = AnimationCurve.Linear(0, 0, 1, 1);
        }

        #region setup
        Border cwBorder = loser.cwBorder;
        Border ccwBorder = loser.ccwBorder;

        // center mesh points
        int mergeVertIndex = -1;
        Vector3[] startCenterVerts = new Vector3[0];
        CenterMeshInfo targetMeshInfo = new CenterMeshInfo();

        // find the ccw merging vert index of center mesh
        float min = Mathf.Infinity;
        for (int k = 1; k < verts.Length; k++)
        {
            // grab screen point of vert from overlay (main) camera
            float tempDistance = Vector2.Distance(GetScreenPointFromVert(k), ccwBorder.centerPointTarget);
            if (tempDistance < min)
            {
                min = tempDistance;
                mergeVertIndex = k;
            }
        }

        // start/target CenterMeshInfo
        startCenterVerts = (Vector3[])verts.Clone();
        Vector3 targetMeshStartVector = Camera.main.ScreenToWorldPoint((ccwBorder.centerPointTarget + cwBorder.centerPointTarget) / 2);
        targetMeshInfo = new CenterMeshInfo(sideCount - 1, targetMeshStartVector, meshSize);
        #endregion

        #region move over time
        // time data
        float elapsedTime = 0;
        float t = 0;

        // lerpz over time
        while (elapsedTime < loseTime)
        {
            elapsedTime += Time.deltaTime;
            t = loseRate.Evaluate(elapsedTime / loseTime);


            int startingVertIndex;
            int targetVertIndex = 0;
            Border tempBorder = ccwBorder;
            // loop from the cw merging vert (mergeVertIndex) around the center mesh
            for (int i = mergeVertIndex; i < mergeVertIndex + sideCount; i++)
            {
                // clamp i within verts
                startingVertIndex = (i < verts.Length) ? i : i - sideCount;

                if (sideCount > 3)
                {
                    // make sure the two merging verts merge to the same center target point
                    if (startingVertIndex == mergeVertIndex)
                    {
                        verts[startingVertIndex] = Vector3.Lerp(startCenterVerts[startingVertIndex], targetMeshInfo.verts[1], t);
                    }
                    else
                    {
                        verts[startingVertIndex] = Vector3.Lerp(startCenterVerts[startingVertIndex], targetMeshInfo.verts[targetVertIndex], t);
                    }
                }
                else
                {
                    verts[startingVertIndex] = Vector3.Lerp(startCenterVerts[startingVertIndex], Vector3.zero, t);
                }

                // redraw
                Redraw();

                // connect border center points
                tempBorder.centerPointTarget = GetScreenPointFromVert(startingVertIndex);
                tempBorder = tempBorder.cwBorder;

                targetVertIndex++;
            }

            yield return null;
        }
        #endregion

        sideCount--;

        // if more than two sides (not 2 players) double check data
        if (sideCount > 2)
        {
            Redraw(targetMeshInfo);
            Border b = ccwBorder;
            for (int i = 0; i < sideCount - 1; i++)
            {
                b.centerPointTarget = GetScreenPointFromVert(i + 1);
                b = b.cwBorder;
            }
        }
    }
示例#2
0
    /// <summary>
    /// redraw the center mesh based on a new CenterMeshInfo
    /// </summary>
    public void Redraw(CenterMeshInfo newMeshInfo)
    {
        tris = newMeshInfo.tris;
        mf.mesh.triangles = newMeshInfo.tris;

        verts = newMeshInfo.verts;
        mf.mesh.vertices = newMeshInfo.verts;
    }
示例#3
0
    /// <summary>
    /// setup the mesh based on newPlayerCount
    /// </summary>
    /// <param name="newPlayerCount"> number of players (sides) to set the mesh up for </param>
    public void InitMesh(int newPlayerCount)
    {
        // update sideCount
        sideCount = newPlayerCount;

        // create mesh info starting at top center
        CenterMeshInfo newMeshInfo = new CenterMeshInfo(sideCount, 90, meshSize + 1);
        verts = newMeshInfo.verts;
        tris = newMeshInfo.tris;

        mf.mesh.vertices = verts;
        mf.mesh.triangles = tris;
    }