Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Animation Creator #26

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d3302c7
tmp
Luca3317 Sep 4, 2024
5463c69
Merge branch 'main' into tmp-branch
Luca3317 Sep 29, 2024
83ee33e
Checkpoint; GenericAnimation start + minor fixes to random stuff
Luca3317 Sep 30, 2024
4833334
Minor fixes to KeyFrameEditor for compile
Luca3317 Oct 3, 2024
bc4479f
First working version of genericanimation => generated code; minor im…
Luca3317 Oct 4, 2024
c4cb8ea
Reset animator to specific time + expose ReadOnlyContext TODO use cac…
Luca3317 Oct 4, 2024
6b3787a
Improvements to generic animation exporter
Luca3317 Oct 5, 2024
641fd0f
Further improvements, bg colors
Luca3317 Oct 5, 2024
a22367d
Checkpoint; Improvements to modifiers, drawers, scaling stuff
Luca3317 Oct 9, 2024
a064cb5
Checkpoint; Improvements to drawers, modifier logic, start clips + ti…
Luca3317 Oct 9, 2024
0a24492
Checkpoint; CharDataModifiers
Luca3317 Oct 11, 2024
38a5ec1
Furthee refactors to mesh modifiers
Luca3317 Oct 11, 2024
1776a2d
First steps in fully replacing old chardata system
Luca3317 Oct 11, 2024
e053b68
Improvement to performance of new system -- now close to old system
Luca3317 Oct 11, 2024
6bf026b
Remove debug.log
Luca3317 Oct 11, 2024
74167c8
Implement equals for coloroverride for performance
Luca3317 Oct 11, 2024
e85c0ee
Yet more fixes
Luca3317 Oct 12, 2024
7dbcc6f
Add ignoreScaling option to GetWaveOffset
Luca3317 Oct 14, 2024
52d8a14
Add scaling and conversion functionality to typedvector
Luca3317 Oct 14, 2024
f9c2d14
Minor rework to scaling utility
Luca3317 Oct 14, 2024
a53ffe8
Checkpoint; CharData API rework
Luca3317 Oct 14, 2024
0b40a5f
Fix bug with vertex deltas not being scaled
Luca3317 Oct 14, 2024
67df663
Rename TMPMeshModifier
Luca3317 Oct 14, 2024
80f8dce
Checkpoint
Luca3317 Oct 14, 2024
bc79cdb
Checkpoint, fixes
Luca3317 Oct 14, 2024
77295af
Checkpoint; first timeline creation tool and exporter
Luca3317 Oct 15, 2024
fd67d8a
Checkpoint; Start split of editor modifiers and internal modifier
Luca3317 Oct 16, 2024
1c88106
First fully working timeline (export untested)
Luca3317 Oct 16, 2024
479f365
Changes to TMPWriter main routine; Mostly untested
Luca3317 Oct 16, 2024
45e6fb6
Animation exports (+ other minor stuff)
Luca3317 Oct 17, 2024
a71c977
Checkpoint; bunch of stuff
Luca3317 Oct 17, 2024
26ebc78
Add TMPro version defines and replace old unity ones
Luca3317 Oct 17, 2024
af90711
Remove some unneeded files
Luca3317 Oct 17, 2024
7c7337c
Remove non-functional caching in clipeditor
Luca3317 Oct 17, 2024
2378ed9
Merge branch 'main' into tmp-branch
Luca3317 Oct 17, 2024
4a740ec
Remove unused imports in TMPAnimator
Luca3317 Oct 17, 2024
aa3f769
Add basic show/hide animation that uses basic animation w/ curve
Luca3317 Oct 18, 2024
5f6de8c
CharDataModifiers changes
Luca3317 Oct 18, 2024
bd781d5
Fix false commit
Luca3317 Oct 18, 2024
30f2fd6
Added lt 0 check to Animation Step appliers
Luca3317 Oct 18, 2024
ea87db8
Checkpoint
Luca3317 Oct 22, 2024
f888b09
Checkpoint; SerializedObject disposing
Luca3317 Oct 23, 2024
dc0599c
First working version of nested reorderable lists
Luca3317 Oct 23, 2024
c1d894e
Minor further fixes
Luca3317 Oct 23, 2024
e4d1de3
Bidirectional conversion (GenericAnim <-> Timeline)
Luca3317 Oct 24, 2024
a2ab7be
Test test
Luca3317 Oct 24, 2024
f1192c4
Another Checkpoint
Luca3317 Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,200 changes: 1,200 additions & 0 deletions Package/Editor/EasingFunctions.curves

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Package/Editor/EasingFunctions.curves.meta

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

56 changes: 56 additions & 0 deletions Package/Editor/FancyAnimationCurveDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using AnimationUtility = TMPEffects.TMPAnimations.AnimationUtility;

[CustomPropertyDrawer(typeof(AnimationUtility.FancyAnimationCurve))]
public class FancyAnimationCurveDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);

var rect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

var width = EditorStyles.label.CalcSize(label);
var ctrlRect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive, rect), label);
var foldoutRect = new Rect(rect.x + width.x + 15, rect.y, 20, EditorGUIUtility.singleLineHeight);

var curveProp = property.FindPropertyRelative("curve");

curveProp.isExpanded = EditorGUI.Foldout(foldoutRect, curveProp.isExpanded, new GUIContent(""));

// TODO Strange ass workaround for offset created by EditorGUI.PrefixLabel
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
EditorGUI.PropertyField(ctrlRect, curveProp, new GUIContent(""));
EditorGUI.indentLevel++;
EditorGUI.indentLevel++;

if (curveProp.isExpanded)
{
EditorGUI.indentLevel++;
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, property.FindPropertyRelative("offsetType"));
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, property.FindPropertyRelative("wrapMode"));
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, property.FindPropertyRelative("uniformity"));
EditorGUI.indentLevel--;
}

EditorGUI.EndProperty();
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
var curveProp = property.FindPropertyRelative("curve");
if (curveProp.isExpanded)
{
return EditorGUIUtility.singleLineHeight * 4;
}

return EditorGUIUtility.singleLineHeight;
}
}
11 changes: 11 additions & 0 deletions Package/Editor/FancyAnimationCurveDrawer.cs.meta

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

8 changes: 8 additions & 0 deletions Package/Editor/GenericAnimation.meta

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

301 changes: 301 additions & 0 deletions Package/Editor/GenericAnimation/AnimationStepDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
using TMPEffects.TMPAnimations;
using UnityEditor;
using UnityEngine;
using UnityEngine.Playables;

[CustomPropertyDrawer(typeof(AnimationStep), false)]
public class AnimationStepDrawer : PropertyDrawer
{
private bool entry = false;

private SerializedProperty entryCurve;
private SerializedProperty exitCurve;
private SerializedProperty entryDuration;
private SerializedProperty exitDuration;

private SerializedProperty loops;
private SerializedProperty repetitions;
private SerializedProperty startTime;
private SerializedProperty duration;
private SerializedProperty modifiers;
private SerializedProperty initModifiers;
private SerializedProperty useInitModifiers;
private SerializedProperty wave;
private SerializedProperty waveOffsetType;
private SerializedProperty useWave;

private SerializedProperty preExtrapolation;
private SerializedProperty postExtrapolation;


private Color backgroundColor;

protected void Init(SerializedProperty property)
{
entryCurve = property.FindPropertyRelative("entryCurve");
exitCurve = property.FindPropertyRelative("exitCurve");
entryDuration = property.FindPropertyRelative("entryDuration");
exitDuration = property.FindPropertyRelative("exitDuration");
loops = property.FindPropertyRelative("loops");
repetitions = property.FindPropertyRelative("repetitions");
startTime = property.FindPropertyRelative("startTime");
duration = property.FindPropertyRelative("duration");
modifiers = property.FindPropertyRelative("modifiers");
initModifiers = property.FindPropertyRelative("initModifiers");
useInitModifiers = property.FindPropertyRelative("useInitialModifiers");
useWave = property.FindPropertyRelative("useWave");
waveOffsetType = property.FindPropertyRelative("waveOffsetType");
wave = property.FindPropertyRelative("wave");
preExtrapolation = property.FindPropertyRelative("preExtrapolation");
postExtrapolation = property.FindPropertyRelative("postExtrapolation");

backgroundColor = EditorGUIUtility.isProSkin
? new Color32(56, 56, 56, 255)
: new Color32(194, 194, 194, 255);
}

protected float GetCommonHeight(SerializedProperty property)
{
float height = EditorGUIUtility.singleLineHeight * 3; // Blending + in out headers

if (entryCurve.isExpanded)
{
height += EditorGUIUtility.singleLineHeight + EditorGUI.GetPropertyHeight(entryCurve);
}

if (exitCurve.isExpanded)
{
height += EditorGUIUtility.singleLineHeight + EditorGUI.GetPropertyHeight(exitCurve);
}

height += EditorGUIUtility.singleLineHeight * 3; // Space + waves

if (useWave.boolValue) height += EditorGUI.GetPropertyHeight(wave, true) + EditorGUIUtility.singleLineHeight;

height += EditorGUIUtility.singleLineHeight * 2; // Space + initial

if (useInitModifiers.boolValue) height += EditorGUI.GetPropertyHeight(initModifiers, true);

height += EditorGUIUtility.singleLineHeight * 2; // Space + modifiers

height += EditorGUI.GetPropertyHeight(modifiers, true);

return height;
}

protected void DrawCommon(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.LabelField(rect, "Blending", EditorStyles.boldLabel);
rect.y += EditorGUIUtility.singleLineHeight;

entryCurve.isExpanded = EditorGUI.Foldout(rect, entryCurve.isExpanded, "Entry");
rect.y += EditorGUIUtility.singleLineHeight;

if (entryCurve.isExpanded)
{
EditorGUI.indentLevel++;
var bgRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight +EditorGUI.GetPropertyHeight(entryCurve));
EditorGUI.DrawRect(bgRect, backgroundColor);

EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(rect, entryDuration);
if (EditorGUI.EndChangeCheck())
{
if (property.FindPropertyRelative("lastMovedEntry") != null)
property.FindPropertyRelative("lastMovedEntry").intValue = 0;
}

rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, entryCurve);
rect.y += EditorGUI.GetPropertyHeight(entryCurve);
EditorGUI.indentLevel--;
}

exitCurve.isExpanded = EditorGUI.Foldout(rect, exitCurve.isExpanded, "Exit");
rect.y += EditorGUIUtility.singleLineHeight;

if (exitCurve.isExpanded)
{
EditorGUI.indentLevel++;
var bgRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight + EditorGUI.GetPropertyHeight(exitCurve));
EditorGUI.DrawRect(bgRect, backgroundColor);

EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(rect, exitDuration);
if (EditorGUI.EndChangeCheck())
{
if (property.FindPropertyRelative("lastMovedEntry") != null)
property.FindPropertyRelative("lastMovedEntry").intValue = 1;
}

rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, exitCurve);
rect.y += EditorGUI.GetPropertyHeight(exitCurve);
EditorGUI.indentLevel--;
}

rect.y += EditorGUIUtility.singleLineHeight;

GUIContent content = new GUIContent();
content.text = "Wave";
content.tooltip =
"Whether to use a wave.";

Vector2 labelSize = EditorStyles.boldLabel.CalcSize(content);
EditorGUI.BeginDisabledGroup(!useWave.boolValue);
EditorGUI.LabelField(rect, content, EditorStyles.boldLabel);
EditorGUI.EndDisabledGroup();
var toggleRect = new Rect(rect.x + labelSize.x + 10, rect.y, rect.width - labelSize.x - 10, rect.height);
useWave.boolValue = EditorGUI.Toggle(toggleRect, useWave.boolValue);
rect.y += EditorGUIUtility.singleLineHeight;

if (useWave.boolValue)
{
EditorGUI.PropertyField(rect, waveOffsetType);
rect.y += EditorGUIUtility.singleLineHeight;

if (wave.isExpanded)
{
var bgRect = new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight, rect.width,
EditorGUI.GetPropertyHeight(wave, true) - EditorGUIUtility.singleLineHeight);
EditorGUI.DrawRect(bgRect, backgroundColor);
}

// EditorGUI.indentLevel++;
EditorGUI.PropertyField(rect, wave, true);
rect.y += EditorGUI.GetPropertyHeight(wave, true);
// EditorGUI.indentLevel--;
}

rect.y += EditorGUIUtility.singleLineHeight;


content = new GUIContent();
content.text = "Initial Modifiers";
content.tooltip =
"Whether to use initial modifiers. If so, the lerp will be between InitialModifiers and Modifiers. Otherwise, the lerp will be between the CharData and Modifiers.";

labelSize = EditorStyles.boldLabel.CalcSize(content);
EditorGUI.BeginDisabledGroup(!useInitModifiers.boolValue);
EditorGUI.LabelField(rect, content, EditorStyles.boldLabel);
EditorGUI.EndDisabledGroup();
toggleRect = new Rect(rect.x + labelSize.x + 10, rect.y, rect.width - labelSize.x - 10, rect.height);
useInitModifiers.boolValue = EditorGUI.Toggle(toggleRect, useInitModifiers.boolValue);

rect.y += EditorGUIUtility.singleLineHeight;
if (useInitModifiers.boolValue)
{
EditorGUI.PropertyField(rect, initModifiers, true);
rect.y += EditorGUI.GetPropertyHeight(initModifiers, true);
}

rect.y += EditorGUIUtility.singleLineHeight;

EditorGUI.LabelField(rect, "Modifier", EditorStyles.boldLabel);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, modifiers, true);
rect.y += EditorGUI.GetPropertyHeight(modifiers, true);
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.managedReferenceValue == null)
{
Debug.LogWarning("Had to init");
property.managedReferenceValue = new AnimationStep();
}

Init(property);
EditorGUI.BeginProperty(position, label, property);
EditorGUI.indentLevel++;

var rect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, label);
rect.y += EditorGUIUtility.singleLineHeight;
if (!property.isExpanded)
{
EditorGUI.EndProperty();
EditorGUI.indentLevel--;
return;
}

EditorGUI.PropertyField(rect, property.FindPropertyRelative("name"));
rect.y += EditorGUIUtility.singleLineHeight * 2f;

EditorGUI.PropertyField(rect, loops);
rect.y += EditorGUIUtility.singleLineHeight;

if (loops.boolValue)
{
EditorGUI.PropertyField(rect, repetitions, new GUIContent("Repetitions (0 = forever)"));
rect.y += EditorGUIUtility.singleLineHeight;
}

EditorGUI.PropertyField(rect, preExtrapolation);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, postExtrapolation);
rect.y += EditorGUIUtility.singleLineHeight * 2;

DrawCommon(rect, property, label);

EditorGUI.indentLevel--;
EditorGUI.EndProperty();
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property.managedReferenceValue == null)
{
Debug.LogWarning("Had to init");

Check notice on line 249 in Package/Editor/GenericAnimation/AnimationStepDrawer.cs

View check run for this annotation

codefactor.io / CodeFactor

Package/Editor/GenericAnimation/AnimationStepDrawer.cs#L249

Arithmetic expressions should declare precedence. (SA1407)
property.managedReferenceValue = new AnimationStep();
}

Init(property);

if (property.isExpanded)
return GetCommonHeight(property) + EditorGUIUtility.singleLineHeight * 6;

return EditorGUIUtility.singleLineHeight;

float totalHeight = EditorGUIUtility.singleLineHeight; // foldout
if (!property.isExpanded) return totalHeight;

totalHeight += EditorGUIUtility.singleLineHeight * 2f; // For the "name" property

if (property.serializedObject.targetObject is not PlayableAsset)
{
totalHeight += EditorGUIUtility.singleLineHeight * 2f; // startTime, duration
}

totalHeight += EditorGUIUtility.singleLineHeight; // entry foldout
if (entryCurve.isExpanded)
{
totalHeight += EditorGUIUtility.singleLineHeight * 2f; // entryDuration and entryCurve
}

totalHeight += EditorGUIUtility.singleLineHeight; // exit foldout
if (exitCurve.isExpanded)
{
totalHeight += EditorGUIUtility.singleLineHeight * 2f; // exitDuration and exitCurve
}

totalHeight += EditorGUIUtility.singleLineHeight * 2; // loops and useWave

if (loops.boolValue)
{
totalHeight += EditorGUIUtility.singleLineHeight; // repetitions
}

if (useWave.boolValue)
{
totalHeight += EditorGUIUtility.singleLineHeight;
totalHeight += EditorGUI.GetPropertyHeight(wave, true);
}

// totalHeight += EditorGUI.GetPropertyHeight(modifiers, true);

totalHeight += EditorGUI.GetPropertyHeight(modifiers, true);

return totalHeight;
}
}
Loading
Loading