-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
BlendTree.cs
97 lines (82 loc) · 2.94 KB
/
BlendTree.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
// 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 UnityEditor.Animations;
using System.Linq;
namespace UnityEditor.Animations
{
[ExcludeFromPreset]
public partial class BlendTree : Motion
{
public void AddChild(Motion motion)
{
AddChild(motion, Vector2.zero, 0);
}
public void AddChild(Motion motion, Vector2 position)
{
AddChild(motion, position, 0);
}
public void AddChild(Motion motion, float threshold)
{
AddChild(motion, Vector2.zero, threshold);
}
public void RemoveChild(int index)
{
Undo.RecordObject(this, "Remove Child");
ChildMotion[] childMotions = children;
ArrayUtility.RemoveAt(ref childMotions, index);
children = childMotions;
}
internal void AddChild(Motion motion, Vector2 position, float threshold)
{
Undo.RecordObject(this, "Added BlendTree Child");
ChildMotion[] childMotions = children;
ChildMotion newMotion = new ChildMotion();
newMotion.timeScale = 1;
newMotion.motion = motion;
newMotion.position = position;
newMotion.threshold = threshold;
newMotion.directBlendParameter = "Blend";
ArrayUtility.Add(ref childMotions, newMotion);
children = childMotions;
}
public BlendTree CreateBlendTreeChild(float threshold)
{
return CreateBlendTreeChild(Vector2.zero, threshold);
}
public BlendTree CreateBlendTreeChild(Vector2 position)
{
return CreateBlendTreeChild(position, 0);
}
internal bool HasChild(BlendTree childTree, bool recursive)
{
foreach (ChildMotion child in children)
{
if (child.motion == childTree)
{
return true;
}
if (recursive && child.motion is BlendTree && (child.motion as BlendTree).HasChild(childTree, true))
{
return true;
}
}
return false;
}
internal BlendTree CreateBlendTreeChild(Vector2 position, float threshold)
{
BlendTree tree = new BlendTree();
tree.name = "BlendTree";
tree.hideFlags = HideFlags.HideInHierarchy;
if (AssetDatabase.GetAssetPath(this) != "")
AssetDatabase.AddObjectToAsset(tree, AssetDatabase.GetAssetPath(this));
Undo.RegisterCreatedObjectUndo(tree, "Blend Tree Created");
Undo.RecordObject(this, "Created BlendTree Child");
AddChild(tree, position, threshold);
return tree;
}
}
}