// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #if USE_LARGE_WORLDS using Real = System.Double; #else using Real = System.Single; #endif using System; using FlaxEngine; namespace FlaxEditor.SceneGraph.Actors { /// /// Actor node for . /// /// [HideInEditor] public sealed class NavLinkNode : ActorNode { /// /// Sub actor node used to edit link start and end points. /// /// public sealed class LinkNode : ActorChildNode { private readonly bool _isStart; /// /// Initializes a new instance of the class. /// /// The parent node. /// The identifier. /// The start node or end node. public LinkNode(NavLinkNode actor, Guid id, bool isStart) : base(actor, id, isStart ? 0 : 1) { _isStart = isStart; } /// public override Transform Transform { get { var actor = (NavLink)_node.Actor; Transform localTrans = new Transform(_isStart ? actor.Start : actor.End); return actor.Transform.LocalToWorld(localTrans); } set { var actor = (NavLink)_node.Actor; Transform localTrans = actor.Transform.WorldToLocal(value); if (_isStart) actor.Start = localTrans.Translation; else actor.End = localTrans.Translation; } } /// public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) { normal = Vector3.Up; var sphere = new BoundingSphere(Transform.Translation, 10.0f); return sphere.Intersects(ref ray.Ray, out distance); } /// public override void OnDebugDraw(ViewportDebugDrawData data) { ParentNode.OnDebugDraw(data); } } /// public NavLinkNode(Actor actor) : base(actor) { var bytes = ID.ToByteArray(); bytes[0] += 1; AddChildNode(new LinkNode(this, new Guid(bytes), true)); bytes[0] += 1; AddChildNode(new LinkNode(this, new Guid(bytes), false)); } /// public override bool AffectsNavigation => true; /// public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) { normal = Vector3.Up; distance = Real.MaxValue; return false; } } }