Exemple #1
0
        public string BuildUrl(string assetBundlePath)
        {
            var platformName = UnityPathUtility.GetPlatformName();
            var assetFolder  = AssetBundlesFolder;

            return(PathUtility.Combine(new string[] { remoteUrl, platformName, assetFolder, assetBundlePath }) + PackageExtension);
        }
Exemple #2
0
        public static T Generate <T>(string assetPath = null, bool log = true) where T : ScriptableObject
        {
            assetPath = Path.ChangeExtension(string.IsNullOrEmpty(assetPath) ? DefaultAssetPath : assetPath, AssetFileExtension);

            var instance = AssetDatabase.LoadAssetAtPath <T>(assetPath);

            if (instance == null)
            {
                var projectPath = UnityPathUtility.ConvertProjectPath(assetPath);
                var path        = PathUtility.Combine(Application.dataPath, projectPath);

                if (!File.Exists(path))
                {
                    AssetDatabase.CreateAsset(CreateInstance <T>(), assetPath);
                    AssetDatabase.SaveAssets();

                    instance = AssetDatabase.LoadAssetAtPath <T>(assetPath);

                    if (log)
                    {
                        Debug.Log(string.Format("Generate: {0}", assetPath));
                    }
                }
            }

            return(instance);
        }
        /// <summary>
        /// CriAssetをアセットバンドルの出力先にコピー.
        /// </summary>
        /// <param name="exportPath"></param>
        /// <param name="externalResourcesPath"></param>
        private static void CopyCriManagedFiles(string exportPath, string externalResourcesPath)
        {
            var assetPaths = AssetDatabase.FindAssets(string.Empty, new string[] { externalResourcesPath })
                             .Select(x => AssetDatabase.GUIDToAssetPath(x))
                             .ToArray();

            foreach (var assetPath in assetPaths)
            {
                var path = assetPath.Replace(externalResourcesPath, string.Empty);

                var source = PathUtility.Combine(UnityPathUtility.GetProjectFolderPath(), assetPath);
                var dest   = PathUtility.Combine(new string[] { exportPath, CriAssetDefinition.CriAssetFolder, path });

                if (PathUtility.GetFilePathType(source) == PathUtility.FilePathType.File)
                {
                    var extension = Path.GetExtension(source);

                    if (CriAssetDefinition.AssetAllExtensions.Contains(extension))
                    {
                        var directory = Path.GetDirectoryName(dest);

                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }

                        File.Copy(source, dest, true);
                    }
                }
            }
        }
        //----- method -----

        private static T GetInstance()
        {
            if (instance == null)
            {
                instance = LoadInstance();
            }

            if (instance == null)
            {
                return(null);
            }

            var assetPath = AssetDatabase.GetAssetPath(instance);
            var path      = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

            var time = File.GetLastWriteTime(path);

            var update = !instance.lastWriteTime.HasValue || instance.lastWriteTime.Value != time;

            if (update)
            {
                if (onReload != null)
                {
                    onReload.OnNext(Unit.Default);
                }

                instance = LoadInstance();
                instance.lastWriteTime = time;
            }

            return(instance);
        }
            public CriAssetInstall(AssetInfo assetInfo, IProgress <float> progress = null)
            {
                AssetInfo = assetInfo;

                var resourcePath = UnityPathUtility.GetLocalPath(assetInfo.ResourcesPath, Instance.sourceDir);

                var downloadUrl = Instance.BuildUrl(resourcePath);
                var installPath = Instance.BuildFilePath(resourcePath);

                var directory = Path.GetDirectoryName(installPath);

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                if (File.Exists(installPath))
                {
                    File.Delete(installPath);
                }

                Task = Observable.FromMicroCoroutine(() => Install(downloadUrl, installPath, progress))
                       .Select(_ => this)
                       .Share();
            }
        private static Object GenerateScriptableObject(Type type, string assetPath)
        {
            assetPath = Path.ChangeExtension(assetPath, AssetFileExtension);

            var instance = AssetDatabase.LoadAssetAtPath(assetPath, type);

            if (instance == null)
            {
                var projectPath = UnityPathUtility.ConvertProjectPath(assetPath);
                var path        = PathUtility.Combine(Application.dataPath, projectPath);

                if (!File.Exists(path))
                {
                    instance = CreateInstance(type);

                    AssetDatabase.CreateAsset(instance, assetPath);

                    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }

            return(instance);
        }
Exemple #7
0
        private void LoadCueInfo(UnityEngine.Object acbAsset)
        {
            cueInfos = new List <CueInfo>();

            // 指定したACBファイル名(キューシート名)を指定してキュー情報を取得.
            var assetPath = AssetDatabase.GetAssetPath(acbAsset);
            var fullPath  = UnityPathUtility.GetProjectFolderPath() + assetPath;
            var acb       = CriAtomExAcb.LoadAcbFile(null, fullPath, "");

            if (acb != null)
            {
                var list = acb.GetCueInfoList();

                foreach (var item in list)
                {
                    var path = PathUtility.GetPathWithoutExtension(assetPath);

                    var cueInfo = new CueInfo(string.Empty, path, item.name, item.userData);

                    cueInfos.Add(cueInfo);
                }

                acb.Dispose();
            }
        }
Exemple #8
0
        private void CalcPerformance(DicingTexture dicingTexture)
        {
            calcPerformance = false;

            if (dicingTexture != null)
            {
                var assetPath = AssetDatabase.GetAssetPath(dicingTexture);
                var fullPath  = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                var fileInfo = new FileInfo(fullPath);

                infoFileSize = (float)fileInfo.Length / MB;
            }
            else
            {
                return;
            }

            var textures = dicingTexture.GetAllDicingSource()
                           .Select(x => AssetDatabase.GUIDToAssetPath(x.guid))
                           .Select(x => AssetDatabase.LoadMainAssetAtPath(x) as Texture2D)
                           .Where(x => x != null)
                           .ToArray();

            // 消費メモリサイズを計測.
            totalMemSize = 0;
            textures.ForEach(x =>
            {
                var mem       = Mathf.NextPowerOfTwo(x.width) * Mathf.NextPowerOfTwo(x.height);
                mem          *= !x.alphaIsTransparency ? 3 : 4;
                totalMemSize += mem;
            });
            totalMemSize /= MB;

            if (dicingTexture.Texture != null)
            {
                var mem = Mathf.NextPowerOfTwo(dicingTexture.Texture.width) * Mathf.NextPowerOfTwo(dicingTexture.Texture.height);
                mem *= !dicingTexture.Texture.alphaIsTransparency ? 3 : 4;
                totalAtlasMemSize = (float)mem / MB;
            }

            // ファイルサイズ.
            totalFileSize = 0f;
            textures.Select(x => AssetDatabase.GetAssetPath(x))
            .Select(x => UnityPathUtility.ConvertAssetPathToFullPath(x))
            .Select(x => new FileInfo(x))
            .ForEach(x => totalFileSize += (float)x.Length / MB);

            if (dicingTexture.Texture != null)
            {
                var assetPath = AssetDatabase.GetAssetPath(dicingTexture.Texture);
                var fullPath  = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                var fileInfo = new FileInfo(fullPath);

                atlasFileSize = (float)fileInfo.Length / MB;
            }

            calcPerformance = true;
        }
        public string BuildUrl(string assetPath)
        {
            var platformName = UnityPathUtility.GetPlatformName();
            var assetFolder  = CriAssetDefinition.CriAssetFolder;

            return(PathUtility.Combine(new string[] { remoteUrl, platformName, assetFolder, assetPath }));
        }
Exemple #10
0
        private static Object GenerateScriptableObject(Type type, string assetPath)
        {
            assetPath = Path.ChangeExtension(assetPath, AssetFileExtension);

            var instance = AssetDatabase.LoadAssetAtPath(assetPath, type);

            if (instance == null)
            {
                var path = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                if (!File.Exists(path))
                {
                    instance = CreateInstance(type);

                    var directory = Path.GetDirectoryName(path);

                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    AssetDatabase.CreateAsset(instance, assetPath);

                    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }

            return(instance);
        }
        // 元になったテクスチャ情報構築.
        private DicingSourceData[] BuildDicingSourceData(DicingTargetData[] targetDatas)
        {
            var result = new List <DicingSourceData>();

            foreach (var targetData in targetDatas)
            {
                var texture   = targetData.texture;
                var assetPath = AssetDatabase.GetAssetPath(texture);
                var fullPath  = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                var item = new DicingSourceData()
                {
                    textureName = Path.GetFileNameWithoutExtension(assetPath),
                    guid        = AssetDatabase.AssetPathToGUID(assetPath),
                    lastUpdate  = File.GetLastWriteTime(fullPath).ToUnixTime(),
                    width       = texture.width,
                    height      = texture.height,
                    xblock      = targetData.bx,
                    yblock      = targetData.by,
                    blockIds    = targetData.blocks.Select(x => x.blockId).ToArray(),
                };

                result.Add(item);
            }

            return(result.ToArray());
        }
Exemple #12
0
        public void Dont_Create_CustomFile_If_File_Exist(UnityFileUtility.FileType fileType)
        {
            var extension      = UnityFileUtility.GetExtension(fileType);
            var cSharpFullPath = UnityPathUtility.GetCsharpUnityAbsoluteFullPath(_childPath, _fileName, extension);

            Assert.AreEqual(true, NotCreateWhenFileExist(fileType, cSharpFullPath));
            ShouldFileInPath(true, fileType);
        }
        public static void GetUnityFullPath()
        {
            var extension = "overrideController";
            var expected  = $"Assets/{_childPath}/{_fileName}.{extension}";

            ShouldEqualResult(expected,
                              UnityPathUtility.GetUnityFullPath(_childPath, _fileName, extension));
        }
Exemple #14
0
        //----- method -----

        protected override void OnCreate()
        {
            filePathCache = new Dictionary <Type, string>();
            dataCache     = new Dictionary <Type, ILocalData>();

            var fileDir = UnityPathUtility.GetPrivateDataPath();

            FileDirectory = fileDir + "/LocalData/";
        }
Exemple #15
0
        public void Load(string assetPath)
        {
            var asset = Resources.Load <GameTextAsset>(UnityPathUtility.ConvertResourcesLoadPath(assetPath));

            if (asset != null)
            {
                Cache = asset.contents.ToDictionary(x => x.SheetId);
            }
        }
Exemple #16
0
        private static void DeleteCriAsset(string sourceFolderPath, string assetFolderPath)
        {
            if (string.IsNullOrEmpty(sourceFolderPath) || string.IsNullOrEmpty(assetFolderPath))
            {
                Debug.LogError("DeleteCriAsset Error.");
                return;
            }

            sourceFolderPath += PathUtility.PathSeparator;
            assetFolderPath   = PathUtility.Combine(UnityPathUtility.GetProjectFolderPath(), assetFolderPath) + PathUtility.PathSeparator;

            if (!Directory.Exists(assetFolderPath))
            {
                return;
            }

            var files = Directory.GetFiles(assetFolderPath, "*", SearchOption.AllDirectories);

            var deleteTargets = files
                                .Where(x => Path.GetExtension(x) != ".meta")
                                .Select(x => Tuple.Create(x, x.Replace(assetFolderPath, sourceFolderPath)))
                                .Where(x => !File.Exists(x.Item2))
                                .ToArray();

            if (deleteTargets.Any())
            {
                var builder = new StringBuilder();

                deleteTargets.ForEach(x => builder.AppendLine(x.Item1.ToString()));

                if (!EditorUtility.DisplayDialog("Delete Confirmation", builder.ToString(), "実行", "中止"))
                {
                    return;
                }

                for (var i = 0; i < deleteTargets.Length; i++)
                {
                    var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(deleteTargets[i].Item1);

                    AssetDatabase.DeleteAsset(assetPath);
                }

                Debug.LogFormat("Delete CriAssets:\n{0}", builder.ToString());
            }

            var deleteDirectorys = DirectoryUtility.DeleteEmpty(assetFolderPath);

            if (deleteDirectorys.Any())
            {
                var builder = new StringBuilder();
                deleteDirectorys.ForEach(x => builder.AppendLine(x));

                Debug.LogFormat("Delete Empty Directory:\n{0}", builder.ToString());
            }
        }
Exemple #17
0
        public long GetFileSize()
        {
            if (!fileSize.HasValue)
            {
                var filePath = UnityPathUtility.ConvertAssetPathToFullPath(AssetPath);

                fileSize = File.Exists(filePath) ? new FileInfo(filePath).Length : 0;
            }

            return(fileSize.Value);
        }
Exemple #18
0
        private string ConvertCriFilePath(string resourcesPath)
        {
            if (string.IsNullOrEmpty(resourcesPath))
            {
                return(null);
            }

            return(isSimulate ?
                   PathUtility.Combine(new string[] { UnityPathUtility.GetProjectFolderPath(), resourceDir, resourcesPath }) :
                   PathUtility.Combine(new string[] { criAssetManager.BuildFilePath(null), resourcesPath }));
        }
Exemple #19
0
 public void SetUp()
 {
     _childPath           = "QWERT";
     _fileName            = "WEjhdfjgh";
     _unityFullFolderPath = $@"{Application.dataPath}\{_childPath}";
     _presetChildPath     = "Test111";
     _presetFileName      = "asdfeedd";
     _pngFullPath         = UnityPathUtility.GetUnityFullPath(_childPath, _fileName, _pngExtension);
     _presetFullPath      = UnityPathUtility.GetUnityFullPath(_presetChildPath, _presetFileName, _presetExtension);
     _mainTexFullPath     = UnityPathUtility.GetUnityFullPath(_childPath, _mainTexFileName, _pngExtension);
 }
Exemple #20
0
        private void SetSecondaryPaths()
        {
            var texturesCount = _secTextureNameList.Length;

            for (var i = 0; i < texturesCount; i++)
            {
                var secTextureFileName = $"secTex{i}";
                UnityFileUtility.CreateTestPng(_childPath, secTextureFileName, TextureColor.white);
                var secTexFullPath = UnityPathUtility.GetUnityFullPath(_childPath, secTextureFileName, _pngExtension);
                _secondaryAssetPaths[i] = secTexFullPath;
            }
        }
Exemple #21
0
        private static bool ImportCriAsset(string sourceFolderPath, string assetFolderPath, string[] assetExtensions)
        {
            if (string.IsNullOrEmpty(sourceFolderPath) || string.IsNullOrEmpty(assetFolderPath))
            {
                Debug.LogError("ImportCriAsset Error.");
                return(false);
            }

            sourceFolderPath += PathUtility.PathSeparator;
            assetFolderPath   = PathUtility.Combine(UnityPathUtility.GetProjectFolderPath(), assetFolderPath) + PathUtility.PathSeparator;

            if (!Directory.Exists(sourceFolderPath))
            {
                Debug.LogWarningFormat("Path Notfound. {0}", sourceFolderPath);
                return(false);
            }

            var files = Directory.GetFiles(sourceFolderPath, "*", SearchOption.AllDirectories);

            var copyTargets = files
                              .Where(x => assetExtensions.Contains(Path.GetExtension(x)))
                              .Select(x => Tuple.Create(x, PathUtility.Combine(assetFolderPath, x.Replace(sourceFolderPath, string.Empty))))
                              .ToArray();

            if (copyTargets.Any())
            {
                var copyCount = 0;

                var log = new StringBuilder();
                log.AppendLine("Copy MovieAssets:");

                for (var i = 0; i < copyTargets.Length; i++)
                {
                    if (FileCopy(copyTargets[i].Item1, copyTargets[i].Item2))
                    {
                        var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(copyTargets[i].Item2);

                        AssetDatabase.ImportAsset(assetPath);

                        log.AppendLine(assetPath);
                        copyCount++;
                    }
                }

                if (0 < copyCount)
                {
                    Debug.Log(log.ToString());
                }
            }

            return(true);
        }
Exemple #22
0
        private string ConvertCriFilePath(string resourcePath)
        {
            if (string.IsNullOrEmpty(resourcePath))
            {
                return(null);
            }

            var assetInfo = GetAssetInfo(resourcePath);

            return(simulateMode ?
                   PathUtility.Combine(new string[] { UnityPathUtility.GetProjectFolderPath(), resourceDir, resourcePath }) :
                   criAssetManager.BuildFilePath(assetInfo));
        }
Exemple #23
0
        public string GetImportFolderPath()
        {
            if (string.IsNullOrEmpty(importFolderPath))
            {
                return(null);
            }

            var projectFolder = UnityPathUtility.GetProjectFolderPath();

            var workspacePath = PathUtility.RelativePathToFullPath(projectFolder, importFolderPath);

            return(workspacePath);
        }
Exemple #24
0
        private string GetFullPath(string relativePath)
        {
            var projectFolder = UnityPathUtility.GetProjectFolderPath();

            var origin = Environment.CurrentDirectory;

            Environment.CurrentDirectory = projectFolder;

            var path = Path.GetFullPath(relativePath);

            Environment.CurrentDirectory = origin;

            return(path);
        }
        public string BuildFilePath(string assetPath)
        {
            var installPath = UnityPathUtility.GetInstallPath();
            var assetFolder = CriAssetDefinition.CriAssetFolder;

            var path = PathUtility.Combine(installPath, assetFolder);

            if (!string.IsNullOrEmpty(assetPath))
            {
                path = PathUtility.Combine(path, assetPath);
            }

            return(path);
        }
Exemple #26
0
        private static void ImportGeneratedCsFile(string csFilePath, string csFileHash)
        {
            var assetPath = UnityPathUtility.ConvertFullPathToAssetPath(csFilePath);

            var hash = GetCsFileHash(csFilePath);

            if (File.Exists(csFilePath))
            {
                if (csFileHash != hash)
                {
                    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                }
            }
        }
Exemple #27
0
        public string BuildFilePath(string assetBundleName)
        {
            var installPath = UnityPathUtility.GetInstallPath();
            var assetFolder = AssetBundlesFolder;

            var path = PathUtility.Combine(installPath, assetFolder);

            if (!string.IsNullOrEmpty(assetBundleName))
            {
                path = PathUtility.Combine(path, assetBundleName) + PackageExtension;
            }

            return(path);
        }
Exemple #28
0
        public void DeleteInvalidInfo()
        {
            var list = new List <ManageInfo>();

            for (var i = 0; i < manageInfos.Length; i++)
            {
                var manageInfo = manageInfos[i];

                if (manageInfo == null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(manageInfo.guid))
                {
                    continue;
                }

                var assetPath = AssetDatabase.GUIDToAssetPath(manageInfo.guid);

                var path = UnityPathUtility.ConvertAssetPathToFullPath(assetPath);

                var isFolder = AssetDatabase.IsValidFolder(assetPath);

                if (isFolder)
                {
                    if (!Directory.Exists(path))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!File.Exists(path))
                    {
                        continue;
                    }
                }

                list.Add(manageInfo);
            }

            if (list.Count != manageInfos.Length)
            {
                manageInfos = list.ToArray();

                UnityEditorUtility.SaveAsset(this);
            }
        }
        private static string GetExportPath()
        {
            var directory  = string.IsNullOrEmpty(Prefs.exportPath) ? null : Path.GetDirectoryName(Prefs.exportPath);
            var folderName = string.IsNullOrEmpty(Prefs.exportPath) ? ExportFolderName : Path.GetFileName(Prefs.exportPath);

            var path = EditorUtility.OpenFolderPanel("Select export folder.", directory, folderName);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            Prefs.exportPath = path;

            return(PathUtility.Combine(path, UnityPathUtility.GetPlatformName()) + PathUtility.PathSeparator);
        }
Exemple #30
0
        //----- field -----

        //----- property -----

        //----- method -----

        public static string GetAssetBundleOutputPath()
        {
            var projectPath  = UnityPathUtility.GetProjectFolderPath();
            var platformName = UnityPathUtility.GetPlatformName();

            var paths = new string[] { projectPath, UnityPathUtility.LibraryFolder, AssetBundleCacheFolder, platformName };

            var assetBundlePath = PathUtility.Combine(paths);

            if (!Directory.Exists(assetBundlePath))
            {
                Directory.CreateDirectory(assetBundlePath);
            }

            return(assetBundlePath);
        }