void Restore() { var assetPath = UnityPath.FromAsset(this); if (assetPath.IsNull) { return; } foreach (var x in assetPath.Parent.ChildFiles) { var clip = UnityEditor.AssetDatabase.LoadAssetAtPath <VRM10Expression>(x.Value); if (clip == null) { continue; } if (!Clips.Contains(clip)) { Clips.Add(clip); } Debug.LogFormat("{0}", clip.name); } Clips = Clips.OrderBy(x => ExpressionKey.CreateFromClip(x)).ToList(); }
static VRM10Expression CreateAndSaveExpression(ExpressionPreset preset, string dir) { var clip = ScriptableObject.CreateInstance <VRM10Expression>(); clip.name = preset.ToString(); var path = System.IO.Path.Combine(dir, $"{preset}.asset"); var unityPath = UnityPath.FromFullpath(path); unityPath.CreateAsset(clip); var loaded = unityPath.LoadAsset <VRM10Expression>(); return(loaded); }
protected virtual GameObject GetPrefab() { var assetPath = AssetDatabase.GetAssetPath(target); if (string.IsNullOrEmpty(assetPath)) { return(null); } var mainObject = AssetDatabase.LoadMainAssetAtPath(assetPath); if (mainObject != null) { //return mainObject; } var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath); if (prefab != null) { return(prefab); } var parent = UnityPath.FromUnityPath(assetPath).Parent; var prefabPath = parent.Parent.Child(parent.FileNameWithoutExtension + ".prefab"); prefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath.Value); if (prefab != null) { return(prefab); } var parentParent = UnityPath.FromUnityPath(assetPath).Parent.Parent; var vrmPath = parent.Parent.Child(parent.FileNameWithoutExtension + ".vrm"); prefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(vrmPath.Value); return(prefab); }
static Texture2D SaveResizedImage(RenderTexture rt, UnityPath path, int size) { var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false); RenderTexture.active = rt; tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply(); //TextureScale.Scale(tex, size, size); tex = TextureScale.GetResized(tex, size, size); byte[] bytes; switch (path.Extension.ToLower()) { case ".png": bytes = tex.EncodeToPNG(); break; case ".jpg": bytes = tex.EncodeToJPG(); break; default: throw new Exception(); } if (Application.isPlaying) { UnityEngine.Object.Destroy(tex); } else { UnityEngine.Object.DestroyImmediate(tex); } File.WriteAllBytes(path.FullPath, bytes); path.ImportAsset(); return(path.LoadAsset <Texture2D>()); }
static VRM10Object CreateAsset(string path) { if (string.IsNullOrEmpty(path)) { return(null); } var unityPath = UnityPath.FromFullpath(path); if (!unityPath.IsUnderAssetsFolder) { EditorUtility.DisplayDialog("error", "The specified path is not inside of Assets/", "OK"); return(null); } var asset = ScriptableObject.CreateInstance <VRM10Object>(); unityPath.CreateAsset(asset); var loaded = unityPath.LoadAsset <VRM10Object>(); return(loaded); }
static string ToAssetPath(string path) { var assetPath = UnityPath.FromFullpath(path); return(assetPath.Value); }
static VRM10Object CreateAsset(string path, Dictionary <ExpressionPreset, VRM10Expression> expressions) { if (string.IsNullOrEmpty(path)) { return(null); } var unityPath = UnityPath.FromFullpath(path); if (!unityPath.IsUnderAssetsFolder) { EditorUtility.DisplayDialog("error", "The specified path is not inside of Assets/", "OK"); return(null); } var asset = ScriptableObject.CreateInstance <VRM10Object>(); foreach (var kv in expressions) { switch (kv.Key) { case ExpressionPreset.aa: asset.Expression.Aa = kv.Value; break; case ExpressionPreset.ih: asset.Expression.Ih = kv.Value; break; case ExpressionPreset.ou: asset.Expression.Ou = kv.Value; break; case ExpressionPreset.ee: asset.Expression.Ee = kv.Value; break; case ExpressionPreset.oh: asset.Expression.Oh = kv.Value; break; case ExpressionPreset.happy: asset.Expression.Happy = kv.Value; break; case ExpressionPreset.angry: asset.Expression.Angry = kv.Value; break; case ExpressionPreset.sad: asset.Expression.Sad = kv.Value; break; case ExpressionPreset.relaxed: asset.Expression.Relaxed = kv.Value; break; case ExpressionPreset.surprised: asset.Expression.Surprised = kv.Value; break; case ExpressionPreset.blink: asset.Expression.Blink = kv.Value; break; case ExpressionPreset.blinkLeft: asset.Expression.BlinkLeft = kv.Value; break; case ExpressionPreset.blinkRight: asset.Expression.BlinkRight = kv.Value; break; case ExpressionPreset.lookUp: asset.Expression.LookUp = kv.Value; break; case ExpressionPreset.lookDown: asset.Expression.LookDown = kv.Value; break; case ExpressionPreset.lookLeft: asset.Expression.LookLeft = kv.Value; break; case ExpressionPreset.lookRight: asset.Expression.LookRight = kv.Value; break; case ExpressionPreset.neutral: asset.Expression.Neutral = kv.Value; break; } } unityPath.CreateAsset(asset); AssetDatabase.Refresh(); var loaded = unityPath.LoadAsset <VRM10Object>(); return(loaded); }