/// <summary>
    /// Construct JSONGameObject from a gameObject
    /// </summary>
    /// <param name="gameObject"></param>
    static JSONGameObject JSONGameObject(GameObject gameObject)
    {
        JSONGameObject jsonGameObject = new JSONGameObject();

        jsonGameObject.name       = gameObject.name;
        jsonGameObject.components = new List <JSONComponent>();
        try
        {
            foreach (Component component in gameObject.GetComponents <Component>())
            {
                List <JSONProperty> jproperty  = new List <JSONProperty>();
                JSONComponent       jComponent = new JSONComponent(component.GetType().Name, jproperty);
                PropertyInfo[]      properties = component.GetType().GetProperties();

                //Avoid component properties
                List <string> avoidablePropertyNames = GetAvoidablePropertyNames();

                foreach (PropertyInfo property in properties)
                {
                    //Avoid  properties
                    if (avoidablePropertyNames.Contains(property.Name))
                    {
                        if (debug)
                        {
                            Debug.LogWarning("Skipped set value for property " + property.Name + " for component " + component.GetType().Name + " for object " + gameObject.name);
                        }
                        continue;
                    }

                    if (property.GetSetMethod() != null)
                    {
                        jproperty.Add(new JSONProperty(property.Name, property.PropertyType.Name, component.GetType().GetProperty(property.Name).GetValue(component, null)));
                    }
                    else
                    {
                        if (debug)
                        {
                            Debug.LogWarning("property " + property.Name + " of component " + component.GetType().Name + " of object " + gameObject.name + " doesnt have SetMethod");
                        }
                    }
                }

                jsonGameObject.components.Add(jComponent);
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
        return(jsonGameObject);
    }
 public void writeJSONComponent(JsonWriter writer, JSONComponent value, JsonSerializer serializer)
 {
     writer.WritePropertyName("type");
     writer.WriteValue(value.type);
 }