public static void CreatePlaceHolderFont()
        {
            var srcpath = CapsModEditor.GetPackageOrModRoot(CapsEditorUtils.__MOD__);

            srcpath += "/~Tools~/CapstonesPlaceHolder.otf";

            if (PlatDependant.IsFileExist(srcpath))
            {
                var sids = Selection.instanceIDs;
                if (sids != null && sids.Length > 0)
                {
                    bool found = false;
                    int  fid   = 0;
                    for (int i = sids.Length - 1; i >= 0; --i)
                    {
                        var sid = sids[i];
                        if (ProjectWindowUtil.IsFolder(sid))
                        {
                            fid   = sid;
                            found = true;
                            break;
                        }
                    }
                    string folder;
                    if (!found)
                    {
                        folder = ProjectWindowUtil.GetContainingFolder(AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(sids[0])));
                    }
                    else
                    {
                        folder = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(fid));
                    }
                    var asset = folder;
                    folder = CapsModEditor.GetAssetPath(folder); // this seems to be useless. Unity's System.IO lib can handle path like Packages/cn.capstones.phfont/xxx

                    string fontName = "";
                    string fileName;

                    for (int i = 1; i <= 99999; ++i)
                    {
                        fontName = "CapstonesPHFont" + i.ToString("00000");
                        if (!_PHFontNameToAssetName.ContainsKey(fontName))
                        {
                            break;
                        }
                    }
                    fileName = fontName;
                    if (PlatDependant.IsFileExist(folder + "/" + fileName + ".otf"))
                    {
                        for (int i = 0; ; ++i)
                        {
                            fileName = fontName + "_" + i;
                            if (!PlatDependant.IsFileExist(folder + "/" + fileName + ".otf"))
                            {
                                break;
                            }
                        }
                    }

                    PlatDependant.CopyFile(srcpath, folder + "/" + fileName + ".otf");

                    // Modify the otf file.
                    using (var stream = PlatDependant.OpenAppend(folder + "/" + fileName + ".otf"))
                    {
                        stream.Seek(0x3cc, System.IO.SeekOrigin.Begin);
                        var buffer = System.Text.Encoding.ASCII.GetBytes(fontName);
                        stream.Write(buffer, 0, buffer.Length);
                        stream.Seek(0x4d0, System.IO.SeekOrigin.Begin);
                        buffer = System.Text.Encoding.BigEndianUnicode.GetBytes(fontName);
                        stream.Write(buffer, 0, buffer.Length);
                    }
                    AssetDatabase.ImportAsset(asset + "/" + fileName + ".otf");

                    PlatDependant.CopyFile(asset + "/" + fileName + ".otf", asset + "/" + fileName + ".otf.~");
                    PlatDependant.CopyFile(asset + "/" + fileName + ".otf.meta", asset + "/" + fileName + ".otf.meta.~");

                    AssetDatabase.CreateAsset(ScriptableObject.CreateInstance <CapsPHFontDesc>(), asset + "/" + fileName + ".phf.asset");
                    AssetDatabase.ImportAsset(asset + "/" + fileName + ".phf.asset");
                    AddPHFont(asset + "/" + fileName + ".phf.asset");
                    SaveCachedPHFonts();
                }
            }
        }
示例#2
0
        public EditorWorkProgressShowerInConsole()
        {
#if UNITY_EDITOR_WIN
            var pipeName = System.DateTime.Now.ToString("yyMMddHHmmss");
            var pipeout  = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsole" + pipeName, System.IO.Pipes.PipeDirection.Out);
            var pipein   = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsoleControl" + pipeName, System.IO.Pipes.PipeDirection.In);
            var arout    = pipeout.BeginWaitForConnection(null, null);
            var arin     = pipein.BeginWaitForConnection(null, null);

            var dir     = Application.dataPath + "/../";
            var tooldir = CapsModEditor.GetPackageOrModRoot(CapsEditorUtils.__MOD__) + "/~Tools~/";
            System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(tooldir + "ProgressShowerInConsole.exe", pipeName);
            si.WorkingDirectory = tooldir;
            _ExProc             = System.Diagnostics.Process.Start(si);

            var thd_Write = new System.Threading.Thread(() =>
            {
                try
                {
                    pipeout.EndWaitForConnection(arout);
                    var sw = new System.IO.StreamWriter(pipeout);
                    while (_MessageReady.WaitOne())
                    {
                        _MessageReady.Reset();
                        lock (_MessageQueue)
                        {
                            foreach (var line in _MessageQueue)
                            {
                                sw.WriteLine(line);
                            }
                            sw.Flush();
                            _MessageQueue.Clear();
                        }
                    }
                }
                finally
                {
                    pipeout.Dispose();
                }
            });
            thd_Write.Start();

            var thd_Read = new System.Threading.Thread(() =>
            {
                try
                {
                    pipein.EndWaitForConnection(arin);
                    var sr = new System.IO.StreamReader(pipein);
                    while (!_ExProc.HasExited)
                    {
                        var line = sr.ReadLine();
                        if (line != null)
                        {
                            if (line == "\uEE05Quit")
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    _ShouldQuit = true;
                    thd_Write.Abort();
                    _MessageReady.Set();
                    pipein.Dispose();
                }
            });
            thd_Read.Start();
#endif
        }