コード例 #1
0
        protected void OnCoarseLocationUpdateMessage(CoarseLocationUpdateMessage message)
        {
            Transform youTransform  = null;
            Transform preyTransform = null;

            foreach (CoarseLocation location in message.Locations)
            {
                MiniMapMarker marker;
                if (MarkerByAgentId.ContainsKey(location.AgentId))
                {
                    marker = MarkerByAgentId[location.AgentId];
                }
                else
                {
                    marker = MapMarkers.InstantiateTemplate();
                    MarkerByAgentId[location.AgentId] = marker;
                }

                marker.Transform.anchoredPosition = ScalePosition(location.Position);

                Color c = Color.green;
                if (location.IsYou)
                {
                    c            = Color.white;
                    youTransform = marker.Transform;
                }
                if (location.IsPrey)
                {
                    c             = Color.red;
                    preyTransform = marker.Transform;
                }
                marker.Image.color = c;

                marker.ToolTipTarget.Text = location.AgentId.ToString();

                AvatarNameCache.Instance.Get(location.AgentId, OnNameReceived);
            }

            // Force visibility of prey and you:
            if (preyTransform != null)
            {
                preyTransform.SetAsLastSibling();
            }

            if (youTransform != null)
            {
                youTransform.SetAsLastSibling();
            }

            // Remove markers that have left:
            for (int i = MarkerByAgentId.Count - 1; i >= 0; i--)
            {
                Guid          key    = MarkerByAgentId.Keys.ElementAt(i);
                MiniMapMarker marker = MarkerByAgentId[key];
                if (message.Locations.FirstOrDefault(x => x.AgentId == key) == null)
                {
                    MapMarkers.ReturnItemToPool(marker);
                    MarkerByAgentId.Remove(key);
                }
            }
        }
コード例 #2
0
ファイル: MiniMap.cs プロジェクト: Siccity/UnitySL
    protected void OnCoarseLocationUpdateMessage(CoarseLocationUpdateMessage message)
    {
        Transform youTransform  = null;
        Transform preyTransform = null;

        foreach (CoarseLocation location in message.Locations)
        {
            MarkerInfo mi;
            if (MarkerInfoByAgentId.ContainsKey(location.AgentId))
            {
                mi = MarkerInfoByAgentId[location.AgentId];
            }
            else
            {
                mi            = new MarkerInfo();
                mi.GameObject = Instantiate(MarkerPrefab, MarkerContainer);
                mi.Transform  = mi.GameObject.GetComponent <RectTransform>();
                mi.Image      = mi.GameObject.GetComponent <Image>();
                mi.Text       = mi.GameObject.GetComponentInChildren <TMP_Text>(true);

                MarkerInfoByAgentId[location.AgentId] = mi;
            }

            mi.Transform.anchoredPosition = ScalePosition(location.Position);

            Color c = Color.green;
            if (location.IsYou)
            {
                c            = Color.white;
                youTransform = mi.Transform;
            }
            if (location.IsPrey)
            {
                c             = Color.red;
                preyTransform = mi.Transform;
            }
            mi.Image.color = c;

            mi.Text.text = location.AgentId.ToString();

            AvatarNameCache.Instance.Get(location.AgentId, OnNameReceived);
        }

        // Force visibility of prey and you:
        if (preyTransform != null)
        {
            preyTransform.SetAsLastSibling();
        }

        if (youTransform != null)
        {
            youTransform.SetAsLastSibling();
        }

        // Remove markers that have left:
        for (int i = MarkerInfoByAgentId.Count - 1; i > 0; i--)
        {
            Guid       key = MarkerInfoByAgentId.Keys.ElementAt(i);
            MarkerInfo mi  = MarkerInfoByAgentId[key];
            if (message.Locations.FirstOrDefault(x => x.AgentId == key) == null)
            {
                Destroy(MarkerInfoByAgentId[key].GameObject);
                MarkerInfoByAgentId.Remove(key);
            }
        }
    }