本文整理汇总了C#中GameObject.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.SetValue方法的具体用法?C# GameObject.SetValue怎么用?C# GameObject.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.SetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Template
public void Template()
{
GameObject.CreateProperty<float>("X", "Layout", "blah", 0);
GameObject.CreateProperty<float>("Y", "Layout", "blah", 0);
GameObject.CreateProperty<float>("Z", "Layout", "blah", 0);
GameObject.CreateProperty<float>("W", "Layout", "blah", 0);
var t = new GameObject();
t.SetValue("X", 10.0f);
t.SetValue("Y", 20.0f);
t.SetValue("Z", 30.0f);
var a = new GameObject();
Assert.AreEqual(0, a.GetValue<float>("X"));
a.Template = t;
Assert.AreEqual(10, a.GetValue<float>("X"));
Assert.AreEqual(20, a.GetValue<float>("Y"));
Assert.AreEqual(30, a.GetValue<float>("Z"));
Assert.IsFalse(a.Properties.Get<float>("X").HasLocalValue);
Assert.IsFalse(a.Properties.Get<float>("Y").HasLocalValue);
Assert.IsFalse(a.Properties.Get<float>("Z").HasLocalValue);
a.SetValue("Y", 999.0f);
Assert.AreEqual(10, a.GetValue<float>("X"));
Assert.AreEqual(999, a.GetValue<float>("Y"));
Assert.AreEqual(30, a.GetValue<float>("Z"));
Assert.IsFalse(a.Properties.Get<float>("X").HasLocalValue);
Assert.IsTrue(a.Properties.Get<float>("Y").HasLocalValue);
Assert.IsFalse(a.Properties.Get<float>("Z").HasLocalValue);
a.Properties.Get<float>("Y").Reset();
Assert.AreEqual(10, a.GetValue<float>("X"));
Assert.AreEqual(20, a.GetValue<float>("Y"));
Assert.AreEqual(30, a.GetValue<float>("Z"));
Assert.IsFalse(a.Properties.Get<float>("X").HasLocalValue);
Assert.IsFalse(a.Properties.Get<float>("Y").HasLocalValue);
Assert.IsFalse(a.Properties.Get<float>("Z").HasLocalValue);
// Enumerate properties.
Assert.AreEqual(3, ((IEnumerable)a.Properties).Cast<IGameProperty>().Count());
_wasCalled = false;
a.TemplateChanged += (s, e) => _wasCalled = true;
a.Template = t;
Assert.IsFalse(_wasCalled);
a.Template = null;
Assert.IsTrue(_wasCalled);
}
示例2: PropertyChanged
public void PropertyChanged()
{
GameObject.CreateProperty<float>("X", "Layout", "blah", 1);
var a = new GameObject();
var p = a.Properties.Get<float>("X");
_wasCalled = false;
float oldValue = 1;
float newValue = 11;
p.Changed += OnPropertyChanged;
p.Changed += (s, e) => Assert.AreEqual(a, s);
p.Changed += (s, e) => Assert.AreEqual(p, e.Property);
p.Changed += (s, e) => Assert.AreEqual(oldValue, e.OldValue);
p.Changed += (s, e) => Assert.AreEqual(newValue, e.NewValue);
p.Changed += (s, e) => Assert.AreEqual(newValue, e.CoercedValue);
a.SetValue("X", 11f);
Assert.IsTrue(_wasCalled);
// Setting an equal value does not trigger event.
_wasCalled = false;
oldValue = 11;
a.SetValue("X", 11f);
Assert.IsFalse(_wasCalled);
// Test de-registration of event handler.
_wasCalled = false;
p.Changed -= OnPropertyChanged;
newValue = 5;
p.Value = 5;
Assert.IsFalse(_wasCalled);
}
示例3: PropertyChanging
public void PropertyChanging()
{
GameObject.CreateProperty<float>("X", "Layout", "blah", 1);
var a = new GameObject();
var p = a.Properties.Get<float>("X");
_wasCalled = false;
float oldValue = 1;
float newValue = 11;
p.Changing += OnPropertyChanged;
p.Changing += (s, e) => e.CoercedValue = 10;
p.Changing += (s, e) => Assert.AreEqual(a, s);
p.Changing += (s, e) => Assert.AreEqual(p, e.Property);
p.Changing += (s, e) => Assert.AreEqual(oldValue, e.OldValue);
p.Changing += (s, e) => Assert.AreEqual(newValue, e.NewValue);
p.Changing += (s, e) => Assert.LessOrEqual(e.CoercedValue, 10);
a.SetValue("X", 11f);
Assert.IsTrue(_wasCalled);
Assert.AreEqual(10, p.Value);
// Test de-registration of event handler.
_wasCalled = false;
p.Changing -= OnPropertyChanged;
oldValue = 10;
newValue = 5;
p.Value = 5;
Assert.IsFalse(_wasCalled);
}
示例4: NotifyPropertyChanged
public void NotifyPropertyChanged()
{
GameObject.CreateProperty<float>("X", "Layout", "blah", 0);
var a = new GameObject();
((INotifyPropertyChanged)a).PropertyChanged += OnPropertyChanged;
((INotifyPropertyChanged)a).PropertyChanged += (s, e) => Assert.AreEqual(a, s);
((INotifyPropertyChanged)a).PropertyChanged += (s, e) => Assert.AreEqual("X", e.PropertyName);
a.SetValue("X", 11f);
Assert.IsTrue(_wasCalled);
// Test de-registering event handler
_wasCalled = false;
((INotifyPropertyChanged)a).PropertyChanged -= OnPropertyChanged;
a.SetValue("X", 12f);
Assert.IsFalse(_wasCalled);
}