public static void LoadOneStaff(string user_file) { GameObject user = GameObject.Find("ITStaff"); if (user == null) { Debug.Log("Error: LoadOneStaff got null when finding ITStaff game object."); return; } //Debug.Log("user_app_path" + user_app_path + " file [" + User_file+"]"); string cfile = System.IO.Path.Combine(GameLoadBehavior.user_app_path, user_file); Debug.Log("user " + cfile); GameObject new_c = Instantiate(user, new Vector3(1.0F, 0, 0), Quaternion.identity); ITStaffBehavior script = (ITStaffBehavior)new_c.GetComponent(typeof(ITStaffBehavior)); script.SetFilePath(cfile); new_c.SetActive(true); script.LoadStaff(); int pos = script.position; //Debug.Log("LoadUsers " + script.User_name + " pos is " + pos); if (pos < 0) { Debug.Log("LoadOneStaff got invalid pos for " + script.user_name); return; } if (pos >= 0) { WorkSpaceScript.WorkSpace ws = WorkSpaceScript.GetWorkSpace(pos); if (ws == null) { Debug.Log("ITStaffBehavior got null workspace for pos" + pos); return; } if (!ws.AddUser(script.user_name)) { Debug.Log("ITStaffBehavior AddUser, could not user, already populated " + script.user_name); return; } float xf, zf; ccUtils.GridTo3dPos(ws.x, ws.y, out xf, out zf); //Debug.Log(ws.x + " " + ws.y + " " + xf + " " + zf); Vector3 v = new Vector3(xf - 1.0f, 0.5f, zf); new_c.transform.position = v; } else { Debug.Log("no postion for " + script.user_name); } }
/*public static void LoadOneUser(string user_file) * { * GameObject user = GameObject.Find("User"); * //Debug.Log("user_app_path" + user_app_path + " file [" + User_file+"]"); * string cfile = System.IO.Path.Combine(GameLoadBehavior.user_app_path, user_file); * //Debug.Log("user " + cdir); * GameObject new_c = Instantiate(user, new Vector3(1.0F, 0, 0), Quaternion.identity); * UserBehavior script = (UserBehavior)new_c.GetComponent(typeof(UserBehavior)); * script.SetFilePath(cfile); * new_c.SetActive(true); * script.LoadUser(); * int pos = script.position; * //Debug.Log("LoadUsers " + script.user_name + " pos is " + pos); * if (pos < 0) * { * Debug.Log("LoadOneUser got invalid pos for " + script.user_name); * return; * } * if (pos >= 0) * { * WorkSpaceScript.WorkSpace ws = WorkSpaceScript.GetWorkSpace(pos); * if (ws == null) * { * Debug.Log("UserBehavior got null workspace for pos" + pos); * return; * } * if (!ws.AddUser(script.user_name)) * { * Debug.Log("UserBehavior AddUser, could not user, already populated " + script.user_name); * return; * } * float xf, zf; * ccUtils.GridTo3dPos(ws.x, ws.y, out xf, out zf); * //Debug.Log(ws.x + " " + ws.y + " " + xf + " " + zf); * Vector3 v = new Vector3(xf - 1.0f, 0.5f, zf); * new_c.transform.position = v; * } * else * { * Debug.Log("no postion for " + script.user_name); * } * }*/ public static void LoadOneUser(string user_file) { string cfile = System.IO.Path.Combine(GameLoadBehavior.user_app_path, user_file); Dictionary <String, String> this_user_info = new Dictionary <string, string>(); GameObject user; this_user_info = LoadUser(cfile, this_user_info); Debug.Log("LoadOneUser " + user_file); string this_user_gender = this_user_info["Gender"]; string this_user_dept = this_user_info["Dept"]; if (this_user_dept == "Tech") { user = GameObject.Find("itstaff-obj"); } else if (this_user_gender == "female") { user = GameObject.Find("femworker-obj"); } else { user = GameObject.Find("maleworker-obj"); } GameObject new_c = Instantiate(user, new Vector3(1.0F, 0, 0), Quaternion.identity); // UserBehavior script = new_c.GetComponent<UserBehavior>(); UserBehavior script = (UserBehavior)new_c.GetComponent(typeof(UserBehavior)); if (script == null) { Debug.Log("Error: LoadUser failed to get script for " + user_file); return; } script.SetFilePath(cfile); new_c.SetActive(true); //Now we can load the stuff that used to be done in LoadUser script.user_name = this_user_info["Name"]; user_dict.Add(this_user_info["Name"], script); script.department = this_user_info["Dept"]; if (!int.TryParse(this_user_info["PosIndex"], out script.position)) { Debug.Log("Error: LoadUser parsing position" + this_user_info["PosIndex"]); } if (!int.TryParse(this_user_info["InitialTraining"], out script.training)) { Debug.Log("Error: LoadUser parsing training" + this_user_info["InitialTraining"]); } int pos = script.position; //Debug.Log("LoadUsers " + script.user_name + " pos is " + pos); if (pos < 0) { Debug.Log("LoadOneUser got invalid pos for " + script.user_name); return; } if (pos >= 0) { WorkSpaceScript.WorkSpace ws = WorkSpaceScript.GetWorkSpace(pos); if (ws == null) { Debug.Log("UserBehavior got null workspace for pos" + pos); return; } if (!ws.AddUser(script.user_name)) { Debug.Log("UserBehavior AddUser, could not user, already populated " + script.user_name); return; } float xf, zf; ccUtils.GridTo3dPos(ws.x, ws.y, out xf, out zf); //Debug.Log(ws.x + " " + ws.y + " " + xf + " " + zf); Vector3 v = new Vector3(xf - 1.0f, 0.5f, zf); new_c.transform.position = v; } else { Debug.Log("no postion for " + script.user_name); } }