2026-06-09 룸 프로토타입 디자인 (진행중)
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ToonScapes.tools
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class SunFacingFX : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Optional manual assignment of the directional light (sun)")]
|
||||
public Light sunLight;
|
||||
|
||||
[Tooltip("If enabled, will automatically find the scene's main directional light")]
|
||||
public bool autoFindSun = true;
|
||||
|
||||
[Tooltip("If true, will rotate opposite to the light direction")]
|
||||
public bool invertDirection = false;
|
||||
|
||||
[Tooltip("How smoothly the object rotates toward the light direction (0 = instant)")]
|
||||
[Range(0f, 1f)]
|
||||
public float smoothFactor = 0.2f;
|
||||
|
||||
private Quaternion targetRotation;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateSunReference();
|
||||
|
||||
if (sunLight == null)
|
||||
return;
|
||||
|
||||
RotateTowardsSun();
|
||||
}
|
||||
|
||||
private void UpdateSunReference()
|
||||
{
|
||||
if (!autoFindSun)
|
||||
return;
|
||||
|
||||
if (sunLight == null || sunLight.type != LightType.Directional)
|
||||
{
|
||||
// Try RenderSettings.sun first
|
||||
sunLight = RenderSettings.sun;
|
||||
|
||||
// If none assigned, find the first directional light in the scene
|
||||
if (sunLight == null)
|
||||
{
|
||||
foreach (var l in Object.FindObjectsByType<Light>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (l.type == LightType.Directional)
|
||||
{
|
||||
sunLight = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void RotateTowardsSun()
|
||||
{
|
||||
Vector3 direction = invertDirection ? sunLight.transform.forward : -sunLight.transform.forward;
|
||||
|
||||
// Compute target rotation
|
||||
targetRotation = Quaternion.LookRotation(direction, Vector3.up);
|
||||
|
||||
// Apply smooth rotation
|
||||
if (smoothFactor > 0f)
|
||||
{
|
||||
float t = 1f - Mathf.Pow(1f - smoothFactor, Time.deltaTime * 60f);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.rotation = targetRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f86c76f2df51f844098242b9efdfe92a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 361638
|
||||
packageName: 'ToonScapes: Spring Isles'
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/ToonScapes/Shared Assets/Scripts/SunAlignedParticles.cs
|
||||
uploadId: 864486
|
||||
82
Assets/ToonScapes/Shared Assets/Scripts/WindManager.cs
Normal file
82
Assets/ToonScapes/Shared Assets/Scripts/WindManager.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ToonScapes.tools
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class WindSettings : MonoBehaviour
|
||||
{
|
||||
// Fixed wind direction
|
||||
[SerializeField] private Vector3 windDirection = new Vector3(1, 0, 0); // Set your fixed wind direction here
|
||||
|
||||
// Wind variables
|
||||
[SerializeField] [Range(0.0F, 20.0F)] private float windStrength = 1.0f;
|
||||
[SerializeField] [Range(0.0F, 20.0F)] private float windScale = 1.0f;
|
||||
[SerializeField] [Range(0.0F, 20.0F)] private float windSpeed = 1.0f;
|
||||
[SerializeField] [Range(0.0F, 20.0F)] private float windJitter = 1.0f;
|
||||
|
||||
// Global Noise Texture
|
||||
[SerializeField] private Texture noiseTexture;
|
||||
|
||||
// Previous values to check for changes
|
||||
private Vector3 previousWindDirection;
|
||||
private float previousWindStrength;
|
||||
private float previousWindScale;
|
||||
private float previousWindSpeed;
|
||||
private float previousWindJitter;
|
||||
private Texture previousNoiseTexture; // Previous noise texture value
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Initialize previous values
|
||||
previousWindDirection = windDirection;
|
||||
previousWindStrength = windStrength;
|
||||
previousWindScale = windScale;
|
||||
previousWindSpeed = windSpeed;
|
||||
previousWindJitter = windJitter;
|
||||
previousNoiseTexture = noiseTexture; // Initialize previous noise texture
|
||||
|
||||
// Set initial shader values
|
||||
UpdateShaderVariables();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Check if any wind settings have changed
|
||||
if (HasWindSettingsChanged())
|
||||
{
|
||||
UpdateShaderVariables();
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasWindSettingsChanged()
|
||||
{
|
||||
// Compare current values with previous values
|
||||
return windDirection != previousWindDirection ||
|
||||
windStrength != previousWindStrength ||
|
||||
windScale != previousWindScale ||
|
||||
windSpeed != previousWindSpeed ||
|
||||
windJitter != previousWindJitter ||
|
||||
noiseTexture != previousNoiseTexture; // Check for noise texture change
|
||||
}
|
||||
|
||||
private void UpdateShaderVariables()
|
||||
{
|
||||
// Set wind settings in the shader
|
||||
Shader.SetGlobalVector("ToonScapesGlobalWindDirection", windDirection);
|
||||
Shader.SetGlobalFloat("ToonScapesGlobalWindStrength", windStrength);
|
||||
Shader.SetGlobalFloat("ToonScapesGlobalWindScale", windScale);
|
||||
Shader.SetGlobalFloat("ToonScapesGlobalWindSpeed", windSpeed);
|
||||
Shader.SetGlobalFloat("ToonScapesGlobalWindJitter", windJitter);
|
||||
Shader.SetGlobalTexture("ToonScapesGlobalNoiseTexture", noiseTexture); // Set global noise texture
|
||||
|
||||
// Update previous values
|
||||
previousWindDirection = windDirection;
|
||||
previousWindStrength = windStrength;
|
||||
previousWindScale = windScale;
|
||||
previousWindSpeed = windSpeed;
|
||||
previousWindJitter = windJitter;
|
||||
previousNoiseTexture = noiseTexture; // Update previous noise texture
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Assets/ToonScapes/Shared Assets/Scripts/WindManager.cs.meta
Normal file
19
Assets/ToonScapes/Shared Assets/Scripts/WindManager.cs.meta
Normal file
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 650d517be9220504a8d72b7fdf9831d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- noiseTexture: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 361638
|
||||
packageName: 'ToonScapes: Spring Isles'
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/ToonScapes/Shared Assets/Scripts/WindManager.cs
|
||||
uploadId: 864486
|
||||
Reference in New Issue
Block a user