示例#1
0
        public string ConvertImage(string sourceFile, string destinationFile, string type)
        {
            #region ActionCheck(convert type)
            switch (type.ToLower())
            {
            case "gif":
                this.converter = new GIF();
                break;

            case "jpg":
                this.converter = new JPEG();
                break;

            case "png":
                this.converter = new PNG();
                break;

            default:
                throw new IlegalOperetaionException();
#pragma warning disable CS0162 // Unreachable code detected
                break;
#pragma warning restore CS0162 // Unreachable code detected
            }
            #endregion
            #region FileExistenceCheck
            //check if sourceFile exists, if not, throw exception
            if (!File.Exists(sourceFile))
            {
                throw new PrimeHoldingImage.Exception.FileNotFoundException();
            }
            #endregion
            #region DestionationFileNameCheck
            //Check if source and destionation file names are the same.
            if (Path.GetFullPath(sourceFile) == Path.GetFullPath(destinationFile))
            {
                throw new DestinationFileNameException("Cant write destinationFile over sourceFile.");
            }
            #endregion
            #region DestinationFileDirectoryExistanceCheck

            if (!Directory.Exists(Path.GetDirectoryName(destinationFile)))
            {
                throw new PrimeHoldingImage.Exception.DirectoryNotFoundException();
            }
            #endregion
            #region DestinationFileFormatCheck
            //check if the file's extension is supported .png != .pNg
            string extension = Path.GetExtension(destinationFile);
            if (extension == ".pNg" || extension == ".jpeg" || extension == ".jpg" || extension == ".gif")
            {
            }
            else
            {
                throw new DestinationFileTypeException();
            }
            #endregion
            this.destinationFile = this.converter.Convert(sourceFile, destinationFile);

            return(this.destinationFile);
        }
示例#2
0
        private void DrawPostConvert(ConvertStrategy strategy)
        {
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Label("Post Convert:", GUILayout.Width(90));
                int id = PostConvertNames.IndexOf(strategy.PostConvert);
                if (id <= 0)
                {
                    id = 0;
                }
                int newid = EditorGUILayout.Popup(id, PostConvertNames.ToArray(), GUILayout.Width(70));
                if (newid != id)
                {
                    strategy.PostConvert = PostConvertNames[newid];
                }
            }
            EditorGUILayout.EndHorizontal();
            MeshPostConvert postConvert;

            if (PostConvertMap.TryGetValue(strategy.PostConvert, out postConvert))
            {
                if (postConvert != null)
                {
                    postConvert.OnGUI();
                }
            }
        }
示例#3
0
        /// <summary>
        /// 產生寫入檔案的路徑
        /// </summary>
        /// <param name="oldPath">原輸入檔案路徑</param>
        /// <param name="strategy">轉檔策略</param>
        private string ForSavePath(string oldPath, ConvertStrategy strategy)
        {
            var result = $"{Path.GetDirectoryName(oldPath)}\\{Path.GetFileNameWithoutExtension(oldPath)}";

            switch (strategy)
            {
            case ConvertStrategy.CsvToJson:
            case ConvertStrategy.XlsxToJson:
                result = string.Concat(result, ".json");
                break;

            case ConvertStrategy.JsonToCsv:
                result = string.Concat(result, ".csv");
                break;

            case ConvertStrategy.JsonToXlsx:
                result = string.Concat(result, ".xlsx");
                break;
            }
            return(result);
        }
示例#4
0
        private bool DrawStrategy(string name, ConvertStrategy strategy)
        {
            EditorGUILayout.BeginVertical(mStyles.mPreviewBox);
            {
                EditorGUILayout.BeginHorizontal(GUILayout.Height(25));
                {
                    string newname = EditorGUILayout.DelayedTextField(name, EditorStyles.boldLabel, GUILayout.Width(200));
                    if (newname != name)
                    {
                        if (!StrategyMap.ContainsKey(newname))
                        {
                            StrategyMap[newname] = strategy;
                            StrategyMap.Remove(name);
                            return(false);
                        }
                    }
                    if (GUILayout.Button("删除策略", GUILayout.Width(80)))
                    {
                        StrategyMap.Remove(name);
                        return(false);
                    }
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(2);

                //draw slots
                EditorGUILayout.BeginHorizontal();
                {
                    DrawSlot(ref strategy.SlotA, "SlotA:");
                    GUILayout.Space(10);
                    DrawSlot(ref strategy.SlotB, "SlotB:");
                    GUILayout.Space(10);
                    DrawSlot(ref strategy.SlotC, "SlotC:");
                    GUILayout.Space(10);
                    DrawSlot(ref strategy.SlotD, "SlotD:");
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(10);

                //draw buffer info
                foreach (var p in strategy.BufferInfos)
                {
                    if (!DrawBufferInfo(p.Key, p.Value))
                    {
                        strategy.BufferInfos.Remove(p.Key);
                        break;
                    }
                    GUILayout.Space(5);
                }
                GUILayout.Space(10);

                //draw strategy function buttons
                EditorGUILayout.BeginHorizontal(GUILayout.Height(25));
                {
                    GUILayout.Label("添加buffer:", GUILayout.Width(80));
                    var s = (ESemantic)EditorGUILayout.EnumPopup(ESemantic.UnKnown, GUILayout.Width(80));
                    if (s != ESemantic.UnKnown)
                    {
                        if (!strategy.BufferInfos.ContainsKey(s))
                        {
                            strategy.BufferInfos.Add(s, new ConvertStrategy.BufferDataInfo(s));
                        }
                    }

                    GUILayout.FlexibleSpace();


                    if (GUILayout.Button("检查", GUILayout.Width(50)))
                    {
                        int id = strategy.CheckValid();
                        Debug.Log(strategy.GetValidInfo(id));
                    }

                    if (GUILayout.Button("生成", GUILayout.Width(50)))
                    {
                        string path = EditorUtility.SaveFilePanel("save mesh file", mSaveMeshPath, mNewMeshName, "fbx");
                        if (!string.IsNullOrEmpty(path))
                        {
                            int id = path.LastIndexOf("/");
                            mNewMeshName  = path.Substring(id + 1);
                            mSaveMeshPath = path.Substring(0, id + 1);

                            var newMesh = strategy.Convert(mNewMeshName);
                            if (newMesh != null)
                            {
                                MeshPostConvert postConvert;
                                if (PostConvertMap.TryGetValue(strategy.PostConvert, out postConvert))
                                {
                                    if (postConvert != null)
                                    {
                                        postConvert.PostConvert(ref newMesh);
                                    }
                                }

                                AddMeshData(newMesh.Name, newMesh);
                                FbxSerializer.WriteMeshFBX(newMesh, path);
                            }
                        }
                    }
                    GUILayout.Space(10);
                }
                EditorGUILayout.EndHorizontal();

                DrawPostConvert(strategy);
            }
            EditorGUILayout.EndVertical();
            // GUILayout.Space(5);
            return(true);
        }
示例#5
0
        private void OnGUI()
        {
            if (mStyles == null)
            {
                mStyles = new Styles();
            }

            //toolbar
            EditorGUILayout.BeginHorizontal(mStyles.mPreviewBox, GUILayout.Height(22));
            {
                if (GUILayout.Button("加载obj文件", GUILayout.Width(80)))
                {
                    string path = EditorUtility.OpenFilePanel("select obj file", mOpenMeshPath, "obj");
                    if (!string.IsNullOrEmpty(path))
                    {
                        int id = path.LastIndexOf("/");
                        mOpenMeshPath = path.Substring(0, id + 1);
                        LoadMesh(path);
                    }
                }

                if (GUILayout.Button("加载rip文件", GUILayout.Width(80)))
                {
                    string path = EditorUtility.OpenFilePanel("select rip file", mOpenMeshPath, "rip");
                    if (!string.IsNullOrEmpty(path))
                    {
                        int id = path.LastIndexOf("/");
                        mOpenMeshPath = path.Substring(0, id + 1);
                        LoadRipFile(path);
                    }
                }

                GUILayout.FlexibleSpace();
                if (GUILayout.Button("策略另存为"))
                {
                    SaveConfigDataToFile();
                }
                GUILayout.Space(30);
                if (GUILayout.Button("打开策略"))
                {
                    LoadConfigDataFromFile();
                }
                GUILayout.Space(30);

                newStrategyName = EditorGUILayout.TextField(newStrategyName, GUILayout.Width(100));
                GUILayout.Space(5);
                if (GUILayout.Button("新建策略", GUILayout.Width(80)))
                {
                    if (!StrategyMap.ContainsKey(newStrategyName))
                    {
                        var strategy = new ConvertStrategy();
                        strategy.BufferInfos.Add(ESemantic.Position, new ConvertStrategy.BufferDataInfo(ESemantic.Position));
                        strategy.BufferInfos.Add(ESemantic.Normal, new ConvertStrategy.BufferDataInfo(ESemantic.Normal));
                        strategy.BufferInfos.Add(ESemantic.Coord0, new ConvertStrategy.BufferDataInfo(ESemantic.Coord0));
                        StrategyMap.Add(newStrategyName, strategy);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(1);

                //draw mesh list
                EditorGUILayout.BeginVertical(mStyles.mPreviewBox, GUILayout.Width(155));
                {
                    GUILayout.Space(2);
                    mMeshListScroll = EditorGUILayout.BeginScrollView(mMeshListScroll);
                    foreach (var p in MeshPathMap)
                    {
                        if (string.IsNullOrEmpty(p.Value) && !MeshMap.ContainsKey(p.Key))
                        {
                            RemoveMeshData(p.Key);
                            break;
                        }
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(2);
                        if (GUILayout.Button(p.Key, EditorStyles.toolbarButton, GUILayout.Width(120)))
                        {
                            MeshData mesh;
                            if (!MeshMap.TryGetValue(p.Key, out mesh))
                            {
                                LoadMesh(p.Value);
                                if (!MeshMap.TryGetValue(p.Key, out mesh))
                                {
                                    Debug.LogWarning("无法打开文件:" + p.Value);
                                    RemoveMeshData(p.Key);
                                    break;
                                }
                            }
                            ViewMeshData(mesh);
                        }
                        if (GUILayout.Button("R", EditorStyles.toolbarButton, GUILayout.Width(30)))
                        {
                            RemoveMeshData(p.Key);
                            break;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(0);

                //draw strategy list
                EditorGUILayout.BeginVertical();
                {
                    mStrategyListScroll = EditorGUILayout.BeginScrollView(mStrategyListScroll);
                    foreach (var strategy in StrategyMap)
                    {
                        if (!DrawStrategy(strategy.Key, strategy.Value))
                        {
                            break;
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }