// Constructor that only registers the static member.
 public MyHighlightSystem() { m_static = this; }
Example #2
0
 // Constructor that only registers the static member.
 public MyHighlightSystem()
 {
     m_static = this;
 }
 private static void OnExclusiveHighlightRejected(MyHighlightSystem.MyHighlightData data, int exclusiveKey)
 {
     m_playerIdsToHighlightData[data.PlayerId].RemoveAll(tuple => tuple.Item1 == data.EntityId);
     // unsubscribe the second event
     MySession.Static.GetComponent<MyHighlightSystem>().ExclusiveHighlightAccepted -= OnExclusiveHighlightAccepted;
 }
        private static void OnExclusiveHighlightAccepted(MyHighlightSystem.MyHighlightData data, int exclusiveKey)
        {
            // Already disposed data
            if (data.Thickness == -1f)
                return;

            var playersList = m_playerIdsToHighlightData[data.PlayerId];
            var indexOf = playersList.FindIndex(tuple => tuple.Item1 == data.EntityId);
            var originalData = playersList[indexOf];
            m_playerIdsToHighlightData[data.PlayerId][indexOf] = new MyTuple<long, int>(originalData.Item1, exclusiveKey);
            // unsubscribe the second event
            MySession.Static.GetComponent<MyHighlightSystem>().ExclusiveHighlightRejected -= OnExclusiveHighlightRejected;
        }
        // Common logic used for highlighting objects from logic provider
        private static void SetHighlight(MyHighlightSystem.MyHighlightData highlightData, long playerId)
        {
            var highlightComp = MySession.Static.GetComponent<MyHighlightSystem>();
            // Determine if we are getting rid of the highlight or updating/adding it
            var enabled = highlightData.Thickness > -1;
            // Try to find exclusive key in the local dictionary
            var exclusiveKey = -1;
            if (m_playerIdsToHighlightData.ContainsKey(playerId))
            {
                exclusiveKey = m_playerIdsToHighlightData[playerId].Find(tuple => tuple.Item1 == highlightData.EntityId).Item2;
                // Tuples default int value is 0 and keys are in range of 10+
                if (exclusiveKey == 0)
                    exclusiveKey = -1;
            }

            // Add requst data with empty exclusive key for non existent records
            if (exclusiveKey == -1)
            {
                // We have nothing to disable highlight for
                if (!enabled)
                    return;
                // Listen to accepted and rejected events - They are being unregistered afterwards
                highlightComp.ExclusiveHighlightAccepted += OnExclusiveHighlightAccepted;
                highlightComp.ExclusiveHighlightRejected += OnExclusiveHighlightRejected;

                if (!m_playerIdsToHighlightData.ContainsKey(playerId))
                    m_playerIdsToHighlightData.Add(playerId, new List<MyTuple<long, int>>());

                m_playerIdsToHighlightData[playerId].Add(new MyTuple<long, int>(highlightData.EntityId, -1));
            }
            else if (!enabled)
            {
                // Removing the highlight
                // Remove the data from per player repository
                m_playerIdsToHighlightData[playerId].RemoveAll(tuple => tuple.Item2 == exclusiveKey);
            }

            // Do the request
            highlightComp.RequestHighlightChangeExclusive(highlightData, exclusiveKey);
        }