From 25d1e30efae117e1d697d56ed97b685de58916f3 Mon Sep 17 00:00:00 2001 From: in0finite Date: Tue, 22 Oct 2019 00:21:04 +0200 Subject: [PATCH] add ability to pass parameters to FindGround() --- Assets/Scripts/Behaviours/Ped/Ped.cs | 27 ++++++++++++++++++------- Assets/Scripts/Behaviours/World/Cell.cs | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Behaviours/Ped/Ped.cs b/Assets/Scripts/Behaviours/Ped/Ped.cs index c2597adb..030b8d08 100644 --- a/Assets/Scripts/Behaviours/Ped/Ped.cs +++ b/Assets/Scripts/Behaviours/Ped/Ped.cs @@ -97,6 +97,14 @@ namespace SanAndreasUnity.Behaviours private Coroutine m_findGroundCoroutine; + public struct FindGroundParams + { + public bool tryFromAbove; + + public static FindGroundParams Default => new FindGroundParams(){tryFromAbove = true}; + public static FindGroundParams DefaultBasedOnLoadedWorld => new FindGroundParams(){tryFromAbove = (null == Cell.Instance || Cell.Instance.HasExterior)}; + } + /// Ped who is controlled by local player. public static Ped Instance { get { return Net.Player.Local != null ? Net.Player.Local.OwnedPed : null; } } @@ -232,12 +240,12 @@ namespace SanAndreasUnity.Behaviours return; if (!IsGrounded) { - FindGround (); + FindGround (FindGroundParams.DefaultBasedOnLoadedWorld); } } - public void Teleport(Vector3 position, Quaternion rotation) { + public void Teleport(Vector3 position, Quaternion rotation, FindGroundParams parameters) { if (!NetStatus.IsServer) return; @@ -248,27 +256,32 @@ namespace SanAndreasUnity.Behaviours this.transform.position = position; this.transform.rotation = rotation; - this.FindGround (); + this.FindGround (parameters); } + public void Teleport(Vector3 position, Quaternion rotation) + { + this.Teleport(position, rotation, FindGroundParams.DefaultBasedOnLoadedWorld); + } + public void Teleport(Vector3 position) { this.Teleport (position, this.transform.rotation); } - public void FindGround () + public void FindGround (FindGroundParams parameters) { if (m_findGroundCoroutine != null) { StopCoroutine (m_findGroundCoroutine); m_findGroundCoroutine = null; } - m_findGroundCoroutine = StartCoroutine (FindGroundCoroutine ()); + m_findGroundCoroutine = StartCoroutine (FindGroundCoroutine (parameters)); } - private IEnumerator FindGroundCoroutine() + private IEnumerator FindGroundCoroutine(FindGroundParams parameters) { yield return null; @@ -444,7 +457,7 @@ namespace SanAndreasUnity.Behaviours Vector3 t = this.transform.position; t.y = 150; this.transform.position = t; - this.FindGround(); + this.FindGround(FindGroundParams.Default); } diff --git a/Assets/Scripts/Behaviours/World/Cell.cs b/Assets/Scripts/Behaviours/World/Cell.cs index 440ae51c..9b34f358 100644 --- a/Assets/Scripts/Behaviours/World/Cell.cs +++ b/Assets/Scripts/Behaviours/World/Cell.cs @@ -23,6 +23,8 @@ namespace SanAndreasUnity.Behaviours.World public List CellIds = new List { 0, 13 }; + public bool HasExterior => this.CellIds.Contains(0); + public Camera PreviewCamera; public List focusPoints = new List ();