private void DrawCascadeSplitGUI <T>(ref SerializedProperty shadowCascadeSplit) { float[] array = null; Type typeFromHandle = typeof(T); if (typeFromHandle == typeof(float)) { array = new float[] { shadowCascadeSplit.floatValue }; } else if (typeFromHandle == typeof(Vector3)) { Vector3 vector3Value = shadowCascadeSplit.vector3Value; array = new float[] { Mathf.Clamp(vector3Value[0], 0f, 1f), Mathf.Clamp(vector3Value[1] - vector3Value[0], 0f, 1f), Mathf.Clamp(vector3Value[2] - vector3Value[1], 0f, 1f) }; } if (array != null) { EditorGUI.BeginChangeCheck(); ShadowCascadeSplitGUI.HandleCascadeSliderGUI(ref array); if (EditorGUI.EndChangeCheck()) { if (typeFromHandle == typeof(float)) { shadowCascadeSplit.floatValue = array[0]; } else { Vector3 vector3Value2 = default(Vector3); vector3Value2[0] = array[0]; vector3Value2[1] = vector3Value2[0] + array[1]; vector3Value2[2] = vector3Value2[1] + array[2]; shadowCascadeSplit.vector3Value = vector3Value2; } } } }
/** * Internal function that takes the shadow cascade splits property field, and dispatches a call to render the GUI. * It also transfers the result back */ private void DrawCascadeSplitGUI <T>(ref SerializedProperty shadowCascadeSplit) { float[] cascadePartitionSizes = null; System.Type type = typeof(T); if (type == typeof(float)) { cascadePartitionSizes = new float[] { shadowCascadeSplit.floatValue } } ; else if (type == typeof(Vector3)) { Vector3 splits = shadowCascadeSplit.vector3Value; cascadePartitionSizes = new float[] { Mathf.Clamp(splits[0], 0.0f, 1.0f), Mathf.Clamp(splits[1] - splits[0], 0.0f, 1.0f), Mathf.Clamp(splits[2] - splits[1], 0.0f, 1.0f) }; } if (cascadePartitionSizes != null) { EditorGUI.BeginChangeCheck(); ShadowCascadeSplitGUI.HandleCascadeSliderGUI(ref cascadePartitionSizes); if (EditorGUI.EndChangeCheck()) { if (type == typeof(float)) { shadowCascadeSplit.floatValue = cascadePartitionSizes[0]; } else { Vector3 updatedValue = new Vector3(); updatedValue[0] = cascadePartitionSizes[0]; updatedValue[1] = updatedValue[0] + cascadePartitionSizes[1]; updatedValue[2] = updatedValue[1] + cascadePartitionSizes[2]; shadowCascadeSplit.vector3Value = updatedValue; } } } }
private void DrawCascadeSplitGUI <T>(ref SerializedProperty shadowCascadeSplit) { float[] normalizedCascadePartitions = (float[])null; System.Type type = typeof(T); if (type == typeof(float)) { normalizedCascadePartitions = new float[1] { shadowCascadeSplit.floatValue } } ; else if (type == typeof(Vector3)) { Vector3 vector3Value = shadowCascadeSplit.vector3Value; normalizedCascadePartitions = new float[3] { Mathf.Clamp(vector3Value[0], 0.0f, 1f), Mathf.Clamp(vector3Value[1] - vector3Value[0], 0.0f, 1f), Mathf.Clamp(vector3Value[2] - vector3Value[1], 0.0f, 1f) }; } if (normalizedCascadePartitions == null) { return; } ShadowCascadeSplitGUI.HandleCascadeSliderGUI(ref normalizedCascadePartitions); if (type == typeof(float)) { shadowCascadeSplit.floatValue = normalizedCascadePartitions[0]; } else { Vector3 vector3 = new Vector3(); vector3[0] = normalizedCascadePartitions[0]; vector3[1] = vector3[0] + normalizedCascadePartitions[1]; vector3[2] = vector3[1] + normalizedCascadePartitions[2]; shadowCascadeSplit.vector3Value = vector3; } }