Beispiel #1
0
        protected MessageEditor(
            ProjectData projectData,
            SetupConfig config,
            MessageDescriptor descriptor,
            ProtoMessageType messageType,
            MessageInfo defaultMessage,
            FileInfo protoFile,
            EnumInfoHelper enumInfoHelper)
        {
            this.m_ProjectData      = projectData;
            this.m_Config           = config;
            this.m_DefaultMessage   = defaultMessage;
            this.m_MessageType      = messageType;
            this.m_Descriptor       = descriptor;
            this.m_EnumInfoHelper   = enumInfoHelper;
            this.m_SavedEditorState =
                new EditorState(m_Config.GetUseAdvanced(m_MessageType), new MessageInfo(m_Descriptor));
            // If using advanced mode, use the saved editor state which has user-inserted fields to prevent
            // inconsistencies.
            EditorState defaultEditorState = m_Config.GetUseAdvanced(m_MessageType)
                ? m_SavedEditorState
                : new EditorState(m_Config.GetUseAdvanced(m_MessageType), defaultMessage);

            this.m_EditorStatePrefs = new EditorStatePrefs <EditorState>(messageType.ToString(), defaultEditorState);
            this.m_EditorState      = m_EditorStatePrefs.Get();
            this.m_ProtoFile        = protoFile;
            CheckValidationErrors();
        }
Beispiel #2
0
        static bool HasSceneEnumChanged()
        {
            var newSceneEnum  = EnumInfoHelper.GetSceneEnum(EditorBuildSettings.scenes);
            var allEnums      = enumInfoHelper.CreateInfoList();
            var prevSceneEnum = allEnums.Find(x => x.name == Names.sceneEnumName);

            return(newSceneEnum.values != prevSceneEnum.values);
        }
Beispiel #3
0
 /// <summary>
 ///     Update scenes enum if scenes have changed in build settings
 /// </summary>
 static void UpdateSceneEnum()
 {
     if (HasSceneEnumChanged())
     {
         Debug.Log("Android Performance Tuner: Scenes enum is updated");
         var newSceneEnum = EnumInfoHelper.GetSceneEnum(EditorBuildSettings.scenes);
         protoFile.AddEnum(newSceneEnum);
     }
 }
Beispiel #4
0
        public static void ShowWindow(FileInfo protoFile, EnumInfoHelper enumInfoHelper, EnumInfo displayInfo)
        {
            var window = ScriptableObject.CreateInstance <NewEnumWindow>();

            window.titleContent     = new GUIContent("Add / Update enum");
            window.position         = new Rect(Screen.width / 2f, Screen.height / 2f, 300, 500);
            window.m_ProtoFile      = protoFile;
            window.m_EnumInfoHelper = enumInfoHelper;
            window.m_Info           = displayInfo;
            window.ShowUtility();
            window.MakeChecks();
        }
Beispiel #5
0
 public FidelityMessageEditor(ProjectData projectData, SetupConfig config, FileInfo protoFile,
                              MessageDescriptor descriptor,
                              EnumInfoHelper enumInfoHelper) : base(
         config,
         descriptor,
         ProtoMessageType.FidelityParams,
         DefaultMessages.fidelityMessage,
         protoFile,
         enumInfoHelper)
 {
     m_ProjectData = projectData;
 }
Beispiel #6
0
        public static void ShowNewEnumWindow(FileInfo protoFile, EnumInfoHelper enumInfoHelper)
        {
            var displayInfo = new EnumInfo()
            {
                name   = "NewEnum" + enumInfoHelper.GetAllNames().Count(),
                values = new List <string>()
                {
                    "VALUE_0", "VALUE_1", "VALUE_2"
                }
            };

            ShowWindow(protoFile, enumInfoHelper, displayInfo);
        }
        /// <summary>
        ///     Update scenes enum if scenes have changed in build settings
        /// </summary>
        static void UpdateSceneEnum()
        {
            var allEnums      = enumInfoHelper.CreateInfoList();
            var newSceneEnum  = EnumInfoHelper.GetSceneEnum(EditorBuildSettings.scenes);
            var prevSceneEnum = allEnums.Find(x => x.name == Names.sceneEnumName);

            if (newSceneEnum.values == prevSceneEnum.values)
            {
                return;
            }
            Debug.Log("Android Performance Tuner: Scenes enum is updated");
            protoFile.AddEnum(newSceneEnum);
        }
Beispiel #8
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;
        }
        public AnnotationMessageEditor(SetupConfig config, FileInfo protoFile, MessageDescriptor descriptor,
                                       EnumInfoHelper enumInfoHelper) : base(
                config,
                descriptor,
                ProtoMessageType.Annotation,
                DefaultMessages.annotationMessage,
                protoFile,
                enumInfoHelper)
        {
            var icon = (Texture)Resources.Load("baseline_info_outline");

            m_SceneFieldInfo   = new GUIContent(icon, k_SceneInfo);
            m_LoadingFieldInfo = new GUIContent(icon, k_LoadingInfo);
        }
        public AnnotationMessageEditor(ProjectData projectData, SetupConfig config, FileInfo protoFile,
                                       MessageDescriptor descriptor,
                                       EnumInfoHelper enumInfoHelper) : base(
                projectData,
                config,
                descriptor,
                ProtoMessageType.Annotation,
                DefaultMessages.annotationMessage,
                protoFile,
                enumInfoHelper)
        {
            var icon  = (Texture)Resources.Load("baseline_info_outline");
            var error = (Texture)Resources.Load("ic_error_outline");

            m_SceneFieldInfo   = new GUIContent(icon, k_SceneInfo);
            m_LoadingFieldInfo = new GUIContent(error, Names.removeLoadingStateTooltip);
        }
Beispiel #11
0
        public static void ShowWindow(FileInfo protoFile, EnumInfoHelper enumInfoHelper)
        {
            var window = ScriptableObject.CreateInstance <NewEnumWindow>();

            window.titleContent     = new GUIContent("New enum");
            window.position         = new Rect(Screen.width / 2f, Screen.height / 2f, 300, 500);
            window.m_ProtoFile      = protoFile;
            window.m_EnumInfoHelper = enumInfoHelper;
            window.m_Info           = new EnumInfo()
            {
                name   = "NewEnum" + enumInfoHelper.GetAllNames().Count(),
                values = new List <string>()
                {
                    "VALUE_0", "VALUE_1", "VALUE_2"
                }
            };
            window.ShowUtility();
        }
Beispiel #12
0
        static Initializer()
        {
            Debug.Log("Android Performance Tuner Initializer");

            setupConfig = FileUtil.LoadSetupConfig();

            devDescriptor = CreateDescriptor();

            protoFile = CreateProtoFile(devDescriptor);

            CreateAsmdefFile();

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

            enumInfoHelper = new EnumInfoHelper(devDescriptor.fileDescriptor);

            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();

            // 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;
        }
 protected MessageEditor(
     SetupConfig config,
     MessageDescriptor descriptor,
     ProtoMessageType messageType,
     MessageInfo defaultMessage,
     FileInfo protoFile,
     EnumInfoHelper enumInfoHelper)
 {
     this.m_Config           = config;
     this.m_DefaultMessage   = defaultMessage;
     this.m_MessageType      = messageType;
     this.m_Descriptor       = descriptor;
     this.m_EnumInfoHelper   = enumInfoHelper;
     this.m_EditorStatePrefs = new EditorStatePrefs <EditorState>(messageType.ToString(),
                                                                  new EditorState(m_Config.GetUseAdvanced(m_MessageType), defaultMessage));
     this.m_EditorState      = m_EditorStatePrefs.Get();
     this.m_ProtoFile        = protoFile;
     this.m_SavedEditorState =
         new EditorState(m_Config.GetUseAdvanced(m_MessageType), new MessageInfo(m_Descriptor));
     CheckValidationErrors();
 }
        static Proto.FileInfo CreateProtoFile(DevDescriptor devDescriptor)
        {
            var protoFile = new Proto.FileInfo(devDescriptor.fileDescriptor);

            // Always add scene and loading state enum.
            protoFile.AddEnum(EnumInfoHelper.GetSceneEnum(EditorBuildSettings.scenes));
            protoFile.AddEnum(DefaultMessages.loadingStateEnum);

            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)
            {
                protoFile.onUpdate();
            }

            return(protoFile);
        }
Beispiel #15
0
        public static void ShowWindow(FileInfo protoFile, FileDescriptor fileDescriptor, EnumInfoHelper enumInfoHelper)
        {
            var window = ScriptableObject.CreateInstance <DeleteEnumWindow>();

            window.titleContent     = new GUIContent("Delete Enum");
            window.m_ProtoFile      = protoFile;
            window.m_FileDescriptor = fileDescriptor;
            window.m_EnumInfoHelper = enumInfoHelper;
            window.position         = new Rect(Screen.width / 2f, Screen.height / 2f, 400, 200);
            window.ShowUtility();
        }