コード例 #1
0
ファイル: BaseHelp.cs プロジェクト: lovoror/unity-mix-gizmos
        /// <summary>
        /// 递归复制目录和文件
        /// </summary>
        /// <param name="src_root">源目录</param>
        /// <param name="des_root">目标目录</param>
        public static void CopyDirectory(string src_root, string des_root)
        {
            // 清空目录
            BaseHelp.ClearDir(des_root);

            // 递归复制
            BaseHelp.ScanPath(
                src_root,
                delegate(string absolute_path)
            {
                string des_file = absolute_path.Replace(src_root, des_root);
                File.Copy(absolute_path, des_file, true);
                return(BaseHelp.ScanPathResult.none);
            },
                delegate(string absolute_path)
            {
                string des_dir = absolute_path.Replace(src_root, des_root);
                if (!Directory.Exists(des_dir))
                {
                    Directory.CreateDirectory(des_dir);
                }
                return(BaseHelp.ScanPathResult.none);
            }
                );
        }
コード例 #2
0
ファイル: BaseHelp.cs プロジェクト: lovoror/unity-mix-gizmos
        /// <summary>
        /// 扫描路径
        /// </summary>
        /// <param name="absolute_path"></param>
        /// <param name="file_handler"></param>
        /// <param name="dir_handler"></param>
        public static void ScanPath(string absolute_path, ScanPathHandler file_handler, ScanPathHandler dir_handler)
        {
            string[] files = Directory.GetFiles(absolute_path);
            int      count = files.Length;

            for (int i = 0; i < count; ++i)
            {
                string         one    = files[i].Replace("\\", "/");
                ScanPathResult result = file_handler.Invoke(one);
                // 通常用于
                if (result == ScanPathResult.file_return)
                {
                    return;
                }
            }

            string[] sub_dirs = Directory.GetDirectories(absolute_path);
            count = sub_dirs.Length;
            for (int i = 0; i < count; ++i)
            {
                string         one    = sub_dirs[i].Replace("\\", "/");
                ScanPathResult result = dir_handler.Invoke(one);
                if (result == ScanPathResult.dir_continue)
                {
                    continue;
                }
                else if (result == ScanPathResult.dir_return)
                {
                    return;
                }
                BaseHelp.ScanPath(one, file_handler, dir_handler);
            }
        }
コード例 #3
0
ファイル: BaseHelp.cs プロジェクト: lovoror/unity-mix-gizmos
        /// <summary>
        /// 获取工程目录绝对路径
        /// </summary>
        /// <returns></returns>
        public static string GetProjectAbsolutePath()
        {
            string project_root = BaseHelp.GetParentDir(Application.dataPath);

            project_root = project_root.Replace("\\", "/");
            return(project_root);
        }
コード例 #4
0
ファイル: BaseHelp.cs プロジェクト: lovoror/unity-mix-gizmos
        /// <summary>
        /// 资源相对工程目录的路径
        /// </summary>
        /// <param name="absolute_path"></param>
        /// <returns></returns>
        public static string GetProjectRelativePath(string absolute_path)
        {
            string project_root = BaseHelp.GetParentDir(Application.dataPath);

            absolute_path = absolute_path.Substring(project_root.Length + 1);
            absolute_path = absolute_path.Replace("\\", "/");
            return(absolute_path);
        }
コード例 #5
0
ファイル: BaseHelp.cs プロジェクト: lovoror/unity-mix-gizmos
        /// <summary>
        /// 清理构建AB生成的manifest汇总信息
        /// </summary>
        /// <param name="root_absolute_path"></param>
        public static void ClearBuildManifest(string root_absolute_path)
        {
            string name = root_absolute_path.Substring(root_absolute_path.LastIndexOf('/') + 1);
            string src  = string.Format("{0}/{1}", root_absolute_path, name);

            File.Delete(src);
            File.Delete(string.Format("{0}.manifest", src));

            BaseHelp.ScanPath(
                root_absolute_path,
                delegate(string file_path)
            {
                if (!file_path.EndsWith(".manifest"))
                {
                    return(ScanPathResult.none);
                }

                File.Delete(file_path);
                return(ScanPathResult.none);
            },
                null
                );
        }
コード例 #6
0
        /// <summary>
        /// 模型导入预处理
        /// </summary>
        void OnPreprocessModel()
        {
            string project_relative_path = this.assetPath;
            string folder         = BaseHelp.GetParentDir(project_relative_path);
            string clip_file_path = string.Format("{0}/MecanimConfig.asset", folder);

            // 如果目录下包含MecanimConfig配置,才进行预处理
            MecanimConfig config = AssetDatabase.LoadAssetAtPath(clip_file_path, typeof(MecanimConfig)) as MecanimConfig;

            if (!config)
            {
                return;
            }

            ModelImporter importer = (ModelImporter)this.assetImporter;

            // 默认不导入材质
            importer.importMaterials      = false;
            importer.importBlendShapes    = false;
            importer.isReadable           = false;
            importer.optimizeMeshPolygons = true;
            importer.optimizeMeshVertices = true;
            importer.weldVertices         = true;
            importer.swapUVChannels       = false;
            importer.generateSecondaryUV  = false;
            // 设置旋转校正为0,避免一定程度的抖动
            importer.animationRotationError = 0;

            // 覆盖默认配置
            importer.isReadable = config.enable_read_write;

            List <ModelImporterClipAnimation> reset_list = new List <ModelImporterClipAnimation>();
            int clip_count = config.clips.Count;

            for (int i = 0; i < clip_count; ++i)
            {
                MecanimClipConfig          clip_config = config.clips[i];
                ModelImporterClipAnimation reset       = new ModelImporterClipAnimation();
                reset.name       = clip_config.name;
                reset.firstFrame = clip_config.start_frame;
                reset.lastFrame  = clip_config.end_frame;
                reset.loopTime   = clip_config.loop;
                reset.wrapMode   = clip_config.loop ? WrapMode.Loop : WrapMode.Default;

                // 事件
                List <AnimationEvent> evts = new List <AnimationEvent>();
                int evt_count = clip_config.evts.Count;
                for (int j = 0; j < evt_count; ++j)
                {
                    MecanimClipEvent mecanim_evt = clip_config.evts[j];
                    AnimationEvent   evt         = new AnimationEvent();
                    evt.time = mecanim_evt.time;
                    // 枚举即是函数名称
                    evt.functionName    = mecanim_evt.evt_type.ToString();
                    evt.stringParameter = mecanim_evt.str_param;
                    evt.intParameter    = mecanim_evt.int_param;
                    evts.Add(evt);
                }
                reset.events = evts.ToArray();

                reset_list.Add(reset);
            }

            // 重新赋值
            importer.clipAnimations = reset_list.ToArray();
        }