Skip to content

Commit

Permalink
feat: new ui with entry, loop, and exit animation/audio
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaNeverUsed committed Jul 3, 2024
1 parent 2a5eb25 commit fda5810
Show file tree
Hide file tree
Showing 7 changed files with 58,899 additions and 6,159 deletions.
40 changes: 31 additions & 9 deletions Packages/befuddledlabs.opensyncdance/Runtime/Gui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public static IEnumerable<Rect> DistributeVertically(int num, Rect space, float
return Enumerable.Range(0, num).Select(i => new Rect(space.x, space.y + dy * i, space.width, h));
}

public static void DrawPropertyFieldWithLabel(Rect rect, SerializedProperty property, string label, GUIStyle labelStyle)
public static void DrawPropertyFieldWithLabel(Rect rect, SerializedProperty property, string label, UnityEngine.GUIStyle labelStyle)
{
if (labelStyle != GUIStyle.none)
if (labelStyle != UnityEngine.GUIStyle.none)
{
EditorGUI.LabelField(rect, label, labelStyle);
rect.x += EditorGUIUtility.labelWidth;
Expand All @@ -44,9 +44,9 @@ public static void DrawPropertyFieldWithLabel(Rect rect, SerializedProperty prop
EditorGUI.PropertyField(rect, property, GUIContent.none);
}

public static void SliderFieldWithLabel(Rect rect, SerializedProperty property, float leftValue, float rightValue, string label, GUIStyle labelStyle)
public static void SliderFieldWithLabel(Rect rect, SerializedProperty property, float leftValue, float rightValue, string label, UnityEngine.GUIStyle labelStyle)
{
if (labelStyle != GUIStyle.none)
if (labelStyle != UnityEngine.GUIStyle.none)
{
EditorGUI.LabelField(rect, label, labelStyle);
rect.x += EditorGUIUtility.labelWidth;
Expand Down Expand Up @@ -96,16 +96,19 @@ public GUIBuilder Draw(Func<GUIBuilder, GUIBuilderElement> builder)
return this;
}

public GUIBuilder DrawField(string field, string label, GUIStyle style)
public GUIBuilder DrawEmpty()
=> Draw(_ => {});

public GUIBuilder DrawField(string field, string label, UnityEngine.GUIStyle style)
=> DrawField(_property.FindPropertyRelative(field), label, style);

public GUIBuilder DrawField(SerializedProperty property, string label, GUIStyle style)
public GUIBuilder DrawField(SerializedProperty property, string label, UnityEngine.GUIStyle style)
=> Draw((Rect space) => DrawPropertyFieldWithLabel(space, property, label, style), EditorGUI.GetPropertyHeight(property));

public GUIBuilder DrawSlider(string field, float min, float max, string label, GUIStyle style)
public GUIBuilder DrawSlider(string field, float min, float max, string label, UnityEngine.GUIStyle style)
=> DrawSlider(_property.FindPropertyRelative(field), min, max, label, style);

public GUIBuilder DrawSlider(SerializedProperty property, float min, float max, string label, GUIStyle style)
public GUIBuilder DrawSlider(SerializedProperty property, float min, float max, string label, UnityEngine.GUIStyle style)
=> Draw((Rect space) => SliderFieldWithLabel(space, property, min, max, label, style), EditorGUI.GetPropertyHeight(property));

public GUIBuilderElement DrawHorizontally(float padding = 4f)
Expand All @@ -126,7 +129,26 @@ public GUIBuilderElement DrawVertically(float padding = 4f)
item.Draw(new Rect(space.x, space.y, space.width, item.height));
space.y += item.height + padding;
}
}, _itemsToDraw.Sum(x => x.height + padding * (_itemsToDraw.Count - 1)));
}, _itemsToDraw.Sum(x => x.height) + padding * (_itemsToDraw.Count - 1));
}

public GUIBuilderElement DrawFoldout(string foldoutField, string label = "", float padding = 4f)
{
var foldoutProperty = _property.FindPropertyRelative(foldoutField);
return new GUIBuilderElement((Rect space) => {
foldoutProperty.boolValue = EditorGUI.Foldout(new Rect(space.x, space.y, space.width, 20), foldoutProperty.boolValue, label);
if (foldoutProperty.boolValue)
{
space.y += 20 + padding;
for (int i = 0; i < _itemsToDraw.Count; i++)
{
var item = _itemsToDraw[i];
item.Draw(new Rect(space.x, space.y, space.width, item.height));
space.y += item.height + padding;
}
}
_property.serializedObject.ApplyModifiedProperties();
}, foldoutProperty.boolValue ? _itemsToDraw.Sum(x => x.height) + padding * _itemsToDraw.Count + 20 : 20);
}
}
}
Expand Down
119 changes: 73 additions & 46 deletions Packages/befuddledlabs.opensyncdance/Runtime/OpenSyncDance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using AnimatorAsCode.V1;
using AnimatorAsCode.V1.VRC;
using UnityEditor;
Expand Down Expand Up @@ -59,6 +58,15 @@ Zufolo Impazzito

namespace BefuddledLabs.OpenSyncDance
{
public static class GUIStyle {
public static int LabelWidth = 50;

public static UnityEngine.GUIStyle Light = new() {normal = new GUIStyleState {textColor = new Color32(0xF6, 0xBA, 0xFB, 0xFF)}};
public static UnityEngine.GUIStyle Mid = new() {normal = new GUIStyleState {textColor = new Color32(0xE2, 0x6C, 0xD7, 0xFF)}};
public static UnityEngine.GUIStyle Dark = new() {normal = new GUIStyleState {textColor = new Color32(0x97, 0x29, 0xFC, 0xFF)}};
public static UnityEngine.GUIStyle Black = new() {normal = new GUIStyleState {textColor = new Color32(0x11, 0x00, 0x2A, 0xFF)}};
}

[Serializable]
public enum AudioType
{
Expand All @@ -76,7 +84,8 @@ public enum AudioSyncMethod
}

[Serializable]
public class AnimationAudio {
public class AnimationAudio
{
public AudioClip audioClip;
public AudioType audioType;

Expand All @@ -90,22 +99,29 @@ public class AnimationAudio {
[CustomPropertyDrawer(typeof(AnimationAudio))]
public class AnimationAudioDrawer : PropertyDrawer
{
ExtraGUI.GUIBuilderElement GetLayout(SerializedProperty property)
=> ExtraGUI.Builder(property)
.Draw(x => x
.DrawField("audioClip", "audio", GUIStyle.none)
.DrawField("audioType", "type", GUIStyle.none)
.DrawHorizontally())
ExtraGUI.GUIBuilderElement GetLayout(SerializedProperty property)
{
var ui = ExtraGUI.Builder(property)
.Draw(x => x
.DrawField("audioUrl", "URL", GUIStyle.none)
.DrawField("startTimeStamp", "start", GUIStyle.none)
.DrawField("endTimeStamp", "end", GUIStyle.none)
.DrawHorizontally())
.DrawVertically();
.DrawField("audioClip", "audio", GUIStyle.Mid)
.DrawEmpty()
.DrawField("audioType", "type", GUIStyle.Mid)
.DrawHorizontally());
if ((AudioType)property.FindPropertyRelative("audioType").boxedValue == AudioType.Youtube) {
ui.Draw(x => x
.DrawField("audioUrl", "URL", GUIStyle.Dark)
.DrawField("startTimeStamp", "start", GUIStyle.Dark)
.DrawField("endTimeStamp", "end", GUIStyle.Dark)
.DrawHorizontally());

}
return ui.DrawVertically();
}

public override void OnGUI(Rect space, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(space, label, property);
EditorGUIUtility.labelWidth = GUIStyle.LabelWidth;

GetLayout(property).Draw(space);

Expand All @@ -117,8 +133,10 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
}

[Serializable]
public class SyncedAnimation
public class SyncedAnimation
{
public bool expanded;

public AnimationClip animationClip;
public bool animationUseFootIK;
public AudioSyncMethod syncMethod;
Expand All @@ -131,16 +149,17 @@ public class SyncedAnimationDrawer : PropertyDrawer
ExtraGUI.GUIBuilderElement GetLayout(SerializedProperty property)
=> ExtraGUI.Builder(property)
.Draw(x => x
.DrawField("animationClip", "animation", GUIStyle.none)
.DrawField("animationUseFootIK", "foot ik", GUIStyle.none)
.DrawField("syncMethod", "sync", GUIStyle.none)
.DrawField("animationClip", "anim", GUIStyle.Light)
.DrawField("animationUseFootIK", "foot ik", GUIStyle.Light)
.DrawField("syncMethod", "sync", GUIStyle.Light)
.DrawHorizontally())
.DrawField("audio", "audio", GUIStyle.none)
.DrawVertically();
.DrawField("audio", "audio", UnityEngine.GUIStyle.none)
.DrawFoldout("expanded");

public override void OnGUI(Rect space, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(space, label, property);
EditorGUIUtility.labelWidth = GUIStyle.LabelWidth;

GetLayout(property).Draw(space);

Expand All @@ -157,6 +176,8 @@ public class SyncedEmote
public Texture2D icon;
public string name;

public bool expanded;

public SyncedAnimation entry;
public SyncedAnimation loop;
public SyncedAnimation exit;
Expand All @@ -165,27 +186,29 @@ public class SyncedEmote
[CustomPropertyDrawer(typeof(SyncedEmote))]
public class SyncedEmoteDrawer : PropertyDrawer
{
ExtraGUI.GUIBuilderElement GetLayout(SerializedProperty property)
=> ExtraGUI.Builder(property)
ExtraGUI.GUIBuilderElement GetLayout(SerializedProperty property) {
return ExtraGUI.Builder(property)
.Draw(x => x
.DrawField("name", "name", GUIStyle.none)
.DrawField("name", "name", GUIStyle.Dark)
.DrawHorizontally())
.DrawField("entry", "[P]", GUIStyle.none)
.DrawField("loop", "[L]", GUIStyle.none)
.DrawField("exit", "[S]", GUIStyle.none)
.DrawVertically();
.DrawField("entry", "Entry", GUIStyle.Mid)
.DrawField("loop", "Loop", GUIStyle.Mid)
.DrawField("exit", "Exit", GUIStyle.Mid)
.DrawFoldout("expanded", property.FindPropertyRelative("name").stringValue);
}

public override void OnGUI(Rect space, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(space, label, property);
EditorGUIUtility.labelWidth = GUIStyle.LabelWidth;

GetLayout(property).Draw(space);

EditorGUI.EndProperty();
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
=> GetLayout(property).height;
=> GetLayout(property).height + 4;
}

public class OpenSyncDance : MonoBehaviour, IEditorOnly
Expand Down Expand Up @@ -341,8 +364,8 @@ public override void OnInspectorGUI()
assetContainer_property = serializedObject.FindProperty("animatorControllerFX");
EditorGUILayout.PropertyField(assetContainer_property, true);

var animation_property = serializedObject.FindProperty("animations");
EditorGUILayout.PropertyField(animation_property, true);
var emote_property = serializedObject.FindProperty("animations");
EditorGUILayout.PropertyField(emote_property, true);

// Advanced settings for smarty pants. You probably don't need this.
if (_uiAdvancedFoldoutState = EditorGUILayout.BeginFoldoutHeaderGroup(_uiAdvancedFoldoutState, "Advanced"))
Expand All @@ -362,36 +385,33 @@ public override void OnInspectorGUI()
{
EditorGUILayout.EndFoldoutHeaderGroup();
}


serializedObject.ApplyModifiedProperties();

if (DownloadManager.Hasytdlp && DownloadManager.HasFFmpeg)
{
if (GUILayout.Button("Download Missing AudioClips"))
{
EditorGUI.BeginChangeCheck();
foreach (var animations in _self.animations)
{
var anims = new [] {
animations.entry,
animations.loop,
animations.exit
for (var index = 0; index < emote_property.arraySize; index++) {
var syncedEmote = emote_property.GetArrayElementAtIndex(index);
var anims = new[] {
syncedEmote.FindPropertyRelative("entry"),
syncedEmote.FindPropertyRelative("loop"),
syncedEmote.FindPropertyRelative("exit"),
};

foreach (var anim in anims)
{
if (anim.audio.audioType != AudioType.Youtube)
foreach (var anim in anims) {
var animObject = (SyncedAnimation)anim.boxedValue;
if (animObject.audio.audioType != AudioType.Youtube)
continue;
if (anim.audio.audioClip != null)
if (animObject.audio.audioClip != null)
continue;
if (anim.animationClip == null)
if (animObject.animationClip == null)
continue;
anim.audio.audioClip = DownloadManager.DownloadYouTubeLink(anim);

anim.FindPropertyRelative("audio").FindPropertyRelative("audioClip").boxedValue = DownloadManager.DownloadYouTubeLink(animObject);
}

}

if (EditorGUI.EndChangeCheck())
EditorUtility.SetDirty(_self);
}
Expand All @@ -402,6 +422,8 @@ public override void OnInspectorGUI()
DownloadManager.DownloadBoth();
}

serializedObject.ApplyModifiedProperties();

if (GUILayout.Button("Generate!"))
{
// TODO: create new animation controller if it doesn't exist
Expand Down Expand Up @@ -611,6 +633,7 @@ private void GenerateReceiveLayer()
{
var loopState = parent.NewState("loopState");
var exitState = parent.NewState("exitState");
entryState.TransitionsTo(loopState).Automatically();
loopState.TransitionsTo(exitState).When(param.ExitCondition);
exitState.Exits().Automatically();

Expand All @@ -630,6 +653,10 @@ private void GenerateReceiveLayer()
entryState.TrackingAnimates(AacAv3.Av3TrackingElement.LeftFingers);
entryState.TrackingAnimates(AacAv3.Av3TrackingElement.RightFingers);

entryState.State.iKOnFeet = item.entry.animationUseFootIK;
loopState.State.iKOnFeet = item.loop.animationUseFootIK;
exitState.State.iKOnFeet = item.exit.animationUseFootIK;

if (item.entry.animationClip != null)
entryState.WithAnimation(item.entry.animationClip);
if (item.loop.animationClip != null)
Expand Down
Loading

0 comments on commit fda5810

Please sign in to comment.