2 using System.Collections.Generic;
 
   15         set { _name = value ?? 
""; }
 
   20         get { 
return int.Parse(_name); }
 
   21         set { _name = value.ToString(); }
 
   24     public short ShortName
 
   26         get { 
return short.Parse(_name); }
 
   27         set { _name = value.ToString(); }
 
   32         get { 
return long.Parse(_name); }
 
   33         set { _name = value.ToString(); }
 
   38         get { 
return byte.Parse(_name); }
 
   39         set { _name = value.ToString(); }
 
   42     public sbyte SByteName
 
   44         get { 
return sbyte.Parse(_name); }
 
   45         set { _name = value.ToString(); }
 
   50         get { 
return char.Parse(_name); }
 
   51         set { _name = value.ToString(); }
 
   56         get { 
return uint.Parse(_name); }
 
   57         set { _name = value.ToString(); }
 
   60     public ushort UShortName
 
   62         get { 
return ushort.Parse(_name); }
 
   63         set { _name = value.ToString(); }
 
   66     public ulong ULongName
 
   68         get { 
return ulong.Parse(_name); }
 
   69         set { _name = value.ToString(); }
 
   72     public float FloatName
 
   74         get { 
return float.Parse(_name); }
 
   75         set { _name = value.ToString(); }
 
   78     public double DoubleName
 
   80         get { 
return double.Parse(_name); }
 
   81         set { _name = value.ToString(); }
 
   86         get { 
return bool.Parse(_name); }
 
   87         set { _name = value.ToString(); }
 
   90     public DateTime TimeName
 
   92         get { 
return DateTime.Parse(_name); }
 
   93         set { _name = value.ToString(); }
 
   96     public Vector2 Vector2Name
 
  100             string[] tokens = _name.Split();
 
  102             return new Vector2(
float.Parse(tokens[0]), 
float.Parse(tokens[1]));
 
  104         set { _name = value.x + 
" " + value.y; }
 
  107     public Vector3 Vector3Name
 
  111             string[] tokens = _name.Split();
 
  113             return new Vector3(
float.Parse(tokens[0]), 
float.Parse(tokens[1]), 
float.Parse(tokens[2]));
 
  115         set { _name = value.x + 
" " + value.y + 
" " + value.z; }
 
  118     public Vector4 Vector4Name
 
  122             string[] tokens = _name.Split();
 
  124             return new Vector4(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  125                 float.Parse(tokens[2]), 
float.Parse(tokens[3]));
 
  127         set { _name = value.x + 
" " + value.y + 
" " + value.z + 
" " + value.w; }
 
  130     public Quaternion QuaternionName
 
  134             string[] tokens = _name.Split();
 
  136             return new Quaternion(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  137                                     float.Parse(tokens[2]), 
float.Parse(tokens[3]));
 
  139         set { _name = value.x + 
" " + value.y + 
" " + value.z + 
" " + value.w; }
 
  146             string[] tokens = _name.Split();
 
  149                 new Vector3(
float.Parse(tokens[0]), 
float.Parse(tokens[0]), 
float.Parse(tokens[0])),
 
  150                 new Vector3(
float.Parse(tokens[0]), 
float.Parse(tokens[0]), 
float.Parse(tokens[0])));
 
  154             _name = value.origin.x + 
" " + value.origin.y + 
" " + value.origin.z + 
" " 
  155                 + value.direction.x + 
" " + value.direction.y + 
" " + value.direction.z;
 
  159     public Matrix4x4 MatrixName
 
  163             string[] tokens = _name.Split();
 
  165             var mat = 
new Matrix4x4();
 
  166             mat.m00 = 
float.Parse(tokens[0]);
 
  167             mat.m01 = 
float.Parse(tokens[1]);
 
  168             mat.m02 = 
float.Parse(tokens[2]);
 
  169             mat.m03 = 
float.Parse(tokens[3]);
 
  170             mat.m10 = 
float.Parse(tokens[4]);
 
  171             mat.m11 = 
float.Parse(tokens[5]);
 
  172             mat.m12 = 
float.Parse(tokens[6]);
 
  173             mat.m13 = 
float.Parse(tokens[7]);
 
  174             mat.m20 = 
float.Parse(tokens[8]);
 
  175             mat.m21 = 
float.Parse(tokens[9]);
 
  176             mat.m22 = 
float.Parse(tokens[10]);
 
  177             mat.m23 = 
float.Parse(tokens[11]);
 
  178             mat.m30 = 
float.Parse(tokens[12]);
 
  179             mat.m31 = 
float.Parse(tokens[13]);
 
  180             mat.m32 = 
float.Parse(tokens[14]);
 
  181             mat.m33 = 
float.Parse(tokens[15]);
 
  187             _name = 
string.Join(
" ", 
new string[] {
 
  188                 value.m00.ToString(),
 
  189                 value.m01.ToString(),
 
  190                 value.m02.ToString(),
 
  191                 value.m03.ToString(),
 
  192                 value.m10.ToString(),
 
  193                 value.m11.ToString(),
 
  194                 value.m12.ToString(),
 
  195                 value.m13.ToString(),
 
  196                 value.m20.ToString(),
 
  197                 value.m21.ToString(),
 
  198                 value.m22.ToString(),
 
  199                 value.m23.ToString(),
 
  200                 value.m30.ToString(),
 
  201                 value.m31.ToString(),
 
  202                 value.m32.ToString(),
 
  208     public Color ColorName
 
  212             string[] tokens = _name.Split();
 
  214             if (tokens.Length < 4)
 
  215                 return new Color(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  216                                     float.Parse(tokens[2]));
 
  217             else return new Color(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  218                                     float.Parse(tokens[2]), 
float.Parse(tokens[3]));
 
  220         set { _name = value.r + 
" " + value.g + 
" " + value.b + 
" " + value.a; }
 
  223     public GameObject GameObjectName
 
  231         get { 
return _value; }
 
  232         set { _value = value ?? 
""; }
 
  237         get { 
return int.Parse(_value); }
 
  238         set { _value = value.ToString(); }
 
  241     public short ShortValue
 
  243         get { 
return short.Parse(_value); }
 
  244         set { _value = value.ToString(); }
 
  247     public long LongValue
 
  249         get { 
return long.Parse(_value); }
 
  250         set { _value = value.ToString(); }
 
  253     public byte ByteValue
 
  255         get { 
return byte.Parse(_value); }
 
  256         set { _value = value.ToString(); }
 
  259     public sbyte SByteValue
 
  261         get { 
return sbyte.Parse(_value); }
 
  262         set { _value = value.ToString(); }
 
  265     public char CharValue
 
  267         get { 
return char.Parse(_value); }
 
  268         set { _value = value.ToString(); }
 
  271     public uint UIntValue
 
  273         get { 
return uint.Parse(_value); }
 
  274         set { _value = value.ToString(); }
 
  277     public ushort UShortValue
 
  279         get { 
return ushort.Parse(_value); }
 
  280         set { _value = value.ToString(); }
 
  283     public ulong ULongValue
 
  285         get { 
return ulong.Parse(_value); }
 
  286         set { _value = value.ToString(); }
 
  289     public float FloatValue
 
  291         get { 
return float.Parse(_value); }
 
  292         set { _value = value.ToString(); }
 
  295     public double DoubleValue
 
  297         get { 
return double.Parse(_value); }
 
  298         set { _value = value.ToString(); }
 
  301     public bool BoolValue
 
  303         get { 
return bool.Parse(_value); }
 
  304         set { _value = value.ToString(); }
 
  307     public DateTime TimeValue
 
  309         get { 
return DateTime.Parse(_value); }
 
  310         set { _value = value.ToString(); }
 
  313     public Vector2 Vector2Value
 
  317             string[] tokens = _value.Split();
 
  319             return new Vector2(
float.Parse(tokens[0]), 
float.Parse(tokens[1]));
 
  321         set { _value = value.x + 
" " + value.y; }
 
  324     public Vector3 Vector3Value
 
  328             string[] tokens = _value.Split();
 
  330             return new Vector3(
float.Parse(tokens[0]), 
float.Parse(tokens[1]), 
float.Parse(tokens[2]));
 
  332         set { _value = value.x + 
" " + value.y + 
" " + value.z; }
 
  335     public Vector4 Vector4Value
 
  339             string[] tokens = _value.Split();
 
  341             return new Vector4(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  342                 float.Parse(tokens[2]), 
float.Parse(tokens[3]));
 
  344         set { _value = value.x + 
" " + value.y + 
" " + value.z + 
" " + value.w; }
 
  347     public Quaternion QuaternionValue
 
  351             string[] tokens = _value.Split();
 
  353             return new Quaternion(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  354                                     float.Parse(tokens[2]), 
float.Parse(tokens[3]));
 
  356         set { _value = value.x + 
" " + value.y + 
" " + value.z + 
" " + value.w; }
 
  363             string[] tokens = _value.Split();
 
  366                 new Vector3(
float.Parse(tokens[0]), 
float.Parse(tokens[0]), 
float.Parse(tokens[0])),
 
  367                 new Vector3(
float.Parse(tokens[0]), 
float.Parse(tokens[0]), 
float.Parse(tokens[0])));
 
  371             _value = value.origin.x + 
" " + value.origin.y + 
" " + value.origin.z + 
" " 
  372                 + value.direction.x + 
" " + value.direction.y + 
" " + value.direction.z;
 
  376     public Matrix4x4 MatrixValue
 
  380             string[] tokens = _value.Split();
 
  382             var mat = 
new Matrix4x4();
 
  383             mat.m00 = 
float.Parse(tokens[0]);
 
  384             mat.m01 = 
float.Parse(tokens[1]);
 
  385             mat.m02 = 
float.Parse(tokens[2]);
 
  386             mat.m03 = 
float.Parse(tokens[3]);
 
  387             mat.m10 = 
float.Parse(tokens[4]);
 
  388             mat.m11 = 
float.Parse(tokens[5]);
 
  389             mat.m12 = 
float.Parse(tokens[6]);
 
  390             mat.m13 = 
float.Parse(tokens[7]);
 
  391             mat.m20 = 
float.Parse(tokens[8]);
 
  392             mat.m21 = 
float.Parse(tokens[9]);
 
  393             mat.m22 = 
float.Parse(tokens[10]);
 
  394             mat.m23 = 
float.Parse(tokens[11]);
 
  395             mat.m30 = 
float.Parse(tokens[12]);
 
  396             mat.m31 = 
float.Parse(tokens[13]);
 
  397             mat.m32 = 
float.Parse(tokens[14]);
 
  398             mat.m33 = 
float.Parse(tokens[15]);
 
  404             _value = 
string.Join(
" ", 
new string[] {
 
  405                 value.m00.ToString(),
 
  406                 value.m01.ToString(),
 
  407                 value.m02.ToString(),
 
  408                 value.m03.ToString(),
 
  409                 value.m10.ToString(),
 
  410                 value.m11.ToString(),
 
  411                 value.m12.ToString(),
 
  412                 value.m13.ToString(),
 
  413                 value.m20.ToString(),
 
  414                 value.m21.ToString(),
 
  415                 value.m22.ToString(),
 
  416                 value.m23.ToString(),
 
  417                 value.m30.ToString(),
 
  418                 value.m31.ToString(),
 
  419                 value.m32.ToString(),
 
  425     public Color ColorValue
 
  429             string[] tokens = _value.Split();
 
  431             if (tokens.Length < 4)
 
  432                 return new Color(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  433                                     float.Parse(tokens[2]));
 
  434             else return new Color(
float.Parse(tokens[0]), 
float.Parse(tokens[1]),
 
  435                                     float.Parse(tokens[2]), 
float.Parse(tokens[3]));
 
  437         set { _value = value.r + 
" " + value.g + 
" " + value.b + 
" " + value.a; }
 
  440     public GameObject GameObjectValue
 
  446     public UJeli[] Children
 
  448         get { 
return GetChildren(); }
 
  451     public string[] ChildNames
 
  453         get { 
return (from child in _children select child.Name).ToArray(); }
 
  456     public string[] ChildValues
 
  458         get { 
return (from child in _children select child.Value).ToArray(); }
 
  463         get { 
return _parent; }
 
  466     private static string[] newLines =
 
  467         new string[] { 
"\r\n", 
"\r", 
"\n", 
"\n\r" };
 
  472     List<UJeli> _children;
 
  474     public static UJeli Parse (
string text)
 
  479         foreach (
string line 
in text.Split(newLines, StringSplitOptions.RemoveEmptyEntries))
 
  481             if (line.TrimStart().StartsWith(
"//"))
 
  484             int newTabs = CountTabs(line);
 
  488                 node = node.AddChild();
 
  490             else if (newTabs < tabs)
 
  492                 UJeli sibling = node;
 
  494                 while (newTabs < tabs)
 
  496                     sibling = sibling.Parent;
 
  500                 if (sibling.Parent != null)
 
  501                     node = sibling.Parent.AddChild();
 
  506                 if (node.Parent != null)
 
  507                     node = node.Parent.AddChild();
 
  508                 else if (node._name != 
"")
 
  514             string rest = line.Substring(tabs);
 
  515             int space = rest.IndexOf(
"=");
 
  519                 node._name = rest.Substring(0, space).Trim();
 
  520                 node._value = rest.Substring(space + 1).Trim();
 
  522             else node._name = rest;
 
  525         while (node.Parent != null)
 
  533     public static UJeli Load (
string fileName)
 
  535         string fullFileName = fileName;
 
  537         if (File.Exists(fullFileName))
 
  538             return Parse(File.ReadAllText(fullFileName));
 
  542     static string WriteNode (
UJeli node, 
int tabs)
 
  546         for (
int i = 0; i < tabs; i++)
 
  555             if (node._value != 
"")
 
  556                 text += 
" = " + node._value;
 
  561         foreach (
UJeli c 
in node.GetChildren())
 
  563             text += WriteNode(c, tabs + 1);
 
  569     static int CountTabs (
string text)
 
  573         while (numTabs < text.Length && text[numTabs] == 
'\t')
 
  581     public UJeli () : 
this(
"") { }
 
  583     public UJeli (
object name) : 
this(name, 
"") { }
 
  585     public UJeli (
object name, 
object value)
 
  587         _children = 
new List<UJeli>();
 
  592                 Vector2Name = (Vector2)name;
 
  593             else if (name is Vector3)
 
  594                 Vector3Name = (Vector3)name;
 
  595             else if (name is Quaternion)
 
  596                 QuaternionName = (Quaternion)name;
 
  597             else if (name is Color)
 
  598                 ColorName = (Color)name;
 
  599             else if (name is GameObject)
 
  601             else _name = name.ToString();
 
  607             if (value is Vector2)
 
  608                 Vector2Value = (Vector2)value;
 
  609             else if (value is Vector3)
 
  610                 Vector3Value = (Vector3)value;
 
  611             else if (value is Quaternion)
 
  612                 QuaternionValue = (Quaternion)value;
 
  613             else if (value is Color)
 
  614                 ColorValue = (Color)value;
 
  615             else if (value is GameObject)
 
  617             else _value = value.ToString();
 
  622     public UJeli this[
string name]
 
  624         get { 
return GetChild(name, 0); }
 
  627     public UJeli this[
string name, 
int index]
 
  629         get { 
return GetChild(name, index); }
 
  632     public UJeli this[
int index]
 
  634         get { 
return GetChild(index); }
 
  637     public UJeli Clone ()
 
  639         UJeli clone = Parse(ToString());
 
  641         clone._value = _value;
 
  645     public T GetEnumName<T> ()
 
  647         return GetEnumName<T>(
false);
 
  650     public T GetEnumName<T> (
bool ignoreCase)
 
  652         return (T)Enum.Parse(typeof(T), _name, ignoreCase);
 
  655     public T GetEnumValue<T> ()
 
  657         return GetEnumValue<T>(
false);
 
  660     public T GetEnumValue<T> (
bool ignoreCase)
 
  662         return (T)Enum.Parse(typeof(T), _value, ignoreCase);
 
  665     public T[] GetChildNames<T> (Func<string, T> convert)
 
  667         return (from child in _children select convert(child.Name)).ToArray();
 
  670     public T[] GetChildValues<T> (Func<string, T> convert)
 
  672         return (from child in _children select convert(child.Value)).ToArray();
 
  675     public Dictionary<string, string> GetChildDictionary ()
 
  677         return GetChildDictionary<string, string>(x => x, x => x);
 
  680     public Dictionary<string, T> GetChildDictionaryStringNames<T> (Func<string, T> convertValue)
 
  682         return GetChildDictionary<string, T>(x => x, convertValue);
 
  685     public Dictionary<T, string> GetChildDictionaryStringValues<T> (Func<string, T> convertName)
 
  687         return GetChildDictionary<T, string>(convertName, x => x);
 
  690     public Dictionary<T1, T2> GetChildDictionary<T1, T2> (
 
  691         Func<string, T1> convertName, Func<string, T2> convertValue)
 
  693         Dictionary<T1, T2> dict = 
new Dictionary<T1, T2>();
 
  695         foreach (
UJeli child 
in _children)
 
  697             dict[convertName(child.Name)] = convertValue(child.Value);
 
  703     public void GenerateChildren<T> (IEnumerable<T> nameObjects)
 
  705         GenerateChildren<T>(nameObjects, null);
 
  708     public void GenerateChildren<T> (IEnumerable<T> nameObjects, Func<T, string> convert)
 
  711             convert = o => o.ToString();
 
  713         foreach (T nameObject 
in nameObjects)
 
  715             AddChild(convert(nameObject));
 
  719     public void GenerateChildren<T1, T2> (IDictionary<T1, T2> childDict)
 
  721         GenerateChildren<T1, T2>(childDict, null, null);
 
  724     public void GenerateChildrenSimpleNames<T1, T2> (IDictionary<T1, T2> childDict,
 
  725         Func<T2, string> convertValue)
 
  727         GenerateChildren<T1, T2>(childDict, null, convertValue);
 
  730     public void GenerateChildrenSimpleValues<T1, T2> (IDictionary<T1, T2> childDict,
 
  731         Func<T1, string> convertName)
 
  733         GenerateChildren<T1, T2>(childDict, convertName, null);
 
  736     public void GenerateChildren<T1, T2> (IDictionary<T1, T2> childDict,
 
  737         Func<T1, string> convertName, Func<T2, string> convertValue)
 
  739         if (convertName == null)
 
  740             convertName = o => o.ToString();
 
  742         if (convertValue == null)
 
  743             convertValue = o => o.ToString();
 
  745         foreach (var pair 
in childDict)
 
  747             AddChild(convertName(pair.Key), convertValue(pair.Value));
 
  751     public UJeli AddChild ()
 
  753         return AddChild(
new UJeli());
 
  756     public UJeli AddChild (
string name)
 
  758         return AddChild(
new UJeli(name));
 
  761     public UJeli AddChild (
string name, 
object value)
 
  763         return AddChild(
new UJeli(name, value));
 
  768         _children.Add(child);
 
  769         child._parent = 
this;
 
  773     public bool HasChild (
string name)
 
  775         return GetChild(name) != null;
 
  778     public UJeli GetChild (
string name, 
int index)
 
  782         foreach (
UJeli c 
in _children)
 
  784             if (c._name.Equals(name) && i++ == index)
 
  791     public UJeli GetChild (
string name)
 
  793         return GetChild(name, 0);
 
  796     public UJeli GetChild (
int index)
 
  798         if (index < _children.Count)
 
  799             return _children[index];
 
  804     public UJeli[] GetChildren ()
 
  806         return _children.ToArray();
 
  809     public UJeli[] GetChildren (
string name)
 
  811         List<UJeli> matches = 
new List<UJeli>();
 
  813         foreach (
UJeli c 
in _children)
 
  819         return matches.ToArray();
 
  822     public int CountChildren ()
 
  824         return _children.Count;
 
  827     public int CountChildren (
string name)
 
  829         return GetChildren(name).Length;
 
  832     public void RemoveChild (
string name, 
int index)
 
  834         RemoveChild(GetChild(name, index));
 
  837     public void RemoveChild (
string name)
 
  839         RemoveChild(GetChild(name));
 
  842     public void RemoveChild (
int index)
 
  844         RemoveChild(GetChild(index));
 
  847     public void RemoveChild (
UJeli child)
 
  849         _children.Remove(child);
 
  852     public void RemoveChildren (
string name)
 
  854         foreach (
UJeli c 
in GetChildren(name))
 
  860     public void ClearChildren ()
 
  865     public void Save (
string fileName)
 
  867         string folder = Directory.GetParent(fileName).FullName;
 
  869         if (!Directory.Exists(folder))
 
  870             Directory.CreateDirectory(folder);
 
  872         File.WriteAllText(fileName, ToString());
 
  875     public override string ToString ()
 
  877         return WriteNode(
this, -1);
 
static int GetObjectIndex(GameObject go)
Gets the object index of a given object. 
 
static GameObject GetObject(int objectIndex)
Get an object by its object index. 
 
Unity version of Jeli markup class. 
 
This class server two main functions: 1) As a MonoBehaviour, it allows for network synchronization of...