You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-15 04:30:09 +00:00
3.0.0-preview.37
# [3.0.0-preview.37](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.36...v3.0.0-preview.37) (2020-10-01)
### Bug Fixes
* fix menus ([5fa12b5](5fa12b5338))
This commit is contained in:
@@ -4,67 +4,76 @@ using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
|
||||
static class ImportSampleMenu_UIParticle
|
||||
namespace Coffee.UIExtensions
|
||||
{
|
||||
private const string k_DisplayName = "UI Particle";
|
||||
private const string k_JsonGuid = "823dc693d087a4b559c7e1547274cc7d";
|
||||
|
||||
[MenuItem("Assets/Samples/" + k_DisplayName + "/Import Demo")]
|
||||
private static void ImportDemo()
|
||||
internal static class ImportSampleMenu_UIParticle
|
||||
{
|
||||
ImportSample(k_JsonGuid, "Demo");
|
||||
}
|
||||
private const string k_DisplayName = "UI Particle";
|
||||
private const string k_JsonGuid = "823dc693d087a4b559c7e1547274cc7d";
|
||||
|
||||
private static void ImportSample(string jsonGuid, string sampleName)
|
||||
{
|
||||
var jsonPath = AssetDatabase.GUIDToAssetPath(jsonGuid);
|
||||
var packageRoot = Path.GetDirectoryName(jsonPath).Replace('\\', '/');
|
||||
var json = File.ReadAllText(jsonPath);
|
||||
var version = Regex.Match(json, "\"version\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value;
|
||||
var src = string.Format("{0}/Samples~/{1}", packageRoot, sampleName);
|
||||
var dst = string.Format("Assets/Samples/{0}/{1}/{2}", k_DisplayName, version, sampleName);
|
||||
var previousPath = GetPreviousSamplePath(k_DisplayName, sampleName);
|
||||
|
||||
// Remove the previous sample directory.
|
||||
if (!string.IsNullOrEmpty(previousPath))
|
||||
[MenuItem("Assets/Samples/" + k_DisplayName + "/Demo")]
|
||||
private static void ImportSample()
|
||||
{
|
||||
var msg = "A different version of the sample is already imported at\n\n"
|
||||
+ previousPath
|
||||
+ "\n\nIt will be deleted when you update. Are you sure you want to continue?";
|
||||
if (!EditorUtility.DisplayDialog("Sample Importer", msg, "OK", "Cancel"))
|
||||
return;
|
||||
|
||||
FileUtil.DeleteFileOrDirectory(previousPath);
|
||||
|
||||
var metaFile = previousPath + ".meta";
|
||||
if (File.Exists(metaFile))
|
||||
FileUtil.DeleteFileOrDirectory(metaFile);
|
||||
ImportSample(k_JsonGuid, "Demo");
|
||||
}
|
||||
|
||||
if (!Directory.Exists(dst))
|
||||
FileUtil.DeleteFileOrDirectory(dst);
|
||||
[MenuItem("Assets/Samples/" + k_DisplayName + "/Cartoon FX & War FX Demo")]
|
||||
private static void ImportSample_CFX()
|
||||
{
|
||||
ImportSample(k_JsonGuid, "Cartoon FX & War FX Demo");
|
||||
}
|
||||
|
||||
var dstDir = Path.GetDirectoryName(dst);
|
||||
if (!Directory.Exists(dstDir))
|
||||
Directory.CreateDirectory(dstDir);
|
||||
private static void ImportSample(string jsonGuid, string sampleName)
|
||||
{
|
||||
var jsonPath = AssetDatabase.GUIDToAssetPath(jsonGuid);
|
||||
var packageRoot = Path.GetDirectoryName(jsonPath).Replace('\\', '/');
|
||||
var json = File.ReadAllText(jsonPath);
|
||||
var version = Regex.Match(json, "\"version\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value;
|
||||
var src = string.Format("{0}/Samples~/{1}", packageRoot, sampleName);
|
||||
var dst = string.Format("Assets/Samples/{0}/{1}/{2}", k_DisplayName, version, sampleName);
|
||||
var previousPath = GetPreviousSamplePath(k_DisplayName, sampleName);
|
||||
|
||||
if (Directory.Exists(src))
|
||||
FileUtil.CopyFileOrDirectory(src, dst);
|
||||
else
|
||||
throw new DirectoryNotFoundException(src);
|
||||
// Remove the previous sample directory.
|
||||
if (!string.IsNullOrEmpty(previousPath))
|
||||
{
|
||||
var msg = "A different version of the sample is already imported at\n\n"
|
||||
+ previousPath
|
||||
+ "\n\nIt will be deleted when you update. Are you sure you want to continue?";
|
||||
if (!EditorUtility.DisplayDialog("Sample Importer", msg, "OK", "Cancel"))
|
||||
return;
|
||||
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
|
||||
}
|
||||
FileUtil.DeleteFileOrDirectory(previousPath);
|
||||
|
||||
private static string GetPreviousSamplePath(string displayName, string sampleName)
|
||||
{
|
||||
var sampleRoot = string.Format("Assets/Samples/{0}", displayName);
|
||||
var sampleRootInfo = new DirectoryInfo(sampleRoot);
|
||||
if (!sampleRootInfo.Exists) return null;
|
||||
var metaFile = previousPath + ".meta";
|
||||
if (File.Exists(metaFile))
|
||||
FileUtil.DeleteFileOrDirectory(metaFile);
|
||||
}
|
||||
|
||||
return sampleRootInfo.GetDirectories()
|
||||
.Select(versionDir => Path.Combine(versionDir.ToString(), sampleName))
|
||||
.FirstOrDefault(Directory.Exists);
|
||||
if (!Directory.Exists(dst))
|
||||
FileUtil.DeleteFileOrDirectory(dst);
|
||||
|
||||
var dstDir = Path.GetDirectoryName(dst);
|
||||
if (!Directory.Exists(dstDir))
|
||||
Directory.CreateDirectory(dstDir);
|
||||
|
||||
if (Directory.Exists(src))
|
||||
FileUtil.CopyFileOrDirectory(src, dst);
|
||||
else
|
||||
throw new DirectoryNotFoundException(src);
|
||||
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
|
||||
}
|
||||
|
||||
private static string GetPreviousSamplePath(string displayName, string sampleName)
|
||||
{
|
||||
var sampleRoot = string.Format("Assets/Samples/{0}", displayName);
|
||||
var sampleRootInfo = new DirectoryInfo(sampleRoot);
|
||||
if (!sampleRootInfo.Exists) return null;
|
||||
|
||||
return sampleRootInfo.GetDirectories()
|
||||
.Select(versionDir => Path.Combine(versionDir.ToString(), sampleName))
|
||||
.FirstOrDefault(Directory.Exists);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user