示例#1
0
 //Gizmos to help visualize it
 private void OnDrawGizmos()
 {
     foreach (Rails r in cameraPath)
     {
         Gizmos.color = r.color;
         Gizmos.DrawLine(endPoints[r.startPoint].transform.position, r.pos[0].position);
         int i = 0;
         for (; i < r.pos.Length - 1; ++i)
         {
             Gizmos.DrawLine(r.pos[i].position, r.pos[i + 1].position);
             Gizmos.DrawRay(r.pos[i].position, r.pos[i].forward);
         }
         Gizmos.DrawLine(endPoints[r.endPoint].transform.position, r.pos[i].position);
         //Segment 2
         {
             Gizmos.color = r.color;
             WATransform[] pos = new WATransform[r.pos.Length + 2];
             pos[0]     = new WATransform();
             pos[0].pos = endPoints[r.startPoint].transform.position;
             pos[0].rot = endPoints[r.startPoint].transform.rotation;
             i          = 0;
             for (; i < r.pos.Length; i++)
             {
                 pos[i + 1]     = new WATransform();
                 pos[i + 1].pos = r.pos[i].position;
                 pos[i + 1].rot = r.pos[i].localRotation;
             }
             pos[i + 1]     = new WATransform();
             pos[i + 1].pos = endPoints[r.endPoint].transform.position;
             pos[i + 1].rot = endPoints[r.endPoint].transform.rotation;
             WATransform pos1 = PositionLerpRecursive(pos, 0.1f);
             Gizmos.DrawLine(pos[0].pos, pos1.pos);
             WATransform pos2 = PositionLerpRecursive(pos, 0.2f);
             Gizmos.DrawLine(pos1.pos, pos2.pos);
             pos1 = PositionLerpRecursive(pos, 0.3f);
             Gizmos.DrawLine(pos2.pos, pos1.pos);
             pos2 = PositionLerpRecursive(pos, 0.4f);
             Gizmos.DrawLine(pos1.pos, pos2.pos);
             pos1 = PositionLerpRecursive(pos, 0.5f);
             Gizmos.DrawLine(pos2.pos, pos1.pos);
             pos2 = PositionLerpRecursive(pos, 0.6f);
             Gizmos.DrawLine(pos1.pos, pos2.pos);
             pos1 = PositionLerpRecursive(pos, 0.7f);
             Gizmos.DrawLine(pos2.pos, pos1.pos);
             pos2 = PositionLerpRecursive(pos, 0.8f);
             Gizmos.DrawLine(pos1.pos, pos2.pos);
             pos1 = PositionLerpRecursive(pos, 0.9f);
             Gizmos.DrawLine(pos2.pos, pos1.pos);
             Gizmos.DrawLine(pos1.pos, pos[pos.Length - 1].pos);
         }
     }
     //Draw the endpoints and the directions their facing
     Gizmos.color = Color.white;
     foreach (Points t in endPoints)
     {
         Gizmos.DrawSphere(t.transform.position, 0.2f);
         Gizmos.DrawRay(t.transform.position, t.transform.forward);
     }
 }
示例#2
0
    //More indepth
    //private void OnDrawGizmosSelected()
    //{
    //	foreach (Rails r in cameraPath)
    //	{
    //		Gizmos.color = r.color;
    //		WATransform[] pos = new WATransform[r.pos.Length + 2];
    //		pos[0] = new WATransform();
    //		pos[0].pos = endPoints[r.startPoint].transform.position;
    //		pos[0].rot = endPoints[r.startPoint].transform.rotation;
    //		int i = 0;
    //		for (; i < r.pos.Length; i++)
    //		{
    //			pos[i + 1] = new WATransform();
    //			pos[i + 1].pos = r.pos[i].position;
    //			pos[i + 1].rot = r.pos[i].localRotation;
    //		}
    //		pos[i + 1] = new WATransform();
    //		pos[i + 1].pos = endPoints[r.endPoint].transform.position;
    //		pos[i + 1].rot = endPoints[r.endPoint].transform.rotation;
    //		WATransform pos1 = PositionLerpRecursive(pos, 0.1f);
    //		Gizmos.DrawLine(pos[0].pos, pos1.pos);
    //		WATransform pos2 = PositionLerpRecursive(pos, 0.2f);
    //		Gizmos.DrawLine(pos1.pos, pos2.pos);
    //		pos1 = PositionLerpRecursive(pos, 0.3f);
    //		Gizmos.DrawLine(pos2.pos, pos1.pos);
    //		pos2 = PositionLerpRecursive(pos, 0.4f);
    //		Gizmos.DrawLine(pos1.pos, pos2.pos);
    //		pos1 = PositionLerpRecursive(pos, 0.5f);
    //		Gizmos.DrawLine(pos2.pos, pos1.pos);
    //		pos2 = PositionLerpRecursive(pos, 0.6f);
    //		Gizmos.DrawLine(pos1.pos, pos2.pos);
    //		pos1 = PositionLerpRecursive(pos, 0.7f);
    //		Gizmos.DrawLine(pos2.pos, pos1.pos);
    //		pos2 = PositionLerpRecursive(pos, 0.8f);
    //		Gizmos.DrawLine(pos1.pos, pos2.pos);
    //		pos1 = PositionLerpRecursive(pos, 0.9f);
    //		Gizmos.DrawLine(pos2.pos, pos1.pos);
    //		Gizmos.DrawLine(pos1.pos, pos[pos.Length - 1].pos);
    //	}
    //}
    #endregion

    //Recursive lerp to guide the camera smoothly along its rails
    private WATransform PositionLerpRecursive(WATransform[] _pos, float _time)
    {
        if (_pos.Length == 1)
        {
            return(_pos[0]);
        }
        //Create a new array thats 1 shorter then the original
        WATransform[] pos = new WATransform[_pos.Length - 1];
        //Fill it
        for (int i = 0; i < pos.Length; ++i)
        {
            WATransform temp = new WATransform();
            temp.pos = Vector3.Lerp(_pos[i].pos, _pos[i + 1].pos, _time);
            temp.rot = Quaternion.Lerp(_pos[i].rot, _pos[i + 1].rot, _time);
            pos[i]   = temp;
        }
        //Next iter
        return(PositionLerpRecursive(pos, _time));
    }
示例#3
0
    // Update is called once per frame
    private void MainMenuUpdate()
    {
        //If we want to move the camera somewhere
        if (moving)
        {
            if (reverse)
            {
                timer -= Time.deltaTime / cameraPath[path].travelTime;
                //Break on timeout
                if (timer < 0.0f)
                {
                    moving  = false;
                    current = cameraPath[path].startPoint;
                }
            }
            else
            {
                timer += Time.deltaTime / cameraPath[path].travelTime;
                //Break on timeout
                if (timer > 1.0f)
                {
                    moving  = false;
                    current = cameraPath[path].endPoint;
                }
            }
            //Lerp rotation and position between points
            WATransform[] pos = new WATransform[cameraPath[path].pos.Length + 2];
            //First the start point
            pos[0]     = new WATransform();
            pos[0].pos = endPoints[cameraPath[path].startPoint].transform.position;
            pos[0].rot = endPoints[cameraPath[path].startPoint].transform.rotation;
            int i = 0;
            for (; i < cameraPath[path].pos.Length; i++)
            {
                pos[i + 1]     = new WATransform();
                pos[i + 1].pos = cameraPath[path].pos[i].position;
                pos[i + 1].rot = cameraPath[path].pos[i].localRotation;
            }
            //Lastly the endpoint
            pos[i + 1]     = new WATransform();
            pos[i + 1].pos = endPoints[cameraPath[path].endPoint].transform.position;
            pos[i + 1].rot = endPoints[cameraPath[path].endPoint].transform.rotation;
            //Process
            WATransform output = PositionLerpRecursive(pos, timer);
            mainCamera.transform.position      = output.pos;
            mainCamera.transform.localRotation = output.rot;
        }
        else         //Deny input commands while move in progress
        {
            if (state == MENU_STATE.CHARACTER_SELECT)
            {
                selectionScreen.SetActive(true);

                Vector2 p1Selection;
                Vector2 p2Selection;
                //First come first serve selection
                //add some way for players to see who they selected
                p1Selection.x = XCI.GetAxis(XboxAxis.LeftStickX, p1XCtrl.controller);
                p1Selection.y = XCI.GetAxis(XboxAxis.LeftStickY, p1XCtrl.controller);

                p2Selection.x = XCI.GetAxis(XboxAxis.LeftStickX, p2XCtrl.controller);
                p2Selection.y = XCI.GetAxis(XboxAxis.LeftStickY, p2XCtrl.controller);

                //p1Selection.x = Input.GetAxis("Horizontal");
                //p1Selection.y = Input.GetAxis("Vertical");

                //DEBUG just start
                if (Input.GetKeyDown(KeyCode.Z))
                {
                    p1Selected = 1;
                    p2Selected = 2;
                    endPoints[current].call.Invoke();
                }
                //moving at ???? meaningless units a second
                p1Vec += p1Selection * selectionScreenMovespeed * Time.deltaTime;
                p2Vec += p2Selection * selectionScreenMovespeed * Time.deltaTime;

                p1Cursor.GetComponent <RectTransform>().localPosition = p1Vec;
                p2Cursor.GetComponent <RectTransform>().localPosition = p2Vec;
                //Cursor no escape
                Rect edges = selectionScreen.GetComponent <RectTransform>().rect;
                if (p1Vec.x >= edges.xMax)
                {
                    p1Vec.x = edges.xMax;
                }
                else if (p1Vec.x <= edges.xMin)
                {
                    p1Vec.x = edges.xMin;
                }
                if (p1Vec.y >= edges.yMax)
                {
                    p1Vec.y = edges.yMax;
                }
                else if (p1Vec.y <= edges.yMin)
                {
                    p1Vec.y = edges.yMin;
                }
                //Cursor no escape 2
                if (p2Vec.x >= edges.xMax)
                {
                    p2Vec.x = edges.xMax;
                }
                else if (p2Vec.x <= edges.xMin)
                {
                    p2Vec.x = edges.xMin;
                }
                if (p2Vec.y >= edges.yMax)
                {
                    p2Vec.y = edges.yMax;
                }
                else if (p2Vec.y <= edges.yMin)
                {
                    p2Vec.y = edges.yMin;
                }

                //P1 Poosh
                if (XCI.GetButtonDown(XboxButton.A, p1XCtrl.controller))
                {
                    //P1 cursor hitboxes
                    if (p1Vec.x <= rChu.xMax && p1Vec.x >= rChu.xMin &&
                        p1Vec.y <= rChu.yMax && p1Vec.y >= rChu.yMin)
                    {
                        if (p2Selected != 1 && p1Selected != 2)
                        {
                            p1Selected = 1;
                            oChu.GetComponent <CanvasRenderer>().SetColor(Color.red);
                        }
                        else
                        {
                            //p1Selected = -1;
                        }
                    }
                    else if (p1Vec.x <= rSiz.xMax && p1Vec.x >= rSiz.xMin &&
                             p1Vec.y <= rSiz.yMax && p1Vec.y >= rSiz.yMin)
                    {
                        if (p2Selected != 2 && p1Selected != 1)
                        {
                            p1Selected = 2;
                            oSiz.GetComponent <CanvasRenderer>().SetColor(Color.red);
                        }
                        else
                        {
                            //p1Selected = -1;
                        }
                    }
                }
                else if (XCI.GetButtonDown(XboxButton.B, p1XCtrl.controller))
                {
                    //Reset color to white
                    if (p1Selected == 1)
                    {
                        oChu.GetComponent <CanvasRenderer>().SetColor(Color.white);
                    }
                    else if (p1Selected == 2)
                    {
                        oSiz.GetComponent <CanvasRenderer>().SetColor(Color.white);
                    }
                    //Clear selected
                    p1Selected = -1;
                }
                //P2 Poosh
                if (XCI.GetButtonDown(XboxButton.A, p2XCtrl.controller))
                {
                    //P2 cursor hitboxes
                    if (p2Vec.x <= rChu.xMax && p2Vec.x >= rChu.xMin &&
                        p2Vec.y <= rChu.yMax && p2Vec.y >= rChu.yMin)
                    {
                        if (p1Selected != 1 && p2Selected != 2)
                        {
                            p2Selected = 1;
                            oChu.GetComponent <CanvasRenderer>().SetColor(Color.blue);
                        }
                        else
                        {
                            //p2Selected = -1;
                        }
                    }
                    else if (p2Vec.x <= rSiz.xMax && p2Vec.x >= rSiz.xMin &&
                             p2Vec.y <= rSiz.yMax && p2Vec.y >= rSiz.yMin)
                    {
                        if (p1Selected != 2 && p2Selected != 1)
                        {
                            p2Selected = 2;
                            oSiz.GetComponent <CanvasRenderer>().SetColor(Color.blue);
                        }
                        else
                        {
                            //p2Selected = -1;
                        }
                    }
                }
                else if (XCI.GetButtonDown(XboxButton.B, p2XCtrl.controller))
                {
                    //Reset color to white
                    if (p2Selected == 1)
                    {
                        oChu.GetComponent <CanvasRenderer>().SetColor(Color.white);
                    }
                    else if (p2Selected == 2)
                    {
                        oSiz.GetComponent <CanvasRenderer>().SetColor(Color.white);
                    }
                    //Clear selected
                    p2Selected = -1;
                }
            }
            //Debug keyboard buttons
            if (Input.GetKeyDown(KeyCode.Return))
            {
                endPoints[current].call.Invoke();
            }
            //Positive Movement
            else if (Input.GetKeyDown(KeyCode.D))
            {
                if (endPoints[current].movePositive != -1)
                {
                    MoveTo(endPoints[current].movePositive);
                }
            }
            //Negative movement
            else if (Input.GetKeyDown(KeyCode.A))
            {
                if (endPoints[current].moveNegative != -1)
                {
                    MoveTo(endPoints[current].moveNegative);
                }
            }

            //Xbone controller inputs
            if (xboxController.useController)
            {
                float horiAxis = XCI.GetAxis(XboxAxis.LeftStickX);
                //Confirm
                if (XCI.GetButtonDown(XboxButton.A, xboxController.controller))
                {
                    endPoints[current].call.Invoke();
                }
                else if (horiAxis > 0.5f)                 //Positive Movement
                {
                    MoveTo(endPoints[current].movePositive);
                }
                else if (horiAxis < -0.5f)                 //Negative Movement
                {
                    MoveTo(endPoints[current].moveNegative);
                }
            }
        }
    }