Dot
How do I use Dot
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: RPGMovement.cs
Copy
51 void UpdateAnimation()
52 {
53 Vector3 movementVector = transform.position - m_LastPosition;
54
55 float speed = Vector3.Dot( movementVector.normalized, transform.forward );
56 float direction = Vector3.Dot( movementVector.normalized, transform.right );
57
58 if( Mathf.Abs( speed ) < 0.2f )
59 {
60 speed = 0f;
61 }
62
63 if( speed > 0.6f )
64 {
65 speed = 1f;
66 direction = 0f;
67 }
68
69 if( speed >= 0f )
70 {
71 if( Mathf.Abs( direction ) > 0.7f )
72 {
73 speed = 1f;
74 }
75 }
76
77 m_AnimatorSpeed = Mathf.MoveTowards( m_AnimatorSpeed, speed, Time.deltaTime * 5f );
78
79 m_Animator.SetFloat( "Speed", m_AnimatorSpeed );
80 m_Animator.SetFloat( "Direction", direction );
81
82 m_LastPosition = transform.position;
83 }
File name: PhotonConverter.cs
Copy
189 static void ConvertToPhotonAPI(string file)
190 {
191 string text = File.ReadAllText(file);
192
193 bool isJS = file.Contains(".js");
194
195 file = file.Replace("\\", "/"); // Get Class name for JS
196 string className = file.Substring(file.LastIndexOf("/")+1);
197 className = className.Substring(0, className.IndexOf("."));
198
199
200 //REGEXP STUFF
201 //Valid are: Space { } , /n /r
202 //string NOT_VAR = @"([^A-Za-z0-9_\[\]\.]+)";
203 string NOT_VAR_WITH_DOT = @"([^A-Za-z0-9_]+)";
204
205 //string VAR_NONARRAY = @"[^A-Za-z0-9_]";
206
207
208 //NetworkView
209 {
210 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkView" + NOT_VAR_WITH_DOT, "$1PhotonView$2");
211 text = PregReplace(text, NOT_VAR_WITH_DOT + "networkView" + NOT_VAR_WITH_DOT, "$1photonView$2");
212 text = PregReplace(text, NOT_VAR_WITH_DOT + "stateSynchronization" + NOT_VAR_WITH_DOT, "$1synchronization$2");
213 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkStateSynchronization" + NOT_VAR_WITH_DOT, "$1ViewSynchronization$2"); // map Unity enum to ours
214 //.RPC
215 text = PregReplace(text, NOT_VAR_WITH_DOT + "RPCMode.Server" + NOT_VAR_WITH_DOT, "$1PhotonTargets.MasterClient$2");
216 text = PregReplace(text, NOT_VAR_WITH_DOT + "RPCMode" + NOT_VAR_WITH_DOT, "$1PhotonTargets$2");
217 }
218
219 //NetworkMessageInfo: 100%
220 {
221 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkMessageInfo" + NOT_VAR_WITH_DOT, "$1PhotonMessageInfo$2");
222 text = PregReplace(text, NOT_VAR_WITH_DOT + "networkView" + NOT_VAR_WITH_DOT, "$1photonView$2");
223 }
224
225 //NetworkViewID:
226 {
227 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkViewID" + NOT_VAR_WITH_DOT, "$1int$2"); //We simply use an int
228 }
229
230 //NetworkPlayer
231 {
232 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkPlayer" + NOT_VAR_WITH_DOT, "$1PhotonPlayer$2");
233 }
234
235 //Network
236 {
237 //Monobehaviour callbacks
238 {
239 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnPlayerConnected" + NOT_VAR_WITH_DOT, "$1OnPhotonPlayerConnected$2");
240 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnPlayerDisconnected" + NOT_VAR_WITH_DOT, "$1OnPhotonPlayerDisconnected$2");
241 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnNetworkInstantiate" + NOT_VAR_WITH_DOT, "$1OnPhotonInstantiate$2");
242 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnSerializeNetworkView" + NOT_VAR_WITH_DOT, "$1OnPhotonSerializeView$2");
243 text = PregReplace(text, NOT_VAR_WITH_DOT + "BitStream" + NOT_VAR_WITH_DOT, "$1PhotonStream$2");
244
245 //Not completely the same meaning
246 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnServerInitialized" + NOT_VAR_WITH_DOT, "$1OnCreatedRoom$2");
247 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnConnectedToServer" + NOT_VAR_WITH_DOT, "$1OnJoinedRoom$2");
248
249 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnFailedToConnectToMasterServer" + NOT_VAR_WITH_DOT, "$1OnFailedToConnectToPhoton$2");
250 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnFailedToConnect" + NOT_VAR_WITH_DOT, "$1OnFailedToConnect_OBSELETE$2");
251 }
252
253 //Variables
254 {
255
256 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.connections" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.playerList$2");
257 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.isServer" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isMasterClient$2");
258 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.isClient" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isNonMasterClientInRoom$2");
259
260 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkPeerType" + NOT_VAR_WITH_DOT, "$1ConnectionState$2");
261 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.peerType" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.connectionState$2");
262 text = PregReplace(text, NOT_VAR_WITH_DOT + "ConnectionState.Server" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isMasterClient$2");
263 text = PregReplace(text, NOT_VAR_WITH_DOT + "ConnectionState.Client" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isNonMasterClientInRoom$2");
264 text = PregReplace(text, NOT_VAR_WITH_DOT + "PhotonNetwork.playerList.Length" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.playerList.Count$2");
265
266 /*DROPPED:
267 minimumAllocatableViewIDs
268 natFacilitatorIP is dropped
269 natFacilitatorPort is dropped
270 connectionTesterIP
271 connectionTesterPort
272 proxyIP
273 proxyPort
274 useProxy
275 proxyPassword
276 */
277 }
278
279 //Methods
280 {
281 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.InitializeServer" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.CreateRoom$2");
282 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.Connect" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.JoinRoom$2");
283 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.GetAveragePing" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.GetPing$2");
284 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.GetLastPing" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.GetPing$2");
285 /*DROPPED:
286 TestConnection
287 TestConnectionNAT
288 HavePublicAddress
289 */
290 }
291
292 //Overall
293 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network" + NOT_VAR_WITH_DOT, "$1PhotonNetwork$2");
294
295
296 //Changed methods
297 string ignoreMe = @"([A-Za-z0-9_\[\]\(\) ]+)";
298
299 text = PregReplace(text, NOT_VAR_WITH_DOT + "PhotonNetwork.GetPing\\(" + ignoreMe+"\\);", "$1PhotonNetwork.GetPing();");
300 text = PregReplace(text, NOT_VAR_WITH_DOT + "PhotonNetwork.CloseConnection\\(" + ignoreMe+","+ignoreMe+"\\);", "$1PhotonNetwork.CloseConnection($2);");
301
302 }
303
304 //General
305 {
306 if (text.Contains("Photon")) //Only use the PhotonMonoBehaviour if we use photonView and friends.
307 {
308 if (isJS)//JS
309 {
310 if (text.Contains("extends MonoBehaviour"))
311 text = PregReplace(text, "extends MonoBehaviour", "extends Photon.MonoBehaviour");
312 else
313 text = "class " + className + " extends Photon.MonoBehaviour {\n" + text + "\n}";
314 }
315 else //C#
316 text = PregReplace(text, ": MonoBehaviour", ": Photon.MonoBehaviour");
317 }
318 }
319
320 File.WriteAllText(file, text);
321 }
File name: ShowStatusWhenConnecting.cs
Copy
8 void OnGUI()
9 {
10 if( Skin != null )
11 {
12 GUI.skin = Skin;
13 }
14
15 float width = 400;
16 float height = 100;
17
18 Rect centeredRect = new Rect( ( Screen.width - width ) / 2, ( Screen.height - height ) / 2, width, height );
19
20 GUILayout.BeginArea( centeredRect, GUI.skin.box );
21 {
22 GUILayout.Label( "Connecting" + GetConnectingDots(), GUI.skin.customStyles[ 0 ] );
23 GUILayout.Label( "Status: " + PhotonNetwork.connectionStateDetailed );
24 }
25 GUILayout.EndArea();
26
27 if( PhotonNetwork.connectionStateDetailed == PeerState.Joined )
28 {
29 enabled = false;
30 }
31 }
File name: ShowStatusWhenConnecting.cs
Copy
33 string GetConnectingDots()
34 {
35 string str = "";
36 int numberOfDots = Mathf.FloorToInt( Time.timeSinceLevelLoad * 3f % 4 );
37
38 for( int i = 0; i < numberOfDots; ++i )
39 {
40 str += " .";
41 }
42
43 return str;
44 }
File name: VSCode.cs
Copy
480 static void CheckForUpdate()
481 {
482 var fileContent = string.Empty;
483
484 EditorUtility.DisplayProgressBar("VSCode", "Checking for updates ...", 0.5f);
485
486 // Because were not a runtime framework, lets just use the simplest way of doing this
487 try
488 {
489 using (var webClient = new System.Net.WebClient())
490 {
491 fileContent = webClient.DownloadString("https://raw.githubusercontent.com/dotBunny/VSCode/master/Plugins/Editor/VSCode.cs");
492 }
493 }
494 catch (Exception e)
495 {
496 if (Debug)
497 {
498 UnityEngine.Debug.Log("[VSCode] " + e.Message);
499
500 }
501
502 // Don't go any further if there is an error
503 return;
504 }
505 finally
506 {
507 EditorUtility.ClearProgressBar();
508 }
509
510 // Set the last update time
511 LastUpdate = DateTime.Now;
512
513 // Fix for oddity in downlo
514 if (fileContent.Substring(0, 2) != "/*")
515 {
516 int startPosition = fileContent.IndexOf("/*", StringComparison.CurrentCultureIgnoreCase);
517
518 // Jump over junk characters
519 fileContent = fileContent.Substring(startPosition);
520 }
521
522 string[] fileExploded = fileContent.Split('\n');
523 if (fileExploded.Length > 7)
524 {
525 float github = Version;
526 if (float.TryParse(fileExploded[6].Replace("*", "").Trim(), out github))
527 {
528 GitHubVersion = github;
529 }
530
531
532 if (github > Version)
533 {
534 var GUIDs = AssetDatabase.FindAssets("t:Script VSCode");
535 var path = Application.dataPath.Substring(0, Application.dataPath.Length - "/Assets".Length) + System.IO.Path.DirectorySeparatorChar +
536 AssetDatabase.GUIDToAssetPath(GUIDs[0]).Replace('/', System.IO.Path.DirectorySeparatorChar);
537
538 if (EditorUtility.DisplayDialog("VSCode Update", "A newer version of the VSCode plugin is available, would you like to update your version?", "Yes", "No"))
539 {
540 // Always make sure the file is writable
541 System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
542 fileInfo.IsReadOnly = false;
543
544 // Write update file
545 File.WriteAllText(path, fileContent);
546
547 // Force update on text file
548 AssetDatabase.ImportAsset(AssetDatabase.GUIDToAssetPath(GUIDs[0]), ImportAssetOptions.ForceUpdate);
549 }
550
551 }
552 }
553 }
File name: Dots.cs
Copy
16 public void Update()
17 {
18 GameObject player = animals.getAnimal(0);
19 dots[0].transform.localPosition = new Vector3(player.transform.localPosition.x * 4.2f / 225 - 2.9f, dots[0].transform.localPosition.y, dots[0].transform.localPosition.z);
20
21 animalX = player.transform.localPosition.x;
22 rankTemp = 8;
23
24 for (int i = 1; i < 8; i++)
25 {
26 GameObject animal = animals.getAnimal(i);
27 dots[i].transform.localPosition = new Vector3(animal.transform.localPosition.x * 4.2f / 225 - 2.9f, dots[i].transform.localPosition.y, dots[i].transform.localPosition.z);
28 if (animalX >= animal.transform.localPosition.x)
29 {
30 rankTemp--;
31 }
32 }
33 rankPlayer = rankTemp;
34 }
File name: TaskBar.cs
Copy
32 public void Update()
33 {
34 rankFont.setText(dots.getRankPlayer() + "", 0, 0, "GUI", "GUI");
35 fontTime.setText(((int)(time * 100)) / 100.0f + "", 0, 0, "GUI", "GUI");
36 fontGold.setText(gold + "", 0, 0, "GUI", "GUI");
37 fontScore.setText(score + "", 0, 0, "GUI", "GUI");
38 }
File name: ScrollHelp.cs
Copy
65 public void Update()
66 {
67 if (Input.GetButtonDown("Fire1"))
68 {
69 touchX = Input.mousePosition.x;
70 isUpdate = false;
71 updateDots();
72 }
73 else if (Input.GetButton("Fire1"))//su kien giu chuot
74 {
75 deltaX = Input.mousePosition.x - touchX;
76
77 rect1.x += deltaX;
78 rect2.x += deltaX;
79 rect3.x += deltaX;
80 rect4.x += deltaX;
81
82 touchX = Input.mousePosition.x;
83
84 }
85 else if (Input.GetButtonUp("Fire1"))
86 {
87 Current = currentBg(rect1.x);
88 offsetX = -538 * Current - 10 * Current - rect1.x;
89 step = offsetX * 5;
90 isUpdate = true;
91 rxs[0] = rect1.x + offsetX;
92 rxs[1] = rect2.x + offsetX;
93 rxs[2] = rect3.x + offsetX;
94 rxs[3] = rect4.x + offsetX;
95 }
96
97
98 if (isUpdate)
99 {
100 if (offsetX < 0)
101 {
102 if (rect1.x > rxs[0])
103 {
104 rect1.x += step * Time.deltaTime;
105 rect2.x += step * Time.deltaTime;
106 rect3.x += step * Time.deltaTime;
107 rect4.x += step * Time.deltaTime;
108 }
109 else
110 {
111 rect1.x = rxs[0];
112 rect2.x = rxs[1];
113 rect3.x = rxs[2];
114 rect4.x = rxs[3];
115 isUpdate = false;
116 updateDots();
117 }
118 }
119 else
120 {
121 if (rect1.x < rxs[0])
122 {
123 rect1.x += step * Time.deltaTime;
124 rect2.x += step * Time.deltaTime;
125 rect3.x += step * Time.deltaTime;
126 rect4.x += step * Time.deltaTime;
127 }
128 else
129 {
130 rect1.x = rxs[0];
131 rect2.x = rxs[1];
132 rect3.x = rxs[2];
133 rect4.x = rxs[3];
134 isUpdate = false;
135 updateDots();
136 }
137 }
138 }
139 }
File name: ScrollHelp.cs
Copy
153 private void updateDots()
154 {
155 switch (Current)
156 {
157 case 0:
158 bigDot.transform.position = new Vector3(dot0.transform.position.x, dot0.transform.position.y, bigDot.transform.position.z);
159 break;
160 case 1:
161 bigDot.transform.position = new Vector3(dot1.transform.position.x, dot1.transform.position.y, bigDot.transform.position.z);
162 break;
163 case 2:
164 bigDot.transform.position = new Vector3(dot2.transform.position.x, dot2.transform.position.y, bigDot.transform.position.z);
165 break;
166 case 3:
167 bigDot.transform.position = new Vector3(dot3.transform.position.x, dot3.transform.position.y, bigDot.transform.position.z);
168 break;
169 }
170 }
Download file with original file name:Dot
Dot 96 lượt xem
Gõ tìm kiếm nhanh...