Example #1
0
 public static void OutputGuildTimeLine(GuildTimelineData timelineData, string defaultName)
 {
     try
     {
         OpenFileName openFileName = new OpenFileName();
         openFileName.structSize   = Marshal.SizeOf(openFileName);
         openFileName.filter       = "Lua scripts(*.lua)\0*.lua\0";
         openFileName.file         = new string(new char[256]);
         openFileName.maxFile      = openFileName.file.Length;
         openFileName.fileTitle    = new string(new char[64]);
         openFileName.maxFileTitle = openFileName.fileTitle.Length;
         openFileName.initialDir   = Application.dataPath;
         openFileName.title        = "选择保存Lua脚本路径";
         openFileName.defExt       = "lua";
         openFileName.file         = defaultName;
         openFileName.flags        = 530952;
         var flag = DllTest.GetSaveFileName(openFileName);
         var text = openFileName.file.Replace("\\", "/");
         if (flag)
         {
             SaveTimeline(timelineData, text);
         }
     }
     catch (Exception e)
     {
         MainManager.Instance.WindowConfigMessage(e.ToString(), null);
     }
 }
Example #2
0
    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("");
        }
    }
    /// <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);
    }
Example #4
0
        static void Main(string[] args)
        {
            DllTest test = new DllTest();

            Console.WriteLine("Sum : " + test.Add(10, 20));
            Console.ReadLine();
        }
Example #5
0
    /// <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("");
    }
Example #6
0
    void GlobalInit()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
#if UNITY_STANDALONE_WIN
        DllTest.GetProcessWnd();
#endif
        try
        {
            //全局的初始化
            LogMgr.GlobalInit();
            Utility.GlobalInit();
            RuntimeInfo.GlobalInit();
            SDKMgr.Instance.GlobalPreInit();

            Resolution.GlobalInit();
            StringTable.GlobalInit();
            SceneObjMgr.Instance.GlobalInit();
            ResManager.Instance.GlobalInit();   //Res需要在SDKMgr的前面。
            //ReportException.Instance.GlobalInit();
            SDKMgr.Instance.GlobalInit();
            ServerSetting.GlobalInit();

            GlobalUpdate.GlobalInit();
            NetCmdMapping.GlobalInit();
            LogicManager.Instance.GlobalInit();
            UICamera.onPress = OnPress;
            Utility.GlobalInit();
        }
        catch (System.Exception e)
        {
            ReportException.Instance.AddException(e.ToString());
        }
    }
Example #7
0
    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);
            }
        }
    }
Example #8
0
    public void Save()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.structSize = Marshal.SizeOf(ofn);
        ofn.filter     = ".xml\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      = "Save Data";
        ofn.defExt     = "xml";
        ofn.flags      = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;

        if (DllTest.GetSaveFileName(ofn))
        {
            fileName = ofn.file;
            SortNotes();
            xmlTools.WriteXml(fileName);
        }

        if (ofn.file == "")
        {
            return;
        }
    }
    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);
        }
    }
Example #10
0
        private void btn2_Click_1(object sender, RoutedEventArgs e)
        {
            string strText1 = textBox5.Text.Trim();
            string strText2 = textBox6.Text.Trim();
            int    ret      = DllTest.testMulti(int.Parse(strText1), int.Parse(strText2));

            textBox7.Text = String.Concat(ret);
        }
Example #11
0
        private void btn1_Click_1(object sender, RoutedEventArgs e)
        {
            string strText1 = textBox1.Text.Trim();
            string strText2 = textBox2.Text.Trim();
            int    ret      = DllTest.testAdd(int.Parse(strText1), int.Parse(strText2));

            textBox3.Text = String.Concat(ret);
        }
Example #12
0
        private void btn2_Click_1(object sender, RoutedEventArgs e)
        {
            string strText1 = textBox5.Text.Trim();
            string strText2 = textBox6.Text.Trim();
            // 非托管动态链接库DLL的调用过程:
            // <3> 在程序中调用重新声明的函数
            int ret = DllTest.testMulti(int.Parse(strText1), int.Parse(strText2));

            textBox7.Text = String.Concat(ret);
        }
    public static void OpenPhoto()
    {
#if UNITY_ANDROID
        SDKMgr.Instance.AndroidObj.CallStatic("_OpenPhoto", Application.persistentDataPath + "/images");
#elif UNITY_IOS
        _OpenPhoto();
#else
        DllTest.GetFile();
#endif
    }
        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);
            }
        }
Example #15
0
    void Update()
    {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
        DllTest.CheckExecuteResult();
#endif
#if !UNITY_EDITOR
        try
        {
#endif
        CehckEscape();
        long tick          = System.DateTime.Now.Ticks;
        System.TimeSpan ts = new System.TimeSpan(tick - m_LastTick);
        m_LastTick = tick;
        uint curTick = Utility.GetTickCount();
        m_Delta = Utility.TickToFloat(curTick - m_FrameTick);
        if ((ts.TotalSeconds > 5 || m_Delta >= 5.0f) && LogicManager.Instance.IsPlaying)
        {
            //LogMgr.Log("Refresh,delta:" + m_Delta + ",tick:" + ts.TotalSeconds+",Socket:" + NetServices.Instance.IsSocketConnected);
            SceneRuntime.RefreshScene();
        }
        m_FrameTick = curTick;

        if (BlockLogic.Instance.Update(m_Delta))
        {
            //如果当前没有阻塞
            LogicManager.Instance.Update(m_Delta);
        }

        if (ServerSetting.IS_TEST)
        {
            WndManager.Instance.Check();
            ComputeFPS(m_Delta);
        }
#if !UNITY_EDITOR
    }

    catch (System.Exception e)
    {
        //异常提交
        ReportException.Instance.AddException(e.ToString());
    }
#endif
    }
Example #16
0
    void OnApplicationFocus()
    {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
        DllTest.SetExecuteFocus();
#endif
        if (m_bPause && m_bFocus)
        {
            m_bFocus = false;   //失去
        }
        else if (m_bPause)
        {
            m_bFocus = true;    //获得
        }
        else
        {
            return;
        }
        CheckFocusState();
    }
    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]);
    }
Example #18
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;
        }
    }
Example #19
0
    public void Open()
    {
        OpenFileName ofn = new OpenFileName();

        ofn.dlgOwner     = DllTest.GetActiveWindow(); // makes the window modal, but also causes flicker, solved by two WaitForEndOfFrame in coroutine
        ofn.structSize   = Marshal.SizeOf(ofn);
        ofn.filter       = "PNG Files\0*.png\0All Files\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   = Environment.CurrentDirectory;

        ofn.title  = "Open Project";
        ofn.defExt = "PNG";
        ofn.flags  = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR

        if (DllTest.GetSaveFileName(ofn))
        {
            StartCoroutine(TakeScreenShot(ofn));
        }
    }
Example #20
0
    //打开导入的钱包文件
    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
    }
Example #21
0
        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);
            }
        }
Example #22
0
    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");
        }
    }
Example #23
0
    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");
        }
    }
Example #24
0
    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;
        }
    }
Example #25
0
        public IEnumerator writeXML(List <Lego> voxels)
        {
            GameObject target = GameObject.Find("Target");
            OBJ        obj    = target.GetComponent <OBJ> ();

            string sSavePath = "result.lxfml";

            OpenFileName ofn = new OpenFileName();

            ofn.structSize = Marshal.SizeOf(ofn);

            ofn.filter = "LXFML-Files (*.lxfml)\0*.lxfml\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 = "Save Model";

            ofn.defExt = "LXFML";                                                       //显示文件的类型

            ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
            // ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;

            if (DllTest.GetSaveFileName(ofn))
            {
                // StartCoroutine(WaitLoad(ofn.file));//加载图片到panle
                sSavePath = ofn.file;
                Debug.Log("Selected file with full path: {0}" + ofn.file);
            }

            /*
             * SaveFileDialog saveFileDialog = new SaveFileDialog();
             * saveFileDialog.Filter = "LXFML-Files (*.lxfml)|*.lxfml"  ;
             * if (saveFileDialog.ShowDialog () == DialogResult.OK) {
             *      sSavePath = saveFileDialog.FileName;
             * }*/
            //string sSavePath = EditorUtility.SaveFilePanel("Save Session","","","lxfml");

            StreamWriter writer = File.CreateText(sSavePath);

            int threshold = (int)Mathf.Floor(((float)voxels.Count) / 10000);

            if (threshold == 0)
            {
                threshold = 1;
            }
            Debug.Log(threshold);

            saving           = true;
            onLoading        = true;
            obj.onProcessing = true;

            Debug.Log(voxels.Count);
            LoadingText.GetComponent <Text> ().text = "Saving \n writing to file...";

            ref_trans_strs = new List <string> ();

            writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
            writer.WriteLine("<LXFML versionMajor=\"5\" versionMinor=\"0\" name=\"" + fileName + "\">");
            writer.WriteLine("  <Meta>");
            writer.WriteLine("    <Application name=\"LEGO Digital Designer\" versionMajor=\"4\" versionMinor=\"3\"/>");
            writer.WriteLine("    <Brand name=\"LDD\"/>");
            writer.WriteLine("    <BrickSet version=\"1564.2\"/>");
            writer.WriteLine("  </Meta>");
            writer.WriteLine("  <Cameras>");
            writer.WriteLine("    <Camera refID=\"0\" fieldOfView=\"80\" distance=\"69.282035827636719\" transformation=\"0.70710688829421997,0,-0.70710688829421997,-0.40824830532073975,0.81649661064147949,-0.40824830532073975,0.57735037803649902,0.57735013961791992,0.57735037803649902,39.999996185302734,39.999992370605469,39.999996185302734\"/>");
            writer.WriteLine("  </Cameras>");
            writer.WriteLine("  <Bricks cameraRef=\"0\">");
            int counter = 0;

            foreach (Lego grid in voxels)
            {
                int    key;
                string matrix;
                bool   isHorizontal = false;
                if (grid.getDimen().x > grid.getDimen().y)
                {
                    //horizontal case
                    key = (int)(grid.getDimen().y *10.0f + grid.getDimen().x);
                    //Debug.Log (key);
                    matrix = "1,0,0,0,1,0,0,0,1,";
                    if (grid.getDimen().y == 2)
                    {
                        isHorizontal = true;
                    }
                }
                else
                {
                    //vertical case
                    key    = (int)(grid.getDimen().x *10.0f + grid.getDimen().y);
                    matrix = "0,0,1,0,1,0,-1,0,0,";
                }
                string designId;
                if (grid.getType() == LegoType.BRCIK)
                {
                    designId = brickID[key];
                }
                else
                {
                    designId = plateID[key];
                }
                writer.WriteLine("    <Brick refID=\"" + counter.ToString() + "\" designID=\"" + designId + "\">");
                writer.WriteLine("      <Part refID=\"" + counter.ToString() + "\" designID=\"" + designId + "\" materials=\"" + color2material[(int)grid.getColor()] + "\">");
                Vector3 lPos     = grid.getLPosition(isHorizontal);
                string  lPos_str = String.Format("{0:0.##},{1:0.##},{2:0.##}", lPos.x, lPos.y, lPos.z);
                ref_trans_strs.Add(lPos_str);

                writer.WriteLine("        <Bone refID=\"" + counter.ToString() + "\" transformation=\"" + matrix + lPos_str + "\">");
                writer.WriteLine("        </Bone>");
                writer.WriteLine("      </Part>");
                writer.WriteLine("    </Brick>");

                counter++;
                if (counter % threshold == 0)
                {
                    percentage = (float)counter / ((float)voxels.Count);
                }

                yield return(new WaitForFixedUpdate());
            }
            writer.WriteLine("  </Bricks>");
            writer.WriteLine("  <GroupSystems>");
            writer.WriteLine("    <GroupSystems>");
            writer.WriteLine("    </GroupSystems>");
            writer.WriteLine("  </GroupSystems>");
            writer.WriteLine("  <BuildingInstructions>");
            writer.WriteLine("  </BuildingInstructions>");
            writer.WriteLine("</LXFML>");
            writer.Close();
            Debug.Log("outputed");
            obj.onProcessing = false;
            onLoading        = false;
            yield return(new WaitForFixedUpdate());

            saving = false;
            yield return(new WaitForSeconds(0.0f));
        }
Example #26
0
    } // _LoadActionPlan()

    //https://forum.unity.com/threads/finally-a-serializable-dictionary-for-unity-extracted-from-system-collections-generic.335797/
    // Unity doesn't know how to serialize generic dictionaries.

    //https://www.codeproject.com/Questions/454134/Serialize-Dictionary-in-csharp
    void _SaveActionPlan(Dictionary <string, List <ActionPlanController.Action> > myDict)
    {
        // string dictPath = UnityEngine.Application.dataPath + "/ActionPlans/" + m_fileName;


        OpenFileName sfn = new OpenFileName();



        sfn.structSize = Marshal.SizeOf(sfn);
        sfn.filter     = "All Files\0*.xml\0\0"; //"All Files\0*.*\0\0".
        // ofn.filter = "Log files\0*.log\0Batch files\0*.bat\0";
        sfn.file         = new string(new char[256]);
        sfn.maxFile      = sfn.file.Length;
        sfn.fileTitle    = new string(new char[64]);
        sfn.maxFileTitle = sfn.fileTitle.Length;
        sfn.initialDir   = UnityEngine.Application.dataPath + "/ActionPlan/";
        sfn.title        = "Wrtie Action Plan File";
        sfn.defExt       = "xml";
        sfn.flags        = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
        //OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR

        //https://stackoverflow.com/questions/43573907/c-sharp-interop-returning-struct-from-unmanaged-code-with-out-parameter-gives

        //StartCoroutine(ExecuteAfterTime(10000));



        if (!DllTest.GetSaveFileName(sfn))
        {
            Debug.LogError("File Saving Dialog Failed");
            return;
        }

        //return;


        //// Open SaveFileDialog
        //SaveFileDialog save = new SaveFileDialog();
        //save.Filter = "ActionPlanFile(*.xml)|*.xml";
        //save.InitialDirectory = Directory.GetCurrentDirectory();
        //save.Title = "Save Action Plan";
        //if (save.ShowDialog() != DialogResult.OK)
        //    return;

        //m_fileName

        FileStream fs = new FileStream(sfn.file, FileMode.Create);
        //FileStream fs = new FileStream(m_fileName, FileMode.Create);


        TextWriter textWriter = new StreamWriter(fs);
        SerializableDictionary <string, List <ActionPlanController.Action> > serializableDict = new SerializableDictionary <string,
                                                                                                                            List <ActionPlanController.Action> >();

        // copy dictionary to serializable dictionary
        foreach (var kvp in myDict)
        {
            Debug.Log(kvp.Key + ":" + kvp.Value);
            serializableDict.Add(kvp.Key, kvp.Value);
        }

        XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary <string,
                                                                                    List <ActionPlanController.Action> >));

        serializer.Serialize(textWriter, serializableDict);
        textWriter.Close();


        //BinaryReader br = new BinaryReader(fs);


        ////var binaryFormatter = new BinaryFormatter();

        ////var fi = new System.IO.FileInfo(dictPath);

        ////try
        ////{
        ////    using (var binaryFile = fi.Create())
        ////    {
        ////        binaryFormatter.Serialize(binaryFile, myDict);
        ////        binaryFile.Flush();
        ////        binaryFile.Close();
        ////    }

        ////}

        ////catch (Exception ex)
        ////{
        ////    Debug.LogError(" Exception: " + ex.ToString());

        ////}

        ////Dictionary<String, List<ActionPlanController.Action>>
        //// b is this
        //SerializableDictionary<string, List<ActionPlanController.Action>> b = new SerializableDictionary<string,
        //                                                     List<ActionPlanController.Action>>();
        //// copy dictionary to serializable dictionary
        //foreach (var kvp in myDict)
        //{
        //    b.Add(kvp.Key, kvp.Value);

        //}



        ////List<string> stringList = new List<string>();
        //// stringList.Add("1");
        //// b.Add("One", stringList);

        //XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string,
        //                                             List<ActionPlanController.Action>>));
        //TextWriter textWriter = new StreamWriter(saveFileName);
        //serializer.Serialize(textWriter, b);
        //textWriter.Close();


        //FileStream file = File.Create(dictPath);

        //FileStream file = new FileStream(dictPath, FileMode.OpenOrCreate, FileAccess.Write);

        //BinaryFormatter bf = new BinaryFormatter();
        //// Serialize(Stream serializationStream, object graph);
        //try
        //{
        //    bf.Serialize(file, myDict);
        //}

        //catch (Exception ex)
        //{
        //    Debug.LogError(" Exception: " + ex.ToString()) ;

        //}
        //file.Close(); ;
    }// _SaveActionPlan
Example #27
0
    }// _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()
Example #28
0
        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;
        }
    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));
            }
        }
    }
Example #30
0
    // 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);
        }
    }