public static void SetSunStudyData(Unity.SunStudy.SunStudy sunStudy, SunStudyData sunStudyData)
 {
     sunStudy.MinuteOfDay    = sunStudyData.timeOfDay;
     sunStudy.DayOfYear      = sunStudyData.timeOfYear;
     sunStudy.UtcOffset      = sunStudyData.utcOffset / 100f;
     sunStudy.CoordLatitude  = sunStudyData.latitude;
     sunStudy.CoordLongitude = sunStudyData.longitude;
     sunStudy.NorthAngle     = sunStudyData.northAngle;
     sunStudy.Azimuth        = sunStudyData.azimuth;
     sunStudy.Altitude       = sunStudyData.altitude;
     sunStudy.PlacementMode  = sunStudyData.isStaticMode ? SunPlacementMode.Static : SunPlacementMode.Geographical;
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (m_ShowPlacement = EditorGUILayout.Foldout(m_ShowPlacement, "Placement"))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    EditorGUILayout.PropertyField(m_PlacementModeProp, new GUIContent("Mode"));

                    if (check.changed)
                    {
                        m_ShowCoordinates = true;
                        m_ShowTime        = true;
                        m_ShowIntensity   = true;
                    }
                }

                if (m_PlacementModeProp.enumValueIndex == (int)SunPlacementMode.Static)
                {
                    EditorGUILayout.Slider(m_AzimuthProp, 0f, 360f, "Azimuth");
                    EditorGUILayout.Slider(m_AltitudeProp, -90f, +90f, "Altitude");
                }
                else // SunPlacementMode.Geographical
                {
                    using (new EditorGUI.DisabledScope(true))
                    {
                        EditorGUILayout.PropertyField(m_AzimuthProp, new GUIContent("Azimuth"));
                        EditorGUILayout.PropertyField(m_AltitudeProp, new GUIContent("Altitude"));
                    }
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel("True North");

                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        Vector2 northDirection = m_NorthDirectionProp.vector2Value;

                        EditorGUILayout.LabelField("X", GUILayout.Width(10));
                        northDirection.x = EditorGUILayout.FloatField(northDirection.x);
                        EditorGUILayout.LabelField("Z", GUILayout.Width(10));
                        northDirection.y = EditorGUILayout.FloatField(northDirection.y);
                        EditorGUILayout.LabelField("", GUILayout.Width(50));

                        if (check.changed)
                        {
                            m_NorthDirectionProp.vector2Value = northDirection;
                        }
                    }
                }

                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    float northAngle = EditorGUILayout.Slider(" ", SunStudy.GetNorthAngle(m_NorthDirectionProp.vector2Value), 0f, 360f);

                    if (check.changed)
                    {
                        m_NorthDirectionProp.vector2Value = m_NorthDirectionProp.vector2Value.magnitude * SunStudy.GetNorthDirection(northAngle);
                    }
                }
            }

            bool placementGeographical = m_PlacementModeProp.enumValueIndex == (int)SunPlacementMode.Geographical;

            using (new EditorGUI.DisabledScope(!placementGeographical))
            {
                m_ShowCoordinates = EditorGUILayout.Foldout(m_ShowCoordinates, "Coordinates") && placementGeographical;

                if (m_ShowCoordinates)
                {
                    EditorGUILayout.PropertyField(m_CoordinateModeProp, new GUIContent("Mode"));

                    if (m_CoordinateModeProp.enumValueIndex == (int)SunCoordinateMode.LatitudeLongitude)
                    {
                        EditorGUILayout.Slider(m_CoordLatitudeProp, -90f, +90f, "Latitude");
                        EditorGUILayout.Slider(m_CoordLongitudeProp, -180f, +180f, "Longitude");
                    }
                    else // SunCoordinateMode.Address or SunCoordinateMode.DegreesMinutesSeconds
                    {
                        using (new EditorGUI.DisabledScope(true))
                        {
                            EditorGUILayout.PropertyField(m_CoordLatitudeProp, new GUIContent("Latitude"));
                            EditorGUILayout.PropertyField(m_CoordLongitudeProp, new GUIContent("Longitude"));
                        }

                        if (m_CoordinateModeProp.enumValueIndex == (int)SunCoordinateMode.Address)
                        {
                            EditorGUILayout.DelayedTextField(m_CoordAddressProp, new GUIContent("Address"));

                            using (new EditorGUI.DisabledScope(true))
                            {
                                EditorGUILayout.PropertyField(m_GeocodingMessageProp, new GUIContent("Message"));
                            }
                        }
                        else // SunCoordinateMode.DegreesMinutesSeconds
                        {
                            using (new EditorGUILayout.HorizontalScope())
                            {
                                EditorGUILayout.PrefixLabel(" ");

                                EditorGUILayout.LabelField("", GUILayout.Width(0.1f));

                                using (var check = new EditorGUI.ChangeCheckScope())
                                {
                                    int enumValueIndex = GUILayout.SelectionGrid(m_CoordNSProp.enumValueIndex, new string[] { "N", "S" }, 2, EditorStyles.radioButton, GUILayout.Width(60));

                                    if (check.changed)
                                    {
                                        m_CoordNSProp.enumValueIndex = enumValueIndex;
                                    }
                                }

                                EditorGUILayout.LabelField("", GUILayout.Width(5));

                                EditorGUILayout.PropertyField(m_CoordNSDegProp, GUIContent.none, GUILayout.Width(30));
                                EditorGUILayout.LabelField("deg", GUILayout.Width(25));
                                EditorGUILayout.PropertyField(m_CoordNSMinProp, GUIContent.none, GUILayout.Width(30));
                                EditorGUILayout.LabelField("min", GUILayout.Width(25));
                                EditorGUILayout.PropertyField(m_CoordNSSecProp, GUIContent.none, GUILayout.Width(30));
                                EditorGUILayout.LabelField("sec", GUILayout.Width(25));
                            }

                            using (new EditorGUILayout.HorizontalScope())
                            {
                                EditorGUILayout.PrefixLabel(" ");

                                EditorGUILayout.LabelField("", GUILayout.Width(0.1f));

                                using (var check = new EditorGUI.ChangeCheckScope())
                                {
                                    int enumValueIndex = GUILayout.SelectionGrid(m_CoordEWProp.enumValueIndex, new string[] { "E", "W" }, 2, EditorStyles.radioButton, GUILayout.Width(60));

                                    if (check.changed)
                                    {
                                        m_CoordEWProp.enumValueIndex = enumValueIndex;
                                    }
                                }

                                EditorGUILayout.LabelField("", GUILayout.Width(5));

                                EditorGUILayout.PropertyField(m_CoordEWDegProp, GUIContent.none, GUILayout.Width(30));
                                EditorGUILayout.LabelField("deg", GUILayout.Width(25));
                                EditorGUILayout.PropertyField(m_CoordEWMinProp, GUIContent.none, GUILayout.Width(30));
                                EditorGUILayout.LabelField("min", GUILayout.Width(25));
                                EditorGUILayout.PropertyField(m_CoordEWSecProp, GUIContent.none, GUILayout.Width(30));
                                EditorGUILayout.LabelField("sec", GUILayout.Width(25));
                            }
                        }
                    }
                }

                m_ShowTime = EditorGUILayout.Foldout(m_ShowTime, "Time") && placementGeographical;

                if (m_ShowTime)
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.PrefixLabel("Time");

                        EditorGUILayout.PropertyField(m_YearProp, GUIContent.none, GUILayout.Width(35));
                        EditorGUILayout.LabelField("−", GUILayout.Width(10));

                        using (var check = new EditorGUI.ChangeCheckScope())
                        {
                            int monthValue = EditorGUILayout.Popup(m_MonthProp.intValue - 1, k_MonthNames, GUILayout.Width(75));

                            if (check.changed)
                            {
                                m_MonthProp.intValue = monthValue + 1;
                            }
                        }

                        EditorGUILayout.LabelField("−", GUILayout.Width(10));
                        EditorGUILayout.PropertyField(m_DayProp, GUIContent.none, GUILayout.Width(20));

                        EditorGUILayout.LabelField("", GUILayout.Width(10));

                        EditorGUILayout.PropertyField(m_HourProp, GUIContent.none, GUILayout.Width(20));
                        EditorGUILayout.LabelField(":", GUILayout.Width(7));
                        EditorGUILayout.PropertyField(m_MinuteProp, GUIContent.none, GUILayout.Width(20));
                        EditorGUILayout.LabelField(": 00", GUILayout.Width(25));
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.PrefixLabel(" ");

                        EditorGUILayout.LabelField("UTC Offset", GUILayout.Width(65));

                        using (var check = new EditorGUI.ChangeCheckScope())
                        {
                            int utcOffsetValue = EditorGUILayout.IntPopup((int)(m_UtcOffsetProp.floatValue * 100f), k_UtcOffsetNames, k_UtcOffsetValues, GUILayout.Width(60));

                            if (check.changed)
                            {
                                m_UtcOffsetProp.floatValue = utcOffsetValue / 100f;
                            }
                        }
                    }

                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        int dayOfYear = EditorGUILayout.IntSlider("Day of Year", SunStudy.GetDayOfYear(m_YearProp.intValue, m_MonthProp.intValue, m_DayProp.intValue), 1, SunStudy.GetDayOfYear(m_YearProp.intValue, 12, 31));

                        if (check.changed)
                        {
                            (m_MonthProp.intValue, m_DayProp.intValue) = SunStudy.SetDayOfYear(m_YearProp.intValue, dayOfYear);
                        }
                    }

                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        int minuteOfDay = EditorGUILayout.IntSlider("Minute of Day", SunStudy.GetMinuteOfDay(m_HourProp.intValue, m_MinuteProp.intValue), 0, 1439);

                        if (check.changed)
                        {
                            (m_HourProp.intValue, m_MinuteProp.intValue) = SunStudy.SetMinuteOfDay(minuteOfDay);
                        }
                    }
                }

                m_ShowIntensity = EditorGUILayout.Foldout(m_ShowIntensity, "Intensity") && placementGeographical;

                if (m_ShowIntensity)
                {
                    EditorGUILayout.PropertyField(m_SunLightProp);

                    using (new EditorGUI.DisabledScope(m_SunLightProp.objectReferenceValue == null))
                    {
                        EditorGUILayout.PropertyField(m_IntensityProp);
                        EditorGUILayout.PropertyField(m_ApplyDimmingProp);
                    }

                    using (new EditorGUI.DisabledScope(true))
                    {
                        EditorGUILayout.PropertyField(m_DimmingProp);
                    }
                }

                bool coordinateAddress = m_CoordinateModeProp.enumValueIndex == (int)SunCoordinateMode.Address;

                using (new EditorGUI.DisabledScope(!coordinateAddress))
                {
                    m_ShowGeocodingApi = EditorGUILayout.Foldout(m_ShowGeocodingApi, "Geocoding API") && placementGeographical && coordinateAddress;

                    if (m_ShowGeocodingApi)
                    {
                        using (var check = new EditorGUI.ChangeCheckScope())
                        {
                            string geocodingApiKey = EditorGUILayout.TextField("Key", PlayerPrefs.GetString(SunStudy.k_PlayerPrefGeocodingApiKey));

                            if (check.changed)
                            {
                                PlayerPrefs.SetString(SunStudy.k_PlayerPrefGeocodingApiKey, geocodingApiKey);
                            }
                        }
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }