Ejemplo n.º 1
0
        static void Init()
        {
            Debug.Log("Android Performance Tuner Initializer");

            setupConfig   = FileUtil.LoadSetupConfig();
            devDescriptor = CreateDescriptor();

            // When a new package is imported in Unity 2018, EditorBuildSettings.scenes are not updated yet when
            // Initializer() is called, thus the .proto file does not reflect possible changes in the scenes.
            // This callback creates the .proto file when the package has finished importing and the
            // EditorBuildSettings are up to date.
#if UNITY_2018
            AssetDatabase.importPackageCompleted += (packageName) =>
            {
                CreateProtoFile(devDescriptor);
            };
#endif

            enumInfoHelper = new EnumInfoHelper(devDescriptor.fileDescriptor);
            protoFile      = CreateProtoFile(devDescriptor);

            CreateAsmdefFile();

            projectData = new ProjectData();
            projectData.LoadFromStreamingAssets(devDescriptor);

            EditorBuildSettings.sceneListChanged += () =>
            {
                Debug.Log("Android Performance Tuner SceneListChanged");
                UpdateSceneEnum();
            };

            if (!FidelityBuilder.builder.valid)
            {
                initMessage = "Fidelity message is not generated yet or your project is still compiling. " +
                              "If this message persists, try to re-import the plugin and generated assets." +
                              "\n[macOS] Check if protoc compiler can be opened. " +
                              "In the Finder locate protoc binary in AndroidPerformanceTuner/Editor/Protoc, " +
                              "control-click the binary, choose Open and then click Open. ";
                Debug.Log(initMessage);
                valid = false;
                return;
            }

            UpdateFidelityMessages();
            CheckForLoadingStateInAnnotation();

            // TODO(kseniia): Check for possible inconsistencies in the data, set to false if any found
            // TODO(kseniia): or remove "valid" if all problems could be fixed in-place
            valid = true;
        }
Ejemplo n.º 2
0
        static Proto.FileInfo CreateProtoFile(DevDescriptor devDescriptor)
        {
            var protoFile = new Proto.FileInfo(devDescriptor.fileDescriptor);

            // Always add scene.
            protoFile.AddEnum(EnumInfoHelper.GetSceneEnum(EditorBuildSettings.scenes));

            protoFile.onUpdate += () =>
            {
                Action onFail = null;
                if (File.Exists(Paths.devProtoPath))
                {
                    var previousText = File.ReadAllText(Paths.devProtoPath);
                    onFail = () => { File.WriteAllText(Paths.devProtoPath, previousText); };
                }

                Directory.CreateDirectory(Path.GetDirectoryName(Paths.devProtoPath));
                File.WriteAllText(Paths.devProtoPath, protoFile.ToProtoString());
                if (!ProtocCompiler.GenerateProtoAndDesc() && onFail != null)
                {
                    onFail();
                }
                else
                {
                    AssetDatabase.Refresh();
                    areFidelityMessagesDirty = true;
                }
            };

            // If files do not exist yet, call OnUpdate to generate them (.proto, .descriptor and .cs).
            if (!File.Exists(Paths.devProtoPath) ||
                !File.Exists(Paths.devDescriptorPath) ||
                !FidelityBuilder.builder.valid ||
                HasSceneEnumChanged())
            {
                protoFile.onUpdate();
            }

            return(protoFile);
        }