Skip to content

Commit

Permalink
LegacySupport
Browse files Browse the repository at this point in the history
なにもしなければ自動で既存Actionを読み込むし、なにかすれば名前の設定や取捨選択もできる close #46
  • Loading branch information
pandrabox committed Sep 28, 2024
1 parent 9ff2271 commit cf1c0fa
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 12 deletions.
5 changes: 2 additions & 3 deletions Editor/ControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace com.github.pandrabox.emoteprefab.editor
{
public class PutControlPanel
{
public const string OBJNAME = "EmotePrefab_ControlPanel";
/// <summary>
/// To call from Unity menu
/// </summary>
Expand All @@ -34,7 +33,7 @@ public static void PutControlPanelMain()
EditorUtility.DisplayDialog("PutControlPanel", "この機能はHierarchyでControlPanelをアクティブにしたいアバターを選択してから使って下さい","OK");
return;
}
var existController = descriptor.transform.Find(OBJNAME);
var existController = descriptor.transform.Find(Config.ControlPanelObjName);
if (existController != null)
{
if (existController.GetComponent<ControlPanel>()== null)
Expand All @@ -44,7 +43,7 @@ public static void PutControlPanelMain()
Selection.activeGameObject = existController.gameObject;
return;
}
var obj = new GameObject(OBJNAME);
var obj = new GameObject(Config.ControlPanelObjName);
obj.transform.SetParent(descriptor.transform);
obj.AddComponent<ControlPanel>();
Selection.activeGameObject = obj;
Expand Down
10 changes: 9 additions & 1 deletion Editor/EmotePrefabInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ public class EmotePrefabInitializer
public EmotePrefabInitializer(VRCAvatarDescriptor descriptor)
{
Descriptor = descriptor;
GetControlPanel();
CreateLegacys();
GetEmotePrefabs();
if (!HasTask) return;
CreateWorkDir();
CopyControllers();
CreateRootObject();
GetControlPanel();
CreateActionObject();
CreateFXObject();
CreateFXRelativeObject();
Expand All @@ -52,6 +53,13 @@ private static void GetEmotePrefabs()
}
}

private static void CreateLegacys()
{
if(PanelSetting.LegacySupport)
{
new LegacySupport(Descriptor);
}
}
private static void GetControlPanel()
{
PanelSetting = Descriptor.transform.GetComponentsInChildren<ControlPanel>(false).Where(e => e.Enable).FirstOrDefault();
Expand Down
41 changes: 38 additions & 3 deletions Runtime/EmotePrefabBulkGeneration.cs → Runtime/BulkGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using VRC.SDK3.Dynamics.PhysBone.Components;
using static com.github.pandrabox.emoteprefab.runtime.Generic;

public class EmotePrefabBulkGeneration : EditorWindow
public class BulkGeneration : EditorWindow
{
private DefaultAsset targetFolder;
private Vector2 scrollPosition;
Expand All @@ -21,13 +21,48 @@ public class EmotePrefabBulkGeneration : EditorWindow
public static void ShowWindow()
{
// ウィンドウを表示
GetWindow<EmotePrefabBulkGeneration>("EmotePrefabBulkGeneration");
GetWindow<BulkGeneration>("BulkGeneration");
}
private void LegacySupporArea()
{

GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
var selectObj = Selection.gameObjects.FirstOrDefault();
if (selectObj == null)
{
GUILayout.Label("この機能を使うためには、対象のアバターをHierarchyでクリックして下さい", labelStyle);
return;
}
var descriptor = FindComponentFromParent<VRCAvatarDescriptor>(selectObj);
if (descriptor == null)
{
GUILayout.Label("この機能を使うためには、対象のアバターをHierarchyでクリックして下さい", labelStyle);
return;
}
GUILayout.Label($@"対象アバター:{descriptor.name}");
if (descriptor.transform.Find(Config.LegacyObjName) != null)
{
GUILayout.Label("実行済み", labelStyle);
return;
}
if (GUILayout.Button("実行"))
{
new LegacySupport(descriptor);
var cp = descriptor.transform.Find(Config.ControlPanelObjName).GetComponent<ControlPanel>();
cp.LegacySupport = false;
EditorUtility.DisplayDialog("一括生成", $@"アバター直下に{Config.LegacyObjName}オブジェクトを生成し、重複防止のためControlPanelのLegacySupportをOFFにしました。", "OK");
}
}
// エディタウィンドウの内容を描画
private void OnGUI()
{
GUILayout.Label("一括生成", EditorStyles.boldLabel);
GUILayout.Label("一括生成(既存Actionから)", EditorStyles.boldLabel);
LegacySupporArea();

GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));


GUILayout.Label("一括生成(フォルダから)", EditorStyles.boldLabel);
targetFolder = (DefaultAsset)EditorGUILayout.ObjectField("対象フォルダ", targetFolder, typeof(DefaultAsset), false);

if (targetFolder == null) return;
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions Runtime/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public static class Config
/// GemeratedFXレイヤにおけるShrinkPhysBonesレイヤのIndex
/// </summary>
public static readonly int ShrinkPhysBonesIndex = 2;

public static readonly string LegacyObjName = "EmotePrefab_Legacies";
public static readonly string ControlPanelObjName = "EmotePrefab_ControlPanel";
}
}

Expand Down
13 changes: 9 additions & 4 deletions Runtime/ControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ControlPanel : MonoBehaviour, VRC.SDKBase.IEditorOnly
public int UseSyncBitNum;
public bool UseHeightControl = true;
public float HeightUpper=3, HeightLower=-3;
public bool LegacySupport = true;
}


Expand Down Expand Up @@ -71,14 +72,14 @@ void Disable(string msg)
{
Disable("親オブジェクトにVRCAvatarDescriptorが見つかりませんでした。親のオブジェクトの状態を確認するか、このオブジェクトを削除して「Pan→PutControlPanel」より再導入して下さい。");
}
var controlPanelsCount = descriptor.transform.Cast<Transform>().Count(c => c.name == "EmotePrefab_ControlPanel" && c.GetComponent<ControlPanel>() != null);
var controlPanelsCount = descriptor.transform.Cast<Transform>().Count(c => c.name == Config.ControlPanelObjName && c.GetComponent<ControlPanel>() != null);
if (controlPanelsCount > 1)
{
Disable("ControlPanelが複数見つかりました。1つのアバターに導入できるControlPanelは1つのみです。不要なオブジェクトを削除して下さい。");
}
if (nowinstance.gameObject.name != "EmotePrefab_ControlPanel")
if (nowinstance.gameObject.name != Config.ControlPanelObjName)
{
Disable("このコンポーネントは「EmotePrefab_ControlPanel」という名前のオブジェクトにアタッチされているときのみ有効です。オブジェクトの名前を修正するか、削除して「Pan→PutControlPanel」より再導入して下さい。");
Disable($@"このコンポーネントは「{Config.ControlPanelObjName}」という名前のオブジェクトにアタッチされているときのみ有効です。オブジェクトの名前を修正するか、削除して「Pan→PutControlPanel」より再導入して下さい。");
}
//if (descriptor.transform.chil)

Expand Down Expand Up @@ -112,10 +113,14 @@ void Disable(string msg)
GUILayout.Label("表情レイヤ", TitleStyle());
EditorGUILayout.PropertyField(serializedObject.FindProperty("FaxialExpressionLayer"));


GUILayout.Label("既存Actionに登録されている全Animationを登録", TitleStyle());
EditorGUILayout.PropertyField(serializedObject.FindProperty("LegacySupport"));

GUILayout.Label("EmotePrefab一括生成", TitleStyle());
if (GUILayout.Button("起動"))
{
EmotePrefabBulkGeneration.ShowWindow();
BulkGeneration.ShowWindow();
}

}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/EmoteMenuInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum AutoFolderModeType
parallel,
none
}
public bool Sort;
public bool Sort=true;
public AutoFolderModeType AutoFolderMode;
}
}
Expand Down
44 changes: 44 additions & 0 deletions Runtime/LegacySupport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#if UNITY_EDITOR

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using com.github.pandrabox.emoteprefab.runtime;
using nadena.dev.ndmf;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDKBase;
using static com.github.pandrabox.emoteprefab.runtime.Generic;


namespace com.github.pandrabox.emoteprefab.runtime
{
public class LegacySupport
{
public LegacySupport(VRCAvatarDescriptor descriptor)
{
AnimationClip[] clips = descriptor.baseAnimationLayers[3].animatorController?.animationClips;
if (clips == null) return;
HashSet<AnimationClip> uniqueClipsSet = new HashSet<AnimationClip>(clips);
AnimationClip[] uniqueClips = new AnimationClip[uniqueClipsSet.Count];
uniqueClipsSet.CopyTo(uniqueClips);
var root = new GameObject(Config.LegacyObjName);
var folder = root.AddComponent<EmoteFolder>();
folder.FolderName = "Legacies";
root.transform.SetParent(descriptor.transform);
foreach(var cl in uniqueClips)
{
var obj = new GameObject();
obj.transform.SetParent(root.transform);
var ep = obj.AddComponent<EmotePrefab>();
ep.SetEasy(cl);
}
}
}
}

#endif

11 changes: 11 additions & 0 deletions Runtime/LegacySupport.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf1c0fa

Please sign in to comment.