-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Adnc.AnimatorHelpers.Editors.CustomEditors { | ||
[CustomEditor(typeof(AnimatorPlayback))] | ||
public class AnimatorPlaybackEditor : Editor { | ||
private SortableListAnimatorVariable _listBools; | ||
private SortableListAnimatorVariable _listFloats; | ||
private SortableListAnimatorVariable _listInts; | ||
private SortableListAnimatorVariable _listTriggers; | ||
|
||
private void OnEnable () { | ||
_listBools = new SortableListAnimatorVariable(this, "bools", "Set Bools"); | ||
_listFloats = new SortableListAnimatorVariable(this, "floats", "Set Floats"); | ||
_listInts = new SortableListAnimatorVariable(this, "ints", "Set Ints"); | ||
_listTriggers = new SortableListAnimatorVariable(this, "triggers", "Set Triggers"); | ||
} | ||
|
||
public override void OnInspectorGUI () { | ||
serializedObject.Update(); | ||
|
||
_listBools.Update(); | ||
_listFloats.Update(); | ||
_listInts.Update(); | ||
_listTriggers.Update(); | ||
|
||
var propWait = serializedObject.FindProperty("waitForCondition"); | ||
EditorGUILayout.PropertyField(propWait); | ||
|
||
if (propWait.boolValue) { | ||
var propCondition = serializedObject.FindProperty("conditions"); | ||
EditorGUILayout.PropertyField(propCondition, true); | ||
} | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Adnc.Utility.Editors; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Adnc.AnimatorHelpers.Editors.CustomEditors { | ||
public class SortableListAnimatorVariable : SortableListBase { | ||
public SortableListAnimatorVariable (Editor editor, string property, string title) : base(editor, property, title) { | ||
_list.drawElementCallback = (rect, index, active, focused) => { | ||
var element = _serializedProp.GetArrayElementAtIndex(index); | ||
var propName = element.FindPropertyRelative("name"); | ||
var propValue = element.FindPropertyRelative("value"); | ||
|
||
rect.height -= EditorGUIUtility.standardVerticalSpacing; | ||
|
||
if (propValue != null) { | ||
var col1 = rect; | ||
col1.width /= 2; | ||
col1.width -= EditorGUIUtility.standardVerticalSpacing; | ||
EditorGUI.PropertyField(col1, propName, new GUIContent()); | ||
|
||
var col2 = col1; | ||
col2.x += col1.width + EditorGUIUtility.standardVerticalSpacing; | ||
EditorGUI.PropertyField(col2, propValue, new GUIContent()); | ||
} else { | ||
EditorGUI.PropertyField(rect, propName, new GUIContent()); | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using Adnc.AnimatorHelpers.Conditions; | ||
using Adnc.AnimatorHelpers.Variables; | ||
using Adnc.Utility.Testing; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace Adnc.AnimatorHelpers.Editors.Testing { | ||
public class TestAnimatorPlayback : TestBase { | ||
private const string ANIMATOR_STUB_LOC = "AnimatorTesting/AnimatorStub"; | ||
|
||
private AnimatorPlayback _playback; | ||
private Animator _anim; | ||
|
||
[SetUp] | ||
public void SetupAnimatorPlayback () { | ||
_playback = ScriptableObject.CreateInstance<AnimatorPlayback>(); | ||
var stub = Resources.Load<GameObject>(ANIMATOR_STUB_LOC); | ||
_anim = Object.Instantiate(stub).GetComponent<Animator>(); | ||
} | ||
|
||
[TearDown] | ||
public void TeardownAnimatorPlayback () { | ||
Object.DestroyImmediate(_anim.gameObject); | ||
_playback = null; | ||
_anim = null; | ||
} | ||
|
||
[Test] | ||
public void StubBoolIsFalse () { | ||
Assert.IsFalse(_anim.GetBool("bool")); | ||
} | ||
|
||
[Test] | ||
public void StubFloatIsZero () { | ||
Assert.IsTrue(Mathf.Abs(_anim.GetFloat("float")) < 0.1f); | ||
} | ||
|
||
[Test] | ||
public void StubIntIsZero () { | ||
Assert.IsTrue(_anim.GetInteger("int") == 0); | ||
} | ||
|
||
[Test] | ||
public void PlaySetsAnimatorBool () { | ||
_playback.bools.Add(new VarBool { | ||
name = "bool", | ||
value = true | ||
}); | ||
|
||
_playback.Play(_anim); | ||
|
||
Assert.IsTrue(_anim.GetBool("bool")); | ||
} | ||
|
||
[Test] | ||
public void PlaySetsAnimatorFloat () { | ||
_playback.floats.Add(new VarFloat { | ||
name = "float", | ||
value = 1 | ||
}); | ||
|
||
_playback.Play(_anim); | ||
|
||
Assert.AreEqual(_anim.GetFloat("float"), 1); | ||
} | ||
|
||
[Test] | ||
public void PlaySetsAnimatorInt () { | ||
_playback.ints.Add(new VarInt { | ||
name = "int", | ||
value = 1 | ||
}); | ||
|
||
_playback.Play(_anim); | ||
|
||
Assert.AreEqual(_anim.GetInteger("int"), 1); | ||
} | ||
|
||
[Test] | ||
public void IsConditionMetTrueWithNoAnimatorNull () { | ||
Assert.IsTrue(_playback.IsConditionsMet(null)); | ||
} | ||
|
||
[Test] | ||
public void IsConditionMetIsTrueWithNoConditions () { | ||
_playback.conditions.RemoveAt(0); | ||
Assert.IsTrue(_playback.IsConditionsMet(_anim)); | ||
} | ||
|
||
[Test] | ||
public void IsConditionMetFalseWhenConditionsNotMet () { | ||
_playback.conditions.RemoveAt(0); | ||
_playback.conditions.Add(new Condition { | ||
compareValues = OperatorAll.AreEqual, | ||
variableBool = new VarBool { | ||
name = "bool", | ||
value = true | ||
}, | ||
variableType = ConditionVarType.Bool | ||
}); | ||
|
||
Assert.IsFalse(_playback.IsConditionsMet(_anim)); | ||
} | ||
|
||
[Test] | ||
public void IsConditionMetTrueWhenConditionsAreMet () { | ||
_playback.conditions.RemoveAt(0); | ||
_playback.conditions.Add(new Condition { | ||
compareValues = OperatorAll.AreEqual, | ||
variableBool = new VarBool { | ||
name = "bool", | ||
value = true | ||
}, | ||
variableType = ConditionVarType.Bool | ||
}); | ||
|
||
_anim.SetBool("bool", true); | ||
|
||
Assert.IsTrue(_playback.IsConditionsMet(_anim)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.