浏览代码

Added OnVFXOutputEvent / Fixes for VFX Actions / Added AssemblyInfo Defines

/feature-on-vfx-output-event
Thomas ICHÉ 4 年前
当前提交
8b84168d
共有 8 个文件被更改,包括 152 次插入11 次删除
  1. 3
      Editor/PropertyDrawers/CallableReorderableList.cs
  2. 42
      Icons/Misc/ic-vfx.png
  3. 5
      Runtime/GameplayIngredients.asmdef
  4. 1
      Runtime/GameplayIngredients.cs
  5. 19
      Runtime/LevelScripting/Actions/VFXSendEventAction.cs
  6. 20
      Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs
  7. 62
      Runtime/LevelScripting/Events/OnVFXOutputEvent.cs
  8. 11
      Runtime/LevelScripting/Events/OnVFXOutputEvent.cs.meta

3
Editor/PropertyDrawers/CallableReorderableList.cs


using UnityEditor;
using UnityEditorInternal;
using System.Linq;
using System.Reflection;
namespace GameplayIngredients.Editor
{

{
public static void AddCallable(this GameObject gameObject, Component component, string propertyName, System.Type t)
{
var field = component.GetType().GetFields().Where(f => f.Name == propertyName).FirstOrDefault();
var field = component.GetType().GetFields(BindingFlags.Public| BindingFlags.Instance | BindingFlags.NonPublic).Where(f => f.Name == propertyName).FirstOrDefault();
var val = field.GetValue(component) as Callable[];
if (t != null && typeof(Callable).IsAssignableFrom(t))

42
Icons/Misc/ic-vfx.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 2.8 KiB

5
Runtime/GameplayIngredients.asmdef


"name": "com.unity.modules.screencapture",
"expression": "1.0.0",
"define": "MODULE_SCREENCAPTURE"
},
{
"name": "com.unity.visualeffectgraph",
"expression": "10.0.0",
"define": "PACKAGE_VFXGRAPH"
}
],
"noEngineReferences": false

1
Runtime/GameplayIngredients.cs


public const string rigsPath = basePath + "Rigs/";
public const string timerPath = basePath + "Timers/";
public const string stateMachinePath = basePath + "State Machines/";
public const string vfxPath = basePath + "VFX/";
}

19
Runtime/LevelScripting/Actions/VFXSendEventAction.cs


using UnityEngine;
#if PACKAGE_VFXGRAPH
#endif
[AddComponentMenu(ComponentMenu.actionsPath + "VFX Send Event Action")]
[Callable("Game", "Misc/ic-vfx.png")]
#if !PACKAGE_VFXGRAPH
[WarnDisabledModule("Visual Effect Graph")]
#endif
[AddComponentMenu(ComponentMenu.vfxPath + "VFX Send Event Action")]
[Callable("Visual Effects", "Misc/ic-vfx.png")]
#if PACKAGE_VFXGRAPH
[NonNullCheck]
#endif
#if PACKAGE_VFXGRAPH
var attrib = visualEffect.CreateVFXEventAttribute();
visualEffect.SendEvent(eventName, attrib);
visualEffect?.SendEvent(eventName);
#else
Debug.LogWarning("VFXSendEventAction could not attach to VFX as VFX Graph package is not installed, if you're running HDRP or URP, please install it using package manager.");
#endif
}
public override string GetDefaultName()

20
Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs


using UnityEngine;
#if PACKAGE_VFXGRAPH
#endif
[AddComponentMenu(ComponentMenu.actionsPath + "VFX Set Property Action")]
[Callable("Game", "Misc/ic-vfx.png")]
#if !PACKAGE_VFXGRAPH
[WarnDisabledModule("Visual Effect Graph")]
#endif
[AddComponentMenu(ComponentMenu.vfxPath + "VFX Set Property Action")]
[Callable("Visual Effects", "Misc/ic-vfx.png")]
public class VFXSetPropertyAction : ActionBase
{
public enum DataType

UInt,
Int
}
#if PACKAGE_VFXGRAPH
#endif
[FormerlySerializedAs("parameter")]
public string property = "Property";

{
int id = Shader.PropertyToID(property);
if(HasParameter(id))
#if PACKAGE_VFXGRAPH
if (HasProperty(id))
{
if (!Override)
visualEffect.ResetOverride(id);

}
}
}
#else
Debug.LogWarning("VFXSetPropertyAction could not attach to VFX as VFX Graph package is not installed, if you're running HDRP or URP, please install it using package manager.");
#endif
bool HasParameter(int id)
bool HasProperty(int id)
{
switch(dataType)
{

62
Runtime/LevelScripting/Events/OnVFXOutputEvent.cs


using UnityEngine;
#if PACKAGE_VFXGRAPH
using UnityEngine.VFX;
#endif
namespace GameplayIngredients.Events
{
#if !PACKAGE_VFXGRAPH
[WarnDisabledModule("Visual Effect Graph")]
#else
[AddComponentMenu(ComponentMenu.vfxPath + "On VFX Output Event")]
[RequireComponent(typeof(VisualEffect))]
#endif
public class OnVFXOutputEvent : EventBase
{
public string vfxEventName { get => m_VFXEventName; set { m_VFXEventName = value; CacheEventName(); } }
[SerializeField]
string m_VFXEventName = "On Received Event";
int m_VFXEventID;
[SerializeField]
protected Callable[] onEventReceived;
private void OnEnable()
{
CacheEventName();
#if PACKAGE_VFXGRAPH
GetComponent<VisualEffect>().outputEventReceived += OnVFXOutputEvent_Received;
#else
Debug.LogWarning("OnVFXOutputEvent could not attach to VFX as VFX Graph package is not installed, if you're running HDRP or URP, please install it using package manager.");
#endif
}
private void OnDisable()
{
#if PACKAGE_VFXGRAPH
GetComponent<VisualEffect>().outputEventReceived -= OnVFXOutputEvent_Received;
#endif
}
private void OnValidate()
{
CacheEventName();
}
void CacheEventName()
{
m_VFXEventID = Shader.PropertyToID(m_VFXEventName);
}
#if PACKAGE_VFXGRAPH
void OnVFXOutputEvent_Received(VFXOutputEventArgs args)
{
if(args.nameId == m_VFXEventID)
{
Callable.Call(onEventReceived, gameObject);
}
}
#endif
}
}

11
Runtime/LevelScripting/Events/OnVFXOutputEvent.cs.meta


fileFormatVersion: 2
guid: 68ebf341e2a981b47b256be279fd4bf8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 9a14315cb05b557459e14128a03f988f, type: 3}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存