You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-14 20:20:06 +00:00
3.0.0-preview.7
# [3.0.0-preview.7](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.6...v3.0.0-preview.7) (2020-03-02) ### Bug Fixes * add package keywords ([49d8f3f](49d8f3fe4c)) * fix sample path ([57ee210](57ee21005e))
This commit is contained in:
@@ -2,41 +2,59 @@
|
||||
#if !UNITY_2019_1_OR_NEWER
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Coffee.UIExtensions
|
||||
{
|
||||
public class UIParticleMenu
|
||||
{
|
||||
[MenuItem("Assets/Samples/Import UIParticle Sample")]
|
||||
static void ImportSample()
|
||||
static string GetPreviousSamplePath(string displayName, string sampleName)
|
||||
{
|
||||
const string sampleGuid = "dc0fe9e7fe61947fab1522ab29e2fc88";
|
||||
const string jsonGuid = "823dc693d087a4b559c7e1547274cc7d";
|
||||
const string SAMPLE_NAME = "Demo";
|
||||
string sampleRoot = $"Assets/Samples/{displayName}";
|
||||
var sampleRootInfo = new DirectoryInfo(sampleRoot);
|
||||
if (!sampleRootInfo.Exists) return null;
|
||||
|
||||
string jsonPath = AssetDatabase.GUIDToAssetPath(jsonGuid);
|
||||
foreach (var versionDir in sampleRootInfo.GetDirectories())
|
||||
{
|
||||
var samplePath = Path.Combine(versionDir.ToString(), sampleName);
|
||||
if (Directory.Exists(samplePath))
|
||||
return samplePath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static void ImportSample(string packageName, string sampleName)
|
||||
{
|
||||
string jsonPath = $"Packages/{packageName}/package.json";
|
||||
string json = File.ReadAllText(jsonPath);
|
||||
string version = Regex.Match(json, "\"version\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value;
|
||||
string displayName = Regex.Match(json, "\"displayName\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value;
|
||||
string src = Path.GetDirectoryName(jsonPath) + "/Samples~/" + SAMPLE_NAME;
|
||||
string dst = string.Format("Assets/Samples/{0}/{1}/{2}",displayName, version, SAMPLE_NAME);
|
||||
string src = $"{Path.GetDirectoryName(jsonPath)}/Samples~/{sampleName}";
|
||||
string dst = $"Assets/Samples/{displayName}/{version}/{sampleName}";
|
||||
string previous = GetPreviousSamplePath(displayName, sampleName);
|
||||
|
||||
// Remove old samples
|
||||
string samplePath = AssetDatabase.GUIDToAssetPath(sampleGuid);
|
||||
if (samplePath.StartsWith("Assets/") && FileUtil.PathExists(samplePath))
|
||||
if (!string.IsNullOrEmpty(previous))
|
||||
{
|
||||
FileUtil.DeleteFileOrDirectory(samplePath);
|
||||
FileUtil.DeleteFileOrDirectory(samplePath + ".meta");
|
||||
string msg = "A different version of the sample is already imported at\n\n"
|
||||
+ previous
|
||||
+ "\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(previous);
|
||||
FileUtil.DeleteFileOrDirectory(previous + ".meta");
|
||||
}
|
||||
|
||||
FileUtil.CopyDirectoryRecursive(src, dst);
|
||||
FileUtil.CopyFileOrDirectory(src + ".meta", dst + ".meta");
|
||||
AssetDatabase.ImportAsset(dst, ImportAssetOptions.ImportRecursive);
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Samples/Import UIParticle Sample")]
|
||||
static void ImportSample()
|
||||
{
|
||||
ImportSample("com.coffee.ui-particle", "Demo");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user