Cant
How do I use Cant
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PunSceneSettings.cs
Copy
70 public static int MinViewIdForScene(string scene)
71 {
72 if (string.IsNullOrEmpty(scene))
73 {
74 return 0;
75 }
76
77 PunSceneSettings pss = Instance;
78 if (pss == null)
79 {
80 Debug.LogError("pss cant be null");
81 return 0;
82 }
83
84 foreach (SceneSetting setting in pss.MinViewIdPerScene)
85 {
86 if (setting.sceneName.Equals(scene))
87 {
88 return setting.minViewId;
89 }
90 }
91 return 0;
92 }
File name: NetworkingPeer.cs
Copy
1918 private void SendVacantViewIds()
1919 {
1920 Debug.Log("SendVacantViewIds()");
1921 List
1922 foreach (PhotonView view in this.photonViewList.Values)
1923 {
1924 if (!view.isOwnerActive)
1925 {
1926 vacantViews.Add(view.viewID);
1927 }
1928 }
1929
1930 Debug.Log("Sending vacant view IDs. Length: " + vacantViews.Count);
1931 //this.OpRaiseEvent(PunEvent.VacantViewIds, true, vacantViews.ToArray());
1932 this.OpRaiseEvent(PunEvent.VacantViewIds, vacantViews.ToArray(), true, null);
1933 }
File name: PickupItemSyncer.cs
Copy
37 public void AskForPickupItemSpawnTimes()
38 {
39 if (this.IsWaitingForPickupInit)
40 {
41 if (PhotonNetwork.playerList.Length < 2)
42 {
43 Debug.Log("Cant ask anyone else for PickupItem spawn times.");
44 this.IsWaitingForPickupInit = false;
45 return;
46 }
47
48
49 // find a another player (than the master, who likely is gone) to ask for the PickupItem spawn times
50 PhotonPlayer nextPlayer = PhotonNetwork.masterClient.GetNext();
51 if (nextPlayer == null || nextPlayer.Equals(PhotonNetwork.player))
52 {
53 nextPlayer = PhotonNetwork.player.GetNext();
54 //Debug.Log("This player is the Master's next. Asking this client's 'next' player: " + ((nextPlayer != null) ? nextPlayer.ToStringFull() : ""));
55 }
56
57 if (nextPlayer != null && !nextPlayer.Equals(PhotonNetwork.player))
58 {
59 this.photonView.RPC("RequestForPickupTimes", nextPlayer);
60
61 // you could restart this invoke and try to find another player after 4 seconds. but after a while it doesnt make a difference anymore
62 //this.Invoke("AskForPickupItemSpawnTimes", 2.0f);
63 }
64 else
65 {
66 Debug.Log("No player left to ask");
67 this.IsWaitingForPickupInit = false;
68 }
69 }
70 }
File name: PickupItemSyncer.cs
Copy
87 private void SendPickedUpItems(PhotonPlayer targtePlayer)
88 {
89 if (targtePlayer == null)
90 {
91 Debug.LogWarning("Cant send PickupItem spawn times to unknown targetPlayer.");
92 return;
93 }
94
95 double now = PhotonNetwork.time;
96 double soon = now + TimeDeltaToIgnore;
97
98
99 PickupItem[] items = new PickupItem[PickupItem.DisabledPickupItems.Count];
100 PickupItem.DisabledPickupItems.CopyTo(items);
101
102 List
103 for (int i = 0; i < items.Length; i++)
104 {
105 PickupItem pi = items[i];
106 if (pi.SecondsBeforeRespawn <= 0)
107 {
108 valuesToSend.Add(pi.ViewID);
109 valuesToSend.Add((float)0.0f);
110 }
111 else
112 {
113 double timeUntilRespawn = pi.TimeOfRespawn - PhotonNetwork.time;
114 if (pi.TimeOfRespawn > soon)
115 {
116 // the respawn of this item is not "immediately", so we include it in the message "these items are not active" for the new player
117 Debug.Log(pi.ViewID + " respawn: " + pi.TimeOfRespawn + " timeUntilRespawn: " + timeUntilRespawn + " (now: " + PhotonNetwork.time + ")");
118 valuesToSend.Add(pi.ViewID);
119 valuesToSend.Add((float)timeUntilRespawn);
120 }
121 }
122 }
123
124 Debug.Log("Sent count: " + valuesToSend.Count + " now: " + now);
125 this.photonView.RPC("PickupItemInit", targtePlayer, PhotonNetwork.time, valuesToSend.ToArray());
126 }
File name: Enemy.cs
Copy
83 protected override void OnCantMove 84 {
85 //Declare hitPlayer and set it to equal the encountered component.
86 Player hitPlayer = component as Player;
87
88 //Call the LoseFood function of hitPlayer passing it playerDamage, the amount of foodpoints to be subtracted.
89 hitPlayer.LoseFood (playerDamage);
90
91 //Set the attack trigger of animator to trigger Enemy attack animation.
92 animator.SetTrigger ("enemyAttack");
93
94 //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between.
95 SoundManager.instance.RandomizeSfx (attackSound1, attackSound2);
96 }
File name: MovingObject.cs
Copy
93 protected virtual void AttemptMove 95 {
96 //Hit will store whatever our linecast hits when Move is called.
97 RaycastHit2D hit;
98
99 //Set canMove to true if Move was successful, false if failed.
100 bool canMove = Move (xDir, yDir, out hit);
101
102 //Check if nothing was hit by linecast
103 if(hit.transform == null)
104 //If nothing was hit, return and don't execute further code.
105 return;
106
107 //Get a component reference to the component of type T attached to the object that was hit
108 T hitComponent = hit.transform.GetComponent
109
110 //If canMove is false and hitComponent is not equal to null, meaning MovingObject is blocked and has hit something it can interact with.
111 if(!canMove && hitComponent != null)
112
113 //Call the OnCantMove function and pass it hitComponent as a parameter.
114 OnCantMove (hitComponent);
115 }
File name: Player.cs
Copy
162 protected override void OnCantMove 163 {
164 //Set hitWall to equal the component passed in as a parameter.
165 Wall hitWall = component as Wall;
166
167 //Call the DamageWall function of the Wall we are hitting.
168 hitWall.DamageWall (wallDamage);
169
170 //Set the attack trigger of the player's animation controller in order to play the player's attack animation.
171 animator.SetTrigger ("playerChop");
172 }
Cant 110 lượt xem
Gõ tìm kiếm nhanh...