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,58 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Use this class to enable or disable other gameobjects automatically on Start or Awake
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Activation On Start")]
public class MMActivationOnStart : MonoBehaviour
{
/// The possible modes that define whether this should run at Awake or Start
public enum Modes { Awake, Start }
/// the selected mode for this instance
public Modes Mode = Modes.Start;
/// if true, objects will be activated on start, disabled otherwise
public bool StateOnStart = true;
/// the list of gameobjects whose active state will be affected on start
public List<GameObject> TargetObjects;
/// <summary>
/// On Awake, we set our state if needed
/// </summary>
protected virtual void Awake()
{
if (Mode != Modes.Awake)
{
return;
}
SetState();
}
/// <summary>
/// On Start, we set our state if needed
/// </summary>
protected virtual void Start()
{
if (Mode != Modes.Start)
{
return;
}
SetState();
}
/// <summary>
/// Sets the state of all target objects
/// </summary>
protected virtual void SetState()
{
foreach (GameObject obj in TargetObjects)
{
obj.SetActive(StateOnStart);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 55a9829731bf3d3458319a5a829f1f04
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/MMTools/Accessories/MMActivation/MMActivationOnStart.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to store bindings
/// </summary>
[Serializable]
public class PlatformBindings
{
public enum PlatformActions { DoNothing, Disable }
public RuntimePlatform Platform = RuntimePlatform.WindowsPlayer;
public PlatformActions PlatformAction = PlatformActions.DoNothing;
}
/// <summary>
/// Add this class to a gameobject, and it'll enable/disable it based on platform context, using Application.platform to detect the platform
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Application Platform Activation")]
public class MMApplicationPlatformActivation : MonoBehaviour
{
/// the possible times at which this script can run
public enum ExecutionTimes { Awake, Start, OnEnable }
[Header("Settings")]
/// the selected execution time
public ExecutionTimes ExecutionTime = ExecutionTimes.Awake;
/// whether or not this should output a debug line in the console
public bool DebugToTheConsole = false;
[Header("Platforms")]
public List<PlatformBindings> Platforms;
/// <summary>
/// On Enable, processes the state if needed
/// </summary>
protected virtual void OnEnable()
{
if (ExecutionTime == ExecutionTimes.OnEnable)
{
Process();
}
}
/// <summary>
/// On Awake, processes the state if needed
/// </summary>
protected virtual void Awake()
{
if (ExecutionTime == ExecutionTimes.Awake)
{
Process();
}
}
/// <summary>
/// On Start, processes the state if needed
/// </summary>
protected virtual void Start()
{
if (ExecutionTime == ExecutionTimes.Start)
{
Process();
}
}
/// <summary>
/// Enables or disables the object based on current platform
/// </summary>
protected virtual void Process()
{
foreach (PlatformBindings platform in Platforms)
{
if (platform.Platform == Application.platform)
{
DisableIfNeeded(platform.PlatformAction, platform.Platform.ToString());
}
}
if (Application.platform == RuntimePlatform.Android)
{
}
}
/// <summary>
/// Disables the object if needed, and outputs a debug log if requested
/// </summary>
/// <param name="platform"></param>
/// <param name="platformName"></param>
protected virtual void DisableIfNeeded(PlatformBindings.PlatformActions platform, string platformName)
{
if (this.gameObject.activeInHierarchy && (platform == PlatformBindings.PlatformActions.Disable))
{
this.gameObject.SetActive(false);
if (DebugToTheConsole)
{
Debug.LogFormat(this.gameObject.name + " got disabled via MMPlatformActivation, platform : " + platformName + ".");
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 4b49077b56e67ff469bc52b6a64e5e17
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/MMTools/Accessories/MMActivation/MMApplicationPlatformActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// A data class to store auto execution info to be used in MMAutoExecution
/// </summary>
[System.Serializable]
public class MMAutoExecutionItem
{
/// if this is true, Event will be invoked on Awake
public bool AutoExecuteOnAwake;
/// if this is true, Event will be invoked on Enable
public bool AutoExecuteOnEnable;
/// if this is true, Event will be invoked on Disable
public bool AutoExecuteOnDisable;
/// if this is true, Event will be invoked on Start
public bool AutoExecuteOnStart;
/// if this is true, Event will be invoked on Instantiate (you'll need to send a OnInstantiate message for this to happen
public bool AutoExecuteOnInstantiate;
public UnityEvent Event;
}
/// <summary>
/// This simple class lets you trigger Unity events automatically, on Awake, Enable, Disable, Start, or on instantiate
/// For that last one, you'll want to send a "OnInstantiate" message when instantiating this object
/// </summary>
public class MMAutoExecution : MonoBehaviour
{
/// a list of events to trigger automatically
public List<MMAutoExecutionItem> Events;
/// <summary>
/// On Awake we invoke our events if needed
/// </summary>
protected virtual void Awake()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnAwake) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Start we invoke our events if needed
/// </summary>
protected virtual void Start()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnStart) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Enable we invoke our events if needed
/// </summary>
protected virtual void OnEnable()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnEnable) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Enable we invoke our events if needed
/// </summary>
protected virtual void OnDisable()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnDisable) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Instantiate we invoke our events if needed
/// </summary>
protected virtual void OnInstantiate()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnInstantiate) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 723c68a65280145479e4e0b2f94a6ff0
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/MMTools/Accessories/MMActivation/MMAutoExecution.cs
uploadId: 830868

View File

@@ -0,0 +1,46 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to a gameobject, and it'll let you enable target monos after all other targets have been disabled
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Conditional Activation")]
public class MMConditionalActivation : MonoBehaviour
{
/// a list of monos to enable
public MonoBehaviour[] EnableThese;
/// a list of all the monos that have to have been disabled first
public MonoBehaviour[] AfterTheseAreAllDisabled;
protected bool _enabled = false;
/// <summary>
/// On update, we check if we should disable
/// </summary>
protected virtual void Update()
{
if (_enabled)
{
return;
}
bool allDisabled = true;
foreach (MonoBehaviour component in AfterTheseAreAllDisabled)
{
if (component.isActiveAndEnabled)
{
allDisabled = false;
}
}
if (allDisabled)
{
foreach (MonoBehaviour component in EnableThese)
{
component.enabled = true;
}
_enabled = true;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8434b53deaa9ae04f87f3c24bf70d482
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/MMTools/Accessories/MMActivation/MMConditionalActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,18 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to an object and it'll persist across scenes
/// </summary>
public class MMDontDestroyOnLoad : MonoBehaviour
{
/// <summary>
/// On Awake we make sure our object will not destroy on the next scene load
/// </summary>
protected void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c6dc6bc8e4bb2834e80531c648886d13
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/MMTools/Accessories/MMActivation/MMDontDestroyOnLoad.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
using UnityEngine.InputSystem;
#endif
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to store MMInputExecution bindings, associating a target keycode to UnityEvents
/// </summary>
[System.Serializable]
public class MMInputExecutionBinding
{
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
public Key TargetInputKey = Key.Space;
#else
/// the key the user needs to press to trigger events
public KeyCode TargetKey = KeyCode.Space;
#endif
/// the event to trigger when the key is pressed down
public UnityEvent OnKeyDown;
/// the event to trigger every frame if the key is being pressed
public UnityEvent OnKey;
/// the event to trigger when the key is released
public UnityEvent OnKeyUp;
/// <summary>
/// Checks for input and invokes events if needed
/// </summary>
public virtual void ProcessInput()
{
bool key = false;
bool keyDown = false;
bool keyUp = false;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
key = Keyboard.current[TargetInputKey].isPressed;
keyDown = Keyboard.current[TargetInputKey].wasPressedThisFrame;
keyUp = Keyboard.current[TargetInputKey].wasReleasedThisFrame;
#else
key = Input.GetKey(TargetKey);
keyDown = Input.GetKeyDown(TargetKey);
keyUp = Input.GetKeyUp(TargetKey);
#endif
if (OnKey != null)
{
if (key)
{
OnKey.Invoke();
}
}
if (OnKeyDown != null)
{
if (keyDown)
{
OnKeyDown.Invoke();
}
}
if (OnKeyUp != null)
{
if (keyUp)
{
OnKeyUp.Invoke();
}
}
}
}
/// <summary>
/// A simple class used to bind target keys to specific events to trigger when the key is pressed or released
/// </summary>
public class MMInputExecution : MonoBehaviour
{
[Header("Bindings")]
/// a list of bindings
public List<MMInputExecutionBinding> Bindings;
/// <summary>
/// On update we process our input
/// </summary>
protected virtual void Update()
{
HandleInput();
}
/// <summary>
/// Parses all bindings and asks them to trigger events if needed
/// </summary>
protected virtual void HandleInput()
{
if (Bindings == null)
{
return;
}
foreach(MMInputExecutionBinding binding in Bindings)
{
binding.ProcessInput();
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: af3876ae77702e24e8e1b06f675c0860
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/MMTools/Accessories/MMActivation/MMInputExecution.cs
uploadId: 830868

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// Attach this class to a collider and it'll let you trigger events when the user clicks/drags/enters/etc that collider
/// </summary>
public class MMOnMouse : MonoBehaviour
{
/// OnMouseDown is called when the user has pressed the mouse button while over the Collider.
[Tooltip("OnMouseDown is called when the user has pressed the mouse button while over the Collider.")]
public UnityEvent OnMouseDownEvent;
/// OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse.
[Tooltip("OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse.")]
public UnityEvent OnMouseDragEvent;
/// Called when the mouse enters the Collider.
[Tooltip("Called when the mouse enters the Collider.")]
public UnityEvent OnMouseEnterEvent;
/// Called when the mouse is not any longer over the Collider.
[Tooltip("Called when the mouse is not any longer over the Collider.")]
public UnityEvent OnMouseExitEvent;
/// Called every frame while the mouse is over the Collider.
[Tooltip("Called every frame while the mouse is over the Collider.")]
public UnityEvent OnMouseOverEvent;
/// OnMouseUp is called when the user has released the mouse button.
[Tooltip("OnMouseUp is called when the user has released the mouse button.")]
public UnityEvent OnMouseUpEvent;
/// OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed.
[Tooltip("OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed.")]
public UnityEvent OnMouseUpAsButtonEvent;
protected virtual void OnMouseDown()
{
OnMouseDownEvent.Invoke();
}
protected virtual void OnMouseDrag()
{
OnMouseDragEvent.Invoke();
}
protected virtual void OnMouseEnter()
{
OnMouseEnterEvent.Invoke();
}
protected virtual void OnMouseExit()
{
OnMouseExitEvent.Invoke();
}
protected virtual void OnMouseOver()
{
OnMouseOverEvent.Invoke();
}
protected virtual void OnMouseUp()
{
OnMouseUpEvent.Invoke();
}
protected virtual void OnMouseUpAsButton()
{
OnMouseUpAsButtonEvent.Invoke();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 80361f5e0185bb247a814457c589c1f3
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/MMTools/Accessories/MMActivation/MMOnMouse.cs
uploadId: 830868

View File

@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This component lets you parent the transform you put it on to any target parent (or to the root if none is set), on Awake, Start or anytime you call its Parent() method
/// </summary>
public class MMParentingOnStart : MonoBehaviour
{
/// the possible modes this can run on
public enum Modes { Awake, Start, Script }
/// the selected mode
public Modes Mode = Modes.Awake;
/// the parent to parent to, leave empty if you want to unparent completely
public Transform TargetParent;
/// <summary>
/// On Awake we parent if needed
/// </summary>
protected virtual void Awake()
{
if (Mode == Modes.Awake)
{
Parent();
}
}
/// <summary>
/// On Start we parent if needed
/// </summary>
protected virtual void Start()
{
if (Mode == Modes.Start)
{
Parent();
}
}
/// <summary>
/// Sets this transform's parent to the target
/// </summary>
public virtual void Parent()
{
this.transform.SetParent(TargetParent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 996385a9b56b4d14eb03dc65ed309620
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/MMTools/Accessories/MMActivation/MMParentingOnStart.cs
uploadId: 830868

View File

@@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// This class will let you trigger a OnRandomInterval event periodically, at random intervals
/// </summary>
public class MMPeriodicExecution : MonoBehaviour
{
/// the min and max duration of the interval between two events, in seconds
[MMVector("Min", "Max")]
public Vector2 RandomIntervalDuration = new Vector2(1f, 3f);
/// the event to play at the end of each interval
public UnityEvent OnRandomInterval;
protected float _lastUpdateAt = 0f;
protected float _currentInterval = 0f;
/// <summary>
/// On Start we initialize our interval duration
/// </summary>
protected virtual void Start()
{
DetermineNewInterval();
}
/// <summary>
/// On Update we check if we've reached the end of an interval
/// </summary>
protected virtual void Update()
{
if (Time.time - _lastUpdateAt > _currentInterval)
{
OnRandomInterval?.Invoke();
_lastUpdateAt = Time.time;
DetermineNewInterval();
}
}
/// <summary>
/// Randomizes a new duration
/// </summary>
protected virtual void DetermineNewInterval()
{
_currentInterval = Random.Range(RandomIntervalDuration.x, RandomIntervalDuration.y);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b91c53058d9ddc04bbc92506986923a3
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/MMTools/Accessories/MMActivation/MMPeriodicExecution.cs
uploadId: 830868

View File

@@ -0,0 +1,230 @@
using UnityEngine;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this class to a gameobject, and it'll enable/disable it based on platform context, using conditional defintions to do so
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Platform Activation")]
public class MMPlatformActivation : MonoBehaviour
{
/// the possible times at which this script can run
public enum ExecutionTimes { Awake, Start, OnEnable }
public enum PlatformActions { DoNothing, Disable }
[Header("Settings")]
/// the selected execution time
public ExecutionTimes ExecutionTime = ExecutionTimes.Awake;
/// whether or not this should output a debug line in the console
public bool DebugToTheConsole = false;
[Header("Desktop")]
/// whether or not this gameobject should be active on Windows
public PlatformActions UNITY_STANDALONE_WIN = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on OSX
public PlatformActions UNITY_STANDALONE_OSX = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Linux
public PlatformActions UNITY_STANDALONE_LINUX = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on standalone
public PlatformActions UNITY_STANDALONE = PlatformActions.DoNothing;
[Header("Mobile")]
/// whether or not this gameobject should be active on iOS
public PlatformActions UNITY_IOS = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on iPhone
public PlatformActions UNITY_IPHONE = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Android
public PlatformActions UNITY_ANDROID = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Tizen
public PlatformActions UNITY_TIZEN = PlatformActions.DoNothing;
[Header("Console")]
/// whether or not this gameobject should be active on Wii
public PlatformActions UNITY_WII = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on PS4
public PlatformActions UNITY_PS4 = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on XBoxOne
public PlatformActions UNITY_XBOXONE = PlatformActions.DoNothing;
[Header("Others")]
/// whether or not this gameobject should be active on WebGL
public PlatformActions UNITY_WEBGL = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Lumin
public PlatformActions UNITY_LUMIN = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on TVOS
public PlatformActions UNITY_TVOS = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on WSA
public PlatformActions UNITY_WSA = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Facebook
public PlatformActions UNITY_FACEBOOK = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Ads
public PlatformActions UNITY_ADS = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Analytics
public PlatformActions UNITY_ANALYTICS = PlatformActions.DoNothing;
[Header("Active in Editor")]
/// whether or not this gameobject should be active in Editor
public PlatformActions UNITY_EDITOR = PlatformActions.DoNothing;
/// whether or not this gameobject should be active in Editor on Windows
public PlatformActions UNITY_EDITOR_WIN = PlatformActions.DoNothing;
/// whether or not this gameobject should be active in Editor on OSX
public PlatformActions UNITY_EDITOR_OSX = PlatformActions.DoNothing;
/// whether or not this gameobject should be active in Editor on Linux
public PlatformActions UNITY_EDITOR_LINUX = PlatformActions.DoNothing;
/// <summary>
/// On Enable, processes the state if needed
/// </summary>
protected virtual void OnEnable()
{
if (ExecutionTime == ExecutionTimes.OnEnable)
{
Process();
}
}
/// <summary>
/// On Awake, processes the state if needed
/// </summary>
protected virtual void Awake()
{
if (ExecutionTime == ExecutionTimes.Awake)
{
Process();
}
}
/// <summary>
/// On Start, processes the state if needed
/// </summary>
protected virtual void Start()
{
if (ExecutionTime == ExecutionTimes.Start)
{
Process();
}
}
/// <summary>
/// Enables or disables the object based on current platform
/// </summary>
protected virtual void Process()
{
// DESKTOP ----------------------------------------------------------------------------------
#if UNITY_STANDALONE_WIN
DisableIfNeeded(UNITY_STANDALONE_WIN, "Windows");
#endif
#if UNITY_STANDALONE_OSX
DisableIfNeeded(UNITY_STANDALONE_OSX, "OSX");
#endif
#if UNITY_STANDALONE_LINUX
DisableIfNeeded(UNITY_STANDALONE_LINUX, "Linux");
#endif
#if UNITY_STANDALONE
DisableIfNeeded(UNITY_STANDALONE, "Standalone");
#endif
// MOBILE ----------------------------------------------------------------------------------
#if UNITY_IOS
DisableIfNeeded(UNITY_IOS, "iOS");
#endif
#if UNITY_IPHONE
DisableIfNeeded(UNITY_IPHONE, "iPhone");
#endif
#if UNITY_ANDROID
DisableIfNeeded(UNITY_ANDROID, "Android");
#endif
#if UNITY_TIZEN
DisableIfNeeded(UNITY_TIZEN, "Tizen");
#endif
// CONSOLE ----------------------------------------------------------------------------------
#if UNITY_WII
DisableIfNeeded(UNITY_WII, "Wii");
#endif
#if UNITY_PS4
DisableIfNeeded(UNITY_PS4, "PS4");
#endif
#if UNITY_XBOXONE
DisableIfNeeded(UNITY_XBOXONE, "XBoxOne");
#endif
// CONSOLE ----------------------------------------------------------------------------------
#if UNITY_WEBGL
DisableIfNeeded(UNITY_WEBGL, "WebGL");
#endif
#if UNITY_LUMIN
DisableIfNeeded(UNITY_LUMIN, "Lumin");
#endif
#if UNITY_TVOS
DisableIfNeeded(UNITY_TVOS, "TV OS");
#endif
#if UNITY_WSA
DisableIfNeeded(UNITY_WSA, "WSA");
#endif
#if UNITY_FACEBOOK
DisableIfNeeded(UNITY_FACEBOOK, "Facebook");
#endif
#if UNITY_ADS
DisableIfNeeded(UNITY_ADS, "Ads");
#endif
#if UNITY_ANALYTICS
DisableIfNeeded(UNITY_ANALYTICS, "Analytics");
#endif
// EDITOR ----------------------------------------------------------------------------------
#if UNITY_EDITOR
DisableIfNeeded(UNITY_EDITOR, "Editor");
#endif
#if UNITY_EDITOR_WIN
DisableIfNeeded(UNITY_EDITOR_WIN, "Editor Windows");
#endif
#if UNITY_EDITOR_OSX
DisableIfNeeded(UNITY_EDITOR_OSX, "Editor OSX");
#endif
#if UNITY_EDITOR_LINUX
DisableIfNeeded(UNITY_EDITOR_LINUX, "Editor Linux");
#endif
}
/// <summary>
/// Disables the object if needed, and outputs a debug log if requested
/// </summary>
/// <param name="platform"></param>
/// <param name="platformName"></param>
protected virtual void DisableIfNeeded(PlatformActions platform, string platformName)
{
if (this.gameObject.activeInHierarchy && (platform == PlatformActions.Disable))
{
this.gameObject.SetActive(false);
if (DebugToTheConsole)
{
Debug.LogFormat(this.gameObject.name + " got disabled via MMPlatformActivation, platform : " + platformName + ".");
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5a39fcd2b055db14184fbda2b333f40c
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/MMTools/Accessories/MMActivation/MMPlatformActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,255 @@
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to an object and it'll be auto destroyed X seconds after its Start()
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Timed Activation")]
public class MMTimedActivation : MonoBehaviour
{
/// the possible activation modes
public enum TimedStatusChange { Enable, Disable, Destroy }
/// the possible trigger modes
public enum ActivationModes { Awake, Start, OnEnable, OnTriggerEnter, OnTriggerExit, OnTriggerEnter2D, OnTriggerExit2D, Script }
/// the possible ways to check if the collider matches
public enum TriggerModes { None, Tag, Layer }
/// the possible delay modes
public enum DelayModes { Time, Frames }
[Header("Trigger Mode")]
/// the moment you want the countdown to state change to start
public ActivationModes ActivationMode = ActivationModes.Start;
/// the target layer for activation if using OnTriggerEnter or OnTriggerExit
[MMEnumCondition("ActivationMode", (int)ActivationModes.OnTriggerEnter, (int)ActivationModes.OnTriggerExit)]
public TriggerModes TriggerMode;
/// the layer the target collider should be on
[MMEnumCondition("TriggerMode", (int)TriggerModes.Layer)]
public LayerMask TargetTriggerLayer;
/// the tag the target collider should have
[MMEnumCondition("TriggerMode", (int)TriggerModes.Tag)]
public string TargetTriggerTag;
[Header("Delay")]
/// the chosen delay mode, whether to wait in seconds or frames
public DelayModes DelayMode = DelayModes.Time;
/// The time (in seconds) before we destroy the object
[MMEnumCondition("DelayMode", (int)DelayModes.Time)]
public float TimeBeforeStateChange = 2;
/// the amount of frames to wait for when in Frames DelayMode
[MMEnumCondition("DelayMode", (int)DelayModes.Frames)]
public int FrameCount = 1;
[Header("Timed Activation")]
/// the possible targets you want the state to change
public List<GameObject> TargetGameObjects;
/// the possible targets you want the state to change
public List<MonoBehaviour> TargetBehaviours;
/// the destruction mode for this object : destroy or disable
public TimedStatusChange TimeDestructionMode = TimedStatusChange.Disable;
[Header("Actions")]
/// Unity events to trigger after the delay
public UnityEvent TimedActions;
/// <summary>
/// On awake, initialize our delay and trigger our change state countdown if needed
/// </summary>
protected virtual void Awake()
{
if (ActivationMode == ActivationModes.Awake)
{
StartChangeState();
}
}
/// <summary>
/// Call this method to start the countdown to activation
/// </summary>
public virtual void TriggerSequence()
{
StartChangeState();
}
/// <summary>
/// On start, trigger our change state countdown if needed
/// </summary>
protected virtual void Start()
{
if (ActivationMode == ActivationModes.Start)
{
StartChangeState();
}
}
/// <summary>
/// On enable, trigger our change state countdown if needed
/// </summary>
protected virtual void OnEnable()
{
if (ActivationMode == ActivationModes.OnEnable)
{
StartChangeState();
}
}
/// <summary>
/// On trigger enter, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerEnter(Collider collider)
{
if ((ActivationMode == ActivationModes.OnTriggerEnter) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
/// <summary>
/// On trigger exit, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerExit(Collider collider)
{
if ((ActivationMode == ActivationModes.OnTriggerExit) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
#if MM_PHYSICS2D
/// <summary>
/// On trigger enter 2D, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerEnter2D(Collider2D collider)
{
if ((ActivationMode == ActivationModes.OnTriggerEnter2D) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
/// <summary>
/// On trigger exit 2D, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerExit2D(Collider2D collider)
{
if ((ActivationMode == ActivationModes.OnTriggerExit2D) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
#endif
/// <summary>
/// Returns true if the target matches our settings, false otherwise
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
protected virtual bool CorrectTagOrLayer(GameObject target)
{
switch (TriggerMode)
{
case TriggerModes.None:
return true;
case TriggerModes.Layer:
if (((1 << target.layer) & TargetTriggerLayer) != 0)
{
return true;
}
else
{
return false;
}
case TriggerModes.Tag:
return (target.CompareTag(TargetTriggerTag));
}
return false;
}
/// <summary>
/// On start change state, starts the timed activation
/// </summary>
protected virtual void StartChangeState()
{
StartCoroutine(TimedActivationSequence());
}
/// <summary>
/// Waits and triggers state change and events
/// </summary>
protected virtual IEnumerator TimedActivationSequence()
{
if (DelayMode == DelayModes.Time)
{
yield return MMCoroutine.WaitFor(TimeBeforeStateChange);
}
else
{
yield return StartCoroutine(MMCoroutine.WaitForFrames(FrameCount));
}
StateChange();
Activate();
}
/// <summary>
/// Triggers actions if needed
/// </summary>
protected virtual void Activate()
{
if (TimedActions != null)
{
TimedActions.Invoke();
}
}
/// <summary>
/// Changes the object's status or destroys it
/// </summary>
protected virtual void StateChange()
{
foreach(GameObject targetGameObject in TargetGameObjects)
{
switch (TimeDestructionMode)
{
case TimedStatusChange.Destroy:
Destroy(targetGameObject);
break;
case TimedStatusChange.Disable:
targetGameObject.SetActive(false);
break;
case TimedStatusChange.Enable:
targetGameObject.SetActive(true);
break;
}
}
foreach (MonoBehaviour targetBehaviour in TargetBehaviours)
{
switch (TimeDestructionMode)
{
case TimedStatusChange.Destroy:
Destroy(targetBehaviour);
break;
case TimedStatusChange.Disable:
targetBehaviour.enabled = false;
break;
case TimedStatusChange.Enable:
targetBehaviour.enabled = true;
break;
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 46840d8dc203908469ee327b591ae35f
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/MMTools/Accessories/MMActivation/MMTimedActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,45 @@
using UnityEngine;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to an object and it'll be auto destroyed X seconds after its Start()
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Timed Destruction")]
public class MMTimedDestruction : MonoBehaviour
{
/// the possible destruction modes
public enum TimedDestructionModes { Destroy, Disable }
/// the destruction mode for this object : destroy or disable
public TimedDestructionModes TimeDestructionMode = TimedDestructionModes.Destroy;
/// The time (in seconds) before we destroy the object
public float TimeBeforeDestruction=2;
/// <summary>
/// On Start(), we schedule the object's destruction
/// </summary>
protected virtual void Start ()
{
StartCoroutine(Destruction());
}
/// <summary>
/// Destroys the object after TimeBeforeDestruction seconds
/// </summary>
protected virtual IEnumerator Destruction()
{
yield return MMCoroutine.WaitFor(TimeBeforeDestruction);
if (TimeDestructionMode == TimedDestructionModes.Destroy)
{
Destroy(gameObject);
}
else
{
gameObject.SetActive(false);
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 9e71ad30bf1524741b90c1bd0354e1e0
timeCreated: 1523894079
licenseType: Store
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/MMTools/Accessories/MMActivation/MMTimedDestruction.cs
uploadId: 830868

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This very simple class simply exposes a method to toggle the GameObject it's on (or a target one if left empty in the inspector) active or inactive
/// </summary>
public class MMToggleActive : MonoBehaviour
{
[Header("Target - leave empty for self")]
/// the target gameobject to toggle. Leave blank for auto grab
public GameObject TargetGameObject;
/// a test button
[MMInspectorButton("ToggleActive")]
public bool ToggleActiveButton;
/// <summary>
/// On awake, grabs self if needed
/// </summary>
protected virtual void Awake()
{
if (TargetGameObject == null)
{
TargetGameObject = this.gameObject;
}
}
/// <summary>
/// Toggles the target gameobject's active state
/// </summary>
public virtual void ToggleActive()
{
TargetGameObject.SetActive(!TargetGameObject.activeInHierarchy);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3aad8b45814dc6f4cab32abed0a152b8
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/MMTools/Accessories/MMActivation/MMToggleActive.cs
uploadId: 830868

View File

@@ -0,0 +1,141 @@
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
[AddComponentMenu("More Mountains/Tools/Activation/MM Trigger And Collision")]
public class MMTriggerAndCollision : MonoBehaviour
{
public LayerMask CollisionLayerMask;
public UnityEvent OnCollisionEnterEvent;
public UnityEvent OnCollisionExitEvent;
public UnityEvent OnCollisionStayEvent;
public LayerMask TriggerLayerMask;
public UnityEvent OnTriggerEnterEvent;
public UnityEvent OnTriggerExitEvent;
public UnityEvent OnTriggerStayEvent;
public LayerMask Collision2DLayerMask;
public UnityEvent OnCollision2DEnterEvent;
public UnityEvent OnCollision2DExitEvent;
public UnityEvent OnCollision2DStayEvent;
public LayerMask Trigger2DLayerMask;
public UnityEvent OnTrigger2DEnterEvent;
public UnityEvent OnTrigger2DExitEvent;
public UnityEvent OnTrigger2DStayEvent;
// Collision 2D ------------------------------------------------------------------------------------
#if MM_PHYSICS2D
protected virtual void OnCollisionEnter2D (Collision2D collision)
{
if (Collision2DLayerMask.MMContains (collision.gameObject))
{
OnCollision2DEnterEvent.Invoke();
}
}
protected virtual void OnCollisionExit2D (Collision2D collision)
{
if (Collision2DLayerMask.MMContains (collision.gameObject))
{
OnCollision2DExitEvent.Invoke();
}
}
protected virtual void OnCollisionStay2D (Collision2D collision)
{
if (Collision2DLayerMask.MMContains (collision.gameObject))
{
OnCollision2DStayEvent.Invoke();
}
}
// Trigger 2D ------------------------------------------------------------------------------------
protected virtual void OnTriggerEnter2D (Collider2D collider)
{
if (Trigger2DLayerMask.MMContains (collider.gameObject))
{
OnTrigger2DEnterEvent.Invoke();
}
}
protected virtual void OnTriggerExit2D (Collider2D collider)
{
if (Trigger2DLayerMask.MMContains (collider.gameObject))
{
OnTrigger2DExitEvent.Invoke();
}
}
protected virtual void OnTriggerStay2D (Collider2D collider)
{
if (Trigger2DLayerMask.MMContains (collider.gameObject))
{
OnTrigger2DStayEvent.Invoke();
}
}
#endif
// Collision ------------------------------------------------------------------------------------
protected virtual void OnCollisionEnter(Collision c)
{
if (0 != (CollisionLayerMask.value & 1 << c.transform.gameObject.layer))
{
OnCollisionEnterEvent.Invoke();
}
}
protected virtual void OnCollisionExit(Collision c)
{
if (0 != (CollisionLayerMask.value & 1 << c.transform.gameObject.layer))
{
OnCollisionExitEvent.Invoke();
}
}
protected virtual void OnCollisionStay(Collision c)
{
if (0 != (CollisionLayerMask.value & 1 << c.transform.gameObject.layer))
{
OnCollisionStayEvent.Invoke();
}
}
// Trigger ------------------------------------------------------------------------------------
protected virtual void OnTriggerEnter (Collider collider)
{
if (TriggerLayerMask.MMContains (collider.gameObject))
{
OnTriggerEnterEvent.Invoke();
}
}
protected virtual void OnTriggerExit (Collider collider)
{
if (TriggerLayerMask.MMContains (collider.gameObject))
{
OnTriggerExitEvent.Invoke();
}
}
protected virtual void OnTriggerStay (Collider collider)
{
if (TriggerLayerMask.MMContains (collider.gameObject))
{
OnTriggerStayEvent.Invoke();
}
}
protected virtual void Reset()
{
Collision2DLayerMask = LayerMask.NameToLayer("Everything");
CollisionLayerMask = LayerMask.NameToLayer("Everything");
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 007ea1391362e4845aee91886eb0cda3
timeCreated: 1523908029
licenseType: Store
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/MMTools/Accessories/MMActivation/MMTriggerAndCollision.cs
uploadId: 830868

View File

@@ -0,0 +1,161 @@
using UnityEngine;
namespace MoreMountains.Tools
{
[System.Flags]
public enum TriggerAndCollisionMask
{
IgnoreAll = 0,
OnTriggerEnter = 1 << 0,
OnTriggerStay = 1 << 1,
OnTriggerExit = 1 << 2,
OnCollisionEnter = 1 << 3,
OnCollisionStay = 1 << 4,
OnCollisionExit = 1 << 5,
OnTriggerEnter2D = 1 << 6,
OnTriggerStay2D = 1 << 7,
OnTriggerExit2D = 1 << 8,
OnCollisionEnter2D = 1 << 9,
OnCollisionStay2D = 1 << 10,
OnCollisionExit2D = 1 << 11,
OnAnyTrigger3D = OnTriggerEnter | OnTriggerStay | OnTriggerExit,
OnAnyCollision3D = OnCollisionEnter | OnCollisionStay | OnCollisionExit,
OnAnyTrigger2D = OnTriggerEnter2D | OnTriggerStay2D | OnTriggerExit2D,
OnAnyCollision2D = OnCollisionEnter2D | OnCollisionStay2D | OnCollisionExit2D,
OnAnyTrigger = OnAnyTrigger3D | OnAnyTrigger2D,
OnAnyCollision = OnAnyCollision3D | OnAnyCollision2D,
All_3D = OnAnyTrigger3D | OnAnyCollision3D,
All_2D = OnAnyTrigger2D | OnAnyCollision2D,
All = All_3D | All_2D,
}
public abstract class MMTriggerAndCollisionFilter : MonoBehaviour
{
public TriggerAndCollisionMask TriggerAndCollisionFilter = TriggerAndCollisionMask.All;
// Tested to check if callback should be used or ignored
protected virtual bool UseEvent(TriggerAndCollisionMask value) => 0 != (TriggerAndCollisionFilter & value);
// Collision 2D ------------------------------------------------------------------------------------
#if MM_PHYSICS2D
protected abstract void OnCollisionEnter2D_(Collision2D collision);
void OnCollisionEnter2D (Collision2D collision)
{
if (UseEvent(TriggerAndCollisionMask.OnCollisionEnter2D))
{
OnCollisionEnter2D_(collision);
}
}
protected abstract void OnCollisionExit2D_(Collision2D collision);
void OnCollisionExit2D (Collision2D collision)
{
if (UseEvent(TriggerAndCollisionMask.OnCollisionExit2D))
{
OnCollisionExit2D_(collision);
}
}
protected abstract void OnCollisionStay2D_(Collision2D collision);
void OnCollisionStay2D (Collision2D collision)
{
if (UseEvent(TriggerAndCollisionMask.OnCollisionStay2D))
{
OnCollisionStay2D_(collision);
}
}
// Trigger 2D ------------------------------------------------------------------------------------
protected abstract void OnTriggerEnter2D_(Collider2D collider);
void OnTriggerEnter2D (Collider2D collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerEnter2D))
{
OnTriggerEnter2D_(collider);
}
}
protected abstract void OnTriggerExit2D_(Collider2D collider);
void OnTriggerExit2D (Collider2D collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerExit2D))
{
OnTriggerExit2D_(collider);
}
}
protected abstract void OnTriggerStay2D_ (Collider2D collider);
void OnTriggerStay2D (Collider2D collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerStay2D))
{
OnTriggerStay2D_(collider);
}
}
#endif
// Collision ------------------------------------------------------------------------------------
protected abstract void OnCollisionEnter_ (Collision c);
void OnCollisionEnter(Collision c)
{
if (UseEvent(TriggerAndCollisionMask.OnCollisionEnter))
{
OnCollisionEnter_(c);
}
}
protected abstract void OnCollisionExit_ (Collision c);
void OnCollisionExit(Collision c)
{
if (UseEvent(TriggerAndCollisionMask.OnCollisionExit))
{
OnCollisionExit_(c);
}
}
protected abstract void OnCollisionStay_ (Collision c);
void OnCollisionStay(Collision c)
{
if (UseEvent(TriggerAndCollisionMask.OnCollisionStay))
{
OnCollisionStay_(c);
}
}
// Trigger ------------------------------------------------------------------------------------
protected abstract void OnTriggerEnter_(Collider collider);
void OnTriggerEnter (Collider collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerEnter))
{
OnTriggerEnter_(collider);
}
}
protected abstract void OnTriggerExit_(Collider collider);
void OnTriggerExit (Collider collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerExit))
{
OnTriggerExit_(collider);
}
}
protected abstract void OnTriggerStay_(Collider collider);
void OnTriggerStay (Collider collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerStay))
{
OnTriggerStay_(collider);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5cc2d50cc470a8b448cb93411e66d069
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/MMTools/Accessories/MMActivation/MMTriggerAndCollisionFilter.cs
uploadId: 830868

View File

@@ -0,0 +1,81 @@
using System;
using System.Web;
using UnityEngine;
namespace MoreMountains.Tools
{
public abstract class MMTriggerFilter : MonoBehaviour
{
public TriggerAndCollisionMask TriggerFilter = TriggerAndCollisionMask.All;
protected virtual void OnValidate()
{
// Only allow trigger related bits
TriggerFilter &= TriggerAndCollisionMask.OnAnyTrigger;
}
protected virtual bool UseEvent(TriggerAndCollisionMask value) => 0 != (TriggerFilter & value);
// Trigger 2D ------------------------------------------------------------------------------------
#if MM_PHYSICS2D
protected abstract void OnTriggerEnter2D_(Collider2D collider);
void OnTriggerEnter2D (Collider2D collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerEnter2D))
{
OnTriggerEnter2D_(collider);
}
}
protected abstract void OnTriggerExit2D_(Collider2D collider);
void OnTriggerExit2D (Collider2D collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerExit2D))
{
OnTriggerExit2D_(collider);
}
}
protected abstract void OnTriggerStay2D_ (Collider2D collider);
void OnTriggerStay2D (Collider2D collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerStay2D))
{
OnTriggerStay2D_(collider);
}
}
#endif
// Trigger ------------------------------------------------------------------------------------
protected abstract void OnTriggerEnter_(Collider collider);
void OnTriggerEnter (Collider collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerEnter))
{
OnTriggerEnter_(collider);
}
}
protected abstract void OnTriggerExit_(Collider collider);
void OnTriggerExit (Collider collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerExit))
{
OnTriggerExit_(collider);
}
}
protected abstract void OnTriggerStay_(Collider collider);
void OnTriggerStay (Collider collider)
{
if (UseEvent(TriggerAndCollisionMask.OnTriggerStay))
{
OnTriggerStay_(collider);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8583d7ca8b7ea2c418257447cb3032f9
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/MMTools/Accessories/MMActivation/MMTriggerFilter.cs
uploadId: 830868