// Update all of the weather systems. public void UpdateForTimeOfDay(SkyProfile skyProfile, float timeOfDay) { if (!skyProfile) { return; } m_Profile = skyProfile; m_TimeOfDay = timeOfDay; // Update all the controllers state. if (weatherDepthCamera != null) { weatherDepthCamera.enabled = skyProfile.IsFeatureEnabled(ProfileFeatureKeys.RainSplashFeature); } if (rainDownfallController != null) { rainDownfallController.UpdateForTimeOfDay(skyProfile, timeOfDay); } if (rainSplashController != null) { rainSplashController.UpdateForTimeOfDay(skyProfile, timeOfDay); } if (lightningController != null) { lightningController.UpdateForTimeOfDay(skyProfile, timeOfDay); } }
private void OnEnable() { serializedObject.Update(); m_Profile = (SkyProfile)target; m_SectionHeaderBg = CreateColorImage(SectionColorForEditorSkin()); // Make the sure the profile's features are in sync with shader material. ApplyKeywordsToMaterial(); }
public static void AddSkyResource(SkyProfile profile, Texture texture) { CreateSkyDataDirectory(profile); string texturePath = GetSkyProfileAssetPath(profile, texture.name); if (AssetDatabase.IsValidFolder(Path.GetDirectoryName(texturePath)) == false) { AssetDatabase.CreateFolder(Path.GetDirectoryName(texturePath), Path.GetFileName(texturePath)); } AssetDatabase.CreateAsset(texture, texturePath); }
public static void ApplyKeywordsToMaterial(SkyProfile profile, Material skyboxMaterial) { foreach (ProfileFeatureSection section in profile.featureDefinitions) { foreach (ProfileFeatureDefinition definition in section.featureDefinitions) { SetShaderKeyword( definition.shaderKeyword, profile.IsFeatureEnabled(definition.featureKey), skyboxMaterial); } } }
public void UpdateForTimeOfDay(SkyProfile skyProfile, float timeOfDay, RainSplashArtItem style) { m_SkyProfile = skyProfile; m_TimeOfDay = timeOfDay; m_Style = style; if (m_SkyProfile == null) { return; } SyncDataFromSkyProfile(); }
// Use vertex shader to fix aspect ratio. public static void RenderNumberGroup(Rect rect, SkyProfile profile, NumberKeyframeGroup group) { lock (profile) { bool sortKeyFrames = false; RenderLinePath(rect, group); for (int i = 0; i < group.keyframes.Count; i++) { NumberKeyframe currentKey = group.GetKeyframe(i); int nextIndex = (i + 1) % group.keyframes.Count; NumberKeyframe nextKey = group.GetKeyframe(nextIndex); // Clamp time if we're wrapping around. float nextTime = nextKey.time; if (nextTime <= currentKey.time) { nextTime = 1.0f; } bool didSingleClick = false; bool isDragging = false; bool keyframeUpdated = false; SkyEditorUtility.DrawNumericKeyMarker(rect, currentKey, group, profile, out didSingleClick, out isDragging, out keyframeUpdated); if (keyframeUpdated) { sortKeyFrames = true; } if (didSingleClick || isDragging) { KeyframeInspectorWindow.SetKeyframeData( currentKey, group, KeyframeInspectorWindow.KeyType.Numeric, profile); if (didSingleClick && KeyframeInspectorWindow.inspectorEnabled == false) { KeyframeInspectorWindow.ShowWindow(); } } } if (sortKeyFrames) { group.SortKeyframes(); } } }
// Render a timeline of numeric keyframe positions. private void RenderNumericRowAndAdvance(ref Rect rect, SkyProfile profile, NumberKeyframeGroup group, ProfileGroupDefinition groupDefinition) { rect.height = NUMBER_ROW_HEIGHT; UpdateActiveSelectedRow(rect, group.id, groupDefinition.propertyKey); Rect valueRowRect; Rect nameRowRect; bool isActive; LoadRowInformation(ref rect, group.id, NUMBER_ROW_HEIGHT, out valueRowRect, out nameRowRect, out isActive); RenderRowTitle(nameRowRect, group.name, isActive, groupDefinition); NumberTimelineRow.RenderNumberGroup(valueRowRect, profile, group); }
// Render a timeline of gradient keyframes. private void RenderGradientRowAndAdvance(ref Rect rect, SkyProfile profile, ColorKeyframeGroup group, ProfileGroupDefinition groupDefinition) { rect.height = COLOR_ROW_HEIGHT; UpdateActiveSelectedRow(rect, group.id, groupDefinition.propertyKey); Rect valueRowRect; Rect nameRowRect; bool isActive; LoadRowInformation(ref rect, group.id, COLOR_ROW_HEIGHT, out valueRowRect, out nameRowRect, out isActive); RenderRowTitle(nameRowRect, group.name, isActive, groupDefinition); ColorTimelineRow.RenderColorGroupRow(valueRowRect, profile, group); }
public static string GetSkyProfileAssetPath(SkyProfile profile, string assetName) { CreateSkyDataDirectory(profile); string profileAssetPath = AssetDatabase.GetAssetPath(profile); if (profileAssetPath == null || profileAssetPath.Length == 0) { Debug.LogError("Can't return asset path that doesn't exist in database"); return(null); } string skyResourceDir = Path.GetDirectoryName(profileAssetPath); return(skyResourceDir + "/Data/" + assetName + ".asset"); }
public static void CreateSkyDataDirectory(SkyProfile profile) { string profilePath = AssetDatabase.GetAssetPath(profile); if (profilePath == null) { Debug.LogError("Failed to locate sky profile on disk, is it saved yet?"); return; } string containingDir = Path.GetDirectoryName(profilePath); string fullSkyDataPath = containingDir + "/" + GENERATED_CONTENT_DIR; if (AssetDatabase.IsValidFolder(fullSkyDataPath) == false) { AssetDatabase.CreateFolder(containingDir, GENERATED_CONTENT_DIR); } }
public static void ShowAddTimelinePropertyMenu(SkyProfile profile, List <ProfileGroupDefinition> groups) { s_Profile = profile; GenericMenu menu = new GenericMenu(); foreach (ProfileGroupSection sectionInfo in s_Profile.GetProfileDefinitions()) { foreach (ProfileGroupDefinition groupInfo in sectionInfo.groups) { if (s_Profile.IsManagedByTimeline(groupInfo.propertyKey) == false && s_Profile.CanGroupBeOnTimeline(groupInfo)) { string itemName = sectionInfo.sectionTitle + "/" + groupInfo.groupName; menu.AddItem(new GUIContent(itemName), false, DidSelectAddTimelineProperty, groupInfo.propertyKey); } } } menu.ShowAsContext(); }
public void UpdateForTimeOfDay(SkyProfile skyProfile, float timeOfDay, LightningArtItem artItem) { m_SkyProfile = skyProfile; m_TimeOfDay = timeOfDay; m_Style = artItem; if (m_SkyProfile == null) { Debug.LogError("Assigned null sky profile!"); return; } if (m_Style == null) { Debug.LogError("Can't render lightning without an art item"); return; } SyncDataFromSkyProfile(); }
// Render a timeline of sphere point keyframes. private void RenderSpherePointRowAndAdvance(ref Rect rect, SkyProfile profile, SpherePointKeyframeGroup group, ProfileGroupDefinition groupDefinition) { rect.height = SPHERE_POINT_ROW_HEIGHT; UpdateActiveSelectedRow(rect, group.id, groupDefinition.propertyKey); Rect valueRowRect; Rect nameRowRect; bool isActive; LoadRowInformation(ref rect, group.id, SPHERE_POINT_ROW_HEIGHT, out valueRowRect, out nameRowRect, out isActive); // Render debug points if this is active. if (isActive) { ShowSpherePointKeyframesInSkybox(group); } RenderRowTitle(nameRowRect, group.name, isActive, groupDefinition); SpherePointTimelineRow.RenderSpherePointRow(valueRowRect, profile, group); }
public static void RenderColorGroupRow(Rect rect, SkyProfile profile, ColorKeyframeGroup colors) { bool sortGroup = false; RenderColorGroupRow(rect, colors); for (int i = 0; i < colors.keyframes.Count; i++) { ColorKeyframe currentKey = colors.GetKeyframe(i); // Track key marker mouse events and render. bool didSingleClick = false; bool isDragging = false; bool keyframeUpdated = false; SkyEditorUtility.DrawHorizontalKeyMarker(rect, currentKey, profile, out didSingleClick, out isDragging, out keyframeUpdated); if (keyframeUpdated) { sortGroup = true; } // Show the color keyframe property window. if (didSingleClick || isDragging) { // Load info about this keyframe and show the editor window. KeyframeInspectorWindow.SetKeyframeData( currentKey, colors, KeyframeInspectorWindow.KeyType.Color, profile); if (didSingleClick) { KeyframeInspectorWindow.ShowWindow(); } } } if (sortGroup) { colors.SortKeyframes(); } }
private void RebuildTimelineDefinitions(SkyProfile profile) { if (m_TimelineDefinitions == null) { m_TimelineDefinitions = new List <ProfileGroupDefinition>(); } m_TimelineDefinitions.Clear(); foreach (string groupKey in profile.timelineManagedKeys) { ProfileGroupDefinition groupDefinition = profile.GetGroupDefinitionForKey(groupKey); if (groupDefinition == null) { //Debug.LogError("Failed to get group definition for key: " + groupKey); continue; } m_TimelineDefinitions.Add(groupDefinition); } }
public static void SetHelpItem(SkyProfile profile, string propertyKey, bool showWindow) { m_Profile = profile; BuildHelpContentIfNecessary(); if (m_HelpItems.ContainsKey(propertyKey) == false) { return; } m_CurrentHelpKey = propertyKey; if (showWindow) { ShowWindow(); } if (_instance != null) { SharedHelpWindow().Repaint(); } }
private float CalculateWindowContentHeight(SkyProfile profile) { if (profile == null) { return(0); } int colorRowCount = 0; int numericRowCount = 0; int spherePointRowCount = 0; foreach (ProfileGroupDefinition groupInfo in m_TimelineDefinitions) { if (profile.IsManagedByTimeline(groupInfo.propertyKey) == false) { continue; } if (groupInfo.type == ProfileGroupDefinition.GroupType.Number) { numericRowCount += 1; } else if (groupInfo.type == ProfileGroupDefinition.GroupType.Color) { colorRowCount += 1; } else if (groupInfo.type == ProfileGroupDefinition.GroupType.SpherePoint) { spherePointRowCount += 1; } } float colorsHeight = colorRowCount * (COLOR_ROW_HEIGHT + ROW_PADDING); float numbersHeight = numericRowCount * (NUMBER_ROW_HEIGHT + ROW_PADDING); float spherePointHeight = spherePointRowCount * (SPHERE_POINT_ROW_HEIGHT + ROW_PADDING); float contentHeight = colorsHeight + numbersHeight + spherePointHeight + TIME_HEADER_HEIGHT; return(contentHeight); }
private void RenderAllRows(Rect rect, SkyProfile profile) { Rect rowRect = new Rect(rect.x, rect.y + ROW_PADDING / 2.0f, rect.width, COLOR_ROW_HEIGHT); // Render all rows that are managed by the timeline. foreach (ProfileGroupDefinition groupInfo in m_TimelineDefinitions) { if (profile.IsManagedByTimeline(groupInfo.propertyKey) == false) { continue; } if (groupInfo.type == ProfileGroupDefinition.GroupType.Number) { RenderNumericRowAndAdvance( ref rowRect, profile, profile.GetGroup <NumberKeyframeGroup>(groupInfo.propertyKey), groupInfo); } else if (groupInfo.type == ProfileGroupDefinition.GroupType.Color) { RenderGradientRowAndAdvance( ref rowRect, profile, profile.GetGroup <ColorKeyframeGroup>(groupInfo.propertyKey), groupInfo); } else if (groupInfo.type == ProfileGroupDefinition.GroupType.SpherePoint) { RenderSpherePointRowAndAdvance( ref rowRect, profile, profile.GetGroup <SpherePointKeyframeGroup>(groupInfo.propertyKey), groupInfo); } } }
private void ApplyDefaultSettings(SkyProfile profile) { // Lightning art. if (profile.lightningArtSet == null) { profile.lightningArtSet = GetDefaultArtStyleWithName <LightningArtSet>("DefaultLightningArtSet"); } // Splash art. if (profile.rainSplashArtSet == null) { profile.rainSplashArtSet = GetDefaultArtStyleWithName <RainSplashArtSet>("DefaultRainSplashArtSet"); } // Rain near texture. TextureKeyframeGroup group = profile.GetGroup <TextureKeyframeGroup>(ProfilePropertyKeys.RainNearTextureKey); if (group.keyframes.Count == 1 && group.keyframes[0].texture == null) { group.keyframes[0].texture = SkyEditorUtility.LoadEditorResourceTexture("RainDownfall-1"); if (group.keyframes[0].texture == null) { Debug.LogWarning("Failed to locate default near rain texture"); } } // Rain far texture. group = profile.GetGroup <TextureKeyframeGroup>(ProfilePropertyKeys.RainFarTextureKey); if (group.keyframes.Count == 1 && group.keyframes[0].texture == null) { group.keyframes[0].texture = SkyEditorUtility.LoadEditorResourceTexture("RainDownfall-3"); if (group.keyframes[0].texture == null) { Debug.LogWarning("Failed to locate default far rain texture"); } } }
public void UpdateForTimeOfDay(SkyProfile skyProfile, float timeOfDay) { m_SkyProfile = skyProfile; m_TimeOfDay = timeOfDay; }
public void UpdateForTimeOfDay(SkyProfile skyProfile, float timeOfDay) { m_SkyProfile = skyProfile; m_TimeOfDay = timeOfDay; if (!skyProfile) { return; } // Update the volume. if (m_RainAudioSource == null) { m_RainAudioSource = GetComponent <AudioSource>(); } // Suppress rain sounds if rain isn't enabled. if (skyProfile == null || m_SkyProfile.IsFeatureEnabled(ProfileFeatureKeys.RainFeature) == false) { if (m_RainAudioSource != null) { m_RainAudioSource.enabled = false; } return; } if (!rainMaterial) { Debug.LogError("Can't render rain without a rain material"); return; } if (!rainMeshRenderer) { Debug.LogError("Can't show rain without an enclosure mesh renderer."); return; } if (m_PropertyBlock == null) { m_PropertyBlock = new MaterialPropertyBlock(); } rainMeshRenderer.enabled = true; rainMeshRenderer.material = rainMaterial; rainMeshRenderer.GetPropertyBlock(m_PropertyBlock); float rainNearIntensity = skyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainNearIntensityKey, timeOfDay); float rainFarIntensity = skyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainFarIntensityKey, timeOfDay); Texture rainNearTexture = skyProfile.GetTexturePropertyValue(ProfilePropertyKeys.RainNearTextureKey, timeOfDay); Texture rainFarTexture = skyProfile.GetTexturePropertyValue(ProfilePropertyKeys.RainFarTextureKey, timeOfDay); float rainNearSpeed = skyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainNearSpeedKey, timeOfDay); float rainFarSpeed = skyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainFarSpeedKey, timeOfDay); Color tintColor = m_SkyProfile.GetColorPropertyValue(ProfilePropertyKeys.RainTintColorKey, m_TimeOfDay); float turbulence = m_SkyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainWindTurbulence, m_TimeOfDay); float turbulenceSpeed = m_SkyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainWindTurbulenceSpeed, m_TimeOfDay); float nearTiling = m_SkyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainNearTextureTiling, m_TimeOfDay); float farTiling = m_SkyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainFarTextureTiling, m_TimeOfDay); if (rainNearTexture != null) { m_PropertyBlock.SetTexture("_NearTex", rainNearTexture); m_PropertyBlock.SetVector("_NearTex_ST", new Vector4(nearTiling, nearTiling, nearTiling, 1)); } m_PropertyBlock.SetFloat("_NearDensity", rainNearIntensity); m_PropertyBlock.SetFloat("_NearRainSpeed", rainNearSpeed); if (rainFarTexture != null) { m_PropertyBlock.SetTexture("_FarTex", rainFarTexture); m_PropertyBlock.SetVector("_FarTex_ST", new Vector4(farTiling, farTiling, farTiling, 1)); } m_PropertyBlock.SetFloat("_FarDensity", rainFarIntensity); m_PropertyBlock.SetFloat("_FarRainSpeed", rainFarSpeed); m_PropertyBlock.SetColor("_TintColor", tintColor); m_PropertyBlock.SetFloat("_Turbulence", turbulence); m_PropertyBlock.SetFloat("_TurbulenceSpeed", turbulenceSpeed); rainMeshRenderer.SetPropertyBlock(m_PropertyBlock); if (skyProfile.IsFeatureEnabled(ProfileFeatureKeys.RainSoundFeature)) { m_RainAudioSource.enabled = true; m_RainAudioSource.volume = skyProfile.GetNumberPropertyValue(ProfilePropertyKeys.RainSoundVolumeKey, timeOfDay); } else { m_RainAudioSource.enabled = false; } }
private void OnGUI() { LoadStyles(); TimeOfDayController timeController = FindObjectOfType <TimeOfDayController>() as TimeOfDayController; // Render a setup helper UI. if (timeController == null) { RenderNeedsSkySetupLayout(); return; } // Render a profile help message UI. if (timeController.skyProfile == null) { RenderNeedsProfileLayout(); return; } m_ActiveTimeController = timeController; m_ActiveSkyProfile = timeController ? timeController.skyProfile : null; RebuildTimelineDefinitions(timeController.skyProfile); float contentHeight = CalculateWindowContentHeight(timeController.skyProfile); float scrollbarInset = 0; // Select the first colorGroup if one isn't selected. if (TimelineSelection.selectedGroupUUID == null && timeController.skyProfile.timelineManagedKeys.Count > 0) { IKeyframeGroup group = timeController.skyProfile.GetGroup(timeController.skyProfile.timelineManagedKeys[0]); if (group != null) { TimelineSelection.selectedGroupUUID = group.id; } } // Inset content on the right to make room for scroll bar. if (contentHeight > position.height) { scrollbarInset = CONTENT_INSET; } // Timeline rect. Rect contentRect = new Rect( 0, 0, position.width - scrollbarInset, position.height); // Check if mouse left the window, and cancel drag operations. if (Event.current.type == EventType.MouseLeaveWindow || contentRect.Contains(Event.current.mousePosition) == false) { SkyEditorUtility.CancelTimelineDrags(); } // Loads the list of timeline groups to render. RenderTimelineEditor(contentRect, timeController, contentHeight); // Save the edits to the profile object. if (timeController != null) { EditorUtility.SetDirty(timeController.skyProfile); // Keep the scene view rendering in sync for live editing. timeController.UpdateSkyForCurrentTime(); } }
public static void RemoveSkyDataResource(SkyProfile profile, string textureName) { string texturePath = GetSkyProfileAssetPath(profile, textureName); AssetDatabase.DeleteAsset(texturePath); }
public static void SetKeyframeData(IBaseKeyframe keyframe, IKeyframeGroup group, KeyType keyType, SkyProfile profile) { KeyframeInspectorWindow.keyframe = keyframe; KeyframeInspectorWindow.@group = group; KeyframeInspectorWindow.keyType = keyType; KeyframeInspectorWindow.profile = profile; }
private Shader GetBestShaderForSkyProfile(SkyProfile profile) { string shaderName = SkyEditorUtility.GetBestDefaultShaderNameForUnityVersion(); return(Shader.Find(shaderName)); }
public static void ShowAddTimelinePropertyMenu(SkyProfile profile) { List <ProfileGroupDefinition> offTimeline = profile.GetGroupDefinitionsNotManagedByTimeline(); ShowAddTimelinePropertyMenu(profile, offTimeline); }
public override void OnInspectorGUI() { serializedObject.Update(); m_Profile = (SkyProfile)target; // For new profiles we'll automatically build them. if (forceRebuildProfileId != -1 && forceRebuildProfileId == m_Profile.GetInstanceID()) { RebuildSkySystem(); forceRebuildProfileId = -1; } if (RenderSkyboxMaterial() == false) { serializedObject.ApplyModifiedProperties(); return; } if (m_Sections == null) { m_Sections = new Dictionary <string, ProfileFeatureSection>(); } foreach (ProfileFeatureSection section in m_Profile.featureDefinitions) { m_Sections[section.sectionKey] = section; } bool didChangeProfile = false; // Features. if (RenderFeatureSection()) { didChangeProfile = true; } // Timeline. if (RenderTimelineList()) { didChangeProfile = true; } // Properties. if (RenderProfileDefinitions()) { didChangeProfile = true; } TimeOfDayController tc = GameObject.FindObjectOfType <TimeOfDayController>(); if (tc != null) { tc.UpdateSkyForCurrentTime(); } serializedObject.ApplyModifiedProperties(); if (didChangeProfile) { EditorUtility.SetDirty(m_Profile); } }
private void SetupSceneWithPreset(ProfilePreset preset) { ClearSkyControllers(); Scene currentScene = SceneManager.GetActiveScene(); string sceneDir = Path.GetDirectoryName(currentScene.path); string profileContainerName = currentScene.name + " - Sky Data"; string profileContainerDir = SkyEditorUtility.GenerateUniqueFolder(sceneDir, profileContainerName, true); // Create new sky controller. GameObject skySystemPrefab = SkyEditorUtility.LoadEditorPrefab(SKY_CONTROLLER_PREFAB); if (skySystemPrefab == null) { Debug.LogError("Failed to locate sky controller prefab"); return; } TimeOfDayController tc = Instantiate(skySystemPrefab).GetComponent <TimeOfDayController>(); tc.name = SKY_CONTROLLER_PREFAB; // Create a new sky profile. string profileAssetPath = SkyEditorUtility.GenerateUniqueFilename(profileContainerDir, "SkyProfile", ".asset"); AssetDatabase.CopyAsset(preset.assetPath, profileAssetPath); // Load the new SKy Profile. SkyProfile profile = AssetDatabase.LoadAssetAtPath(profileAssetPath, typeof(SkyProfile)) as SkyProfile; if (profile == null) { Debug.LogError("Failed to duplicate profile"); return; } // Create the skybox material. Material skyboxMaterial = new Material(GetBestShaderForSkyProfile(profile)); string skyboxPath = SkyEditorUtility.GenerateUniqueFilename(profileContainerDir, "SkyboxMaterial", ".mat"); AssetDatabase.CreateAsset(skyboxMaterial, skyboxPath); profile.skyboxMaterial = skyboxMaterial; // Link things together. tc.skyProfile = profile; tc.skyProfile.skyboxMaterial = skyboxMaterial; tc.skyTime = .22f; // Configure the profile a bit and setup in the current scene. SkyProfileEditor.ApplyKeywordsToMaterial(tc.skyProfile, skyboxMaterial); SkyProfileEditor.forceRebuildProfileId = profile.GetInstanceID(); RenderSettings.skybox = skyboxMaterial; ApplyDefaultSettings(profile); // Drop a lightning spawn area into the scene in case user enables the feature. if (!ContainsLightningSpawnArea()) { CreateLightningSpawnArea(); } EditorUtility.SetDirty(skyboxMaterial); EditorUtility.SetDirty(tc.skyProfile); EditorUtility.SetDirty(tc); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); Selection.activeObject = tc.skyProfile; }