/// <summary> /// Begin a new transition group /// </summary> /// <param name="index">Index of the group in Transitions</param> /// <param name="randomSeed">Random seed</param> public void StartNewTransitionGroup(int index, int randomSeed) { Initialize(randomSeed); currentTransition = Transitions[index]; transitionTime = TransitionTime.Random(random); holdTime = HoldTime.Random(random); totalTime = transitionTime; Debug.LogFormat("Starting Weather Transition {0}, transition time: {1:0.00}, hold time: {2:0.00}", currentTransition.TransitionGroup.Title, transitionTime, holdTime); // turn off things that don't need to be setup on every transition WeatherMakerScript.Instance.LightningScript.EnableLightning = false; foreach (WeatherMakerPropertyTransition t in currentTransition.TransitionGroup.Transitions) { t.UpdateStartValue(); } // store properties in case they are not animated - for this we will lerp these to low or 0 values as we want them essentially off by default unless they are animated startPrecipitationIntensity = WeatherMakerScript.Instance.PrecipitationIntensity; startFogDensity = (WeatherMakerScript.Instance.FogScript.FogProfile == null ? 0.0f : WeatherMakerScript.Instance.FogScript.FogProfile.FogDensity); startWindIntensity = WeatherMakerScript.Instance.WindIntensity; currentTransition.CustomUpdater = CustomUpdater; // how long the group transition lasts WeatherMakerScript.Instance.CloudChangeDuration = (UseBuiltInCloudAnimation ? transitionTime : 0.0f); holdingTransition = false; WeatherMakerScript.Instance.RaiseWeatherManagerTransitionStarted(WeatherMakerScript.Instance.WeatherManagers.IndexOf(this), index, randomSeed); }
private void StartNewTransitionGroup(WeatherMakerTransitionGroupWeight w) { currentTransition = w; // turn off things that don't need to be setup on every transition WeatherScript.LightningScript.EnableLightning = false; foreach (WeatherMakerPropertyTransition t in w.TransitionGroup.Transitions) { t.UpdateStartValue(); } // store properties in case they are not animated - for this we will lerp these to low or 0 values as we want them essentially off by default unless they are animated startPrecipitationIntensity = WeatherScript.PrecipitationIntensity; startFogDensity = WeatherScript.FogScript.FogDensity; startWindIntensity = WeatherScript.WindIntensity; currentTransition.CustomUpdater = CustomUpdater; // how long the group transition lasts transitionTime = TransitionTime.Random(); holdTime = HoldTime.Random(); totalTime = transitionTime; WeatherScript.CloudChangeDuration = (UseBuiltInCloudAnimation ? transitionTime : 0.0f); holdingTransition = false; Debug.LogFormat("Starting Weather Transition {0}, transition time: {1:0.00}, hold time: {2:0.00}", w.TransitionGroup.Title, transitionTime, holdTime); }
private float HeightForTransitionGroup(int index) { string foldoutKey = "WM_TF_" + index; bool foldout; if (foldouts.TryGetValue(foldoutKey, out foldout) && !foldout) { return(transitionGroupHeightMinimized); } WeatherMakerTransitionGroupWeight w = script.Transitions[index]; return(w.TransitionGroup.Transitions.Count == 0 ? transitionGroupMinHeight + 20.0f : transitionGroupMinHeight + (w.TransitionGroup.Transitions.Count * transitionHeight)); }
private void Update() { elapsedTime += Time.deltaTime; if (elapsedTime >= totalTime) { elapsedTime = 0.0f; if (holdingTransition || currentTransition == null) { currentTransition = null; PickTransition(); } else { // finish the transition currentTransition.Update(1.0f); holdingTransition = true; totalTime = holdTime; } } else if (currentTransition != null && !holdingTransition) { currentTransition.Update(elapsedTime / totalTime); } }
private void OnDisable() { elapsedTime = totalTime = holdTime = 0.0f; holdingTransition = false; currentTransition = null; }
private void RenderTransitionGroup(Rect rect, int index) { if (rect.width <= 0) { return; } WeatherMakerTransitionGroupWeight w = script.Transitions[index]; string foldoutKey = "WM_TF_" + index; bool foldout; foldouts.TryGetValue(foldoutKey, out foldout); rect.y += 2.0f; rect.x += 10.0f; rect.height = individualHeight - 4.0f; float width = rect.width; if (foldout) { rect.width = 24.0f; foldout = EditorGUI.Foldout(rect, foldout, string.Empty); } else { foldout = EditorGUI.Foldout(rect, foldout, new GUIContent(w.TransitionGroup.Title + ", Weight: " + w.Weight)); } rect.width = width; foldouts[foldoutKey] = foldout; if (foldout) { rect.width -= 8.0f; Rect origRect = rect; float x = rect.x; EditorGUIUtility.labelWidth = 50.0f; EditorGUIUtility.fieldWidth = 30.0f; rect.width = 100.0f; w.Weight = EditorGUI.IntField(rect, new GUIContent("Weight", "Weight for this transition group. Higher weights make the transition group more likely to occur."), w.Weight); rect.x = rect.xMax + 10.0f; rect.width = Mathf.Max(1.0f, width - 120.0f); w.TransitionGroup.Title = EditorGUI.TextField(rect, new GUIContent("Title", "Title for this transition, a short description."), w.TransitionGroup.Title); origRect.y += individualHeight + 2.0f; origRect.height -= 24.0f; string propPath = "Transitions.Array.data[" + index + "].TransitionGroup.Transitions"; SerializedProperty prop = scriptObject.FindProperty(propPath); if (w.TransitionList == null) { w.TransitionList = new ReorderableList(prop.serializedObject, prop, true, true, true, true); w.TransitionList.drawElementCallback = (rect2, index2, active, focused) => { RenderTransition(w, rect2, index2); }; w.TransitionList.drawHeaderCallback = rect2 => { EditorGUI.LabelField(rect2, "Transitions"); }; w.TransitionList.elementHeightCallback = (int index2) => { return(transitionHeight); }; } w.TransitionList.DoList(origRect); } }
private void RenderTransition(WeatherMakerTransitionGroupWeight w, Rect rect, int index) { if (index >= w.TransitionGroup.Transitions.Count) { return; } float textFieldWidth = Mathf.Min(rect.width, 150.0f); float longWidth = Mathf.Min(rect.width, 300.0f); float fullWidth = rect.width - 10.0f; WeatherMakerPropertyTransition t = w.TransitionGroup.Transitions[index]; EditorGUIUtility.labelWidth = labelWidth; float width = rect.width; float x = rect.x; rect.height = individualHeight; rect.width = fullWidth; MonoBehaviour newTarget = (MonoBehaviour)EditorGUI.ObjectField(rect, "Target", t.Target, typeof(MonoBehaviour), true); if (newTarget != t.Target) { t.Target = newTarget; t.FieldNamePopup = null; } rect.y += individualHeightWithSpacing; if (t.Target != null) { List <FieldInfo> fields = GetPossibleFields(t.Target); if (fields.Count == 0) { EditorGUI.LabelField(rect, "* No valid fields found *"); } else { if (t.FieldNamePopup == null) { t.FieldNamePopup = new PopupList(); t.FieldNamePopup.SelectedIndexChanged = (pu, ea) => { if (t.FieldNamePopup.SelectedItemIndex < fields.Count) { t.FieldName = fields[t.FieldNamePopup.SelectedItemIndex].Name; } t.Curve = null; }; } rect.width = longWidth; int i = 0; foreach (FieldInfo f in fields) { if (f.Name == t.FieldName) { t.FieldNamePopup.SelectedItemIndex = i; break; } i++; } EditorGUI.LabelField(rect, "Field:"); rect.x += EditorGUIUtility.labelWidth; rect.width = fullWidth - EditorGUIUtility.labelWidth; GUIStyle buttonStyle = "button"; buttonStyle.alignment = TextAnchor.MiddleLeft; if (GUI.Button(rect, fields[t.FieldNamePopup.SelectedItemIndex].Name + " (" + GetFieldDisplayName(fields[t.FieldNamePopup.SelectedItemIndex].FieldType.Name) + ")", buttonStyle)) { List <GUIContent> options = new List <GUIContent>(); foreach (FieldInfo f in fields) { options.Add(new GUIContent(f.Name + " (" + GetFieldDisplayName(f.FieldType.Name) + ")")); } t.FieldNamePopup.ListStyle = comboBoxStyle; t.FieldNamePopup.Items = options.ToArray(); PopupWindow.Show(rect, t.FieldNamePopup); } string newName = fields[t.FieldNamePopup.SelectedItemIndex].Name; if (newName != t.FieldName) { t.FieldName = newName; GUI.changed = true; } rect.x = x; rect.y += individualHeightWithSpacing + 2.0f; FieldInfo field = t.Target.GetType().GetField(t.FieldName, BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); rect.width = fullWidth; RenderField(rect, t, field, textFieldWidth); rect.y += individualHeightWithSpacing; AnimationCurve curve = t.Curve; if (curve == null || curve.length == 0) { Type ft = fields[t.FieldNamePopup.SelectedItemIndex].FieldType; // default to immediately setting the value if (ft == typeof(bool) || ft == typeof(System.Enum) || ft == typeof(RangeOfFloats) || ft == typeof(RangeOfIntegers)) { curve = AnimationCurve.Linear(0.0f, 1.0f, 0.0f, 1.0f); } else { // default to linear curve curve = AnimationCurve.Linear(0.0f, 0.0f, 1.0f, 1.0f); } } t.Curve = EditorGUI.CurveField(rect, "Curve", curve); rect.y += individualHeightWithSpacing; rect.height = 0.0f; rect.width = fullWidth; EditorDrawLine.DrawLine(rect, Color.cyan, 1.0f); } } }