浏览代码

Added VFX Set Property Action and VFX Send Event Action

/main
Thomas ICHÉ 5 年前
当前提交
f7468bae
共有 5 个文件被更改,包括 167 次插入0 次删除
  1. 2
      CHANGELOG.md
  2. 17
      Runtime/LevelScripting/Actions/VFXSendEventAction.cs
  3. 11
      Runtime/LevelScripting/Actions/VFXSendEventAction.cs.meta
  4. 126
      Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs
  5. 11
      Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs.meta

2
CHANGELOG.md


* **Call Tree Explorer**: Added Category for Erroneous Calls
* Added **ToggleBehaviourAction** working the same as ToggleGameObjectAction, but for behaviour components instead.
* **SendMessageBehaviour** (Timeline Send Message Tracks/Clips) now displays an instigator game object field in the inspector to be attached to the sent message.
* Added **VFXSetPropertyAction**
* Added **VFXSendEventAction**
#### Fixed

17
Runtime/LevelScripting/Actions/VFXSendEventAction.cs


using GameplayIngredients.Actions;
using UnityEngine;
using UnityEngine.VFX;
public class VFXSendEventAction : ActionBase
{
public VisualEffect visualEffect;
public string eventName = "Event";
public override void Execute(GameObject instigator = null)
{
int id = Shader.PropertyToID(eventName);
var attrib = visualEffect.CreateVFXEventAttribute();
visualEffect.SendEvent(eventName, attrib);
}
}

11
Runtime/LevelScripting/Actions/VFXSendEventAction.cs.meta


fileFormatVersion: 2
guid: 4845d67d1445f99478775602bba410c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

126
Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs


using GameplayIngredients.Actions;
using UnityEngine;
using UnityEngine.VFX;
using NaughtyAttributes;
using UnityEngine.Serialization;
public class VFXSetPropertyAction : ActionBase
{
public enum DataType
{
Bool,
Float,
Vector2,
Vector3,
Vector4,
Texture2D,
Texture3D,
UInt,
Int
}
public VisualEffect visualEffect;
[FormerlySerializedAs("parameter")]
public string property = "Property";
public bool Override = true;
[SerializeField]
protected DataType dataType = DataType.Float;
[ShowIf("isBool")]
public bool BoolValue = false;
[ShowIf("isFloat")]
public float FloatValue = 0.0f;
[ShowIf("isVector2")]
public Vector2 Vector2Value = Vector2.zero;
[ShowIf("isVector3")]
public Vector3 Vector3Value = Vector3.zero;
[ShowIf("isVector4")]
public Vector4 Vector4Value = Vector4.zero;
[ShowIf("isTexture2D")]
public Texture2D Texture2DValue;
[ShowIf("isTexture3D")]
public Texture3D Texture3DValue;
[ShowIf("isUInt")]
public uint UIntValue = 0;
[ShowIf("isInt")]
public int IntValue = 0;
public override void Execute(GameObject instigator = null)
{
int id = Shader.PropertyToID(property);
if(HasParameter(id))
{
if (!Override)
visualEffect.ResetOverride(id);
else
{
switch (dataType)
{
case DataType.Bool: visualEffect.SetBool(id, BoolValue); break;
case DataType.Float: visualEffect.SetFloat(id, FloatValue); break;
case DataType.Vector2: visualEffect.SetVector2(id, Vector2Value); break;
case DataType.Vector3: visualEffect.SetVector3(id, Vector3Value); break;
case DataType.Vector4: visualEffect.SetVector4(id, Vector4Value); break;
case DataType.Texture2D: visualEffect.SetTexture(id, Texture2DValue); break;
case DataType.Texture3D: visualEffect.SetTexture(id, Texture3DValue); break;
case DataType.UInt: visualEffect.SetUInt(id, UIntValue); break;
case DataType.Int: visualEffect.SetInt(id, IntValue); break;
}
}
}
}
bool HasParameter(int id)
{
switch(dataType)
{
case DataType.Bool: return visualEffect.HasBool(id);
case DataType.Float: return visualEffect.HasFloat(id);
case DataType.Vector2: return visualEffect.HasVector2(id);
case DataType.Vector3: return visualEffect.HasVector3(id);
case DataType.Vector4: return visualEffect.HasVector4(id);
case DataType.Texture2D: return visualEffect.HasTexture(id);
case DataType.Texture3D: return visualEffect.HasTexture(id);
case DataType.UInt: return visualEffect.HasUInt(id);
case DataType.Int: return visualEffect.HasInt(id);
}
return false;
}
public override string GetDefaultName()
{
if (!Override)
return $"Reset VFX override for parameter :'{property}' ({dataType})";
else
{
switch (dataType)
{
case DataType.Bool: return $"{visualEffect.name} {property} {BoolValue} ";
case DataType.Float: return $"{visualEffect.name} {property} {FloatValue} ";
case DataType.Vector2: return $"{visualEffect.name} {property} {Vector2Value} ";
case DataType.Vector3: return $"{visualEffect.name} {property} {Vector3Value} ";
case DataType.Vector4: return $"{visualEffect.name} {property} {Vector4Value} ";
case DataType.Texture2D: return $"{visualEffect.name} {property} {Texture2DValue} ";
case DataType.Texture3D: return $"{visualEffect.name} {property} {Texture3DValue} ";
case DataType.UInt: return $"{visualEffect.name} {property} {UIntValue} ";
case DataType.Int: return $"{visualEffect.name} {property} {IntValue} ";
default:
return $"Set VFX <UNKNOWN> parameter :'{property}'";
}
}
}
bool isBool() { return dataType == DataType.Bool; }
bool isFloat() { return dataType == DataType.Float; }
bool isVector2() { return dataType == DataType.Vector2; }
bool isVector3() { return dataType == DataType.Vector3; }
bool isVector4() { return dataType == DataType.Vector4; }
bool isTexture2D() { return dataType == DataType.Texture2D; }
bool isTexture3D() { return dataType == DataType.Texture3D; }
bool isUInt() { return dataType == DataType.UInt; }
bool isInt() { return dataType == DataType.Int; }
}

11
Runtime/LevelScripting/Actions/VFXSetPropertyAction.cs.meta


fileFormatVersion: 2
guid: f78535f6bcf4e134fba8e5bdaadcf1da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存