public void FShowOffensivePlay(DATA_OffPlay offPlay, PLY_SnapSpot snapSpot) { for (int i = 0; i < offPlay.mRoles.Length; i++) { // figure out where they start first. Vector2 vStart = new Vector2(); DATA_Formation f = IO_Formations.FLOAD_FORMATION(offPlay.mFormation); for (int j = 0; j < f.mSpots.Length; j++) { if (f.mTags[j] == offPlay.mTags[i]) { vStart = f.mSpots[j]; vStart.y *= -1f; } } if (offPlay.mRoles[i] == "BLOCK") { RenderPassBlock(vStart, snapSpot); } // We have to first get the route data. else if (offPlay.mRoles[i] == "ROUTE") { for (int j = 0; j < offPlay.mRoutes.Count; j++) { if (offPlay.mRoutes[j].mOwner == offPlay.mTags[i]) { // now we render the route piece by piece. RenderRoute(offPlay.mRoutes[j].mSpots, vStart, snapSpot); } } } } }
public void BT_PlaysUpdate() { string text = mDropPlays.captionText.text; Debug.Log("They want to see this play shown: " + text); DATA_OffPlay p = IO_OffensivePlays.FLoadPlay(text); p.mName = "NO NAME"; SetUpNewFormation(p.mFormation); SetPlayerRolesFromPlayData(p); mPlay = p; RenderJobs(); }
private void SetPlayerRolesFromPlayData(DATA_OffPlay play) { if (mAths.Count != play.mRoles.Length) { Debug.Log("ERROR. Number of players in scene does not match number of players in play"); Debug.Log(mAths.Count); Debug.Log(play.mRoles.Length); return; } for (int i = 0; i < mAths.Count; i++) { for (int j = 0; j < play.mRoles.Length; j++) { if (play.mTags[j] == mAths[i].mTag) { mAths[i].mRole = play.mRoles[j]; } } } return; }
void Start() { IO_Formations.FLoadAllFormations(); RefreshFormationDropdown(); RefreshPlaysDropdown(); mAths = new List <ED_OP_Ply>(); rRouteNodes = new List <ED_OP_GFX_RT_ND>(); mPlay = IO_OffensivePlays.FLoadPlay("Default"); mPlay.mName = "NO NAME"; mSnapSpot.x = rGrid.mAxLth / 2; mSnapSpot.y = rGrid.mAxLth - 5; LoadValidRoles(); ENTER_BEGIN(); // DATA_OffPlay oPlay = IO_OffensivePlays.FLoadPlay("Default"); // oPlay.mName = "TestWrite"; // oPlay.mFormation = "Default"; // IO_OffensivePlays.FWritePlay(oPlay); }
public void FSetUpPlayers(string sOffName, PLY_SnapSpot rSnapSpot) { DATA_OffPlay p = IO_OffensivePlays.FLoadPlay(sOffName); Debug.Log("About to run: " + p.mName); DATA_Formation f = IO_Formations.FLOAD_FORMATION(p.mFormation); Debug.Log("From this formation: " + f.mName); List <PRAC_Off_Ply> plys = new List <PRAC_Off_Ply>(); // --------------- Set up the players according to the formation. for (int i = 0; i < f.mTags.Length; i++) { Vector3 vSpot = new Vector3(); vSpot.x = f.mSpots[i].x; vSpot.z = f.mSpots[i].y * -1f; vSpot.y = 0f; vSpot += rSnapSpot.transform.position; var clone = Instantiate(PF_OffPlayer, vSpot, transform.rotation); clone.mTag = f.mTags[i]; plys.Add(clone); } // ---------------- Now give the players their roles. for (int i = 0; i < p.mTags.Length; i++) { for (int j = 0; j < plys.Count; j++) { if (plys[j].mTag == p.mTags[i]) { plys[j].mRole = p.mRoles[i]; } } } // --------------- Assign all the routes to the proper receivers. for (int i = 0; i < p.mRoutes.Count; i++) { for (int j = 0; j < plys.Count; j++) { if (plys[j].mTag == p.mRoutes[i].mOwner) { plys[j].mSpots = p.mRoutes[i].mSpots; for (int k = 0; k < plys[j].mSpots.Count; k++) { Vector2 v = plys[j].mSpots[k]; v.y *= -1f; plys[j].mSpots[k] = v; } } } } // --------------------------- Shove the player "into" the QB position. for (int i = 0; i < plys.Count; i++) { if (plys[i].mTag == "QB") { FindObjectOfType <PC_Controller>().transform.position = plys[i].transform.position; } } return; }
public static void FWritePlay(DATA_OffPlay p) { // ----------------------------------- First do some error checking to make sure the play is valid. if (p.mName == "NAME ME") { Debug.Log("ERROR. This play must be given a unique name"); return; } // Should also check against a list of valid tags. eg. RB1 valid, NO_TAG not valid. foreach (string s in p.mRoles) { if (s == "NO ROLE") { Debug.Log("ERROR. One or more players without a role"); return; } } foreach (string s in p.mTags) { if (s == "NO TAG") { Debug.Log("ERROR. One or more players without a tag"); return; } } if (p.mRoles.Length != p.mTags.Length) { Debug.Log("ERROR. Tag/Role length mismatches"); Debug.Log("Num tags: " + p.mTags.Length); Debug.Log("Num Roles: " + p.mRoles.Length); return; } foreach (DATA_ORoute r in p.mRoutes) { bool ownerValid = false; foreach (string s in p.mTags) { if (s == r.mOwner) { ownerValid = true; } } if (!ownerValid) { Debug.Log("ERROR. One or more routes does not have a valid owner."); Debug.Log("OWNER: " + r.mOwner); } } // ---------------------------------- Save to disc string sName = p.mName; StreamWriter sw = new StreamWriter(Application.dataPath + "/FILE_IO/OffensivePlays/" + sName + ".txt"); sw.WriteLine("NAME"); sw.WriteLine(p.mName); sw.WriteLine("FORMATION"); sw.WriteLine(p.mFormation); sw.WriteLine("NUM PLAYERS"); sw.WriteLine(p.mTags.Length); for (int i = 0; i < p.mTags.Length; i++) { sw.WriteLine(p.mTags[i]); sw.WriteLine(p.mRoles[i]); } sw.WriteLine("NUM RECEIVERS"); sw.WriteLine(p.mRoutes.Count); sw.WriteLine("ROUTES"); for (int i = 0; i < p.mRoutes.Count; i++) { sw.WriteLine(p.mRoutes[i].mOwner); sw.WriteLine("NUM SPOTS"); sw.WriteLine(p.mRoutes[i].mSpots.Count); for (int j = 0; j < p.mRoutes[i].mSpots.Count; j++) { sw.WriteLine(UT_Strings.FConvertVecToString(p.mRoutes[i].mSpots[j])); } } sw.Close(); }
public static DATA_OffPlay FLoadPlay(string name) { string path = Application.dataPath + "/FILE_IO/OffensivePlays/" + name + ".txt"; string[] sLines = System.IO.File.ReadAllLines(path); DATA_OffPlay p = new DATA_OffPlay(); for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NUM PLAYERS")) { int numPlayers = int.Parse(sLines[i + 1]); p.mTags = new string[numPlayers]; p.mRoles = new string[numPlayers]; } } for (int i = 0; i < sLines.Length; i++) { if (sLines[i].Contains("NAME")) { p.mName = sLines[i + 1]; } if (sLines[i].Contains("FORMATION")) { p.mFormation = sLines[i + 1]; } if (sLines[i].Contains("NUM PLAYERS")) { int ix = i + 2; for (int j = 0; j < p.mTags.Length; j++) { p.mTags[j] = sLines[ix++]; p.mRoles[j] = sLines[ix++]; } } if (sLines[i].Contains("NUM RECEIVERS")) { int num = int.Parse(sLines[i + 1]); int ix = i + 3; for (int j = 0; j < num; j++) { DATA_ORoute r = new DATA_ORoute(); r.mOwner = sLines[ix++]; ix++; // skip over NUM SPOTS line int numSpots = int.Parse(sLines[ix++]); r.mSpots = new List <Vector2>(); for (int k = 0; k < numSpots; k++) { Vector2 v = UT_Strings.FGetVecFromString(sLines[ix++]); r.mSpots.Add(v); } p.mRoutes.Add(r); } } } return(p); }