Exemple #1
0
        private void OnEnable()
        {
            // Get target
            m_target = (AzureTimeController)target;
            m_target.UpdateCalendar();
            m_dateButtonLabel = m_target.GetDateString();
            m_dayOfWeekLabel  = m_target.GetDayOfWeekString();

            // Find the serialized properties
            m_timeSystem             = serializedObject.FindProperty("timeSystem");
            m_timeDirection          = serializedObject.FindProperty("timeDirection");
            m_repeatMode             = serializedObject.FindProperty("repeatMode");
            m_timeline               = serializedObject.FindProperty("timeline");
            m_latitude               = serializedObject.FindProperty("latitude");
            m_longitude              = serializedObject.FindProperty("longitude");
            m_utc                    = serializedObject.FindProperty("utc");
            m_dayLength              = serializedObject.FindProperty("dayLength");
            m_isTimeEvaluatedByCurve = serializedObject.FindProperty("isTimeEvaluatedByCurve");
            m_dayLengthCurve         = serializedObject.FindProperty("dayLengthCurve");
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            // Initializations
            m_buttonGridIndex     = 0;
            m_selectedCalendarDay = m_target.selectedCalendarDay;
            m_dateButtonLabel     = m_target.GetDateString();
            m_dayOfWeekLabel      = m_target.GetDayOfWeekString();

            // Start custom inspector
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            // Calendar header buttons
            EditorGUILayout.BeginHorizontal("box");
            if (GUILayout.Button("<<", EditorStyles.miniButtonLeft, GUILayout.Width(25)))
            {
                DecreaseYear();
            }
            if (GUILayout.Button("<", EditorStyles.miniButtonMid, GUILayout.Width(25)))
            {
                DecreaseMonth();
            }
            if (GUILayout.Button(m_dateButtonLabel, EditorStyles.miniButtonMid))
            {
                m_showCustomDate  = !m_showCustomDate;
                m_dateSelector[0] = m_target.month;
                m_dateSelector[1] = m_target.day;
                m_dateSelector[2] = m_target.year;
            }
            if (GUILayout.Button(">", EditorStyles.miniButtonMid, GUILayout.Width(25)))
            {
                IncreaseMonth();
            }
            if (GUILayout.Button(">>", EditorStyles.miniButtonRight, GUILayout.Width(25)))
            {
                IncreaseYear();
            }
            EditorGUILayout.EndHorizontal();

            if (m_showCustomDate)
            {
                GUILayout.Space(-4);
                EditorGUILayout.BeginVertical("box");
                EditorGUI.MultiIntField(EditorGUILayout.GetControlRect(), m_dateSelectorContent, m_dateSelector);
                m_dateSelector[0] = Mathf.Clamp(m_dateSelector[0], 1, 12);
                m_dateSelector[1] = Mathf.Min(m_dateSelector[1], DateTime.DaysInMonth(m_target.year, m_target.month));
                m_dateSelector[2] = Mathf.Clamp(m_dateSelector[2], 0, 9999);
                if (GUILayout.Button("Go To", EditorStyles.miniButtonMid))
                {
                    m_target.SetNewDate(m_dateSelector[2], m_dateSelector[0], m_dateSelector[1]);
                    m_selectedCalendarDay = m_target.selectedCalendarDay;
                    m_showCustomDate      = false;
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(3);
            }

            // Draws the days of the week strings above the selectable grid
            GUILayout.Space(-5);
            EditorGUILayout.BeginHorizontal("box");
            GUILayout.Label("Sun");
            GUILayout.Label("Mon");
            GUILayout.Label("Tue");
            GUILayout.Label("Wed");
            GUILayout.Label("Thu");
            GUILayout.Label("Fri");
            GUILayout.Label("Sat");
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(-5);

            // Creates the calendar selectable grid
            EditorGUILayout.BeginVertical("Box");
            for (int i = 0; i < 6; i++)
            {
                EditorGUILayout.BeginHorizontal();
                for (int j = 0; j < 7; j++)
                {
                    m_isDaySelected = m_selectedCalendarDay == m_buttonGridIndex ? true : false;
                    if (GUILayout.Toggle(m_isDaySelected, m_target.DayList[m_buttonGridIndex], GUI.skin.button, GUILayout.MinWidth(30)))
                    {
                        if (m_target.DayList[m_buttonGridIndex] != "")
                        {
                            m_selectedCalendarDay = m_buttonGridIndex;
                        }
                    }

                    m_buttonGridIndex++;
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();

            // Options
            EditorGUILayout.PropertyField(m_timeSystem, m_guiContent[0]);
            EditorGUILayout.PropertyField(m_timeDirection, m_guiContent[10]);
            EditorGUILayout.PropertyField(m_repeatMode, m_guiContent[1]);

            // Sliders
            EditorGUILayout.Slider(m_timeline, 0.0f, 24.0f, m_guiContent[2]);
            EditorGUILayout.Slider(m_latitude, -90.0f, 90.0f, m_guiContent[3]);
            EditorGUILayout.Slider(m_longitude, -180.0f, 180.0f, m_guiContent[4]);
            EditorGUILayout.Slider(m_utc, -12.0f, 12.0f, m_guiContent[5]);
            EditorGUILayout.PropertyField(m_dayLength, m_guiContent[6]);

            // Day-Night length curve
            EditorGUILayout.BeginVertical("Box");
            GUILayout.Space(-5);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            GUILayout.Label("Day and Night Length", EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();
            // Toggle
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(m_guiContent[7]);
            EditorGUILayout.PropertyField(m_isTimeEvaluatedByCurve, GUIContent.none, GUILayout.Width(15));
            EditorGUILayout.EndHorizontal();
            // Reset Button
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("R", GUILayout.Width(25), GUILayout.Height(25)))
            {
                m_dayLengthCurve.animationCurveValue = AnimationCurve.Linear(0, 0, 24, 24);
            }
            // Curve field
            EditorGUILayout.CurveField(m_dayLengthCurve, Color.yellow, new Rect(0, 0, 24, 24), GUIContent.none, GUILayout.Height(25));
            EditorGUILayout.EndHorizontal();
            // Current time display
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(m_guiContent[8]);
            GUILayout.Label(m_dayOfWeekLabel
                            + " " + m_target.hour.ToString("00")
                            + ":" + m_target.minute.ToString("00"), GUILayout.ExpandWidth(false));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            // Update the inspector when there is a change
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_target, "Undo Azure Time Controller");
                if (m_target.selectedCalendarDay != m_selectedCalendarDay)
                {
                    m_target.day = m_selectedCalendarDay + 1 - m_target.GetDayOfWeek(m_target.year, m_target.month, 1);
                    m_target.selectedCalendarDay = m_selectedCalendarDay;
                }

                serializedObject.ApplyModifiedProperties();
                m_target.UpdateCalendar();
            }

            // Updates the calendar if the undo command is performed
            if (Event.current.commandName == "UndoRedoPerformed")
            {
                m_target.UpdateCalendar();
            }
        }
        public override void OnInspectorGUI()
        {
            // Initializations
            m_buttonGridIndex = 0;

            // Start custom inspector
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            // Logo
            m_controlRect = EditorGUILayout.GetControlRect(GUILayout.Height(65));
            EditorGUI.LabelField(m_controlRect, "", "", "selectionRect");
            if (logoTexture)
            {
                GUI.DrawTexture(new Rect(m_controlRect.x, m_controlRect.y, 261, 56), logoTexture);
            }
            EditorGUILayout.Space(-18);
            GUILayout.Label(" Version 7.0.2", EditorStyles.miniLabel);

            // Calendar header buttons
            EditorGUILayout.BeginHorizontal("box");
            if (GUILayout.Button("<<", EditorStyles.miniButtonLeft, GUILayout.Width(25)))
            {
                DecreaseYear();
            }
            if (GUILayout.Button("<", EditorStyles.miniButtonMid, GUILayout.Width(25)))
            {
                DecreaseMonth();
            }
            if (GUILayout.Button(m_target.GetDateString(), EditorStyles.miniButtonMid))
            {
                m_showFastDateSelector = !m_showFastDateSelector;
                m_fastDateSelector[0]  = m_month.intValue;
                m_fastDateSelector[1]  = m_day.intValue;
                m_fastDateSelector[2]  = m_year.intValue;
            }
            if (GUILayout.Button(">", EditorStyles.miniButtonMid, GUILayout.Width(25)))
            {
                IncreaseMonth();
            }
            if (GUILayout.Button(">>", EditorStyles.miniButtonRight, GUILayout.Width(25)))
            {
                IncreaseYear();
            }
            EditorGUILayout.EndHorizontal();

            if (m_showFastDateSelector)
            {
                EditorGUILayout.Space(-4);
                EditorGUILayout.BeginVertical("box");
                EditorGUI.MultiIntField(EditorGUILayout.GetControlRect(), m_dateSelectorContent, m_fastDateSelector);
                m_fastDateSelector[0] = Mathf.Clamp(m_fastDateSelector[0], 1, 12);
                m_fastDateSelector[2] = Mathf.Clamp(m_fastDateSelector[2], 0, 9999);
                m_fastDateSelector[1] = Mathf.Min(m_fastDateSelector[1], DateTime.DaysInMonth(m_fastDateSelector[2], m_fastDateSelector[0]));
                if (GUILayout.Button("Go To", EditorStyles.miniButtonMid))
                {
                    Undo.RecordObject(m_target, "Undo Azure Time Controller");
                    m_target.SetDate(m_fastDateSelector[2], m_fastDateSelector[0], m_fastDateSelector[1]);
                    m_target.ForceEditorUpdate();
                    m_showFastDateSelector = false;
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space(3);
            }

            // Draws the days of the week strings above the selectable grid
            EditorGUILayout.Space(-5);
            EditorGUILayout.BeginHorizontal("box");
            GUILayout.Label("Sun");
            GUILayout.Label("Mon");
            GUILayout.Label("Tue");
            GUILayout.Label("Wed");
            GUILayout.Label("Thu");
            GUILayout.Label("Fri");
            GUILayout.Label("Sat");
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space(-5);

            // Creates the calendar selectable grid
            EditorGUILayout.BeginVertical("Box");
            for (int i = 0; i < 6; i++)
            {
                EditorGUILayout.BeginHorizontal();
                for (int j = 0; j < 7; j++)
                {
                    m_isDaySelected = m_selectedCalendarDay.intValue == m_buttonGridIndex ? true : false;
                    if (GUILayout.Toggle(m_isDaySelected, m_dayNumberList.GetArrayElementAtIndex(m_buttonGridIndex).stringValue, GUI.skin.button, GUILayout.MinWidth(30)))
                    {
                        if (m_dayNumberList.GetArrayElementAtIndex(m_buttonGridIndex).stringValue != "")
                        {
                            m_selectedCalendarDay.intValue = m_buttonGridIndex;
                        }
                    }

                    m_buttonGridIndex++;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();

            // References
            EditorGUILayout.PropertyField(m_sunTransform);
            EditorGUILayout.PropertyField(m_moonTransform);
            EditorGUILayout.PropertyField(m_directionalLight);
            EditorGUILayout.PropertyField(m_followTarget);
            //EditorGUILayout.Space();

            // Options
            EditorGUILayout.PropertyField(m_timeSystem);
            EditorGUILayout.PropertyField(m_timeDirection);
            EditorGUILayout.PropertyField(m_dateLoop);

            // Sliders
            EditorGUILayout.Slider(m_timeline, 0.0f, 24.0f);
            EditorGUILayout.Slider(m_latitude, -90.0f, 90.0f);
            EditorGUILayout.Slider(m_longitude, -180.0f, 180.0f);
            EditorGUILayout.Slider(m_utc, -12.0f, 12.0f);
            EditorGUILayout.PropertyField(m_dayLength);
            EditorGUILayout.PropertyField(m_minLightAltitude);

            // Day-Night length curve
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.Space(-5);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            GUILayout.Label("Day and Night Length", EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();

            // Toggle
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Evaluate Time of Day by Curve?", "Will the 'time of day' be evaluated based on the timeline or based on the day-night length curve?"));
            EditorGUILayout.PropertyField(m_isTimeEvaluatedByCurve, GUIContent.none, GUILayout.Width(15));
            EditorGUILayout.EndHorizontal();

            // Reset Button
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("R", GUILayout.Width(25), GUILayout.Height(25)))
            {
                Undo.RecordObject(m_target, "Undo Azure Time Controller");
                m_dayLengthCurve.animationCurveValue = AnimationCurve.Linear(0, 0, 24, 24);
            }

            // Curve field
            EditorGUILayout.CurveField(m_dayLengthCurve, Color.yellow, new Rect(0, 0, 24, 24), GUIContent.none, GUILayout.Height(25));
            EditorGUILayout.EndHorizontal();

            // Time of day display
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Current Time of Day:", "Displays the current 'time of day' based on the 'time position' of the day-night cycle"));
            GUILayout.Label(m_target.GetDayOfWeekString() + " " + m_hour.intValue.ToString("00") + ":" + m_minute.intValue.ToString("00"), GUILayout.ExpandWidth(false));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            // Draw the celestial bodies reorderable lists
            if (m_timeSystem.enumValueIndex == 1)
            {
                m_reorderableCelestialBodiesList.DoLayoutList();
            }

            // Events
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_onMinuteChange);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_onHourChange);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_onDayChange);
            EditorGUILayout.Space(10);

            // Custom event list header
            EditorGUILayout.BeginHorizontal("RL Header");
            m_controlRect = EditorGUILayout.GetControlRect();
            EditorGUI.LabelField(new Rect(m_controlRect.x + 2, m_controlRect.y, m_controlRect.width, m_controlRect.height), "Custom Event List", EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();
            m_controlRect = EditorGUILayout.GetControlRect(GUILayout.Height(25));

            // Draw the custom event list
            EditorGUILayout.Space(-25);
            m_reorderableCeustomEventList.DoLayoutList();
            EditorGUILayout.Space(25);

            // Custom event scan mode
            EditorGUI.LabelField(new Rect(m_controlRect.x, m_controlRect.y - 2, m_controlRect.width, m_controlRect.height), "", "", "RL Background");
            EditorGUI.LabelField(new Rect(m_controlRect.x + 6, m_controlRect.y + 8, 10, m_controlRect.height), "", "", "RL DragHandle");
            //EditorGUI.LabelField(new Rect(m_controlRect.x + 19, m_controlRect.y + 1, m_controlRect.width - 30, EditorGUIUtility.singleLineHeight), "Scan Mode");
            EditorGUI.PropertyField(new Rect(m_controlRect.x + 5, m_controlRect.y + 1, m_controlRect.width - 10, m_controlRect.height), m_customEventScanMode, new GUIContent("Scan Mode", ""));

            // Update the inspector when there is a change
            if (EditorGUI.EndChangeCheck())
            {
                m_day.intValue = m_selectedCalendarDay.intValue + 1 - m_target.GetDayOfWeek(m_year.intValue, m_month.intValue, 1);
                serializedObject.ApplyModifiedProperties();
                m_target.UpdateCalendar();
                //m_target.ComputeCelestialCoordinates();
            }

            // Updates the calendar if the undo command is performed
            if (Event.current.commandName == "UndoRedoPerformed")
            {
                m_target.UpdateCalendar();
                m_target.ForceEditorUpdate();
            }
        }