Selaa lähdekoodia

Merge branch 'master' of http://git.thirdlevel.gmbh:80/GameDevOS/LD39

DasGewehr 9 vuotta sitten
vanhempi
commit
183dc7ed73

+ 9 - 0
game/Assets/Animation.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: d50ec002efdd94687908f0e27e2d45c8
+folderAsset: yes
+timeCreated: 1501346877
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 0
game/Assets/Editor.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 8db886966ab03481798a18eb702a04fe
+folderAsset: yes
+timeCreated: 1501419311
+licenseType: Free
+DefaultImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 64 - 42
game/Assets/Prefabs/DayTimeManager.prefab

@@ -9,91 +9,73 @@ Prefab:
     m_Modifications: []
     m_RemovedComponents: []
   m_ParentPrefab: {fileID: 0}
-  m_RootGameObject: {fileID: 1918410337494552}
+  m_RootGameObject: {fileID: 1960232569590872}
   m_IsPrefabParent: 1
---- !u!1 &1918410337494552
+--- !u!1 &1506175633501982
 GameObject:
   m_ObjectHideFlags: 0
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
   serializedVersion: 5
   m_Component:
-  - component: {fileID: 4618518221219600}
-  - component: {fileID: 114038366060908416}
+  - component: {fileID: 4068608461427198}
+  - component: {fileID: 108055089003181920}
   m_Layer: 0
-  m_Name: DayTimeManager
-  m_TagString: DayTimeManager
+  m_Name: Sunlight
+  m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
   m_IsActive: 1
---- !u!1 &1982852636499602
+--- !u!1 &1960232569590872
 GameObject:
   m_ObjectHideFlags: 0
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
   serializedVersion: 5
   m_Component:
-  - component: {fileID: 4086179075244344}
-  - component: {fileID: 108209417384162848}
-  - component: {fileID: 95461355863206716}
+  - component: {fileID: 4930176882217988}
+  - component: {fileID: 114806071709842584}
   m_Layer: 0
-  m_Name: Sunlight
-  m_TagString: Untagged
+  m_Name: DayTimeManager
+  m_TagString: DayTimeManager
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
   m_IsActive: 1
---- !u!4 &4086179075244344
+--- !u!4 &4068608461427198
 Transform:
   m_ObjectHideFlags: 1
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
-  m_GameObject: {fileID: 1982852636499602}
+  m_GameObject: {fileID: 1506175633501982}
   m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
   m_LocalPosition: {x: 0, y: 10, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
-  m_Father: {fileID: 4618518221219600}
+  m_Father: {fileID: 4930176882217988}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
---- !u!4 &4618518221219600
+--- !u!4 &4930176882217988
 Transform:
   m_ObjectHideFlags: 1
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
-  m_GameObject: {fileID: 1918410337494552}
+  m_GameObject: {fileID: 1960232569590872}
   m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children:
-  - {fileID: 4086179075244344}
+  - {fileID: 4068608461427198}
   m_Father: {fileID: 0}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
---- !u!95 &95461355863206716
-Animator:
-  serializedVersion: 3
-  m_ObjectHideFlags: 1
-  m_PrefabParentObject: {fileID: 0}
-  m_PrefabInternal: {fileID: 100100000}
-  m_GameObject: {fileID: 1982852636499602}
-  m_Enabled: 1
-  m_Avatar: {fileID: 0}
-  m_Controller: {fileID: 0}
-  m_CullingMode: 0
-  m_UpdateMode: 0
-  m_ApplyRootMotion: 0
-  m_LinearVelocityBlending: 0
-  m_WarningMessage: 
-  m_HasTransformHierarchy: 1
-  m_AllowConstantClipSamplingOptimization: 1
---- !u!108 &108209417384162848
+--- !u!108 &108055089003181920
 Light:
   m_ObjectHideFlags: 1
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
-  m_GameObject: {fileID: 1982852636499602}
+  m_GameObject: {fileID: 1506175633501982}
   m_Enabled: 1
   serializedVersion: 8
   m_Type: 1
@@ -138,18 +120,58 @@ Light:
   m_UseColorTemperature: 0
   m_ShadowRadius: 0
   m_ShadowAngle: 0
---- !u!114 &114038366060908416
+--- !u!114 &114806071709842584
 MonoBehaviour:
   m_ObjectHideFlags: 1
   m_PrefabParentObject: {fileID: 0}
   m_PrefabInternal: {fileID: 100100000}
-  m_GameObject: {fileID: 1918410337494552}
+  m_GameObject: {fileID: 1960232569590872}
   m_Enabled: 1
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: fa3a4f9ebf76b4ac2bc610f0f6b7d935, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  sunlight: {fileID: 108209417384162848}
-  secondsPerDay: 15
-  rotAxis: 0
+  sunlight: {fileID: 108055089003181920}
+  secondsPerDay: 60
+  MorningColor: {r: 1, g: 0.83205926, b: 0.36764705, a: 0}
+  NoonColor: {r: 0.9485294, g: 0.84463364, b: 0.6695502, a: 0}
+  EveningColor: {r: 0.23529412, g: 0.3137255, b: 0.47058824, a: 0}
+  NightColor: {r: 0.1254902, g: 0.1254902, b: 0.18431373, a: 0}
   maxAngle: 50
+  colorCurve:
+    serializedVersion: 2
+    m_Curve:
+    - serializedVersion: 2
+      time: 0
+      value: 0
+      inSlope: 0
+      outSlope: 0
+      tangentMode: 0
+    - serializedVersion: 2
+      time: 0.50038546
+      value: 0.105107576
+      inSlope: 0.26548746
+      outSlope: 0.26548746
+      tangentMode: 0
+    - serializedVersion: 2
+      time: 0.7999664
+      value: 0.20412965
+      inSlope: 1.2750924
+      outSlope: 1.2750924
+      tangentMode: 0
+    - serializedVersion: 2
+      time: 1
+      value: 1
+      inSlope: 2
+      outSlope: 2
+      tangentMode: 0
+    m_PreInfinity: 2
+    m_PostInfinity: 2
+    m_RotationOrder: 0
+  dayTime: 0
+  morningStartTime: 8
+  noonStartTime: 11
+  eveningStartTime: 17
+  nightStartTime: 20
+  startTime: 1
+  dayTimeLabel: 3

+ 1 - 1
game/Assets/Prefabs/DayTimeManager.prefab.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 673629bba9f02458cacf9d13115e1078
-timeCreated: 1501361428
+timeCreated: 1501421844
 licenseType: Free
 NativeFormatImporter:
   mainObjectFileID: 100100000

+ 8 - 8
game/Assets/Scenes/DayNightChange.unity

@@ -756,35 +756,35 @@ Prefab:
   m_Modification:
     m_TransformParent: {fileID: 0}
     m_Modifications:
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalPosition.x
       value: 0
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalPosition.y
       value: 0
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalPosition.z
       value: 0
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalRotation.x
       value: 0
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalRotation.y
       value: 0
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalRotation.z
       value: 0
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_LocalRotation.w
       value: 1
       objectReference: {fileID: 0}
-    - target: {fileID: 4618518221219600, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
+    - target: {fileID: 4930176882217988, guid: 673629bba9f02458cacf9d13115e1078, type: 2}
       propertyPath: m_RootOrder
       value: 5
       objectReference: {fileID: 0}

+ 154 - 102
game/Assets/Scripts/DayTimeManager.cs

@@ -4,109 +4,161 @@ using UnityEngine;
 
 public enum RotationAxis
 {
-	X, Y
+    X, Y
 }
 
-public class DayTimeManager : MonoBehaviour {
-
-	public Light sunlight;
-	public float secondsPerDay; 
-
-	public RotationAxis rotAxis = RotationAxis.X; 
-
-	public float maxAngle = 50.0f;
-
-	private float _elapsedTime;
-
-	public float timeFactor {
-		get {
-			return _elapsedTime / secondsPerDay;
-		}
-	}
-
-	public DayTimeLabel dayTimeLabel {
-		get {
-			if (timeFactor >= 6.0f / 24.0f && timeFactor < 11.0f / 24.0f)
-			{
-				return DayTimeLabel.Morning;
-			}
-
-			if (timeFactor >= 11.0f / 24.0f && timeFactor < 17.0f / 24.0f)
-			{
-				return DayTimeLabel.Noon;
-			}
-
-			if (timeFactor >= 17.0f / 24.0f && timeFactor < 22.0f / 24.0f)
-			{
-				return DayTimeLabel.Evening;
-			}
-
-			if (timeFactor >= 23.0f / 24.0f && timeFactor < 24.0f / 24.0f)
-			{
-				return DayTimeLabel.Night;
-			}
-
-			if (timeFactor >= 0.0f / 24.0f && timeFactor < 6.0f / 24.0f)
-			{
-				return DayTimeLabel.Night;
-			}
-
-			return DayTimeLabel.Morning;
-		}
-	}
-
-	private float _timeDirection = 1.0f;
-
-	private Vector3 _position;
-	private Vector3 _rotation;
-
-	void Awake () {
-
-	}
-
-	// Use this for initialization
-	void Start () {
-		_position = sunlight.gameObject.transform.position;
-		_rotation = sunlight.gameObject.transform.rotation.ToEulerAngles();
-	}
-	
-	// Update is called once per frame
-	void Update () {
-		
-		_elapsedTime += Time.deltaTime;
-		if (_elapsedTime >= secondsPerDay)
-		{
-			_elapsedTime = 0;
-		}
-
-		float intensityAngle = this.timeFactor * Mathf.PI;
-		sunlight.intensity = Mathf.Sin(intensityAngle);
-
-		float rotationDirection = Mathf.Sign(this.timeFactor - 0.5f);
-
-		switch (rotAxis)
-		{
-			case RotationAxis.X:
-			{
-				sunlight.gameObject.transform.rotation.SetEulerAngles(_rotation.x + rotationDirection * maxAngle, _rotation.y, _rotation.z);
-			} break;
-
-			case RotationAxis.Y:
-			{
-				sunlight.gameObject.transform.rotation.SetEulerAngles(_rotation.x, _rotation.y + rotationDirection * maxAngle, _rotation.z);
-			} break;
-		}
-
-	}
-
-	float FactorToDayTime(float factor)
-	{
-		return factor * 24.0f;
-	}
-
-	float DayTimeToFactor(float dayTime)
-	{
-		return dayTime / 24.0f;
-	}
+public class DayTimeManager : MonoBehaviour
+{
+
+    public Light sunlight;
+    public float secondsPerDay;
+
+    public Color MorningColor;
+    public Color NoonColor;
+    public Color EveningColor;
+    public Color NightColor;
+
+    public float maxAngle = 50.0f;
+
+    private float _elapsedTime;
+
+    public float timeFactor
+    {
+        get
+        {
+            return _elapsedTime / secondsPerDay;
+        }
+    }
+
+    public AnimationCurve colorCurve;
+
+    public float dayTime;
+
+    float _morningStartFactor;
+    float _noonStartFactor;
+    float _eveningStartFactor;
+    float _nightStartFactor;
+    public float morningStartTime = 8.0f;
+    public float noonStartTime = 11.0f;
+    public float eveningStartTime = 17.0f;
+    public float nightStartTime = 20.0f;
+
+    public DayTimeLabel startTime = DayTimeLabel.Noon;
+
+    public DayTimeLabel dayTimeLabel = DayTimeLabel.Night;
+
+    private float _timeDirection = 1.0f;
+
+    private Vector3 _position;
+    private Vector3 _rotation;
+
+    void Awake()
+    {
+
+    }
+
+    // Use this for initialization
+    void Start()
+    {
+        _morningStartFactor = morningStartTime / 24.0f;
+        _noonStartFactor = noonStartTime / 24.0f;
+        _eveningStartFactor = eveningStartTime / 24.0f;
+        _nightStartFactor = nightStartTime / 24.0f;
+
+        switch (startTime)
+        {
+            case DayTimeLabel.Morning:
+                {
+                    _elapsedTime = _morningStartFactor * secondsPerDay;
+                }
+                break;
+            case DayTimeLabel.Noon:
+                {
+                    _elapsedTime = _noonStartFactor * secondsPerDay;
+                }
+                break;
+            case DayTimeLabel.Evening:
+                {
+                    _elapsedTime = _eveningStartFactor * secondsPerDay;
+                }
+                break;
+            case DayTimeLabel.Night:
+                {
+                    _elapsedTime = _nightStartFactor * secondsPerDay;
+                }
+                break;
+        }
+        _position = sunlight.gameObject.transform.position;
+        _rotation = sunlight.gameObject.transform.rotation.eulerAngles;
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+
+        _elapsedTime += Time.deltaTime;
+        if (_elapsedTime >= secondsPerDay)
+        {
+            _elapsedTime = 0;
+        }
+
+        float intensityAngle = this.timeFactor * Mathf.PI;
+        sunlight.intensity = Mathf.Sin(intensityAngle);
+
+        float rotationDirection = (this.timeFactor - 0.5f) * 2;
+
+        // Debug.Log("DayTimeLabel: " + dayTimeLabel.ToString());
+
+        sunlight.gameObject.transform.rotation = Quaternion.Euler(_rotation.x + rotationDirection * maxAngle, _rotation.y + rotationDirection * maxAngle, _rotation.z);
+        // Debug.Log("Rotate around x: " + (_rotation.x + rotationDirection * maxAngle));
+
+        Color resultColor = Color.white;
+        if (timeFactor >= _morningStartFactor && timeFactor < _noonStartFactor)
+        {
+            float morningFactor = (timeFactor - _morningStartFactor) / (_noonStartFactor - _morningStartFactor);
+            resultColor = Color.Lerp(MorningColor, NoonColor, colorCurve.Evaluate(morningFactor));
+            dayTimeLabel = DayTimeLabel.Morning;
+        }
+
+        if (timeFactor >= _noonStartFactor && timeFactor < _eveningStartFactor)
+        {
+            float noonFactor = (timeFactor - _noonStartFactor) / (_eveningStartFactor - _noonStartFactor);
+            resultColor = Color.Lerp(NoonColor, EveningColor, colorCurve.Evaluate(noonFactor));
+            dayTimeLabel = DayTimeLabel.Noon;
+        }
+
+        if (timeFactor >= _eveningStartFactor && timeFactor < _nightStartFactor)
+        {
+            float eveningFactor = (timeFactor - _eveningStartFactor) / (_nightStartFactor - _eveningStartFactor);
+            resultColor = Color.Lerp(EveningColor, NightColor, colorCurve.Evaluate(eveningFactor));
+            dayTimeLabel = DayTimeLabel.Evening;
+        }
+
+        if (timeFactor >= _nightStartFactor && timeFactor < 1.0f)
+        {
+            float nightFactor1 = (timeFactor - _nightStartFactor) / ((1.0f - _nightStartFactor) + _morningStartFactor);
+            resultColor = Color.Lerp(NightColor, MorningColor, colorCurve.Evaluate(nightFactor1));
+            dayTimeLabel = DayTimeLabel.Night;
+        }
+
+        if (timeFactor >= 0 && timeFactor < _morningStartFactor)
+        {
+            float nightFactor2 = (timeFactor + (1.0f - _nightStartFactor)) / ((1.0f - _nightStartFactor) + _morningStartFactor);
+            resultColor = Color.Lerp(NightColor, MorningColor, colorCurve.Evaluate(nightFactor2));
+            dayTimeLabel = DayTimeLabel.Night;
+        }
+        sunlight.color = resultColor;
+        dayTime = timeFactor * 24.0f;
+    }
+
+    float FactorToDayTime(float factor)
+    {
+        return factor * 24.0f;
+    }
+
+    float DayTimeToFactor(float dayTime)
+    {
+        return dayTime / 24.0f;
+    }
 
 }