123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // Magica Cloth.
- // Copyright (c) MagicaSoft, 2020-2022.
- // https://magicasoft.jp
- using System.Collections.Generic;
- using UnityEngine;
- namespace MagicaCloth
- {
- public class WindController : MonoBehaviour
- {
- [SerializeField]
- private WindZone unityWindZone = null;
- [SerializeField]
- private float unityWindZoneScale = 0.1f;
- [SerializeField]
- private Renderer arrowRenderer = null;
- [SerializeField]
- private Gradient arrowGradient = new Gradient();
- [SerializeField]
- private List<Transform> rotationTransforms = new List<Transform>();
- [SerializeField]
- private GameObject blastWavePrefab;
- [SerializeField]
- private float blastWaveSpawnRadius = 3.0f;
- private float angleY = 0.0f;
- private float angleX = 0.0f;
- void Start()
- {
- }
- public void OnDirectionY(float value)
- {
- angleY = value;
- UpdateDirection();
- }
- public void OnDirectionX(float value)
- {
- angleX = value;
- UpdateDirection();
- }
- public void OnMain(float value)
- {
- Wind.Main = value;
- // Link Unit Wind Zone
- if (unityWindZone)
- {
- unityWindZone.windMain = value * unityWindZoneScale;
- }
- // arrow color
- if (arrowRenderer)
- {
- var t = Mathf.InverseLerp(0.0f, 50.0f, value);
- var col = arrowGradient.Evaluate(t);
- arrowRenderer.material.color = col;
- }
- }
- public void OnTurbulence(float value)
- {
- Wind.Turbulence = value;
- }
- public void OnFrequency(float value)
- {
- Wind.Frequency = value;
- }
- public void OnBlastWave()
- {
- if (blastWavePrefab == null)
- return;
- // position
- var lpos = Random.insideUnitSphere * blastWaveSpawnRadius;
- lpos.y = 0;
- var pos = transform.TransformPoint(lpos);
- // spawn blast wave
- Instantiate(blastWavePrefab, pos, Quaternion.identity);
- }
- private MagicaDirectionalWind Wind
- {
- get
- {
- return GetComponent<MagicaDirectionalWind>();
- }
- }
- private void UpdateDirection()
- {
- var lrot = Quaternion.Euler(angleX, angleY, 0.0f);
- foreach (var t in rotationTransforms)
- if (t)
- t.localRotation = lrot;
- //transform.rotation = Quaternion.Euler(angleX, angleY, 0.0f);
- Wind.DirectionAngleX = angleX;
- Wind.DirectionAngleY = angleY;
- }
- }
- }
|