HKI Core
Vector3.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 = "Vector3", menuName = "HKI/Variables/Vector3", order = 6)]
14  public class Vector3 : HKIVarGeneric<UnityEngine.Vector3>
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  XmlAttribute valueZAttribute = parentNode.OwnerDocument.CreateAttribute("ValueZ");
31  valueZAttribute.Value = Value.z.ToString();
32  node.Attributes.Append(valueZAttribute);
33  }
34 
35  public override void Load(XmlNode node)
36  {
37  if (node.Attributes == null)
38  {
39  Debug.LogError("(Vector3) >" + name + "< Loading failed because this XmlNode has not attributes!");
40  return;
41  }
42 
43  XmlAttribute valueXAttribute = node.Attributes["ValueX"];
44  if (valueXAttribute == null)
45  {
46  Debug.LogError("(Vector3) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueX<!");
47  return;
48  }
49 
50  XmlAttribute valueYAttribute = node.Attributes["ValueY"];
51  if (valueYAttribute == null)
52  {
53  Debug.LogError("(Vector3) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueY<!");
54  return;
55  }
56 
57  XmlAttribute valueZAttribute = node.Attributes["ValueZ"];
58  if(valueZAttribute == null)
59  {
60  Debug.LogError("(Vector3) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueZ<!");
61  return;
62  }
63 
64  float parsedXValue;
65  if (!float.TryParse(valueXAttribute.Value, out parsedXValue))
66  Debug.LogError("(Vector3) >" + name + "< Loading failed because parsing of >" + valueXAttribute.Value + "< failed!");
67 
68  float parsedYValue;
69  if (!float.TryParse(valueYAttribute.Value, out parsedYValue))
70  Debug.LogError("(Vector3) >" + name + "< Loading failed because parsing of >" + valueYAttribute.Value + "< failed!");
71 
72  float parsedZValue;
73  if (!float.TryParse(valueZAttribute.Value, out parsedZValue))
74  Debug.LogError("(Vector3) >" + name + "< Loading failed because parsing of >" + valueZAttribute.Value + "< failed!");
75 
76  SetValue = new UnityEngine.Vector3(parsedXValue, parsedYValue, parsedZValue);
77  }
78  }
79 }
override void Save(XmlNode parentNode)
Definition: Vector3.cs:17
Implementation of a Vector3 value as a HKIVar via HKIVarGeneric.
Definition: Vector3.cs:14
override void Load(XmlNode node)
Definition: Vector3.cs:35
This class adds a generic implementation to HKIVar. This reduces the repetitive implementation of thi...