コード例 #1
0
 private void LateUpdate()
 {
     if (!RelevanceSystem.ENABLED)
     {
         return;
     }
     Dictionary <GameObject, Relevance> .Enumerator enumerator = this.m_Components.GetEnumerator();
     while (enumerator.MoveNext())
     {
         KeyValuePair <GameObject, Relevance> keyValuePair = enumerator.Current;
         Relevance value = keyValuePair.Value;
         if (value && value.enabled && value.LastUpdate <= Time.time - 0.5f)
         {
             value.LastUpdate = Time.time + UnityEngine.Random.Range(0f, 0.2f);
             Relevance.ERelevanceCalculationResult erelevanceCalculationResult;
             float num = value.CalculateRelevance(ReplTools.GetLocalPeer(), out erelevanceCalculationResult);
             if (num >= 0.2f && !value.gameObject.activeSelf)
             {
                 value.gameObject.SetActive(true);
                 value.OnRelevanceActivated(ReplTools.GetLocalPeer());
             }
             bool flag = false;
             if (value.ReplIsOwner())
             {
                 bool    flag2   = value.ReplCanChangeOwnership() && !value.ReplIsTransferringOwnership() && value.m_CreationTime < Time.time - 1f;
                 P2PPeer p2PPeer = null;
                 float   num2    = 0f;
                 for (int i = 0; i < ReplTools.GetRemotePeers().Count; i++)
                 {
                     P2PPeer p2PPeer2 = ReplTools.GetRemotePeers()[i];
                     float   num3     = value.CalculateRelevance(p2PPeer2, out erelevanceCalculationResult);
                     if (erelevanceCalculationResult == Relevance.ERelevanceCalculationResult.ToActivate)
                     {
                         value.OnRelevanceActivated(p2PPeer2);
                     }
                     else if (erelevanceCalculationResult == Relevance.ERelevanceCalculationResult.ToDeactivate)
                     {
                         value.OnRelevanceDeactivated(p2PPeer2);
                     }
                     if (flag2 && num3 > num2 && (num <= 0f || num3 > num + 0.1f))
                     {
                         num2    = num3;
                         p2PPeer = p2PPeer2;
                     }
                 }
                 if (p2PPeer != null)
                 {
                     value.ReplGiveOwnership(p2PPeer);
                 }
                 if (num <= 0f && value.CanBeRemovedByRelevance(true) && !value.ReplIsTransferringOwnership())
                 {
                     UnityEngine.Object.Destroy(value.gameObject);
                     flag = true;
                 }
             }
             if (!flag && num <= 0.1f && value.gameObject.activeSelf)
             {
                 value.gameObject.SetActive(false);
                 value.OnRelevanceDeactivated(ReplTools.GetLocalPeer());
             }
         }
     }
     enumerator.Dispose();
 }