Beispiel #1
0
        public void Freeze(int version)
        {
            if (version <= 0)
            {
                return;
            }

            var repositoryRoot = AssetSyncConfiger.GetInstance().GetRepositoryRootPath();

            if (string.IsNullOrEmpty(repositoryRoot))
            {
                return;
            }

            var syncItems = AssetSyncConfiger.GetInstance().syncItems;

            if (syncItems == null || syncItems.Count <= 0)
            {
                return;
            }

            string versionFolderName = string.Format("{0}", version);
            string repositoryPath    = XPathTools.Combine(repositoryRoot, versionFolderName);

            foreach (var syncItem in syncItems)
            {
                string destPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath);
                if (XFolderTools.Exists(destPath))
                {
                    XFolderTools.DeleteDirectory(destPath, true);
                }
            }
        }
Beispiel #2
0
        protected override void OnInit()
        {
            var cfgObj = AddObject(AssetSyncConfiger.GetInstance());
            var prop   = AddProperty("syncItems");

            m_itemSortedList = new ReorderableList(cfgObj, prop, true, true, true, true);
            m_itemSortedList.elementHeight = 100;//设置单个元素的高度

            //绘制单个元素
            m_itemSortedList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                var element = prop.GetArrayElementAtIndex(index);
                rect.height -= 4;
                rect.y      += 2;
                EditorGUI.PropertyField(rect, element);
            };

            //背景色
            m_itemSortedList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) =>
            {
                GUI.backgroundColor = Color.yellow;
            };

            //头部
            m_itemSortedList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, "常规同步项");
        }
Beispiel #3
0
 public void Sync()
 {
     //遍历版本库文件夹
     XFolderTools.TraverseFolder(AssetSyncConfiger.GetInstance().GetRepositoryRootPath(), (fullPath) =>
     {
         string folderName = Path.GetFileNameWithoutExtension(fullPath);
         int version;
         if (int.TryParse(folderName, out version))
         {
             Sync(version);
         }
     });
 }
Beispiel #4
0
        protected override void OnShow()
        {
            GUILayout.BeginVertical();
            if (GUILayout.Button("同步"))
            {
                AssetSyncManager.GetInstance().Sync();
            }

            AssetSyncConfiger.GetInstance().minVersion         = EditorGUILayout.IntField("最小同步版本", AssetSyncConfiger.GetInstance().minVersion);
            AssetSyncConfiger.GetInstance().repositoryRootPath = GUILayoutEx.ShowPathBar("版本库路径", AssetSyncConfiger.GetInstance().repositoryRootPath);


            m_itemSortedList.DoLayoutList();

            GUILayout.EndVertical();
        }
Beispiel #5
0
        public void Sync(int version)
        {
            var syncItems = AssetSyncConfiger.GetInstance().syncItems;

            if (syncItems == null || syncItems.Count <= 0)
            {
                return;
            }

            string fullPath          = XPathTools.Combine(AssetSyncConfiger.GetInstance().repositoryRootPath, string.Format("{0}", version));
            string repositoryPath    = fullPath;
            string versionFolderName = Path.GetFileNameWithoutExtension(fullPath);
            int    curVersion        = AssetSyncConfiger.GetInstance().GetRepositoryVersion(versionFolderName);

            if (curVersion > 0 && curVersion >= AssetSyncConfiger.GetInstance().minVersion)
            {
                foreach (var syncItem in syncItems)
                {
                    string srcPath    = syncItem.srcPath;
                    string searchPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath);
                    string syncPath   = XPathTools.Combine(repositoryPath, syncItem.realSyncPath);
                    if (XFolderTools.Exists(srcPath) && XFolderTools.Exists(searchPath) && XFolderTools.Exists(syncPath))
                    {
                        List <string> syncFileList   = new List <string>();
                        List <string> syncFolderList = new List <string>();
                        if (syncItem.searchMode == AssetSyncItem.SearchMode.Forward)     //根据搜索文件找资源
                        {
                            string srcEx = GetFolderFirstFileExtension(srcPath);
                            XFolderTools.TraverseFiles(searchPath, (filePath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(filePath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(filePath);
                                }

                                string srcFilePath = XPathTools.Combine(srcPath, string.Format("{0}{1}", fileKey, srcEx));
                                if (XFileTools.Exists(srcFilePath))
                                {
                                    syncFileList.Add(srcFilePath);
                                }
                            });

                            XFolderTools.TraverseFolder(searchPath, (folderPath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(folderPath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(folderPath);
                                }

                                string srcFolderPath = XPathTools.Combine(srcPath, string.Format("{0}", fileKey));
                                if (XFolderTools.Exists(srcFolderPath))
                                {
                                    syncFolderList.Add(srcFolderPath);
                                }
                            });
                        }
                        else if (syncItem.searchMode == AssetSyncItem.SearchMode.Reverse)   //根据资源匹对文件
                        {
                            XFolderTools.TraverseFiles(srcPath, (filePath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(filePath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(filePath);
                                }

                                string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey));
                                if (XFileTools.Exists(searchFilePath))
                                {
                                    syncFileList.Add(filePath);
                                }
                            });

                            XFolderTools.TraverseFolder(srcPath, (folderPath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(folderPath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(folderPath);
                                }

                                string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey));
                                if (XFileTools.Exists(searchFilePath))
                                {
                                    syncFolderList.Add(folderPath);
                                }
                            });
                        }

                        HashSet <string> syncFileDict = new HashSet <string>();
                        foreach (var syncSrcFile in syncFileList)
                        {
                            //把文件拷贝到同步目录
                            string syncFileName = Path.GetFileName(syncSrcFile);
                            string syncDestPath = XPathTools.Combine(syncPath, syncFileName);
                            XFileTools.Delete(syncDestPath);
                            XFileTools.Copy(syncSrcFile, syncDestPath);

                            if (!syncFileDict.Contains(syncDestPath))
                            {
                                syncFileDict.Add(syncDestPath);
                            }
                        }

                        HashSet <string> syncFolderDict = new HashSet <string>();
                        foreach (var syncSrcFolder in syncFolderList)
                        {
                            //把文件拷贝到同步目录
                            string syncFileName = Path.GetFileName(syncSrcFolder);
                            string syncDestPath = XPathTools.Combine(syncPath, syncFileName);

                            XFolderTools.DeleteDirectory(syncDestPath, true);
                            XFolderTools.CopyDirectory(syncSrcFolder, syncDestPath);

                            if (!syncFolderDict.Contains(syncDestPath))
                            {
                                syncFolderDict.Add(syncDestPath);
                            }
                        }

                        //移除不在同步的文件
                        XFolderTools.TraverseFiles(syncPath, (syncFullPath) =>
                        {
                            if (!syncFileDict.Contains(syncFullPath))
                            {
                                XFileTools.Delete(syncFullPath);
                            }
                        });

                        XFolderTools.TraverseFolder(syncPath, (syncFullPath) =>
                        {
                            if (!syncFolderDict.Contains(syncFullPath))
                            {
                                XFolderTools.DeleteDirectory(syncFullPath, true);
                            }
                        });
                    }
                }
            }
        }
Beispiel #6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //创建一个属性包装器,用于将常规GUI控件与SerializedProperty一起使用
            using (new EditorGUI.PropertyScope(position, label, property))
            {
                //绘制name
                EditorGUIUtility.labelWidth = 100;                               //设置属性名宽度 Name HP
                position.height             = EditorGUIUtility.singleLineHeight; //输入框高度,默认一行的高度

                SerializedProperty nameProperty = property.FindPropertyRelative("name");
                nameProperty.stringValue = EditorGUI.TextField(new Rect(position)
                {
                    y     = position.y + 0 * EditorGUIUtility.singleLineHeight,
                    width = Math.Max(0, position.width),
                }, "备注", nameProperty.stringValue);


                EditorGUIUtility.labelWidth = 100;
                SerializedProperty srcPathProperty = property.FindPropertyRelative("srcPath");
                srcPathProperty.stringValue = EditorGUI.TextField(new Rect(position)
                {
                    y     = position.y + 1 * EditorGUIUtility.singleLineHeight,
                    width = Math.Max(0, position.width - 100),
                }, "资源路径", srcPathProperty.stringValue);
                GUILayout.BeginArea(new Rect(position)
                {
                    x     = EditorGUIUtility.currentViewWidth - 105,
                    y     = position.y + 1 * EditorGUIUtility.singleLineHeight + 78,
                    width = 100,
                });
                if (GUILayout.Button("浏览"))
                {
                    var selectedPath = EditorUtility.SaveFolderPanel("Source Folder Path", "Assets", "");
                    if (!string.IsNullOrEmpty(selectedPath))
                    {
                        srcPathProperty.stringValue = selectedPath;
                    }
                }
                GUILayout.EndArea();


                EditorGUIUtility.labelWidth = 100;
                SerializedProperty realSearceProperty = property.FindPropertyRelative("realSearcePath");
                realSearceProperty.stringValue = EditorGUI.TextField(new Rect(position)
                {
                    y     = position.y + 2 * EditorGUIUtility.singleLineHeight,
                    width = Math.Max(0, position.width - 100),
                }, "比对扫描路径", realSearceProperty.stringValue);
                GUILayout.BeginArea(new Rect(position)
                {
                    x     = EditorGUIUtility.currentViewWidth - 105,
                    y     = position.y + 2 * EditorGUIUtility.singleLineHeight + 78,
                    width = 100,
                });
                if (GUILayout.Button("浏览"))
                {
                    var selectedPath = EditorUtility.SaveFolderPanel("Destination Folder Path", "Assets", "");
                    if (!string.IsNullOrEmpty(selectedPath))
                    {
                        realSearceProperty.stringValue = AssetSyncConfiger.GetInstance().GetCheckFolderRelativePath(selectedPath);
                    }
                }
                GUILayout.EndArea();

                EditorGUIUtility.labelWidth = 100;
                SerializedProperty realSyncProperty = property.FindPropertyRelative("realSyncPath");
                realSyncProperty.stringValue = EditorGUI.TextField(new Rect(position)
                {
                    y     = position.y + 3 * EditorGUIUtility.singleLineHeight,
                    width = Math.Max(0, position.width - 100),
                }, "同步目标路径", realSyncProperty.stringValue);
                GUILayout.BeginArea(new Rect(position)
                {
                    x     = EditorGUIUtility.currentViewWidth - 105,
                    y     = position.y + 3 * EditorGUIUtility.singleLineHeight + 78,
                    width = 100,
                });
                if (GUILayout.Button("浏览"))
                {
                    var selectedPath = EditorUtility.SaveFolderPanel("Destination Folder Path", "Assets", "");
                    if (!string.IsNullOrEmpty(selectedPath))
                    {
                        realSyncProperty.stringValue = AssetSyncConfiger.GetInstance().GetCheckFolderRelativePath(selectedPath);
                    }
                }
                GUILayout.EndArea();


                SerializedProperty searchModeProperty = property.FindPropertyRelative("searchMode");
                searchModeProperty.enumValueIndex = (int)(AssetSyncItem.SearchMode)EditorGUI.EnumPopup(new Rect(position)
                {
                    y     = position.y + 4 * EditorGUIUtility.singleLineHeight,
                    width = Math.Max(0, position.width),
                }, "扫描模式", (AssetSyncItem.SearchMode)searchModeProperty.enumValueIndex);


                SerializedProperty searchKeyProperty = property.FindPropertyRelative("searchKey");
                searchKeyProperty.enumValueIndex = (int)(AssetSyncItem.SearchKey)EditorGUI.EnumPopup(new Rect(position)
                {
                    y     = position.y + 5 * EditorGUIUtility.singleLineHeight,
                    width = Math.Max(0, position.width),
                }, "扫描关键字", (AssetSyncItem.SearchKey)searchKeyProperty.enumValueIndex);
            }
        }