/
StateMachine.cs
750 lines (609 loc) · 27.7 KB
/
StateMachine.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.Linq;
namespace UnityEditor.Animations
{
internal struct PushUndoIfNeeded
{
public bool pushUndo
{
get { return impl.m_PushUndo; }
set { impl.m_PushUndo = value; }
}
public PushUndoIfNeeded(bool pushUndo)
{
m_Impl = new PushUndoIfNeededImpl(pushUndo);
}
public void DoUndo(Object target, string undoOperation)
{
impl.DoUndo(target, undoOperation);
}
public void DoUndoCreated(Object target, string undoOperation)
{
impl.DoUndoCreated(target, undoOperation);
}
PushUndoIfNeededImpl impl
{
get
{
if (m_Impl == null)
m_Impl = new PushUndoIfNeededImpl(true);
return m_Impl;
}
}
PushUndoIfNeededImpl m_Impl;
private class PushUndoIfNeededImpl
{
public PushUndoIfNeededImpl(bool pushUndo)
{
m_PushUndo = pushUndo;
}
public void DoUndo(Object target, string undoOperation)
{
if (m_PushUndo)
{
Undo.RegisterCompleteObjectUndo(target, undoOperation);
}
}
public void DoUndoCreated(Object target, string undoOperation)
{
if (m_PushUndo)
{
Undo.RegisterCreatedObjectUndo(target, undoOperation);
}
}
public bool m_PushUndo;
}
}
public partial class AnimatorTransitionBase : Object
{
private PushUndoIfNeeded undoHandler = new PushUndoIfNeeded(true);
internal bool pushUndo { set { undoHandler.pushUndo = value; } }
public void AddCondition(AnimatorConditionMode mode, float threshold, string parameter)
{
undoHandler.DoUndo(this, "Condition added");
AnimatorCondition[] conditionVector = conditions;
AnimatorCondition newCondition = new AnimatorCondition();
newCondition.mode = mode;
newCondition.parameter = parameter;
newCondition.threshold = threshold;
ArrayUtility.Add(ref conditionVector, newCondition);
conditions = conditionVector;
}
public void RemoveCondition(AnimatorCondition condition)
{
undoHandler.DoUndo(this, "Condition removed");
AnimatorCondition[] conditionVector = conditions;
ArrayUtility.Remove(ref conditionVector, condition);
conditions = conditionVector;
}
}
internal class AnimatorDefaultTransition : ScriptableObject
{
}
public partial class AnimatorState : Object
{
private PushUndoIfNeeded undoHandler = new PushUndoIfNeeded(true);
internal bool pushUndo { set { undoHandler.pushUndo = value; } }
public void AddTransition(AnimatorStateTransition transition)
{
undoHandler.DoUndo(this, "Transition added");
AnimatorStateTransition[] transitionsVector = transitions;
ArrayUtility.Add(ref transitionsVector, transition);
transitions = transitionsVector;
}
public void RemoveTransition(AnimatorStateTransition transition)
{
undoHandler.DoUndo(this, "Transition removed");
AnimatorStateTransition[] transitionsVector = transitions;
ArrayUtility.Remove(ref transitionsVector, transition);
transitions = transitionsVector;
if (MecanimUtilities.AreSameAsset(this, transition))
Undo.DestroyObjectImmediate(transition);
}
private AnimatorStateTransition CreateTransition(bool setDefaultExitTime)
{
AnimatorStateTransition newTransition = new AnimatorStateTransition();
newTransition.hasExitTime = false;
newTransition.hasFixedDuration = true;
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(newTransition, AssetDatabase.GetAssetPath(this));
newTransition.hideFlags = HideFlags.HideInHierarchy;
undoHandler.DoUndoCreated(newTransition, "Transition Created");
if (setDefaultExitTime)
SetDefaultTransitionExitTime(ref newTransition);
return newTransition;
}
private void SetDefaultTransitionExitTime(ref AnimatorStateTransition newTransition)
{
newTransition.hasExitTime = true;
if (motion != null && motion.averageDuration > 0.0f)
{
const float transitionDefaultDuration = 0.25f;
float transitionDurationNormalized = transitionDefaultDuration / motion.averageDuration;
newTransition.duration = transitionDefaultDuration;
newTransition.exitTime = 1.0f - transitionDurationNormalized;
}
else
{
newTransition.duration = 0.25f;
newTransition.exitTime = 0.75f;
}
}
public AnimatorStateTransition AddTransition(AnimatorState destinationState)
{
AnimatorStateTransition newTransition = CreateTransition(false);
newTransition.destinationState = destinationState;
AddTransition(newTransition);
return newTransition;
}
public AnimatorStateTransition AddTransition(AnimatorStateMachine destinationStateMachine)
{
AnimatorStateTransition newTransition = CreateTransition(false);
newTransition.destinationStateMachine = destinationStateMachine;
AddTransition(newTransition);
return newTransition;
}
public AnimatorStateTransition AddTransition(AnimatorState destinationState, bool defaultExitTime)
{
AnimatorStateTransition newTransition = CreateTransition(defaultExitTime);
newTransition.destinationState = destinationState;
AddTransition(newTransition);
return newTransition;
}
public AnimatorStateTransition AddTransition(AnimatorStateMachine destinationStateMachine, bool defaultExitTime)
{
AnimatorStateTransition newTransition = CreateTransition(defaultExitTime);
newTransition.destinationStateMachine = destinationStateMachine;
AddTransition(newTransition);
return newTransition;
}
public AnimatorStateTransition AddExitTransition()
{
return AddExitTransition(false);
}
public AnimatorStateTransition AddExitTransition(bool defaultExitTime)
{
AnimatorStateTransition newTransition = CreateTransition(defaultExitTime);
newTransition.isExit = true;
AddTransition(newTransition);
return newTransition;
}
internal AnimatorStateMachine FindParent(AnimatorStateMachine root)
{
if (root.HasState(this, false)) return root;
else return root.stateMachinesRecursive.Find(sm => sm.stateMachine.HasState(this, false)).stateMachine;
}
internal AnimatorStateTransition FindTransition(AnimatorState destinationState) // pp todo return a list?
{
return (new List<AnimatorStateTransition>(transitions)).Find(t => t.destinationState == destinationState);
}
[System.Obsolete("uniqueName does not exist anymore. Consider using .name instead.", true)]
public string uniqueName
{
get { return ""; }
}
[System.Obsolete("GetMotion() is obsolete. Use motion", true)]
public Motion GetMotion()
{
return null;
}
[System.Obsolete("uniqueNameHash does not exist anymore.", true)]
public int uniqueNameHash
{
get { return -1; }
}
}
public partial class AnimatorStateMachine : Object
{
private PushUndoIfNeeded undoHandler = new PushUndoIfNeeded(true);
internal bool pushUndo { set { undoHandler.pushUndo = value; } }
internal class StateMachineCache
{
static Dictionary<AnimatorStateMachine, ChildAnimatorStateMachine[]> m_ChildStateMachines;
static bool m_Initialized;
static void Init()
{
if (!m_Initialized)
{
m_ChildStateMachines = new Dictionary<AnimatorStateMachine, ChildAnimatorStateMachine[]>();
m_Initialized = true;
}
}
static public void Clear()
{
Init();
m_ChildStateMachines.Clear();
}
static public ChildAnimatorStateMachine[] GetChildStateMachines(AnimatorStateMachine parent)
{
Init();
ChildAnimatorStateMachine[] children;
if (m_ChildStateMachines.TryGetValue(parent, out children) == false)
{
children = parent.stateMachines;
m_ChildStateMachines.Add(parent, children);
}
return children;
}
}
internal List<ChildAnimatorState> statesRecursive
{
get
{
List<ChildAnimatorState> ret = new List<ChildAnimatorState>();
ret.AddRange(states);
for (int j = 0; j < stateMachines.Length; j++)
{
ret.AddRange(stateMachines[j].stateMachine.statesRecursive);
}
return ret;
}
}
internal List<ChildAnimatorStateMachine> stateMachinesRecursive
{
get
{
List<ChildAnimatorStateMachine> ret = new List<ChildAnimatorStateMachine>();
var childStateMachines = AnimatorStateMachine.StateMachineCache.GetChildStateMachines(this);
ret.AddRange(childStateMachines);
for (int j = 0; j < childStateMachines.Length; j++)
{
ret.AddRange(childStateMachines[j].stateMachine.stateMachinesRecursive);
}
return ret;
}
}
internal List<AnimatorStateTransition> anyStateTransitionsRecursive
{
get
{
List<AnimatorStateTransition> childTransitions = new List<AnimatorStateTransition>();
childTransitions.AddRange(anyStateTransitions);
foreach (ChildAnimatorStateMachine stateMachine in stateMachines)
{
childTransitions.AddRange(stateMachine.stateMachine.anyStateTransitionsRecursive);
}
return childTransitions;
}
}
internal Vector3 GetStatePosition(AnimatorState state)
{
ChildAnimatorState[] animatorStates = states;
for (int i = 0; i < animatorStates.Length; i++)
if (state == animatorStates[i].state)
return animatorStates[i].position;
System.Diagnostics.Debug.Fail("Can't find state (" + state.name + ") in parent state machine (" + name + ").");
return Vector3.zero;
}
internal void SetStatePosition(AnimatorState state, Vector3 position)
{
ChildAnimatorState[] childStates = states;
for (int i = 0; i < childStates.Length; i++)
if (state == childStates[i].state)
{
childStates[i].position = position;
states = childStates;
return;
}
System.Diagnostics.Debug.Fail("Can't find state (" + state.name + ") in parent state machine (" + name + ").");
}
internal Vector3 GetStateMachinePosition(AnimatorStateMachine stateMachine)
{
ChildAnimatorStateMachine[] childSM = stateMachines;
for (int i = 0; i < childSM.Length; i++)
if (stateMachine == childSM[i].stateMachine)
return childSM[i].position;
System.Diagnostics.Debug.Fail("Can't find state machine (" + stateMachine.name + ") in parent state machine (" + name + ").");
return Vector3.zero;
}
internal void SetStateMachinePosition(AnimatorStateMachine stateMachine, Vector3 position)
{
ChildAnimatorStateMachine[] childSM = stateMachines;
for (int i = 0; i < childSM.Length; i++)
if (stateMachine == childSM[i].stateMachine)
{
childSM[i].position = position;
stateMachines = childSM;
return;
}
System.Diagnostics.Debug.Fail("Can't find state machine (" + stateMachine.name + ") in parent state machine (" + name + ").");
}
public AnimatorState AddState(string name)
{
return AddState(name, states.Length > 0 ? states[states.Length - 1].position + new Vector3(35, 65) : new Vector3(200, 0, 0));
}
public AnimatorState AddState(string name, Vector3 position)
{
AnimatorState state = new AnimatorState();
state.hideFlags = HideFlags.HideInHierarchy;
state.name = MakeUniqueStateName(name);
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(state, AssetDatabase.GetAssetPath(this));
undoHandler.DoUndoCreated(state, "State Created");
AddState(state, position);
return state;
}
public void AddState(AnimatorState state, Vector3 position)
{
ChildAnimatorState[] childStates = states;
if (System.Array.Exists(childStates, childState => childState.state == state))
{
Debug.LogWarning(System.String.Format("State '{0}' already exists in state machine '{1}', discarding new state.", state.name, name));
return;
}
undoHandler.DoUndo(this, "State added");
ChildAnimatorState newState = new ChildAnimatorState();
newState.state = state;
newState.position = position;
ArrayUtility.Add(ref childStates, newState);
states = childStates;
}
public void RemoveState(AnimatorState state)
{
undoHandler.DoUndo(this, "State removed");
undoHandler.DoUndo(state, "State removed");
RemoveStateInternal(state);
}
public AnimatorStateMachine AddStateMachine(string name)
{
return AddStateMachine(name, Vector3.zero);
}
public AnimatorStateMachine AddStateMachine(string name, Vector3 position)
{
AnimatorStateMachine stateMachine = new AnimatorStateMachine();
stateMachine.hideFlags = HideFlags.HideInHierarchy;
stateMachine.name = MakeUniqueStateMachineName(name);
AddStateMachine(stateMachine, position);
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(stateMachine, AssetDatabase.GetAssetPath(this));
undoHandler.DoUndoCreated(stateMachine, "StateMachine Created");
return stateMachine;
}
public void AddStateMachine(AnimatorStateMachine stateMachine, Vector3 position)
{
ChildAnimatorStateMachine[] childStateMachines = stateMachines;
if (System.Array.Exists(childStateMachines, childStateMachine => childStateMachine.stateMachine == stateMachine))
{
Debug.LogWarning(System.String.Format("Sub state machine '{0}' already exists in state machine '{1}', discarding new state machine.", stateMachine.name, name));
return;
}
undoHandler.DoUndo(this, "StateMachine " + stateMachine.name + " added");
ChildAnimatorStateMachine newStateMachine = new ChildAnimatorStateMachine();
newStateMachine.stateMachine = stateMachine;
newStateMachine.position = position;
ArrayUtility.Add(ref childStateMachines, newStateMachine);
stateMachines = childStateMachines;
}
public void RemoveStateMachine(AnimatorStateMachine stateMachine)
{
undoHandler.DoUndo(this, "StateMachine removed");
undoHandler.DoUndo(stateMachine, "StateMachine removed");
RemoveStateMachineInternal(stateMachine);
}
private AnimatorStateTransition AddAnyStateTransition()
{
AnimatorStateTransition newTransition = new AnimatorStateTransition();
newTransition.hasExitTime = false;
newTransition.hasFixedDuration = true;
newTransition.duration = 0.25f;
newTransition.exitTime = 0.75f;
newTransition.hideFlags = HideFlags.HideInHierarchy;
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(newTransition, AssetDatabase.GetAssetPath(this));
undoHandler.DoUndoCreated(newTransition, "AnyState Transition Created");
undoHandler.DoUndo(this, "AnyState Transition Added");
AnimatorStateTransition[] transitionsVector = anyStateTransitions;
ArrayUtility.Add(ref transitionsVector, newTransition);
anyStateTransitions = transitionsVector;
return newTransition;
}
public AnimatorStateTransition AddAnyStateTransition(AnimatorState destinationState)
{
AnimatorStateTransition newTransition = AddAnyStateTransition();
newTransition.destinationState = destinationState;
return newTransition;
}
public AnimatorStateTransition AddAnyStateTransition(AnimatorStateMachine destinationStateMachine)
{
AnimatorStateTransition newTransition = AddAnyStateTransition();
newTransition.destinationStateMachine = destinationStateMachine;
return newTransition;
}
public bool RemoveAnyStateTransition(AnimatorStateTransition transition)
{
if ((new List<AnimatorStateTransition>(anyStateTransitions)).Any(t => t == transition))
{
undoHandler.DoUndo(this, "AnyState Transition Removed");
AnimatorStateTransition[] transitionsVector = anyStateTransitions;
ArrayUtility.Remove(ref transitionsVector, transition);
anyStateTransitions = transitionsVector;
if (MecanimUtilities.AreSameAsset(this, transition))
Undo.DestroyObjectImmediate(transition);
return true;
}
return false;
}
internal void RemoveAnyStateTransitionRecursive(AnimatorStateTransition transition)
{
if (RemoveAnyStateTransition(transition))
return;
List<ChildAnimatorStateMachine> childStateMachines = stateMachinesRecursive;
foreach (ChildAnimatorStateMachine sm in childStateMachines)
{
if (sm.stateMachine.RemoveAnyStateTransition(transition))
return;
}
}
public AnimatorTransition AddStateMachineTransition(AnimatorStateMachine sourceStateMachine)
{
AnimatorTransition newTransition = new AnimatorTransition();
AddStateMachineTransition(sourceStateMachine, newTransition);
return newTransition;
}
public AnimatorTransition AddStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorStateMachine destinationStateMachine)
{
var newTransition = new AnimatorTransition();
newTransition.destinationStateMachine = destinationStateMachine;
AddStateMachineTransition(sourceStateMachine, newTransition);
return newTransition;
}
public AnimatorTransition AddStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorState destinationState)
{
var newTransition = new AnimatorTransition();
newTransition.destinationState = destinationState;
AddStateMachineTransition(sourceStateMachine, newTransition);
return newTransition;
}
internal void AddStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorTransition transition)
{
transition.hideFlags = HideFlags.HideInHierarchy;
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(transition, AssetDatabase.GetAssetPath(this));
undoHandler.DoUndoCreated(transition, "StateMachine Transition Created");
undoHandler.DoUndo(this, "StateMachine Transition Added");
AnimatorTransition[] transitionsVector = GetStateMachineTransitions(sourceStateMachine);
ArrayUtility.Add(ref transitionsVector, transition);
SetStateMachineTransitions(sourceStateMachine, transitionsVector);
}
public AnimatorTransition AddStateMachineExitTransition(AnimatorStateMachine sourceStateMachine)
{
var newTransition = new AnimatorTransition();
newTransition.isExit = true;
AddStateMachineTransition(sourceStateMachine, newTransition);
return newTransition;
}
public bool RemoveStateMachineTransition(AnimatorStateMachine sourceStateMachine, AnimatorTransition transition)
{
undoHandler.DoUndo(this, "StateMachine Transition Removed");
AnimatorTransition[] transitionsVector = GetStateMachineTransitions(sourceStateMachine);
int baseSize = transitionsVector.Length;
ArrayUtility.Remove(ref transitionsVector, transition);
SetStateMachineTransitions(sourceStateMachine, transitionsVector);
if (MecanimUtilities.AreSameAsset(this, transition))
Undo.DestroyObjectImmediate(transition);
return baseSize != transitionsVector.Length;
}
private AnimatorTransition AddEntryTransition()
{
AnimatorTransition newTransition = new AnimatorTransition();
newTransition.hideFlags = HideFlags.HideInHierarchy;
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(newTransition, AssetDatabase.GetAssetPath(this));
undoHandler.DoUndoCreated(newTransition, "Entry Transition Created");
undoHandler.DoUndo(this, "Entry Transition Added");
AnimatorTransition[] transitionsVector = entryTransitions;
ArrayUtility.Add(ref transitionsVector, newTransition);
entryTransitions = transitionsVector;
return newTransition;
}
public AnimatorTransition AddEntryTransition(AnimatorState destinationState)
{
AnimatorTransition newTransition = AddEntryTransition();
newTransition.destinationState = destinationState;
return newTransition;
}
public AnimatorTransition AddEntryTransition(AnimatorStateMachine destinationStateMachine)
{
AnimatorTransition newTransition = AddEntryTransition();
newTransition.destinationStateMachine = destinationStateMachine;
return newTransition;
}
public bool RemoveEntryTransition(AnimatorTransition transition)
{
if ((new List<AnimatorTransition>(entryTransitions)).Any(t => t == transition))
{
undoHandler.DoUndo(this, "Entry Transition Removed");
AnimatorTransition[] transitionsVector = entryTransitions;
ArrayUtility.Remove(ref transitionsVector, transition);
entryTransitions = transitionsVector;
if (MecanimUtilities.AreSameAsset(this, transition))
Undo.DestroyObjectImmediate(transition);
return true;
}
return false;
}
internal ChildAnimatorState FindState(int nameHash)
{
return (new List<ChildAnimatorState>(states)).Find(s => s.state.nameHash == nameHash);
}
internal ChildAnimatorState FindState(string name)
{
return (new List<ChildAnimatorState>(states)).Find(s => s.state.name == name);
}
internal bool HasState(AnimatorState state)
{
return statesRecursive.Any(s => s.state == state);
}
internal bool IsDirectParent(AnimatorStateMachine stateMachine)
{
return stateMachines.Any(sm => sm.stateMachine == stateMachine);
}
internal bool HasStateMachine(AnimatorStateMachine child)
{
return stateMachinesRecursive.Any(sm => sm.stateMachine == child);
}
internal bool HasTransition(AnimatorState stateA, AnimatorState stateB)
{
return stateA.transitions.Any(t => t.destinationState == stateB) ||
stateB.transitions.Any(t => t.destinationState == stateA);
}
internal AnimatorStateMachine FindParent(AnimatorStateMachine stateMachine)
{
if (stateMachines.Any(childSM => childSM.stateMachine == stateMachine))
return this;
else
return stateMachinesRecursive.Find(sm => sm.stateMachine.stateMachines.Any(childSM => childSM.stateMachine == stateMachine)).stateMachine;
}
internal AnimatorStateMachine FindStateMachine(string path)
{
string[] smNames = path.Split('.');
// first element is always Root statemachine 'this'
AnimatorStateMachine currentSM = this;
// last element is state name, we don't care
for (int i = 1; i < smNames.Length - 1 && currentSM != null; ++i)
{
var childStateMachines = AnimatorStateMachine.StateMachineCache.GetChildStateMachines(currentSM);
int index = System.Array.FindIndex(childStateMachines, t => t.stateMachine.name == smNames[i]);
currentSM = index >= 0 ? childStateMachines[index].stateMachine : null;
}
return (currentSM == null) ? this : currentSM;
}
internal AnimatorStateMachine FindStateMachine(AnimatorState state)
{
if (HasState(state, false))
return this;
List<ChildAnimatorStateMachine> childStateMachines = stateMachinesRecursive;
int index = childStateMachines.FindIndex(sm => sm.stateMachine.HasState(state, false));
return index >= 0 ? childStateMachines[index].stateMachine : null;
}
internal AnimatorStateTransition FindTransition(AnimatorState destinationState)
{
return (new List<AnimatorStateTransition>(anyStateTransitions)).Find(t => t.destinationState == destinationState);
}
[System.Obsolete("stateCount is obsolete. Use .states.Length instead.", true)]
int stateCount
{
get { return 0; }
}
[System.Obsolete("stateMachineCount is obsolete. Use .stateMachines.Length instead.", true)]
int stateMachineCount
{
get { return 0; }
}
[System.Obsolete("GetTransitionsFromState is obsolete. Use AnimatorState.transitions instead.", true)]
AnimatorState GetTransitionsFromState(AnimatorState state)
{
return null;
}
[System.Obsolete("uniqueNameHash does not exist anymore.", true)]
int uniqueNameHash
{
get { return -1; }
}
}
}