<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Multiplayer on the map - it's easy (Online Maps + Photon PUN2)]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=936</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=936&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Multiplayer on the map - it's easy (Online Maps + Photon PUN2).]]></description>
		<lastBuildDate>Sun, 09 Jun 2019 18:40:04 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Multiplayer on the map - it's easy (Online Maps + Photon PUN2)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5128#p5128</link>
			<description><![CDATA[<p>Make a marker a field, instead of a local variable, and invoke the logic from OnDrag on a timer.<br /><a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.InvokeRepeating.html">https://docs.unity3d.com/ScriptReferenc … ating.html</a><br /><a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html">https://docs.unity3d.com/ScriptReferenc … utine.html</a></p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sun, 09 Jun 2019 18:40:04 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5128#p5128</guid>
		</item>
		<item>
			<title><![CDATA[Re: Multiplayer on the map - it's easy (Online Maps + Photon PUN2)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5125#p5125</link>
			<description><![CDATA[<p>How Can i update marker position without marker.OnDrag?<br />i want to be updated every second automatically</p>]]></description>
			<author><![CDATA[null@example.com (www.alid.ir)]]></author>
			<pubDate>Sun, 09 Jun 2019 15:45:55 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5125#p5125</guid>
		</item>
		<item>
			<title><![CDATA[Re: Multiplayer on the map - it's easy (Online Maps + Photon PUN2)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5070#p5070</link>
			<description><![CDATA[<p>Use OnlineMapsLocationService.position to get a player’s location.<br /><a href="http://infinity-code.com/doxygen/online-maps/classOnlineMapsLocationServiceBase.html#a1ced3b12069bbb55866823444f547053">http://infinity-code.com/doxygen/online … 444f547053</a></p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 31 May 2019 11:35:57 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5070#p5070</guid>
		</item>
		<item>
			<title><![CDATA[Re: Multiplayer on the map - it's easy (Online Maps + Photon PUN2)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5067#p5067</link>
			<description><![CDATA[<p>How Can i change players location By GPS</p>]]></description>
			<author><![CDATA[null@example.com (Adminsh)]]></author>
			<pubDate>Fri, 31 May 2019 06:13:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5067#p5067</guid>
		</item>
		<item>
			<title><![CDATA[Multiplayer on the map - it's easy (Online Maps + Photon PUN2)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4174#p4174</link>
			<description><![CDATA[<p><div class="fancy_video_tag_player"><iframe class="youtube-player" type="text/html" width="640" height="385" src="https://www.youtube.com/embed/Yl5K_Wr6Umk" frameborder="0"></iframe></div></p><p><strong>Script:</strong><br /></p><div class="codebox"><pre><code>/*     INFINITY CODE 2013-2018      */
/*   http://www.infinity-code.com   */

using System.Collections.Generic;
using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using Random = UnityEngine.Random;

namespace InfinityCode.OnlineMapsExamples
{
    /// &lt;summary&gt;
    /// Example of how to display the location of several users on the map at the same time usign Photon PUN2.
    /// Drag the player marker to move it synchronously for all clients.
    /// &lt;/summary&gt;
    public class SyncDraggingUsingPhoton : MonoBehaviourPunCallbacks
    {
        /// &lt;summary&gt;
        /// Dictionary of other players
        /// &lt;/summary&gt;
        public Dictionary&lt;string, OnlineMapsMarker3D&gt; otherPlayers;

        /// &lt;summary&gt;
        /// Array of marker prefabs
        /// &lt;/summary&gt;
        public GameObject[] prefabs;

        /// &lt;summary&gt;
        /// Reference to the map
        /// &lt;/summary&gt;
        private OnlineMaps map;

        /// &lt;summary&gt;
        /// Reference to the control
        /// &lt;/summary&gt;
        private OnlineMapsTileSetControl control;

        /// &lt;summary&gt;
        /// Creates a marker for another player, and sets the position
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;player&quot;&gt;&lt;/param&gt;
        private void CreateOtherPlayer(Player player)
        {
            // Get player properties
            Hashtable props = player.CustomProperties;
            double longitude = (double)props[&quot;longitude&quot;];
            double latitude = (double)props[&quot;latitude&quot;];
            int prefabIndex = (int)props[&quot;prefab_index&quot;];
            string id = player.UserId;

            // Create a new marker
            OnlineMapsMarker3D marker = OnlineMapsMarker3DManager.CreateItem(longitude, latitude, prefabs[prefabIndex]);
            marker.label = player.NickName;
            otherPlayers.Add(id, marker);
        }

        /// &lt;summary&gt;
        /// Called when the client is connected to the Master Server and ready for matchmaking and other tasks
        /// &lt;/summary&gt;
        public override void OnConnectedToMaster()
        {
            // Create a new room or connect to an existing one
            RoomOptions roomOptions = new RoomOptions();
            roomOptions.IsVisible = false;
            roomOptions.MaxPlayers = 4;
            roomOptions.PublishUserId = true;
            PhotonNetwork.JoinOrCreateRoom(&quot;Test Room&quot;, roomOptions, TypedLobby.Default);

            double tlx, tly, brx, bry;
            map.GetCorners(out tlx, out tly, out brx, out bry);

            // Create current player marker
            int prefabIndex = Random.Range(0, prefabs.Length);
            double longitude = Random.Range((float)tlx, (float)brx);
            double latitude = Random.Range((float)bry, (float)tly);
            OnlineMapsMarker3D marker = OnlineMapsMarker3DManager.CreateItem(longitude, latitude, prefabs[prefabIndex]);
            marker.label = &quot;My Player&quot;;

            // Make a marker draggable, and subscribe to the drag event
            marker.SetDraggable();
            marker.OnDrag += OnDrag;

            // Center the map on the marker
            map.position = marker.position;

            // Create initial properties
            Hashtable hashtable = new Hashtable
            {
                {&quot;prefab_index&quot;, prefabIndex},
                {&quot;longitude&quot;, longitude},
                {&quot;latitude&quot;, latitude}
            };
            PhotonNetwork.SetPlayerCustomProperties(hashtable);
        }

        /// &lt;summary&gt;
        /// Called when dragging a player marker
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;marker&quot;&gt;Player marker&lt;/param&gt;
        private void OnDrag(OnlineMapsMarkerBase marker)
        {
            // Update location in player properties
            double longitude, latitude;
            marker.GetPosition(out longitude, out latitude);
            Hashtable hashtable = new Hashtable
            {
                {&quot;longitude&quot;, longitude},
                { &quot;latitude&quot;, latitude}
            };

            PhotonNetwork.SetPlayerCustomProperties(hashtable);
        }

        /// &lt;summary&gt;
        /// Called when the LoadBalancingClient entered a room, no matter if this client created it or simply joined
        /// &lt;/summary&gt;
        public override void OnJoinedRoom()
        {
            // Create markers for other players.
            foreach (KeyValuePair&lt;int, Player&gt; pair in PhotonNetwork.CurrentRoom.Players)
            {
                Player player = pair.Value;
                if (player.IsLocal) continue;
                CreateOtherPlayer(player);
            }
        }

        /// &lt;summary&gt;
        /// Called when a remote player entered the room. This Player is already added to the playerlist
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;otherPlayer&quot;&gt;The player who entered the room&lt;/param&gt;
        public override void OnPlayerEnteredRoom(Player otherPlayer)
        {
            CreateOtherPlayer(otherPlayer);
        }

        /// &lt;summary&gt;
        /// Called when a remote player left the room or became inactive
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;otherPlayer&quot;&gt;The player who left the room&lt;/param&gt;
        public override void OnPlayerLeftRoom(Player otherPlayer)
        {
            OnlineMapsMarker3D marker;
            if (otherPlayers.TryGetValue(otherPlayer.UserId, out marker))
            {
                otherPlayers.Remove(otherPlayer.UserId);
                OnlineMapsMarker3DManager.RemoveItem(marker);
            }
        }

        /// &lt;summary&gt;
        /// Called when custom player-properties are changed
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;targetPlayer&quot;&gt;Player that changed&lt;/param&gt;
        /// &lt;param name=&quot;changedProps&quot;&gt;Properties that changed&lt;/param&gt;
        public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
        {
            if (targetPlayer.IsLocal) return;

            // Update player marker location
            double longitude = (double)changedProps[&quot;longitude&quot;];
            double latitude = (double)changedProps[&quot;latitude&quot;];

            string id = targetPlayer.UserId;
            OnlineMapsMarker3D marker;

            if (otherPlayers.TryGetValue(id, out marker))
            {
                marker.SetPosition(longitude, latitude);
                map.Redraw();
            }
        }

        private void Start()
        {
            map = OnlineMaps.instance;
            control = OnlineMapsTileSetControl.instance;
            otherPlayers = new Dictionary&lt;string, OnlineMapsMarker3D&gt;();

            // Connect to Photon as configured in the PhotonServerSettings file
            PhotonNetwork.LocalPlayer.NickName = &quot;Player &quot; + Random.Range(0, 100000);
            PhotonNetwork.ConnectUsingSettings();
        }
    }
}</code></pre></div><p>Edit (2019.10.11):<br />Updated script for Online Maps v3.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 07 Nov 2018 06:40:58 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4174#p4174</guid>
		</item>
	</channel>
</rss>
