/// <summary> /// 打开文件选择弹窗 /// </summary> public static string OpenFileDialog() { //OpenFileDialog ofd = new OpenFileDialog(); //new一个方法 //ofd.InitialDirectory = "file://" + UnityEngine.Application.dataPath; //定义打开的默认文件夹位置//定义打开的默认文件夹位置 //ofd.Filter = "(*.jpg,*.png,*.jpeg,*.bmp)|*.jpg;*.png;*.jpeg;*.bmp"; //if (ofd.ShowDialog() == DialogResult.OK) //{ // return ofd.FileName; //} //else //{ // return ""; //} OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); //三菱(*.gxw)\0*.gxw\0西门子(*.mwp)\0*.mwp\0All Files\0*.*\0\0 ofn.filter = "*.jpg\0*.png\0*.jpeg\0*.bmp\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; //默认路径 ofn.title = "Open Project"; ofn.defExt = "JPG"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { return(ofn.file); } return(""); }
string Ruta() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Archivos de imagen\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; //默认路径 ofn.title = "Cargar imagen"; ofn.defExt = "JPG"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { //Debug.Log ("Selected file with full path: {0}" + ofn.file); return(ofn.file); } else { return(""); } }
void OnGUI() { if (GUI.Button(new Rect(0, 0, 100, 35), "OpenDialog")) { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath;//默认路径 ofn.title = "Open Project"; ofn.defExt = "JPG"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { StartCoroutine(WaitLoad(ofn.file));//加载图片到panle Debug.Log("Selected file with full path: {0}" + ofn.file); } } }
public static void GetFile() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "JPG Files\0*.jpg\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath;// ofn.title = StringTable.GetString("Open_Photo_Tittle"); ofn.defExt = "JPG";// //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetOpenFileName(ofn)) { string path = ofn.file; path = path.Replace('\\', '/'); HeaderManager.Instance.UploadHeader(path); } }
/// <summary> /// 打开选择文件的窗口 /// </summary> /// <returns></returns> static public string OpenFileDisplay() { string path = ""; OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath;//默认路径 ofn.title = "Open Project"; ofn.defExt = "JPG"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { path = ofn.file; } return(path); }
public static void OpenFileDialog() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); //三菱(*.gxw)\0*.gxw\0西门子(*.mwp)\0*.mwp\0All Files\0*.*\0\0 ofn.filter = "模型(*.fbx)\0*.fbx\0模型(*.obg)\0*.obg\0All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = "桌面";//默认路径 ofn.title = "选择模型所在的文件地址"; //ofn.defExt = "FBX";//显示文件的类型、 //ofn.defExt = "fbx files (*.fbx)|*.fbx|obj files (*.obj)|*.obj"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { //字符串小写,好简便判断选取的类型 string filePath = ofn.file.ToLower(); FileInfo fi = new FileInfo(filePath); if (fi.Extension == ".fbx" || fi.Extension == ".obj") { GameObject go = LoadModelFormLocal.LoadModel(filePath); if (null != go) { //进行 } } Debug.Log("Selected file with full path: {0}" + ofn.file); } }
public static string[] OpenFile(string sTitile, string sPath, string ext) { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = ext; //"All Files\0*.*\0All Files\0*.jpg\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = sPath; ofn.title = sTitile; //ofn.defExt = sdefaultext; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 /*| 0x00000200*/ | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { return(new string[] { ofn.file }); } return(new string[0]); }
/// <summary> /// 탐색기를 열어서 파일 가져옴. /// </summary> public void LoadAudioClip() { if (EditorManager.editorMgr.audioSource.isPlaying) { EditorManager.editorMgr.audioSource.Stop(); } OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "OGG Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Open Music"; ofn.defExt = "ogg"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetOpenFileName(ofn)) { fileUrl = ofn.file; if (ButtonManager.b_LoadBGM) { Data.fileURL = fileUrl; } else if (ButtonManager.b_LoadESD) { effectSoundMgr.fileURL = fileUrl; } StartCoroutine(WaitLoadBGM(fileUrl)); } if (ofn.file == "") { return; } }
private void SystemFileRequester() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Select Texture Image"; ofn.defExt = "PNG"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { StartCoroutine(WaitToLoad(ofn.file)); OutputWindow_Log(MESSAGE_TEXT[MESSAGES.SELECTED_FILE], ofn.file); } }
//打开导入的钱包文件 void onCLick_wallet_open2() { #if UNITY_ANDROID Debug.Log("这里是安卓设备^_^"); #endif #if UNITY_IPHONE Debug.Log("这里是苹果设备>_<"); #endif #if UNITY_STANDALONE_WIN OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; //默认路径 ofn.title = "Open Project"; ofn.defExt = "json"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { if (ofn.fileTitle.Substring(ofn.fileTitle.Length - 5) != ".json") { showNotice("导入文件错误"); showOpenWallet(""); } else { showOpenWallet(ofn.fileTitle); sdk_http._instance.wallet_load(ofn.file); Debug.Log("Selected file with full path: {0}" + ofn.file); } } #endif }
public void OpenFileDialog() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "\0.txt\0TypingTitan\\Typing Titan\\Assets\\Sample Files"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Please choose a file!"; ofn.defExt = "txt"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { Debug.Log("This shows the dialog box finish"); if (ofn.file.Length != 0) { var fileContent = File.ReadAllBytes(ofn.file); } string lineRead = ""; codeOutput.text = ""; StreamReader reader = new StreamReader(ofn.file); while (!reader.EndOfStream) { lineRead = reader.ReadLine(); Debug.Log(lineRead); codeOutput.text += lineRead.Trim() + "\n"; } reader.Close(); } else { SceneManager.LoadScene("Error Screen"); } }
void TestOpenFileWindow() { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "图片文件(*.jpg*.png*)\0*.jpg;*.png"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; //默认路径 ofn.title = "请选择图片!"; ofn.defExt = "jpg"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { path = ofn.file; Tips.text = path; MessageBox.Show(path, "Tips"); } }
public void LoadTxt() { if (EditorManager.editorMgr.audioSource.isPlaying) { EditorManager.editorMgr.audioSource.Stop(); } OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "OGG Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Open Data"; ofn.defExt = "xml"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetOpenFileName(ofn)) { fileUrl = ofn.file; StartCoroutine(xmlTool.LoadXml(fileUrl)); //StartCoroutine(WaitLoadTXT(fileUrl)); } if (ofn.file == "") { if (EditorManager.editorMgr.audioSource.clip != null) { EditorManager.editorMgr.audioSource.Play(); } return; } }
// Update is called once per frame void Update() { //Debug.Log("goiing" + going.ToString()); if (Input.GetButton("Openfile")) { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Open Project"; ofn.defExt = "JPG"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetOpenFileName(ofn)) { Debug.Log("Selected file with full path: {0}" + ofn.file); } if (ofn.file.Length > 1) { pipe.run(ofn.file); } } float h = Input.GetAxisRaw("Clockspeed"); if (h != 0f) { ClockTime += h / 10; LineTime = ClockTime / 5; } if (Input.GetButton("Pause")) { going = false; currentTimer = 0; } if (Input.GetButton("Go")) { going = true; currentTimer = 0; } if (Input.GetButton("Reload")) { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } if (going) { currentTimer += Time.deltaTime; } coolTimer += Time.deltaTime; if (currentTimer >= ClockTime || (coolTimer > ClockTime && Input.GetButton("Step"))) { Debug.Log("call delay"); if (clock_cnt > pipe.cycle_cnt) { return; } clock_cnt++; currentTimer = 0; manal.triggerLines(); delayer.delayUpdate(clock_cnt); } }
public void OnGUI() { if (onProcessing) { return; } GUI.depth = 10; GUI.enabled = false; objPath = GUI.TextField(new Rect(10, 10, 300, 20), objPath); GUI.enabled = true; if (GUI.Button(new Rect(310, 10, 20, 20), "...")) { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Object Files (*.obj)\0*.obj\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Select Object"; ofn.defExt = "OBJ"; //显示文件的类型 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR // ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest.GetOpenFileName(ofn)) { // StartCoroutine(WaitLoad(ofn.file));//加载图片到panle objPath = ofn.file; Debug.Log("Selected file with full path: " + ofn.file); } /* * if(openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){ * objPath = openFileDialog.FileName; * }else{ * objPath=""; * } */ //objPath = EditorUtility.OpenFilePanel("Please select an object file","","obj"); Debug.Log(objPath); } if (GUI.Button(new Rect(10, 40, 100, 20), "import")) { hasLegoized = false; if (objPath == "") { MessageBox.Show("You Must Select an Object first!", "Select Object"); /*EditorUtility.DisplayDialog( * "Select Object", * "You Must Select an Object first!", * "Ok");*/ return; } else { isObjectLoaded = false; Destroy(GetComponent("MeshFilter")); Destroy(GetComponent("MeshRenderer")); Destroy(GetComponent("MeshCollider")); GameObject voxelContainer = GameObject.Find("Voxelized"); GameObject legoContainer = GameObject.Find("Legoizer"); StartCoroutine(removeVoxels(voxelContainer)); StartCoroutine(removeVoxels(legoContainer)); buffer = new GeometryBuffer(); mtllib = ""; StartCoroutine(Load("file:///" + objPath)); } } GUI.enabled = isObjectLoaded; GUI.Label(new Rect(10, 70, 220, 20), "Sample Resolution (1000-8000000): "); samplingResolutionStr = GUI.TextField(new Rect(230, 70, 100, 20), samplingResolutionStr, 25); samplingResolutionStr = Regex.Replace(samplingResolutionStr, "[^0-9]", ""); sampleResoultion = int.Parse(samplingResolutionStr); colorMode = GUI.SelectionGrid(new Rect(10, 100, 220, 20), colorMode, colorModes, colorModes.Length, GUI.skin.toggle); if (GUI.Button(new Rect(10, 130, 100, 20), "Legoize")) { hasLegoized = false; if (sampleResoultion < 1001 || sampleResoultion > 8000000) { MessageBox.Show("The sample resolution must be in between 1000 to 8000000", "Out of Range"); /*EditorUtility.DisplayDialog( * "Out of Range", * "The sample resolution must be in between 1000 to 8000000", * "Ok");*/ return; } GameObject voxelContainer = GameObject.Find("Voxelized"); GameObject legoContainer = GameObject.Find("Legoizer"); while (voxelContainer.transform.childCount > 0) { GameObject.DestroyImmediate(voxelContainer.transform.GetChild(0).gameObject); } while (legoContainer.transform.childCount > 0) { GameObject.DestroyImmediate(legoContainer.transform.GetChild(0).gameObject); } Resources.UnloadUnusedAssets(); System.GC.Collect(); Voxelizer voxelizer = GameObject.Find("Voxelized").GetComponent <Voxelizer> (); StartCoroutine(voxelizer.voxelize()); } GUI.enabled = true; if (hasLegoized) { if (GUI.Button(new Rect(10, 160, 100, 20), "Save")) { LxfmlWriter xmlWriter = GameObject.Find("FileWriter").GetComponent <LxfmlWriter> (); StartCoroutine(xmlWriter.writeXML(legos)); } } }
}// _SaveActionPlan void _LoadActionPlan(Dictionary <string, List <ActionPlanController.Action> > myDict) { // // Open Dialog // OpenFileDialog open = new OpenFileDialog(); // open.Filter = "ActionPlanFile(*.xml)|*.xml"; // open.InitialDirectory = Directory.GetCurrentDirectory(); // open.Title = "Open Action Plan"; // if (open.ShowDialog() != DialogResult.OK) // return; OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.xml\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath + "/ActionPlan/"; ofn.title = "Open Action Plan File"; ofn.defExt = "xml"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR if (!DllTest.GetOpenFileName(ofn)) { Debug.LogError("File Opening Dialog Failed"); return; } FileStream fs = new FileStream(ofn.file, FileMode.Open); //FileStream fs = new FileStream(m_fileName, FileMode.Open); //BinaryReader br = new BinaryReader(fs); XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary <string, List <ActionPlanController.Action> >)); // StreamReader: TextReader // public object Deserialize(XmlReader xmlReader, XmlDeserializationEvents events); //public object Deserialize(Stream stream); //public object Deserialize(TextReader textReader); TextReader textReader = new StreamReader(fs); SerializableDictionary <string, List <ActionPlanController.Action> > serializableDict = (SerializableDictionary <string, List <ActionPlanController.Action> >) serializer.Deserialize(textReader); textReader.Close(); // public class Action //{ // public List<float> T; // public float V; //} // copy serializable dictionary to dictionary foreach (var kvp in serializableDict) { Debug.Log(" serializableDict:" + kvp.Key + ":"); // kvp.Value is a List foreach (var value in kvp.Value) { Debug.Log("[" + value.T[0] + "," + value.T[1] + "]:" + value.V); } } // copy serializable dictionary to dictionary foreach (var kvp in serializableDict) { myDict[kvp.Key] = kvp.Value; } // debug // copy serializable dictionary to dictionary foreach (var kvp in myDict) { Debug.Log("myDict:" + kvp.Key + ":"); foreach (var value in kvp.Value) // kvp.Value is a List { Debug.Log("[" + value.T[0] + "," + value.T[1] + "]:" + value.V); } } //OpenFileName ofn = new OpenFileName(); //ofn.structSize = Marshal.SizeOf(ofn); //ofn.filter = "All Files\0*.xml\0\0"; //ofn.file = new string(new char[256]); //ofn.maxFile = ofn.file.Length; //ofn.fileTitle = new string(new char[64]); //ofn.maxFileTitle = ofn.fileTitle.Length; //ofn.initialDir = UnityEngine.Application.dataPath; //ofn.title = "Open Action Plan File"; ////ofn.defExt = "JPG"; //ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR //if (DllTest.GetOpenFileName(ofn)) //{ // // FileStream(string path, FileMode mode, FileAccess access); // FileStream fileStream = new FileStream(ofn.file, FileMode.Open, FileAccess.Read); // //https://m.blog.naver.com/PostView.nhn?blogId=y2kgr&logNo=80208479466&categoryNo=13&proxyReferer=&proxyReferer=https%3A%2F%2Fwww.google.com%2F // // //FileStream fs = new FileStream(openDialog.FileName, FileMode.Open); // // //reader = new StreamReader( fs, mode) // // // https://docs.microsoft.com/ko-kr/dotnet/framework/winforms/controls/how-to-open-files-using-the-openfiledialog-component // // // using (var reader = new StreamReader( openDialog.FileName) ) // // //https://stackoverflow.com/questions/37094671/save-a-dictionary-to-a-binary-file // // var binaryFormatter = new BinaryFormatter(); // // var fi = new System.IO.FileInfo(ofn.file); // //// Dictionary<int, string> readBack; // // using (var binaryFile = fi.OpenRead()) // // { // // myDict = (Dictionary<string, List<ActionPlanController.Action>>) // // binaryFormatter.Deserialize(binaryFile); // // } // // b is this // // SerializableDictionary<string, List<ActionPlanController.Action>> // // b = new SerializableDictionary<string, // // List<ActionPlanController.Action>>(); // //b = (SerializableDictionary<string, List<ActionPlanController.Action>>)myDict; // //List<string> stringList = new List<string>(); // // stringList.Add("1"); // // b.Add("One", stringList); // XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string, // List<ActionPlanController.Action>>)); // TextReader textReader = new StreamReader(fileStream); // SerializableDictionary<string, List<ActionPlanController.Action>> b // = (SerializableDictionary<string, List<ActionPlanController.Action>>) // serializer.Deserialize(textReader); // textReader.Close(); // // copy serializable dictionary to dictionary // foreach (var kvp in b) // { // myDict.Add(kvp.Key, kvp.Value); // } //// debug // foreach (var kvp in myDict) // Debug.Log(kvp.Key + ":" + kvp.Value); //}//if } // _LoadActionPlan()
private void AssetFlip() { var origCursor = UnityEngine.Cursor.visible; try { var test = (SingleBuilderBoardTool)SingletonBehaviour <SingleBuilderBoardTool> .Instance; } catch { // pass } try { UnityEngine.Cursor.visible = true; OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Obj Files\0*.obj\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath; ofn.title = "Select OBJ File"; ofn.defExt = "OBJ"; ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllTest.GetOpenFileName(ofn)) { var catPath = ofn.file; // We have to first grab the CameraController._targetZoomLerpValue to disable the movement when our rotate is happening. This is the only way to prevent zooming while we are rotating var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static; if (SingletonBehaviour <BoardToolManager> .HasInstance && (SingletonBehaviour <BoardToolManager> .Instance.IsCurrentTool <SingleBuilderBoardTool>())) { var btm = (SingleBuilderBoardTool)SingletonBehaviour <SingleBuilderBoardTool> .Instance; TilePreviewBoardAsset selectedAsset = (TilePreviewBoardAsset)btm.GetType().GetField("_selectedTileBoardAsset", flags).GetValue(btm); UnityEngine.Debug.Log("Selected Asset: " + selectedAsset); AssetLoader[] assetLoaders = (AssetLoader[])selectedAsset.GetType().GetField("_assetLoaders", flags).GetValue(selectedAsset); UnityEngine.Debug.Log("Asset Loaders: " + assetLoaders); Mesh newMesh = FastObjImporter.Instance.ImportFile(catPath); for (int i = 0; i < assetLoaders.Length; i++) { UnityEngine.Debug.Log("Asset Loader: " + assetLoaders[i].Guid + " : " + assetLoaders[i].assetName + " : " + assetLoaders[i].assetBundlePath); //var w = new WWW("file://Users/Paulo/Desktop/img_2013_008_original.jpg"); UnityEngine.Debug.Log("New Mesh: " + newMesh.name + " : " + newMesh.vertices.Length); //Mesh holderMesh = new Mesh(); //ObjImporter objImport = new ObjImporter(); //holderMesh = objImport.ImportFile("E:\\Projects\\Talespirehax\\TestImport\\12222_Cat_v1_l3.obj"); //Material mat = new Material(Shader.Find("Standard")); GameObject loadedAsset = (GameObject)assetLoaders[i].GetType().GetField("_loadedAsset", flags).GetValue(assetLoaders[i]); //var newMesh = (new OBJLoader().Load(catPath)).GetComponent<MeshFilter>().mesh; UnityEngine.Debug.Log("New Mesh: " + newMesh.name + " : " + newMesh.vertices.Length); loadedAsset.GetComponent <MeshFilter>().mesh = newMesh; } var catMtl = Path.ChangeExtension(ofn.file, ".mtl"); // This is silly, it replaces every single mesh with the new mesh. //MeshFilter[] mfs = FindObjectsOfType<MeshFilter>(); //for (int i = 0; i < mfs.Length; i++) //{ // try // { // mfs[i].mesh = newMesh; // } // catch // { // // // } //} for (int i = 0; i < selectedAsset.Renderers.Length; i++) { try { UnityEngine.Debug.Log("Renderer Name: " + selectedAsset.Renderers[i].name); //Color[] colors = selectedAsset.Renderers[i].material //Dictionary<string, Material> materials = new MTLLoader().Load(catMtl, selectedAsset.Renderers[i].material); //foreach (string key in materials.Keys) //{ // UnityEngine.Debug.Log("Mat: " + key); //} //selectedAsset.Renderers[i].material = materials.GetEnumerator().Current.Value; var catTexturePath = "E:/Projects/Talespirehax/TestImport/Cat_diffuse.jpg"; //selectedAsset.Renderers[i].material.doubleSidedGI = true; //Texture2D catTexture = new MTLLoader().TryLoadTexture(catTexturePath); //Texture2D tex = new Texture2D(16, 16, TextureFormat.PVRTC_RGBA4, false); //byte[] pvrtcBytes = new byte[] //{ // 0x30, 0x32, 0x32, 0x32, 0xe7, 0x30, 0xaa, 0x7f, 0x32, 0x32, 0x32, 0x32, 0xf9, 0x40, 0xbc, 0x7f, // 0x03, 0x03, 0x03, 0x03, 0xf6, 0x30, 0x02, 0x05, 0x03, 0x03, 0x03, 0x03, 0xf4, 0x30, 0x03, 0x06, // 0x32, 0x32, 0x32, 0x32, 0xf7, 0x40, 0xaa, 0x7f, 0x32, 0xf2, 0x02, 0xa8, 0xe7, 0x30, 0xff, 0xff, // 0x03, 0x03, 0x03, 0xff, 0xe6, 0x40, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xaa, 0xe9, 0x40, 0x9f, 0xff, // 0x5b, 0x03, 0x03, 0x03, 0xca, 0x6a, 0x0f, 0x30, 0x03, 0x03, 0x03, 0xff, 0xca, 0x68, 0x0f, 0x30, // 0xaa, 0x94, 0x90, 0x40, 0xba, 0x5b, 0xaf, 0x68, 0x40, 0x00, 0x00, 0xff, 0xca, 0x58, 0x0f, 0x20, // 0x00, 0x00, 0x00, 0xff, 0xe6, 0x40, 0x01, 0x2c, 0x00, 0xff, 0x00, 0xaa, 0xdb, 0x41, 0xff, 0xff, // 0x00, 0x00, 0x00, 0xff, 0xe8, 0x40, 0x01, 0x1c, 0x00, 0xff, 0x00, 0xaa, 0xbb, 0x40, 0xff, 0xff, //}; //// Load data into the texture and upload it to the GPU. //tex.LoadRawTextureData(pvrtcBytes); //tex.Apply(); UnityEngine.Debug.Log("Shader: " + selectedAsset.Renderers[i].material.shader.name); Material newMat = new Material(Shader.Find("Standard")); newMat.CopyPropertiesFromMaterial(selectedAsset.Renderers[i].material); selectedAsset.Renderers[i].material = newMat; Texture2D catTexture = LoadPNG(catTexturePath); selectedAsset.Renderers[i].material.mainTexture = catTexture; var catBumpTexturePath = "E:/Projects/Talespirehax/TestImport/Cat_bump.jpg"; Texture2D catBumpTexture = LoadPNG(catBumpTexturePath); //Texture2D catBumpTexture = new MTLLoader().TryLoadTexture(catBumpTexturePath); selectedAsset.Renderers[i].material.SetTexture("_BumpMap", catBumpTexture); //Color cl = selectedAsset.Renderers[i].material.color; //float scale = selectedAsset.Renderers[i].material.shader = //UnityEngine.Debug.Log("Bump Scale: " + scale); //selectedAsset.Renderers[i].material.SetFloat("_BumpScale", 0f); //selectedAsset.Renderers[i].material.SetColor("_BumpMap", new Color(cl.r, cl.g, cl.b, 0.5f));// .a = 0; } catch { // } // After adjusting don't forget to push it back to TaleSpire so they can keep track of it. // btm.GetType().GetField("_angle", flags).SetValue(btm, angle); } } } } catch (System.Exception ex) { UnityEngine.Debug.Log("Crash in Asset Preview Plugin"); UnityEngine.Debug.Log(ex.Message); UnityEngine.Debug.Log(ex.StackTrace); UnityEngine.Debug.Log(ex.InnerException); UnityEngine.Debug.Log(ex.Source); } UnityEngine.Cursor.visible = origCursor; }