Drop









How do I use Drop
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ChatGui.cs Copy
58     public void Start()
59     {
60         DontDestroyOnLoad(this.gameObject);
61         Application.runInBackground = true; // this must run in background or it will drop connection if not focussed.
62
63         if (string.IsNullOrEmpty(this.UserName))
64         {
65             this.UserName = "user" + Environment.TickCount%99; //made-up username
66         }
67
68         chatClient = new ChatClient(this);
69         chatClient.Connect(ChatAppId, "1.0", this.UserName, null);
70
71         if (this.AlignBottom)
72         {
73             this.GuiRect.y = Screen.height - this.GuiRect.height;
74         }
75         if (this.FullScreen)
76         {
77             this.GuiRect.x = 0;
78             this.GuiRect.y = 0;
79             this.GuiRect.width = Screen.width;
80             this.GuiRect.height = Screen.height;
81         }
82
83         Debug.Log(this.UserName);
84     }
File name: PickupDemoGui.cs Copy
15     public void OnGUI()
16     {
17         if (!PhotonNetwork.inRoom)
18         {
19             return;
20         }
21
22
23         if (this.ShowScores)
24         {
25             GUILayout.Label("Your Score: " + PhotonNetwork.player.GetScore());
26         }
27
28
29         if (this.ShowDropButton)
30         {
31             foreach (PickupItem item in PickupItem.DisabledPickupItems)
32             {
33                 if (item.PickupIsMine && item.SecondsBeforeRespawn <= 0)
34                 {
35                     if (GUILayout.Button("Drop " + item.name))
36                     {
37                         item.Drop(); // drops the item at the place where it originates
38                     }
39
40                     GameObject playerCharGo = PhotonNetwork.player.TagObject as GameObject;
41                     if (playerCharGo != null && GUILayout.Button("Drop here " + item.name))
42                     {
43                         // drop the item at some other place. next to the user's character would be fine...
44                         Vector3 random = Random.insideUnitSphere;
45                         random.y = 0;
46                         random = random.normalized;
47                         Vector3 itempos = playerCharGo.transform.position + this.DropOffset * random;
48
49                         item.Drop(itempos);
50                     }
51                 }
52             }
53         }
54
55
56         if (this.ShowTeams)
57         {
58             foreach (var teamName in PunTeams.PlayersPerTeam.Keys)
59             {
60                 GUILayout.Label("Team: " + teamName.ToString());
61                 List teamPlayers = PunTeams.PlayersPerTeam[teamName];
62                 foreach (PhotonPlayer player in teamPlayers)
63                 {
64                     GUILayout.Label(" " + player.ToStringFull() + " Score: " + player.GetScore());
65                 }
66             }
67
68             if (GUILayout.Button("to red"))
69             {
70                 PhotonNetwork.player.SetTeam(PunTeams.Team.red);
71             }
72             if (GUILayout.Button("to blue"))
73             {
74                 PhotonNetwork.player.SetTeam(PunTeams.Team.blue);
75             }
76         }
77     }
File name: PhotonNetwork.cs Copy
2479     internal static void RPC(PhotonView view, string methodName, PhotonTargets target, bool encrypt, params object[] parameters)
2480     {
2481         if (!VerifyCanUseNetwork())
2482         {
2483             return;
2484         }
2485
2486         if (room == null)
2487         {
2488             Debug.LogWarning("Cannot send RPCs in Lobby! RPC dropped.");
2489             return;
2490         }
2491
2492         if (networkingPeer != null)
2493         {
2494             networkingPeer.RPC(view, methodName, target, encrypt, parameters);
2495         }
2496         else
2497         {
2498             Debug.LogWarning("Could not execute RPC " + methodName + ". Possible scene loading in progress?");
2499         }
2500     }
File name: PickupItem.cs Copy
105     public void Drop()
106     {
107         if (this.PickupIsMine)
108         {
109             this.photonView.RPC("PunRespawn", PhotonTargets.AllViaServer);
110         }
111     }
File name: PickupItem.cs Copy
114     public void Drop(Vector3 newPosition)
115     {
116         if (this.PickupIsMine)
117         {
118             this.photonView.RPC("PunRespawn", PhotonTargets.AllViaServer, newPosition);
119         }
120     }
File name: PickupItem.cs Copy
124     public void PunPickup(PhotonMessageInfo msgInfo)
125     {
126         // when this client's RPC gets executed, this client no longer waits for a sent pickup and can try again
127         if (msgInfo.sender.isLocal) this.SentPickup = false;
128
129
130         // In this solution, picked up items are disabled. They can't be picked up again this way, etc.
131         // You could check "active" first, if you're not interested in failed pickup-attempts.
132         if (!this.gameObject.GetActive())
133         {
134             // optional logging:
135             Debug.Log("Ignored PU RPC, cause item is inactive. " + this.gameObject + " SecondsBeforeRespawn: " + SecondsBeforeRespawn + " TimeOfRespawn: " + this.TimeOfRespawn + " respawn in future: " + (TimeOfRespawn > PhotonNetwork.time));
136             return; // makes this RPC being ignored
137         }
138
139
140         // if the RPC isn't ignored by now, this is a successful pickup. this might be "my" pickup and we should do a callback
141         this.PickupIsMine = msgInfo.sender.isLocal;
142
143         // call the method OnPickedUp(PickupItem item) if a GameObject was defined as callback target
144         if (this.OnPickedUpCall != null)
145         {
146             // you could also skip callbacks for items that are not picked up by this client by using: if (this.PickupIsMine)
147             this.OnPickedUpCall.SendMessage("OnPickedUp", this);
148         }
149
150
151         // setup a respawn (or none, if the item has to be dropped)
152         if (SecondsBeforeRespawn <= 0)
153         {
154             this.PickedUp(0.0f); // item doesn't auto-respawn. must be dropped
155         }
156         else
157         {
158             // how long it is until this item respanws, depends on the pickup time and the respawn time
159             double timeSinceRpcCall = (PhotonNetwork.time - msgInfo.timestamp);
160             double timeUntilRespawn = SecondsBeforeRespawn - timeSinceRpcCall;
161
162             //Debug.Log("msg timestamp: " + msgInfo.timestamp + " time until respawn: " + timeUntilRespawn);
163
164             if (timeUntilRespawn > 0)
165             {
166                 this.PickedUp((float)timeUntilRespawn);
167             }
168         }
169     }
File name: Piece.cs Copy
210  public void Drop() {
211   dropping = true;
212   SetEmissionOriginal();
213   StopMoveCoroutine();
214   gameObject.GetComponent().useGravity = true;
215   //GCPlayer currPlayer = GameManager.Instance.CurrentPlayer;
216   UnHighlightPossibleEats();
217   UnHighlightPossibleMoves();
218   ready = false;
219  }
File name: Piece.cs Copy
222   void OnCollisionEnter(Collision collision) {
223         if (dropping && collision.collider.gameObject) {
224    ready = true;
225    dropping = false;
226   }
227     }
File name: GCPlayer.cs Copy
76  public void OnInputEvent(InputActionType action) {
77   switch (action) {
78    case InputActionType.GRAB_PIECE:
79     Node gNode = Finder.RayHitFromScreen(Input.mousePosition);
80     if (gNode == null) break;
81     piece = gNode.Piece;
82     if (piece == null) break;
83     if (!piece.IsReady) break;
84     if (Click(gNode) && piece && Has(piece) && Click(piece)) {
85      piece.Pickup();
86      piece.Compute();
87      piece.HighlightPossibleMoves();
88      piece.HighlightPossibleEats();
89      GameManager.Instance.GameState.Grab();
90     }
91
92     //check clickable for tile and piece then pass Player
93     //check if player has piece - PIECE
94     //check if player has piece if not empty - NODE
95     break;
96    case InputActionType.CANCEL_PIECE:
97      if (piece != null) {
98       //if (!piece.IsReady) break;
99       piece.Drop();
100       piece = null;
101       GameManager.Instance.GameState.Cancel();
102      }
103     break;
104    case InputActionType.PLACE_PIECE:
105     Node tNode = Finder.RayHitFromScreen(Input.mousePosition);
106     if (tNode == null) break;
107     Piece tPiece = tNode.Piece;
108     if (tPiece == null) {
109      if (piece.IsPossibleMove(tNode)) {
110       if (Rules.IsCheckMove(this,piece,tNode, true)) {
111        Debug.Log("Move checked"); // do nothing
112       } else {
113        piece.MoveToXZ(tNode, Drop);
114        GameManager.Instance.GameState.Place();
115       }
116      }
117     } else {
118      if (piece.IsPossibleEat(tNode)) {
119       if (Rules.IsCheckEat(this,piece,tNode, true)) {
120        Debug.Log("Eat checked"); // do nothing
121       } else {
122        GCPlayer oppPlayer = GameManager.Instance.Opponent(this);
123        oppPlayer.RemovePiece(tPiece);
124        AddEatenPieces(tPiece);
125        tPiece.ScaleOut(0.2f, 1.5f);
126        piece.MoveToXZ(tNode, Drop);
127        GameManager.Instance.GameState.Place();
128       }
129      }
130     }
131     break;
132   }
133  }
File name: GCPlayer.cs Copy
149  private void Drop() {
150   piece.Drop();
151   piece.Compute();
152   GameManager.Instance.GameState.Release();
153   piece = null;
154  }

Download file with original file name:Drop

Drop 93 lượt xem

Gõ tìm kiếm nhanh...