示例#1
0
        /// <summary>
        /// // 저장된 이미지값을 컬렉션으로 가져오는 메서드
        /// </summary>
        /// <returns>성공정으로 검색이 된다면 컬렉션을 반환</returns>
        internal List <ImageVO> SelectImages()
        {
            List <ImageVO> lst = new List <ImageVO>();
            string         sp  = "SelectImages";

            SqlParameter[] sqlParameters = null;

            try
            {
                SqlDataReader sdr = new DBConnection().Select(sp, sqlParameters);
                while (sdr.Read())
                {
                    ImageVO imageVO = new ImageVO();
                    imageVO.Num  = int.Parse(sdr["num"].ToString());
                    imageVO.Name = sdr["name"].ToString();
                    byte[] b = (byte[])sdr["image"];
                    imageVO.Image = b;

                    lst.Add(imageVO);
                }

                return(lst);
            }
            catch (SqlException ee)
            {
                System.Windows.Forms.MessageBox.Show(ee.StackTrace);
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// // 저장된 이미지들을 이름으로 검색해 객체로 가져오는 메서드
        /// </summary>
        /// <param name="name">검색할 이미지 명</param>
        /// <returns>이미지의 정보들을 imageVO객체로 반환한다.</returns>
        internal ImageVO SelectImagesByName(string name)
        {
            string sp = "SelectImagesByName";

            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("name", name)
            };

            try
            {
                SqlDataReader sdr     = new DBConnection().Select(sp, sqlParameters);
                ImageVO       imageVO = new ImageVO();

                while (sdr.Read())
                {
                    imageVO.Num   = int.Parse(sdr["num"].ToString());
                    imageVO.Name  = sdr["name"].ToString();
                    imageVO.Image = (byte[])sdr["image"];
                }

                return(imageVO);
            }
            catch (SqlException ee)
            {
                System.Windows.Forms.MessageBox.Show(ee.StackTrace);
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// 이미지를 등록하기위한 InsertImage 메서드
        /// </summary>
        /// <param name="imgVO">이미지의 정보가 담겨있는 ImgVO객체</param>
        /// <returns>DB 등록여부를 반환</returns>
        internal bool InsertImage(ImageVO imgVO)
        {
            DBConnection connection      = new DBConnection();
            string       storedProcedure = "InsertImages";

            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("name", imgVO.Name),
                new SqlParameter("image", imgVO.Image)
            };

            try
            {
                return(connection.Insert(storedProcedure, sqlParameters));
            }
            catch (SqlException)
            {
                throw;
            }
        }
示例#4
0
        private async Task <IList <IValueObject> > DownloadAndSaveImages(IList <IValueObject> images)
        {
            ImageService.ClearImageDirectory();
            var downloadImageTask = Task.Run(() =>
            {
                IList <IValueObject> result = new List <IValueObject>();
                foreach (ImageVO imageVO in images)
                {
                    ImageVO imageVOResult = imageVO.Clone();
                    imageVOResult.Src     = DownloadAndSaveImageFromUrl(imageVO.Src);
                    if (!String.IsNullOrEmpty(imageVOResult.Src))
                    {
                        result.Add(imageVOResult);
                    }
                }
                return(result);
            });

            return(await downloadImageTask);
        }
示例#5
0
        /// <summary>
        /// 이미지 폴더내의 새로운 이미지를 DB에 저장하기위한 메서드
        /// </summary>
        private void UploadImage()
        {
            foreach (var fileName in needsToUpload)
            {
                ImageVO imgVO = new ImageVO();
                imgVO.Name = fileName;

                MemoryStream ms  = new MemoryStream();
                Image        img = Image.FromFile(Application.StartupPath + "\\images\\" + fileName);
                img.Save(ms, img.RawFormat);

                imgVO.Image = ms.ToArray();
                try
                {
                    new ImagesDAO().InsertImage(imgVO);
                    MessageBox.Show(imgVO.Name + " 이(가) 업로드 되었습니다.");
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.StackTrace);
                }
            }
        }
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();


        findSprite    = EditorGUILayout.ObjectField("查找 Sprite", findSprite, typeof(Sprite), false) as Sprite;
        replaceSprite = EditorGUILayout.ObjectField("替换 Sprite", replaceSprite, typeof(Sprite), false) as Sprite;

        GUILayout.Box("查找目录:(用';'分隔)");
        sceneFolderStr = GUILayout.TextArea(sceneFolderStr, 500, GUILayout.MinHeight(50));
        sceneFolderStr = sceneFolderStr.Trim();
        sceneFolders   = sceneFolderStr.Split(';');
        isSaveScene    = GUILayout.Toggle(isSaveScene, "是否保存场景");

        if (findSprite != null)
        {
            if (GUILayout.Button("查找"))
            {
                sceneList.Clear();
                if (!EditorApplication.SaveCurrentSceneIfUserWantsTo())
                {
                    return;
                }
                string editorScenePath = EditorApplication.currentScene;



//				string[] guids = AssetDatabase.FindAssets ("t:scene", new string[] {"Assets/Game/Arts_Modules", "Assets/Game/Scenes"});
                string[] guids      = AssetDatabase.FindAssets("t:scene", sceneFolders);
                string   activePath = AssetDatabase.GetAssetPath(findSprite);
                Debug.Log("activePath=" + activePath);
                foreach (string guid in guids)
                {
                    string  scenePath = AssetDatabase.GUIDToAssetPath(guid);
                    SceneVO sceneVO   = new SceneVO();
                    sceneVO.path = scenePath;

                    //打开场景
                    EditorApplication.OpenScene(scenePath);
                    //获取场景中的所有游戏对象
                    Image[] images = (Image[])FindObjectsOfTypeAll(typeof(Image));

                    foreach (Image image  in images)
                    {
                        if (image.sprite == null)
                        {
                            continue;
                        }

                        string path = AssetDatabase.GetAssetPath(image.sprite);
                        if (path == activePath)
                        {
                            ImageVO imageVO = new ImageVO();
                            imageVO.path  = GetGameObjectPath(image.gameObject);
                            imageVO.scene = sceneVO;
                            sceneVO.list.Add(imageVO);
                            PrefabType prefabType = PrefabUtility.GetPrefabType(image.gameObject);
                            if (prefabType == PrefabType.PrefabInstance)
                            {
                                UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(image.gameObject);
                                imageVO.prefabPath = AssetDatabase.GetAssetPath(parentObject);
                            }
                            else if (prefabType == PrefabType.Prefab)
                            {
                                imageVO.prefabPath = AssetDatabase.GetAssetPath(image.gameObject);
                            }
                        }
                    }

                    if (sceneVO.list.Count > 0)
                    {
                        sceneList.Add(sceneVO);
                    }
                }

                if (!string.IsNullOrEmpty(editorScenePath))
                {
                    EditorApplication.OpenScene(editorScenePath);
                }
            }


            if (replaceSprite != null)
            {
                if (GUILayout.Button("替换所有(注意:确认无误后再点击)"))
                {
                    sceneList.Clear();
                    if (!EditorApplication.SaveCurrentSceneIfUserWantsTo())
                    {
                        return;
                    }
                    string editorScenePath = EditorApplication.currentScene;



                    //				string[] guids = AssetDatabase.FindAssets ("t:scene", new string[] {"Assets/Game/Arts_Modules", "Assets/Game/Scenes"});
                    string[] guids      = AssetDatabase.FindAssets("t:scene", sceneFolders);
                    string   activePath = AssetDatabase.GetAssetPath(findSprite);
                    Debug.Log("activePath=" + activePath);
                    foreach (string guid in guids)
                    {
                        string  scenePath = AssetDatabase.GUIDToAssetPath(guid);
                        SceneVO sceneVO   = new SceneVO();
                        sceneVO.path = scenePath;

                        //打开场景
                        if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                        {
                            EditorApplication.OpenScene(scenePath);
                            //获取场景中的所有游戏对象
                            Image[] images = (Image[])FindObjectsOfTypeAll(typeof(Image));

                            foreach (Image image  in images)
                            {
                                if (image.sprite == null)
                                {
                                    continue;
                                }

                                string path = AssetDatabase.GetAssetPath(image.sprite);
                                if (path == activePath)
                                {
                                    ImageVO imageVO = new ImageVO();
                                    imageVO.path  = GetGameObjectPath(image.gameObject);
                                    imageVO.scene = sceneVO;
                                    sceneVO.list.Add(imageVO);
                                    PrefabType prefabType = PrefabUtility.GetPrefabType(image.gameObject);
                                    if (prefabType == PrefabType.PrefabInstance)
                                    {
                                        UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(image.gameObject);
                                        imageVO.prefabPath = AssetDatabase.GetAssetPath(parentObject);
                                    }
                                    else if (prefabType == PrefabType.Prefab)
                                    {
                                        imageVO.prefabPath = AssetDatabase.GetAssetPath(image.gameObject);
                                    }

                                    image.sprite = replaceSprite;
                                }
                            }

                            if (sceneVO.list.Count > 0)
                            {
                                sceneList.Add(sceneVO);
                                if (isSaveScene)
                                {
                                    EditorApplication.SaveScene();
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(editorScenePath))
                    {
                        if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                        {
                            EditorApplication.OpenScene(editorScenePath);
                        }
                    }
                }
            }
        }



        GUILayout.Space(30);
        GUILayout.Box("搜索结果:");
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

        foreach (SceneVO sceneVO in sceneList)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(sceneVO.path))
            {
                if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                {
                    EditorApplication.OpenScene(sceneVO.path);
                }
            }

            if (EditorApplication.currentScene == sceneVO.path)
            {
                if (replaceSprite != null && GUILayout.Button("替换", GUILayout.Width(50)))
                {
                    //获取场景中的所有游戏对象
                    Image[] images = (Image[])FindObjectsOfTypeAll(typeof(Image));

                    string activePath = AssetDatabase.GetAssetPath(findSprite);
                    foreach (Image image  in images)
                    {
                        if (image.sprite == null)
                        {
                            continue;
                        }

                        string path = AssetDatabase.GetAssetPath(image.sprite);
                        if (path == activePath)
                        {
                            image.sprite = replaceSprite;
                            EditorUtility.SetDirty(image);
                        }
                    }

                    if (isSaveScene)
                    {
                        EditorApplication.SaveScene();
                    }
                }
            }
            EditorGUILayout.EndHorizontal();



            //-------------------------
            foreach (ImageVO imageVO in sceneVO.list)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(imageVO.path);


                if (!string.IsNullOrEmpty(imageVO.prefabPath) && GUILayout.Button("Prefab", GUILayout.Width(50)))
                {
                    Selection.activeGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(imageVO.prefabPath);
                }


                if (GUILayout.Button("Find", GUILayout.Width(50)))
                {
                    Debug.Log("imageVO.prefabPath = " + imageVO.prefabPath);

                    if (EditorApplication.currentScene != sceneVO.path)
                    {
                        if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                        {
                            EditorApplication.OpenScene(sceneVO.path);

                            Selection.activeGameObject = GameObject.Find(imageVO.path);
                        }
                    }
                    else
                    {
                        Selection.activeGameObject = GameObject.Find(imageVO.path);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(20);
        }

        EditorGUILayout.EndScrollView();

        EditorGUILayout.EndVertical();
    }