在此项目中,您能够访问使用 Visual Effect Graph 制作的示例场景和效果。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

79 行
1.9 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.VFX;
public static class ARRShaderPropertyToID
{
public static int galaxyMapInitialize = Shader.PropertyToID("Initialize");
}
public class ARRadarController : MonoBehaviour {
public AnimationCurve curve;
private float m_value = 0f;
public float showSpeed = 0.7f;
public float hideSpeed = 1.2f;
public bool toggle;
private Light m_light;
private float m_lightIntensity = 0f;
private VisualEffect m_vf;
private void Awake()
{
m_light = GetComponentInChildren<Light>();
if (m_light != null)
m_lightIntensity = m_light.intensity;
m_vf = GetComponent<VisualEffect>();
}
private void OnEnable()
{
toggle = true;
}
IEnumerator Start ()
{
// m_vf = GetComponent<VisualEffect>();
while (true)
{
if (m_vf == null)
{
Debug.LogWarning("No Visual Effect component found; the ARRadarController script needs to be attached to the ARRadar effect.");
break;
}
if (toggle)
{
if (m_value < 1f)
m_value += Time.deltaTime * showSpeed * curve.Evaluate(m_value);
if (m_value > 1f)
m_value = 1f;
}
else
{
if (m_value > 0f)
m_value -= Time.deltaTime * hideSpeed * curve.Evaluate(m_value);
if (m_value < 0f)
m_value = 0f;
}
if (m_light != null)
m_light.intensity = Mathf.Lerp(0f, m_lightIntensity, m_value);
m_vf.SetFloat(ARRShaderPropertyToID.galaxyMapInitialize, m_value);
if (Input.GetKeyDown(KeyCode.Space))
toggle = !toggle;
yield return null;
}
}
}