// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved. // This code can only be used under the standard Unity Asset Store End User License Agreement // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms using Doozy.Runtime.Common.Extensions; using Doozy.Runtime.Common.Utils; using Doozy.Runtime.Mody.Actions; using UnityEngine; using UnityEngine.Events; // ReSharper disable MemberCanBePrivate.Global namespace Doozy.Runtime.Mody.Modules { /// Mody module used to trigger a UnityEvent [AddComponentMenu("Doozy/Mody/UnityEvent Module")] public class UnityEventModule : ModyModule { #if UNITY_EDITOR [UnityEditor.MenuItem("GameObject/Doozy/Mody/UnityEvent Module", false, 8)] private static void CreateComponent(UnityEditor.MenuCommand menuCommand) { GameObjectUtils.AddToScene("UnityEvent Module", false, true); } #endif /// Default module name public const string DEFAULT_MODULE_NAME = "UnityEvent"; /// Target UnityEvent public UnityEvent Event = new UnityEvent(); /// Simple action that triggers the UnityEvent public SimpleModyAction InvokeEvent; /// Construct a UnityEvent Module with the default name public UnityEventModule() : this(DEFAULT_MODULE_NAME) {} /// Construct a UnityEvent Module with the given name /// Module name public UnityEventModule(string moduleName) : base(moduleName.IsNullOrEmpty() ? DEFAULT_MODULE_NAME : moduleName) {} /// Initialize the actions protected override void SetupActions() { this.AddAction(InvokeEvent ??= new SimpleModyAction(this, nameof(InvokeEvent), ExecuteInvokeEvent)); } /// Execute Invoke on the UnityEvent public void ExecuteInvokeEvent() { Event?.Invoke(); } } }