Beispiel #1
0
        // Load icon from Info.IconFileName, add it to AssetPaths
        private void ImportIcon()
        {
            bool hasIconFileName = !string.IsNullOrEmpty(Info.IconFileName);

            if (hasIconFileName || layerAutomaticIcon != null)
            {
                /* Note: At one point I tried to optimize it, by detecting when
                 * icon is already in the assets
                 * ( Info.IconFileName.StartsWith(Application.dataPath) )
                 * and then just adding the existing asset-relative path to AssetPaths.
                 *
                 * But it doesn't work: we need the file to be called "icon.asset"
                 * ("icon.png" is ignored by Unity bundle building, as it has unrecognized
                 * extension). So we need to read + write the file anyway.
                 */

                Texture2D texture;
                if (hasIconFileName)
                {
                    byte[] data = File.ReadAllBytes(Info.IconFileName);
                    texture = new Texture2D(1, 1);
                    texture.LoadImage(data);
                }
                else
                {
                    texture = layerAutomaticIcon;
                }

                string iconAssetPath = AssetDirs.TempAssetsDir + "/icon.asset";
                AssetDatabase.CreateAsset(texture, iconAssetPath);
                AssetPaths.Add(iconAssetPath);
            }
        }
Beispiel #2
0
        // Exports finished GameObject to a .prefab
        private void CreatePrefab(ModelLayerInfo layerInfo, GameObject modelGameObject, string objectName)
        {
            string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;

            AssetDirs.CreateAssetDirectory(rootAssetsDir);

            string prefabPath = rootAssetsDir + "/" + objectName + ".prefab";

            AssetPaths.Add(prefabPath);
            PrefabUtility.SaveAsPrefabAsset(modelGameObject, prefabPath);
        }
Beispiel #3
0
        // Saves imported model to a Unity-friendly files, to be put in AssetBundles.
        private void SaveFilesForExport(ModelLayerInfo layerInfo, string objectName, Mesh modelMesh, GameObject modelGameObject)
        {
            string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;

            AssetDirs.CreateAssetDirectory(rootAssetsDir);

            string meshPath = rootAssetsDir + "/" + objectName + ".asset";

            AssetPaths.Add(meshPath);
            AssetDatabase.CreateAsset(modelMesh, meshPath);

            string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab";

            AssetPaths.Add(gameObjectPath);
            PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath);

            if (layerInfo.UseAsIcon)
            {
                PrepareForPreview(modelGameObject);
                LayerAutomaticIconGenerate(modelGameObject);
            }
        }
        // Saves imported model to a Unity-friendly files, to be put in AssetBundles.
        private void SaveFilesForExport(GameObject modelGameObject, ModelLayerInfo layerInfo, string objectName)
        {
            string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;

            AssetDirs.CreateAssetDirectory(rootAssetsDir);

            Mesh   modelMesh = modelGameObject.GetComponent <MeshFilter>().mesh;
            string meshPath  = rootAssetsDir + "/" + objectName + ".asset";

            AssetPaths.Add(meshPath);
            AssetDatabase.CreateAsset(modelMesh, meshPath);

            string rawDataPath = layerInfo.Directory + @"\" + "data.raw";
            // This is strange to copy data first as Asset then copy asset to build dir
            string tmpDataPath = rootAssetsDir + "/tmp_data.bytes";
            string dataPath    = rootAssetsDir + "/" + objectName + "_data.bytes";

            if (File.Exists(tmpDataPath))
            {
                FileUtil.DeleteFileOrDirectory(tmpDataPath);
            }
            FileUtil.CopyFileOrDirectory(rawDataPath, tmpDataPath);
            AssetPaths.Add(dataPath);
            AssetDatabase.Refresh();
            AssetDatabase.CopyAsset(tmpDataPath, dataPath);


            string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab";

            AssetPaths.Add(gameObjectPath);
            PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath);

            if (layerInfo.UseAsIcon)
            {
                PrepareForPreview(modelGameObject);
                LayerAutomaticIconGenerate(modelGameObject);
            }
        }
Beispiel #5
0
        public void SetOptions(VFSGroupOption option)
        {
            mOption   = option;
            GroupName = option.GroupName;
            foreach (var path in option.FolderPaths)
            {
                if (!path.EndsWith("/"))
                {
                    string _path = path + "/";
                    FolderPaths.Add(_path);
                    FolderPathsLower.Add(_path.ToLower());
                }
                else
                {
                    FolderPaths.Add(path);
                    FolderPathsLower.Add(path.ToLower());
                }
            }

            foreach (var path in option.AssetPaths)
            {
                AssetPaths.Add(path);
                AssetPathsLower.Add(path.ToLower());
            }

            //忽略子目录,子目录必须是FolderPaths的子目录,这里初始化的时候过滤一下无效的配置,节省后面的运算
            foreach (var path in option.IgnoreSubPath)
            {
                string _path      = (path.EndsWith("/")) ? path : path + "/";
                string path_lower = _path.ToLower();
                foreach (var folder in FolderPathsLower)
                {
                    if (VFSUtil.IsSubpath(path_lower, folder, false))
                    {
                        IgnoreSubpath.Add(_path);
                        IgnoreSubpathLower.Add(path_lower);
                        break;
                    }
                }
            }

            //忽略后缀名
            foreach (var ext in option.IngnoreExtName)
            {
                IgnoreExtensionLower.Add(ext.StartsWith(".") ? ext.ToLower() : "." + ext.ToLower());
            }

            //特殊打包规则
            foreach (var rule in option.FolderSpecialBuildRules)
            {
                bool flag = true;
                if (rule.DevType == FolderBuildDevelopType.normal && rule.BuildType == FolderBuildType.normal)
                {
                    flag = false;//这是条没必要的规则
                }
                if (rule.FolderPath.IsNullOrEmpty() || rule.FolderPath.IsNullOrWhiteSpace())
                {
                    flag = false;
                }

                string _folder_path  = (rule.FolderPath.EndsWith("/")) ? rule.FolderPath : rule.FolderPath + "/";
                string _folder_lower = _folder_path.ToLower();

                if (!IsSubfolderOfFolderList(_folder_path))
                {
                    flag = false;
                }

                if (flag)
                {
                    var _rule = rule;
                    _rule.FolderPath = _folder_path;
                    var lower_rule = rule;
                    lower_rule.FolderPath = _folder_lower;
                    SpecialFolderBuildRules.Add(_rule);
                    SpecialFolderBuildRulesLower.Add(lower_rule);
                }
            }
        }