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