Space-Smash-Out/Assets/Plugins/PrimeTween/Demo/Scripts/DirectionalLightController.cs
Jakob Feldmann 64162cb4a1 feat: whole project restructuring
This can be seen as the initial state of the project after the released demo.

The changes include:
- New ship models
- Singleton manager structure to keep project scaleable in the future
     - Managing players, their settings, character choices, statistics, match setups, controls etc. in a separate decoupled scene
- Main menu with transitions to the arena scene
- Beginnings of a custom audio solution
- Logging with Log4Net

It is really a complete overhaul of the projects structure and management.
2024-04-01 23:06:39 +02:00

35 lines
1.5 KiB
C#

#if PRIME_TWEEN_INSTALLED
using PrimeTween;
using UnityEngine;
namespace PrimeTweenDemo {
public class DirectionalLightController : MonoBehaviour {
[SerializeField] Light directionalLight;
[SerializeField] Camera mainCamera;
[SerializeField] Color startColor;
[SerializeField] Color endColor;
float angleX;
float angleY;
void OnEnable() {
// This overload is simpler, but allocates small amount of garbage because 'this' reference is captured in a closure.
// It ok to use it once in a while but for hot code paths consider using the overload that accepts 'target' as first parameter.
var xRotationSettings = new TweenSettings<float>(45, 10, 10, Ease.Linear, -1, CycleMode.Yoyo);
Tween.Custom(xRotationSettings, newX => angleX = newX);
// This overload is more verbose, but doesn't allocate garbage.
var yRotationSettings = new TweenSettings<float>(45, 405, 20, Ease.Linear, -1);
Tween.Custom(this, yRotationSettings, (target, newY) => target.angleY = newY);
var colorSettings = new TweenSettings<Color>(startColor, endColor, 10, Ease.InCirc, -1, CycleMode.Rewind);
Tween.LightColor(directionalLight, colorSettings);
Tween.CameraBackgroundColor(mainCamera, colorSettings);
Tween.Custom(colorSettings, color => RenderSettings.fogColor = color);
}
void Update() {
transform.localEulerAngles = new Vector3(angleX, angleY);
}
}
}
#endif