private string SerializeAttribute(BehaviorNodeControl node, EditorCachedNodeField field)
        {
            if (node.m_fieldControls.ContainsKey(field.name))
            {
                Control c = node.m_fieldControls[field.name];

                if (field.type == typeof(int))
                {
                    return(string.Format("{0}=\"{1}\"", field.systemName, (c as IntField).Value));
                }
                else if (field.type == typeof(float))
                {
                    return(string.Format("{0}=\"{1}\"", field.systemName, (c as FloatField).Value));
                }
                else if (field.type == typeof(Vector2))
                {
                    return(string.Format("{0}=\"{1},{2}\"", field.systemName, (c as Vector2Field).Value.x, (c as Vector2Field).Value.y));
                }
                else if (field.type == typeof(Vector3))
                {
                    return(string.Format("{0}=\"{1},{2},{3}\"", field.systemName, (c as Vector3Field).Value.x, (c as Vector3Field).Value.y, (c as Vector3Field).Value.z));
                }
                else if (field.type == typeof(Vector4))
                {
                    return(string.Format("{0}=\"{1},{2},{3}\"", field.systemName, (c as Vector4Field).Value.x, (c as Vector4Field).Value.y, (c as Vector4Field).Value.z, (c as Vector4Field).Value.w));
                }
                else if (field.type == typeof(string))
                {
                    return(string.Format("{0}=\"{1}\"", field.systemName, (c as TextField).Value));
                }
                else if (field.type == typeof(Rect))
                {
                    return(string.Format("{0}=\"{1},{2},{3},{4}\"", field.systemName, (c as RectField).Value.xMin, (c as RectField).Value.yMin, (c as RectField).Value.width, (c as RectField).Value.height));
                }
                else if (field.type == typeof(Color))
                {
                    return(string.Format("{0}=\"{1},{2},{3}\"", field.systemName, (c as ColorField).Value.r, (c as ColorField).Value.g, (c as ColorField).Value.b, (c as ColorField).Value.a));
                }
                else if (field.type == typeof(Bounds))
                {
                    return(string.Format("{0}=\"{1},{2},{3},{4},{5},{6}\"", field.systemName, (c as BoundsField).Value.center.x, (c as BoundsField).Value.center.y, (c as BoundsField).Value.center.z, (c as BoundsField).Value.extents.x, (c as BoundsField).Value.extents.y, (c as BoundsField).Value.extents.z));
                }
                else if (field.type.IsEnum)
                {
                    return(string.Format("{0}=\"{1}\"", field.systemName, (c as EnumDropdown).Value));
                }
                else if (field.type == typeof(bool))
                {
                    return(string.Format("{0}=\"{1}\"", field.systemName, (c as Toggle).Value));
                }
            }

            return("");
        }
        private string SerializeAttribute( BehaviorNodeControl node, EditorCachedNodeField field )
        {
            if ( node.m_fieldControls.ContainsKey( field.name ) )
            {
                Control c = node.m_fieldControls[ field.name ];

                if ( field.type == typeof( int ) )
                {
                    return string.Format( "{0}=\"{1}\"", field.systemName, ( c as IntField ).Value );                    
                }
                else if ( field.type == typeof( float ) )
                {
                    return string.Format( "{0}=\"{1}\"", field.systemName, ( c as FloatField ).Value );                    
                }
                else if ( field.type == typeof( Vector2 ) )
                {
                    return string.Format( "{0}=\"{1},{2}\"", field.systemName, ( c as Vector2Field ).Value.x, ( c as Vector2Field ).Value.y );                      
                }
                else if ( field.type == typeof( Vector3 ) )
                {
                    return string.Format( "{0}=\"{1},{2},{3}\"", field.systemName, ( c as Vector3Field ).Value.x, ( c as Vector3Field ).Value.y, ( c as Vector3Field ).Value.z );                                          
                }
                else if ( field.type == typeof( Vector4 ) )
                {
                    return string.Format( "{0}=\"{1},{2},{3}\"", field.systemName, ( c as Vector4Field ).Value.x, ( c as Vector4Field ).Value.y, ( c as Vector4Field ).Value.z, ( c as Vector4Field ).Value.w );                                          
                }
                else if ( field.type == typeof( string ) )
                {
                    return string.Format( "{0}=\"{1}\"", field.systemName, ( c as TextField ).Value );                    
                }
                else if ( field.type == typeof( Rect ) )
                {
                    return string.Format( "{0}=\"{1},{2},{3},{4}\"", field.systemName, ( c as RectField ).Value.xMin, ( c as RectField ).Value.yMin, ( c as RectField ).Value.width, ( c as RectField ).Value.height );                    
                }
                else if ( field.type == typeof( Color ) )
                {
                    return string.Format( "{0}=\"{1},{2},{3}\"", field.systemName, ( c as ColorField ).Value.r, ( c as ColorField ).Value.g, ( c as ColorField ).Value.b, ( c as ColorField ).Value.a );
                }
                else if ( field.type == typeof( Bounds ) )
                {
                    return string.Format( "{0}=\"{1},{2},{3},{4},{5},{6}\"", field.systemName, ( c as BoundsField ).Value.center.x, ( c as BoundsField ).Value.center.y, ( c as BoundsField ).Value.center.z, ( c as BoundsField ).Value.extents.x, ( c as BoundsField ).Value.extents.y, ( c as BoundsField ).Value.extents.z );                    
                }
                else if ( field.type.IsEnum )
                {
                    return string.Format( "{0}=\"{1}\"", field.systemName, ( c as EnumDropdown ).Value );                    
                }
                else if ( field.type == typeof( bool ) )
                {
                    return string.Format( "{0}=\"{1}\"", field.systemName, ( c as Toggle ).Value );                    
                }
            }

            return "";
        }
        private void DeserializeFields(XmlNode xml, EditorCachedNode data, BehaviorNodeControl control)
        {
            foreach (KeyValuePair <string, Control> kvp in control.m_fieldControls)
            {
                string  fieldName  = kvp.Key;
                string  systemName = "";
                Control c          = kvp.Value;

                bool found = false;
                EditorCachedNodeField field = default(EditorCachedNodeField);

                foreach (EditorCachedNodeField f in data.fields)
                {
                    if (f.name == fieldName)
                    {
                        found      = true;
                        field      = f;
                        systemName = f.systemName;
                        break;
                    }
                }

                if (!found)
                {
                    continue;
                }

                if (xml.Attributes[systemName] == null)
                {
                    continue;
                }

                string sval = xml.Attributes[systemName].InnerText;

                if (field.type == typeof(int))
                {
                    (c as IntField).Value = int.Parse(sval);
                }
                else if (field.type == typeof(float))
                {
                    (c as FloatField).Value = float.Parse(sval);
                }
                else if (field.type == typeof(Vector2))
                {
                    string[] split = sval.Split(',');
                    (c as Vector2Field).Value = new Vector2(float.Parse(split[0]), float.Parse(split[1]));
                }
                else if (field.type == typeof(Vector3))
                {
                    string[] split = sval.Split(',');
                    (c as Vector3Field).Value = new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
                }
                else if (field.type == typeof(Vector4))
                {
                    string[] split = sval.Split(',');
                    (c as Vector4Field).Value = new Vector4(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]), float.Parse(split[3]));
                }
                else if (field.type == typeof(string))
                {
                    (c as TextField).Value = sval;
                }
                else if (field.type == typeof(Rect))
                {
                    string[] split = sval.Split(',');
                    (c as RectField).Value = new Rect(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]), float.Parse(split[3]));
                }
                else if (field.type == typeof(Color))
                {
                    string[] split = sval.Split(',');
                    (c as ColorField).Value = new Color(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
                }
                else if (field.type == typeof(Bounds))
                {
                    string[] split = sval.Split(',');
                    (c as BoundsField).Value = new Bounds(new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2])), new Vector3(float.Parse(split[3]), float.Parse(split[4]), float.Parse(split[5])));
                }
                else if (field.type.IsEnum)
                {
                    System.Enum e = (System.Enum)System.Enum.Parse(field.type, sval);
                    (c as EnumDropdown).Value = e;
                }
                else if (field.type == typeof(bool))
                {
                    (c as Toggle).Value = bool.Parse(sval);
                }
            }
        }