#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.RigidbodyTasks { using Opsive.GraphDesigner.Runtime.Variables; using UnityEngine; [Opsive.Shared.Utility.Category("Rigidbody")] [Opsive.Shared.Utility.Description("Freezes/unfreezes specific constraints with smooth transition.")] public class FreezeConstraints : TargetGameObjectAction { [Tooltip("Freeze position on X axis.")] [SerializeField] protected SharedVariable m_FreezePositionX = false; [Tooltip("Freeze position on Y axis.")] [SerializeField] protected SharedVariable m_FreezePositionY = false; [Tooltip("Freeze position on Z axis.")] [SerializeField] protected SharedVariable m_FreezePositionZ = false; [Tooltip("Freeze rotation on X axis.")] [SerializeField] protected SharedVariable m_FreezeRotationX = false; [Tooltip("Freeze rotation on Y axis.")] [SerializeField] protected SharedVariable m_FreezeRotationY = false; [Tooltip("Freeze rotation on Z axis.")] [SerializeField] protected SharedVariable m_FreezeRotationZ = false; private UnityEngine.Rigidbody m_ResolvedRigidbody; /// /// Called when the state machine is initialized. /// /// /// Initializes the target GameObject. /// protected override void InitializeTarget() { base.InitializeTarget(); m_ResolvedRigidbody = m_ResolvedGameObject.GetComponent(); } /// /// Updates the constraints. /// /// The status of the action. public override TaskStatus OnUpdate() { if (m_ResolvedRigidbody == null) { return TaskStatus.Success; } var constraints = RigidbodyConstraints.None; if (m_FreezePositionX.Value) { constraints |= RigidbodyConstraints.FreezePositionX; } if (m_FreezePositionY.Value) { constraints |= RigidbodyConstraints.FreezePositionY; } if (m_FreezePositionZ.Value) { constraints |= RigidbodyConstraints.FreezePositionZ; } if (m_FreezeRotationX.Value) { constraints |= RigidbodyConstraints.FreezeRotationX; } if (m_FreezeRotationY.Value) { constraints |= RigidbodyConstraints.FreezeRotationY; } if (m_FreezeRotationZ.Value) { constraints |= RigidbodyConstraints.FreezeRotationZ; } m_ResolvedRigidbody.constraints = constraints; return TaskStatus.Success; } /// /// Resets the action values back to their default. /// public override void Reset() { base.Reset(); m_FreezePositionX = false; m_FreezePositionY = false; m_FreezePositionZ = false; m_FreezeRotationX = false; m_FreezeRotationY = false; m_FreezeRotationZ = false; } } } #endif