HKI Core
FloatWidthHeight.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  public class FloatWidthHeight : HKIVarGeneric<FloatingPointWidthHeight>
16  {
17  // Interface functions
18  public override void Save(XmlNode parentNode)
19  {
20  XmlNode node = parentNode.OwnerDocument.CreateElement(name.Replace(" ", ""));
21  parentNode.AppendChild(node);
22 
23  XmlAttribute valueWidthAttribute = parentNode.OwnerDocument.CreateAttribute("ValueWidth");
24  valueWidthAttribute.Value = Value.Width.ToString();
25  node.Attributes.Append(valueWidthAttribute);
26 
27  XmlAttribute valueHeightAttribute = parentNode.OwnerDocument.CreateAttribute("ValueHeight");
28  valueHeightAttribute.Value = Value.Height.ToString();
29  node.Attributes.Append(valueHeightAttribute);
30  }
31 
32  public override void Load(XmlNode node)
33  {
34  if (node.Attributes == null)
35  {
36  Debug.LogError("(FloatWidthHeight) >" + name + "< Loading failed because this XmlNode has not attributes!");
37  return;
38  }
39 
40  XmlAttribute valueWidthAttribute = node.Attributes["ValueWidth"];
41  if(valueWidthAttribute == null)
42  {
43  Debug.LogError("(FloatWidthHeight) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueWidth<!");
44  return;
45  }
46 
47  XmlAttribute valueHeightAttribute = node.Attributes["ValueHeight"];
48  if (valueHeightAttribute == null)
49  {
50  Debug.LogError("(FloatWidthHeight) >" + name + "< Loading failed because this XmlNode has not an attribute with the name >ValueHeight<!");
51  return;
52  }
53 
54  float parsedWidthValue;
55  if (!float.TryParse(valueWidthAttribute.Value, out parsedWidthValue))
56  Debug.LogError("(FloatWidthHeight) >" + name + "< Loading failed because parsing of >" + valueWidthAttribute.Value + "< failed!");
57 
58  float parsedHeightValue;
59  if (!float.TryParse(valueHeightAttribute.Value, out parsedHeightValue))
60  Debug.LogError("(FloatWidthHeight) >" + name + "< Loading failed because parsing of >" + valueHeightAttribute.Value + "< failed!");
61 
62  SetValue = new FloatingPointWidthHeight { Width = parsedWidthValue, Height = parsedHeightValue };
63  }
64  }
65 }
override void Load(XmlNode node)
override void Save(XmlNode parentNode)
This is a data type that combines a float width and a float height value into one value...
Implementation of a FloatingPointWidthHeight value as a HKIVar via HKIVarGeneric. ...
This class adds a generic implementation to HKIVar. This reduces the repetitive implementation of thi...