#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.Conversions { using Opsive.GraphDesigner.Runtime.Variables; using UnityEngine; [Opsive.Shared.Utility.Category("Conversions")] [Opsive.Shared.Utility.Description("Gets the root GameObject (topmost parent) from a GameObject or Transform.")] public class GetRootGameObject : Action { [Tooltip("The GameObject to get the root from. If null, uses Transform.")] [SerializeField] protected SharedVariable m_SourceGameObject; [Tooltip("The Transform to get the root from. Only used if GameObject is null.")] [SerializeField] protected SharedVariable m_SourceTransform; [Tooltip("The resulting root GameObject.")] [SerializeField] [RequireShared] protected SharedVariable m_RootGameObject; /// /// Gets the root GameObject. /// /// The status of the action. public override TaskStatus OnUpdate() { Transform sourceTransform = null; if (m_SourceGameObject.Value != null) { sourceTransform = m_SourceGameObject.Value.transform; } else if (m_SourceTransform.Value != null) { sourceTransform = m_SourceTransform.Value; } if (sourceTransform == null) { m_RootGameObject.Value = null; return TaskStatus.Success; } m_RootGameObject.Value = sourceTransform.root.gameObject; return TaskStatus.Success; } /// /// Resets the action values back to their default. /// public override void Reset() { base.Reset(); m_SourceGameObject = null; m_SourceTransform = null; m_RootGameObject = null; } } } #endif