From ed18032be43397debbd538cae258c226ebeeb2e9 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 21 Feb 2020 21:07:45 +0900 Subject: [PATCH] fix: sample version --- .../Scripts/Editor/UIParticleMenu.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Packages/UIParticle/Scripts/Editor/UIParticleMenu.cs b/Packages/UIParticle/Scripts/Editor/UIParticleMenu.cs index 8b12fbb..286614c 100644 --- a/Packages/UIParticle/Scripts/Editor/UIParticleMenu.cs +++ b/Packages/UIParticle/Scripts/Editor/UIParticleMenu.cs @@ -1,5 +1,7 @@ #if IGNORE_ACCESS_CHECKS // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY. #if !UNITY_2019_1_OR_NEWER +using System.IO; +using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -12,13 +14,27 @@ public class UIParticleMenu [MenuItem("Assets/Samples/Import UIParticle Sample")] static void ImportSample() { - const string src = "Packages/com.coffee.ui-particle/Samples~/Demo"; - const string dst = "Assets/Samples/UI Particle/3.0.0/Demo"; + const string sampleGuid = "dc0fe9e7fe61947fab1522ab29e2fc88"; + const string jsonGuid = "823dc693d087a4b559c7e1547274cc7d"; + const string SAMPLE_NAME = "Demo"; - if (FileUtil.PathExists(dst)) - FileUtil.DeleteFileOrDirectory(dst); + string jsonPath = AssetDatabase.GUIDToAssetPath(jsonGuid); + 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); + + // Remove old samples + string samplePath = AssetDatabase.GUIDToAssetPath(sampleGuid); + if (samplePath.StartsWith("Assets/") && FileUtil.PathExists(samplePath)) + { + FileUtil.DeleteFileOrDirectory(samplePath); + FileUtil.DeleteFileOrDirectory(samplePath + ".meta"); + } FileUtil.CopyDirectoryRecursive(src, dst); + FileUtil.CopyFileOrDirectory(src + ".meta", dst + ".meta"); AssetDatabase.ImportAsset(dst, ImportAssetOptions.ImportRecursive); } }