public static void LoadOneComputer(string computer_file) { GameObject computer; computer = GameObject.Find("Computer"); //Debug.Log("user_app_path" + user_app_path + " file [" + computer_file+"]"); string cdir = System.IO.Path.Combine(GameLoadBehavior.user_app_path, COMPUTERS); string cfile = System.IO.Path.Combine(cdir, computer_file); //Debug.Log("computer " + cdir); GameObject new_c = Instantiate(computer, new Vector3(1.0F, 0, 0), Quaternion.identity); ComputerBehavior script = (ComputerBehavior)new_c.GetComponent(typeof(ComputerBehavior)); script.SetFilePath(cfile); new_c.SetActive(true); script.LoadComponent(); script.LoadComputer(); int pos = script.position; //Debug.Log("LoadComputers " + script.computer_name + " pos is " + pos); if (pos < 0) { Debug.Log("LoadOneComputer got invalid pos for " + script.component_name); return; } WorkSpaceScript.WorkSpace ws = WorkSpaceScript.GetWorkSpace(pos); int slot = ws.AddComputer(script.component_name); 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, 0.5f, zf); new_c.transform.position = v; }
public static void LoadOneComputer(string computer_file) { GameObject computer; computer = GameObject.Find("Computer"); //Debug.Log("user_app_path" + user_app_path + " file [" + computer_file+"]"); string cdir = System.IO.Path.Combine(GameLoadBehavior.user_app_path, COMPUTERS); string cfile = System.IO.Path.Combine(cdir, computer_file); Debug.Log("computer " + cdir); GameObject new_c = Instantiate(computer, new Vector3(1.0F, 0, 0), Quaternion.identity); ComputerBehavior script = (ComputerBehavior)new_c.GetComponent(typeof(ComputerBehavior)); script.SetFilePath(cfile); new_c.SetActive(true); script.LoadComponent(); script.LoadComputerInfoFromFile(); script.hw = hw_name; //This is the part that will hopefully load the correct assets from dict SkinnedMeshRenderer this_render = new_c.GetComponent <SkinnedMeshRenderer>(); try { this_render.sharedMesh = CatalogBehavior.object_mesh_dict[script.hw]; } catch (KeyNotFoundException) { Debug.Log("Key Exception in object_mesh_dict caused by " + script.hw); } try { this_render.material = CatalogBehavior.object_mat_dict[script.hw]; } catch (KeyNotFoundException) { Debug.Log("Key Exception in object_mat_dict caused by " + script.hw); } int pos = script.position; //Debug.Log("LoadComputers " + script.computer_name + " pos is " + pos); if (pos < 0) { Debug.Log("LoadOneComputer got invalid pos for " + script.component_name); return; } WorkSpaceScript.WorkSpace ws = WorkSpaceScript.GetWorkSpace(pos); int slot = ws.AddComputer(script.component_name); 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, 0.5f, zf); new_c.transform.position = v; }