Exemplo n.º 1
0
    public bool Export <T>(string path, object[] objArr) where T : Attribute
    {
        if (objArr == null || objArr.Length <= 0 || string.IsNullOrEmpty(path))
        {
            return(false);
        }

        if (!path.EndsWith(".json"))
        {
            path += ".json";
        }

        StringBuilder sb = new StringBuilder();

        sb.Append("[");
        foreach (object obj in objArr)
        {
            sb.AppendFormat("{{\"type\":\"{0}\",", obj.GetType().Name);
            sb.Append("\"data\":{");
            Dictionary <string, object> reflectDic = InjectDataBinder.ReflectAllData <T>(obj);
            saveJson(sb, reflectDic);
            sb.Append("}},");
        }
        if (sb[sb.Length - 1] == ',')
        {
            sb.Remove(sb.Length - 1, 1);
        }

        sb.Append("]");

        FileGameUtil.WriteText(path, sb.ToString());
#if UNITY_EDITOR
        AssetDatabase.Refresh();
#endif
        return(true);
    }
Exemplo n.º 2
0
    public bool Export <T>(string path, object[] objArr)  where T : Attribute
    {
        if (objArr == null || objArr.Length <= 0 || string.IsNullOrEmpty(path))
        {
            return(false);
        }

        if (!path.EndsWith(".xml"))
        {
            path += ".xml";
        }

        string allPath = string.Concat(ApplicationPath.PersistentRootPath, path);

        ApplicationPath.CreateDirectory(allPath);

        XmlDocument    doc     = new XmlDocument();
        XmlDeclaration dec     = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");
        XmlElement     rootEle = doc.CreateElement("data");

        foreach (object obj in objArr)
        {
            Dictionary <string, object> dataDic = InjectDataBinder.ReflectAllData <T>(obj);

            XmlElement element = doc.CreateElement(obj.GetType().Name);
            this.saveXml(doc, element, dataDic);
            rootEle.AppendChild(element);
        }
        doc.AppendChild(dec);
        doc.AppendChild(rootEle);
        doc.Save(allPath);
#if UNITY_EDITOR
        AssetDatabase.Refresh();
#endif
        return(true);
    }