//================================================================================ // 関数(static) //================================================================================ /// <summary> /// 設定を ProjectSettings フォルダから読み込みます /// </summary> internal static PlatformCheckerSettings Load() { if (m_instance != null) { return(m_instance); } m_instance = CreateInstance <PlatformCheckerSettings>(); if (!File.Exists(PATH)) { return(m_instance); } var json = File.ReadAllText(PATH, Encoding.UTF8); JsonUtility.FromJsonOverwrite(json, m_instance); if (m_instance == null) { m_instance = CreateInstance <PlatformCheckerSettings>(); } return(m_instance); }
/// <summary> /// アクティブになった時に呼び出されます /// </summary> public override void OnActivate(string searchContext, VisualElement rootElement) { m_settings = PlatformCheckerSettings.Load(); m_serializedObject = new SerializedObject(m_settings); m_buildTargetGroupsProperty = m_serializedObject.FindProperty("m_buildTargetGroups"); m_logLevelProperty = m_serializedObject.FindProperty("m_logLevel"); m_messageProperty = m_serializedObject.FindProperty("m_message"); }
/// <summary> /// GUI を描画する時に呼び出されます /// </summary> public override void OnGUI(string searchContext) { using (var checkScope = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.PropertyField(m_buildTargetGroupsProperty); EditorGUILayout.PropertyField(m_logLevelProperty); EditorGUILayout.PropertyField(m_messageProperty); if (checkScope.changed) { m_serializedObject.ApplyModifiedProperties(); PlatformCheckerSettings.Save(); } } }
/// <summary> /// Unity エディタの現在のプラットフォームが正しいか確認します /// </summary> private static void Check() { var settings = PlatformCheckerSettings.Load(); if (settings == null) { return; } var buildTargetGroups = settings.BuildTargetGroups; if (buildTargetGroups == null || buildTargetGroups.Count <= 0) { return; } var activeBuildTarget = EditorUserBuildSettings.activeBuildTarget; var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(activeBuildTarget); if (buildTargetGroups.Contains(buildTargetGroup)) { return; } var logLevel = settings.LogLevel; var message = settings.Message; switch (logLevel) { case LogLevel.INFO: Debug.Log(message); break; case LogLevel.WARNING: Debug.LogWarning(message); break; case LogLevel.ERROR: Debug.LogError(message); break; default: throw new ArgumentOutOfRangeException(); } }