void DefaultAnchorButtonGUI()
        {
            bool anchorWasEdited = (m_SafeArea.m_Panel.anchorMin != m_SafeArea.m_DefaultAnchorMin) || (m_SafeArea.m_Panel.anchorMax != m_SafeArea.m_DefaultAnchorMax);

            EditorGUILayout.LabelField("Default Anchors Min (" + m_SafeArea.m_DefaultAnchorMin.x + ", " + m_SafeArea.m_DefaultAnchorMin.y + ")"
                                       + "   Current Anchors Min (" + m_SafeArea.m_Panel.anchorMin.x + ", " + m_SafeArea.m_Panel.anchorMin.y + ")");
            EditorGUILayout.LabelField("Default Anchors Max (" + m_SafeArea.m_DefaultAnchorMax.x + ", " + m_SafeArea.m_DefaultAnchorMax.y + ")"
                                       + "   Current Anchors Max (" + m_SafeArea.m_Panel.anchorMax.x + ", " + m_SafeArea.m_Panel.anchorMax.y + ")");
            if (!Application.isPlaying && !m_SafeArea.m_IsSimulatingDevice)
            {
                EditorGUILayout.HelpBox("When the Unity DeviceSimulator package is enabled, default Anchors values need to be saved manually after being edited.", MessageType.Info);
                var previousColor = GUI.color;
                if (anchorWasEdited)
                {
                    GUI.color = Color.yellow;
                    EditorGUILayout.HelpBox("Anchors have been changed." +
                                            "\n\nIf you edited the Anchors, you need to save their new values using the button below. " +
                                            "\n\nIf you didn't edited them, it means they are temporarily changed by the device simulation, and you can ignore that message.", MessageType.Warning);
                    if (DeviceInfo.GetSafeArea().x != 0 || DeviceInfo.GetSafeArea().y != 0 || DeviceInfo.GetSafeArea().width != DeviceInfo.GetResolution().x || DeviceInfo.GetSafeArea().height != DeviceInfo.GetResolution().y)
                    {
                        EditorGUILayout.HelpBox("A device with notches is currently being simulated by the DeviceSimulator. It is recommended to edit and save the SafeArea Anchors only after switching from Simulator to GameView mode, or after selecting a device without notches.", MessageType.Warning);
                    }
                }
                if (GUILayout.Button("Save current Anchors as default"))
                {
                    m_SafeArea.m_DefaultAnchorMin = m_SafeArea.m_Panel.anchorMin;
                    m_SafeArea.m_DefaultAnchorMax = m_SafeArea.m_Panel.anchorMax;
                }
                if (anchorWasEdited)
                {
                    GUI.color = previousColor;
                }
            }
        }
        void ApplySafeAreaIfNeeded()
        {
            // We only apply safe area when detecting a change
            Rect safeArea = DeviceInfo.GetSafeArea();

            if (safeArea != m_LastSafeArea)
            {
                ApplySafeArea();
            }
        }
 void DefaultAnchorGUI()
 {
     EditorGUILayout.LabelField("Default Anchors Min (" + m_SafeArea.m_DefaultAnchorMin.x + ", " + m_SafeArea.m_DefaultAnchorMin.y + ")");
     EditorGUILayout.LabelField("Default Anchors Max (" + m_SafeArea.m_DefaultAnchorMax.x + ", " + m_SafeArea.m_DefaultAnchorMax.y + ")");
     // We automatically update the default Anchors if no device simulation is running
     if (!Application.isPlaying && !m_SafeArea.m_IsSimulatingDevice &&
         (DeviceInfo.GetSafeArea().x == 0 && DeviceInfo.GetSafeArea().y == 0 && DeviceInfo.GetSafeArea().width == DeviceInfo.GetResolution().x&& DeviceInfo.GetSafeArea().height == DeviceInfo.GetResolution().y))
     {
         m_SafeArea.m_DefaultAnchorMin = m_SafeArea.m_Panel.anchorMin;
         m_SafeArea.m_DefaultAnchorMax = m_SafeArea.m_Panel.anchorMax;
     }
 }
Exemple #4
0
        void ApplySafeAreaIfNeeded()
        {
            Rect safeArea = DeviceInfo.GetSafeArea();

                        #if !UNITY_EDITOR
            if (safeArea == m_LastSafeArea)
            {
                return;
            }
                        #endif

            ApplySafeArea(safeArea);
        }
        void ApplySafeArea()
        {
            Rect safeArea = DeviceInfo.GetSafeArea();

            ApplySafeArea(safeArea);
        }