Пример #1
0
        AssetList AssetOperations.IAssetSelection.GetSelectedAssets()
        {
            AssetList result = new AssetList();

            foreach (UnityEngine.Object obj in UnityEditor.Selection.objects)
            {
                result.Add(new Asset(AssetPath.GetFullPath(obj)));
            }

            return(result);
        }
Пример #2
0
        private bool ChangeStorageFolder(string proposedFolder)
        {
            if (string.Equals(proposedFolder, _storagePath, StringComparison.OrdinalIgnoreCase) || !AssetPath.IsProjectPath(proposedFolder))
            {
                return(false);
            }

            proposedFolder = AssetPath.ProjectRelativePath(proposedFolder);
            bool apexified = proposedFolder.EndsWith("Resources/" + AIManager.StorageFolder);

            if (!proposedFolder.EndsWith("Resources") && !apexified)
            {
                EditorUtility.DisplayDialog("Invalid Storage Folder", "The storage folder selected must be a Resources folder. This can however be anywhere inside the Assets folder.", "Ok");
                return(false);
            }

            if (!apexified)
            {
                proposedFolder = AssetPath.Combine(proposedFolder, AIManager.StorageFolder);
            }

            AssetPath.EnsurePath(proposedFolder);

            //Move files from current storage location to new location.
            var fullStoragePath = AssetPath.GetFullPath(_storagePath);

            if (Directory.Exists(fullStoragePath))
            {
                foreach (var asset in Directory.GetFiles(fullStoragePath, "*.asset", SearchOption.TopDirectoryOnly))
                {
                    var fileName = Path.GetFileName(asset);
                    var msg      = AssetDatabase.MoveAsset(AssetPath.ProjectRelativePath(asset), AssetPath.Combine(proposedFolder, fileName));
                    if (!string.IsNullOrEmpty(msg))
                    {
                        EditorUtility.DisplayDialog("Error Moving Assets", msg, "Ok");
                        return(false);
                    }
                }

                AssetDatabase.DeleteAsset(_storagePath);
            }

            _storagePath = proposedFolder;

            return(true);
        }
Пример #3
0
    public virtual IEnumerator LoadAsync()
    {
#if UNITY_EDITOR
        if (AssetPath.mode == AssetMode.Editor)
        {
            yield break;
        }
#endif
        if (status == LoadStatus.Done)
        {
            yield break;
        }
        else if (status == LoadStatus.Loading)
        {
            yield return(new WaitUntil(() => status >= LoadStatus.Done));
        }
        else
        {
            string path = AssetPath.GetFullPath(bundleName);
            AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path);

            status = LoadStatus.Loading;

            yield return(request);

            status = LoadStatus.Done;

            if (bundle == null)
            {
                if (request.isDone && request.assetBundle)
                {
                    bundle = request.assetBundle;
                }
                else
                {
                    status = LoadStatus.Error;
                    Debug.Log("Can't Load AssetBundle:" + bundleName + "  from :" + path + "!!");
                }
            }
        }
    }
Пример #4
0
        internal static void WriteNameMapFile()
        {
            var targetFolder = AIGeneralSettings.instance.nameMapPath;

            if (string.IsNullOrEmpty(targetFolder))
            {
                targetFolder = AssetPath.GetApexRoot(true);
                AIGeneralSettings.instance.nameMapPath = targetFolder;
                AIGeneralSettings.instance.SaveChanges();
            }

            targetFolder = AssetPath.GetFullPath(targetFolder);
            if (!Directory.Exists(targetFolder))
            {
                Debug.LogWarning("Unable to create name map, please setup a target folder under settings.");
                return;
            }

            var filePath = AssetPath.Combine(targetFolder, AIGeneralSettings.NameMapFileName);

            var b      = new StringBuilder();
            var aiList = StoredAIs.AIs;
            var count  = aiList.count;

            for (int i = 0; i < count; i++)
            {
                var name = correctName(aiList[i].name);
                if (name != null)
                {
                    b.AppendFormat(Template.ItemTemplate, name, aiList[i].aiId);
                    b.AppendLine();
                }
            }

            using (var writer = new StreamWriter(filePath))
            {
                writer.WriteLine(Template.FileTemplate, b);
            }

            AssetDatabase.Refresh();
        }
Пример #5
0
        private bool ChangeNameMapFolder(string proposedFolder)
        {
            if (string.Equals(proposedFolder, _nameMapPath, StringComparison.OrdinalIgnoreCase) || !AssetPath.IsProjectPath(proposedFolder))
            {
                return(false);
            }

            proposedFolder = AssetPath.ProjectRelativePath(proposedFolder);
            AssetPath.EnsurePath(proposedFolder);

            //Move map from current location to new location.
            if (!string.IsNullOrEmpty(_nameMapPath))
            {
                var existingFile = AssetPath.Combine(AssetPath.GetFullPath(_nameMapPath), NameMapFileName);

                if (File.Exists(existingFile))
                {
                    var oldFilePath = AssetPath.Combine(_nameMapPath, NameMapFileName);
                    var newFilePath = AssetPath.Combine(proposedFolder, NameMapFileName);

                    var msg = AssetDatabase.MoveAsset(oldFilePath, newFilePath);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        EditorUtility.DisplayDialog("Error Moving Asset", msg, "Ok");
                        return(false);
                    }
                    else
                    {
                        AssetDatabase.Refresh();
                    }
                }
            }

            _nameMapPath = proposedFolder;

            return(true);
        }