HKI Core
Vector2.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Xml;
3 
4 namespace HKI.Core.Variables
5 {
11  [System.Serializable]
12  [HKIVarBasic]
13  [CreateAssetMenu(fileName = "Vector2", menuName = "HKI/Variables/Vector2", order = 5)]
14  public class Vector2 : HKIVarGeneric<UnityEngine.Vector2>
15  {
16  // Interface functions
17  public override void Save(XmlNode parentNode)
18  {
19  XmlNode node = parentNode.OwnerDocument.CreateElement(name.Replace(" ", ""));
20  parentNode.AppendChild(node);
21 
22  XmlAttribute valueXAttribute = parentNode.OwnerDocument.CreateAttribute("ValueX");
23  valueXAttribute.Value = Value.x.ToString();
24  node.Attributes.Append(valueXAttribute);
25 
26  XmlAttribute valueYAttribute = parentNode.OwnerDocument.CreateAttribute("ValueY");
27  valueYAttribute.Value = Value.y.ToString();
28  node.Attributes.Append(valueYAttribute);
29  }
30 
31  public override void Load(XmlNode node)
32  {
33  if(node.Attributes == null)
34  {
35  Debug.LogError("(Vector2) >" + name + "< Loading failed because this XmlNode has not attributes!");
36  return;
37  }
38 
39  XmlAttribute valueXAttribute = node.Attributes["ValueX"];
40  if(valueXAttribute == null)
41  {
42  Debug.LogError("(Vector2) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueX<!");
43  return;
44  }
45 
46  XmlAttribute valueYAttribute = node.Attributes["ValueY"];
47  if(valueYAttribute == null)
48  {
49  Debug.LogError("(Vector2) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueY<!");
50  return;
51  }
52 
53  float parsedXValue;
54  if(!float.TryParse(valueXAttribute.Value, out parsedXValue))
55  Debug.LogError("(Vector2) >" + name + "< Loading failed because parsing of >" + valueXAttribute.Value + "< failed!");
56 
57  float parsedYValue;
58  if (!float.TryParse(valueYAttribute.Value, out parsedYValue))
59  Debug.LogError("(Vector2) >" + name + "< Loading failed because parsing of >" + valueYAttribute.Value + "< failed!");
60 
61  SetValue = new UnityEngine.Vector2(parsedXValue, parsedYValue);
62  }
63  }
64 }
override void Load(XmlNode node)
Definition: Vector2.cs:31
override void Save(XmlNode parentNode)
Definition: Vector2.cs:17
Implementation of a Vector2 value as a HKIVar via HKIVarGeneric.
Definition: Vector2.cs:14
This class adds a generic implementation to HKIVar. This reduces the repetitive implementation of thi...