From 221086fe955966aeac85d86cfcb26fcdd9d11c55 Mon Sep 17 00:00:00 2001 From: in0finite Date: Wed, 26 Jun 2019 03:08:44 +0200 Subject: [PATCH] working on displaying players on minimap --- Assets/Scripts/Behaviours/Player2Minimap.cs | 43 +++++++++++++++++++ .../Scripts/Behaviours/Player2Minimap.cs.meta | 11 +++++ Assets/Scripts/UI/MapWindow.cs | 11 +++++ Docs/Multiplayer.md | 2 - 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Assets/Scripts/Behaviours/Player2Minimap.cs create mode 100644 Assets/Scripts/Behaviours/Player2Minimap.cs.meta diff --git a/Assets/Scripts/Behaviours/Player2Minimap.cs b/Assets/Scripts/Behaviours/Player2Minimap.cs new file mode 100644 index 00000000..e197d0f4 --- /dev/null +++ b/Assets/Scripts/Behaviours/Player2Minimap.cs @@ -0,0 +1,43 @@ +using UnityEngine; +using SanAndreasUnity.UI; +using SanAndreasUnity.Utilities; + +namespace SanAndreasUnity.Behaviours +{ + + public class Player2Minimap : MonoBehaviour + { + Net.Player m_player; + + + void Awake() + { + m_player = this.GetComponentOrThrow(); + } + + void OnEnable() + { + UI.MapWindow.Instance.onDrawMapItems += OnMinimapGUI; + } + + void OnDisable() + { + UI.MapWindow.Instance.onDrawMapItems -= OnMinimapGUI; + } + + void OnMinimapGUI() + { + if (m_player == Net.Player.Local) // don't draw anything for local player - it's done by map window + return; + + var ped = m_player.OwnedPed; + if (null == ped) + return; + + MapWindow.Instance.DrawItemOnMapRotated( MiniMap.Instance.PlayerBlip, ped.transform.position, ped.transform.forward, + (int) MapWindow.Instance.PlayerPointerSize ); + + } + + } +} diff --git a/Assets/Scripts/Behaviours/Player2Minimap.cs.meta b/Assets/Scripts/Behaviours/Player2Minimap.cs.meta new file mode 100644 index 00000000..db342966 --- /dev/null +++ b/Assets/Scripts/Behaviours/Player2Minimap.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de46f572586cdb697b6c95283affa511 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/MapWindow.cs b/Assets/Scripts/UI/MapWindow.cs index 43cabb98..f6e59cca 100644 --- a/Assets/Scripts/UI/MapWindow.cs +++ b/Assets/Scripts/UI/MapWindow.cs @@ -7,6 +7,8 @@ namespace SanAndreasUnity.UI { public class MapWindow : PauseMenuWindow { + public static MapWindow Instance { get; private set; } + //private Rect visibleMapRect = new Rect (); private Vector2 m_focusPos = Vector2.one * MiniMap.mapSize / 2.0f; private float zoomLevel = 1; @@ -16,6 +18,7 @@ namespace SanAndreasUnity.UI { private Texture2D m_infoAreaTexture; private float m_playerPointerSize = 10; + public float PlayerPointerSize { get => m_playerPointerSize; set { m_playerPointerSize = value; } } private bool m_drawZones = false; private bool m_isWaypointPlaced = false; @@ -25,6 +28,8 @@ namespace SanAndreasUnity.UI { private Vector2 m_infoAreaScrollViewPos = Vector2.zero; + public event System.Action onDrawMapItems = delegate {}; + MapWindow() { @@ -42,6 +47,9 @@ namespace SanAndreasUnity.UI { void Awake () { + if (null == Instance) + Instance = this; + m_infoAreaTexture = F.CreateTexture (1, 1, Color.grey); } @@ -572,6 +580,9 @@ namespace SanAndreasUnity.UI { } + // draw registered items + onDrawMapItems(); + // draw player pointer this.DrawItemOnMapRotated( MiniMap.Instance.PlayerBlip, Ped.Instance.transform.position, Ped.Instance.transform.forward, (int) m_playerPointerSize ); // this.DrawItemOnMapRotated( MiniMap.Instance.PlayerBlip, Player.Instance.transform.position, Player.Instance.transform.forward, 10 ); diff --git a/Docs/Multiplayer.md b/Docs/Multiplayer.md index eab222f8..2ffc7389 100644 --- a/Docs/Multiplayer.md +++ b/Docs/Multiplayer.md @@ -14,8 +14,6 @@ - Cell focus is not always assigned on client - it happens when a syncvar for current ped in Player script arrives after Ped.Start() -- add option to pause spawning, and to set spawn interval - - display players on minimap - port the whole UI to multiplayer