public static void GenerateRegisterClassesForStripping(HashSet <UnityType> nativeClassesAndBaseClasses, TextWriter output)
 {
     output.WriteLine("template <typename T> void RegisterClass();");
     output.WriteLine("template <typename T> void RegisterStrippedTypeInfo(int, const char*, const char*);");
     output.WriteLine();
     foreach (UnityType current in UnityType.GetTypes())
     {
         if (current.baseClass != null && !current.isEditorOnly)
         {
             if (current.hasNativeNamespace)
             {
                 output.WriteLine("class {0};", current.name);
             }
             else
             {
                 output.WriteLine("namespace {0} {{ class {1}; }}", current.nativeNamespace, current.name);
             }
             output.WriteLine();
         }
     }
     output.Write("void RegisterAllClasses() \n{\n");
     output.WriteLine("\tvoid RegisterBuiltinTypes();");
     output.WriteLine("\tRegisterBuiltinTypes();");
     output.WriteLine("\t// Non stripped classes");
     foreach (UnityType current2 in UnityType.GetTypes())
     {
         if (current2.baseClass != null && !current2.isEditorOnly && nativeClassesAndBaseClasses.Contains(current2))
         {
             output.WriteLine("\tRegisterClass<{0}>();", current2.qualifiedName);
         }
     }
     output.WriteLine();
     output.Write("\n}\n");
 }
Пример #2
0
        public static void GenerateRegisterClassesForStripping(HashSet <UnityType> nativeClassesAndBaseClasses, TextWriter output)
        {
            output.WriteLine("template <typename T> void RegisterClass();");
            output.WriteLine("template <typename T> void RegisterStrippedTypeInfo(int, const char*, const char*);");
            output.WriteLine();
            foreach (UnityType type in UnityType.GetTypes())
            {
                if ((type.baseClass != null) && !type.isEditorOnly)
                {
                    if (!type.hasNativeNamespace)
                    {
                        output.WriteLine("class {0};", type.name);
                    }
                    else
                    {
                        output.WriteLine("namespace {0} {{ class {1}; }}", type.nativeNamespace, type.name);
                    }
                    output.WriteLine();
                }
            }
            output.Write("void RegisterAllClasses() \n{\n");
            output.WriteLine("\tvoid RegisterBuiltinTypes();");
            output.WriteLine("\tRegisterBuiltinTypes();");
            output.WriteLine("\t// {0} Non stripped classes", nativeClassesAndBaseClasses.Count);
            int num = 1;

            foreach (UnityType type2 in UnityType.GetTypes())
            {
                if (((type2.baseClass != null) && !type2.isEditorOnly) && nativeClassesAndBaseClasses.Contains(type2))
                {
                    output.WriteLine("\t// {0}. {1}\n", num++, type2.qualifiedName);
                    output.WriteLine("\tRegisterClass<{0}>();\n", type2.qualifiedName);
                }
            }
            output.WriteLine();
            output.Write("\n}\n");
        }
Пример #3
0
        private static void WriteStaticallyLinkedModuleClassRegistration(TextWriter w, HashSet <UnityType> nativeClasses, HashSet <UnityType> classesToSkip)
        {
            w.WriteLine("template <typename T> void RegisterUnityClass(const char*);");
            w.WriteLine("template <typename T> void RegisterStrippedType(int, const char*, const char*);");
            w.WriteLine();

            WriteFunctionInvokeRegisterStaticallyLinkedModuleClasses(w, nativeClasses);

            // Forward declare types
            if (nativeClasses != null)
            {
                foreach (var type in UnityType.GetTypes())
                {
                    if (type.baseClass == null || type.isEditorOnly || classesToSkip.Contains(type))
                    {
                        continue;
                    }

                    if (type.hasNativeNamespace)
                    {
                        w.Write("namespace {0} {{ class {1}; }} ", type.nativeNamespace, type.name);
                    }
                    else
                    {
                        w.Write("class {0}; ", type.name);
                    }

                    if (nativeClasses.Contains(type))
                    {
                        w.WriteLine("template <> void RegisterUnityClass<{0}>(const char*);", type.qualifiedName);
                    }
                    else
                    {
                        w.WriteLine();
                    }
                }
                w.WriteLine();
            }

            // Class registration function
            w.WriteLine("void RegisterAllClasses()");
            w.WriteLine("{");

            if (nativeClasses == null)
            {
                w.WriteLine("\tvoid RegisterAllClassesGranular();");
                w.WriteLine("\tRegisterAllClassesGranular();");
            }
            else
            {
                w.WriteLine("void RegisterBuiltinTypes();");
                w.WriteLine("RegisterBuiltinTypes();");
                w.WriteLine("\t//Total: {0} non stripped classes", nativeClasses.Count);

                int index = 0;
                foreach (var klass in nativeClasses)
                {
                    w.WriteLine("\t//{0}. {1}", index, klass.qualifiedName);
                    if (classesToSkip.Contains(klass) || (klass.baseClass == null))
                    {
                        w.WriteLine("\t//Skipping {0}", klass.qualifiedName);
                    }
                    else
                    {
                        w.WriteLine("\tRegisterUnityClass<{0}>(\"{1}\");", klass.qualifiedName, klass.module);
                    }
                    ++index;
                }
                w.WriteLine();

                // Register stripped classes

                // TODO (ulfj ) 2016-08-15 : Right now we cannot deal with types that are compiled into the editor
                // but not the player due to other defines than UNITY_EDITOR in them module definition file
                // (for example WorldAnchor only being there if ENABLE_HOLOLENS_MODULE_API). Doing this would
                // require either some non trivial changes to the module registration macros or a way for these
                // conditionals to be included in the RTTI so we can emit them when generating the code, so we
                // disabling the registration of stripped classes for now and will get back to this when we have
                // landed the remaining changes to the type system.

                //w.WriteLine("\t//Stripped classes");
                //foreach (var type in UnityType.GetTypes())
                //{
                //  if (type.baseClass == null || type.isEditorOnly || classesToSkip.Contains(type) || nativeClasses.Contains(type))
                //      continue;

                //  w.WriteLine("\tRegisterStrippedType<{0}>({1}, \"{2}\", \"{3}\");", type.qualifiedName, type.persistentTypeID, type.name, type.nativeNamespace);
                //}
            }
            w.WriteLine("}");
        }
        public static void GenerateRegisterClassesForStripping(HashSet <UnityType> nativeClassesAndBaseClasses, TextWriter output)
        {
            // Forward declare template function
            output.WriteLine("template <typename T> void RegisterClass(const char*);");
            output.WriteLine("template <typename T> void RegisterStrippedType(int, const char*, const char*);");
            output.WriteLine();

            // Forward declaration
            foreach (var type in UnityType.GetTypes())
            {
                if (type.baseClass == null || type.isEditorOnly)
                {
                    continue;
                }

                if (!type.hasNativeNamespace)
                {
                    output.WriteLine("class {0};", type.name);
                }
                else
                {
                    output.WriteLine("namespace {0} {{ class {1}; }}", type.nativeNamespace, type.name);
                }

                output.WriteLine();
            }

            output.Write("void RegisterAllClasses() \n{\n");
            output.WriteLine("\tvoid RegisterBuiltinTypes();");
            output.WriteLine("\tRegisterBuiltinTypes();");

            // Write non stripped class registration
            output.WriteLine("\t// {0} Non stripped classes\n", nativeClassesAndBaseClasses.Count);
            int count = 1;

            foreach (var type in UnityType.GetTypes())
            {
                if (type.baseClass == null || type.isEditorOnly || !nativeClassesAndBaseClasses.Contains(type))
                {
                    continue;
                }

                output.WriteLine("\t// {0}. {1}", count++, type.qualifiedName);
                output.WriteLine("\tRegisterClass<{0}>(\"{1}\");\n", type.qualifiedName, type.module);
            }

            output.WriteLine();

            // Write stripped class registration

            // TODO (ulfj ) 2016-08-15 : Right now we cannot deal with types that are compiled into the editor
            // but not the player due to other defines than UNITY_EDITOR in them module definition file
            // (for example WorldAnchor only being there if ENABLE_HOLOLENS_MODULE_API). Doing this would
            // require either some non trivial changes to the module registration macros or a way for these
            // conditionals to be included in the RTTI so we can emit them when generating the code, so we
            // disabling the registration of stripped classes for now and will get back to this when we have
            // landed the remaining changes to the type system.

            //output.WriteLine("\t// Stripped classes");
            //foreach (var type in UnityType.GetTypes())
            //{
            //  if (type.baseClass == null || type.isEditorOnly || nativeClassesAndBaseClasses.Contains(type))
            //      continue;

            //  output.WriteLine("\tRegisterStrippedType<{0}>();", type.qualifiedName);
            //}

            output.Write("\n}\n");
        }
Пример #5
0
 private static void WriteModuleAndClassRegistrationFile(string file, HashSet <string> nativeModules, HashSet <UnityType> nativeClasses, HashSet <UnityType> classesToSkip)
 {
     using (TextWriter textWriter = new StreamWriter(file))
     {
         textWriter.WriteLine("template <typename T> void RegisterClass();");
         textWriter.WriteLine("template <typename T> void RegisterStrippedTypeInfo(int, const char*, const char*);");
         textWriter.WriteLine();
         CodeStrippingUtils.WriteStaticallyLinkedModuleRegistration(textWriter, nativeModules, nativeClasses);
         textWriter.WriteLine();
         if (nativeClasses != null)
         {
             foreach (UnityType current in UnityType.GetTypes())
             {
                 if (current.baseClass != null && !current.isEditorOnly && !classesToSkip.Contains(current))
                 {
                     if (current.hasNativeNamespace)
                     {
                         textWriter.Write("namespace {0} {{ class {1}; }} ", current.nativeNamespace, current.name);
                     }
                     else
                     {
                         textWriter.Write("class {0}; ", current.name);
                     }
                     if (nativeClasses.Contains(current))
                     {
                         textWriter.WriteLine("template <> void RegisterClass<{0}>();", current.qualifiedName);
                     }
                     else
                     {
                         textWriter.WriteLine();
                     }
                 }
             }
             textWriter.WriteLine();
         }
         textWriter.WriteLine("void RegisterAllClasses()");
         textWriter.WriteLine("{");
         if (nativeClasses == null)
         {
             textWriter.WriteLine("\tvoid RegisterAllClassesGranular();");
             textWriter.WriteLine("\tRegisterAllClassesGranular();");
         }
         else
         {
             textWriter.WriteLine("void RegisterBuiltinTypes();");
             textWriter.WriteLine("RegisterBuiltinTypes();");
             textWriter.WriteLine("\t//Total: {0} non stripped classes", nativeClasses.Count);
             int num = 0;
             foreach (UnityType current2 in nativeClasses)
             {
                 textWriter.WriteLine("\t//{0}. {1}", num, current2.qualifiedName);
                 if (classesToSkip.Contains(current2))
                 {
                     textWriter.WriteLine("\t//Skipping {0}", current2.qualifiedName);
                 }
                 else
                 {
                     textWriter.WriteLine("\tRegisterClass<{0}>();", current2.qualifiedName);
                 }
                 num++;
             }
             textWriter.WriteLine();
         }
         textWriter.WriteLine("}");
         textWriter.Close();
     }
 }