-
Notifications
You must be signed in to change notification settings - Fork 16
/
ControllerInitialStateContext.cs
50 lines (45 loc) · 1.44 KB
/
ControllerInitialStateContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
public static class ControllerInitialState
{
[MenuItem("Assets/Set Initial State", false, 16)]
private static void SetInitialStates()
{
List<AnimatorController> conts = GetSelectedControllers();
if (conts != null && conts.Count > 0)
{
foreach (AnimatorController con in conts)
{
SetInitialState(con);
}
}
}
public static List<AnimatorController> GetSelectedControllers()
{
var conts = Selection.GetFiltered(typeof(AnimatorController), SelectionMode.Assets);
List<AnimatorController> animConts = new List<AnimatorController>();
if (conts.Length > 0)
{
foreach (var cont in conts)
{
animConts.Add(cont as AnimatorController);
}
return animConts;
}
return null;
}
private static void SetInitialState(AnimatorController cont)
{
AnimatorStateMachine asm = cont.layers[0].stateMachine;
AnimatorState newState = asm.AddState("Default State");
asm.defaultState = newState;
}
[MenuItem("Assets/Set Initial State", true)]
static bool SetInitialStateValidation()
{
return Selection.activeObject && Selection.activeObject.GetType() == typeof(AnimatorController);
}
}