Ejemplo n.º 1
0
    public static string SaveObj(ISavable obj)
    {
        Debug.Log(obj);
        FieldInfo[] prop = obj.GetType().GetFields();
        Array.Sort(prop, delegate(FieldInfo x, FieldInfo y) { return(x.Name.CompareTo(y.Name)); });

        List <string> comps = new List <string>();

        comps.Add(obj.getPrefab());
        string STransform = JsonUtility.ToJson(new STransform(((Component)obj).gameObject.transform));

        comps.Add(STransform);

        foreach (FieldInfo p in prop)
        {
            //Debug.Log(p);
            if (null != p && !p.IsNotSerialized)
            {
                Debug.Log(p);
                Type   pType = p.FieldType;
                object pVal  = p.GetValue(obj);
                pVal = Convert.ChangeType(pVal, pType);
                //Debug.Log(pVal);
                comps.Add(JsonUtility.ToJson(pVal));
            }
        }

        ListContainer <string> compsContainer = new ListContainer <string>();

        compsContainer.lis = comps;
        string retval = JsonUtility.ToJson(compsContainer);

        return(retval);
    }