Skip to content

Commit b3697d5

Browse files
committed
twinkle twinkle little star
1 parent 52ad60e commit b3697d5

File tree

5 files changed

+3801
-415
lines changed

5 files changed

+3801
-415
lines changed

TerrainTest/Assets/Scenes/HexTest1.unity

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ RenderSettings:
3939
m_ReflectionIntensity: 1
4040
m_CustomReflection: {fileID: 0}
4141
m_Sun: {fileID: 0}
42-
m_IndirectSpecularColor: {r: 0.14239225, g: 0.4553069, b: 0.7502265, a: 1}
42+
m_IndirectSpecularColor: {r: 0.14212555, g: 0.45508352, b: 0.75003, a: 1}
4343
m_UseRadianceAmbientProbe: 0
4444
--- !u!157 &3
4545
LightmapSettings:
@@ -872,6 +872,50 @@ Transform:
872872
m_Children: []
873873
m_Father: {fileID: 0}
874874
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
875+
--- !u!1 &1856641497
876+
GameObject:
877+
m_ObjectHideFlags: 0
878+
m_CorrespondingSourceObject: {fileID: 0}
879+
m_PrefabInstance: {fileID: 0}
880+
m_PrefabAsset: {fileID: 0}
881+
serializedVersion: 6
882+
m_Component:
883+
- component: {fileID: 1856641499}
884+
- component: {fileID: 1856641498}
885+
m_Layer: 0
886+
m_Name: Sky
887+
m_TagString: Untagged
888+
m_Icon: {fileID: 0}
889+
m_NavMeshLayer: 0
890+
m_StaticEditorFlags: 0
891+
m_IsActive: 1
892+
--- !u!114 &1856641498
893+
MonoBehaviour:
894+
m_ObjectHideFlags: 0
895+
m_CorrespondingSourceObject: {fileID: 0}
896+
m_PrefabInstance: {fileID: 0}
897+
m_PrefabAsset: {fileID: 0}
898+
m_GameObject: {fileID: 1856641497}
899+
m_Enabled: 1
900+
m_EditorHideFlags: 0
901+
m_Script: {fileID: 11500000, guid: cf1185f006b0116479cda2e75b68b211, type: 3}
902+
m_Name:
903+
m_EditorClassIdentifier:
904+
--- !u!4 &1856641499
905+
Transform:
906+
m_ObjectHideFlags: 0
907+
m_CorrespondingSourceObject: {fileID: 0}
908+
m_PrefabInstance: {fileID: 0}
909+
m_PrefabAsset: {fileID: 0}
910+
m_GameObject: {fileID: 1856641497}
911+
serializedVersion: 2
912+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
913+
m_LocalPosition: {x: 0, y: 0, z: 0}
914+
m_LocalScale: {x: 1, y: 1, z: 1}
915+
m_ConstrainProportionsScale: 0
916+
m_Children: []
917+
m_Father: {fileID: 0}
918+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
875919
--- !u!1 &1909803965
876920
GameObject:
877921
m_ObjectHideFlags: 0
@@ -935,3 +979,4 @@ SceneRoots:
935979
- {fileID: 365010942}
936980
- {fileID: 1642047805}
937981
- {fileID: 1033698234}
982+
- {fileID: 1856641499}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
[CreateAssetMenu(fileName = "BiomeSky", menuName = "ScriptableObjects/Biome Sky", order = 1)]
6+
public class SkyColorScriptableObject : ScriptableObject
7+
{
8+
public Color skyColor;
9+
public Color horizonColor;
10+
public Color groundColor;
11+
}

TerrainTest/Assets/Scripts/SkyColorScriptableObject.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
1+
using System.Collections;
12
using UnityEngine;
23

34
[ExecuteAlways]
45
public class SkyboxController : MonoBehaviour
56
{
6-
[SerializeField] Transform _Sun = default;
7-
[SerializeField] Transform _Moon = default;
7+
SkyColorScriptableObject lastSky = null;
8+
SkyColorScriptableObject currSky = null;
89

9-
void LateUpdate()
10-
{
11-
// Directions are defined to point towards the object
10+
float transitTime = 3.0f;
11+
float transitTimeSplit = 0.1f;
12+
WaitForSeconds transitWait = new WaitForSeconds(0.1f);
1213

13-
// Sun
14-
Shader.SetGlobalVector("_SunDir", -_Sun.transform.forward);
14+
void UpdateSkyColor(SkyColorScriptableObject currSky) {
15+
if (this.currSky != null) {
16+
this.lastSky = this.currSky;
17+
this.currSky = currSky;
1518

16-
// Moon
17-
Shader.SetGlobalVector("_MoonDir", -_Moon.transform.forward);
19+
// Start transition
20+
StartCoroutine(TransitSky());
21+
}
22+
else {
23+
// First sky
24+
this.currSky = currSky;
25+
26+
// Send sky color to shader
27+
SendSkyColorToShader(currSky.skyColor, currSky.horizonColor, currSky.groundColor);
28+
}
29+
}
30+
31+
IEnumerator TransitSky() {
32+
for (float t = 0.0f; t < transitTime; t += transitTimeSplit) {
33+
float lerp = t / transitTime;
34+
35+
Color skyColor = Color.Lerp(lastSky.skyColor, currSky.skyColor, lerp);
36+
Color horizonColor = Color.Lerp(lastSky.horizonColor, currSky.horizonColor, lerp);
37+
Color groundColor = Color.Lerp(lastSky.groundColor, currSky.groundColor, lerp);
38+
39+
SendSkyColorToShader(skyColor, horizonColor, groundColor);
40+
41+
yield return transitWait;
42+
}
43+
}
44+
45+
void SendSkyColorToShader(Color skyColor, Color horizonColor, Color GroundColor) {
46+
Shader.SetGlobalColor("_SkyColor", currSky.skyColor);
47+
Shader.SetGlobalColor("_HorizonColor", currSky.horizonColor);
48+
Shader.SetGlobalColor("_GroundColor", currSky.groundColor);
1849
}
1950
}

0 commit comments

Comments
 (0)