Exemplo n.º 1
0
 void Update()
 {
     if (observable != null && observable.owner == null)
     {
         if (EdgeManager.gameStarted)
         {
             observable.SetOwnership(EdgeManager.GetPlayer(0).playerId);//owner is first player in the room
         }
     }
 }
Exemplo n.º 2
0
        public void SetOwnership(string ownerId)
        {
            owner = EdgeManager.GetPlayer(ownerId);
            if (owner == null)
            {
                throw new Exception("EdgeMultiplay: Couldn't find player with id: " + ownerId);
            }

            if (owner.observer == null)
            {
                owner.gameObject.AddComponent <EdgeMultiplayObserver>();
            }
            owner.observer.observables.Add(this);
            owner.observer.UpdateObservables();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Changes the owner of an Observable object
 /// <para>ChangeOwnership() will change the owner in the local player's world and </para>
 /// <para>update all room members about Ownership change.</para>
 /// </summary>
 /// <param name="newOwnerId">The new owner player id</param>
 public void ChangeOwnership(string newOwnerId)
 {
     if (owner != null)
     {
         if (newOwnerId == owner.playerId)
         {
             Debug.LogWarning("EdgeMultiplay: No ownership change needed you already own the observable object");
             return;
         }
         if (owner.observer != null)
         {
             owner.observer.observables.Remove(this);
         }
         owner = EdgeManager.GetPlayer(newOwnerId);
         if (owner == null)
         {
             throw new Exception("EdgeMultiplay: Couldn't find player with id: " + newOwnerId);
         }
         if (owner.observer == null)
         {
             owner.gameObject.AddComponent <EdgeMultiplayObserver>();
         }
         owner.observer.observables.Add(this);
         owner.observer.UpdateObservables();
         GamePlayEvent changeOwnershipEvent = new GamePlayEvent()
         {
             eventName  = "ObservableOwnershipChange",
             stringData = new string[1] {
                 newOwnerId
             },
             integerData = new int[1] {
                 observableIndex
             }
         };
         EdgeManager.MessageSender.BroadcastMessage(changeOwnershipEvent);
     }
     else
     {
         Debug.LogError("EdgeMultiplay: Observer has no owner, Use observer.SetOwnership() first");
         return;
     }
 }