Ejemplo n.º 1
0
    // Fun fact, scriptable objects created at runtime will not be kept.

    public DATA_Play FConvertPlayToDATA(string sName)
    {
        DATA_Play play = new DATA_Play();

        play.mName = sName;

        // get array of all ED_Roles? Then save them.
        PE_Role[] roles = FindObjectsOfType <PE_Role>();
        play.mPlayerRoles = new DT_PlayerRole[roles.Length];
        for (int i = 0; i < roles.Length; i++)
        {
            DT_PlayerRole temp = new DT_PlayerRole();
            temp.mRole = roles[i].mRole;
            // temp.mStart = roles[i].mStartPos;
            temp.mTag = roles[i].mTag;

            // find the position from the field position.
            float fMetersToPixels = 50f / rField.GetComponent <RectTransform>().rect.width;      // field is 50 meters
            temp.mStart.x = (roles[i].transform.position.x - rField.transform.position.x) / fMetersToPixels;
            // adjust for starting on 10.
            temp.mStart.y = (roles[i].transform.position.y - rField.transform.position.y) / fMetersToPixels + 15f;

            // oh lol, forgot to add detail.
            temp.mDetail = roles[i].mDetails;

            play.mPlayerRoles[i] = temp;
        }

        return(play);
    }
Ejemplo n.º 2
0
    public Vector2 FConvertWorldSpaceToYardsFromCenter(float fFieldW, PE_Field rField, Vector2 vWorldPos)
    {
        float   fMetersToPixels = fFieldW / rField.GetComponent <RectTransform>().rect.width;
        Vector2 vPos            = new Vector2();

        vPos.x = (vWorldPos.x - rField.transform.position.x) / fMetersToPixels;
        vPos.y = (vWorldPos.y - rField.transform.position.y) / fMetersToPixels;

        return(vPos);
    }
Ejemplo n.º 3
0
    // We also have to destroy the roles currently in the scene.
    public void FLoadPlay(DATA_Play play)
    {
        PE_Role[] roles = FindObjectsOfType <PE_Role>();
        for (int i = 0; i < roles.Length; i++)
        {
            Destroy(roles[i].gameObject);
        }

        Debug.Log("Play: " + play.mName);
        for (int i = 0; i < play.mPlayerRoles.Length; i++)
        {
            PE_Role role = Instantiate(PF_PlayerRole, transform.position, transform.rotation);
            role.mTag        = play.mPlayerRoles[i].mTag;
            role.mRole       = play.mPlayerRoles[i].mRole; // just a string now.
            role.mDetails    = play.mPlayerRoles[i].mDetail;
            role.mStartPos.x = play.mPlayerRoles[i].mStart.x;
            role.mStartPos.y = play.mPlayerRoles[i].mStart.y;

            // Here I'm making sure that the players always start on whole numbers, even if the play is not saved that way.
            role.mStartPos.x = (float)System.Math.Round((double)role.mStartPos.x, 0);
            role.mStartPos.y = (float)System.Math.Round((double)role.mStartPos.y, 0);

            // okay, now actually make it spawn in the right spot.
            // update. I guess we need to work in pixels.
            float   fMetersToPixels = 50f / rField.GetComponent <RectTransform>().rect.width;
            Vector3 vPos            = new Vector3();
            vPos.x = rField.transform.position.x + role.mStartPos.x * fMetersToPixels;
            vPos.y = rField.transform.position.y + role.mStartPos.y * fMetersToPixels;
            // set the y to the 10 yard line, normalized. That is where I decided the play starts from.
            vPos.y -= 15f * fMetersToPixels;
            role.transform.position = vPos;
        }

        // Since the old ones are garbage now.
        cSelector.FGetNewReferences();
    }