示例#1
0
        public IEnumerator Start()
        {
            string outpath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/Maps/";

            types = new List <Type>();
            Directory.CreateDirectory(outpath);
            for (int i = 0; i <= 16; i++)
            {
                AsyncOperation ope = SceneManager.LoadSceneAsync(i, LoadSceneMode.Single);

                yield return(new WaitUntil(() => ope.isDone));

                List <jsonGameObject> objjson = new List <jsonGameObject>();
                GameObject[]          objects = SceneManager.GetActiveScene().GetRootGameObjects();

                foreach (GameObject child in objects)
                {
                    Component[] comp = child.GetComponents <Component>();

                    jsonGameObject go = new jsonGameObject
                    {
                        Name     = child.name,
                        componts = OutputComponents(comp),
                        children = GetChildren(child.transform)
                    };
                    objjson.Add(go);
                }

                File.WriteAllText(outpath + "map" + i + ".json", JsonConvert.SerializeObject(objjson, Formatting.Indented));
            }
            yield return(null);

            File.WriteAllText(outpath + "types.json", JsonConvert.SerializeObject(types, Formatting.Indented));
            SceneManager.LoadScene(0, LoadSceneMode.Single);

            Directory.CreateDirectory(outpath + "classes/");
            foreach (Type type in types)
            {
                if (type.FullName.StartsWith("RoR2"))
                {
                    if (type.Name.EndsWith("]"))
                    {
                        continue;
                    }
                    string output = "";
                    output += "using UnityEngine;\n\n";
                    output += "namespace " + type.Namespace + "{\n\n";
                    output += "    public class " + type.Name + " : MonoBehaviour {\n";
                    foreach (FieldInfo field in type.GetFields())
                    {
                        output += "        public " + GetCSharpName(field.FieldType) + " " + field.Name + ";\n";
                    }
                    output += "    }\n";
                    output += "}\n";
                    File.WriteAllText(outpath + "classes/" + type.Name + ".cs", output);
                }
            }
        }
示例#2
0
        public static List <jsonGameObject> GetChildren(Transform transform)
        {
            List <jsonGameObject> gameObjects = new List <jsonGameObject>();

            for (int i = 0; i < transform.childCount; i++)
            {
                GameObject  child = transform.GetChild(i).gameObject;
                Component[] comp  = child.GetComponents <Component>();

                jsonGameObject go = new jsonGameObject
                {
                    Name     = child.name,
                    componts = OutputComponents(comp),
                    children = GetChildren(transform.GetChild(i))
                };
                gameObjects.Add(go);
            }
            return(gameObjects);
        }