Unity/VFX Graph
Unity VFX Graph: script로 제어하기
잉_민
2022. 10. 13. 23:18
728x90
반응형
using UnityEngine;
namespace LSM
{
sealed class LSM_ChangeStage : MonoBehaviour
{
float _line;
void Update()
{
var delta = Input.GetKey(KeyCode.Space) ? 1.0f : 0f;
delta *= Time.deltaTime;
float sum = _line + delta;
if (Input.GetKeyUp(KeyCode.Space))
{
sum = 0;
}
_line = Mathf.Clamp01(sum);
var vfx = GetComponent<UnityEngine.VFX.VisualEffect>();
vfx.SetFloat("_Line", sum);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
using Current;
using DG.Tweening;
using System;
namespace LSM
{
[RequireComponent(typeof(AudioSource))]
public class LSM_Gamemanager : MonoBehaviour
{
public VisualEffect[] vFXColor_s;
//public VisualEffect[] vFXLineLenth_s;
public VisualEffect[] vFXStreetFall;
//public Animator[] animators;
//MS stair
public VisualEffect vFxStair;
//public Texture2D tex_Start;
private int x = 0;
private Texture2D[] pCaches;
public int max_num;
// public GameObject subwayLineEffect;
float delta=0;
//bool isCheck = false;
//float line;
//float lineSum;
//Vector3 b1PosInitial = new Vector3(-3, -53, 159);
//Vector3 b1Pos = Vector3.zero;
//public AudioSource audioSource;
//public AudioClip[] audioClips;
// Start is called before the first frame update
void Start()
{
StateManager.onStateChanged += OnStateChanged;
//subwayLineEffect.SetActive(false);
//if(audioSource== null)
//{
// audioSource = GetComponent<AudioSource>();
//}
//MS
pCaches = Resources.LoadAll<Texture2D>("test_01");
vFxStair.SetTexture("New_Tex", pCaches[0]);
}
private void OnStateChanged(SceneState newScene)
{
if(newScene == SceneState.END)
{
//MS stairEffect
StairEffect();
//SM turbulence 초기화
delta = 0f;
}
}
// Update is called once per frame
void Update()
{
//SubwayEffect();
switch (StateManager.SceneState)
{
case SceneState.SUBWAY:
SubwayEffect();
break;
case SceneState.FALL:
delta += Time.deltaTime*0.2f;
Turbulance();
break;
case SceneState.CORRIDOR:
//CorridorEffect();
break;
case SceneState.CITY:
//CityEffect();
break;
case SceneState.END:
//isCheck = true;
break;
}
}
private void Turbulance()
{
//fall씬에서 터뷸런스 효과를 줘라
for (int i = 0; i < vFXStreetFall.Length; i++)
{
vFXStreetFall[i].SetFloat("_Turbulence",delta);
}
}
private void StairEffect()
{
//씬에 가자마자 한번 실행
StartCoroutine(callPcache());
}
IEnumerator callPcache()
{
for (int x = 1; x <= max_num - 1; x++)
{
yield return new WaitForSeconds(0.03f);
vFxStair.SetTexture("New_Tex", pCaches[x]);
// print("texture is set x = " + x + "texutre name is " + pCaches[x].name);
// print("done!");
}
}
private void SubwayEffect()
{
//오른손은 색깔 변화
float colorValue = ControllerInput.GetTriggerValue(OVRInput.Controller.RTouch);
for (int i = 0; i < vFXColor_s.Length; i++)
{
vFXColor_s[i].SetFloat("_LerpColor", colorValue);
}
//if(ControllerInput.IsTriggerGetDown(OVRInput.Controller.RTouch) || Input.GetKeyDown(KeyCode.Space))
//{
// //audioSource.PlayOneShot(audioClips[0], 0.8f);
//}
//왼손은 subwayLine Effect
// if(ControllerInput.IsTriggerGetDown(OVRInput.Controller.LTouch) || Input.GetKeyDown(KeyCode.Space))
//{
// subwayLineEffect.SetActive(true);
// }
// if(ControllerInput.IsTriggerGetUp(OVRInput.Controller.LTouch) || Input.GetKeyDown(KeyCode.Space))
//{
// subwayLineEffect.SetActive(false);
// audioSource.PlayOneShot(audioClips[1], 0.8f);
// }
}
//private void CityEffect()
//{
// if(ControllerInput.IsTriggerGetDown(OVRInput.Controller.LTouch) || ControllerInput.IsTriggerGetDown(OVRInput.Controller.RTouch))
// {
// //네온 애니메이션을 실행해라
// for (int i = 0; i < animators.Length; i++)
// {
// animators[i].SetBool("isBlinking", true);
// }
// }
// if(ControllerInput.IsTriggerGetUp(OVRInput.Controller.LTouch) || ControllerInput.IsTriggerGetUp(OVRInput.Controller.RTouch))
// {
// for (int i = 0; i < animators.Length; i++)
// {
// animators[i].SetBool("isBlinking", false);
// }
// }
//}
//private void CorridorEffect()
//{
// //오른손은 색깔 변화
// float colorValue = ControllerInput.GetTriggerValue(OVRInput.Controller.RTouch);
// //왼손은 길이
// float lengthValue = ControllerInput.GetTriggerValue(OVRInput.Controller.LTouch);
// for(int i=0; i< vFXLineLenth_s.Length;i++)
// {
// vFXLineLenth_s[i].SetFloat("_ColorEffect", colorValue);
// vFXLineLenth_s[i].SetFloat("_LineLengthEffect", lengthValue);
// }
//}
public float lerpSpeed = 5.0f;
//IEnumerator Expand(Vector3 _b1Pos, int _indexJ, int _indexI)
//{
// Vector3 _tempB1Pos = _b1Pos;
// Vector3 destPos = _b1Pos += new Vector3(0, 0, _indexJ * 10);
// while(_tempB1Pos.z != destPos.z)
// {
// yield return null;
// _tempB1Pos = Vector3.Lerp(_tempB1Pos, destPos, lerpSpeed * Time.deltaTime);
// vFXLineLenth_s[_indexI].SetVector3("_Pos", _tempB1Pos);
// }
// while(_tempB1Pos.z != _b1Pos.z)
// {
// yield return null;
// _tempB1Pos = Vector3.Lerp(_tempB1Pos, _b1Pos, lerpSpeed * Time.deltaTime);
// vFXLineLenth_s[_indexI].SetVector3("_Pos", _tempB1Pos);
// }
// yield return null;
//}
}
}
https://github.com/keijiro/Eyeball/blob/main/Assets/Controller.cs
GitHub - keijiro/Eyeball: Unity VFX Shader Graph sample
Unity VFX Shader Graph sample. Contribute to keijiro/Eyeball development by creating an account on GitHub.
github.com
블랙보드에서 프로퍼티?? 어트리뷰트?? 추가해준다
728x90
반응형