Skip to content

Commit

Permalink
OnVFXOutputEvent (#52)
Browse files Browse the repository at this point in the history
* Added OnVFXOutputEvent / Fixes for VFX Actions / Added AssemblyInfo Defines

* Updated Changelog
  • Loading branch information
peeweek authored May 2, 2021
1 parent 7a57491 commit 15cbf73
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Added

* Added `OnVFXOutputEvent` that triggers upon a visual effect output event
* Added `WarnDisabledModuleAttribute` for GameplayIngredientsBehaviors that need to be disabled (encapsulate into #ifdefs )
* Added New Input System support:
* Handles presence/absence of both systems (legacy/new) in Screenshot Manager, UIEventManager
Expand All @@ -17,12 +18,15 @@
* `OnInputDirectEvent` polls state without InputActions
* `OnPlayerInputAction` gets input from a `PlayerInput`
* Reworked PlayerInput for FirstPersonController using both Input Systems

* Added Cinemachine Actions:
* `CinemachineSetCameraNoiseAction` : Defines or remove noise for a Virtual Camera
* `CinemachineSetCustomBlendsAction` : Defines custom blends for the Cinemachine Brain of the Virtual Camera Manager
* `CinemachineCameraShakeAction` : Trigger camera shakes for Cinemachine Impulse Sources

#### Fixed

* Fixed Callable add Menu that did not set correctly non-public callable lists.

## 2020.2.6

#### Added
Expand Down
3 changes: 2 additions & 1 deletion Editor/PropertyDrawers/CallableReorderableList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEditor;
using UnityEditorInternal;
using System.Linq;
using System.Reflection;

namespace GameplayIngredients.Editor
{
Expand Down Expand Up @@ -124,7 +125,7 @@ public static class CallableExtensions
{
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))
Expand Down
Binary file modified Icons/Misc/ic-vfx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Runtime/GameplayIngredients.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"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
Expand Down
1 change: 1 addition & 0 deletions Runtime/GameplayIngredients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static class ComponentMenu
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/";
}


Expand Down
19 changes: 15 additions & 4 deletions Runtime/LevelScripting/Actions/VFXSendEventAction.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
using UnityEngine;
#if PACKAGE_VFXGRAPH
using UnityEngine.VFX;
#endif

namespace GameplayIngredients.Actions
{
[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")]
public class VFXSendEventAction : ActionBase
{
#if PACKAGE_VFXGRAPH
[NonNullCheck]
public VisualEffect visualEffect;
#endif

public string eventName = "Event";

public override void Execute(GameObject instigator = null)
{
#if PACKAGE_VFXGRAPH
int id = Shader.PropertyToID(eventName);
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()
Expand Down
20 changes: 15 additions & 5 deletions Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using UnityEngine;
#if PACKAGE_VFXGRAPH
using UnityEngine.VFX;
#endif
using NaughtyAttributes;
using UnityEngine.Serialization;

namespace GameplayIngredients.Actions
{
[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
Expand All @@ -21,8 +26,9 @@ public enum DataType
UInt,
Int
}

#if PACKAGE_VFXGRAPH
public VisualEffect visualEffect;
#endif

[FormerlySerializedAs("parameter")]
public string property = "Property";
Expand Down Expand Up @@ -54,7 +60,8 @@ public override void Execute(GameObject instigator = null)
{
int id = Shader.PropertyToID(property);

if(HasParameter(id))
#if PACKAGE_VFXGRAPH
if (HasProperty(id))
{
if (!Override)
visualEffect.ResetOverride(id);
Expand All @@ -74,9 +81,12 @@ public override void Execute(GameObject instigator = null)
}
}
}
#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)
{
Expand Down
62 changes: 62 additions & 0 deletions Runtime/LevelScripting/Events/OnVFXOutputEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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 changes: 11 additions & 0 deletions Runtime/LevelScripting/Events/OnVFXOutputEvent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15cbf73

Please sign in to comment.