using CinemaDirector.Helpers; using System.Collections.Generic; using UnityEngine; namespace CinemaDirector { /// /// An event to set the mass of the rigidbody of a given actor. /// [CutsceneItemAttribute("Physics", "Set Mass", CutsceneItemGenre.ActorItem)] public class SetMassEvent : CinemaActorEvent, IRevertable { // The new mass. public float Mass = 1f; // Options for reverting in editor. [SerializeField] private RevertMode editorRevertMode = RevertMode.Revert; // Options for reverting during runtime. [SerializeField] private RevertMode runtimeRevertMode = RevertMode.Revert; /// /// Cache the state of all actors related to this event. /// /// All the revert info related to this event. public RevertInfo[] CacheState() { List actors = new List(GetActors()); List reverts = new List(); foreach (Transform go in actors) { if (go != null) { Rigidbody rb = go.GetComponent(); if (rb != null) { reverts.Add(new RevertInfo(this, rb, "mass", rb.mass)); } } } return reverts.ToArray(); } /// /// Trigger this event and set a new mass for the actor's rigidbody. /// /// The actor whose mass will be set. public override void Trigger(GameObject actor) { if (actor == null) return; Rigidbody affectedObjectRigidBody = actor.GetComponent(); if (affectedObjectRigidBody != null) { affectedObjectRigidBody.mass = Mass; } } /// /// Option for choosing when this Event will Revert to initial state in Editor. /// public RevertMode EditorRevertMode { get { return editorRevertMode; } set { editorRevertMode = value; } } /// /// Option for choosing when this Event will Revert to initial state in Runtime. /// public RevertMode RuntimeRevertMode { get { return runtimeRevertMode; } set { runtimeRevertMode = value; } } } }