-
Notifications
You must be signed in to change notification settings - Fork 4
/
ActorConstraint.cs
85 lines (74 loc) · 1.7 KB
/
ActorConstraint.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
using System;
using System.IO;
using System.Collections.Generic;
namespace Nima
{
public abstract class ActorConstraint : ActorComponent
{
protected bool m_IsEnabled;
protected float m_Strength;
public bool IsEnabled
{
get
{
return m_IsEnabled;
}
set
{
if(value == m_IsEnabled)
{
return;
}
m_IsEnabled = value;
MarkDirty();
}
}
public override void OnDirty(byte dirt)
{
MarkDirty();
}
public float Strength
{
get
{
return m_Strength;
}
set
{
if(value == m_Strength)
{
return;
}
m_Strength = value;
MarkDirty();
}
}
protected void MarkDirty()
{
m_Parent.MarkTransformDirty();
}
public abstract void Constrain(ActorNode node);
public override void ResolveComponentIndices(ActorComponent[] components)
{
base.ResolveComponentIndices(components);
if(m_Parent != null)
{
// This works because nodes are exported in hierarchy order, so we are assured constraints get added in order as we resolve indices.
m_Parent.AddConstraint(this);
}
}
public static ActorConstraint Read(Actor actor, BinaryReader reader, ActorConstraint component)
{
ActorComponent.Read(actor, reader, component);
component.m_Strength = reader.ReadSingle();
component.m_IsEnabled = reader.ReadByte() == 1;
return component;
}
public void Copy(ActorConstraint node, Actor resetActor)
{
base.Copy(node, resetActor);
m_IsEnabled = node.m_IsEnabled;
m_Strength = node.m_Strength;
}
}
}