コード例 #1
0
        public static string Generate(string className, string GUID)
        {
            var targetUnit      = new CodeCompileUnit();
            var targetNamespace = new CodeNamespace(TypedSceneSettings.Namespace);
            var targetClass     = new CodeTypeDeclaration(className);

            targetNamespace.Imports.Add(new CodeNamespaceImport("UnityEngine.SceneManagement"));
            targetClass.BaseTypes.Add("TypedScene");

            AddConstantValue(targetClass, typeof(string), "GUID", GUID);

            var loadingParameters = SceneAnalyzer.GetLoadingParameters(GUID);

            foreach (var loadingParameter in loadingParameters)
            {
                AddLoadingMethod(targetClass, loadingParameter);
            }

            targetNamespace.Types.Add(targetClass);
            targetUnit.Namespaces.Add(targetNamespace);

            var provider = CodeDomProvider.CreateProvider("CSharp");
            var options  = new CodeGeneratorOptions();

            options.BracingStyle = "C";

            var code = new StringWriter();

            provider.GenerateCodeFromCompileUnit(targetUnit, code, options);

            return(code.ToString());
        }
コード例 #2
0
        public static bool ValidateSceneImport(string scenePath)
        {
            var name      = Path.GetFileNameWithoutExtension(scenePath);
            var validName = GetValidName(name);

            if (name != validName)
            {
                var validPath = Path.GetDirectoryName(scenePath) + Path.DirectorySeparatorChar + validName + TypedSceneSettings.SceneExtension;
                File.Move(scenePath, validPath);
                File.Delete(scenePath + TypedSceneSettings.MetaExtension);
                AssetDatabase.ImportAsset(validPath, ImportAssetOptions.ForceUpdate);
                return(false);
            }

            if (SceneAnalyzer.TryAddTypedProcessor(AssetDatabase.AssetPathToGUID(scenePath)))
            {
                return(false);
            }

            return(true);
        }