浏览代码

Delayed logic modes and Audio Play Clip random pitch and volume (#8)

* Add delay mode to delayed logic, add randomization options to play audio clip action

* Update CHANGELOG.md
/main
Thomas ICHÉ 4 年前
当前提交
0eb43594
共有 3 个文件被更改,包括 38 次插入19 次删除
  1. 2
      CHANGELOG.md
  2. 18
      Runtime/LevelScripting/Actions/AudioPlayClipAction.cs
  3. 37
      Runtime/LevelScripting/Logic/DelayedLogic.cs

2
CHANGELOG.md


* **Messager** is now able to pass instigator Game Object through message broadcast.
* **OnMessageEvent** now passes the optional instigator instead of itself as instigator to the Calls. In order to pass itself use an intermediate **SetInstigatorLogic** that targets the OnMessageEvent owner to replicate the former behaviour.
* **SendMessageAction** now passes its instigator game object to the **Messager**
* **Delayed Logic** now has a mode that allows you to have a random delay within a range.
* **Audio Play Clip Action** now allows you to randomize volume and pitch within a range of values every time you play the clip.
#### Added

18
Runtime/LevelScripting/Actions/AudioPlayClipAction.cs


using System.Collections;
using System;
using UnityEngine.Audio;
using UnityEngine.Events;
using NaughtyAttributes;
namespace GameplayIngredients.Actions
{

public AudioSource Source;
public bool RandomizePitch = false;
[ShowIf("RandomizePitch")]
public Vector2 PitchRange = new Vector2(0,3);
public bool RandomizeVolume = false;
[ShowIf("RandomizeVolume")]
public Vector2 VolumeRange = new Vector2(0, 1);
public override void Execute(GameObject instigator = null)
{

if (RandomizePitch)
Source.pitch = Random.Range(PitchRange.x, PitchRange.y);
if (RandomizeVolume)
Source.volume = Random.Range(VolumeRange.x, VolumeRange.y);
if (Clip != null)
Source.clip = Clip;

}
}

37
Runtime/LevelScripting/Logic/DelayedLogic.cs


using NaughtyAttributes;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
public enum DelayMode { Constant, Random };
public DelayMode delayMode;
[ShowIf("DelayIsConstant")]
[ShowIf("DelayIsRandom")]
public Vector2 DelayRange = Vector2.one;
private void OnValidate()
{
if (DelayIsConstant())
DelayRange = new Vector2(Delay, Delay + 1);
}
private bool DelayIsRandom()
{
bool random = delayMode == DelayMode.Random ? true : false;
return random;
}
private bool DelayIsConstant() { return !DelayIsRandom(); }
if(m_Coroutine != null)
if (m_Coroutine != null)
{
StopCoroutine(m_Coroutine);
Callable.Call(OnCanceled, instigator);

float newDelay;
m_Coroutine = RunDelay(Delay, instigator);
if (delayMode == DelayMode.Random)
newDelay = Random.Range(DelayRange.x, DelayRange.y);
else
newDelay = Delay;
m_Coroutine = RunDelay(newDelay, instigator);
IEnumerator RunDelay(float Seconds, GameObject instigator = null)
{
yield return new WaitForSeconds(Seconds);

}
}
}
正在加载...
取消
保存