Ejemplo n.º 1
0
        /// <summary>
        /// AOT向けにシリアライザを生成する
        /// </summary>
        public static void GenerateCode()
        {
            var info = new ObjectSerialization(typeof(glTF_VRM_extensions), "vrm", "Serialize_");

            Debug.Log(info);

            using (var s = File.Open(OutPath, FileMode.Create))
                using (var w = new StreamWriter(s, new UTF8Encoding(false)))
                {
                    w.Write(Begin);
                    info.GenerateSerializer(w, "Serialize");
                    w.Write(End);
                }

            Debug.LogFormat("write: {0}", OutPath);
            UnityPath.FromFullpath(OutPath).ImportAsset();
        }
Ejemplo n.º 2
0
        static void GenerateSerializerTypes(System.Type type)
        {
            var info = new ObjectSerialization(type, "vci", "Serialize_");

            Debug.Log(info);

            var name = string.Format("{0}_Serialize", type.Name);

            using (var s = File.Open(GetPath(name), FileMode.Create))
                using (var w = new StreamWriter(s, new UTF8Encoding(false)))
                {
                    w.NewLine = "\n";
                    w.Write(@"
using System;
using System.Collections.Generic;
using UniJSON;
using UnityEngine;
using UniGLTF;
using VCI;
using Object = System.Object;

namespace VCI {

public static class ");
                    w.Write(@"
" + type.Name + "_Serializer");

                    w.Write(@"
{

");
                    info.GenerateSerializer(w, "Serialize");
                    // footer
                    w.Write(@"
} // VciSerializer
} // VCI
");
                }

            // CRLF を LF に変換して再保存
            File.WriteAllText(GetPath(name), File.ReadAllText(GetPath(name), Encoding.UTF8).Replace("\r\n", "\n"), Encoding.UTF8);

            Debug.LogFormat("write: {0}", GetPath(name));
            UnityPath.FromFullpath(GetPath(name)).ImportAsset();
        }