コード例 #1
0
        /// <summary>
        /// This is called when we select the poi in the editor
        /// </summary>
        private void OnEnable()
        {
            if (target == null)
            {
                return;
            }
            m_trigger = (TriggerControlEnviro)target;

            if (m_trigger.m_enviroSky == null)
            {
                m_trigger.m_enviroSky = GameObject.FindObjectOfType <EnviroSkyMgr>();
            }

            if (m_trigger.m_enviroSky != null)
            {
                EnviroZone zone = m_trigger.m_enviroSky.gameObject.GetComponent <EnviroZone>();
                if (zone != null)
                {
                    m_zoneWeatheraPrefabs = zone.zoneWeatherPresets;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Draw the gui
        /// </summary>
        public override void OnInspectorGUI()
        {
            //Get our trigger
            m_trigger = (TriggerControlEnviro)target;

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle          = new GUIStyle(GUI.skin.label);
                m_wrapStyle.wordWrap = true;
            }

            //Create a nice text intro
            GUILayout.BeginVertical("Enviro Weather Trigger", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("This trigger controls Enviro time and weather settings.", m_wrapStyle);
            GUILayout.EndVertical();

            EditorGUI.BeginChangeCheck();

            GUILayout.Space(5);

            if (m_trigger.m_enviroSky == null)
            {
                EditorGUILayout.LabelField("Enviro Sky is missing from scene!!");
            }

            bool  controlTime = EditorGUILayout.Toggle("Control Time", m_trigger.m_controlTime);
            float startTime   = m_trigger.m_startTime;
            float endTime     = m_trigger.m_endTime;

            if (controlTime)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.LabelField(string.Format("{0:00}:{1:00} - {2:00}:{3:00}", Mathf.FloorToInt(startTime), (startTime % 1.0f) * 60f, Mathf.FloorToInt(endTime), (endTime % 1.0f) * 60f));
                startTime = EditorGUILayout.Slider(GetLabel("Start Time"), startTime, 0f, 23.99f);
                endTime   = EditorGUILayout.Slider(GetLabel("End Time"), endTime, 0f, 23.99f);
                EditorGUI.indentLevel--;
            }

            bool  controlWeather        = EditorGUILayout.Toggle("Control Weather", m_trigger.m_controlWeather);
            int   weatherID             = m_trigger.m_weatherID;
            float weatherTransitionTime = m_trigger.m_weatherTransitionTime;

            if (controlWeather)
            {
                EditorGUI.indentLevel++;
                if (m_zoneWeatheraPrefabs.Count > 0)
                {
                    GUIContent[] zonePrefabs = new GUIContent[m_zoneWeatheraPrefabs.Count];
                    for (int idx = 0; idx < zonePrefabs.Length; idx++)
                    {
                        zonePrefabs[idx] = new GUIContent(m_zoneWeatheraPrefabs[idx].Name);
                    }
                    weatherID = EditorGUILayout.Popup(GetLabel("Weather"), weatherID, zonePrefabs);
                }
                else
                {
                    weatherID = EditorGUILayout.IntField("Weather ID", weatherID);
                }
                weatherTransitionTime = EditorGUILayout.FloatField("Transition Time", weatherTransitionTime);
                EditorGUI.indentLevel--;
            }

            GUILayout.Space(5);

            //Check for changes, make undo record, make changes and let editor know we are dirty
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_trigger, "Made trigger changes");

                m_trigger.m_triggerAtStart  = controlTime || controlWeather;
                m_trigger.m_triggerOnUpdate = controlTime;
                m_trigger.m_triggerAtEnd    = false;

                m_trigger.m_controlTime = controlTime;
                m_trigger.m_startTime   = startTime;
                m_trigger.m_endTime     = endTime;

                m_trigger.m_controlWeather        = controlWeather;
                m_trigger.m_weatherID             = weatherID;
                m_trigger.m_weatherTransitionTime = weatherTransitionTime;

                //Mark it as dirty
                EditorUtility.SetDirty(m_trigger);
            }
        }