Added Feel plugin

This commit is contained in:
journaliciouz
2025-12-11 14:49:16 +01:00
parent 97dce4aaf6
commit 1942a531d4
2820 changed files with 257786 additions and 9 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c0cd952ed9971344c97734e47ae5bfdc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 76b756cf8480fcd4bb9db669233c29c5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,166 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.FeedbacksForThirdParty
{
[System.Serializable]
[AddComponentMenu("")]
#if MM_CINEMACHINE || MM_CINEMACHINE3
[FeedbackPath("Camera/Cinemachine Impulse")]
#endif
[MovedFrom(false, null, "MoreMountains.Feedbacks.Cinemachine")]
[FeedbackHelp("This feedback lets you trigger a Cinemachine Impulse event. You'll need a Cinemachine Impulse Listener on your camera for this to work.")]
public class MMF_CinemachineImpulse : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.CameraColor; } }
public override bool HasCustomInspectors => true;
public override bool HasAutomaticShakerSetup => true;
#endif
public override bool HasRandomness => true;
#if MM_CINEMACHINE || MM_CINEMACHINE3
[MMFInspectorGroup("Cinemachine Impulse", true, 28)]
/// the impulse definition to broadcast
[Tooltip("the impulse definition to broadcast")]
public CinemachineImpulseDefinition m_ImpulseDefinition = new CinemachineImpulseDefinition();
/// the velocity to apply to the impulse shake
[Tooltip("the velocity to apply to the impulse shake")]
public Vector3 Velocity;
/// whether or not to clear impulses (stopping camera shakes) when the Stop method is called on that feedback
[Tooltip("whether or not to clear impulses (stopping camera shakes) when the Stop method is called on that feedback")]
public bool ClearImpulseOnStop = false;
#endif
[Header("Gizmos")]
/// whether or not to draw gizmos to showcase the various distance properties of this feedback, when applicable. Dissipation distance in blue, impact radius in yellow.
[Tooltip("whether or not to draw gizmos to showcase the various distance properties of this feedback, when applicable. Dissipation distance in blue, impact radius in yellow.")]
public bool DrawGizmos = false;
#if MM_CINEMACHINE
/// the duration of this feedback is the duration of the impulse
public override float FeedbackDuration { get { return m_ImpulseDefinition != null ? m_ImpulseDefinition.m_TimeEnvelope.Duration : 0f; } }
#elif MM_CINEMACHINE3
/// the duration of this feedback is the duration of the impulse
public override float FeedbackDuration { get { return m_ImpulseDefinition != null ? m_ImpulseDefinition.TimeEnvelope.Duration : 0f; } }
#endif
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
CinemachineImpulseManager.Instance.IgnoreTimeScale = !InScaledTimescaleMode;
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
m_ImpulseDefinition.CreateEvent(position, Velocity * intensityMultiplier);
#endif
}
/// <summary>
/// Stops the animation if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
if (!Active || !FeedbackTypeAuthorized || !ClearImpulseOnStop)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
CinemachineImpulseManager.Instance.Clear();
#endif
}
/// <summary>
/// When adding the feedback we initialize its cinemachine impulse definition
/// </summary>
public override void OnAddFeedback()
{
#if MM_CINEMACHINE
// sets the feedback properties
if (this.m_ImpulseDefinition == null)
{
this.m_ImpulseDefinition = new CinemachineImpulseDefinition();
}
this.m_ImpulseDefinition.m_RawSignal = Resources.Load<NoiseSettings>("MM_6D_Shake");
this.Velocity = new Vector3(5f, 5f, 5f);
#elif MM_CINEMACHINE3
// sets the feedback properties
if (this.m_ImpulseDefinition == null)
{
this.m_ImpulseDefinition = new CinemachineImpulseDefinition();
}
this.m_ImpulseDefinition.RawSignal = Resources.Load<NoiseSettings>("MM_6D_Shake");
this.Velocity = new Vector3(5f, 5f, 5f);
#endif
}
/// <summary>
/// Draws dissipation distance and impact distance gizmos if necessary
/// </summary>
public override void OnDrawGizmosSelectedHandler()
{
if (!DrawGizmos)
{
return;
}
#if MM_CINEMACHINE
{
if ( (this.m_ImpulseDefinition.m_ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Dissipating)
|| (this.m_ImpulseDefinition.m_ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Propagating)
|| (this.m_ImpulseDefinition.m_ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Legacy) )
{
Gizmos.color = MMColors.Aqua;
Gizmos.DrawWireSphere(Owner.transform.position, this.m_ImpulseDefinition.m_DissipationDistance);
}
if (this.m_ImpulseDefinition.m_ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Legacy)
{
Gizmos.color = MMColors.ReunoYellow;
Gizmos.DrawWireSphere(Owner.transform.position, this.m_ImpulseDefinition.m_ImpactRadius);
}
}
#elif MM_CINEMACHINE3
if (this.m_ImpulseDefinition != null)
{
if ( (this.m_ImpulseDefinition.ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Dissipating)
|| (this.m_ImpulseDefinition.ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Propagating)
|| (this.m_ImpulseDefinition.ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Legacy) )
{
Gizmos.color = MMColors.Aqua;
Gizmos.DrawWireSphere(Owner.transform.position, this.m_ImpulseDefinition.DissipationDistance);
}
if (this.m_ImpulseDefinition.ImpulseType == CinemachineImpulseDefinition.ImpulseTypes.Legacy)
{
Gizmos.color = MMColors.ReunoYellow;
Gizmos.DrawWireSphere(Owner.transform.position, this.m_ImpulseDefinition.ImpactRadius);
}
}
#endif
}
/// <summary>
/// Automatically adds a Cinemachine Impulse Listener to the camera
/// </summary>
public override void AutomaticShakerSetup()
{
MMCinemachineHelpers.AutomaticCinemachineShakersSetup(Owner, "CinemachineImpulse");
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2ee48f409bf2e3e4baf85ca77d2ca0af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Feedbacks/MMF_CinemachineImpulse.cs
uploadId: 830868

View File

@@ -0,0 +1,39 @@
using UnityEngine;
using MoreMountains.Feedbacks;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.FeedbacksForThirdParty
{
[AddComponentMenu("")]
#if MM_CINEMACHINE || MM_CINEMACHINE3
[System.Serializable]
[FeedbackPath("Camera/Cinemachine Impulse Clear")]
#endif
[MovedFrom(false, null, "MoreMountains.Feedbacks.Cinemachine")]
[FeedbackHelp("This feedback lets you trigger a Cinemachine Impulse clear, stopping instantly any impulse that may be playing.")]
public class MMF_CinemachineImpulseClear : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.CameraColor; } }
#endif
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
CinemachineImpulseManager.Instance.Clear();
#endif
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b2362762ee575ad4ab16bb938247878b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Feedbacks/MMF_CinemachineImpulseClear.cs
uploadId: 830868

View File

@@ -0,0 +1,99 @@
using UnityEngine;
using MoreMountains.Feedbacks;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.FeedbacksForThirdParty
{
[System.Serializable]
[AddComponentMenu("")]
#if MM_CINEMACHINE || MM_CINEMACHINE3
[FeedbackPath("Camera/Cinemachine Impulse Source")]
#endif
[MovedFrom(false, null, "MoreMountains.Feedbacks.Cinemachine")]
[FeedbackHelp("This feedback lets you generate an impulse on a Cinemachine Impulse source. You'll need a Cinemachine Impulse Listener on your camera for this to work.")]
public class MMF_CinemachineImpulseSource : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.CameraColor; } }
#if MM_CINEMACHINE || MM_CINEMACHINE3
public override bool EvaluateRequiresSetup() { return (ImpulseSource == null); }
public override string RequiredTargetText { get { return ImpulseSource != null ? ImpulseSource.name : ""; } }
#endif
public override string RequiresSetupText { get { return "This feedback requires that an ImpulseSource be set to be able to work properly. You can set one below."; } }
#endif
[MMFInspectorGroup("Cinemachine Impulse Source", true, 28)]
/// the velocity to apply to the impulse shake
[Tooltip("the velocity to apply to the impulse shake")]
public Vector3 Velocity = new Vector3(1f,1f,1f);
#if MM_CINEMACHINE || MM_CINEMACHINE3
/// the impulse definition to broadcast
[Tooltip("the impulse definition to broadcast")]
public CinemachineImpulseSource ImpulseSource;
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => ImpulseSource = FindAutomatedTarget<CinemachineImpulseSource>();
#endif
/// whether or not to clear impulses (stopping camera shakes) when the Stop method is called on that feedback
[Tooltip("whether or not to clear impulses (stopping camera shakes) when the Stop method is called on that feedback")]
public bool ClearImpulseOnStop = false;
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
if (ImpulseSource != null)
{
ImpulseSource.GenerateImpulse(Velocity);
}
#endif
}
/// <summary>
/// Stops the animation if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized || !ClearImpulseOnStop)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
#if MM_CINEMACHINE || MM_CINEMACHINE3
CinemachineImpulseManager.Instance.Clear();
#endif
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
CinemachineImpulseManager.Instance.Clear();
#endif
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 0f6892e7c981ffa45ad8e24c33bdac4e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Feedbacks/MMF_CinemachineImpulseSource.cs
uploadId: 830868

View File

@@ -0,0 +1,151 @@
using UnityEngine;
using MoreMountains.Feedbacks;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// This feedback will let you change the priorities of your cameras.
/// It requires a bit of setup : adding a MMCinemachinePriorityListener to your different cameras, with unique Channel values on them.
/// Optionally, you can add a MMCinemachinePriorityBrainListener on your Cinemachine Brain to handle different transition types and durations.
/// Then all you have to do is pick a channel and a new priority on your feedback, and play it. Magic transition!
/// </summary>
[AddComponentMenu("")]
#if MM_CINEMACHINE || MM_CINEMACHINE3
[System.Serializable]
[FeedbackPath("Camera/Cinemachine Transition")]
#endif
[MovedFrom(false, null, "MoreMountains.Feedbacks.Cinemachine")]
[FeedbackHelp("This feedback will let you change the priorities of your cameras. It requires a bit of setup : " +
"adding a MMCinemachinePriorityListener to your different cameras, with unique Channel values on them. " +
"Optionally, you can add a MMCinemachinePriorityBrainListener on your Cinemachine Brain to handle different transition types and durations. " +
"Then all you have to do is pick a channel and a new priority on your feedback, and play it. Magic transition!")]
public class MMF_CinemachineTransition : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
public enum Modes { Event, Binding }
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.CameraColor; } }
public override string RequiredTargetText => RequiredChannelText;
#endif
#if MM_CINEMACHINE
/// the duration of this feedback is the duration of the shake
public override float FeedbackDuration { get { return ApplyTimeMultiplier(BlendDefintion.m_Time); } set { BlendDefintion.m_Time = value; } }
#elif MM_CINEMACHINE3
public override float FeedbackDuration { get { return ApplyTimeMultiplier(BlendDefintion.Time); } set { BlendDefintion.Time = value; } }
#endif
#if MM_CINEMACHINE || MM_CINEMACHINE3
public override bool HasAutomatedTargetAcquisition => true;
#endif
#if MM_CINEMACHINE
protected override void AutomateTargetAcquisition() => TargetVirtualCamera = FindAutomatedTarget<CinemachineVirtualCamera>();
#elif MM_CINEMACHINE3
protected override void AutomateTargetAcquisition() => TargetCinemachineCamera = FindAutomatedTarget<CinemachineCamera>();
#endif
public override bool HasChannel => true;
[MMFInspectorGroup("Cinemachine Transition", true, 52)]
/// the selected mode (either via event, or via direct binding of a specific camera)
[Tooltip("the selected mode (either via event, or via direct binding of a specific camera)")]
public Modes Mode = Modes.Event;
#if MM_CINEMACHINE
/// the virtual camera to target
[Tooltip("the virtual camera to target")]
[MMFEnumCondition("Mode", (int)Modes.Binding)]
public CinemachineVirtualCamera TargetVirtualCamera;
#elif MM_CINEMACHINE3
/// the Cinemachine camera to target
[Tooltip("the Cinemachine camera to target")]
[MMFEnumCondition("Mode", (int)Modes.Binding)]
public CinemachineCamera TargetCinemachineCamera;
#endif
/// whether or not to reset the target's values after shake
[Tooltip("whether or not to reset the target's values after shake")]
public bool ResetValuesAfterTransition = true;
[Header("Priority")]
/// the new priority to apply to all virtual cameras on the specified channel
[Tooltip("the new priority to apply to all virtual cameras on the specified channel")]
public int NewPriority = 10;
/// whether or not to force all virtual cameras on other channels to reset their priority to zero
[Tooltip("whether or not to force all virtual cameras on other channels to reset their priority to zero")]
public bool ForceMaxPriority = true;
/// whether or not to apply a new blend
[Tooltip("whether or not to apply a new blend")]
public bool ForceTransition = false;
#if MM_CINEMACHINE || MM_CINEMACHINE3
/// the new blend definition to apply
[Tooltip("the new blend definition to apply")]
[MMFCondition("ForceTransition", true)]
public CinemachineBlendDefinition BlendDefintion;
protected CinemachineBlendDefinition _tempBlend;
#endif
/// <summary>
/// Triggers a priority change on listening virtual cameras
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
_tempBlend = BlendDefintion;
#endif
#if MM_CINEMACHINE
_tempBlend.m_Time = FeedbackDuration;
#elif MM_CINEMACHINE3
_tempBlend.Time = FeedbackDuration;
#endif
#if MM_CINEMACHINE || MM_CINEMACHINE3
if (Mode == Modes.Event)
{
MMCinemachinePriorityEvent.Trigger(ChannelData, ForceMaxPriority, NewPriority, ForceTransition, _tempBlend, ResetValuesAfterTransition, ComputedTimescaleMode);
}
else
{
MMCinemachinePriorityEvent.Trigger(ChannelData, ForceMaxPriority, 0, ForceTransition, _tempBlend, ResetValuesAfterTransition, ComputedTimescaleMode);
SetPriority(NewPriority);
}
#endif
}
protected virtual void SetPriority(int newPriority)
{
#if MM_CINEMACHINE
TargetVirtualCamera.Priority = newPriority;
#elif MM_CINEMACHINE3
PrioritySettings prioritySettings = TargetCinemachineCamera.Priority;
prioritySettings.Value = newPriority;
TargetCinemachineCamera.Priority = prioritySettings;
#endif
}
/// <summary>
/// On restore, we restore our initial state
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
MMCinemachinePriorityEvent.Trigger(ChannelData, ForceMaxPriority, 0, ForceTransition, _tempBlend, ResetValuesAfterTransition, ComputedTimescaleMode, true);
#endif
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2838524600839f84591c1d8a457b2176
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Feedbacks/MMF_CinemachineTransition.cs
uploadId: 830868

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 012099a7c01491d498f5f9098f2c1537
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,99 @@
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
namespace MoreMountains.FeedbacksForThirdParty
{
public class MMCinemachineHelpers : MonoBehaviour
{
public static GameObject AutomaticCinemachineShakersSetup(MMF_Player owner, string feedbackName)
{
GameObject virtualCameraGo = null;
#if MM_CINEMACHINE || MM_CINEMACHINE3
bool newVcam = false;
string additions = owner.name + " "+feedbackName+" feedback automatic shaker setup : ";
#endif
#if MM_CINEMACHINE
//looks for a Cinemachine Brain in the scene
CinemachineBrain cinemachineBrain = (CinemachineBrain)Object.FindAnyObjectByType(typeof(CinemachineBrain));
if (cinemachineBrain == null)
{
cinemachineBrain = Camera.main.gameObject.AddComponent<CinemachineBrain>();
additions += "Added a Cinemachine Brain to the scene. ";
}
// looks for a vcam in the scene
CinemachineVirtualCamera virtualCamera = (CinemachineVirtualCamera)Object.FindAnyObjectByType(typeof(CinemachineVirtualCamera));
if (virtualCamera == null)
{
GameObject newVirtualCamera = new GameObject("CinemachineVirtualCamera");
if (Camera.main != null)
{
newVirtualCamera.transform.position = Camera.main.transform.position;
}
virtualCamera = newVirtualCamera.AddComponent<CinemachineVirtualCamera>();
additions += "Added a Cinemachine Virtual Camera to the scene. ";
newVcam = true;
}
virtualCameraGo = virtualCamera.gameObject;
CinemachineImpulseListener impulseListener = virtualCamera.GetComponent<CinemachineImpulseListener>();
if (impulseListener == null)
{
impulseListener = virtualCamera.gameObject.AddComponent<CinemachineImpulseListener>();
additions += "Added an impulse listener. ";
}
#elif MM_CINEMACHINE3
//looks for a Cinemachine Brain in the scene
CinemachineBrain cinemachineBrain = (CinemachineBrain)Object.FindAnyObjectByType(typeof(CinemachineBrain));
if (cinemachineBrain == null)
{
cinemachineBrain = Camera.main.gameObject.AddComponent<CinemachineBrain>();
additions += "Added a Cinemachine Brain to the scene. ";
}
// looks for a vcam in the scene
CinemachineCamera virtualCamera = (CinemachineCamera)Object.FindAnyObjectByType(typeof(CinemachineCamera));
if (virtualCamera == null)
{
GameObject newVirtualCamera = new GameObject("CinemachineCamera");
if (Camera.main != null)
{
newVirtualCamera.transform.position = Camera.main.transform.position;
}
virtualCamera = newVirtualCamera.AddComponent<CinemachineCamera>();
additions += "Added a Cinemachine Camera to the scene. ";
newVcam = true;
}
virtualCameraGo = virtualCamera.gameObject;
CinemachineImpulseListener impulseListener = virtualCamera.GetComponent<CinemachineImpulseListener>();
if (impulseListener == null)
{
impulseListener = virtualCamera.gameObject.AddComponent<CinemachineImpulseListener>();
additions += "Added an impulse listener. ";
}
#endif
#if MM_CINEMACHINE || MM_CINEMACHINE3
if (newVcam)
{
virtualCameraGo.MMGetOrAddComponent<MMCinemachineCameraShaker>();
virtualCameraGo.MMGetOrAddComponent<MMCinemachineZoom>();
virtualCameraGo.MMGetOrAddComponent<MMCinemachinePriorityListener>();
virtualCameraGo.MMGetOrAddComponent<MMCinemachineClippingPlanesShaker>();
virtualCameraGo.MMGetOrAddComponent<MMCinemachineFieldOfViewShaker>();
additions += "Added camera shaker, zoom, priority listener, clipping planes shaker and field of view shaker to the Cinemachine Camera. ";
}
MMDebug.DebugLogInfo( additions + "You're all set.");
#endif
return virtualCameraGo;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 53907edcd2e7d344c8517b4e1da9e75f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Helpers/MMCinemachineHelpers.cs
uploadId: 830868

View File

@@ -0,0 +1,3 @@
{
"reference": "GUID:4a1cb1490dc4df8409b2580d6b44e75e"
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: afb2be2d186835148b46d3b0c4ae900d
AssemblyDefinitionReferenceImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/MoreMountains.Feedbacks.Cinemachine.asmref
uploadId: 830868

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6f6a830756be1b440bf6d073f91619d7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7f59e54f2bfd184b9dd451a678d089b, type: 3}
m_Name: MM_6D_Shake
m_EditorClassIdentifier:
PositionNoise:
- X:
Frequency: 3.2
Amplitude: 0.011
Constant: 1
Y:
Frequency: 1.9
Amplitude: 0.059
Constant: 1
Z:
Frequency: 3.33
Amplitude: 0.021
Constant: 1
- X:
Frequency: 7.7
Amplitude: 0.009
Constant: 1
Y:
Frequency: 9.1
Amplitude: 0.04
Constant: 0
Z:
Frequency: 9.22
Amplitude: 0.009
Constant: 1
- X:
Frequency: 51.51
Amplitude: 0.002
Constant: 1
Y:
Frequency: 55.54
Amplitude: 0.05
Constant: 1
Z:
Frequency: 58.55
Amplitude: 0.017
Constant: 1
OrientationNoise:
- X:
Frequency: 5.83
Amplitude: 0.09
Constant: 1
Y:
Frequency: 1.8
Amplitude: 0.059
Constant: 1
Z:
Frequency: 2.38
Amplitude: 0.017
Constant: 1
- X:
Frequency: 9.17
Amplitude: 0.14
Constant: 1
Y:
Frequency: 11.35
Amplitude: 0.041
Constant: 1
Z:
Frequency: 10.52
Amplitude: 0.009
Constant: 1
- X:
Frequency: 57.17
Amplitude: 0.15
Constant: 1
Y:
Frequency: 54.17
Amplitude: 0.048
Constant: 1
Z:
Frequency: 63.76
Amplitude: 0.016
Constant: 1

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: bcf6524ce6451f34cb7106d0c00da9a5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Resources/MM_6D_Shake.asset
uploadId: 830868

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 22217fa6cb1ecde4ba6e2ccdeff4ba33
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,233 @@
using System.Collections;
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// Add this component to your Cinemachine Virtual Camera to have it shake when calling its ShakeCamera methods.
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Camera Shaker")]
#if MM_CINEMACHINE
[RequireComponent(typeof(CinemachineVirtualCamera))]
#elif MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineCamera))]
#endif
public class MMCinemachineCameraShaker : MonoBehaviour
{
[Header("Settings")]
/// whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what.
/// MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable
[Tooltip("whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what. " +
"MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable")]
public MMChannelModes ChannelMode = MMChannelModes.Int;
/// the channel to listen to - has to match the one on the feedback
[Tooltip("the channel to listen to - has to match the one on the feedback")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.Int)]
public int Channel = 0;
/// the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel,
/// right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name
[Tooltip("the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel, " +
"right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.MMChannel)]
public MMChannel MMChannelDefinition = null;
/// The default amplitude that will be applied to your shakes if you don't specify one
[Tooltip("The default amplitude that will be applied to your shakes if you don't specify one")]
public float DefaultShakeAmplitude = .5f;
/// The default frequency that will be applied to your shakes if you don't specify one
[Tooltip("The default frequency that will be applied to your shakes if you don't specify one")]
public float DefaultShakeFrequency = 10f;
/// the amplitude of the camera's noise when it's idle
[Tooltip("the amplitude of the camera's noise when it's idle")]
[MMFReadOnly]
public float IdleAmplitude;
/// the frequency of the camera's noise when it's idle
[Tooltip("the frequency of the camera's noise when it's idle")]
[MMFReadOnly]
public float IdleFrequency = 1f;
/// the speed at which to interpolate the shake
[Tooltip("the speed at which to interpolate the shake")]
public float LerpSpeed = 5f;
[Header("Test")]
/// a duration (in seconds) to apply when testing this shake via the TestShake button
[Tooltip("a duration (in seconds) to apply when testing this shake via the TestShake button")]
public float TestDuration = 0.3f;
/// the amplitude to apply when testing this shake via the TestShake button
[Tooltip("the amplitude to apply when testing this shake via the TestShake button")]
public float TestAmplitude = 2f;
/// the frequency to apply when testing this shake via the TestShake button
[Tooltip("the frequency to apply when testing this shake via the TestShake button")]
public float TestFrequency = 20f;
[MMFInspectorButton("TestShake")]
public bool TestShakeButton;
public virtual float GetTime() { return (_timescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime; }
public virtual float GetDeltaTime() { return (_timescaleMode == TimescaleModes.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; }
protected TimescaleModes _timescaleMode;
protected Vector3 _initialPosition;
protected Quaternion _initialRotation;
#if MM_CINEMACHINE
protected Cinemachine.CinemachineBasicMultiChannelPerlin _perlin;
protected Cinemachine.CinemachineVirtualCamera _virtualCamera;
#elif MM_CINEMACHINE3
protected CinemachineBasicMultiChannelPerlin _perlin;
protected CinemachineCamera _virtualCamera;
#endif
protected float _targetAmplitude;
protected float _targetFrequency;
private Coroutine _shakeCoroutine;
/// <summary>
/// On awake we grab our components
/// </summary>
protected virtual void Awake()
{
#if MM_CINEMACHINE
_virtualCamera = this.gameObject.GetComponent<CinemachineVirtualCamera>();
_perlin = _virtualCamera.GetCinemachineComponent<Cinemachine.CinemachineBasicMultiChannelPerlin>();
#elif MM_CINEMACHINE3
_virtualCamera = this.gameObject.GetComponent<CinemachineCamera>();
_perlin = _virtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Noise) as CinemachineBasicMultiChannelPerlin;
#endif
}
/// <summary>
/// On Start we reset our camera to apply our base amplitude and frequency
/// </summary>
protected virtual void Start()
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
if (_perlin != null)
{
#if MM_CINEMACHINE
IdleAmplitude = _perlin.m_AmplitudeGain;
IdleFrequency = _perlin.m_FrequencyGain;
#elif MM_CINEMACHINE3
IdleAmplitude = _perlin.AmplitudeGain;
IdleFrequency = _perlin.FrequencyGain;
#endif
}
#endif
_targetAmplitude = IdleAmplitude;
_targetFrequency = IdleFrequency;
}
protected virtual void Update()
{
#if MM_CINEMACHINE
if (_perlin != null)
{
_perlin.m_AmplitudeGain = _targetAmplitude;
_perlin.m_FrequencyGain = Mathf.Lerp(_perlin.m_FrequencyGain, _targetFrequency, GetDeltaTime() * LerpSpeed);
}
#elif MM_CINEMACHINE3
if (_perlin != null)
{
_perlin.AmplitudeGain = _targetAmplitude;
_perlin.FrequencyGain = Mathf.Lerp(_perlin.FrequencyGain, _targetFrequency, GetDeltaTime() * LerpSpeed);
}
#endif
}
/// <summary>
/// Use this method to shake the camera for the specified duration (in seconds) with the default amplitude and frequency
/// </summary>
/// <param name="duration">Duration.</param>
public virtual void ShakeCamera(float duration, bool infinite, bool useUnscaledTime = false)
{
StartCoroutine(ShakeCameraCo(duration, DefaultShakeAmplitude, DefaultShakeFrequency, infinite, useUnscaledTime));
}
/// <summary>
/// Use this method to shake the camera for the specified duration (in seconds), amplitude and frequency
/// </summary>
/// <param name="duration">Duration.</param>
/// <param name="amplitude">Amplitude.</param>
/// <param name="frequency">Frequency.</param>
public virtual void ShakeCamera(float duration, float amplitude, float frequency, bool infinite, bool useUnscaledTime = false)
{
if (_shakeCoroutine != null)
{
StopCoroutine(_shakeCoroutine);
}
_shakeCoroutine = StartCoroutine(ShakeCameraCo(duration, amplitude, frequency, infinite, useUnscaledTime));
}
/// <summary>
/// This coroutine will shake the
/// </summary>
/// <returns>The camera co.</returns>
/// <param name="duration">Duration.</param>
/// <param name="amplitude">Amplitude.</param>
/// <param name="frequency">Frequency.</param>
protected virtual IEnumerator ShakeCameraCo(float duration, float amplitude, float frequency, bool infinite, bool useUnscaledTime)
{
_targetAmplitude = amplitude;
_targetFrequency = frequency;
_timescaleMode = useUnscaledTime ? TimescaleModes.Unscaled : TimescaleModes.Scaled;
if (!infinite)
{
yield return MMCoroutine.WaitFor(duration);
CameraReset();
}
}
/// <summary>
/// Resets the camera's noise values to their idle values
/// </summary>
public virtual void CameraReset()
{
_targetAmplitude = IdleAmplitude;
_targetFrequency = IdleFrequency;
}
public virtual void OnCameraShakeEvent(float duration, float amplitude, float frequency, float amplitudeX, float amplitudeY, float amplitudeZ, bool infinite, MMChannelData channelData, bool useUnscaledTime)
{
if (!MMChannel.Match(channelData, ChannelMode, Channel, MMChannelDefinition))
{
return;
}
this.ShakeCamera(duration, amplitude, frequency, infinite, useUnscaledTime);
}
public virtual void OnCameraShakeStopEvent(MMChannelData channelData)
{
if (!MMChannel.Match(channelData, ChannelMode, Channel, MMChannelDefinition))
{
return;
}
if (_shakeCoroutine != null)
{
StopCoroutine(_shakeCoroutine);
}
CameraReset();
}
protected virtual void OnEnable()
{
MMCameraShakeEvent.Register(OnCameraShakeEvent);
MMCameraShakeStopEvent.Register(OnCameraShakeStopEvent);
}
protected virtual void OnDisable()
{
MMCameraShakeEvent.Unregister(OnCameraShakeEvent);
MMCameraShakeStopEvent.Unregister(OnCameraShakeStopEvent);
}
protected virtual void TestShake()
{
MMCameraShakeEvent.Trigger(TestDuration, TestAmplitude, TestFrequency, 0f, 0f, 0f, false, new MMChannelData(ChannelMode, Channel, MMChannelDefinition));
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9d66462bf720d28469c8db4b2e52720c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachineCameraShaker.cs
uploadId: 830868

View File

@@ -0,0 +1,233 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// Add this to a Cinemachine virtual camera and it'll let you control its near and far clipping planes
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Clipping Planes Shaker")]
#if MM_CINEMACHINE
[RequireComponent(typeof(CinemachineVirtualCamera))]
#elif MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineCamera))]
#endif
public class MMCinemachineClippingPlanesShaker : MMShaker
{
[MMInspectorGroup("Clipping Planes", true, 45)]
/// whether or not to add to the initial value
public bool RelativeClippingPlanes = false;
[MMInspectorGroup("Near Plane", true, 46)]
/// the curve used to animate the intensity value on
[Tooltip("the curve used to animate the intensity value on")]
public AnimationCurve ShakeNear = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
/// the value to remap the curve's 0 to
[Tooltip("the value to remap the curve's 0 to")]
public float RemapNearZero = 0.3f;
/// the value to remap the curve's 1 to
[Tooltip("the value to remap the curve's 1 to")]
public float RemapNearOne = 100f;
[MMInspectorGroup("Far Plane", true, 47)]
/// the curve used to animate the intensity value on
[Tooltip("the curve used to animate the intensity value on")]
public AnimationCurve ShakeFar = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
/// the value to remap the curve's 0 to
[Tooltip("the value to remap the curve's 0 to")]
public float RemapFarZero = 1000f;
/// the value to remap the curve's 1 to
[Tooltip("the value to remap the curve's 1 to")]
public float RemapFarOne = 1000f;
#if MM_CINEMACHINE
protected CinemachineVirtualCamera _targetCamera;
#elif MM_CINEMACHINE3
protected CinemachineCamera _targetCamera;
#endif
protected float _initialNear;
protected float _initialFar;
protected float _originalShakeDuration;
protected bool _originalRelativeClippingPlanes;
protected AnimationCurve _originalShakeNear;
protected float _originalRemapNearZero;
protected float _originalRemapNearOne;
protected AnimationCurve _originalShakeFar;
protected float _originalRemapFarZero;
protected float _originalRemapFarOne;
/// <summary>
/// On init we initialize our values
/// </summary>
protected override void Initialization()
{
base.Initialization();
#if MM_CINEMACHINE
_targetCamera = this.gameObject.GetComponent<CinemachineVirtualCamera>();
#elif MM_CINEMACHINE3
_targetCamera = this.gameObject.GetComponent<CinemachineCamera>();
#endif
}
/// <summary>
/// When that shaker gets added, we initialize its shake duration
/// </summary>
protected virtual void Reset()
{
ShakeDuration = 0.5f;
}
/// <summary>
/// Shakes values over time
/// </summary>
protected override void Shake()
{
float newNear = ShakeFloat(ShakeNear, RemapNearZero, RemapNearOne, RelativeClippingPlanes, _initialNear);
float newFar = ShakeFloat(ShakeFar, RemapFarZero, RemapFarOne, RelativeClippingPlanes, _initialFar);
SetNearFar(newNear, newFar);
}
protected virtual void SetNearFar(float near, float far)
{
#if MM_CINEMACHINE
_targetCamera.m_Lens.NearClipPlane = near;
_targetCamera.m_Lens.FarClipPlane = far;
#elif MM_CINEMACHINE3
_targetCamera.Lens.NearClipPlane = near;
_targetCamera.Lens.FarClipPlane = far;
#endif
}
/// <summary>
/// Collects initial values on the target
/// </summary>
protected override void GrabInitialValues()
{
#if MM_CINEMACHINE
_initialNear = _targetCamera.m_Lens.NearClipPlane;
_initialFar = _targetCamera.m_Lens.FarClipPlane;
#elif MM_CINEMACHINE3
_initialNear = _targetCamera.Lens.NearClipPlane;
_initialFar = _targetCamera.Lens.FarClipPlane;
#endif
}
/// <summary>
/// When we get the appropriate event, we trigger a shake
/// </summary>
/// <param name="distortionCurve"></param>
/// <param name="duration"></param>
/// <param name="amplitude"></param>
/// <param name="relativeDistortion"></param>
/// <param name="feedbacksIntensity"></param>
/// <param name="channel"></param>
public virtual void OnMMCameraClippingPlanesShakeEvent(AnimationCurve animNearCurve, float duration, float remapNearMin, float remapNearMax, AnimationCurve animFarCurve, float remapFarMin, float remapFarMax, bool relativeValues = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false)
{
if (!CheckEventAllowed(channelData))
{
return;
}
if (stop)
{
Stop();
return;
}
if (restore)
{
ResetTargetValues();
return;
}
if (!Interruptible && Shaking)
{
return;
}
_resetShakerValuesAfterShake = resetShakerValuesAfterShake;
_resetTargetValuesAfterShake = resetTargetValuesAfterShake;
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
_originalShakeNear = ShakeNear;
_originalShakeFar = ShakeFar;
_originalRemapNearZero = RemapNearZero;
_originalRemapNearOne = RemapNearOne;
_originalRemapFarZero = RemapFarZero;
_originalRemapFarOne = RemapFarOne;
_originalRelativeClippingPlanes = RelativeClippingPlanes;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
ShakeNear = animNearCurve;
RemapNearZero = remapNearMin * feedbacksIntensity;
RemapNearOne = remapNearMax * feedbacksIntensity;
ShakeFar = animFarCurve;
RemapFarZero = remapFarMin * feedbacksIntensity;
RemapFarOne = remapFarMax * feedbacksIntensity;
RelativeClippingPlanes = relativeValues;
ForwardDirection = forwardDirection;
}
Play();
}
/// <summary>
/// Resets the target's values
/// </summary>
protected override void ResetTargetValues()
{
base.ResetTargetValues();
SetNearFar(_initialNear, _initialFar);
}
/// <summary>
/// Resets the shaker's values
/// </summary>
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
ShakeNear = _originalShakeNear;
ShakeFar = _originalShakeFar;
RemapNearZero = _originalRemapNearZero;
RemapNearOne = _originalRemapNearOne;
RemapFarZero = _originalRemapFarZero;
RemapFarOne = _originalRemapFarOne;
RelativeClippingPlanes = _originalRelativeClippingPlanes;
}
/// <summary>
/// Starts listening for events
/// </summary>
public override void StartListening()
{
base.StartListening();
MMCameraClippingPlanesShakeEvent.Register(OnMMCameraClippingPlanesShakeEvent);
}
/// <summary>
/// Stops listening for events
/// </summary>
public override void StopListening()
{
base.StopListening();
MMCameraClippingPlanesShakeEvent.Unregister(OnMMCameraClippingPlanesShakeEvent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9ff80f834f6ca564da816a2f08bc75f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachineClippingPlanesShaker.cs
uploadId: 830868

View File

@@ -0,0 +1,203 @@
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// Add this to a Cinemachine virtual camera and it'll let you control its field of view over time, can be piloted by a MMFeedbackCameraFieldOfView
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Field Of View Shaker")]
#if MM_CINEMACHINE
[RequireComponent(typeof(CinemachineVirtualCamera))]
#elif MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineCamera))]
#endif
public class MMCinemachineFieldOfViewShaker : MMShaker
{
[MMInspectorGroup("Field of view", true, 41)]
/// whether or not to add to the initial value
[Tooltip("whether or not to add to the initial value")]
public bool RelativeFieldOfView = false;
/// the curve used to animate the intensity value on
[Tooltip("the curve used to animate the intensity value on")]
public AnimationCurve ShakeFieldOfView = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
/// the value to remap the curve's 0 to
[Tooltip("the value to remap the curve's 0 to")]
[Range(0f, 179f)]
public float RemapFieldOfViewZero = 60f;
/// the value to remap the curve's 1 to
[Tooltip("the value to remap the curve's 1 to")]
[Range(0f, 179f)]
public float RemapFieldOfViewOne = 120f;
#if MM_CINEMACHINE
protected CinemachineVirtualCamera _targetCamera;
#elif MM_CINEMACHINE3
protected CinemachineCamera _targetCamera;
#endif
protected float _initialFieldOfView;
protected float _originalShakeDuration;
protected bool _originalRelativeFieldOfView;
protected AnimationCurve _originalShakeFieldOfView;
protected float _originalRemapFieldOfViewZero;
protected float _originalRemapFieldOfViewOne;
/// <summary>
/// On init we initialize our values
/// </summary>
protected override void Initialization()
{
base.Initialization();
#if MM_CINEMACHINE
_targetCamera = this.gameObject.GetComponent<CinemachineVirtualCamera>();
#elif MM_CINEMACHINE3
_targetCamera = this.gameObject.GetComponent<CinemachineCamera>();
#endif
}
/// <summary>
/// When that shaker gets added, we initialize its shake duration
/// </summary>
protected virtual void Reset()
{
ShakeDuration = 0.5f;
}
/// <summary>
/// Shakes values over time
/// </summary>
protected override void Shake()
{
float newFieldOfView = ShakeFloat(ShakeFieldOfView, RemapFieldOfViewZero, RemapFieldOfViewOne, RelativeFieldOfView, _initialFieldOfView);
SetFieldOfView(newFieldOfView);
}
protected virtual void SetFieldOfView(float newFieldOfView)
{
#if MM_CINEMACHINE
_targetCamera.m_Lens.FieldOfView = newFieldOfView;
#elif MM_CINEMACHINE3
_targetCamera.Lens.FieldOfView = newFieldOfView;
#endif
}
/// <summary>
/// Collects initial values on the target
/// </summary>
protected override void GrabInitialValues()
{
#if MM_CINEMACHINE
_initialFieldOfView = _targetCamera.m_Lens.FieldOfView;
#elif MM_CINEMACHINE3
_initialFieldOfView = _targetCamera.Lens.FieldOfView;
#endif
}
/// <summary>
/// When we get the appropriate event, we trigger a shake
/// </summary>
/// <param name="distortionCurve"></param>
/// <param name="duration"></param>
/// <param name="amplitude"></param>
/// <param name="relativeDistortion"></param>
/// <param name="feedbacksIntensity"></param>
/// <param name="channel"></param>
public virtual void OnMMCameraFieldOfViewShakeEvent(AnimationCurve distortionCurve, float duration, float remapMin, float remapMax, bool relativeDistortion = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false)
{
if (!CheckEventAllowed(channelData))
{
return;
}
if (stop)
{
Stop();
return;
}
if (restore)
{
ResetTargetValues();
return;
}
if (!Interruptible && Shaking)
{
return;
}
_resetShakerValuesAfterShake = resetShakerValuesAfterShake;
_resetTargetValuesAfterShake = resetTargetValuesAfterShake;
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
_originalShakeFieldOfView = ShakeFieldOfView;
_originalRemapFieldOfViewZero = RemapFieldOfViewZero;
_originalRemapFieldOfViewOne = RemapFieldOfViewOne;
_originalRelativeFieldOfView = RelativeFieldOfView;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
ShakeFieldOfView = distortionCurve;
RemapFieldOfViewZero = remapMin * feedbacksIntensity;
RemapFieldOfViewOne = remapMax * feedbacksIntensity;
RelativeFieldOfView = relativeDistortion;
ForwardDirection = forwardDirection;
}
Play();
}
/// <summary>
/// Resets the target's values
/// </summary>
protected override void ResetTargetValues()
{
base.ResetTargetValues();
SetFieldOfView(_initialFieldOfView);
}
/// <summary>
/// Resets the shaker's values
/// </summary>
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
ShakeFieldOfView = _originalShakeFieldOfView;
RemapFieldOfViewZero = _originalRemapFieldOfViewZero;
RemapFieldOfViewOne = _originalRemapFieldOfViewOne;
RelativeFieldOfView = _originalRelativeFieldOfView;
}
/// <summary>
/// Starts listening for events
/// </summary>
public override void StartListening()
{
base.StartListening();
MMCameraFieldOfViewShakeEvent.Register(OnMMCameraFieldOfViewShakeEvent);
}
/// <summary>
/// Stops listening for events
/// </summary>
public override void StopListening()
{
base.StopListening();
MMCameraFieldOfViewShakeEvent.Unregister(OnMMCameraFieldOfViewShakeEvent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d68394ff0deaba948873307b5fe5a801
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachineFieldOfViewShaker.cs
uploadId: 830868

View File

@@ -0,0 +1,257 @@
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// This class will allow you to trigger zooms on your cinemachine camera by sending MMCameraZoomEvents from any other class
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Free Look Zoom")]
#if MM_CINEMACHINE
[RequireComponent(typeof(Cinemachine.CinemachineFreeLook))]
#elif MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineCamera))]
#endif
public class MMCinemachineFreeLookZoom : MonoBehaviour
{
[Header("Channel")]
[MMFInspectorGroup("Shaker Settings", true, 3)]
/// whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what.
/// MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable
[Tooltip("whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what. " +
"MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable")]
public MMChannelModes ChannelMode = MMChannelModes.Int;
/// the channel to listen to - has to match the one on the feedback
[Tooltip("the channel to listen to - has to match the one on the feedback")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.Int)]
public int Channel = 0;
/// the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel,
/// right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name
[Tooltip("the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel, " +
"right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.MMChannel)]
public MMChannel MMChannelDefinition = null;
[Header("Transition Speed")]
/// the animation curve to apply to the zoom transition
[Tooltip("the animation curve to apply to the zoom transition")]
public MMTweenType ZoomTween = new MMTweenType( new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 1f)));
[Header("Test Zoom")]
/// the mode to apply the zoom in when using the test button in the inspector
[Tooltip("the mode to apply the zoom in when using the test button in the inspector")]
public MMCameraZoomModes TestMode;
/// the target field of view to apply the zoom in when using the test button in the inspector
[Tooltip("the target field of view to apply the zoom in when using the test button in the inspector")]
public float TestFieldOfView = 30f;
/// the transition duration to apply the zoom in when using the test button in the inspector
[Tooltip("the transition duration to apply the zoom in when using the test button in the inspector")]
public float TestTransitionDuration = 0.1f;
/// the duration to apply the zoom in when using the test button in the inspector
[Tooltip("the duration to apply the zoom in when using the test button in the inspector")]
public float TestDuration = 0.05f;
[MMFInspectorButton("TestZoom")]
/// an inspector button to test the zoom in play mode
public bool TestZoomButton;
public virtual float GetTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime; }
public virtual float GetDeltaTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; }
public virtual TimescaleModes TimescaleMode { get; set; }
#if MM_CINEMACHINE
protected Cinemachine.CinemachineFreeLook _freeLookCamera;
#elif MM_CINEMACHINE3
protected CinemachineCamera _freeLookCamera;
#endif
protected float _initialFieldOfView;
protected MMCameraZoomModes _mode;
protected bool _zooming = false;
protected float _startFieldOfView;
protected float _transitionDuration;
protected float _duration;
protected float _targetFieldOfView;
protected float _delta = 0f;
protected int _direction = 1;
protected float _reachedDestinationTimestamp;
protected bool _destinationReached = false;
protected float _elapsedTime = 0f;
protected float _zoomStartedAt = 0f;
/// <summary>
/// On Awake we grab our virtual camera
/// </summary>
protected virtual void Awake()
{
#if MM_CINEMACHINE
_freeLookCamera = this.gameObject.GetComponent<Cinemachine.CinemachineFreeLook>();
_initialFieldOfView = _freeLookCamera.m_Lens.FieldOfView;
#elif MM_CINEMACHINE3
_freeLookCamera = this.gameObject.GetComponent<CinemachineCamera>();
_initialFieldOfView = _freeLookCamera.Lens.FieldOfView;
#endif
}
/// <summary>
/// On Update if we're zooming we modify our field of view accordingly
/// </summary>
protected virtual void Update()
{
if (!_zooming)
{
return;
}
_elapsedTime = GetTime() - _zoomStartedAt;
if (_elapsedTime <= _transitionDuration)
{
float t = MMMaths.Remap(_elapsedTime, 0f, _transitionDuration, 0f, 1f);
#if MM_CINEMACHINE
_freeLookCamera.m_Lens.FieldOfView = Mathf.LerpUnclamped(_startFieldOfView, _targetFieldOfView, ZoomTween.Evaluate(t));
#elif MM_CINEMACHINE3
_freeLookCamera.Lens.FieldOfView = Mathf.LerpUnclamped(_startFieldOfView, _targetFieldOfView, ZoomTween.Evaluate(t));
#endif
}
else
{
if (!_destinationReached)
{
_reachedDestinationTimestamp = GetTime();
_destinationReached = true;
}
if ((_mode == MMCameraZoomModes.For) && (_direction == 1))
{
if (GetTime() - _reachedDestinationTimestamp > _duration)
{
_direction = -1;
_zoomStartedAt = GetTime();
_startFieldOfView = _targetFieldOfView;
_targetFieldOfView = _initialFieldOfView;
}
}
else
{
_zooming = false;
}
}
}
/// <summary>
/// A method that triggers the zoom, ideally only to be called via an event, but public for convenience
/// </summary>
/// <param name="mode"></param>
/// <param name="newFieldOfView"></param>
/// <param name="transitionDuration"></param>
/// <param name="duration"></param>
public virtual void Zoom(MMCameraZoomModes mode, float newFieldOfView, float transitionDuration,
float duration, bool relative = false, MMTweenType tweenType = null)
{
if (_zooming)
{
return;
}
_zooming = true;
_elapsedTime = 0f;
_mode = mode;
#if MM_CINEMACHINE
_startFieldOfView = _freeLookCamera.m_Lens.FieldOfView;
#elif MM_CINEMACHINE3
_startFieldOfView = _freeLookCamera.Lens.FieldOfView;
#endif
_transitionDuration = transitionDuration;
_duration = duration;
_transitionDuration = transitionDuration;
_direction = 1;
_destinationReached = false;
_zoomStartedAt = GetTime();
if (tweenType != null)
{
ZoomTween = tweenType;
}
switch (mode)
{
case MMCameraZoomModes.For:
_targetFieldOfView = newFieldOfView;
break;
case MMCameraZoomModes.Set:
_targetFieldOfView = newFieldOfView;
break;
case MMCameraZoomModes.Reset:
_targetFieldOfView = _initialFieldOfView;
break;
}
if (relative)
{
_targetFieldOfView += _initialFieldOfView;
}
}
/// <summary>
/// The method used by the test button to trigger a test zoom
/// </summary>
protected virtual void TestZoom()
{
Zoom(TestMode, TestFieldOfView, TestTransitionDuration, TestDuration);
}
/// <summary>
/// When we get an MMCameraZoomEvent we call our zoom method
/// </summary>
/// <param name="zoomEvent"></param>
public virtual void OnCameraZoomEvent(MMCameraZoomModes mode, float newFieldOfView, float transitionDuration, float duration,
MMChannelData channelData, bool useUnscaledTime, bool stop = false, bool relative = false, bool restore = false, MMTweenType tweenType = null)
{
if (!MMChannel.Match(channelData, ChannelMode, Channel, MMChannelDefinition))
{
return;
}
if (stop)
{
_zooming = false;
return;
}
if (restore)
{
#if MM_CINEMACHINE
_freeLookCamera.m_Lens.FieldOfView = _initialFieldOfView;
#elif MM_CINEMACHINE3
_freeLookCamera.Lens.FieldOfView = _initialFieldOfView;
#endif
return;
}
this.Zoom(mode, newFieldOfView, transitionDuration, duration, relative, tweenType);
}
/// <summary>
/// Starts listening for MMCameraZoomEvents
/// </summary>
protected virtual void OnEnable()
{
MMCameraZoomEvent.Register(OnCameraZoomEvent);
}
/// <summary>
/// Stops listening for MMCameraZoomEvents
/// </summary>
protected virtual void OnDisable()
{
MMCameraZoomEvent.Unregister(OnCameraZoomEvent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c5c6086564eb2a44db13fc3cd3a66644
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachineFreeLookZoom.cs
uploadId: 830868

View File

@@ -0,0 +1,200 @@
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// Add this to a Cinemachine virtual camera and it'll let you control its orthographic size over time, can be piloted by a MMFeedbackCameraOrthographicSize
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Orthographic Size Shaker")]
#if MM_CINEMACHINE
[RequireComponent(typeof(CinemachineVirtualCamera))]
#elif MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineCamera))]
#endif
public class MMCinemachineOrthographicSizeShaker : MMShaker
{
[MMInspectorGroup("Orthographic Size", true, 43)]
/// whether or not to add to the initial value
[Tooltip("whether or not to add to the initial value")]
public bool RelativeOrthographicSize = false;
/// the curve used to animate the intensity value on
[Tooltip("the curve used to animate the intensity value on")]
public AnimationCurve ShakeOrthographicSize = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
/// the value to remap the curve's 0 to
[Tooltip("the value to remap the curve's 0 to")]
public float RemapOrthographicSizeZero = 5f;
/// the value to remap the curve's 1 to
[Tooltip("the value to remap the curve's 1 to")]
public float RemapOrthographicSizeOne = 10f;
#if MM_CINEMACHINE
protected CinemachineVirtualCamera _targetCamera;
#elif MM_CINEMACHINE3
protected CinemachineCamera _targetCamera;
#endif
protected float _initialOrthographicSize;
protected float _originalShakeDuration;
protected bool _originalRelativeOrthographicSize;
protected AnimationCurve _originalShakeOrthographicSize;
protected float _originalRemapOrthographicSizeZero;
protected float _originalRemapOrthographicSizeOne;
/// <summary>
/// On init we initialize our values
/// </summary>
protected override void Initialization()
{
base.Initialization();
#if MM_CINEMACHINE
_targetCamera = this.gameObject.GetComponent<CinemachineVirtualCamera>();
#elif MM_CINEMACHINE3
_targetCamera = this.gameObject.GetComponent<CinemachineCamera>();
#endif
}
/// <summary>
/// When that shaker gets added, we initialize its shake duration
/// </summary>
protected virtual void Reset()
{
ShakeDuration = 0.5f;
}
/// <summary>
/// Shakes values over time
/// </summary>
protected override void Shake()
{
float newOrthographicSize = ShakeFloat(ShakeOrthographicSize, RemapOrthographicSizeZero, RemapOrthographicSizeOne, RelativeOrthographicSize, _initialOrthographicSize);
#if MM_CINEMACHINE
_targetCamera.m_Lens.OrthographicSize = newOrthographicSize;
#elif MM_CINEMACHINE3
_targetCamera.Lens.OrthographicSize = newOrthographicSize;
#endif
}
/// <summary>
/// Collects initial values on the target
/// </summary>
protected override void GrabInitialValues()
{
#if MM_CINEMACHINE
_initialOrthographicSize = _targetCamera.m_Lens.OrthographicSize;
#elif MM_CINEMACHINE3
_initialOrthographicSize = _targetCamera.Lens.OrthographicSize;
#endif
}
/// <summary>
/// When we get the appropriate event, we trigger a shake
/// </summary>
/// <param name="distortionCurve"></param>
/// <param name="duration"></param>
/// <param name="amplitude"></param>
/// <param name="relativeDistortion"></param>
/// <param name="feedbacksIntensity"></param>
/// <param name="channel"></param>
public virtual void OnMMCameraOrthographicSizeShakeEvent(AnimationCurve distortionCurve, float duration, float remapMin, float remapMax, bool relativeDistortion = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false)
{
if (!CheckEventAllowed(channelData))
{
return;
}
if (stop)
{
Stop();
return;
}
if (restore)
{
ResetTargetValues();
return;
}
if (!Interruptible && Shaking)
{
return;
}
_resetShakerValuesAfterShake = resetShakerValuesAfterShake;
_resetTargetValuesAfterShake = resetTargetValuesAfterShake;
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
_originalShakeOrthographicSize = ShakeOrthographicSize;
_originalRemapOrthographicSizeZero = RemapOrthographicSizeZero;
_originalRemapOrthographicSizeOne = RemapOrthographicSizeOne;
_originalRelativeOrthographicSize = RelativeOrthographicSize;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
ShakeOrthographicSize = distortionCurve;
RemapOrthographicSizeZero = remapMin * feedbacksIntensity;
RemapOrthographicSizeOne = remapMax * feedbacksIntensity;
RelativeOrthographicSize = relativeDistortion;
ForwardDirection = forwardDirection;
}
Play();
}
/// <summary>
/// Resets the target's values
/// </summary>
protected override void ResetTargetValues()
{
base.ResetTargetValues();
#if MM_CINEMACHINE
_targetCamera.m_Lens.OrthographicSize = _initialOrthographicSize;
#elif MM_CINEMACHINE3
_targetCamera.Lens.OrthographicSize = _initialOrthographicSize;
#endif
}
/// <summary>
/// Resets the shaker's values
/// </summary>
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
ShakeOrthographicSize = _originalShakeOrthographicSize;
RemapOrthographicSizeZero = _originalRemapOrthographicSizeZero;
RemapOrthographicSizeOne = _originalRemapOrthographicSizeOne;
RelativeOrthographicSize = _originalRelativeOrthographicSize;
}
/// <summary>
/// Starts listening for events
/// </summary>
public override void StartListening()
{
base.StartListening();
MMCameraOrthographicSizeShakeEvent.Register(OnMMCameraOrthographicSizeShakeEvent);
}
/// <summary>
/// Stops listening for events
/// </summary>
public override void StopListening()
{
base.StopListening();
MMCameraOrthographicSizeShakeEvent.Unregister(OnMMCameraOrthographicSizeShakeEvent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 0aded04d7fa45744fb33cc0a43b0d6ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachineOrthographicSizeShaker.cs
uploadId: 830868

View File

@@ -0,0 +1,133 @@
using System.Collections;
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// Add this to a Cinemachine brain and it'll be able to accept custom blend transitions (used with MMFeedbackCinemachineTransition)
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Priority Brain Listener")]
#if MM_CINEMACHINE || MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineBrain))]
#endif
public class MMCinemachinePriorityBrainListener : MonoBehaviour
{
[HideInInspector]
public TimescaleModes TimescaleMode = TimescaleModes.Scaled;
public virtual float GetTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime; }
public virtual float GetDeltaTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; }
#if MM_CINEMACHINE || MM_CINEMACHINE3
protected CinemachineBrain _brain;
protected CinemachineBlendDefinition _initialDefinition;
#endif
protected Coroutine _coroutine;
/// <summary>
/// On Awake we grab our brain
/// </summary>
protected virtual void Awake()
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
_brain = this.gameObject.GetComponent<CinemachineBrain>();
#endif
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
/// <summary>
/// When getting an event we change our default transition if needed
/// </summary>
/// <param name="channel"></param>
/// <param name="forceMaxPriority"></param>
/// <param name="newPriority"></param>
/// <param name="forceTransition"></param>
/// <param name="blendDefinition"></param>
/// <param name="resetValuesAfterTransition"></param>
public virtual void OnMMCinemachinePriorityEvent(MMChannelData channelData, bool forceMaxPriority, int newPriority, bool forceTransition, CinemachineBlendDefinition blendDefinition, bool resetValuesAfterTransition, TimescaleModes timescaleMode, bool restore = false)
{
if (forceTransition)
{
if (_coroutine != null)
{
StopCoroutine(_coroutine);
}
else
{
#if MM_CINEMACHINE
_initialDefinition = _brain.m_DefaultBlend;
#elif MM_CINEMACHINE3
_initialDefinition = _brain.DefaultBlend;
#endif
}
#if MM_CINEMACHINE
_brain.m_DefaultBlend = blendDefinition;
#elif MM_CINEMACHINE3
_brain.DefaultBlend = blendDefinition;
#endif
TimescaleMode = timescaleMode;
#if MM_CINEMACHINE
_coroutine = StartCoroutine(ResetBlendDefinition(blendDefinition.m_Time));
#elif MM_CINEMACHINE3
_coroutine = StartCoroutine(ResetBlendDefinition(blendDefinition.Time));
#endif
}
}
#endif
/// <summary>
/// a coroutine used to reset the default transition to its initial value
/// </summary>
/// <param name="delay"></param>
/// <returns></returns>
protected virtual IEnumerator ResetBlendDefinition(float delay)
{
yield return null;
yield return null;
for (float timer = 0; timer < delay; timer += GetDeltaTime())
{
yield return null;
}
#if MM_CINEMACHINE
_brain.m_DefaultBlend = _initialDefinition;
#elif MM_CINEMACHINE3
_brain.DefaultBlend = _initialDefinition;
#endif
_coroutine = null;
}
/// <summary>
/// On enable we start listening for events
/// </summary>
protected virtual void OnEnable()
{
_coroutine = null;
#if MM_CINEMACHINE || MM_CINEMACHINE3
MMCinemachinePriorityEvent.Register(OnMMCinemachinePriorityEvent);
#endif
}
/// <summary>
/// Stops listening for events
/// </summary>
protected virtual void OnDisable()
{
if (_coroutine != null)
{
StopCoroutine(_coroutine);
}
_coroutine = null;
#if MM_CINEMACHINE || MM_CINEMACHINE3
MMCinemachinePriorityEvent.Unregister(OnMMCinemachinePriorityEvent);
#endif
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2436c2ba147129746badf6cfa2ee2d1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachinePriorityBrainListener.cs
uploadId: 830868

View File

@@ -0,0 +1,158 @@
using System.Collections;
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// Add this to a Cinemachine virtual camera and it'll be able to listen to MMCinemachinePriorityEvent, usually triggered by a MMFeedbackCinemachineTransition
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Priority Listener")]
#if MM_CINEMACHINE || MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineVirtualCameraBase))]
#endif
public class MMCinemachinePriorityListener : MonoBehaviour
{
[HideInInspector]
public TimescaleModes TimescaleMode = TimescaleModes.Scaled;
public virtual float GetTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime; }
public virtual float GetDeltaTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; }
[Header("Priority Listener")]
[Tooltip("whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what. " +
"MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable")]
public MMChannelModes ChannelMode = MMChannelModes.Int;
/// the channel to listen to - has to match the one on the feedback
[Tooltip("the channel to listen to - has to match the one on the feedback")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.Int)]
public int Channel = 0;
/// the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel,
/// right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name
[Tooltip("the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel, " +
"right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.MMChannel)]
public MMChannel MMChannelDefinition = null;
#if MM_CINEMACHINE || MM_CINEMACHINE3
protected CinemachineVirtualCameraBase _camera;
protected int _initialPriority;
#endif
/// <summary>
/// On Awake we store our virtual camera
/// </summary>
protected virtual void Awake()
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
_camera = this.gameObject.GetComponent<CinemachineVirtualCameraBase>();
#endif
#if MM_CINEMACHINE
_initialPriority = _camera.Priority;
#elif MM_CINEMACHINE3
_initialPriority = _camera.Priority.Value;
#endif
}
#if MM_CINEMACHINE || MM_CINEMACHINE3
/// <summary>
/// When we get an event we change our priorities if needed
/// </summary>
/// <param name="channel"></param>
/// <param name="forceMaxPriority"></param>
/// <param name="newPriority"></param>
/// <param name="forceTransition"></param>
/// <param name="blendDefinition"></param>
/// <param name="resetValuesAfterTransition"></param>
public virtual void OnMMCinemachinePriorityEvent(MMChannelData channelData, bool forceMaxPriority, int newPriority, bool forceTransition, CinemachineBlendDefinition blendDefinition, bool resetValuesAfterTransition, TimescaleModes timescaleMode, bool restore = false)
{
StartCoroutine(OnMMCinemachinePriorityEventCo(channelData, forceMaxPriority, newPriority, forceTransition,
blendDefinition, resetValuesAfterTransition, timescaleMode, restore));
}
protected virtual IEnumerator OnMMCinemachinePriorityEventCo(MMChannelData channelData, bool forceMaxPriority, int newPriority, bool forceTransition, CinemachineBlendDefinition blendDefinition, bool resetValuesAfterTransition, TimescaleModes timescaleMode, bool restore = false)
{
yield return null;
TimescaleMode = timescaleMode;
if (MMChannel.Match(channelData, ChannelMode, Channel, MMChannelDefinition))
{
if (restore)
{
SetPriority(_initialPriority);
yield break;
}
SetPriority(newPriority);
}
else
{
if (forceMaxPriority)
{
if (restore)
{
SetPriority(_initialPriority);
yield break;;
}
SetPriority(0);
}
}
}
#endif
protected virtual void SetPriority(int newPriority)
{
#if MM_CINEMACHINE
_camera.Priority = newPriority;
#elif MM_CINEMACHINE3
PrioritySettings prioritySettings = _camera.Priority;
prioritySettings.Value = newPriority;
_camera.Priority = prioritySettings;
#endif
}
/// <summary>
/// On enable we start listening for events
/// </summary>
protected virtual void OnEnable()
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
MMCinemachinePriorityEvent.Register(OnMMCinemachinePriorityEvent);
#endif
}
/// <summary>
/// Stops listening for events
/// </summary>
protected virtual void OnDisable()
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
MMCinemachinePriorityEvent.Unregister(OnMMCinemachinePriorityEvent);
#endif
}
}
/// <summary>
/// An event used to pilot priorities on cinemachine virtual cameras and brain transitions
/// </summary>
public struct MMCinemachinePriorityEvent
{
#if MM_CINEMACHINE || MM_CINEMACHINE3
static private event Delegate OnEvent;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] private static void RuntimeInitialization() { OnEvent = null; }
static public void Register(Delegate callback) { OnEvent += callback; }
static public void Unregister(Delegate callback) { OnEvent -= callback; }
public delegate void Delegate(MMChannelData channelData, bool forceMaxPriority, int newPriority, bool forceTransition, CinemachineBlendDefinition blendDefinition, bool resetValuesAfterTransition, TimescaleModes timescaleMode, bool restore = false);
static public void Trigger(MMChannelData channelData, bool forceMaxPriority, int newPriority, bool forceTransition, CinemachineBlendDefinition blendDefinition, bool resetValuesAfterTransition, TimescaleModes timescaleMode, bool restore = false)
{
OnEvent?.Invoke(channelData, forceMaxPriority, newPriority, forceTransition, blendDefinition, resetValuesAfterTransition, timescaleMode, restore);
}
#endif
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f8650a79a9f5e38449718559d1d6a2f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachinePriorityListener.cs
uploadId: 830868

View File

@@ -0,0 +1,245 @@
using UnityEngine;
#if MM_CINEMACHINE
using Cinemachine;
#elif MM_CINEMACHINE3
using Unity.Cinemachine;
#endif
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// This class will allow you to trigger zooms on your cinemachine camera by sending MMCameraZoomEvents from any other class
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/Cinemachine/MM Cinemachine Zoom")]
#if MM_CINEMACHINE
[RequireComponent(typeof(Cinemachine.CinemachineVirtualCamera))]
#elif MM_CINEMACHINE3
[RequireComponent(typeof(CinemachineCamera))]
#endif
public class MMCinemachineZoom : MonoBehaviour
{
[Header("Channel")]
[MMFInspectorGroup("Shaker Settings", true, 3)]
/// whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what.
/// MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable
[Tooltip("whether to listen on a channel defined by an int or by a MMChannel scriptable object. Ints are simple to setup but can get messy and make it harder to remember what int corresponds to what. " +
"MMChannel scriptable objects require you to create them in advance, but come with a readable name and are more scalable")]
public MMChannelModes ChannelMode = MMChannelModes.Int;
/// the channel to listen to - has to match the one on the feedback
[Tooltip("the channel to listen to - has to match the one on the feedback")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.Int)]
public int Channel = 0;
/// the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel,
/// right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name
[Tooltip("the MMChannel definition asset to use to listen for events. The feedbacks targeting this shaker will have to reference that same MMChannel definition to receive events - to create a MMChannel, " +
"right click anywhere in your project (usually in a Data folder) and go MoreMountains > MMChannel, then name it with some unique name")]
[MMFEnumCondition("ChannelMode", (int)MMChannelModes.MMChannel)]
public MMChannel MMChannelDefinition = null;
/// if this is true, triggering a new zoom event will interrupt any transition that may be in progress
[Tooltip("if this is true, triggering a new zoom event will interrupt any transition that may be in progress")]
public bool Interruptable = false;
[Header("Transition Speed")]
/// the animation curve to apply to the zoom transition
[Tooltip("the animation curve to apply to the zoom transition")]
public MMTweenType ZoomTween = new MMTweenType( new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 1f)));
[Header("Test Zoom")]
/// the mode to apply the zoom in when using the test button in the inspector
[Tooltip("the mode to apply the zoom in when using the test button in the inspector")]
public MMCameraZoomModes TestMode;
/// the target field of view to apply the zoom in when using the test button in the inspector
[Tooltip("the target field of view to apply the zoom in when using the test button in the inspector")]
public float TestFieldOfView = 30f;
/// the transition duration to apply the zoom in when using the test button in the inspector
[Tooltip("the transition duration to apply the zoom in when using the test button in the inspector")]
public float TestTransitionDuration = 0.1f;
/// the duration to apply the zoom in when using the test button in the inspector
[Tooltip("the duration to apply the zoom in when using the test button in the inspector")]
public float TestDuration = 0.05f;
[MMFInspectorButton("TestZoom")]
/// an inspector button to test the zoom in play mode
public bool TestZoomButton;
public virtual float GetTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime; }
public virtual float GetDeltaTime() { return (TimescaleMode == TimescaleModes.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; }
public virtual TimescaleModes TimescaleMode { get; set; }
#if MM_CINEMACHINE
protected Cinemachine.CinemachineVirtualCamera _virtualCamera;
#elif MM_CINEMACHINE3
protected CinemachineCamera _virtualCamera;
#endif
protected float _initialFieldOfView;
protected MMCameraZoomModes _mode;
protected float _startFieldOfView;
protected float _transitionDuration;
protected float _duration;
protected float _targetFieldOfView;
protected float _elapsedTime = 0f;
protected int _direction = 1;
protected float _reachedDestinationTimestamp;
protected bool _destinationReached = false;
protected float _zoomStartedAt = 0f;
/// <summary>
/// On Awake we grab our virtual camera
/// </summary>
protected virtual void Awake()
{
#if MM_CINEMACHINE
_virtualCamera = this.gameObject.GetComponent<Cinemachine.CinemachineVirtualCamera>();
_initialFieldOfView = _virtualCamera.m_Lens.FieldOfView;
#elif MM_CINEMACHINE3
_virtualCamera = this.gameObject.GetComponent<CinemachineCamera>();
_initialFieldOfView = _virtualCamera.Lens.FieldOfView;
#endif
MMCameraZoomEvent.Register(OnCameraZoomEvent);
this.enabled = false;
}
/// <summary>
/// On Update if we're zooming we modify our field of view accordingly
/// </summary>
protected virtual void Update()
{
_elapsedTime = GetTime() - _zoomStartedAt;
if (_elapsedTime <= _transitionDuration)
{
float t = MMMaths.Remap(_elapsedTime, 0f, _transitionDuration, 0f, 1f);
#if MM_CINEMACHINE
_virtualCamera.m_Lens.FieldOfView = Mathf.LerpUnclamped(_startFieldOfView, _targetFieldOfView, ZoomTween.Evaluate(t));
#elif MM_CINEMACHINE3
_virtualCamera.Lens.FieldOfView = Mathf.LerpUnclamped(_startFieldOfView, _targetFieldOfView, ZoomTween.Evaluate(t));
#endif
}
else
{
if (!_destinationReached)
{
_reachedDestinationTimestamp = GetTime();
_destinationReached = true;
}
if ((_mode == MMCameraZoomModes.For) && (_direction == 1))
{
if (GetTime() - _reachedDestinationTimestamp > _duration)
{
_direction = -1;
_zoomStartedAt = GetTime();
_startFieldOfView = _targetFieldOfView;
_targetFieldOfView = _initialFieldOfView;
}
}
else
{
this.enabled = false;
}
}
}
/// <summary>
/// A method that triggers the zoom, ideally only to be called via an event, but public for convenience
/// </summary>
/// <param name="mode"></param>
/// <param name="newFieldOfView"></param>
/// <param name="transitionDuration"></param>
/// <param name="duration"></param>
public virtual void Zoom(MMCameraZoomModes mode, float newFieldOfView, float transitionDuration, float duration, bool useUnscaledTime, bool relative = false, MMTweenType tweenType = null)
{
if (this.enabled && !Interruptable)
{
return;
}
this.enabled = true;
_elapsedTime = 0f;
_mode = mode;
TimescaleMode = useUnscaledTime ? TimescaleModes.Unscaled : TimescaleModes.Scaled;
#if MM_CINEMACHINE
_startFieldOfView = _virtualCamera.m_Lens.FieldOfView;
#elif MM_CINEMACHINE3
_startFieldOfView = _virtualCamera.Lens.FieldOfView;
#endif
_transitionDuration = transitionDuration;
_duration = duration;
_transitionDuration = transitionDuration;
_direction = 1;
_destinationReached = false;
_zoomStartedAt = GetTime();
if (tweenType != null)
{
ZoomTween = tweenType;
}
switch (mode)
{
case MMCameraZoomModes.For:
_targetFieldOfView = newFieldOfView;
break;
case MMCameraZoomModes.Set:
_targetFieldOfView = newFieldOfView;
break;
case MMCameraZoomModes.Reset:
_targetFieldOfView = _initialFieldOfView;
break;
}
if (relative)
{
_targetFieldOfView += _initialFieldOfView;
}
}
/// <summary>
/// The method used by the test button to trigger a test zoom
/// </summary>
protected virtual void TestZoom()
{
Zoom(TestMode, TestFieldOfView, TestTransitionDuration, TestDuration, false);
}
/// <summary>
/// When we get an MMCameraZoomEvent we call our zoom method
/// </summary>
/// <param name="zoomEvent"></param>
public virtual void OnCameraZoomEvent(MMCameraZoomModes mode, float newFieldOfView, float transitionDuration, float duration, MMChannelData channelData,
bool useUnscaledTime, bool stop = false, bool relative = false, bool restore = false, MMTweenType tweenType = null)
{
if (!MMChannel.Match(channelData, ChannelMode, Channel, MMChannelDefinition))
{
return;
}
if (stop)
{
this.enabled = false;
return;
}
if (restore)
{
#if MM_CINEMACHINE
_virtualCamera.m_Lens.FieldOfView = _initialFieldOfView;
#elif MM_CINEMACHINE3
_virtualCamera.Lens.FieldOfView = _initialFieldOfView;
#endif
return;
}
this.Zoom(mode, newFieldOfView, transitionDuration, duration, useUnscaledTime, relative, tweenType);
}
/// <summary>
/// Stops listening for MMCameraZoomEvents
/// </summary>
protected virtual void OnDestroy()
{
MMCameraZoomEvent.Unregister(OnCameraZoomEvent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 51662a222e352d74a8ad12e5843f7501
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/Cinemachine/Shakers/MMCinemachineZoom.cs
uploadId: 830868

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 92069ac0f6705bb49b7e9b8cab5b050d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f81ac7d016b3bba44b13af28b6f81506
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,127 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will trigger a MMBlink object, letting you blink something
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you trigger a blink on an MMBlink object.")]
[System.Serializable]
[FeedbackPath("Renderer/MMBlink")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
public class MMF_Blink : MMF_Feedback
{
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get => MMFeedbacksInspectorColors.RendererColor; }
public override bool HasCustomInspectors { get { return true; } }
public override bool EvaluateRequiresSetup() => (TargetBlink == null);
public override string RequiredTargetText => TargetBlink != null ? TargetBlink.name : "";
public override string RequiresSetupText => "This feedback requires that a TargetBlink be set to be able to work properly. You can set one below.";
#endif
public override float FeedbackDuration { get { return ApplyTimeMultiplier(Duration); } set { Duration = value; } }
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => TargetBlink = FindAutomatedTarget<MMBlink>();
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// the possible modes for this feedback, that correspond to MMBlink's public methods
public enum BlinkModes { Toggle, Start, Stop }
[MMFInspectorGroup("Blink", true, 61, true)]
/// the target object to blink
[Tooltip("the target object to blink")]
public MMBlink TargetBlink;
/// an optional list of extra target objects to blink
[Tooltip("an optional list of extra target objects to blink")]
public List<MMBlink> ExtraTargetBlinks;
/// the selected mode for this feedback
[Tooltip("the selected mode for this feedback")]
public BlinkModes BlinkMode = BlinkModes.Toggle;
/// the duration of the blink. You can set it manually, or you can press the GrabDurationFromBlink button to automatically compute it. For performance reasons, this isn't updated unless you press the button, make sure you do so if you change the blink's duration.
[Tooltip("the duration of the blink. You can set it manually, or you can press the GrabDurationFromBlink button to automatically compute it. For performance reasons, this isn't updated unless you press the button, make sure you do so if you change the blink's duration.")]
public float Duration;
public MMF_Button GrabDurationFromBlinkButton;
/// <summary>
/// Initializes our duration button
/// </summary>
public override void InitializeCustomAttributes()
{
GrabDurationFromBlinkButton = new MMF_Button("Grab Duration From Blink Component", GrabDurationFromBlink);
}
/// <summary>
/// On Custom play, we trigger our MMBlink object
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (TargetBlink == null))
{
return;
}
HandleBlink(TargetBlink);
foreach (MMBlink blink in ExtraTargetBlinks)
{
HandleBlink(blink);
}
}
/// <summary>
/// Toggles, starts or stops blink on the target
/// </summary>
/// <param name="target"></param>
protected virtual void HandleBlink(MMBlink target)
{
target.TimescaleMode = ComputedTimescaleMode;
switch (BlinkMode)
{
case BlinkModes.Toggle:
target.ToggleBlinking();
break;
case BlinkModes.Start:
target.StartBlinking();
break;
case BlinkModes.Stop:
target.StopBlinking();
break;
}
}
/// <summary>
/// On restore, we restore our initial state
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
TargetBlink.StopBlinking();
foreach (MMBlink blink in ExtraTargetBlinks)
{
blink.StopBlinking();
}
}
/// <summary>
/// Grabs and stores the duration from our target blink component if one is set
/// </summary>
public virtual void GrabDurationFromBlink()
{
if (TargetBlink != null)
{
Duration = TargetBlink.Duration;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2b3c116d0e316af4f98aea90424ad690
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Blink.cs
uploadId: 830868

View File

@@ -0,0 +1,82 @@
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
using UnityEngine.Serialization;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback lets you broadcast a float value to the MMRadio system
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you broadcast a float value to the MMRadio system.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("GameObject/Broadcast")]
public class MMF_Broadcast : MMF_FeedbackBase
{
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
#endif
public override bool HasChannel => true;
[Header("Level")]
/// the curve to tween the intensity on
[Tooltip("the curve to tween the intensity on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime, (int)Modes.ToDestination)]
public MMTweenType Curve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)));
/// the value to remap the intensity curve's 0 to
[Tooltip("the value to remap the intensity curve's 0 to")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public float RemapZero = 0f;
/// the value to remap the intensity curve's 1 to
[Tooltip("the value to remap the intensity curve's 1 to")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public float RemapOne = 1f;
/// the value to move the intensity to in instant mode
[Tooltip("the value to move the intensity to in instant mode")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.Instant)]
public float InstantChange;
/// the value to move the intensity to in destination mode
[Tooltip("the value to move the intensity to in destination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationValue;
protected MMF_BroadcastProxy _proxy;
/// <summary>
/// On init we store our initial alpha
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
_proxy = Owner.gameObject.AddComponent<MMF_BroadcastProxy>();
_proxy.Channel = Channel;
PrepareTargets();
}
/// <summary>
/// We setup our target with this object
/// </summary>
protected override void FillTargets()
{
MMF_FeedbackBaseTarget target = new MMF_FeedbackBaseTarget();
MMPropertyReceiver receiver = new MMPropertyReceiver();
receiver.TargetObject = Owner.gameObject;
receiver.TargetComponent = _proxy;
receiver.TargetPropertyName = "ThisLevel";
receiver.RelativeValue = RelativeValues;
target.Target = receiver;
target.LevelCurve = Curve;
target.RemapLevelZero = RemapZero;
target.RemapLevelOne = RemapOne;
target.InstantLevel = InstantChange;
target.ToDestinationLevel = DestinationValue;
_targets.Add(target);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f92a3f5abd60c5e41b92ebf0add536a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Broadcast.cs
uploadId: 830868

View File

@@ -0,0 +1,51 @@
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This component will be automatically added by the MMF_Broadcast feedback
/// </summary>
public class MMF_BroadcastProxy : MonoBehaviour
{
/// the channel on which to broadcast
[Tooltip("the channel on which to broadcast")]
[MMReadOnly]
public int Channel;
/// a debug view of the current level being broadcasted
[Tooltip("a debug view of the current level being broadcasted")]
[MMReadOnly]
public float DebugLevel;
/// whether or not a broadcast is in progress (will be false while the value is not changing, and thus not broadcasting)
[Tooltip("whether or not a broadcast is in progress (will be false while the value is not changing, and thus not broadcasting)")]
[MMReadOnly]
public bool BroadcastInProgress = false;
public virtual float ThisLevel { get; set; }
protected float _levelLastFrame;
/// <summary>
/// On Update we process our broadcast
/// </summary>
protected virtual void Update()
{
ProcessBroadcast();
}
/// <summary>
/// Broadcasts the value if needed
/// </summary>
protected virtual void ProcessBroadcast()
{
BroadcastInProgress = false;
if (ThisLevel != _levelLastFrame)
{
MMRadioLevelEvent.Trigger(Channel, ThisLevel);
BroadcastInProgress = true;
}
DebugLevel = ThisLevel;
_levelLastFrame = ThisLevel;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8117ecb7d1e9e3a49bf38e7ab2c09ff7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_BroadcastProxy.cs
uploadId: 830868

View File

@@ -0,0 +1,84 @@
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback lets you control the opacity of a canvas group over time
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you control the opacity of a canvas group over time.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("UI/CanvasGroup")]
public class MMF_CanvasGroup : MMF_FeedbackBase
{
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
public override bool EvaluateRequiresSetup() { return (TargetCanvasGroup == null); }
public override string RequiredTargetText { get { return TargetCanvasGroup != null ? TargetCanvasGroup.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a TargetCanvasGroup be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasAutomatedTargetAcquisition => true;
public override bool CanForceInitialValue => true;
protected override void AutomateTargetAcquisition() => TargetCanvasGroup = FindAutomatedTarget<CanvasGroup>();
[MMFInspectorGroup("Canvas Group", true, 12, true)]
/// the receiver to write the level to
[Tooltip("the receiver to write the level to")]
public CanvasGroup TargetCanvasGroup;
/// the curve to tween the opacity on
[Tooltip("the curve to tween the opacity on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime, (int)Modes.ToDestination)]
public MMTweenType AlphaCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)));
/// the value to remap the opacity curve's 0 to
[Tooltip("the value to remap the opacity curve's 0 to")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public float RemapZero = 0f;
/// the value to remap the opacity curve's 1 to
[Tooltip("the value to remap the opacity curve's 1 to")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public float RemapOne = 1f;
/// the value to move the opacity to in instant mode
[Tooltip("the value to move the opacity to in instant mode")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.Instant)]
public float InstantAlpha;
/// the value to move the opacity to in destination mode
[Tooltip("the value to move the opacity to in destination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationAlpha;
public override void OnAddFeedback()
{
base.OnAddFeedback();
RelativeValues = false;
}
protected override void FillTargets()
{
if (TargetCanvasGroup == null)
{
return;
}
MMF_FeedbackBaseTarget target = new MMF_FeedbackBaseTarget();
MMPropertyReceiver receiver = new MMPropertyReceiver();
receiver.TargetObject = TargetCanvasGroup.gameObject;
receiver.TargetComponent = TargetCanvasGroup;
receiver.TargetPropertyName = "alpha";
receiver.RelativeValue = RelativeValues;
target.Target = receiver;
target.LevelCurve = AlphaCurve;
target.RemapLevelZero = RemapZero;
target.RemapLevelOne = RemapOne;
target.InstantLevel = InstantAlpha;
target.ToDestinationLevel = DestinationAlpha;
_targets.Add(target);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 0bcfac83087655f42bcb7a42d7d02f05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_CanvasGroup.cs
uploadId: 830868

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will force a break, pausing the editor
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will will force a break, pausing the editor")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Debug/Break")]
public class MMF_DebugBreak : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// the duration of this feedback is 0
public override float FeedbackDuration { get { return 0f; } }
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.DebugColor; } }
#endif
/// <summary>
/// On Play we break
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
Debug.Break();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: af342e664060d4e42bd5f6a5753d95e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_DebugBreak.cs
uploadId: 830868

View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback doesn't do anything by default, it's just meant as a comment, you can store text in it for future reference, maybe to remember how you setup a particular MMFeedbacks. Optionally it can also output that comment to the console on Play.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback doesn't do anything by default, it's just meant as a comment, you can store text in it for future reference, maybe to remember how you setup a particular MMFeedbacks. Optionally it can also output that comment to the console on Play.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Debug/Comment")]
public class MMF_DebugComment : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.DebugColor; } }
#endif
[MMFInspectorGroup("Comment", true, 61)]
/// the comment / note associated to this feedback
[Tooltip("the comment / note associated to this feedback")]
[TextArea(10,30)]
public string Comment;
/// if this is true, the comment will be output to the console on Play
[Tooltip("if this is true, the comment will be output to the console on Play")]
public bool LogComment = false;
/// the color of the message when in DebugLogTime mode
[Tooltip("the color of the message when in DebugLogTime mode")]
[MMCondition("LogComment", true)]
public Color DebugColor = Color.gray;
/// <summary>
/// On Play we output our message to the console if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || !LogComment)
{
return;
}
MMDebug.DebugLogInfo(Comment);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9e5ef4e0e1b94c54b97bc6387c8009bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_DebugComment.cs
uploadId: 830868

View File

@@ -0,0 +1,83 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you output a message to the console, using a custom MM debug method, or Log, Assertion, Error or Warning logs.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you output a message to the console, using a custom MM debug method, or Log, Assertion, Error or Warning logs.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Debug/Log")]
public class MMF_DebugLog : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// the duration of this feedback is 0
public override float FeedbackDuration { get { return 0f; } }
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.DebugColor; } }
#endif
/// the possible debug modes
public enum DebugLogModes { DebugLogTime, Log, Assertion, Error, Warning }
[MMFInspectorGroup("Debug", true, 17)]
/// the selected debug mode
[Tooltip("the selected debug mode")]
public DebugLogModes DebugLogMode = DebugLogModes.DebugLogTime;
/// the message to display
[Tooltip("the message to display")]
[TextArea]
public string DebugMessage = "YOUR DEBUG MESSAGE GOES HERE";
/// the color of the message when in DebugLogTime mode
[Tooltip("the color of the message when in DebugLogTime mode")]
[MMFEnumCondition("DebugLogMode", (int) DebugLogModes.DebugLogTime)]
public Color DebugColor = Color.cyan;
/// whether or not to display the frame count when in DebugLogTime mode
[Tooltip("whether or not to display the frame count when in DebugLogTime mode")]
[MMFEnumCondition("DebugLogMode", (int) DebugLogModes.DebugLogTime)]
public bool DisplayFrameCount = true;
/// <summary>
/// On Play we output our message to the console using the selected mode
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
switch (DebugLogMode)
{
case DebugLogModes.Assertion:
Debug.LogAssertion(DebugMessage);
break;
case DebugLogModes.Log:
Debug.Log(DebugMessage);
break;
case DebugLogModes.Error:
Debug.LogError(DebugMessage);
break;
case DebugLogModes.Warning:
Debug.LogWarning(DebugMessage);
break;
case DebugLogModes.DebugLogTime:
string color = "#" + ColorUtility.ToHtmlStringRGB(DebugColor);
MMDebug.DebugLogTime(DebugMessage, color, 3, DisplayFrameCount);
break;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 18d70b42b0fd93e49b47f2970addf779
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_DebugLog.cs
uploadId: 830868

View File

@@ -0,0 +1,223 @@
#if MM_UI
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
using UnityEngine.UI;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will trigger a one time play on a target FloatController
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you trigger a fade event.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Camera/Fade")]
public class MMF_Fade : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.CameraColor; } }
public override string RequiredTargetText { get { return "ID "+ID; } }
public override bool HasCustomInspectors => true;
public override bool HasAutomaticShakerSetup => true;
#endif
/// the different possible types of fades
public enum FadeTypes { FadeIn, FadeOut, Custom }
/// the different ways to send the position to the fader :
/// - FeedbackPosition : fade at the position of the feedback, plus an optional offset
/// - Transform : fade at the specified Transform's position, plus an optional offset
/// - WorldPosition : fade at the specified world position vector, plus an optional offset
/// - Script : the position passed in parameters when calling the feedback
public enum PositionModes { FeedbackPosition, Transform, WorldPosition, Script }
[MMFInspectorGroup("Fade", true, 43)]
/// the type of fade we want to use when this feedback gets played
[Tooltip("the type of fade we want to use when this feedback gets played")]
public FadeTypes FadeType;
/// the ID of the fader(s) to pilot
[Tooltip("the ID of the fader(s) to pilot")]
public int ID = 0;
/// the duration (in seconds) of the fade
[Tooltip("the duration (in seconds) of the fade")]
public float Duration = 1f;
/// the curve to use for this fade
[Tooltip("the curve to use for this fade")]
public MMTweenType Curve = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic);
/// whether or not this fade should ignore timescale
[Tooltip("whether or not this fade should ignore timescale")]
public bool IgnoreTimeScale = true;
[Header("Custom")]
/// the target alpha we're aiming for with this fade
[Tooltip("the target alpha we're aiming for with this fade")]
public float TargetAlpha;
[Header("Position")]
/// the chosen way to position the fade
[Tooltip("the chosen way to position the fade")]
public PositionModes PositionMode = PositionModes.FeedbackPosition;
/// the transform on which to center the fade
[Tooltip("the transform on which to center the fade")]
[MMFEnumCondition("PositionMode", (int)PositionModes.Transform)]
public Transform TargetTransform;
/// the coordinates on which to center the fadet
[Tooltip("the coordinates on which to center the fade")]
[MMFEnumCondition("PositionMode", (int)PositionModes.WorldPosition)]
public Vector3 TargetPosition;
/// the position offset to apply when centering the fade
[Tooltip("the position offset to apply when centering the fade")]
public Vector3 PositionOffset;
[Header("Optional Target")]
/// this field lets you bind a specific MMFader to this feedback. If left empty, the feedback will trigger a MMFadeEvent instead, targeting all matching faders. If you fill it, only that specific fader will be targeted.
[Tooltip("this field lets you bind a specific MMFader to this feedback. If left empty, the feedback will trigger a MMFadeEvent instead, targeting all matching faders. If you fill it, only that specific fader will be targeted.")]
public MMFader TargetFader;
/// the duration of this feedback is the duration of the fade
public override float FeedbackDuration { get { return ApplyTimeMultiplier(Duration); } set { Duration = value; } }
protected Vector3 _position;
protected FadeTypes _fadeType;
/// <summary>
/// On play we trigger the selected fade event
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
_position = GetPosition(position);
_fadeType = FadeType;
if (!NormalPlayDirection)
{
if (FadeType == FadeTypes.FadeIn)
{
_fadeType = FadeTypes.FadeOut;
}
else if (FadeType == FadeTypes.FadeOut)
{
_fadeType = FadeTypes.FadeIn;
}
}
if (TargetFader != null)
{
switch (_fadeType)
{
case FadeTypes.Custom:
TargetFader.Fade(TargetAlpha, FeedbackDuration, Curve, IgnoreTimeScale);
break;
case FadeTypes.FadeIn:
TargetFader.FadeIn(FeedbackDuration, Curve, IgnoreTimeScale);
break;
case FadeTypes.FadeOut:
TargetFader.FadeOut(FeedbackDuration, Curve, IgnoreTimeScale);
break;
}
}
else
{
switch (_fadeType)
{
case FadeTypes.Custom:
MMFadeEvent.Trigger(FeedbackDuration, TargetAlpha, Curve, ID, IgnoreTimeScale, _position);
break;
case FadeTypes.FadeIn:
MMFadeInEvent.Trigger(FeedbackDuration, Curve, ID, IgnoreTimeScale, _position);
break;
case FadeTypes.FadeOut:
MMFadeOutEvent.Trigger(FeedbackDuration, Curve, ID, IgnoreTimeScale, _position);
break;
}
}
}
/// <summary>
/// Stops the animation if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
MMFadeStopEvent.Trigger(ID);
}
/// <summary>
/// Computes the proper position for this fade
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
protected virtual Vector3 GetPosition(Vector3 position)
{
switch (PositionMode)
{
case PositionModes.FeedbackPosition:
return Owner.transform.position + PositionOffset;
case PositionModes.Transform:
return TargetTransform.position + PositionOffset;
case PositionModes.WorldPosition:
return TargetPosition + PositionOffset;
case PositionModes.Script:
return position + PositionOffset;
default:
return position + PositionOffset;
}
}
/// <summary>
/// On restore, we restore our initial state
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMFadeStopEvent.Trigger(ID, true);
}
/// <summary>
/// Automatically tries to add a MMFader setup to the scene
/// </summary>
public override void AutomaticShakerSetup()
{
if (Object.FindAnyObjectByType<MMFader>() != null)
{
return;
}
(Canvas canvas, bool createdNewCanvas) = Owner.gameObject.MMFindOrCreateObjectOfType<Canvas>("FadeCanvas", null);
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
(Image image, bool createdNewImage) = canvas.gameObject.MMFindOrCreateObjectOfType<Image>("FadeImage", canvas.transform, true);
image.raycastTarget = false;
image.color = Color.black;
RectTransform rectTransform = image.GetComponent<RectTransform>();
rectTransform.anchorMin = new Vector2(0f, 0f);
rectTransform.anchorMax = new Vector2(1f, 1f);
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
image.gameObject.AddComponent<MMFader>();
image.gameObject.GetComponent<CanvasGroup>().alpha = 0;
image.gameObject.GetComponent<CanvasGroup>().interactable = false;
MMDebug.DebugLogInfo("Added a MMFader to the scene. You're all set.");
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 0dc617b01bf230943a22cac5dec24291
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Fade.cs
uploadId: 830868

View File

@@ -0,0 +1,242 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will trigger a one time play on a target FloatController
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you trigger a one time play on a target FloatController.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("GameObject/FloatController")]
public class MMF_FloatController : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// the different possible modes
public enum Modes { OneTime, ToDestination }
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.GameObjectColor; } }
public override bool EvaluateRequiresSetup() { return (TargetFloatController == null); }
public override string RequiredTargetText { get { return TargetFloatController != null ? TargetFloatController.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a TargetFloatController be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasRandomness => true;
public override bool CanForceInitialValue => true;
public override bool ForceInitialValueDelayed => true;
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => TargetFloatController = FindAutomatedTarget<FloatController>();
[MMFInspectorGroup("Float Controller", true, 36, true)]
/// the mode this controller is in
[Tooltip("the mode this controller is in")]
public Modes Mode = Modes.OneTime;
/// the float controller to trigger a one time play on
[Tooltip("the float controller to trigger a one time play on")]
public FloatController TargetFloatController;
/// a list of extra and optional float controllers to trigger a one time play on
[Tooltip("a list of extra and optional float controllers to trigger a one time play on")]
public List<FloatController> ExtraTargetFloatControllers;
/// whether this should revert to original at the end
[Tooltip("whether this should revert to original at the end")]
public bool RevertToInitialValueAfterEnd = false;
/// the duration of the One Time shake
[Tooltip("the duration of the One Time shake")]
[MMFEnumCondition("Mode", (int)Modes.OneTime)]
public float OneTimeDuration = 1f;
/// the amplitude of the One Time shake (this will be multiplied by the curve's height)
[Tooltip("the amplitude of the One Time shake (this will be multiplied by the curve's height)")]
[MMFEnumCondition("Mode", (int)Modes.OneTime)]
public float OneTimeAmplitude = 1f;
/// the low value to remap the normalized curve value to
[Tooltip("the low value to remap the normalized curve value to")]
[MMFEnumCondition("Mode", (int)Modes.OneTime)]
public float OneTimeRemapMin = 0f;
/// the high value to remap the normalized curve value to
[Tooltip("the high value to remap the normalized curve value to")]
[MMFEnumCondition("Mode", (int)Modes.OneTime)]
public float OneTimeRemapMax = 1f;
/// the curve to apply to the one time shake
[Tooltip("the curve to apply to the one time shake")]
[MMFEnumCondition("Mode", (int)Modes.OneTime)]
public AnimationCurve OneTimeCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
/// the value to move this float controller to
[Tooltip("the value to move this float controller to")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float ToDestinationValue = 1f;
/// the duration over which to move the value
[Tooltip("the duration over which to move the value")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float ToDestinationDuration = 1f;
/// the curve over which to move the value in ToDestination mode
[Tooltip("the curve over which to move the value in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public AnimationCurve ToDestinationCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
/// the duration of this feedback is the duration of the one time hit
public override float FeedbackDuration
{
get { return (Mode == Modes.OneTime) ? ApplyTimeMultiplier(OneTimeDuration) : ApplyTimeMultiplier(ToDestinationDuration); }
set { OneTimeDuration = value; ToDestinationDuration = value; }
}
protected float _oneTimeDurationStorage;
protected float _oneTimeAmplitudeStorage;
protected float _oneTimeRemapMinStorage;
protected float _oneTimeRemapMaxStorage;
protected AnimationCurve _oneTimeCurveStorage;
protected float _toDestinationValueStorage;
protected float _toDestinationDurationStorage;
protected AnimationCurve _toDestinationCurveStorage;
protected bool _revertToInitialValueAfterEndStorage;
/// <summary>
/// On init we grab our initial values on the target float controller
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
if (Active && (TargetFloatController != null))
{
_oneTimeDurationStorage = TargetFloatController.OneTimeDuration;
_oneTimeAmplitudeStorage = TargetFloatController.OneTimeAmplitude;
_oneTimeCurveStorage = TargetFloatController.OneTimeCurve;
_oneTimeRemapMinStorage = TargetFloatController.OneTimeRemapMin;
_oneTimeRemapMaxStorage = TargetFloatController.OneTimeRemapMax;
_toDestinationCurveStorage = TargetFloatController.ToDestinationCurve;
_toDestinationDurationStorage = TargetFloatController.ToDestinationDuration;
_toDestinationValueStorage = TargetFloatController.ToDestinationValue;
_revertToInitialValueAfterEndStorage = TargetFloatController.RevertToInitialValueAfterEnd;
}
}
/// <summary>
/// On play we trigger a one time or ToDestination play on our target float controller
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (TargetFloatController == null))
{
return;
}
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
HandleFloatController(TargetFloatController, intensityMultiplier);
foreach (FloatController floatController in ExtraTargetFloatControllers)
{
HandleFloatController(floatController, intensityMultiplier);
}
}
/// <summary>
/// Applies values to and triggers the target float controller
/// </summary>
/// <param name="target"></param>
/// <param name="intensityMultiplier"></param>
protected virtual void HandleFloatController(FloatController target, float intensityMultiplier)
{
target.RevertToInitialValueAfterEnd = RevertToInitialValueAfterEnd;
if (Mode == Modes.OneTime)
{
target.OneTimeDuration = FeedbackDuration;
target.OneTimeAmplitude = OneTimeAmplitude;
target.OneTimeCurve = OneTimeCurve;
if (NormalPlayDirection)
{
target.OneTimeRemapMin = OneTimeRemapMin * intensityMultiplier;
target.OneTimeRemapMax = OneTimeRemapMax * intensityMultiplier;
}
else
{
target.OneTimeRemapMin = OneTimeRemapMax * intensityMultiplier;
target.OneTimeRemapMax = OneTimeRemapMin * intensityMultiplier;
}
target.OneTime();
}
if (Mode == Modes.ToDestination)
{
target.ToDestinationCurve = ToDestinationCurve;
target.ToDestinationDuration = FeedbackDuration;
target.ToDestinationValue = ToDestinationValue;
target.ToDestination();
}
}
/// <summary>
/// On reset we reset our values on the target controller with the ones stored initially
/// </summary>
protected override void CustomReset()
{
base.CustomReset();
if (Active && FeedbackTypeAuthorized && (TargetFloatController != null))
{
ResetFloatController(TargetFloatController);
foreach (FloatController controller in ExtraTargetFloatControllers)
{
ResetFloatController(controller);
}
}
}
protected virtual void ResetFloatController(FloatController controller)
{
controller.OneTimeDuration = _oneTimeDurationStorage;
controller.OneTimeAmplitude = _oneTimeAmplitudeStorage;
controller.OneTimeCurve = _oneTimeCurveStorage;
controller.OneTimeRemapMin = _oneTimeRemapMinStorage;
controller.OneTimeRemapMax = _oneTimeRemapMaxStorage;
controller.ToDestinationCurve = _toDestinationCurveStorage;
controller.ToDestinationDuration = _toDestinationDurationStorage;
controller.ToDestinationValue = _toDestinationValueStorage;
controller.RevertToInitialValueAfterEnd = _revertToInitialValueAfterEndStorage;
}
/// <summary>
/// On stop, we interrupt movement if it was active
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if (TargetFloatController != null)
{
TargetFloatController.Stop();
foreach (FloatController controller in ExtraTargetFloatControllers)
{
controller.Stop();
}
}
}
/// <summary>
/// On restore, we restore our initial state
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
TargetFloatController.RestoreInitialValues();
foreach (FloatController controller in ExtraTargetFloatControllers)
{
controller.RestoreInitialValues();
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 35b65ddee73b8544486c63441149886c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_FloatController.cs
uploadId: 830868

View File

@@ -0,0 +1,164 @@
using MoreMountains.Tools;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will request the spawn of a floating text, usually to signify damage, but not necessarily
/// This requires that a MMFloatingTextSpawner be correctly setup in the scene, otherwise nothing will happen.
/// To do so, create a new empty object, add a MMFloatingTextSpawner to it. Drag (at least) one MMFloatingText prefab into its PooledSimpleMMFloatingText slot.
/// You'll find such prefabs already made in the MMTools/Tools/MMFloatingText/Prefabs folder, but feel free to create your own.
/// Using that feedback will always spawn the same text. While this may be what you want, if you're using the Corgi Engine or TopDown Engine, you'll find dedicated versions
/// directly hooked to the Health component, letting you display damage taken.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will request the spawn of a floating text, usually to signify damage, but not necessarily. " +
"This requires that a MMFloatingTextSpawner be correctly setup in the scene, otherwise nothing will happen. " +
"To do so, create a new empty object, add a MMFloatingTextSpawner to it. Drag (at least) one MMFloatingText prefab into its PooledSimpleMMFloatingText slot. " +
"You'll find such prefabs already made in the MMTools/Tools/MMFloatingText/Prefabs folder, but feel free to create your own. " +
"Using that feedback will always spawn the same text. While this may be what you want, if you're using the Corgi Engine or TopDown Engine, you'll find dedicated versions " +
"directly hooked to the Health component, letting you display damage taken.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("UI/Floating Text")]
public class MMF_FloatingText : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
#endif
/// the duration of this feedback is a fixed value or the lifetime
public override float FeedbackDuration { get { return ApplyTimeMultiplier(Lifetime); } set { Lifetime = value; } }
public override bool HasChannel => true;
public override bool HasRandomness => true;
/// the possible places where the floating text should spawn at
public enum PositionModes { TargetTransform, FeedbackPosition, PlayPosition }
[MMFInspectorGroup("Floating Text", true, 64)]
/// the Intensity to spawn this text with, will act as a lifetime/movement/scale multiplier based on the spawner's settings
[Tooltip("the Intensity to spawn this text with, will act as a lifetime/movement/scale multiplier based on the spawner's settings")]
public float Intensity = 1f;
/// the value to display when spawning this text
[Tooltip("the value to display when spawning this text")]
public string Value = "100";
/// if this is true, the intensity passed to this feedback will be the value displayed
[Tooltip("if this is true, the intensity passed to this feedback will be the value displayed")]
public bool UseIntensityAsValue = false;
/// the possible methods that can be applied to the output value (when using intensity as the output value, string values won't get rounded)
public enum RoundingMethods { NoRounding, Round, Ceil, Floor }
/// the rounding methods to apply to the output value (when using intensity as the output value, string values won't get rounded)
[Tooltip("the rounding methods to apply to the output value (when using intensity as the output value, string values won't get rounded)")]
[MMFInspectorGroup("Rounding", true, 68)]
public RoundingMethods RoundingMethod = RoundingMethods.NoRounding;
[MMFInspectorGroup("Color", true, 65)]
/// whether or not to force a color on the new text, if not, the default colors of the spawner will be used
[Tooltip("whether or not to force a color on the new text, if not, the default colors of the spawner will be used")]
public bool ForceColor = false;
/// the gradient to apply over the lifetime of the text
[Tooltip("the gradient to apply over the lifetime of the text")]
[GradientUsage(true)]
public Gradient AnimateColorGradient = new Gradient();
[MMFInspectorGroup("Lifetime", true, 66)]
/// whether or not to force a lifetime on the new text, if not, the default colors of the spawner will be used
[Tooltip("whether or not to force a lifetime on the new text, if not, the default colors of the spawner will be used")]
public bool ForceLifetime = false;
/// the forced lifetime for the spawned text
[Tooltip("the forced lifetime for the spawned text")]
[MMFCondition("ForceLifetime", true)]
public float Lifetime = 0.5f;
[MMFInspectorGroup("Position", true, 67)]
/// where to spawn the new text (at the position of the feedback, or on a specified Transform)
[Tooltip("where to spawn the new text (at the position of the feedback, or on a specified Transform)")]
public PositionModes PositionMode = PositionModes.FeedbackPosition;
/// in transform mode, the Transform on which to spawn the new floating text
[Tooltip("in transform mode, the Transform on which to spawn the new floating text")]
[MMFEnumCondition("PositionMode", (int)PositionModes.TargetTransform)]
public Transform TargetTransform;
/// the direction to apply to the new floating text (leave it to 0 to let the Spawner decide based on its settings)
[Tooltip("the direction to apply to the new floating text (leave it to 0 to let the Spawner decide based on its settings)")]
public Vector3 Direction = Vector3.zero;
/// a transform to attach the floating text to for the duration of its lifetime. it will then move relative to it
[Tooltip("a transform to attach the floating text to for the duration of its lifetime. it will then move relative to it")]
public Transform AttachmentTransform;
protected Vector3 _playPosition;
protected string _value;
/// <summary>
/// On play we ask the spawner on the specified channel to spawn a new floating text
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
switch (PositionMode)
{
case PositionModes.FeedbackPosition:
_playPosition = Owner.transform.position;
break;
case PositionModes.PlayPosition:
_playPosition = position;
break;
case PositionModes.TargetTransform:
_playPosition = TargetTransform.position;
break;
}
if (RoundingMethod != RoundingMethods.NoRounding)
{
switch (RoundingMethod)
{
case RoundingMethods.Ceil:
break;
}
}
feedbacksIntensity = ApplyRounding(feedbacksIntensity);
_value = UseIntensityAsValue ? feedbacksIntensity.ToString() : Value;
MMFloatingTextSpawnEvent.Trigger(ChannelData, _playPosition, _value, Direction, Intensity * intensityMultiplier, ForceLifetime, Lifetime, ForceColor, AnimateColorGradient,
ComputedTimescaleMode == TimescaleModes.Unscaled, AttachmentTransform);
}
protected virtual float ApplyRounding(float value)
{
if (RoundingMethod == RoundingMethods.NoRounding)
{
return value;
}
switch (RoundingMethod)
{
case RoundingMethods.Round:
return Mathf.Round(value);
case RoundingMethods.Ceil:
return Mathf.Ceil(value);
case RoundingMethods.Floor:
return Mathf.Floor(value);
}
return value;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b34371db751e55942bc9b51871b77ca1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_FloatingText.cs
uploadId: 830868

View File

@@ -0,0 +1,275 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you animate the density, color, end and start distance of your scene's fog
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you animate the density, color, end and start distance of your scene's fog")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Renderer/Fog")]
public class MMF_Fog : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.RendererColor; } }
public override string RequiredTargetText { get { return Mode.ToString(); } }
#endif
public override bool HasRandomness => true;
public override bool HasCustomInspectors => true;
/// the possible modes for this feedback
public enum Modes { OverTime, Instant }
[MMFInspectorGroup("Fog", true, 24)]
/// whether the feedback should affect the sprite renderer instantly or over a period of time
[Tooltip("whether the feedback should affect the sprite renderer instantly or over a period of time")]
public Modes Mode = Modes.OverTime;
/// how long the sprite renderer should change over time
[Tooltip("how long the sprite renderer should change over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float Duration = 2f;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
[MMFInspectorGroup("Fog Density", true, 25)]
/// whether or not to modify the fog's density
[Tooltip("whether or not to modify the fog's density")]
public bool ModifyFogDensity = true;
/// a curve to use to animate the fog's density over time
[Tooltip("a curve to use to animate the fog's density over time")]
public MMTweenType DensityCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)));
/// the value to remap the fog's density curve zero value to
[Tooltip("the value to remap the fog's density curve zero value to")]
public float DensityRemapZero = 0.01f;
/// the value to remap the fog's density curve one value to
[Tooltip("the value to remap the fog's density curve one value to")]
public float DensityRemapOne = 0.05f;
/// the value to change the fog's density to when in instant mode
[Tooltip("the value to change the fog's density to when in instant mode")]
public float DensityInstantChange;
[MMFInspectorGroup("Fog Start Distance", true, 26)]
/// whether or not to modify the fog's start distance
[Tooltip("whether or not to modify the fog's start distance")]
public bool ModifyStartDistance = true;
/// a curve to use to animate the fog's start distance over time
[Tooltip("a curve to use to animate the fog's start distance over time")]
public MMTweenType StartDistanceCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)));
/// the value to remap the fog's start distance curve zero value to
[Tooltip("the value to remap the fog's start distance curve zero value to")]
public float StartDistanceRemapZero = 0f;
/// the value to remap the fog's start distance curve one value to
[Tooltip("the value to remap the fog's start distance curve one value to")]
public float StartDistanceRemapOne = 0f;
/// the value to change the fog's start distance to when in instant mode
[Tooltip("the value to change the fog's start distance to when in instant mode")]
public float StartDistanceInstantChange;
[MMFInspectorGroup("Fog End Distance", true, 27)]
/// whether or not to modify the fog's end distance
[Tooltip("whether or not to modify the fog's end distance")]
public bool ModifyEndDistance = true;
/// a curve to use to animate the fog's end distance over time
[Tooltip("a curve to use to animate the fog's end distance over time")]
public MMTweenType EndDistanceCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)));
/// the value to remap the fog's end distance curve zero value to
[Tooltip("the value to remap the fog's end distance curve zero value to")]
public float EndDistanceRemapZero = 0f;
/// the value to remap the fog's end distance curve one value to
[Tooltip("the value to remap the fog's end distance curve one value to")]
public float EndDistanceRemapOne = 300f;
/// the value to change the fog's end distance to when in instant mode
[Tooltip("the value to change the fog's end distance to when in instant mode")]
public float EndDistanceInstantChange;
[MMFInspectorGroup("Fog Color", true, 28)]
/// whether or not to modify the fog's color
[Tooltip("whether or not to modify the fog's color")]
public bool ModifyColor = true;
/// the colors to apply to the sprite renderer over time
[Tooltip("the colors to apply to the sprite renderer over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public Gradient ColorOverTime;
/// the color to move to in instant mode
[Tooltip("the color to move to in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public Color InstantColor;
/// the duration of this feedback is the duration of the sprite renderer, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { if (Mode != Modes.Instant) { Duration = value; } } }
protected Coroutine _coroutine;
protected Color _initialColor;
protected float _initialStartDistance;
protected float _initialEndDistance;
protected float _initialDensity;
protected Color _initialInstantColor;
protected float _initialInstantStartDistance;
protected float _initialInstantEndDistance;
protected float _initialInstantDensity;
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if (Active)
{
_initialInstantColor = RenderSettings.fogColor;
_initialInstantStartDistance = RenderSettings.fogStartDistance;
_initialInstantEndDistance = RenderSettings.fogEndDistance;
_initialInstantDensity = RenderSettings.fogDensity;
if (ColorOverTime == null)
{
ColorOverTime = new Gradient();
}
}
}
/// <summary>
/// On Play we change the values of our fog
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
_initialColor = RenderSettings.fogColor;
_initialStartDistance = RenderSettings.fogStartDistance;
_initialEndDistance = RenderSettings.fogEndDistance;
_initialDensity = RenderSettings.fogDensity;
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
switch (Mode)
{
case Modes.Instant:
if (ModifyColor)
{
RenderSettings.fogColor = NormalPlayDirection ? InstantColor : _initialColor;
}
if (ModifyStartDistance)
{
RenderSettings.fogStartDistance = NormalPlayDirection ? StartDistanceInstantChange : _initialInstantStartDistance;
}
if (ModifyEndDistance)
{
RenderSettings.fogEndDistance = NormalPlayDirection ? EndDistanceInstantChange : _initialInstantEndDistance;
}
if (ModifyFogDensity)
{
RenderSettings.fogDensity = NormalPlayDirection ? DensityInstantChange * intensityMultiplier : _initialInstantDensity;
}
break;
case Modes.OverTime:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(FogSequence(intensityMultiplier));
break;
}
}
/// <summary>
/// This coroutine will modify the values on the fog settings
/// </summary>
/// <returns></returns>
protected virtual IEnumerator FogSequence(float intensityMultiplier)
{
IsPlaying = true;
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
SetFogValues(remappedTime, intensityMultiplier);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
SetFogValues(FinalNormalizedTime, intensityMultiplier);
_coroutine = null;
IsPlaying = false;
yield return null;
}
/// <summary>
/// Sets the various values on the fog on a specified time (between 0 and 1)
/// </summary>
/// <param name="time"></param>
protected virtual void SetFogValues(float time, float intensityMultiplier)
{
if (ModifyColor)
{
RenderSettings.fogColor = ColorOverTime.Evaluate(time);
}
if (ModifyFogDensity)
{
RenderSettings.fogDensity = MMTween.Tween(time, 0f, 1f, DensityRemapZero, DensityRemapOne, DensityCurve) * intensityMultiplier;
}
if (ModifyStartDistance)
{
RenderSettings.fogStartDistance = MMTween.Tween(time, 0f, 1f, StartDistanceRemapZero, StartDistanceRemapOne, StartDistanceCurve);
}
if (ModifyEndDistance)
{
RenderSettings.fogEndDistance = MMTween.Tween(time, 0f, 1f, EndDistanceRemapZero, EndDistanceRemapOne, EndDistanceCurve);
}
}
/// <summary>
/// Stops this feedback
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized || (_coroutine == null))
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
IsPlaying = false;
Owner.StopCoroutine(_coroutine);
_coroutine = null;
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
RenderSettings.fogColor = _initialColor;
RenderSettings.fogStartDistance = _initialStartDistance;
RenderSettings.fogEndDistance = _initialEndDistance;
RenderSettings.fogDensity = _initialDensity;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ab9c4511f66964b488597580ab1b228f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Fog.cs
uploadId: 830868

View File

@@ -0,0 +1,251 @@
#if MM_UI
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you change the alpha of a target sprite renderer over time.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you change the alpha of a target Image over time.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("UI/Image Alpha")]
public class MMF_ImageAlpha : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
public override bool EvaluateRequiresSetup() { return (BoundImage == null); }
public override string RequiredTargetText { get { return BoundImage != null ? BoundImage.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a BoundImage be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasCustomInspectors => true;
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => BoundImage = FindAutomatedTarget<Image>();
/// the possible modes for this feedback
public enum Modes { OverTime, Instant, ToDestination }
[MMFInspectorGroup("Target Image", true, 12, true)]
/// the Image to affect when playing the feedback
[Tooltip("the Image to affect when playing the feedback")]
public Image BoundImage;
[MMFInspectorGroup("Image Alpha Animation", true, 24)]
/// whether the feedback should affect the Image instantly or over a period of time
[Tooltip("whether the feedback should affect the Image instantly or over a period of time")]
public Modes Mode = Modes.OverTime;
/// how long the Image should change over time
[Tooltip("how long the Image should change over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime, (int)Modes.ToDestination)]
public float Duration = 0.2f;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// the alpha to move to in instant mode
[Tooltip("the alpha to move to in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public float InstantAlpha = 1f;
/// the curve to use when interpolating towards the destination alpha
[Tooltip("the curve to use when interpolating towards the destination alpha")]
public MMTweenType Curve = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic, "", "Mode", (int)Modes.OverTime, (int)Modes.ToDestination);
/// the value to which the curve's 0 should be remapped
[Tooltip("the value to which the curve's 0 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float CurveRemapZero = 0f;
/// the value to which the curve's 1 should be remapped
[Tooltip("the value to which the curve's 1 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float CurveRemapOne = 1f;
/// the alpha to aim towards when in ToDestination mode
[Tooltip("the alpha to aim towards when in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationAlpha = 1f;
/// if this is true, the target will be disabled when this feedbacks is stopped
[Tooltip("if this is true, the target will be disabled when this feedbacks is stopped")]
public bool DisableOnStop = false;
/// the duration of this feedback is the duration of the Image, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { Duration = value; } }
protected Coroutine _coroutine;
protected Color _imageColor;
protected Color _initialColor;
protected float _initialAlpha;
protected float _initialInstantAlpha;
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if (BoundImage == null)
{
Debug.LogWarning("[Image Alpha Feedback] The image alpha feedback on "+Owner.name+" doesn't have a bound image, it won't work. You need to specify an image in its inspector.");
return;
}
if (Active)
{
_initialInstantAlpha = BoundImage.color.a;
}
}
/// <summary>
/// On Play we turn our Image on and start an over time coroutine if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (BoundImage == null))
{
return;
}
_initialColor = BoundImage.color;
Turn(true);
switch (Mode)
{
case Modes.Instant:
_imageColor = BoundImage.color;
_imageColor.a = NormalPlayDirection ? InstantAlpha : _initialInstantAlpha;
BoundImage.color = _imageColor;
break;
case Modes.OverTime:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ImageSequence());
break;
case Modes.ToDestination:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ImageSequence());
break;
}
}
/// <summary>
/// This coroutine will modify the values on the Image
/// </summary>
/// <returns></returns>
protected virtual IEnumerator ImageSequence()
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
_imageColor = BoundImage.color;
_initialAlpha = BoundImage.color.a;
IsPlaying = true;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
SetAlpha(remappedTime);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
SetAlpha(FinalNormalizedTime);
_coroutine = null;
IsPlaying = false;
yield return null;
}
/// <summary>
/// Sets the various values on the sprite renderer on a specified time (between 0 and 1)
/// </summary>
/// <param name="time"></param>
protected virtual void SetAlpha(float time)
{
float newAlpha = 0f;
if (Mode == Modes.OverTime)
{
newAlpha = MMTween.Tween(time, 0f, 1f, CurveRemapZero, CurveRemapOne, Curve);
}
else if (Mode == Modes.ToDestination)
{
newAlpha = MMTween.Tween(time, 0f, 1f, _initialAlpha, DestinationAlpha, Curve);
}
_imageColor.a = newAlpha;
BoundImage.color = _imageColor;
}
/// <summary>
/// Turns the sprite renderer off on stop
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
IsPlaying = false;
base.CustomStopFeedback(position, feedbacksIntensity);
if (Active && DisableOnStop)
{
Turn(false);
}
if (_coroutine != null)
{
Owner.StopCoroutine(_coroutine);
}
_coroutine = null;
}
/// <summary>
/// Turns the sprite renderer on or off
/// </summary>
/// <param name="status"></param>
protected virtual void Turn(bool status)
{
BoundImage.gameObject.SetActive(status);
BoundImage.enabled = status;
}
/// <summary>
/// On restore, we restore our initial state
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
BoundImage.color = _initialColor;
}
/// <summary>
/// On Validate, we init our curves conditions if needed
/// </summary>
public override void OnValidate()
{
base.OnValidate();
if (string.IsNullOrEmpty(Curve.EnumConditionPropertyName))
{
Curve.EnumConditionPropertyName = "Mode";
Curve.EnumConditions = new bool[32];
Curve.EnumConditions[(int)Modes.OverTime] = true;
Curve.EnumConditions[(int)Modes.ToDestination] = true;
}
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 14a47d8bf77ba3943a535dae0d46e99d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_ImageAlpha.cs
uploadId: 830868

View File

@@ -0,0 +1,247 @@
#if MM_UI
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you change the fill value of a target Image over time.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you modify the fill value of a target Image over time.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("UI/Image Fill")]
public class MMF_ImageFill : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
public override bool EvaluateRequiresSetup() { return (BoundImage == null); }
public override string RequiredTargetText { get { return BoundImage != null ? BoundImage.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a BoundImage be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasCustomInspectors => true;
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => BoundImage = FindAutomatedTarget<Image>();
/// the possible modes for this feedback
public enum Modes { OverTime, Instant, ToDestination }
[MMFInspectorGroup("Target Image", true, 12, true)]
/// the Image to affect when playing the feedback
[Tooltip("the Image to affect when playing the feedback")]
public Image BoundImage;
[MMFInspectorGroup("Image Fill Animation", true, 24)]
/// whether the feedback should affect the Image instantly or over a period of time
[Tooltip("whether the feedback should affect the Image instantly or over a period of time")]
public Modes Mode = Modes.OverTime;
/// how long the Image should change over time
[Tooltip("how long the Image should change over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime, (int)Modes.ToDestination)]
public float Duration = 0.2f;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// the fill to move to in instant mode
[Tooltip("the fill to move to in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public float InstantFill = 1f;
/// the curve to use when interpolating towards the destination fill
[Tooltip("the curve to use when interpolating towards the destination fill")]
public MMTweenType Curve = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic, "", "Mode", (int)Modes.OverTime, (int)Modes.ToDestination);
/// the value to which the curve's 0 should be remapped
[Tooltip("the value to which the curve's 0 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float CurveRemapZero = 0f;
/// the value to which the curve's 1 should be remapped
[Tooltip("the value to which the curve's 1 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float CurveRemapOne = 1f;
/// the fill to aim towards when in ToDestination mode
[Tooltip("the fill to aim towards when in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationFill = 1f;
/// if this is true, the target will be disabled when this feedbacks is stopped
[Tooltip("if this is true, the target will be disabled when this feedbacks is stopped")]
public bool DisableOnStop = false;
/// the duration of this feedback is the duration of the Image, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { Duration = value; } }
protected Coroutine _coroutine;
protected float _initialFill;
protected float _initialInstantFill;
protected bool _initialState;
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if (BoundImage == null)
{
Debug.LogWarning("[Image Fill Feedback] The image fill feedback on "+Owner.name+" doesn't have a bound image, it won't work. You need to specify an image in its inspector.");
return;
}
if (Active)
{
_initialInstantFill = BoundImage.fillAmount;
}
}
/// <summary>
/// On Play we turn our Image on and start an over time coroutine if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (BoundImage == null))
{
return;
}
_initialState = BoundImage.gameObject.activeInHierarchy;
Turn(true);
_initialFill = BoundImage.fillAmount;
switch (Mode)
{
case Modes.Instant:
BoundImage.fillAmount = NormalPlayDirection ? InstantFill : _initialInstantFill;
break;
case Modes.OverTime:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ImageSequence());
break;
case Modes.ToDestination:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ImageSequence());
break;
}
}
/// <summary>
/// This coroutine will modify the values on the Image
/// </summary>
/// <returns></returns>
protected virtual IEnumerator ImageSequence()
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
_initialFill = BoundImage.fillAmount;
IsPlaying = true;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
SetFill(remappedTime);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
SetFill(FinalNormalizedTime);
_coroutine = null;
IsPlaying = false;
yield return null;
}
/// <summary>
/// Sets the various values on the sprite renderer on a specified time (between 0 and 1)
/// </summary>
/// <param name="time"></param>
protected virtual void SetFill(float time)
{
float newFill = 0f;
if (Mode == Modes.OverTime)
{
newFill = MMTween.Tween(time, 0f, 1f, CurveRemapZero, CurveRemapOne, Curve);
}
else if (Mode == Modes.ToDestination)
{
newFill = MMTween.Tween(time, 0f, 1f, _initialFill, DestinationFill, Curve);
}
BoundImage.fillAmount = newFill;
}
/// <summary>
/// Turns the sprite renderer off on stop
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
IsPlaying = false;
base.CustomStopFeedback(position, feedbacksIntensity);
if (Active && DisableOnStop)
{
Turn(false);
}
if (_coroutine != null)
{
Owner.StopCoroutine(_coroutine);
}
_coroutine = null;
}
/// <summary>
/// Turns the sprite renderer on or off
/// </summary>
/// <param name="status"></param>
protected virtual void Turn(bool status)
{
BoundImage.gameObject.SetActive(status);
BoundImage.enabled = status;
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
Turn(_initialState);
BoundImage.fillAmount = _initialFill;
}
/// <summary>
/// On Validate, we init our curves conditions if needed
/// </summary>
public override void OnValidate()
{
base.OnValidate();
if (string.IsNullOrEmpty(Curve.EnumConditionPropertyName))
{
Curve.EnumConditionPropertyName = "Mode";
Curve.EnumConditions = new bool[32];
Curve.EnumConditions[(int)Modes.OverTime] = true;
Curve.EnumConditions[(int)Modes.ToDestination] = true;
}
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 95530134bb5ab7b4a959774f63c2e92f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_ImageFill.cs
uploadId: 830868

View File

@@ -0,0 +1,87 @@
using System.Collections;
using UnityEngine;
#if MM_UI
using MoreMountains.Tools;
using UnityEngine.UI;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you change the layer of a target game object when playing the feedback
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you change the layer of a target game object when playing the feedback")]
[System.Serializable]
[FeedbackPath("GameObject/Layer")]
public class MMF_Layer : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.GameObjectColor; } }
public override bool EvaluateRequiresSetup() { return (TargetGameObject == null); }
public override string RequiredTargetText { get { return TargetGameObject != null ? TargetGameObject.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a TargetGameObject be set to be able to work properly. You can set one below."; } }
#endif
/// the duration of this feedback is the duration of the Graphic, or 0 if instant
public override float FeedbackDuration { get { return 0f; } }
public override bool HasChannel => false;
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => TargetGameObject = FindAutomatedTarget<GameObject>();
[MMFInspectorGroup("Graphic", true, 54, true)]
/// the game object you want to change the layer on
[Tooltip("the game object you want to change the layer on")]
public GameObject TargetGameObject;
/// the new layer to assign to the target game object
[Tooltip("the new layer to assign to the target game object")]
[MMLayer]
public int NewLayer;
protected int _initialLayer;
/// <summary>
/// On init we store the initial layer
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if (Active && TargetGameObject != null)
{
_initialLayer = TargetGameObject.layer;
}
}
/// <summary>
/// On Play we change our object's layer to the New Layer
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (TargetGameObject == null))
{
return;
}
TargetGameObject.layer = NewLayer;
}
/// <summary>
/// On restore, we restore our initial layer
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
TargetGameObject.layer = _initialLayer;
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 688b4ab22ad89b24895a20351c49f7d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Layer.cs
uploadId: 830868

View File

@@ -0,0 +1,217 @@
using System.Collections;
using UnityEngine;
using MoreMountains.Tools;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you change the width and color of a target line renderer over time
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you change the width and color of a target line renderer over time")]
[System.Serializable]
[FeedbackPath("Renderer/Line Renderer")]
public class MMF_LineRenderer : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.RendererColor; } }
public override bool EvaluateRequiresSetup() => (TargetLineRenderer == null);
public override string RequiredTargetText => TargetLineRenderer != null ? TargetLineRenderer.name : "";
public override string RequiresSetupText => "This feedback requires that a TargetLineRenderer be set to be able to work properly. You can set one below.";
#endif
public override bool HasRandomness => true;
public override bool HasCustomInspectors => true;
/// the possible modes for this feedback
public enum Modes { OverTime, Instant }
[MMFInspectorGroup("Line Renderer", true, 24, true)]
/// the line renderer whose properties you want to modify
[Tooltip("the line renderer whose properties you want to modify")]
public LineRenderer TargetLineRenderer;
/// whether the feedback should affect the sprite renderer instantly or over a period of time
[Tooltip("whether the feedback should affect the sprite renderer instantly or over a period of time")]
public Modes Mode = Modes.OverTime;
/// how long the sprite renderer should change over time
[Tooltip("how long the sprite renderer should change over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float Duration = 2f;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// a curve to use to animate the line renderer's density over time
[Tooltip("a curve to use to animate the line renderer's density over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public MMTweenType Transition = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)));
[MMFInspectorGroup("Width", true, 25)]
/// whether or not to modify the line renderer's width
[Tooltip("whether or not to modify the line renderer's width")]
public bool ModifyWidth = true;
/// a curve defining the new width of the line renderer, describing the world space width of the line at each point along its length
[Tooltip("a curve defining the new width of the line renderer, describing the world space width of the line at each point along its length")]
public AnimationCurve NewWidth = new AnimationCurve(new Keyframe(0, 1), new Keyframe(1, 0));
[MMFInspectorGroup("Color", true, 28)]
/// whether or not to modify the line renderer's color
[Tooltip("whether or not to modify the line renderer's color")]
public bool ModifyColor = true;
/// the colors to apply to the sprite renderer over time
[Tooltip("the colors to apply to the sprite renderer over time")]
public Gradient NewColor = new Gradient();
/// the duration of this feedback is the duration of the sprite renderer, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { if (Mode != Modes.Instant) { Duration = value; } } }
protected Coroutine _coroutine;
protected Gradient _initialColor;
protected AnimationCurve _initialWidth;
protected Gradient _firstColor;
protected AnimationCurve _firstWidth;
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if (Active)
{
if (TargetLineRenderer == null)
{
Debug.LogWarning("[Line Renderer Feedback] The line renderer feedback on "+Owner.name+" doesn't have a TargetLineRenderer, it won't work. You need to specify one in its inspector.");
return;
}
_firstColor = TargetLineRenderer.colorGradient;
_firstWidth = TargetLineRenderer.widthCurve;
}
}
/// <summary>
/// On Play we change the values of our line renderer
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (TargetLineRenderer == null))
{
return;
}
_initialColor = TargetLineRenderer.colorGradient;
_initialWidth = TargetLineRenderer.widthCurve;
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
switch (Mode)
{
case Modes.Instant:
if (ModifyColor)
{
TargetLineRenderer.colorGradient = NormalPlayDirection ? NewColor : _firstColor;
}
if (ModifyWidth)
{
TargetLineRenderer.widthCurve = NormalPlayDirection ? NewWidth : _firstWidth;
}
break;
case Modes.OverTime:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(LineRendererSequence(intensityMultiplier));
break;
}
}
/// <summary>
/// This coroutine will modify the values on the line renderer over time
/// </summary>
/// <returns></returns>
protected virtual IEnumerator LineRendererSequence(float intensityMultiplier)
{
IsPlaying = true;
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
remappedTime = Transition.Evaluate(remappedTime);
SetLineRendererValues(remappedTime, intensityMultiplier);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
SetLineRendererValues(Transition.Evaluate(FinalNormalizedTime), intensityMultiplier);
_coroutine = null;
IsPlaying = false;
yield return null;
}
/// <summary>
/// Sets the various values on the line renderer on a specified time (between 0 and 1)
/// </summary>
/// <param name="time"></param>
protected virtual void SetLineRendererValues(float time, float intensityMultiplier)
{
if (ModifyColor)
{
if (NormalPlayDirection)
{
TargetLineRenderer.colorGradient = MMColors.LerpGradients(_initialColor, NewColor, time);
}
else
{
TargetLineRenderer.colorGradient = MMColors.LerpGradients(NewColor, _firstColor, time);
}
}
if (ModifyWidth)
{
if (NormalPlayDirection)
{
TargetLineRenderer.widthCurve = MMAnimationCurves.LerpAnimationCurves(_initialWidth, NewWidth, time);
}
else
{
TargetLineRenderer.widthCurve = MMAnimationCurves.LerpAnimationCurves(NewWidth, _firstWidth, time);
}
}
}
/// <summary>
/// Stops this feedback
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized || (_coroutine == null))
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
IsPlaying = false;
Owner.StopCoroutine(_coroutine);
_coroutine = null;
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
TargetLineRenderer.widthCurve = _firstWidth;
TargetLineRenderer.colorGradient = _firstColor;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d9316d13625724948a6824fbd529a617
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_LineRenderer.cs
uploadId: 830868

View File

@@ -0,0 +1,155 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.SceneManagement;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will request the load of a new scene, using the method of your choice
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will request the load of a new scene, using the method of your choice")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Scene/Load Scene")]
public class MMF_LoadScene : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SceneColor; } }
public override bool EvaluateRequiresSetup() { return (DestinationSceneName == ""); }
public override string RequiredTargetText { get { return DestinationSceneName; } }
public override string RequiresSetupText { get { return "This feedback requires that you specify a DestinationSceneName below. Make sure you also add that destination scene to your Build Settings."; } }
#endif
/// the possible ways to load a new scene :
/// - direct : uses Unity's SceneManager API
/// - direct additive : uses Unity's SceneManager API, but with additive mode (so loading the scene on top of the current one)
/// - MMSceneLoadingManager : the simple, original MM way of loading scenes
/// - MMAdditiveSceneLoadingManager : a more advanced way of loading scenes, with (way) more options
public enum LoadingModes { Direct, MMSceneLoadingManager, MMAdditiveSceneLoadingManager, DirectAdditive }
[MMFInspectorGroup("Scene Loading", true, 57, true)]
/// the name of the loading screen scene to use
[Tooltip("the name of the loading screen scene to use - HAS TO BE ADDED TO YOUR BUILD SETTINGS")]
public string LoadingSceneName = "MMAdditiveLoadingScreen";
/// the name of the destination scene
[Tooltip("the name of the destination scene - HAS TO BE ADDED TO YOUR BUILD SETTINGS")]
public string DestinationSceneName = "";
[Header("Mode")]
/// the loading mode to use
[Tooltip("the loading mode to use to load the destination scene : " +
"- direct : uses Unity's SceneManager API" +
"- MMSceneLoadingManager : the simple, original MM way of loading scenes" +
"- MMAdditiveSceneLoadingManager : a more advanced way of loading scenes, with (way) more options")]
public LoadingModes LoadingMode = LoadingModes.MMAdditiveSceneLoadingManager;
[Header("Loading Scene Manager")]
/// the priority to use when loading the new scenes
[Tooltip("the priority to use when loading the new scenes")]
public ThreadPriority Priority = ThreadPriority.High;
/// whether or not to perform extra checks to make sure the loading screen and destination scene are in the build settings
[Tooltip("whether or not to perform extra checks to make sure the loading screen and destination scene are in the build settings")]
public bool SecureLoad = true;
/// the chosen way to unload scenes (none, only the active scene, all loaded scenes)
[Tooltip("the chosen way to unload scenes (none, only the active scene, all loaded scenes)")]
[MMFEnumCondition("LoadingMode", (int)LoadingModes.MMAdditiveSceneLoadingManager)]
public MMAdditiveSceneLoadingManagerSettings.UnloadMethods UnloadMethod =
MMAdditiveSceneLoadingManagerSettings.UnloadMethods.AllScenes;
/// the name of the anti spill scene to use when loading additively.
/// If left empty, that scene will be automatically created, but you can specify any scene to use for that. Usually you'll want your own anti spill scene to be just an empty scene, but you can customize its lighting settings for example.
[Tooltip("the name of the anti spill scene to use when loading additively." +
"If left empty, that scene will be automatically created, but you can specify any scene to use for that. Usually you'll want your own anti spill scene to be just an empty scene, but you can customize its lighting settings for example.")]
[MMFEnumCondition("LoadingMode", (int)LoadingModes.MMAdditiveSceneLoadingManager)]
public string AntiSpillSceneName = "";
/// in additive mode, whether or not to display debug logs of the loading sequence
[Tooltip("in additive mode, whether or not to display debug logs of the loading sequence")]
[MMFEnumCondition("LoadingMode", (int)LoadingModes.MMAdditiveSceneLoadingManager)]
public bool DebugMode = false;
[MMFInspectorGroup("Loading Scene Delays", true, 58)]
/// a delay (in seconds) to apply before the first fade plays
[Tooltip("a delay (in seconds) to apply before the first fade plays")]
public float BeforeEntryFadeDelay = 0f;
/// the duration (in seconds) of the entry fade
[Tooltip("the duration (in seconds) of the entry fade")]
public float EntryFadeDuration = 0.2f;
/// a delay (in seconds) to apply after the first fade plays
[Tooltip("a delay (in seconds) to apply after the first fade plays")]
public float AfterEntryFadeDelay = 0f;
/// a delay (in seconds) to apply before the scene gets activated
[Tooltip("a delay (in seconds) to apply before the scene gets activated")]
public float BeforeSceneActivationDelay = 0f;
/// a delay applied after the scene is loaded
[Tooltip("a delay applied after the scene is loaded")]
public float AfterSceneActivationDelay = 0f;
/// the duration (in seconds) of the exit fade
[Tooltip("the duration (in seconds) of the exit fade")]
public float ExitFadeDuration = 0.2f;
[MMFInspectorGroup("Speed", true, 59)]
/// whether or not to interpolate progress (slower, but usually looks better and smoother)
[Tooltip("whether or not to interpolate progress (slower, but usually looks better and smoother)")]
public bool InterpolateProgress = true;
/// the speed at which the progress bar should move if interpolated
[Tooltip("the speed at which the progress bar should move if interpolated")]
public float ProgressInterpolationSpeed = 5f;
/// a list of progress intervals (values should be between 0 and 1) and their associated speeds, letting you have the bar progress less linearly
[Tooltip("a list of progress intervals (values should be between 0 and 1) and their associated speeds, letting you have the bar progress less linearly")]
public List<MMSceneLoadingSpeedInterval> SpeedIntervals;
[MMFInspectorGroup("Transitions", true, 59)]
/// the order in which to play fades (really depends on the type of fader you have in your loading screen
[Tooltip("the order in which to play fades (really depends on the type of fader you have in your loading screen")]
public MMAdditiveSceneLoadingManager.FadeModes FadeMode = MMAdditiveSceneLoadingManager.FadeModes.FadeInThenOut;
/// the tween to use on the entry fade
[Tooltip("the tween to use on the entry fade")]
public MMTweenType EntryFadeTween = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)));
/// the tween to use on the exit fade
[Tooltip("the tween to use on the exit fade")]
public MMTweenType ExitFadeTween = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)));
/// <summary>
/// On play, we request a load of the destination scene using hte specified method
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (DestinationSceneName == ""))
{
return;
}
switch (LoadingMode)
{
case LoadingModes.Direct:
SceneManager.LoadScene(DestinationSceneName);
break;
case LoadingModes.DirectAdditive:
SceneManager.LoadScene(DestinationSceneName, LoadSceneMode.Additive);
break;
case LoadingModes.MMSceneLoadingManager:
MMSceneLoadingManager.LoadScene(DestinationSceneName, LoadingSceneName);
break;
case LoadingModes.MMAdditiveSceneLoadingManager:
MMAdditiveSceneLoadingManager.LoadScene(DestinationSceneName, LoadingSceneName,
Priority, SecureLoad, InterpolateProgress,
BeforeEntryFadeDelay, EntryFadeDuration,
AfterEntryFadeDelay,
BeforeSceneActivationDelay,
AfterSceneActivationDelay,
ExitFadeDuration,
EntryFadeTween, ExitFadeTween,
ProgressInterpolationSpeed, FadeMode, UnloadMethod, AntiSpillSceneName,
SpeedIntervals, DebugMode);
break;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b4f6df1207b1c5e478e225b94a41fa42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_LoadScene.cs
uploadId: 830868

View File

@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will trigger a MMGameEvent of the specified name when played
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will trigger a MMGameEvent of the specified name when played")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Events/MMGameEvent")]
public class MMF_MMGameEvent : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.EventsColor; } }
public override bool EvaluateRequiresSetup() { return (MMGameEventName == ""); }
public override string RequiredTargetText { get { return MMGameEventName; } }
public override string RequiresSetupText { get { return "This feedback requires that you specify a MMGameEventName below."; } }
#endif
[MMFInspectorGroup("MMGameEvent", true, 57, true)]
public string MMGameEventName;
[MMFInspectorGroup("Optional Payload", true, 58, true)]
public int IntParameter;
public Vector2 Vector2Parameter;
public Vector3 Vector3Parameter;
public bool BoolParameter;
public string StringParameter;
/// <summary>
/// On Play we change the values of our fog
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMGameEvent.Trigger(MMGameEventName, IntParameter, Vector2Parameter, Vector3Parameter, BoolParameter, StringParameter);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5093ea98124b9ba4f88d699459437e2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMGameEvent.cs
uploadId: 830868

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// A feedback used to control all sounds playing on the MMSoundManager at once. It'll let you pause, play, stop and free (stop and returns the audiosource to the pool) sounds. You will need a MMSoundManager in your scene for this to work.
/// </summary>
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager All Sounds Control")]
[FeedbackHelp("A feedback used to control all sounds playing on the MMSoundManager at once. It'll let you pause, play, stop and free (stop and returns the audiosource to the pool) sounds. You will need a MMSoundManager in your scene for this to work.")]
public class MMF_MMSoundManagerAllSoundsControl : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get { return ControlMode.ToString(); } }
#endif
[MMFInspectorGroup("MMSoundManager All Sounds Control", true, 30)]
/// The selected control mode.
[Tooltip("The selected control mode")]
public MMSoundManagerAllSoundsControlEventTypes ControlMode = MMSoundManagerAllSoundsControlEventTypes.Pause;
/// <summary>
/// On Play, we call the specified event, to be caught by the MMSoundManager
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
switch (ControlMode)
{
case MMSoundManagerAllSoundsControlEventTypes.Pause:
MMSoundManagerAllSoundsControlEvent.Trigger(MMSoundManagerAllSoundsControlEventTypes.Pause);
break;
case MMSoundManagerAllSoundsControlEventTypes.Play:
MMSoundManagerAllSoundsControlEvent.Trigger(MMSoundManagerAllSoundsControlEventTypes.Play);
break;
case MMSoundManagerAllSoundsControlEventTypes.Stop:
MMSoundManagerAllSoundsControlEvent.Trigger(MMSoundManagerAllSoundsControlEventTypes.Stop);
break;
case MMSoundManagerAllSoundsControlEventTypes.Free:
MMSoundManagerAllSoundsControlEvent.Trigger(MMSoundManagerAllSoundsControlEventTypes.Free);
break;
case MMSoundManagerAllSoundsControlEventTypes.FreeAllButPersistent:
MMSoundManagerAllSoundsControlEvent.Trigger(MMSoundManagerAllSoundsControlEventTypes.FreeAllButPersistent);
break;
case MMSoundManagerAllSoundsControlEventTypes.FreeAllLooping:
MMSoundManagerAllSoundsControlEvent.Trigger(MMSoundManagerAllSoundsControlEventTypes.FreeAllLooping);
break;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f641f9c946f40f346b424ed65100be88
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerAllSoundsControl.cs
uploadId: 830868

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you trigger save, load, and reset on MMSoundManager settings. You will need a MMSoundManager in your scene for this to work.
/// </summary>
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager Save and Load")]
[FeedbackHelp("This feedback will let you trigger save, load, and reset on MMSoundManager settings. You will need a MMSoundManager in your scene for this to work.")]
public class MMF_MMSoundManagerSaveLoad : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get { return Mode.ToString(); } }
#endif
/// the possible modes you can use to interact with save settings
public enum Modes { Save, Load, Reset }
[MMFInspectorGroup("MMSoundManager Save and Load", true, 30)]
/// the selected mode to interact with save settings on the MMSoundManager
[Tooltip("the selected mode to interact with save settings on the MMSoundManager")]
public Modes Mode = Modes.Save;
/// <summary>
/// On Play, saves, loads or resets settings
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
switch (Mode)
{
case Modes.Save:
MMSoundManagerEvent.Trigger(MMSoundManagerEventTypes.SaveSettings);
break;
case Modes.Load:
MMSoundManagerEvent.Trigger(MMSoundManagerEventTypes.LoadSettings);
break;
case Modes.Reset:
MMSoundManagerEvent.Trigger(MMSoundManagerEventTypes.ResetSettings);
break;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 685b5496a166328449da980c010a79f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerSaveLoad.cs
uploadId: 830868

View File

@@ -0,0 +1,872 @@
using System;
using System.Collections;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;
using UnityEngine.Scripting.APIUpdating;
using UnityEngine.Serialization;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you play a sound via the MMSoundManager. You will need a game object in your scene with a MMSoundManager object on it for this to work.
/// </summary>
[ExecuteAlways]
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager Sound")]
[FeedbackHelp("This feedback will let you play a sound via the MMSoundManager. You will need a game object in your scene with a MMSoundManager object on it for this to work.")]
public class MMF_MMSoundManagerSound : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override bool HasCustomInspectors => true;
public override bool HasAutomaticShakerSetup => true;
public override bool EvaluateRequiresSetup()
{
bool requiresSetup = false;
if (Sfx == null)
{
requiresSetup = true;
}
if ((RandomSfx != null) && (RandomSfx.Length > 0))
{
requiresSetup = false;
foreach (AudioClip clip in RandomSfx)
{
if (clip == null)
{
requiresSetup = true;
}
}
}
if (SoundDataSO != null)
{
requiresSetup = false;
}
return requiresSetup;
}
public override string RequiredTargetText { get { return Sfx != null ? Sfx.name + " - ID:" + ID : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that you set an Audio clip in its Sfx slot below, or one or more clips in the Random Sfx array."; } }
#endif
/// the duration of this feedback is the duration of the clip being played
public override float FeedbackDuration { get { return GetDuration(); } }
public override bool HasRandomness => true;
public enum Sources { AudioClip, AudioResource }
[MMFInspectorGroup("Sound", true, 14, true)]
/// whether this feedback should play an audio clip or an AudioResource
[Tooltip("whether this feedback should play an audio clip or an AudioResource")]
public Sources Source = Sources.AudioClip;
/// the sound clip to play
[Tooltip("the sound clip to play")]
[MMFEnumCondition("Source", (int)Sources.AudioClip)]
public AudioClip Sfx;
/// alternatively, instead of an audio clip you can specify an AudioResource, in which case the Sfx above will be ignored, and the AudioResource will be used
[Tooltip("alternatively, instead of an audio clip you can specify an AudioResource, in which case the Sfx above will be ignored, and the AudioResource will be used")]
[MMFEnumCondition("Source", (int)Sources.AudioResource)]
public AudioResource AudioResourceToPlay;
[MMFInspectorGroup("Random Sound", true, 39, true)]
/// an array to pick a random sfx from
[Tooltip("an array to pick a random sfx from")]
public AudioClip[] RandomSfx;
/// if this is true, random sfx audio clips will be played in sequential order instead of at random
[Tooltip("if this is true, random sfx audio clips will be played in sequential order instead of at random")]
public bool SequentialOrder = false;
/// if we're in sequential order, determines whether or not to hold at the last index, until either a cooldown is met, or the ResetSequentialIndex method is called
[Tooltip("if we're in sequential order, determines whether or not to hold at the last index, until either a cooldown is met, or the ResetSequentialIndex method is called")]
[MMFCondition("SequentialOrder", true)]
public bool SequentialOrderHoldLast = false;
/// if we're in sequential order hold last mode, index will reset to 0 automatically after this duration, unless it's 0, in which case it'll be ignored
[Tooltip("if we're in sequential order hold last mode, index will reset to 0 automatically after this duration, unless it's 0, in which case it'll be ignored")]
[MMFCondition("SequentialOrderHoldLast", true)]
public float SequentialOrderHoldCooldownDuration = 2f;
/// if this is true, sfx will be picked at random until all have been played. once this happens, the list is shuffled again, and it starts over
[Tooltip("if this is true, sfx will be picked at random until all have been played. once this happens, the list is shuffled again, and it starts over")]
public bool RandomUnique = false;
[MMFInspectorGroup("Scriptable Object", true, 14, true)]
/// a scriptable object (created via the Create/MoreMountains/Audio/MMF_SoundData menu) to define settings that will override all other settings on this feedback
[Tooltip("a scriptable object (created via the Create/MoreMountains/Audio/MMF_SoundData menu) to define settings that will override all other settings on this feedback")]
public MMF_MMSoundManagerSoundData SoundDataSO;
[MMFInspectorGroup("Sound Properties", true, 24)]
[Header("Volume")]
/// the minimum volume to play the sound at
[Tooltip("the minimum volume to play the sound at")]
[Range(0f,2f)]
public float MinVolume = 1f;
/// the maximum volume to play the sound at
[Tooltip("the maximum volume to play the sound at")]
[Range(0f,2f)]
public float MaxVolume = 1f;
[Header("Pitch")]
/// the minimum pitch to play the sound at
[Tooltip("the minimum pitch to play the sound at")]
[Range(-3f,3f)]
public float MinPitch = 1f;
/// the maximum pitch to play the sound at
[Tooltip("the maximum pitch to play the sound at")]
[Range(-3f,3f)]
public float MaxPitch = 1f;
[MMFInspectorGroup("SoundManager Options", true, 28)]
/// the track on which to play the sound. Pick the one that matches the nature of your sound
[Tooltip("the track on which to play the sound. Pick the one that matches the nature of your sound")]
public MMSoundManager.MMSoundManagerTracks MmSoundManagerTrack = MMSoundManager.MMSoundManagerTracks.Sfx;
/// the ID of the sound. This is useful if you plan on using sound control feedbacks on it afterwards.
[Tooltip("the ID of the sound. This is useful if you plan on using sound control feedbacks on it afterwards.")]
public int ID = 0;
/// the AudioGroup on which to play the sound. If you're already targeting a preset track, you can leave it blank, otherwise the group you specify here will override it.
[Tooltip("the AudioGroup on which to play the sound. If you're already targeting a preset track, you can leave it blank, otherwise the group you specify here will override it.")]
public AudioMixerGroup AudioGroup = null;
/// if (for some reason) you've already got an audiosource and wouldn't like to use the built-in pool system, you can specify it here
[Tooltip("if (for some reason) you've already got an audiosource and wouldn't like to use the built-in pool system, you can specify it here")]
public AudioSource RecycleAudioSource = null;
/// whether or not this sound should loop
[Tooltip("whether or not this sound should loop")]
public bool Loop = false;
/// whether or not this sound should continue playing when transitioning to another scene
[Tooltip("whether or not this sound should continue playing when transitioning to another scene")]
public bool Persistent = false;
/// whether or not this sound should play if the same sound clip is already playing
[Tooltip("whether or not this sound should play if the same sound clip is already playing")]
public bool DoNotPlayIfClipAlreadyPlaying = false;
/// the maximum amount of instances of this sound allowed to play at once. use -1 for unlimited concurrent plays
[Tooltip("the maximum amount of instances of this sound allowed to play at once. use -1 for unlimited concurrent plays")]
public int MaximumConcurrentInstances = 3;
/// if this is true, this sound will stop playing when stopping the feedback
[Tooltip("if this is true, this sound will stop playing when stopping the feedback")]
public bool StopSoundOnFeedbackStop = false;
[MMFInspectorGroup("Fade In", true, 30)]
/// whether or not to fade this sound in when playing it
[Tooltip("whether or not to fade this sound in when playing it")]
[FormerlySerializedAs("Fade")]
public bool FadeIn = false;
/// if fading, the volume at which to start the fade
[Tooltip("if fading, the volume at which to start the fade")]
[MMCondition("FadeIn", true)]
[FormerlySerializedAs("FadeInitialVolume")]
public float FadeInInitialVolume = 0f;
/// if fading, the duration of the fade, in seconds
[Tooltip("if fading, the duration of the fade, in seconds")]
[MMCondition("FadeIn", true)]
[FormerlySerializedAs("FadeDuration")]
public float FadeInDuration = 1f;
/// if fading, the tween over which to fade the sound
[Tooltip("if fading, the tween over which to fade the sound ")]
[FormerlySerializedAs("FadeTween")]
public MMTweenType FadeInTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutQuartic, "FadeIn");
[MMFInspectorGroup("Fade Out", true, 30)]
/// whether or not to fade this sound in when stopping the feedback
[Tooltip("whether or not to fade this sound in when stopping the feedback")]
public bool FadeOutOnStop = false;
/// if fading out, the duration of the fade, in seconds
[Tooltip("if fading out, the duration of the fade, in seconds")]
[MMCondition("FadeOutOnStop", true)]
public float FadeOutDuration = 1f;
/// if fading out, the tween over which to fade the sound
[Tooltip("if fading out, the tween over which to fade the sound ")]
public MMTweenType FadeOutTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutQuartic, "FadeOutOnStop");
[MMFInspectorGroup("Solo", true, 32)]
/// whether or not this sound should play in solo mode over its destination track. If yes, all other sounds on that track will be muted when this sound starts playing
[Tooltip("whether or not this sound should play in solo mode over its destination track. If yes, all other sounds on that track will be muted when this sound starts playing")]
public bool SoloSingleTrack = false;
/// whether or not this sound should play in solo mode over all other tracks. If yes, all other tracks will be muted when this sound starts playing
[Tooltip("whether or not this sound should play in solo mode over all other tracks. If yes, all other tracks will be muted when this sound starts playing")]
public bool SoloAllTracks = false;
/// if in any of the above solo modes, AutoUnSoloOnEnd will unmute the track(s) automatically once that sound stops playing
[Tooltip("if in any of the above solo modes, AutoUnSoloOnEnd will unmute the track(s) automatically once that sound stops playing")]
public bool AutoUnSoloOnEnd = false;
[MMFInspectorGroup("Spatial Settings", true, 33)]
/// Pans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.
[Tooltip("Pans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.")]
[Range(-1f,1f)]
public float PanStereo;
/// Sets how much this AudioSource is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D.
[Tooltip("Sets how much this AudioSource is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D.")]
[Range(0f,1f)]
public float SpatialBlend;
/// a Transform this sound can 'attach' to and follow it along as it plays
[Tooltip("a Transform this sound can 'attach' to and follow it along as it plays")]
public Transform AttachToTransform;
[MMFInspectorGroup("Effects", true, 36)]
/// Bypass effects (Applied from filter components or global listener filters).
[Tooltip("Bypass effects (Applied from filter components or global listener filters).")]
public bool BypassEffects = false;
/// When set global effects on the AudioListener will not be applied to the audio signal generated by the AudioSource. Does not apply if the AudioSource is playing into a mixer group.
[Tooltip("When set global effects on the AudioListener will not be applied to the audio signal generated by the AudioSource. Does not apply if the AudioSource is playing into a mixer group.")]
public bool BypassListenerEffects = false;
/// When set doesn't route the signal from an AudioSource into the global reverb associated with reverb zones.
[Tooltip("When set doesn't route the signal from an AudioSource into the global reverb associated with reverb zones.")]
public bool BypassReverbZones = false;
/// Sets the priority of the AudioSource.
[Tooltip("Sets the priority of the AudioSource.")]
[Range(0, 256)]
public int Priority = 128;
/// The amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.
[Tooltip("The amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.")]
[Range(0f,1.1f)]
public float ReverbZoneMix = 1f;
[MMFInspectorGroup("Time Options", true, 15)]
/// a timestamp (in seconds, randomized between the defined min and max) at which the sound will start playing, equivalent to the Audiosource API's Time)
[Tooltip("a timestamp (in seconds, randomized between the defined min and max) at which the sound will start playing, equivalent to the Audiosource API's Time)")]
[MMVector("Min", "Max")]
public Vector2 PlaybackTime = new Vector2(0f, 0f);
/// a duration (in seconds, randomized between the defined min and max) for which the sound will play before stopping. Ignored if min and max are zero.
[Tooltip("a duration (in seconds, randomized between the defined min and max) for which the sound will play before stopping. Ignored if min and max are zero.")]
[MMVector("Min", "Max")]
public Vector2 PlaybackDuration = new Vector2(0f, 0f);
[MMFInspectorGroup("3D Sound Settings", true, 37)]
/// Sets the Doppler scale for this AudioSource.
[Tooltip("Sets the Doppler scale for this AudioSource.")]
[Range(0f,5f)]
public float DopplerLevel = 1f;
/// Sets the spread angle (in degrees) of a 3d stereo or multichannel sound in speaker space.
[Tooltip("Sets the spread angle (in degrees) of a 3d stereo or multichannel sound in speaker space.")]
[Range(0,360)]
public int Spread = 0;
/// Sets/Gets how the AudioSource attenuates over distance.
[Tooltip("Sets/Gets how the AudioSource attenuates over distance.")]
public AudioRolloffMode RolloffMode = AudioRolloffMode.Logarithmic;
/// Within the Min distance the AudioSource will cease to grow louder in volume.
[Tooltip("Within the Min distance the AudioSource will cease to grow louder in volume.")]
public float MinDistance = 1f;
/// (Logarithmic rolloff) MaxDistance is the distance a sound stops attenuating at.
[Tooltip("(Logarithmic rolloff) MaxDistance is the distance a sound stops attenuating at.")]
public float MaxDistance = 500f;
/// whether or not to use a custom curve for custom volume rolloff
[Tooltip("whether or not to use a custom curve for custom volume rolloff")]
public bool UseCustomRolloffCurve = false;
/// the curve to use for custom volume rolloff if UseCustomRolloffCurve is true
[Tooltip("the curve to use for custom volume rolloff if UseCustomRolloffCurve is true")]
[MMFCondition("UseCustomRolloffCurve", true)]
public AnimationCurve CustomRolloffCurve;
/// whether or not to use a custom curve for spatial blend
[Tooltip("whether or not to use a custom curve for spatial blend")]
public bool UseSpatialBlendCurve = false;
/// the curve to use for custom spatial blend if UseSpatialBlendCurve is true
[Tooltip("the curve to use for custom spatial blend if UseSpatialBlendCurve is true")]
[MMFCondition("UseSpatialBlendCurve", true)]
public AnimationCurve SpatialBlendCurve;
/// whether or not to use a custom curve for reverb zone mix
[Tooltip("whether or not to use a custom curve for reverb zone mix")]
public bool UseReverbZoneMixCurve = false;
/// the curve to use for custom reverb zone mix if UseReverbZoneMixCurve is true
[Tooltip("the curve to use for custom reverb zone mix if UseReverbZoneMixCurve is true")]
[MMFCondition("UseReverbZoneMixCurve", true)]
public AnimationCurve ReverbZoneMixCurve;
/// whether or not to use a custom curve for spread
[Tooltip("whether or not to use a custom curve for spread")]
public bool UseSpreadCurve = false;
/// the curve to use for custom spread if UseSpreadCurve is true
[Tooltip("the curve to use for custom spread if UseSpreadCurve is true")]
[MMFCondition("UseSpreadCurve", true)]
public AnimationCurve SpreadCurve;
[MMFInspectorGroup("Debug", true, 31)]
/// whether or not to draw sound falloff gizmos when this MMF Player is selected
[Tooltip("whether or not to draw sound falloff gizmos when this MMF Player is selected")]
public bool DrawGizmos = false;
/// an object to use as the center of the gizmos. If left empty, this MMF Player's position will be used.
[Tooltip("an object to use as the center of the gizmos. If left empty, this MMF Player's position will be used.")]
[MMFCondition("DrawGizmos", true)]
public Transform GizmosCenter;
/// the color to use to draw the min distance sphere of the sound falloff gizmos
[Tooltip("the color to use to draw the min distance sphere of the sound falloff gizmos")]
[MMFCondition("DrawGizmos", true)]
public Color MinDistanceColor = MMColors.CadetBlue;
/// the color to use to draw the max distance sphere of the sound falloff gizmos
[Tooltip("the color to use to draw the max distance sphere of the sound falloff gizmos")]
[MMFCondition("DrawGizmos", true)]
public Color MaxDistanceColor = MMColors.Orangered;
/// a test button used to play the sound in inspector
public MMF_Button TestPlayButton;
/// a test button used to stop the sound in inspector
public MMF_Button TestStopButton;
/// a test button used to stop the sound in inspector
public MMF_Button ResetSequentialIndexButton;
protected AudioClip _randomClip;
protected AudioSource _editorAudioSource;
protected MMSoundManagerPlayOptions _options;
protected AudioSource _playedAudioSource;
protected float _randomPlaybackTime;
protected float _randomPlaybackDuration;
protected int _currentIndex = 0;
protected Vector3 _gizmoCenter;
protected MMShufflebag<int> _randomUniqueShuffleBag;
protected AudioClip _lastPlayedClip;
protected Coroutine _isPlayingCoroutine;
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
HandleSO();
_lastPlayedClip = null;
if (RandomSfx == null)
{
RandomSfx = Array.Empty<AudioClip>();
}
if (RandomUnique)
{
_randomUniqueShuffleBag = new MMShufflebag<int>(RandomSfx.Length);
for (int i = 0; i < RandomSfx.Length; i++)
{
_randomUniqueShuffleBag.Add(i,1);
}
}
}
/// <summary>
/// Initializes the debug buttons
/// </summary>
public override void InitializeCustomAttributes()
{
base.InitializeCustomAttributes();
TestPlayButton = new MMF_Button("Debug Play Sound", TestPlaySound);
TestStopButton = new MMF_Button("Debug Stop Sound", TestStopSound);
ResetSequentialIndexButton = new MMF_Button("Reset Sequential Index", ResetSequentialIndex);
}
/// <summary>
/// Plays either a random sound or the specified sfx
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
if (RandomSfx.Length > 0)
{
_randomClip = PickRandomClip();
if (_randomClip != null)
{
PlaySound(_randomClip, position, intensityMultiplier);
return;
}
}
if ((Sfx != null) || (AudioResourceToPlay != null))
{
PlaySound(Sfx, position, intensityMultiplier, AudioResourceToPlay);
return;
}
}
/// <summary>
/// On Stop, we stop our sound if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if (FadeOutOnStop)
{
Owner.StartCoroutine(FadeOutCo());
return;
}
StopSound();
}
protected virtual IEnumerator FadeOutCo()
{
if (_playedAudioSource == null)
{
yield break;
}
MMSoundManager.Instance.FadeSound(_playedAudioSource, FadeOutDuration, _playedAudioSource.volume, 0f, FadeOutTween);
yield return MMCoroutine.WaitFor(FadeOutDuration);
StopSound();
}
protected virtual void StopSound()
{
if (StopSoundOnFeedbackStop && (_playedAudioSource != null))
{
_playedAudioSource.Stop();
if (RecycleAudioSource == null)
{
MMSoundManager.Instance.FreeSound(_playedAudioSource);
}
if (_isPlayingCoroutine != null)
{
Owner.StopCoroutine(_isPlayingCoroutine);
_isPlayingCoroutine = null;
}
_playedAudioSource = null;
}
}
/// <summary>
/// If a scriptable object is specified, we grab its values
/// </summary>
protected virtual void HandleSO()
{
if (SoundDataSO == null)
{
return;
}
Sfx = SoundDataSO.Sfx;
RandomSfx = SoundDataSO.RandomSfx;
SequentialOrder = SoundDataSO.SequentialOrder;
SequentialOrderHoldLast = SoundDataSO.SequentialOrderHoldLast;
SequentialOrderHoldCooldownDuration = SoundDataSO.SequentialOrderHoldCooldownDuration;
RandomUnique = SoundDataSO.RandomUnique;
MinVolume = SoundDataSO.MinVolume;
MaxVolume = SoundDataSO.MaxVolume;
MinPitch = SoundDataSO.MinPitch;
MaxPitch = SoundDataSO.MaxPitch;
PlaybackTime = SoundDataSO.PlaybackTime;
PlaybackDuration = SoundDataSO.PlaybackDuration;
MmSoundManagerTrack = SoundDataSO.MmSoundManagerTrack;
ID = SoundDataSO.ID;
AudioGroup = SoundDataSO.AudioGroup;
RecycleAudioSource = SoundDataSO.RecycleAudioSource;
Loop = SoundDataSO.Loop;
Persistent = SoundDataSO.Persistent;
DoNotPlayIfClipAlreadyPlaying = SoundDataSO.DoNotPlayIfClipAlreadyPlaying;
MaximumConcurrentInstances = SoundDataSO.MaximumConcurrentInstances;
StopSoundOnFeedbackStop = SoundDataSO.StopSoundOnFeedbackStop;
FadeIn = SoundDataSO.FadeIn;
FadeInInitialVolume = SoundDataSO.FadeInInitialVolume;
FadeInDuration = SoundDataSO.FadeInDuration;
FadeInTween = SoundDataSO.FadeInTween;
FadeOutOnStop = SoundDataSO.FadeOutOnStop;
FadeOutDuration = SoundDataSO.FadeOutDuration;
FadeOutTween = SoundDataSO.FadeOutTween;
SoloSingleTrack = SoundDataSO.SoloSingleTrack;
SoloAllTracks = SoundDataSO.SoloAllTracks;
AutoUnSoloOnEnd = SoundDataSO.AutoUnSoloOnEnd;
PanStereo = SoundDataSO.PanStereo;
SpatialBlend = SoundDataSO.SpatialBlend;
if (AttachToTransform == null)
{
AttachToTransform = SoundDataSO.AttachToTransform;
}
BypassEffects = SoundDataSO.BypassEffects;
BypassListenerEffects = SoundDataSO.BypassListenerEffects;
BypassReverbZones = SoundDataSO.BypassReverbZones;
Priority = SoundDataSO.Priority;
ReverbZoneMix = SoundDataSO.ReverbZoneMix;
DopplerLevel = SoundDataSO.DopplerLevel;
Spread = SoundDataSO.Spread;
RolloffMode = SoundDataSO.RolloffMode;
MinDistance = SoundDataSO.MinDistance;
MaxDistance = SoundDataSO.MaxDistance;
UseCustomRolloffCurve = SoundDataSO.UseCustomRolloffCurve;
CustomRolloffCurve = SoundDataSO.CustomRolloffCurve;
UseSpatialBlendCurve = SoundDataSO.UseSpatialBlendCurve;
SpatialBlendCurve = SoundDataSO.SpatialBlendCurve;
UseReverbZoneMixCurve = SoundDataSO.UseReverbZoneMixCurve;
ReverbZoneMixCurve = SoundDataSO.ReverbZoneMixCurve;
UseSpreadCurve = SoundDataSO.UseSpreadCurve;
SpreadCurve = SoundDataSO.SpreadCurve;
}
/// <summary>
/// Randomizes playback time and playback duration
/// </summary>
public virtual void RandomizeTimes()
{
_randomPlaybackTime = Random.Range(PlaybackTime.x, PlaybackTime.y);
_randomPlaybackDuration = Random.Range(PlaybackDuration.x, PlaybackDuration.y);
Owner.ComputeCachedTotalDuration();
}
/// <summary>
/// Triggers a play sound event
/// </summary>
/// <param name="sfx"></param>
/// <param name="position"></param>
/// <param name="intensity"></param>
protected virtual void PlaySound(AudioClip sfx, Vector3 position, float intensity, AudioResource audioResource = null)
{
if (DoNotPlayIfClipAlreadyPlaying)
{
if ((MMSoundManager.Instance.FindByClip(sfx) != null) && (MMSoundManager.Instance.FindByClip(sfx).isPlaying))
{
return;
}
}
if (MaximumConcurrentInstances >= 0)
{
if (MMSoundManager.Instance.CurrentlyPlayingCount(sfx) >= MaximumConcurrentInstances)
{
return;
}
}
float volume = Random.Range(MinVolume, MaxVolume);
if (!Timing.ConstantIntensity)
{
volume = volume * intensity;
}
float pitch = Random.Range(MinPitch, MaxPitch);
RandomizeTimes();
int timeSamples = NormalPlayDirection ? 0 : sfx.samples - 1;
_options.AudioResourceToPlay = audioResource;
_options.MmSoundManagerTrack = MmSoundManagerTrack;
_options.Location = position;
_options.Loop = Loop;
_options.Volume = volume;
_options.ID = ID;
_options.Fade = FadeIn;
_options.FadeInitialVolume = FadeInInitialVolume;
_options.FadeDuration = FadeInDuration;
_options.FadeTween = FadeInTween;
_options.Persistent = Persistent;
_options.RecycleAudioSource = RecycleAudioSource;
_options.AudioGroup = AudioGroup;
_options.Pitch = pitch;
_options.PlaybackTime = _randomPlaybackTime;
_options.PlaybackDuration = _randomPlaybackDuration;
_options.PanStereo = PanStereo;
_options.SpatialBlend = SpatialBlend;
_options.SoloSingleTrack = SoloSingleTrack;
_options.SoloAllTracks = SoloAllTracks;
_options.AutoUnSoloOnEnd = AutoUnSoloOnEnd;
_options.BypassEffects = BypassEffects;
_options.BypassListenerEffects = BypassListenerEffects;
_options.BypassReverbZones = BypassReverbZones;
_options.Priority = Priority;
_options.ReverbZoneMix = ReverbZoneMix;
_options.DopplerLevel = DopplerLevel;
_options.Spread = Spread;
_options.RolloffMode = RolloffMode;
_options.MinDistance = MinDistance;
_options.MaxDistance = MaxDistance;
_options.AttachToTransform = AttachToTransform;
_options.UseSpreadCurve = UseSpreadCurve;
_options.SpreadCurve = SpreadCurve;
_options.UseCustomRolloffCurve = UseCustomRolloffCurve;
_options.CustomRolloffCurve = CustomRolloffCurve;
_options.UseSpatialBlendCurve = UseSpatialBlendCurve;
_options.SpatialBlendCurve = SpatialBlendCurve;
_options.UseReverbZoneMixCurve = UseReverbZoneMixCurve;
_options.ReverbZoneMixCurve = ReverbZoneMixCurve;
_options.DoNotAutoRecycleIfNotDonePlaying = true;
_playedAudioSource = MMSoundManagerSoundPlayEvent.Trigger(sfx, _options);
_isPlayingCoroutine = Owner.StartCoroutine(IsPlayingCoroutine());
_lastPlayTimestamp = FeedbackTime;
_lastPlayedClip = sfx;
}
/// <summary>
/// A coroutine used to determine if the sound is still playing or not
/// </summary>
/// <returns></returns>
protected virtual IEnumerator IsPlayingCoroutine()
{
if (_playedAudioSource != null)
{
while (_playedAudioSource.isPlaying)
{
IsPlaying = true;
yield return null;
}
IsPlaying = false;
yield break;
}
}
/// <summary>
/// Returns the duration of the sound, or of the longest of the random sounds
/// </summary>
/// <returns></returns>
protected virtual float GetDuration()
{
if (SoundDataSO != null)
{
return ComputeDuration(SoundDataSO.Sfx, SoundDataSO.RandomSfx);
}
else
{
return ComputeDuration(Sfx, RandomSfx);
}
}
protected virtual float ComputeDuration(AudioClip sfx, AudioClip[] randomSfx)
{
if (sfx != null)
{
return (_randomPlaybackDuration > 0) ? _randomPlaybackDuration : sfx.length - _randomPlaybackTime;
}
float longest = 0f;
if ((randomSfx != null) && (randomSfx.Length > 0))
{
if (_lastPlayedClip != null)
{
return _lastPlayedClip.length;
}
foreach (AudioClip clip in randomSfx)
{
if ((clip != null) && (clip.length > longest))
{
longest = clip.length;
}
}
return (_randomPlaybackDuration > 0) ? _randomPlaybackDuration : longest - _randomPlaybackTime;
}
return 0f;
}
public override void OnDrawGizmosSelectedHandler()
{
if (!DrawGizmos)
{
return;
}
_gizmoCenter = GizmosCenter != null ? GizmosCenter.position : Owner.transform.position;
Gizmos.color = MinDistanceColor;
Gizmos.DrawWireSphere(_gizmoCenter, MinDistance);
Gizmos.color = MaxDistanceColor;
Gizmos.DrawWireSphere(_gizmoCenter, MaxDistance);
}
/// <summary>
/// Automatically tries to add a MMSoundManager to the scene if none are present
/// </summary>
public override void AutomaticShakerSetup()
{
MMSoundManager soundManager = (MMSoundManager)Object.FindAnyObjectByType(typeof(MMSoundManager));
if (soundManager == null)
{
GameObject soundManagerGo = new GameObject("MMSoundManager");
soundManagerGo.AddComponent<MMSoundManager>();
MMDebug.DebugLogInfo( "Added a MMSoundManager to the scene. You're all set.");
}
}
#region TestMethods
/// <summary>
/// A test method that creates an audiosource, plays it, and destroys itself after play
/// </summary>
public virtual async void TestPlaySound()
{
AudioClip tmpAudioClip = null;
if (Sfx != null)
{
tmpAudioClip = Sfx;
}
if ((RandomSfx != null) && (RandomSfx.Length > 0))
{
tmpAudioClip = PickRandomClip();
}
if ((tmpAudioClip == null) && (AudioResourceToPlay == null))
{
Debug.LogError(Label + " on " + Owner.gameObject.name + " can't play in editor mode, you haven't set its Sfx.");
return;
}
float volume = Random.Range(MinVolume, MaxVolume);
float pitch = Random.Range(MinPitch, MaxPitch);
RandomizeTimes();
GameObject temporaryAudioHost = new GameObject("EditorTestAS_WillAutoDestroy");
SceneManager.MoveGameObjectToScene(temporaryAudioHost.gameObject, Owner.gameObject.scene);
temporaryAudioHost.transform.position = Owner.transform.position;
if (!Application.isPlaying)
{
temporaryAudioHost.AddComponent<MMForceDestroyInPlayMode>();
}
_editorAudioSource = temporaryAudioHost.AddComponent<AudioSource>() as AudioSource;
PlayAudioSource(_editorAudioSource, tmpAudioClip, volume, pitch, _randomPlaybackTime, _randomPlaybackDuration, AudioResourceToPlay);
_lastPlayTimestamp = FeedbackTime;
_lastPlayedClip = tmpAudioClip;
float length = 0f;
if (tmpAudioClip != null)
{
length = (_randomPlaybackDuration > 0) ? _randomPlaybackDuration : tmpAudioClip.length;
}
else
{
length = 10f;
}
length *= 1000;
length = length / Mathf.Abs(pitch);
await Task.Delay((int)length);
Object.DestroyImmediate(temporaryAudioHost);
}
/// <summary>
/// A test method that stops the test sound
/// </summary>
protected virtual void TestStopSound()
{
if (_editorAudioSource != null)
{
_editorAudioSource.Stop();
}
}
/// <summary>
/// Plays the audio source with the specified volume and pitch
/// </summary>
/// <param name="audioSource"></param>
/// <param name="sfx"></param>
/// <param name="volume"></param>
/// <param name="pitch"></param>
protected virtual void PlayAudioSource(AudioSource audioSource, AudioClip sfx, float volume, float pitch, float time, float playbackDuration, AudioResource audioResourceToPlay)
{
// we set that audio source clip to the one in parameters
if (audioResourceToPlay == null)
{
audioSource.clip = sfx;
audioSource.time = time;
}
else
{
audioSource.resource = audioResourceToPlay;
}
// we set the audio source volume to the one in parameters
audioSource.volume = volume;
audioSource.pitch = pitch;
// we set our loop setting
audioSource.loop = false;
// we start playing the sound
audioSource.Play();
}
/// <summary>
/// Determines the next index to play when dealing with random clips
/// </summary>
/// <returns></returns>
protected virtual AudioClip PickRandomClip()
{
int newIndex = 0;
if (!SequentialOrder)
{
if (RandomUnique)
{
newIndex = _randomUniqueShuffleBag.Pick();
}
else
{
newIndex = Random.Range(0, RandomSfx.Length);
}
}
else
{
newIndex = _currentIndex;
if (newIndex >= RandomSfx.Length)
{
if (SequentialOrderHoldLast)
{
newIndex--;
if ((SequentialOrderHoldCooldownDuration > 0)
&& (FeedbackTime - _lastPlayTimestamp > SequentialOrderHoldCooldownDuration))
{
newIndex = 0;
}
}
else
{
newIndex = 0;
}
}
_currentIndex = newIndex + 1;
}
return RandomSfx[newIndex];
}
/// <summary>
/// Forces a reset of the sequential index to 0
/// </summary>
public virtual void ResetSequentialIndex()
{
_currentIndex = 0;
}
/// <summary>
/// Forces a reset of the sequential index to the value specified in parameters
/// </summary>
/// <param name="newIndex"></param>
public virtual void SetSequentialIndex(int newIndex)
{
_currentIndex = newIndex;
}
/// <summary>
/// On validate we randomize our times
/// </summary>
public override void OnValidate()
{
base.OnValidate();
RandomizeTimes();
if ((RandomSfx != null) && (RandomSfx.Length > 0))
{
_randomUniqueShuffleBag = new MMShufflebag<int>(RandomSfx.Length);
for (int i = 0; i < RandomSfx.Length; i++)
{
_randomUniqueShuffleBag.Add(i,1);
}
}
if (string.IsNullOrEmpty(FadeInTween.ConditionPropertyName))
{
FadeInTween.ConditionPropertyName = "Fade";
}
}
#endregion
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ae23e6af7cee13748b98cf83b79d01c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerSound.cs
uploadId: 830868

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you control a specific sound (or sounds), targeted by SoundID, which has to match the SoundID of the sound you intially played. You will need a MMSoundManager in your scene for this to work.
/// </summary>
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager Sound Control")]
[FeedbackHelp("This feedback will let you control a specific sound (or sounds), targeted by SoundID, which has to match the SoundID of the sound you intially played. You will need a MMSoundManager in your scene for this to work.")]
public class MMF_MMSoundManagerSoundControl : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get { return ControlMode.ToString(); } }
#endif
[MMFInspectorGroup("MMSoundManager Sound Control", true, 30)]
/// the action to trigger on the specified sound
[Tooltip("the action to trigger on the specified sound")]
public MMSoundManagerSoundControlEventTypes ControlMode = MMSoundManagerSoundControlEventTypes.Pause;
/// the ID of the sound, has to match the one you specified when playing it
[Tooltip("the ID of the sound, has to match the one you specified when playing it")]
public int SoundID = 0;
protected AudioSource _targetAudioSource;
/// <summary>
/// On play, triggers an event meant to be caught by the MMSoundManager and acted upon
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMSoundManagerSoundControlEvent.Trigger(ControlMode, SoundID);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 55d739433fa69b24e9b9e0fc7388da77
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerSoundControl.cs
uploadId: 830868

View File

@@ -0,0 +1,465 @@
using System;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Audio;
using MoreMountains.Tools;
using UnityEngine.PlayerLoop;
using UnityEngine.SceneManagement;
using Random = UnityEngine.Random;
using UnityEngine.Scripting.APIUpdating;
using Object = UnityEngine.Object;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// A scriptable object used to store data for MMSoundManager play
/// </summary>
[Serializable]
[CreateAssetMenu(menuName = "MoreMountains/Audio/MMF_SoundData")]
public class MMF_MMSoundManagerSoundData : ScriptableObject
{
[Header("Sound")]
/// the sound clip to play
[Tooltip("the sound clip to play")]
public AudioClip Sfx;
[Header("Random Sound")]
/// an array to pick a random sfx from
[Tooltip("an array to pick a random sfx from")]
public AudioClip[] RandomSfx;
/// if this is true, random sfx audio clips will be played in sequential order instead of at random
[Tooltip("if this is true, random sfx audio clips will be played in sequential order instead of at random")]
public bool SequentialOrder = false;
/// if we're in sequential order, determines whether or not to hold at the last index, until either a cooldown is met, or the ResetSequentialIndex method is called
[Tooltip("if we're in sequential order, determines whether or not to hold at the last index, until either a cooldown is met, or the ResetSequentialIndex method is called")]
[MMFCondition("SequentialOrder", true)]
public bool SequentialOrderHoldLast = false;
/// if we're in sequential order hold last mode, index will reset to 0 automatically after this duration, unless it's 0, in which case it'll be ignored
[Tooltip("if we're in sequential order hold last mode, index will reset to 0 automatically after this duration, unless it's 0, in which case it'll be ignored")]
[MMFCondition("SequentialOrderHoldLast", true)]
public float SequentialOrderHoldCooldownDuration = 2f;
/// if this is true, sfx will be picked at random until all have been played. once this happens, the list is shuffled again, and it starts over
[Tooltip("if this is true, sfx will be picked at random until all have been played. once this happens, the list is shuffled again, and it starts over")]
public bool RandomUnique = false;
[Header("Sound Properties")]
[Header("Volume")]
/// the minimum volume to play the sound at
[Tooltip("the minimum volume to play the sound at")]
[Range(0f,2f)]
public float MinVolume = 1f;
/// the maximum volume to play the sound at
[Tooltip("the maximum volume to play the sound at")]
[Range(0f,2f)]
public float MaxVolume = 1f;
[Header("Pitch")]
/// the minimum pitch to play the sound at
[Tooltip("the minimum pitch to play the sound at")]
[Range(-3f,3f)]
public float MinPitch = 1f;
/// the maximum pitch to play the sound at
[Tooltip("the maximum pitch to play the sound at")]
[Range(-3f,3f)]
public float MaxPitch = 1f;
[Header("Time")]
/// a timestamp (in seconds, randomized between the defined min and max) at which the sound will start playing, equivalent to the Audiosource API's Time)
[Tooltip("a timestamp (in seconds, randomized between the defined min and max) at which the sound will start playing, equivalent to the Audiosource API's Time)")]
[MMFVector("Min", "Max")]
public Vector2 PlaybackTime = new Vector2(0f, 0f);
/// a duration (in seconds, randomized between the defined min and max) for which the sound will play before stopping. Ignored if min and max are zero.
[Tooltip("a duration (in seconds, randomized between the defined min and max) for which the sound will play before stopping. Ignored if min and max are zero.")]
[MMVector("Min", "Max")]
public Vector2 PlaybackDuration = new Vector2(0f, 0f);
[Header("Sound Manager Options")]
/// the track on which to play the sound. Pick the one that matches the nature of your sound
[Tooltip("the track on which to play the sound. Pick the one that matches the nature of your sound")]
public MMSoundManager.MMSoundManagerTracks MmSoundManagerTrack = MMSoundManager.MMSoundManagerTracks.Sfx;
/// the ID of the sound. This is useful if you plan on using sound control feedbacks on it afterwards.
[Tooltip("the ID of the sound. This is useful if you plan on using sound control feedbacks on it afterwards.")]
public int ID = 0;
/// the AudioGroup on which to play the sound. If you're already targeting a preset track, you can leave it blank, otherwise the group you specify here will override it.
[Tooltip("the AudioGroup on which to play the sound. If you're already targeting a preset track, you can leave it blank, otherwise the group you specify here will override it.")]
public AudioMixerGroup AudioGroup = null;
/// if (for some reason) you've already got an audiosource and wouldn't like to use the built-in pool system, you can specify it here
[Tooltip("if (for some reason) you've already got an audiosource and wouldn't like to use the built-in pool system, you can specify it here")]
public AudioSource RecycleAudioSource = null;
/// whether or not this sound should loop
[Tooltip("whether or not this sound should loop")]
public bool Loop = false;
/// whether or not this sound should continue playing when transitioning to another scene
[Tooltip("whether or not this sound should continue playing when transitioning to another scene")]
public bool Persistent = false;
/// whether or not this sound should play if the same sound clip is already playing
[Tooltip("whether or not this sound should play if the same sound clip is already playing")]
public bool DoNotPlayIfClipAlreadyPlaying = false;
/// the maximum amount of instances of this sound allowed to play at once. use -1 for unlimited concurrent plays
[Tooltip("the maximum amount of instances of this sound allowed to play at once. use -1 for unlimited concurrent plays")]
public int MaximumConcurrentInstances = -1;
/// if this is true, this sound will stop playing when stopping the feedback
[Tooltip("if this is true, this sound will stop playing when stopping the feedback")]
public bool StopSoundOnFeedbackStop = false;
[Header("Fade In")]
/// whether or not to fade this sound in when playing it
[Tooltip("whether or not to fade this sound in when playing it")]
public bool FadeIn = false;
/// if fading, the volume at which to start the fade
[Tooltip("if fading, the volume at which to start the fade")]
[MMCondition("FadeIn", true)]
public float FadeInInitialVolume = 0f;
/// if fading, the duration of the fade, in seconds
[Tooltip("if fading, the duration of the fade, in seconds")]
[MMCondition("FadeIn", true)]
public float FadeInDuration = 1f;
/// if fading, the tween over which to fade the sound
[Tooltip("if fading, the tween over which to fade the sound ")]
public MMTweenType FadeInTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutQuartic, "FadeIn");
[Header("Fade Out")]
/// whether or not to fade this sound in when stopping the feedback
[Tooltip("whether or not to fade this sound in when stopping the feedback")]
public bool FadeOutOnStop = false;
/// if fading out, the duration of the fade, in seconds
[Tooltip("if fading out, the duration of the fade, in seconds")]
[MMCondition("FadeOutOnStop", true)]
public float FadeOutDuration = 1f;
/// if fading out, the tween over which to fade the sound
[Tooltip("if fading out, the tween over which to fade the sound ")]
public MMTweenType FadeOutTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutQuartic, "FadeOutOnStop");
[Header("Solo")]
/// whether or not this sound should play in solo mode over its destination track. If yes, all other sounds on that track will be muted when this sound starts playing
[Tooltip("whether or not this sound should play in solo mode over its destination track. If yes, all other sounds on that track will be muted when this sound starts playing")]
public bool SoloSingleTrack = false;
/// whether or not this sound should play in solo mode over all other tracks. If yes, all other tracks will be muted when this sound starts playing
[Tooltip("whether or not this sound should play in solo mode over all other tracks. If yes, all other tracks will be muted when this sound starts playing")]
public bool SoloAllTracks = false;
/// if in any of the above solo modes, AutoUnSoloOnEnd will unmute the track(s) automatically once that sound stops playing
[Tooltip("if in any of the above solo modes, AutoUnSoloOnEnd will unmute the track(s) automatically once that sound stops playing")]
public bool AutoUnSoloOnEnd = false;
[Header("Spatial Settings")]
/// Pans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.
[Tooltip("Pans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.")]
[Range(-1f,1f)]
public float PanStereo;
/// Sets how much this AudioSource is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D.
[Tooltip("Sets how much this AudioSource is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D.")]
[Range(0f,1f)]
public float SpatialBlend;
/// a Transform this sound can 'attach' to and follow it along as it plays - when used on a feedback, will only apply if the feedback's AttachToTransform is empty
[Tooltip("a Transform this sound can 'attach' to and follow it along as it plays - when used on a feedback, will only apply if the feedback's AttachToTransform is empty")]
public Transform AttachToTransform;
[Header("Effects")]
/// Bypass effects (Applied from filter components or global listener filters).
[Tooltip("Bypass effects (Applied from filter components or global listener filters).")]
public bool BypassEffects = false;
/// When set global effects on the AudioListener will not be applied to the audio signal generated by the AudioSource. Does not apply if the AudioSource is playing into a mixer group.
[Tooltip("When set global effects on the AudioListener will not be applied to the audio signal generated by the AudioSource. Does not apply if the AudioSource is playing into a mixer group.")]
public bool BypassListenerEffects = false;
/// When set doesn't route the signal from an AudioSource into the global reverb associated with reverb zones.
[Tooltip("When set doesn't route the signal from an AudioSource into the global reverb associated with reverb zones.")]
public bool BypassReverbZones = false;
/// Sets the priority of the AudioSource.
[Tooltip("Sets the priority of the AudioSource.")]
[Range(0, 256)]
public int Priority = 128;
/// The amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.
[Tooltip("The amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.")]
[Range(0f,1.1f)]
public float ReverbZoneMix = 1f;
[Header("3D Sound Settings")]
/// Sets the Doppler scale for this AudioSource.
[Tooltip("Sets the Doppler scale for this AudioSource.")]
[Range(0f,5f)]
public float DopplerLevel = 1f;
/// Sets the spread angle (in degrees) of a 3d stereo or multichannel sound in speaker space.
[Tooltip("Sets the spread angle (in degrees) of a 3d stereo or multichannel sound in speaker space.")]
[Range(0,360)]
public int Spread = 0;
/// Sets/Gets how the AudioSource attenuates over distance.
[Tooltip("Sets/Gets how the AudioSource attenuates over distance.")]
public AudioRolloffMode RolloffMode = AudioRolloffMode.Logarithmic;
/// Within the Min distance the AudioSource will cease to grow louder in volume.
[Tooltip("Within the Min distance the AudioSource will cease to grow louder in volume.")]
public float MinDistance = 1f;
/// (Logarithmic rolloff) MaxDistance is the distance a sound stops attenuating at.
[Tooltip("(Logarithmic rolloff) MaxDistance is the distance a sound stops attenuating at.")]
public float MaxDistance = 500f;
/// whether or not to use a custom curve for custom volume rolloff
[Tooltip("whether or not to use a custom curve for custom volume rolloff")]
public bool UseCustomRolloffCurve = false;
/// the curve to use for custom volume rolloff if UseCustomRolloffCurve is true
[Tooltip("the curve to use for custom volume rolloff if UseCustomRolloffCurve is true")]
[MMCondition("UseCustomRolloffCurve", true)]
public AnimationCurve CustomRolloffCurve;
/// whether or not to use a custom curve for spatial blend
[Tooltip("whether or not to use a custom curve for spatial blend")]
public bool UseSpatialBlendCurve = false;
/// the curve to use for custom spatial blend if UseSpatialBlendCurve is true
[Tooltip("the curve to use for custom spatial blend if UseSpatialBlendCurve is true")]
[MMCondition("UseSpatialBlendCurve", true)]
public AnimationCurve SpatialBlendCurve;
/// whether or not to use a custom curve for reverb zone mix
[Tooltip("whether or not to use a custom curve for reverb zone mix")]
public bool UseReverbZoneMixCurve = false;
/// the curve to use for custom reverb zone mix if UseReverbZoneMixCurve is true
[Tooltip("the curve to use for custom reverb zone mix if UseReverbZoneMixCurve is true")]
[MMCondition("UseReverbZoneMixCurve", true)]
public AnimationCurve ReverbZoneMixCurve;
/// whether or not to use a custom curve for spread
[Tooltip("whether or not to use a custom curve for spread")]
public bool UseSpreadCurve = false;
/// the curve to use for custom spread if UseSpreadCurve is true
[Tooltip("the curve to use for custom spread if UseSpreadCurve is true")]
[MMCondition("UseSpreadCurve", true)]
public AnimationCurve SpreadCurve;
[MMInspectorButton("TestPlaySound")]
public bool TestPlaySoundButton;
protected AudioClip _randomClip;
protected MMShufflebag<int> _randomUniqueShuffleBag;
protected int _currentIndex;
protected float _randomPlaybackTime;
protected float _randomPlaybackDuration;
protected MMSoundManagerPlayOptions _options;
protected AudioSource _playedAudioSource;
protected AudioClip _lastPlayedClip;
protected bool _initialized = false;
protected AudioSource _editorAudioSource;
protected float _lastPlayTimestamp = -float.MaxValue;
protected virtual void Initialization()
{
_lastPlayedClip = null;
if (RandomSfx == null)
{
RandomSfx = Array.Empty<AudioClip>();
}
if (RandomUnique)
{
_randomUniqueShuffleBag = new MMShufflebag<int>(RandomSfx.Length);
for (int i = 0; i < RandomSfx.Length; i++)
{
_randomUniqueShuffleBag.Add(i,1);
}
}
_initialized = true;
}
public virtual void Play(Vector3 position)
{
if (!_initialized || (RandomUnique && _randomUniqueShuffleBag == null))
{
Initialization();
}
if (RandomSfx.Length > 0)
{
_randomClip = PickRandomClip();
if (_randomClip != null)
{
PlaySound(_randomClip, position);
return;
}
}
if ((Sfx != null))
{
PlaySound(Sfx, position);
return;
}
}
protected virtual AudioSource PlaySound(AudioClip sfx, Vector3 position)
{
if (DoNotPlayIfClipAlreadyPlaying)
{
if ((MMSoundManager.Instance.FindByClip(sfx) != null) && (MMSoundManager.Instance.FindByClip(sfx).isPlaying))
{
return null;
}
}
if (MaximumConcurrentInstances >= 0)
{
if (MMSoundManager.Instance.CurrentlyPlayingCount(sfx) >= MaximumConcurrentInstances)
{
return null;
}
}
_lastPlayedClip = null;
float volume = Random.Range(MinVolume, MaxVolume);
float pitch = Random.Range(MinPitch, MaxPitch);
RandomizeTimes();
_options.MmSoundManagerTrack = MmSoundManagerTrack;
_options.Location = position;
_options.Loop = Loop;
_options.Volume = volume;
_options.ID = ID;
_options.Fade = FadeIn;
_options.FadeInitialVolume = FadeInInitialVolume;
_options.FadeDuration = FadeInDuration;
_options.FadeTween = FadeInTween;
_options.Persistent = Persistent;
_options.RecycleAudioSource = RecycleAudioSource;
_options.AudioGroup = AudioGroup;
_options.Pitch = pitch;
_options.PlaybackTime = _randomPlaybackTime;
_options.PlaybackDuration = _randomPlaybackDuration;
_options.PanStereo = PanStereo;
_options.SpatialBlend = SpatialBlend;
_options.SoloSingleTrack = SoloSingleTrack;
_options.SoloAllTracks = SoloAllTracks;
_options.AutoUnSoloOnEnd = AutoUnSoloOnEnd;
_options.BypassEffects = BypassEffects;
_options.BypassListenerEffects = BypassListenerEffects;
_options.BypassReverbZones = BypassReverbZones;
_options.Priority = Priority;
_options.ReverbZoneMix = ReverbZoneMix;
_options.DopplerLevel = DopplerLevel;
_options.Spread = Spread;
_options.RolloffMode = RolloffMode;
_options.MinDistance = MinDistance;
_options.MaxDistance = MaxDistance;
_options.AttachToTransform = AttachToTransform;
_options.UseSpreadCurve = UseSpreadCurve;
_options.SpreadCurve = SpreadCurve;
_options.UseCustomRolloffCurve = UseCustomRolloffCurve;
_options.CustomRolloffCurve = CustomRolloffCurve;
_options.UseSpatialBlendCurve = UseSpatialBlendCurve;
_options.SpatialBlendCurve = SpatialBlendCurve;
_options.UseReverbZoneMixCurve = UseReverbZoneMixCurve;
_options.ReverbZoneMixCurve = ReverbZoneMixCurve;
_options.DoNotAutoRecycleIfNotDonePlaying = true;
_playedAudioSource = MMSoundManagerSoundPlayEvent.Trigger(sfx, _options);
_lastPlayedClip = sfx;
return _playedAudioSource;
}
public virtual void RandomizeTimes()
{
_randomPlaybackTime = Random.Range(PlaybackTime.x, PlaybackTime.y);
_randomPlaybackDuration = Random.Range(PlaybackDuration.x, PlaybackDuration.y);
}
protected virtual AudioClip PickRandomClip()
{
int newIndex = 0;
if (!SequentialOrder)
{
if (RandomUnique)
{
newIndex = _randomUniqueShuffleBag.Pick();
}
else
{
newIndex = Random.Range(0, RandomSfx.Length);
}
}
else
{
newIndex = _currentIndex;
if (newIndex >= RandomSfx.Length)
{
if (SequentialOrderHoldLast)
{
newIndex--;
if (SequentialOrderHoldCooldownDuration > 0)
{
newIndex = 0;
}
}
else
{
newIndex = 0;
}
}
_currentIndex = newIndex + 1;
}
return RandomSfx[newIndex];
}
public virtual async void TestPlaySound()
{
if (!_initialized || (RandomUnique && _randomUniqueShuffleBag == null))
{
Initialization();
}
AudioClip tmpAudioClip = null;
if (Sfx != null)
{
tmpAudioClip = Sfx;
}
if ((RandomSfx != null) && (RandomSfx.Length > 0))
{
tmpAudioClip = PickRandomClip();
}
if (tmpAudioClip == null)
{
Debug.LogError("This SoundData can't play in editor mode, you haven't set its Sfx.");
return;
}
float volume = Random.Range(MinVolume, MaxVolume);
float pitch = Random.Range(MinPitch, MaxPitch);
RandomizeTimes();
GameObject temporaryAudioHost = new GameObject("EditorTestAS_WillAutoDestroy");
SceneManager.MoveGameObjectToScene(temporaryAudioHost.gameObject, SceneManager.GetActiveScene());
temporaryAudioHost.transform.position = Vector3.zero;
if (!Application.isPlaying)
{
temporaryAudioHost.AddComponent<MMForceDestroyInPlayMode>();
}
_editorAudioSource = temporaryAudioHost.AddComponent<AudioSource>() as AudioSource;
PlayAudioSource(_editorAudioSource, tmpAudioClip, volume, pitch, _randomPlaybackTime, _randomPlaybackDuration);
_lastPlayTimestamp = Time.time;
_lastPlayedClip = tmpAudioClip;
float length = 0f;
if (tmpAudioClip != null)
{
length = (_randomPlaybackDuration > 0) ? _randomPlaybackDuration : tmpAudioClip.length;
}
else
{
length = 10f;
}
length *= 1000;
length = length / Mathf.Abs(pitch);
await Task.Delay((int)length);
Object.DestroyImmediate(temporaryAudioHost);
}
protected virtual void PlayAudioSource(AudioSource audioSource, AudioClip sfx, float volume, float pitch, float time, float playbackDuration)
{
audioSource.clip = sfx;
audioSource.time = time;
audioSource.volume = volume;
audioSource.pitch = pitch;
audioSource.loop = false;
audioSource.Play();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 93cb35ed4e3a7554cbb5cdc5e2bdfd4d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerSoundData.cs
uploadId: 830868

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback lets you trigger fades on a specific sound via the MMSoundManager. You will need a MMSoundManager in your scene for this to work.
/// </summary>
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager Sound Fade")]
[FeedbackHelp("This feedback lets you trigger fades on a specific sound via the MMSoundManager. You will need a MMSoundManager in your scene for this to work.")]
public class MMF_MMSoundManagerSoundFade : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get { return "ID "+SoundID; } }
#endif
[MMFInspectorGroup("MMSoundManager Sound Fade", true, 30)]
/// the ID of the sound you want to fade. Has to match the ID you specified when playing the sound initially
[Tooltip("the ID of the sound you want to fade. Has to match the ID you specified when playing the sound initially")]
public int SoundID = 0;
/// the duration of the fade, in seconds
[Tooltip("the duration of the fade, in seconds")]
public float FadeDuration = 1f;
/// the volume towards which to fade
[Tooltip("the volume towards which to fade")]
[Range(MMSoundManagerSettings._minimalVolume,MMSoundManagerSettings._maxVolume)]
public float FinalVolume = MMSoundManagerSettings._minimalVolume;
/// the tween to apply over the fade
[Tooltip("the tween to apply over the fade")]
public MMTweenType FadeTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutQuartic);
protected AudioSource _targetAudioSource;
/// <summary>
/// On play, we start our fade via a fade event
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMSoundManagerSoundFadeEvent.Trigger(MMSoundManagerSoundFadeEvent.Modes.PlayFade, SoundID, FadeDuration, FinalVolume, FadeTween);
}
/// <summary>
/// On stop, we stop our fade via a fade event
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMSoundManagerSoundFadeEvent.Trigger(MMSoundManagerSoundFadeEvent.Modes.StopFade, SoundID, FadeDuration, FinalVolume, FadeTween);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 14c18eda2751dd04ba846546118f8d97
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerSoundFade.cs
uploadId: 830868

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you control all sounds playing on a specific track (master, UI, music, sfx), and play, pause, mute, unmute, resume, stop, free them all at once. You will need a MMSoundManager in your scene for this to work.
/// </summary>
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager Track Control")]
[FeedbackHelp("This feedback will let you control all sounds playing on a specific track (master, UI, music, sfx), and play, pause, mute, unmute, resume, stop, free them all at once. You will need a MMSoundManager in your scene for this to work.")]
public class MMF_MMSoundManagerTrackControl : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get { return Track.ToString() + " " + ControlMode.ToString(); } }
#endif
/// the possible modes you can use to interact with the track. Free will stop all sounds and return them to the pool
public enum ControlModes { Mute, UnMute, SetVolume, Pause, Play, Stop, Free }
[MMFInspectorGroup("MMSoundManager Track Control", true, 30)]
/// the track to mute/unmute/pause/play/stop/free/etc
[Tooltip("the track to mute/unmute/pause/play/stop/free/etc")]
public MMSoundManager.MMSoundManagerTracks Track;
/// the selected control mode to interact with the track. Free will stop all sounds and return them to the pool
[Tooltip("the selected control mode to interact with the track. Free will stop all sounds and return them to the pool")]
public ControlModes ControlMode = ControlModes.Pause;
/// if setting the volume, the volume to assign to the track
[Tooltip("if setting the volume, the volume to assign to the track")]
[MMEnumCondition("ControlMode", (int) ControlModes.SetVolume)]
public float Volume = 0.5f;
/// <summary>
/// On play, orders the entire track to follow the specific command, via a MMSoundManager event
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
switch (ControlMode)
{
case ControlModes.Mute:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.MuteTrack, Track);
break;
case ControlModes.UnMute:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.UnmuteTrack, Track);
break;
case ControlModes.SetVolume:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.SetVolumeTrack, Track, Volume);
break;
case ControlModes.Pause:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.PauseTrack, Track);
break;
case ControlModes.Play:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.PlayTrack, Track);
break;
case ControlModes.Stop:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.StopTrack, Track);
break;
case ControlModes.Free:
MMSoundManagerTrackEvent.Trigger(MMSoundManagerTrackEventTypes.FreeTrack, Track);
break;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f5c2406e2726fb2418de78aecddaefbe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerTrackControl.cs
uploadId: 830868

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using MoreMountains.Tools;
using UnityEngine.Audio;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you fade all the sounds on a specific track at once. You will need a MMSoundManager in your scene for this to work.
/// </summary>
[AddComponentMenu("")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMSoundManager Track Fade")]
[FeedbackHelp("This feedback will let you fade all the sounds on a specific track at once. You will need a MMSoundManager in your scene for this to work.")]
public class MMF_MMSoundManagerTrackFade : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get { return Track.ToString(); } }
#endif
/// the duration of this feedback is the duration of the fade
public override float FeedbackDuration { get { return FadeDuration; } }
[MMFInspectorGroup("MMSoundManager Track Fade", true, 30)]
/// the track to fade the volume on
[Tooltip("the track to fade the volume on")]
public MMSoundManager.MMSoundManagerTracks Track;
/// the duration of the fade, in seconds
[Tooltip("the duration of the fade, in seconds")]
public float FadeDuration = 1f;
/// the volume to reach at the end of the fade
[Tooltip("the volume to reach at the end of the fade")]
[Range(MMSoundManagerSettings._minimalVolume,MMSoundManagerSettings._maxVolume)]
public float FinalVolume = MMSoundManagerSettings._minimalVolume;
/// the tween to operate the fade on
[Tooltip("the tween to operate the fade on")]
public MMTweenType FadeTween = new MMTweenType(MMTween.MMTweenCurve.EaseInOutQuartic);
/// <summary>
/// On Play, triggers a fade event, meant to be caught by the MMSoundManager
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMSoundManagerTrackFadeEvent.Trigger(MMSoundManagerTrackFadeEvent.Modes.PlayFade, Track, FadeDuration, FinalVolume, FadeTween);
}
/// <summary>
/// On stop, we stop our fade via a fade event
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMSoundManagerTrackFadeEvent.Trigger(MMSoundManagerTrackFadeEvent.Modes.StopFade, Track, FadeDuration, FinalVolume, FadeTween);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 266e8e08f7762ff488684f17ba9da511
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_MMSoundManagerTrackFade.cs
uploadId: 830868

View File

@@ -0,0 +1,96 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will trigger a post processing moving filter event, meant to be caught by a MMPostProcessingMovableFilter object
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will trigger a post processing moving filter event, meant to be caught by a MMPostProcessingMovableFilter object")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("PostProcess/PPMovingFilter")]
public class MMF_PPMovingFilter : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.PostProcessColor; } }
public override string RequiredTargetText => RequiredChannelText;
#endif
/// the duration of this feedback is the duration of the transition
public override float FeedbackDuration { get { return ApplyTimeMultiplier(TransitionDuration); } set { TransitionDuration = value; } }
public override bool HasChannel => true;
/// the possible modes for this feedback
public enum Modes { Toggle, On, Off }
[MMFInspectorGroup("PostProcessing Profile Moving Filter", true, 54)]
/// the selected mode for this feedback
[Tooltip("the selected mode for this feedback")]
public Modes Mode = Modes.Toggle;
/// the duration of the transition
[Tooltip("the duration of the transition")]
public float TransitionDuration = 1f;
/// the curve to move along to
[Tooltip("the curve to move along to")]
public MMTweenType Curve = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic);
protected bool _active = false;
protected bool _toggle = false;
/// <summary>
/// On custom play, we trigger a MMPostProcessingMovingFilterEvent with the selected parameters
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
_active = (Mode == Modes.On);
_toggle = (Mode == Modes.Toggle);
MMPostProcessingMovingFilterEvent.Trigger(Curve, _active, _toggle, FeedbackDuration, Channel);
}
/// <summary>
/// On stop we stop our transition
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
MMPostProcessingMovingFilterEvent.Trigger(Curve, _active, _toggle, FeedbackDuration, stop:true);
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
MMPostProcessingMovingFilterEvent.Trigger(Curve, _active, _toggle, FeedbackDuration, restore:true);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: bad88d19339cd824eae939fb6492e1db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_PPMovingFilter.cs
uploadId: 830868

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you pilot a MMPlaylist
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you pilot a MMPlaylist")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("Audio/MMPlaylist")]
public class MMF_Playlist : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.SoundsColor; } }
public override string RequiredTargetText { get => Mode.ToString(); }
public override bool HasChannel => true;
#endif
public enum Modes { Play, PlayNext, PlayPrevious, Stop, Pause, PlaySongAt, SetVolumeMultiplier, ChangePlaylist }
[MMFInspectorGroup("MMPlaylist", true, 13)]
/// the action to call on the playlist
[Tooltip("the action to call on the playlist")]
public Modes Mode = Modes.PlayNext;
/// the index of the song to play
[Tooltip("the index of the song to play")]
[MMEnumCondition("Mode", (int)Modes.PlaySongAt)]
public int SongIndex = 0;
/// the volume multiplier to apply
[Tooltip("the volume multiplier to apply")]
[MMEnumCondition("Mode", (int)Modes.SetVolumeMultiplier)]
public float VolumeMultiplier = 1f;
/// whether to apply the volume multiplier instantly (true) or only when the next song starts playing (false)
[Tooltip("whether to apply the volume multiplier instantly (true) or only when the next song starts playing (false)")]
[MMEnumCondition("Mode", (int)Modes.SetVolumeMultiplier)]
public bool ApplyVolumeMultiplierInstantly = false;
/// in change playlist mode, the playlist to which to switch to. Only works with MMSMPlaylistManager
[Tooltip("in change playlist mode, the playlist to which to switch to. Only works with MMSMPlaylistManager")]
[MMEnumCondition("Mode", (int)Modes.ChangePlaylist)]
public MMSMPlaylist NewPlaylist;
/// in change playlist mode, whether or not to play the new playlist after the switch. Only works with MMSMPlaylistManager
[Tooltip("in change playlist mode, whether or not to play the new playlist after the switch. Only works with MMSMPlaylistManager")]
[MMEnumCondition("Mode", (int)Modes.ChangePlaylist)]
public bool ChangePlaylistAndPlay = true;
protected Coroutine _coroutine;
/// <summary>
/// On Play we change the values of our fog
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
switch (Mode)
{
case Modes.Play:
MMPlaylistPlayEvent.Trigger(Channel);
break;
case Modes.PlayNext:
MMPlaylistPlayNextEvent.Trigger(Channel);
break;
case Modes.PlayPrevious:
MMPlaylistPlayPreviousEvent.Trigger(Channel);
break;
case Modes.Stop:
MMPlaylistStopEvent.Trigger(Channel);
break;
case Modes.Pause:
MMPlaylistPauseEvent.Trigger(Channel);
break;
case Modes.PlaySongAt:
MMPlaylistPlayIndexEvent.Trigger(Channel, SongIndex);
break;
case Modes.SetVolumeMultiplier:
MMPlaylistVolumeMultiplierEvent.Trigger(Channel, VolumeMultiplier, ApplyVolumeMultiplierInstantly);
break;
case Modes.ChangePlaylist:
MMPlaylistChangeEvent.Trigger(Channel, NewPlaylist, ChangePlaylistAndPlay);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: cd1ba6e99150bc54788ab1cadf6a8f09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Playlist.cs
uploadId: 830868

View File

@@ -0,0 +1,316 @@
using MoreMountains.Tools;
using System.Collections;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you target (almost) any property, on any object in your scene.
/// It also works on scriptable objects. Drag an object, select a property, and setup your feedback " +
/// to update that property over time
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you target (almost) any property, on any object in your scene. " +
"It also works on scriptable objects. Drag an object, select a property, and setup your feedback " +
"to update that property over time.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("GameObject/Property")]
public class MMF_Property : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// the duration of this feedback is the duration of the target property, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { if (Mode != Modes.Instant) { Duration = value; } } }
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.GameObjectColor; } }
public override bool EvaluateRequiresSetup() { return (Target == null); }
public override string RequiredTargetText { get { return Target != null ? Target.TargetObject.name+" - "+Target.TargetPropertyName : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a Target be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasRandomness => true;
public override bool CanForceInitialValue => true;
public override bool ForceInitialValueDelayed => true;
public override bool HasCustomInspectors => true;
/// the possible modes for this feedback
public enum Modes { OverTime, Instant, ToDestination }
[MMFInspectorGroup("Target Property", true, 12)]
/// the receiver to write the level to
[Tooltip("the receiver to write the level to")]
public MMPropertyReceiver Target;
[MMFInspectorGroup("Mode", true, 29)]
/// whether the feedback should affect the target property instantly or over a period of time
[Tooltip("whether the feedback should affect the target property instantly or over a period of time")]
public Modes Mode = Modes.OverTime;
/// how long the target property should change over time
[Tooltip("how long the target property should change over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime, (int)Modes.ToDestination)]
public float Duration = 0.2f;
/// whether or not that target property should be turned off on start
[Tooltip("whether or not that target property should be turned off on start")]
public bool StartsOff = false;
/// whether or not the values should be relative or not
[Tooltip("whether or not the values should be relative or not")]
public bool RelativeValues = true;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// if this is true, initial value will be computed for every play, otherwise only once, on initialization
[Tooltip("if this is true, initial value will be computed for every play, otherwise only once, on initialization")]
public bool DetermineInitialValueOnPlay = false;
[MMFInspectorGroup("Level", true, 30)]
/// the curve to tween the intensity on
[Tooltip("the curve to tween the intensity on")]
public MMTweenType LevelCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.3f, 1f), new Keyframe(1, 0)), "", "Mode", (int)Modes.OverTime, (int)Modes.ToDestination);
/// the value to remap the intensity curve's 0 to
[Tooltip("the value to remap the intensity curve's 0 to")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float RemapLevelZero = 0f;
/// the value to remap the intensity curve's 1 to
[Tooltip("the value to remap the intensity curve's 1 to")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float RemapLevelOne = 1f;
/// the value to move the intensity to in instant mode
[Tooltip("the value to move the intensity to in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public float InstantLevel;
/// the value towards which to animate when in ToDestination mode
[Tooltip("the value towards which to animate when in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float ToDestinationLevel = 5f;
protected float _initialIntensity;
protected Coroutine _coroutine;
/// <summary>
/// On init we turn the target property off if needed
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if (Target == null)
{
Debug.LogWarning("[Property Feedback] The property feedback on "+Owner.name+" doesn't have a Target, it won't work. You need to specify one in its inspector.");
return;
}
Target.Initialization(Owner.gameObject);
GetInitialIntensity();
if (Active)
{
if (StartsOff)
{
Turn(false);
}
}
}
/// <summary>
/// Stores the current level of the target
/// </summary>
protected virtual void GetInitialIntensity()
{
_initialIntensity = Target.GetLevel();
}
/// <summary>
/// On Play we turn our target property on and start an over time coroutine if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized || (Target == null))
{
return;
}
if (DetermineInitialValueOnPlay)
{
GetInitialIntensity();
}
Turn(true);
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
switch (Mode)
{
case Modes.Instant:
float newLevel = NormalPlayDirection ? InstantLevel : _initialIntensity;
Target.SetLevel(newLevel);
break;
case Modes.OverTime:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(UpdateValueSequence(intensityMultiplier));
break;
case Modes.ToDestination:
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ToDestinationSequence(intensityMultiplier));
break;
}
}
/// <summary>
/// This coroutine will animate the target property's value towards the defined ToDestinationLevel.
/// Note that in RelativeValue mode, this ToDestinationLevel will be added to the initial value
/// </summary>
/// <param name="intensityMultiplier"></param>
protected virtual IEnumerator ToDestinationSequence(float intensityMultiplier)
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
float initialValue = Target.GetLevel();
float destinationValue = ToDestinationLevel;
if (RelativeValues)
{
destinationValue += _initialIntensity;
}
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
SetValues(remappedTime, intensityMultiplier, initialValue, destinationValue, false);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
SetValues(FinalNormalizedTime, intensityMultiplier, initialValue, destinationValue, false);
if (StartsOff)
{
Turn(false);
}
_coroutine = null;
yield return null;
}
/// <summary>
/// This coroutine will modify the values on the target property
/// </summary>
/// <returns></returns>
protected virtual IEnumerator UpdateValueSequence(float intensityMultiplier)
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
SetValues(remappedTime, intensityMultiplier, RemapLevelZero, RemapLevelOne, true);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
SetValues(FinalNormalizedTime, intensityMultiplier, RemapLevelZero, RemapLevelOne, true);
if (StartsOff)
{
Turn(false);
}
_coroutine = null;
yield return null;
}
/// <summary>
/// Sets the various values on the target property on a specified time (between 0 and 1)
/// </summary>
/// <param name="time"></param>
protected virtual void SetValues(float time, float intensityMultiplier, float remapZero, float remapOne, bool applyRelative)
{
float intensity = MMTween.Tween(time, 0f, 1f, remapZero, remapOne, LevelCurve);
intensity *= intensityMultiplier;
if (applyRelative && RelativeValues)
{
intensity += _initialIntensity;
}
Target.SetLevel(intensity);
}
/// <summary>
/// Turns the target property object off on stop if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
base.CustomStopFeedback(position, feedbacksIntensity);
if (Active)
{
if (_coroutine != null)
{
Owner.StopCoroutine(_coroutine);
_coroutine = null;
Target.SetLevel(_initialIntensity);
}
if (StartsOff)
{
Turn(false);
}
}
}
/// <summary>
/// Turns the target object on or off
/// </summary>
/// <param name="status"></param>
protected virtual void Turn(bool status)
{
if (Target.TargetComponent.gameObject != null)
{
Target.TargetComponent.gameObject.SetActive(status);
}
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if (StartsOff)
{
Turn(false);
}
Target.SetLevel(_initialIntensity);
}
/// <summary>
/// On Validate, we init our curves conditions if needed
/// </summary>
public override void OnValidate()
{
base.OnValidate();
if (string.IsNullOrEmpty(LevelCurve.EnumConditionPropertyName))
{
LevelCurve.EnumConditionPropertyName = "Mode";
LevelCurve.EnumConditions = new bool[32];
LevelCurve.EnumConditions[(int)Modes.OverTime] = true;
LevelCurve.EnumConditions[(int)Modes.ToDestination] = true;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b567abd7b952dc748b9dd6b139e37bbf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_Property.cs
uploadId: 830868

View File

@@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MoreMountains.Tools;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback will let you trigger a play on a target MMRadioSignal (usually used by a MMRadioBroadcaster to emit a value that can then be listened to by MMRadioReceivers. From this feedback you can also specify a duration, timescale and multiplier.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback will let you trigger a play on a target MMRadioSignal (usually used by a MMRadioBroadcaster to emit a value that can then be listened to by MMRadioReceivers. From this feedback you can also specify a duration, timescale and multiplier.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("GameObject/MMRadioSignal")]
public class MMF_RadioSignal : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.GameObjectColor; } }
public override bool EvaluateRequiresSetup() { return (TargetSignal == null); }
public override string RequiredTargetText { get { return TargetSignal != null ? TargetSignal.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a TargetSignal be set to be able to work properly. You can set one below."; } }
#endif
/// the duration of this feedback is 0
public override float FeedbackDuration { get { return 0f; } }
public override bool HasRandomness => true;
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => TargetSignal = FindAutomatedTarget<MMRadioSignal>();
[MMFInspectorGroup("Radio Signal", true, 72)]
/// The target MMRadioSignal to trigger
[Tooltip("The target MMRadioSignal to trigger")]
public MMRadioSignal TargetSignal;
/// the timescale to operate on
[Tooltip("the timescale to operate on")]
public MMRadioSignal.TimeScales TimeScale = MMRadioSignal.TimeScales.Unscaled;
/// the duration of the shake, in seconds
[Tooltip("the duration of the shake, in seconds")]
public float Duration = 1f;
/// a global multiplier to apply to the end result of the combination
[Tooltip("a global multiplier to apply to the end result of the combination")]
public float GlobalMultiplier = 1f;
/// <summary>
/// On Play we set the values on our target signal and make it start shaking its level
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (Active && FeedbackTypeAuthorized)
{
if (TargetSignal != null)
{
float intensityMultiplier = ComputeIntensity(feedbacksIntensity, position);
TargetSignal.Duration = Duration;
TargetSignal.GlobalMultiplier = GlobalMultiplier * intensityMultiplier;
TargetSignal.TimeScale = TimeScale;
TargetSignal.StartShaking();
}
}
}
/// <summary>
/// On Stop, stops the target signal
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
base.CustomStopFeedback(position, feedbacksIntensity);
if (Active)
{
if (TargetSignal != null)
{
TargetSignal.Stop();
}
}
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if (TargetSignal != null)
{
TargetSignal.Stop();
TargetSignal.ApplyLevel(0f);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d01c21882f8c03844831b4d587f470b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_RadioSignal.cs
uploadId: 830868

View File

@@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
[System.Serializable]
public class WeightedEvent
{
public int Weight;
public UnityEvent Event;
}
/// <summary>
/// This feedback allows you to play a random Unity Event, out of a weighted list. To use it, add items to its WeightedEvents list. For each of them, you'll need to specify a weight (the higher the weight, the more likely it'll be picked) and the event to trigger. For an event in that list to have a chance to be picked, the weights can't be zero.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback allows you to play a random Unity Event, out of a weighted list. To use it, add items to its WeightedEvents list. For each of them, you'll need to specify a weight (the higher the weight, the more likely it'll be picked) and the event to trigger. For an event in that list to have a chance to be picked, the weights can't be zero.")]
[System.Serializable]
[FeedbackPath("Events/Random Unity Events")]
public class MMF_RandomEvents : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.EventsColor; } }
#endif
[MMFInspectorGroup("Events", true, 44)]
/// the list of events from which to pick
[Tooltip("the list of events from which to pick")]
public List<WeightedEvent> WeightedEvents;
protected MMShufflebag<int> _weightShuffleBag;
/// <summary>
/// On init, triggers the init events
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if ((WeightedEvents == null) || (WeightedEvents.Count == 0))
{
return;
}
_weightShuffleBag = new MMShufflebag<int>(WeightedEvents.Count);
for (var index = 0; index < WeightedEvents.Count; index++)
{
_weightShuffleBag.Add(index, WeightedEvents[index].Weight);
}
}
/// <summary>
/// On Play, triggers the play events
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if ((WeightedEvents == null) || (WeightedEvents.Count == 0) || (_weightShuffleBag == null))
{
return;
}
int newIndex = _weightShuffleBag.Pick();
WeightedEvents[newIndex].Event.Invoke();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8f1a7efd09d5b3647afbef7890b18017
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_RandomEvents.cs
uploadId: 830868

View File

@@ -0,0 +1,109 @@
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback lets you control the min and max anchors of a RectTransform over time. That's the normalized position in the parent RectTransform that the lower left and upper right corners are anchored to.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you control the min and max anchors of a RectTransform over time. That's the normalized position in the parent RectTransform that the lower left and upper right corners are anchored to.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("UI/RectTransform Anchor")]
public class MMF_RectTransformAnchor : MMF_FeedbackBase
{
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
public override bool EvaluateRequiresSetup() { return (TargetRectTransform == null); }
public override string RequiredTargetText { get { return TargetRectTransform != null ? TargetRectTransform.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a TargetRectTransform be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasAutomatedTargetAcquisition => true;
public override bool CanForceInitialValue => true;
protected override void AutomateTargetAcquisition() => TargetRectTransform = FindAutomatedTarget<RectTransform>();
[MMFInspectorGroup("Target RectTransform", true, 37, true)]
/// the target RectTransform to control
[Tooltip("the target RectTransform to control")]
public RectTransform TargetRectTransform;
[MMFInspectorGroup("Anchor Min", true, 43)]
/// whether or not to modify the min anchor
[Tooltip("whether or not to modify the min anchor")]
public bool ModifyAnchorMin = true;
/// the curve to animate the min anchor on
[Tooltip("the curve to animate the min anchor on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public MMTweenType AnchorMinCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)));
/// the value to remap the min anchor curve's 0 on
[Tooltip("the value to remap the min anchor curve's 0 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public Vector2 AnchorMinRemapZero = Vector2.zero;
/// the value to remap the min anchor curve's 1 on
[Tooltip("the value to remap the min anchor curve's 1 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime, (int)MMFeedbackBase.Modes.Instant)]
public Vector2 AnchorMinRemapOne = Vector2.one;
[MMFInspectorGroup("Anchor Max", true, 44)]
/// whether or not to modify the max anchor
[Tooltip("whether or not to modify the max anchor")]
public bool ModifyAnchorMax = true;
/// the curve to animate the max anchor on
[Tooltip("the curve to animate the max anchor on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public MMTweenType AnchorMaxCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)));
/// the value to remap the max anchor curve's 0 on
[Tooltip("the value to remap the max anchor curve's 0 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public Vector2 AnchorMaxRemapZero = Vector2.zero;
/// the value to remap the max anchor curve's 1 on
[Tooltip("the value to remap the max anchor curve's 1 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime, (int)MMFeedbackBase.Modes.Instant)]
public Vector2 AnchorMaxRemapOne = Vector2.one;
protected override void FillTargets()
{
if (TargetRectTransform == null)
{
return;
}
MMF_FeedbackBaseTarget targetMin = new MMF_FeedbackBaseTarget();
MMPropertyReceiver receiverMin = new MMPropertyReceiver();
receiverMin.TargetObject = TargetRectTransform.gameObject;
receiverMin.TargetComponent = TargetRectTransform;
receiverMin.TargetPropertyName = "anchorMin";
receiverMin.RelativeValue = RelativeValues;
receiverMin.Vector2RemapZero = AnchorMinRemapZero;
receiverMin.Vector2RemapOne = AnchorMinRemapOne;
receiverMin.ShouldModifyValue = ModifyAnchorMin;
targetMin.Target = receiverMin;
targetMin.LevelCurve = AnchorMinCurve;
targetMin.RemapLevelZero = 0f;
targetMin.RemapLevelOne = 1f;
targetMin.InstantLevel = 1f;
_targets.Add(targetMin);
MMF_FeedbackBaseTarget targetMax = new MMF_FeedbackBaseTarget();
MMPropertyReceiver receiverMax = new MMPropertyReceiver();
receiverMax.TargetObject = TargetRectTransform.gameObject;
receiverMax.TargetComponent = TargetRectTransform;
receiverMax.TargetPropertyName = "anchorMax";
receiverMax.RelativeValue = RelativeValues;
receiverMax.Vector2RemapZero = AnchorMaxRemapZero;
receiverMax.Vector2RemapOne = AnchorMaxRemapOne;
receiverMax.ShouldModifyValue = ModifyAnchorMax;
targetMax.Target = receiverMax;
targetMax.LevelCurve = AnchorMaxCurve;
targetMax.RemapLevelZero = 0f;
targetMax.RemapLevelOne = 1f;
targetMax.InstantLevel = 1f;
_targets.Add(targetMax);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 40c1cb23e17feb24ca503ff4d7cbf7b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMFeedbacks/MMFeedbacksForThirdParty/MMTools/Feedbacks/MMF_RectTransformAnchor.cs
uploadId: 830868

View File

@@ -0,0 +1,109 @@
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
namespace MoreMountains.Feedbacks
{
/// <summary>
/// This feedback lets you control the offset of the lower left corner of the rectangle relative to the lower left anchor, and the offset of the upper right corner of the rectangle relative to the upper right anchor.
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback lets you control the offset of the lower left corner of the rectangle relative to the lower left anchor, and the offset of the upper right corner of the rectangle relative to the upper right anchor.")]
[MovedFrom(false, null, "MoreMountains.Feedbacks.MMTools")]
[System.Serializable]
[FeedbackPath("UI/RectTransform Offset")]
public class MMF_RectTransformOffset : MMF_FeedbackBase
{
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
public override bool EvaluateRequiresSetup() { return (TargetRectTransform == null); }
public override string RequiredTargetText { get { return TargetRectTransform != null ? TargetRectTransform.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires that a TargetRectTransform be set to be able to work properly. You can set one below."; } }
#endif
public override bool HasAutomatedTargetAcquisition => true;
public override bool CanForceInitialValue => true;
protected override void AutomateTargetAcquisition() => TargetRectTransform = FindAutomatedTarget<RectTransform>();
[MMFInspectorGroup("Target RectTransform", true, 37, true)]
/// The RectTransform we want to modify
public RectTransform TargetRectTransform;
[MMFInspectorGroup("Offset Min", true, 40)]
/// whether we should modify the offset min or not
[Tooltip("whether we should modify the offset min or not")]
public bool ModifyOffsetMin = true;
/// the curve to animate the min offset on
[Tooltip("the curve to animate the min offset on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public MMTweenType OffsetMinCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)));
/// the value to remap the min curve's 0 on
[Tooltip("the value to remap the min curve's 0 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public Vector2 OffsetMinRemapZero = Vector2.zero;
/// the value to remap the min curve's 1 on
[Tooltip("the value to remap the min curve's 1 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime, (int)MMFeedbackBase.Modes.Instant)]
public Vector2 OffsetMinRemapOne = Vector2.one;
[MMFInspectorGroup("Offset Max", true, 41)]
/// whether we should modify the offset max or not
[Tooltip("whether we should modify the offset max or not")]
public bool ModifyOffsetMax = true;
/// the curve to animate the max offset on
[Tooltip("the curve to animate the max offset on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public MMTweenType OffsetMaxCurve = new MMTweenType(new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)));
/// the value to remap the max curve's 0 on
[Tooltip("the value to remap the max curve's 0 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime)]
public Vector2 OffsetMaxRemapZero = Vector2.zero;
/// the value to remap the max curve's 1 on
[Tooltip("the value to remap the max curve's 1 on")]
[MMFEnumCondition("Mode", (int)MMFeedbackBase.Modes.OverTime, (int)MMFeedbackBase.Modes.Instant)]
public Vector2 OffsetMaxRemapOne = Vector2.one;
protected override void FillTargets()
{
if (TargetRectTransform == null)
{
return;
}
MMF_FeedbackBaseTarget targetMin = new MMF_FeedbackBaseTarget();
MMPropertyReceiver receiverMin = new MMPropertyReceiver();
receiverMin.TargetObject = TargetRectTransform.gameObject;
receiverMin.TargetComponent = TargetRectTransform;
receiverMin.TargetPropertyName = "offsetMin";
receiverMin.RelativeValue = RelativeValues;
receiverMin.Vector2RemapZero = OffsetMinRemapZero;
receiverMin.Vector2RemapOne = OffsetMinRemapOne;
receiverMin.ShouldModifyValue = ModifyOffsetMin;
targetMin.Target = receiverMin;
targetMin.LevelCurve = OffsetMinCurve;
targetMin.RemapLevelZero = 0f;
targetMin.RemapLevelOne = 1f;
targetMin.InstantLevel = 1f;
_targets.Add(targetMin);
MMF_FeedbackBaseTarget targetMax = new MMF_FeedbackBaseTarget();
MMPropertyReceiver receiverMax = new MMPropertyReceiver();
receiverMax.TargetObject = TargetRectTransform.gameObject;
receiverMax.TargetComponent = TargetRectTransform;
receiverMax.TargetPropertyName = "offsetMax";
receiverMax.RelativeValue = RelativeValues;
receiverMax.Vector2RemapZero = OffsetMaxRemapZero;
receiverMax.Vector2RemapOne = OffsetMaxRemapOne;
receiverMax.ShouldModifyValue = ModifyOffsetMax;
targetMax.Target = receiverMax;
targetMax.LevelCurve = OffsetMaxCurve;
targetMax.RemapLevelZero = 0f;
targetMax.RemapLevelOne = 1f;
targetMax.InstantLevel = 1f;
_targets.Add(targetMax);
}
}
}

Some files were not shown because too many files have changed in this diff Show More