├── .gitignore
├── Assets
├── Assemblies.meta
├── Assemblies
│ ├── Lidgren.Network.XML
│ ├── Lidgren.Network.XML.meta
│ ├── Lidgren.Network.dll
│ ├── Lidgren.Network.dll.meta
│ ├── Lidgren.Network.pdb
│ └── Lidgren.Network.pdb.meta
├── Materials.meta
├── Materials
│ ├── Materials.meta
│ ├── Materials
│ │ ├── proto_blue.mat
│ │ └── proto_blue.mat.meta
│ ├── Player.mat
│ ├── Player.mat.meta
│ ├── Target.mat
│ ├── Target.mat.meta
│ ├── proto_blue.tga
│ └── proto_blue.tga.meta
├── Resources.meta
├── Resources
│ ├── Player.prefab
│ ├── Player.prefab.meta
│ ├── Target.prefab
│ └── Target.prefab.meta
├── Scenes.meta
├── Scenes
│ ├── Example.unity
│ └── Example.unity.meta
├── Scripts.meta
└── Scripts
│ ├── LocalCamera.cs
│ ├── LocalCamera.cs.meta
│ ├── MathUtils.cs
│ ├── MathUtils.cs.meta
│ ├── NetworkActions.cs
│ ├── NetworkActions.cs.meta
│ ├── NetworkActor.cs
│ ├── NetworkActor.cs.meta
│ ├── NetworkActorRegistry.cs
│ ├── NetworkActorRegistry.cs.meta
│ ├── NetworkClient.cs
│ ├── NetworkClient.cs.meta
│ ├── NetworkClientBehaviour.cs
│ ├── NetworkClientBehaviour.cs.meta
│ ├── NetworkClientInfo.cs
│ ├── NetworkClientInfo.cs.meta
│ ├── NetworkController.cs
│ ├── NetworkController.cs.meta
│ ├── NetworkPeer.cs
│ ├── NetworkPeer.cs.meta
│ ├── NetworkPosition.cs
│ ├── NetworkPosition.cs.meta
│ ├── NetworkRemoteCall.cs
│ ├── NetworkRemoteCall.cs.meta
│ ├── NetworkRemoteCallReceiver.cs
│ ├── NetworkRemoteCallReceiver.cs.meta
│ ├── NetworkServer.cs
│ ├── NetworkServer.cs.meta
│ ├── NetworkServerBehaviour.cs
│ ├── NetworkServerBehaviour.cs.meta
│ ├── NetworkState.cs
│ ├── NetworkState.cs.meta
│ ├── NetworkTime.cs
│ ├── NetworkTime.cs.meta
│ ├── NetworkUtils.cs
│ ├── NetworkUtils.cs.meta
│ ├── PlayerActor.cs
│ ├── PlayerActor.cs.meta
│ ├── RecyclableObjectPool.cs
│ ├── RecyclableObjectPool.cs.meta
│ ├── UserCommand.cs
│ ├── UserCommand.cs.meta
│ ├── UserInput.cs
│ └── UserInput.cs.meta
└── ProjectSettings
├── AudioManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── InputManager.asset
├── NavMeshLayers.asset
├── NetworkManager.asset
├── ProjectSettings.asset
├── QualitySettings.asset
├── TagManager.asset
└── TimeManager.asset
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | /Library
3 | /Temp
4 | *.csproj
5 | *.pidb
6 | *.unityproj
7 | *.sln
8 | *.userprefs
9 | /Build
--------------------------------------------------------------------------------
/Assets/Assemblies.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ede6a3ad26ea9fd4188a2ffe1bd313d1
3 |
--------------------------------------------------------------------------------
/Assets/Assemblies/Lidgren.Network.XML:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Lidgren.Network
5 |
6 |
7 |
8 |
9 | Triple DES encryption
10 |
11 |
12 |
13 |
14 | Interface for an encryption algorithm
15 |
16 |
17 |
18 |
19 | Encrypt an outgoing message in place
20 |
21 |
22 |
23 |
24 | Decrypt an incoming message in place
25 |
26 |
27 |
28 |
29 | NetTriplsDESEncryption constructor
30 |
31 |
32 |
33 |
34 | NetTriplsDESEncryption constructor
35 |
36 |
37 |
38 |
39 | NetTriplsDESEncryption constructor
40 |
41 |
42 |
43 |
44 | Encrypt outgoing message
45 |
46 |
47 |
48 |
49 | Decrypt incoming message
50 |
51 |
52 |
53 |
54 | Big integer class based on BouncyCastle (http://www.bouncycastle.org) big integer code
55 |
56 |
57 |
58 |
59 | Statistics for a NetConnection instance
60 |
61 |
62 |
63 |
64 | Returns a string that represents this object
65 |
66 |
67 |
68 |
69 | Gets the number of sent packets for this connection
70 |
71 |
72 |
73 |
74 | Gets the number of received packets for this connection
75 |
76 |
77 |
78 |
79 | Gets the number of sent bytes for this connection
80 |
81 |
82 |
83 |
84 | Gets the number of received bytes for this connection
85 |
86 |
87 |
88 |
89 | Gets the number of resent reliable messages for this connection
90 |
91 |
92 |
93 |
94 | A fast random number generator for .NET
95 | Colin Green, January 2005
96 |
97 | September 4th 2005
98 | Added NextBytesUnsafe() - commented out by default.
99 | Fixed bug in Reinitialise() - y,z and w variables were not being reset.
100 |
101 | Key points:
102 | 1) Based on a simple and fast xor-shift pseudo random number generator (RNG) specified in:
103 | Marsaglia, George. (2003). Xorshift RNGs.
104 | http://www.jstatsoft.org/v08/i14/xorshift.pdf
105 |
106 | This particular implementation of xorshift has a period of 2^128-1. See the above paper to see
107 | how this can be easily extened if you need a longer period. At the time of writing I could find no
108 | information on the period of System.Random for comparison.
109 |
110 | 2) Faster than System.Random. Up to 8x faster, depending on which methods are called.
111 |
112 | 3) Direct replacement for System.Random. This class implements all of the methods that System.Random
113 | does plus some additional methods. The like named methods are functionally equivalent.
114 |
115 | 4) Allows fast re-initialisation with a seed, unlike System.Random which accepts a seed at construction
116 | time which then executes a relatively expensive initialisation routine. This provides a vast speed improvement
117 | if you need to reset the pseudo-random number sequence many times, e.g. if you want to re-generate the same
118 | sequence many times. An alternative might be to cache random numbers in an array, but that approach is limited
119 | by memory capacity and the fact that you may also want a large number of different sequences cached. Each sequence
120 | can each be represented by a single seed value (int) when using FastRandom.
121 |
122 | Notes.
123 | A further performance improvement can be obtained by declaring local variables as static, thus avoiding
124 | re-allocation of variables on each call. However care should be taken if multiple instances of
125 | FastRandom are in use or if being used in a multi-threaded environment.
126 |
127 |
128 |
129 | Gets a global NetRandom instance
130 |
131 |
132 |
133 |
134 | Initialises a new instance using time dependent seed.
135 |
136 |
137 |
138 |
139 | Initialises a new instance using an int value as seed.
140 | This constructor signature is provided to maintain compatibility with
141 | System.Random
142 |
143 |
144 |
145 |
146 | Create a semi-random seed based on an object
147 |
148 |
149 |
150 |
151 | Reinitialises using an int value as a seed.
152 |
153 |
154 |
155 |
156 |
157 | Generates a random int over the range 0 to int.MaxValue-1.
158 | MaxValue is not generated in order to remain functionally equivalent to System.Random.Next().
159 | This does slightly eat into some of the performance gain over System.Random, but not much.
160 | For better performance see:
161 |
162 | Call NextInt() for an int over the range 0 to int.MaxValue.
163 |
164 | Call NextUInt() and cast the result to an int to generate an int over the full Int32 value range
165 | including negative values.
166 |
167 |
168 |
169 |
170 |
171 | Generates a random int over the range 0 to upperBound-1, and not including upperBound.
172 |
173 |
174 |
175 |
176 |
177 |
178 | Generates a random int over the range lowerBound to upperBound-1, and not including upperBound.
179 | upperBound must be >= lowerBound. lowerBound may be negative.
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 | Generates a random double. Values returned are from 0.0 up to but not including 1.0.
188 |
189 |
190 |
191 |
192 |
193 | Generates a random single. Values returned are from 0.0 up to but not including 1.0.
194 |
195 |
196 |
197 |
198 | Fills the provided byte array with random bytes.
199 | This method is functionally equivalent to System.Random.NextBytes().
200 |
201 |
202 |
203 |
204 |
205 | Generates a uint. Values returned are over the full range of a uint,
206 | uint.MinValue to uint.MaxValue, inclusive.
207 |
208 | This is the fastest method for generating a single random number because the underlying
209 | random number generator algorithm generates 32 random bits that can be cast directly to
210 | a uint.
211 |
212 |
213 |
214 |
215 | Generates a random int over the range 0 to int.MaxValue, inclusive.
216 | This method differs from Next() only in that the range is 0 to int.MaxValue
217 | and not 0 to int.MaxValue-1.
218 |
219 | The slight difference in range means this method is slightly faster than Next()
220 | but is not functionally equivalent to System.Random.Next().
221 |
222 |
223 |
224 |
225 |
226 | Generates a single random bit.
227 | This method's performance is improved by generating 32 bits in one operation and storing them
228 | ready for future calls.
229 |
230 |
231 |
232 |
233 |
234 | Statistics for a NetPeer instance
235 |
236 |
237 |
238 |
239 | Returns a string that represents this object
240 |
241 |
242 |
243 |
244 | Gets the number of sent packets since the NetPeer was initialized
245 |
246 |
247 |
248 |
249 | Gets the number of received packets since the NetPeer was initialized
250 |
251 |
252 |
253 |
254 | Gets the number of sent messages since the NetPeer was initialized
255 |
256 |
257 |
258 |
259 | Gets the number of received messages since the NetPeer was initialized
260 |
261 |
262 |
263 |
264 | Gets the number of sent bytes since the NetPeer was initialized
265 |
266 |
267 |
268 |
269 | Gets the number of received bytes since the NetPeer was initialized
270 |
271 |
272 |
273 |
274 | Gets the number of bytes allocated (and possibly garbage collected) for message storage
275 |
276 |
277 |
278 |
279 | Gets the number of bytes in the recycled pool
280 |
281 |
282 |
283 |
284 | Partly immutable after NetPeer has been initialized
285 |
286 |
287 |
288 |
289 | NetPeerConfiguration constructor
290 |
291 |
292 |
293 |
294 | Enables receiving of the specified type of message
295 |
296 |
297 |
298 |
299 | Disables receiving of the specified type of message
300 |
301 |
302 |
303 |
304 | Enables or disables receiving of the specified type of message
305 |
306 |
307 |
308 |
309 | Gets if receiving of the specified type of message is enabled
310 |
311 |
312 |
313 |
314 | Creates a memberwise shallow clone of this configuration
315 |
316 |
317 |
318 |
319 | Gets the identifier of this application; the library can only connect to matching app identifier peers
320 |
321 |
322 |
323 |
324 | Gets or sets the name of the library network thread. Cannot be changed once NetPeer is initialized.
325 |
326 |
327 |
328 |
329 | Gets or sets the maximum amount of connections this peer can hold. Cannot be changed once NetPeer is initialized.
330 |
331 |
332 |
333 |
334 | Gets or sets the maximum amount of bytes to send in a single packet, excluding ip, udp and lidgren headers
335 |
336 |
337 |
338 |
339 | Gets or sets the default capacity in bytes when NetPeer.CreateMessage() is called without argument
340 |
341 |
342 |
343 |
344 | Gets or sets the time between latency calculating pings
345 |
346 |
347 |
348 |
349 | Gets or sets if the library should recycling messages to avoid excessive garbage collection. Cannot be changed once NetPeer is initialized.
350 |
351 |
352 |
353 |
354 | Gets or sets the number of seconds timeout will be postponed on a successful ping/pong
355 |
356 |
357 |
358 |
359 | Enables UPnP support; enabling port forwarding and getting external ip
360 |
361 |
362 |
363 |
364 | Gets or sets the local ip address to bind to. Defaults to IPAddress.Any. Cannot be changed once NetPeer is initialized.
365 |
366 |
367 |
368 |
369 | Gets or sets the local port to bind to. Defaults to 0. Cannot be changed once NetPeer is initialized.
370 |
371 |
372 |
373 |
374 | Gets or sets the size in bytes of the receiving buffer. Defaults to 131071 bytes. Cannot be changed once NetPeer is initialized.
375 |
376 |
377 |
378 |
379 | Gets or sets the size in bytes of the sending buffer. Defaults to 131071 bytes. Cannot be changed once NetPeer is initialized.
380 |
381 |
382 |
383 |
384 | Gets or sets if the NetPeer should accept incoming connections. This is automatically set to true in NetServer and false in NetClient.
385 |
386 |
387 |
388 |
389 | Gets or sets the number of seconds between handshake attempts
390 |
391 |
392 |
393 |
394 | Gets or sets the maximum number of handshake attempts before failing to connect
395 |
396 |
397 |
398 |
399 | Gets or sets if the NetPeer should send large messages to try to expand the maximum transmission unit size
400 |
401 |
402 |
403 |
404 | Gets or sets how often to send large messages to expand MTU if AutoExpandMTU is enabled
405 |
406 |
407 |
408 |
409 | Gets or sets the number of failed expand mtu attempts to perform before setting final MTU
410 |
411 |
412 |
413 |
414 | Gets or sets the simulated amount of sent packets lost from 0.0f to 1.0f
415 |
416 |
417 |
418 |
419 | Gets or sets the minimum simulated amount of one way latency for sent packets in seconds
420 |
421 |
422 |
423 |
424 | Gets or sets the simulated added random amount of one way latency for sent packets in seconds
425 |
426 |
427 |
428 |
429 | Gets the average simulated one way latency in seconds
430 |
431 |
432 |
433 |
434 | Gets or sets the simulated amount of duplicated packets from 0.0f to 1.0f
435 |
436 |
437 |
438 |
439 | Represents a connection to a remote peer
440 |
441 |
442 |
443 |
444 | Approves this connection; sending a connection response to the remote host
445 |
446 |
447 |
448 |
449 | Approves this connection; sending a connection response to the remote host
450 |
451 | The local hail message that will be set as RemoteHailMessage on the remote host
452 |
453 |
454 |
455 | Denies this connection; disconnecting it
456 |
457 |
458 |
459 |
460 | Denies this connection; disconnecting it
461 |
462 | The stated reason for the disconnect, readable as a string in the StatusChanged message on the remote host
463 |
464 |
465 |
466 | Disconnect from the remote peer
467 |
468 | the message to send with the disconnect message
469 |
470 |
471 |
472 | Change the internal endpoint to this new one. Used when, during handshake, a switch in port is detected (due to NAT)
473 |
474 |
475 |
476 |
477 | Send a message to this remote connection
478 |
479 | The message to send
480 | How to deliver the message
481 | Sequence channel within the delivery method
482 |
483 |
484 |
485 | Zero windowSize indicates that the channel is not yet instantiated (used)
486 | Negative freeWindowSlots means this amount of messages are currently queued but delayed due to closed window
487 |
488 |
489 |
490 |
491 | Returns a string that represents this object
492 |
493 |
494 |
495 |
496 | Gets local time value comparable to NetTime.Now from a remote value
497 |
498 |
499 |
500 |
501 | Gets the remote time value for a local time value produced by NetTime.Now
502 |
503 |
504 |
505 |
506 | The message that the remote part specified via Connect() or Approve() - can be null.
507 |
508 |
509 |
510 |
511 | Gets or sets the application defined object containing data about the connection
512 |
513 |
514 |
515 |
516 | Gets the peer which holds this connection
517 |
518 |
519 |
520 |
521 | Gets the current status of the connection (synced to the last status message read)
522 |
523 |
524 |
525 |
526 | Gets various statistics for this connection
527 |
528 |
529 |
530 |
531 | Gets the remote endpoint for the connection
532 |
533 |
534 |
535 |
536 | Gets the unique identifier of the remote NetPeer for this connection
537 |
538 |
539 |
540 |
541 | Gets the local hail message that was sent as part of the handshake
542 |
543 |
544 |
545 |
546 | Gets the current average roundtrip time in seconds
547 |
548 |
549 |
550 |
551 | Time offset between this peer and the remote peer
552 |
553 |
554 |
555 |
556 | Outgoing message used to send data to remote peer(s)
557 |
558 |
559 |
560 |
561 | Returns the internal data buffer, don't modify
562 |
563 |
564 |
565 |
566 | Ensures the buffer can hold this number of bits
567 |
568 |
569 |
570 |
571 | Ensures the buffer can hold this number of bits
572 |
573 |
574 |
575 |
576 | Writes a boolean value using 1 bit
577 |
578 |
579 |
580 |
581 | Write a byte
582 |
583 |
584 |
585 |
586 | Writes a signed byte
587 |
588 |
589 |
590 |
591 | Writes 1 to 8 bits of a byte
592 |
593 |
594 |
595 |
596 | Writes all bytes in an array
597 |
598 |
599 |
600 |
601 | Writes the specified number of bytes from an array
602 |
603 |
604 |
605 |
606 | Writes an unsigned 16 bit integer
607 |
608 |
609 |
610 |
611 |
612 | Writes an unsigned integer using 1 to 16 bits
613 |
614 |
615 |
616 |
617 | Writes a signed 16 bit integer
618 |
619 |
620 |
621 |
622 | Writes a 32 bit signed integer
623 |
624 |
625 |
626 |
627 | Writes a 32 bit unsigned integer
628 |
629 |
630 |
631 |
632 | Writes a 32 bit signed integer
633 |
634 |
635 |
636 |
637 | Writes a signed integer using 1 to 32 bits
638 |
639 |
640 |
641 |
642 | Writes a 64 bit unsigned integer
643 |
644 |
645 |
646 |
647 | Writes an unsigned integer using 1 to 64 bits
648 |
649 |
650 |
651 |
652 | Writes a 64 bit signed integer
653 |
654 |
655 |
656 |
657 | Writes a signed integer using 1 to 64 bits
658 |
659 |
660 |
661 |
662 | Writes a 32 bit floating point value
663 |
664 |
665 |
666 |
667 | Writes a 64 bit floating point value
668 |
669 |
670 |
671 |
672 | Write Base128 encoded variable sized unsigned integer of up to 32 bits
673 |
674 | number of bytes written
675 |
676 |
677 |
678 | Write Base128 encoded variable sized signed integer of up to 32 bits
679 |
680 | number of bytes written
681 |
682 |
683 |
684 | Write Base128 encoded variable sized signed integer of up to 64 bits
685 |
686 | number of bytes written
687 |
688 |
689 |
690 | Write Base128 encoded variable sized unsigned integer of up to 64 bits
691 |
692 | number of bytes written
693 |
694 |
695 |
696 | Compress (lossy) a float in the range -1..1 using numberOfBits bits
697 |
698 |
699 |
700 |
701 | Compress (lossy) a float in the range 0..1 using numberOfBits bits
702 |
703 |
704 |
705 |
706 | Compress a float within a specified range using a certain number of bits
707 |
708 |
709 |
710 |
711 | Writes an integer with the least amount of bits need for the specified range
712 | Returns number of bits written
713 |
714 |
715 |
716 |
717 | Write a string
718 |
719 |
720 |
721 |
722 | Writes an endpoint description
723 |
724 |
725 |
726 |
727 | Writes the local time to a message; readable (and convertable to local time) by the remote host using ReadTime()
728 |
729 |
730 |
731 |
732 | Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
733 |
734 |
735 |
736 |
737 | Pads data with the specified number of bits.
738 |
739 |
740 |
741 |
742 | Append all the bits of message to this message
743 |
744 |
745 |
746 |
747 | Append all the bits of message to this message
748 |
749 |
750 |
751 |
752 | Writes all public and private declared instance fields of the object in alphabetical order using reflection
753 |
754 |
755 |
756 |
757 | Writes all fields with specified binding in alphabetical order using reflection
758 |
759 |
760 |
761 |
762 | Writes all public and private declared instance properties of the object in alphabetical order using reflection
763 |
764 |
765 |
766 |
767 | Writes all properties with specified binding in alphabetical order using reflection
768 |
769 |
770 |
771 |
772 | Encrypt this message using the provided algorithm; no more writing can be done before sending it or the message will be corrupt!
773 |
774 |
775 |
776 |
777 | Returns a string that represents this object
778 |
779 |
780 |
781 |
782 | Gets or sets the length of the buffer in bytes
783 |
784 |
785 |
786 |
787 | Gets or sets the length of the buffer in bits
788 |
789 |
790 |
791 |
792 | Incoming message either sent from a remote peer or generated within the library
793 |
794 |
795 |
796 |
797 | Ensures the buffer can hold this number of bits
798 |
799 |
800 |
801 |
802 | Write Base128 encoded variable sized unsigned integer
803 |
804 | number of bytes written
805 |
806 |
807 |
808 | Write Base128 encoded variable sized signed integer
809 |
810 | number of bytes written
811 |
812 |
813 |
814 | Write Base128 encoded variable sized unsigned integer
815 |
816 | number of bytes written
817 |
818 |
819 |
820 | Compress (lossy) a float in the range -1..1 using numberOfBits bits
821 |
822 |
823 |
824 |
825 | Compress (lossy) a float in the range 0..1 using numberOfBits bits
826 |
827 |
828 |
829 |
830 | Compress a float within a specified range using a certain number of bits
831 |
832 |
833 |
834 |
835 | Writes an integer with the least amount of bits need for the specified range
836 | Returns number of bits written
837 |
838 |
839 |
840 |
841 | Write a string
842 |
843 |
844 |
845 |
846 | Writes an endpoint description
847 |
848 |
849 |
850 |
851 | Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
852 |
853 |
854 |
855 |
856 | Pads data with the specified number of bits.
857 |
858 |
859 |
860 |
861 | Returns the internal data buffer, don't modify
862 |
863 |
864 |
865 |
866 | Reads a 1-bit Boolean without advancing the read pointer
867 |
868 |
869 |
870 |
871 | Reads a Byte without advancing the read pointer
872 |
873 |
874 |
875 |
876 | Reads an SByte without advancing the read pointer
877 |
878 |
879 |
880 |
881 | Reads the specified number of bits into a Byte without advancing the read pointer
882 |
883 |
884 |
885 |
886 | Reads the specified number of bytes without advancing the read pointer
887 |
888 |
889 |
890 |
891 | Reads the specified number of bytes without advancing the read pointer
892 |
893 |
894 |
895 |
896 | Reads an Int16 without advancing the read pointer
897 |
898 |
899 |
900 |
901 | Reads a UInt16 without advancing the read pointer
902 |
903 |
904 |
905 |
906 | Reads an Int32 without advancing the read pointer
907 |
908 |
909 |
910 |
911 | Reads the specified number of bits into an Int32 without advancing the read pointer
912 |
913 |
914 |
915 |
916 | Reads a UInt32 without advancing the read pointer
917 |
918 |
919 |
920 |
921 | Reads the specified number of bits into a UInt32 without advancing the read pointer
922 |
923 |
924 |
925 |
926 | Reads a UInt64 without advancing the read pointer
927 |
928 |
929 |
930 |
931 | Reads an Int64 without advancing the read pointer
932 |
933 |
934 |
935 |
936 | Reads the specified number of bits into an UInt64 without advancing the read pointer
937 |
938 |
939 |
940 |
941 | Reads the specified number of bits into an Int64 without advancing the read pointer
942 |
943 |
944 |
945 |
946 | Reads a 32-bit Single without advancing the read pointer
947 |
948 |
949 |
950 |
951 | Reads a 32-bit Single without advancing the read pointer
952 |
953 |
954 |
955 |
956 | Reads a 64-bit Double without advancing the read pointer
957 |
958 |
959 |
960 |
961 | Reads a string without advancing the read pointer
962 |
963 |
964 |
965 |
966 | Reads a boolean value (stored as a single bit) written using Write(bool)
967 |
968 |
969 |
970 |
971 | Reads a byte
972 |
973 |
974 |
975 |
976 | Reads a signed byte
977 |
978 |
979 |
980 |
981 | Reads 1 to 8 bits into a byte
982 |
983 |
984 |
985 |
986 | Reads the specified number of bytes
987 |
988 |
989 |
990 |
991 | Reads the specified number of bytes into a preallocated array
992 |
993 | The destination array
994 | The offset where to start writing in the destination array
995 | The number of bytes to read
996 |
997 |
998 |
999 | Reads the specified number of bits into a preallocated array
1000 |
1001 | The destination array
1002 | The offset where to start writing in the destination array
1003 | The number of bits to read
1004 |
1005 |
1006 |
1007 | Reads a 16 bit signed integer written using Write(Int16)
1008 |
1009 |
1010 |
1011 |
1012 | Reads a 16 bit unsigned integer written using Write(UInt16)
1013 |
1014 |
1015 |
1016 |
1017 | Reads a 32 bit signed integer written using Write(Int32)
1018 |
1019 |
1020 |
1021 |
1022 | Reads a signed integer stored in 1 to 32 bits, written using Write(Int32, Int32)
1023 |
1024 |
1025 |
1026 |
1027 | Reads an 32 bit unsigned integer written using Write(UInt32)
1028 |
1029 |
1030 |
1031 |
1032 | Reads an unsigned integer stored in 1 to 32 bits, written using Write(UInt32, Int32)
1033 |
1034 |
1035 |
1036 |
1037 | Reads a 64 bit unsigned integer written using Write(UInt64)
1038 |
1039 |
1040 |
1041 |
1042 | Reads a 64 bit signed integer written using Write(Int64)
1043 |
1044 |
1045 |
1046 |
1047 | Reads an unsigned integer stored in 1 to 64 bits, written using Write(UInt64, Int32)
1048 |
1049 |
1050 |
1051 |
1052 | Reads a signed integer stored in 1 to 64 bits, written using Write(Int64, Int32)
1053 |
1054 |
1055 |
1056 |
1057 | Reads a 32 bit floating point value written using Write(Single)
1058 |
1059 |
1060 |
1061 |
1062 | Reads a 32 bit floating point value written using Write(Single)
1063 |
1064 |
1065 |
1066 |
1067 | Reads a 64 bit floating point value written using Write(Double)
1068 |
1069 |
1070 |
1071 |
1072 | Reads a variable sized UInt32 written using WriteVariableUInt32()
1073 |
1074 |
1075 |
1076 |
1077 | Reads a variable sized Int32 written using WriteVariableInt32()
1078 |
1079 |
1080 |
1081 |
1082 | Reads a variable sized Int64 written using WriteVariableInt64()
1083 |
1084 |
1085 |
1086 |
1087 | Reads a variable sized UInt32 written using WriteVariableInt64()
1088 |
1089 |
1090 |
1091 |
1092 | Reads a 32 bit floating point value written using WriteSignedSingle()
1093 |
1094 | The number of bits used when writing the value
1095 | A floating point value larger or equal to -1 and smaller or equal to 1
1096 |
1097 |
1098 |
1099 | Reads a 32 bit floating point value written using WriteUnitSingle()
1100 |
1101 | The number of bits used when writing the value
1102 | A floating point value larger or equal to 0 and smaller or equal to 1
1103 |
1104 |
1105 |
1106 | Reads a 32 bit floating point value written using WriteRangedSingle()
1107 |
1108 | The minimum value used when writing the value
1109 | The maximum value used when writing the value
1110 | The number of bits used when writing the value
1111 | A floating point value larger or equal to MIN and smaller or equal to MAX
1112 |
1113 |
1114 |
1115 | Reads a 32 bit integer value written using WriteRangedInteger()
1116 |
1117 | The minimum value used when writing the value
1118 | The maximum value used when writing the value
1119 | A signed integer value larger or equal to MIN and smaller or equal to MAX
1120 |
1121 |
1122 |
1123 | Reads a string written using Write(string)
1124 |
1125 |
1126 |
1127 |
1128 | Reads a stored IPv4 endpoint description
1129 |
1130 |
1131 |
1132 |
1133 | Reads a value, in local time comparable to NetTime.Now, written using WriteTime()
1134 | Must have a connected sender
1135 |
1136 |
1137 |
1138 |
1139 | Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
1140 |
1141 |
1142 |
1143 |
1144 | Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
1145 |
1146 |
1147 |
1148 |
1149 | Pads data with the specified number of bits.
1150 |
1151 |
1152 |
1153 |
1154 | Decrypt a message
1155 |
1156 | The encryption algorithm used to encrypt the message
1157 | true on success
1158 |
1159 |
1160 |
1161 | Returns a string that represents this object
1162 |
1163 |
1164 |
1165 |
1166 | Reads all public and private declared instance fields of the object in alphabetical order using reflection
1167 |
1168 |
1169 |
1170 |
1171 | Reads all fields with the specified binding of the object in alphabetical order using reflection
1172 |
1173 |
1174 |
1175 |
1176 | Reads all public and private declared instance fields of the object in alphabetical order using reflection
1177 |
1178 |
1179 |
1180 |
1181 | Reads all fields with the specified binding of the object in alphabetical order using reflection
1182 |
1183 |
1184 |
1185 |
1186 | Gets or sets the read position in the buffer, in bits (not bytes)
1187 |
1188 |
1189 |
1190 |
1191 | Gets the position in the buffer in bytes; note that the bits of the first returned byte may already have been read - check the Position property to make sure.
1192 |
1193 |
1194 |
1195 |
1196 | Gets the type of this incoming message
1197 |
1198 |
1199 |
1200 |
1201 | Gets the delivery method this message was sent with (if user data)
1202 |
1203 |
1204 |
1205 |
1206 | Gets the sequence channel this message was sent with (if user data)
1207 |
1208 |
1209 |
1210 |
1211 | IPEndPoint of sender, if any
1212 |
1213 |
1214 |
1215 |
1216 | NetConnection of sender, if any
1217 |
1218 |
1219 |
1220 |
1221 | What local time the message was received from the network
1222 |
1223 |
1224 |
1225 |
1226 | Gets the length of the message payload in bytes
1227 |
1228 |
1229 |
1230 |
1231 | Gets the length of the message payload in bits
1232 |
1233 |
1234 |
1235 |
1236 | Exception thrown in the Lidgren Network Library
1237 |
1238 |
1239 |
1240 |
1241 | NetException constructor
1242 |
1243 |
1244 |
1245 |
1246 | NetException constructor
1247 |
1248 |
1249 |
1250 |
1251 | NetException constructor
1252 |
1253 |
1254 |
1255 |
1256 | NetException constructor
1257 |
1258 |
1259 |
1260 |
1261 | Throws an exception, in DEBUG only, if first parameter is false
1262 |
1263 |
1264 |
1265 |
1266 | Throws an exception, in DEBUG only, if first parameter is false
1267 |
1268 |
1269 |
1270 |
1271 | Fixed size vector of booleans
1272 |
1273 |
1274 |
1275 |
1276 | NetBitVector constructor
1277 |
1278 |
1279 |
1280 |
1281 | Returns true if all bits/booleans are set to zero/false
1282 |
1283 |
1284 |
1285 |
1286 | Returns the number of bits/booleans set to one/true
1287 |
1288 |
1289 |
1290 |
1291 |
1292 | Shift all bits one step down, cycling the first bit to the top
1293 |
1294 |
1295 |
1296 |
1297 | Gets the first (lowest) index set to true
1298 |
1299 |
1300 |
1301 |
1302 | Gets the bit/bool at the specified index
1303 |
1304 |
1305 |
1306 |
1307 | Sets or clears the bit/bool at the specified index
1308 |
1309 |
1310 |
1311 |
1312 | Sets all bits/booleans to zero/false
1313 |
1314 |
1315 |
1316 |
1317 | Returns a string that represents this object
1318 |
1319 |
1320 |
1321 |
1322 | Gets the number of bits/booleans stored in this vector
1323 |
1324 |
1325 |
1326 |
1327 | Gets the bit/bool at the specified index
1328 |
1329 |
1330 |
1331 |
1332 | Methods to encrypt and decrypt data using the XTEA algorithm
1333 |
1334 |
1335 |
1336 |
1337 | Base for a non-threadsafe encryption class
1338 |
1339 |
1340 |
1341 |
1342 | NetBlockEncryptionBase constructor
1343 |
1344 |
1345 |
1346 |
1347 | Encrypt am outgoing message with this algorithm; no writing can be done to the message after encryption, or message will be corrupted
1348 |
1349 |
1350 |
1351 |
1352 | Decrypt an incoming message encrypted with corresponding Encrypt
1353 |
1354 | message to decrypt
1355 | true if successful; false if failed
1356 |
1357 |
1358 |
1359 | Encrypt a block of bytes
1360 |
1361 |
1362 |
1363 |
1364 | Decrypt a block of bytes
1365 |
1366 |
1367 |
1368 |
1369 | Block size in bytes for this cipher
1370 |
1371 |
1372 |
1373 |
1374 | 16 byte key
1375 |
1376 |
1377 |
1378 |
1379 | 16 byte key
1380 |
1381 |
1382 |
1383 |
1384 | String to hash for key
1385 |
1386 |
1387 |
1388 |
1389 | Encrypts a block of bytes
1390 |
1391 |
1392 |
1393 |
1394 | Decrypts a block of bytes
1395 |
1396 |
1397 |
1398 |
1399 | Gets the block size for this cipher
1400 |
1401 |
1402 |
1403 |
1404 | Represents a local peer capable of holding zero, one or more connections to remote peers
1405 |
1406 |
1407 |
1408 |
1409 | Emit a discovery signal to all hosts on your subnet
1410 |
1411 |
1412 |
1413 |
1414 | Emit a discovery signal to a single known host
1415 |
1416 |
1417 |
1418 |
1419 | Emit a discovery signal to a single known host
1420 |
1421 |
1422 |
1423 |
1424 | Send a discovery response message
1425 |
1426 |
1427 |
1428 |
1429 | Call this to register a callback for when a new message arrives
1430 |
1431 |
1432 |
1433 |
1434 | NetPeer constructor
1435 |
1436 |
1437 |
1438 |
1439 | Binds to socket and spawns the networking thread
1440 |
1441 |
1442 |
1443 |
1444 | Get the connection, if any, for a certain remote endpoint
1445 |
1446 |
1447 |
1448 |
1449 | Read a pending message from any connection, blocking up to maxMillis if needed
1450 |
1451 |
1452 |
1453 |
1454 | Read a pending message from any connection, if any
1455 |
1456 |
1457 |
1458 |
1459 | Create a connection to a remote endpoint
1460 |
1461 |
1462 |
1463 |
1464 | Create a connection to a remote endpoint
1465 |
1466 |
1467 |
1468 |
1469 | Create a connection to a remote endpoint
1470 |
1471 |
1472 |
1473 |
1474 | Create a connection to a remote endpoint
1475 |
1476 |
1477 |
1478 |
1479 | Send raw bytes; only used for debugging
1480 |
1481 |
1482 |
1483 |
1484 | Disconnects all active connections and closes the socket
1485 |
1486 |
1487 |
1488 |
1489 | Creates a new message for sending
1490 |
1491 |
1492 |
1493 |
1494 | Creates a new message for sending and writes the provided string to it
1495 |
1496 |
1497 |
1498 |
1499 | Creates a new message for sending
1500 |
1501 | initial capacity in bytes
1502 |
1503 |
1504 |
1505 | Recycles a NetIncomingMessage instance for reuse; taking pressure off the garbage collector
1506 |
1507 |
1508 |
1509 |
1510 | Creates an incoming message with the required capacity for releasing to the application
1511 |
1512 |
1513 |
1514 |
1515 | Send a message to a specific connection
1516 |
1517 | The message to send
1518 | The recipient connection
1519 | How to deliver the message
1520 |
1521 |
1522 |
1523 | Send a message to a specific connection
1524 |
1525 | The message to send
1526 | The recipient connection
1527 | How to deliver the message
1528 | Sequence channel within the delivery method
1529 |
1530 |
1531 |
1532 | Send a message to a list of connections
1533 |
1534 | The message to send
1535 | The list of recipients to send to
1536 | How to deliver the message
1537 | Sequence channel within the delivery method
1538 |
1539 |
1540 |
1541 | Send a message to an unconnected host
1542 |
1543 |
1544 |
1545 |
1546 | Send a message to an unconnected host
1547 |
1548 |
1549 |
1550 |
1551 | Send a message to an unconnected host
1552 |
1553 |
1554 |
1555 |
1556 | Send NetIntroduction to hostExternal and clientExternal; introducing client to host
1557 |
1558 |
1559 |
1560 |
1561 | Called when host/client receives a NatIntroduction message from a master server
1562 |
1563 |
1564 |
1565 |
1566 | Called when receiving a NatPunchMessage from a remote endpoint
1567 |
1568 |
1569 |
1570 |
1571 | Gets the socket, if Start() has been called
1572 |
1573 |
1574 |
1575 |
1576 | Gets the NetPeerStatus of the NetPeer
1577 |
1578 |
1579 |
1580 |
1581 | Signalling event which can be waited on to determine when a message is queued for reading.
1582 | Note that there is no guarantee that after the event is signaled the blocked thread will
1583 | find the message in the queue. Other user created threads could be preempted and dequeue
1584 | the message before the waiting thread wakes up.
1585 |
1586 |
1587 |
1588 |
1589 | Gets a unique identifier for this NetPeer based on Mac address and ip/port. Note! Not available until Start() has been called!
1590 |
1591 |
1592 |
1593 |
1594 | Gets the port number this NetPeer is listening and sending on, if Start() has been called
1595 |
1596 |
1597 |
1598 |
1599 | Returns an UPnP object if enabled in the NetPeerConfiguration
1600 |
1601 |
1602 |
1603 |
1604 | Gets or sets the application defined object containing data about the peer
1605 |
1606 |
1607 |
1608 |
1609 | Gets a copy of the list of connections
1610 |
1611 |
1612 |
1613 |
1614 | Gets the number of active connections
1615 |
1616 |
1617 |
1618 |
1619 | Statistics on this NetPeer since it was initialized
1620 |
1621 |
1622 |
1623 |
1624 | Gets the configuration used to instanciate this NetPeer
1625 |
1626 |
1627 |
1628 |
1629 | RC2 encryption
1630 |
1631 |
1632 |
1633 |
1634 | NetRC2Encryption constructor
1635 |
1636 |
1637 |
1638 |
1639 | NetRC2Encryption constructor
1640 |
1641 |
1642 |
1643 |
1644 | NetRC2Encryption constructor
1645 |
1646 |
1647 |
1648 |
1649 |
1650 | Encrypt outgoing message
1651 |
1652 |
1653 |
1654 |
1655 | Decrypt incoming message
1656 |
1657 |
1658 |
1659 |
1660 | AES encryption
1661 |
1662 |
1663 |
1664 |
1665 | NetAESEncryption constructor
1666 |
1667 |
1668 |
1669 |
1670 | NetAESEncryption constructor
1671 |
1672 |
1673 |
1674 |
1675 | NetAESEncryption constructor
1676 |
1677 |
1678 |
1679 |
1680 | Encrypt outgoing message
1681 |
1682 |
1683 |
1684 |
1685 | Decrypt incoming message
1686 |
1687 |
1688 |
1689 |
1690 | All the constants used when compiling the library
1691 |
1692 |
1693 |
1694 |
1695 | Number of channels which needs a sequence number to work
1696 |
1697 |
1698 |
1699 |
1700 | Number of reliable channels
1701 |
1702 |
1703 |
1704 |
1705 | Thread safe (blocking) expanding queue with TryDequeue() and EnqueueFirst()
1706 |
1707 |
1708 |
1709 |
1710 | NetQueue constructor
1711 |
1712 |
1713 |
1714 |
1715 | Adds an item last/tail of the queue
1716 |
1717 |
1718 |
1719 |
1720 | Places an item first, at the head of the queue
1721 |
1722 |
1723 |
1724 |
1725 | Gets an item from the head of the queue, or returns default(T) if empty
1726 |
1727 |
1728 |
1729 |
1730 | Returns default(T) if queue is empty
1731 |
1732 |
1733 |
1734 |
1735 | Determines whether an item is in the queue
1736 |
1737 |
1738 |
1739 |
1740 | Copies the queue items to a new array
1741 |
1742 |
1743 |
1744 |
1745 | Removes all objects from the queue
1746 |
1747 |
1748 |
1749 |
1750 | Gets the number of items in the queue
1751 |
1752 |
1753 |
1754 |
1755 | Gets the current capacity for the queue
1756 |
1757 |
1758 |
1759 |
1760 | Helper class for NetBuffer to write/read bits
1761 |
1762 |
1763 |
1764 |
1765 | Read 1-8 bits from a buffer into a byte
1766 |
1767 |
1768 |
1769 |
1770 | Read several bytes from a buffer
1771 |
1772 |
1773 |
1774 |
1775 | Write a byte consisting of 1-8 bits to a buffer; assumes buffer is previously allocated
1776 |
1777 |
1778 |
1779 |
1780 | Write several whole bytes
1781 |
1782 |
1783 |
1784 |
1785 | Reads the specified number of bits into an UInt32
1786 |
1787 |
1788 |
1789 |
1790 | Writes the specified number of bits into a byte array
1791 |
1792 |
1793 |
1794 |
1795 | Writes the specified number of bits into a byte array
1796 |
1797 |
1798 |
1799 |
1800 | Write Base128 encoded variable sized unsigned integer
1801 |
1802 | number of bytes written
1803 |
1804 |
1805 |
1806 | Reads a UInt32 written using WriteUnsignedVarInt(); will increment offset!
1807 |
1808 |
1809 |
1810 |
1811 | Specialized version of NetPeer used for a "client" connection. It does not accept any incoming connections and maintains a ServerConnection property
1812 |
1813 |
1814 |
1815 |
1816 | NetClient constructor
1817 |
1818 |
1819 |
1820 |
1821 |
1822 | Connect to a remote server
1823 |
1824 | The remote endpoint to connect to
1825 | The hail message to pass
1826 | server connection, or null if already connected
1827 |
1828 |
1829 |
1830 | Disconnect from server
1831 |
1832 | reason for disconnect
1833 |
1834 |
1835 |
1836 | Sends message to server
1837 |
1838 |
1839 |
1840 |
1841 | Sends message to server
1842 |
1843 |
1844 |
1845 |
1846 | Returns a string that represents this object
1847 |
1848 |
1849 |
1850 |
1851 | Gets the connection to the server, if any
1852 |
1853 |
1854 |
1855 |
1856 | Gets the connection status of the server connection (or NetConnectionStatus.Disconnected if no connection)
1857 |
1858 |
1859 |
1860 |
1861 | Sender part of Selective repeat ARQ for a particular NetChannel
1862 |
1863 |
1864 |
1865 |
1866 | Example class; not very good encryption
1867 |
1868 |
1869 |
1870 |
1871 | NetXorEncryption constructor
1872 |
1873 |
1874 |
1875 |
1876 | NetXorEncryption constructor
1877 |
1878 |
1879 |
1880 |
1881 | Encrypt an outgoing message
1882 |
1883 |
1884 |
1885 |
1886 | Decrypt an incoming message
1887 |
1888 |
1889 |
1890 |
1891 | Time service
1892 |
1893 |
1894 |
1895 |
1896 | Given seconds it will output a human friendly readable string (milliseconds if less than 60 seconds)
1897 |
1898 |
1899 |
1900 |
1901 | Get number of seconds since the application started
1902 |
1903 |
1904 |
1905 |
1906 | Helper methods for implementing SRP authentication
1907 |
1908 |
1909 |
1910 |
1911 | Compute multiplier (k)
1912 |
1913 |
1914 |
1915 |
1916 | Create 16 bytes of random salt
1917 |
1918 |
1919 |
1920 |
1921 | Create 32 bytes of random ephemeral value
1922 |
1923 |
1924 |
1925 |
1926 | Computer private key (x)
1927 |
1928 |
1929 |
1930 |
1931 | Creates a verifier that the server can later use to authenticate users later on (v)
1932 |
1933 |
1934 |
1935 |
1936 | SHA hash data
1937 |
1938 |
1939 |
1940 |
1941 | Compute client public ephemeral value (A)
1942 |
1943 |
1944 |
1945 |
1946 | Compute server ephemeral value (B)
1947 |
1948 |
1949 |
1950 |
1951 | Compute intermediate value (u)
1952 |
1953 |
1954 |
1955 |
1956 | Computes the server session value
1957 |
1958 |
1959 |
1960 |
1961 | Computes the client session value
1962 |
1963 |
1964 |
1965 |
1966 | Create XTEA symmetrical encryption object from sessionValue
1967 |
1968 |
1969 |
1970 |
1971 | UPnP support class
1972 |
1973 |
1974 |
1975 |
1976 | NetUPnP constructor
1977 |
1978 |
1979 |
1980 |
1981 | Add a forwarding rule to the router using UPnP
1982 |
1983 |
1984 |
1985 |
1986 | Delete a forwarding rule from the router using UPnP
1987 |
1988 |
1989 |
1990 |
1991 | Retrieve the extern ip using UPnP
1992 |
1993 |
1994 |
1995 |
1996 | Specialized version of NetPeer used for "server" peers
1997 |
1998 |
1999 |
2000 |
2001 | NetServer constructor
2002 |
2003 |
2004 |
2005 |
2006 | Send a message to all connections
2007 |
2008 | The message to send
2009 | How to deliver the message
2010 |
2011 |
2012 |
2013 | Send a message to all connections except one
2014 |
2015 | The message to send
2016 | How to deliver the message
2017 | Don't send to this particular connection
2018 | Which sequence channel to use for the message
2019 |
2020 |
2021 |
2022 | Returns a string that represents this object
2023 |
2024 |
2025 |
2026 |
2027 | How the library deals with resends and handling of late messages
2028 |
2029 |
2030 |
2031 |
2032 | Indicates an error
2033 |
2034 |
2035 |
2036 |
2037 | Unreliable, unordered delivery
2038 |
2039 |
2040 |
2041 |
2042 | Unreliable delivery, but automatically dropping late messages
2043 |
2044 |
2045 |
2046 |
2047 | Reliable delivery, but unordered
2048 |
2049 |
2050 |
2051 |
2052 | Reliable delivery, except for late messages which are dropped
2053 |
2054 |
2055 |
2056 |
2057 | Reliable, ordered delivery
2058 |
2059 |
2060 |
2061 |
2062 | Status for a NetConnection instance
2063 |
2064 |
2065 |
2066 |
2067 | No connection, or attempt, in place
2068 |
2069 |
2070 |
2071 |
2072 | Connect has been sent; waiting for ConnectResponse
2073 |
2074 |
2075 |
2076 |
2077 | Connect was received and ConnectResponse has been sent; waiting for ConnectionEstablished
2078 |
2079 |
2080 |
2081 |
2082 | Connected
2083 |
2084 |
2085 |
2086 |
2087 | In the process of disconnecting
2088 |
2089 |
2090 |
2091 |
2092 | Disconnected
2093 |
2094 |
2095 |
2096 |
2097 | Lidgren Network Library
2098 |
2099 |
2100 |
2101 |
2102 | Utility methods
2103 |
2104 |
2105 |
2106 |
2107 | Get IPv4 endpoint from notation (xxx.xxx.xxx.xxx) or hostname and port number
2108 |
2109 |
2110 |
2111 |
2112 | Get IPv4 address from notation (xxx.xxx.xxx.xxx) or hostname
2113 |
2114 |
2115 |
2116 |
2117 | Returns the physical (MAC) address for the first usable network interface
2118 |
2119 |
2120 |
2121 |
2122 | Create a hex string from an Int64 value
2123 |
2124 |
2125 |
2126 |
2127 | Create a hex string from an array of bytes
2128 |
2129 |
2130 |
2131 |
2132 | Gets my local IP address (not necessarily external) and subnet mask
2133 |
2134 |
2135 |
2136 |
2137 | Returns true if the IPEndPoint supplied is on the same subnet as this host
2138 |
2139 |
2140 |
2141 |
2142 | Returns true if the IPAddress supplied is on the same subnet as this host
2143 |
2144 |
2145 |
2146 |
2147 | Returns how many bits are necessary to hold a certain number
2148 |
2149 |
2150 |
2151 |
2152 | Returns how many bytes are required to hold a certain number of bits
2153 |
2154 |
2155 |
2156 |
2157 | Convert a hexadecimal string to a byte array
2158 |
2159 |
2160 |
2161 |
2162 | Converts a number of bytes to a shorter, more readable string representation
2163 |
2164 |
2165 |
2166 |
2167 | Gets the window size used internally in the library for a certain delivery method
2168 |
2169 |
2170 |
2171 |
2172 | Result of a SendMessage call
2173 |
2174 |
2175 |
2176 |
2177 | Message failed to enqueue; for example if there's no connection in place
2178 |
2179 |
2180 |
2181 |
2182 | Message was immediately sent
2183 |
2184 |
2185 |
2186 |
2187 | Message was queued for delivery
2188 |
2189 |
2190 |
2191 |
2192 | Message was dropped immediately since too many message were queued
2193 |
2194 |
2195 |
2196 |
2197 | The type of a NetIncomingMessage
2198 |
2199 |
2200 |
2201 |
2202 | Error; this value should never appear
2203 |
2204 |
2205 |
2206 |
2207 | Status for a connection changed
2208 |
2209 |
2210 |
2211 |
2212 | Data sent using SendUnconnectedMessage
2213 |
2214 |
2215 |
2216 |
2217 | Connection approval is needed
2218 |
2219 |
2220 |
2221 |
2222 | Application data
2223 |
2224 |
2225 |
2226 |
2227 | Receipt of delivery
2228 |
2229 |
2230 |
2231 |
2232 | Discovery request for a response
2233 |
2234 |
2235 |
2236 |
2237 | Discovery response to a request
2238 |
2239 |
2240 |
2241 |
2242 | Verbose debug message
2243 |
2244 |
2245 |
2246 |
2247 | Debug message
2248 |
2249 |
2250 |
2251 |
2252 | Warning message
2253 |
2254 |
2255 |
2256 |
2257 | Error message
2258 |
2259 |
2260 |
2261 |
2262 | NAT introduction was successful
2263 |
2264 |
2265 |
2266 |
2267 | A roundtrip was measured and NetConnection.AverageRoundtripTime was updated
2268 |
2269 |
2270 |
2271 |
2272 | Status for a NetPeer instance
2273 |
2274 |
2275 |
2276 |
2277 | NetPeer is not running; socket is not bound
2278 |
2279 |
2280 |
2281 |
2282 | NetPeer is in the process of starting up
2283 |
2284 |
2285 |
2286 |
2287 | NetPeer is bound to socket and listening for packets
2288 |
2289 |
2290 |
2291 |
2292 | Shutdown has been requested and will be executed shortly
2293 |
2294 |
2295 |
2296 |
2297 | Sender part of Selective repeat ARQ for a particular NetChannel
2298 |
2299 |
2300 |
2301 |
2302 | DES encryption
2303 |
2304 |
2305 |
2306 |
2307 | NetDESEncryption constructor
2308 |
2309 |
2310 |
2311 |
2312 | NetDESEncryption constructor
2313 |
2314 |
2315 |
2316 |
2317 | NetDESEncryption constructor
2318 |
2319 |
2320 |
2321 |
2322 | Encrypt outgoing message
2323 |
2324 |
2325 |
2326 |
2327 | Decrypt incoming message
2328 |
2329 |
2330 |
2331 |
2332 |
--------------------------------------------------------------------------------
/Assets/Assemblies/Lidgren.Network.XML.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5841fe5da55158f47915c4d8a08c723e
3 |
--------------------------------------------------------------------------------
/Assets/Assemblies/Lidgren.Network.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/Assets/Assemblies/Lidgren.Network.dll
--------------------------------------------------------------------------------
/Assets/Assemblies/Lidgren.Network.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fb0efa7ddd3fa4c4aae7ed584c50aeed
3 | MonoAssemblyImporter:
4 | serializedVersion: 1
5 | iconMap: {}
6 | executionOrder: {}
7 |
--------------------------------------------------------------------------------
/Assets/Assemblies/Lidgren.Network.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/Assets/Assemblies/Lidgren.Network.pdb
--------------------------------------------------------------------------------
/Assets/Assemblies/Lidgren.Network.pdb.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e77ac304376d30f4da0dbfc3957f7fbe
3 |
--------------------------------------------------------------------------------
/Assets/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 489418391082d5d43a7f327d155de189
3 |
--------------------------------------------------------------------------------
/Assets/Materials/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e7c5fd35d577823408f84216d982b767
3 |
--------------------------------------------------------------------------------
/Assets/Materials/Materials/proto_blue.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 3
6 | m_ObjectHideFlags: 0
7 | m_PrefabParentObject: {fileID: 0}
8 | m_PrefabInternal: {fileID: 0}
9 | m_Name: proto_blue
10 | m_Shader: {fileID: 7, guid: 0000000000000000e000000000000000, type: 0}
11 | m_SavedProperties:
12 | serializedVersion: 2
13 | m_TexEnvs:
14 | data:
15 | first:
16 | name: _MainTex
17 | second:
18 | m_Texture: {fileID: 2800000, guid: 820cbf700cff7a94f975ee1e81bcfd8d, type: 1}
19 | m_Scale: {x: 10, y: 10}
20 | m_Offset: {x: 0, y: 0}
21 | m_Floats: {}
22 | m_Colors:
23 | data:
24 | first:
25 | name: _Color
26 | second: {r: 1, g: 1, b: 1, a: 1}
27 | --- !u!1002 &2100001
28 | EditorExtensionImpl:
29 | serializedVersion: 6
30 |
--------------------------------------------------------------------------------
/Assets/Materials/Materials/proto_blue.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 03e4dd0cafeef3449a2d8c689cc71795
3 |
--------------------------------------------------------------------------------
/Assets/Materials/Player.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 3
6 | m_ObjectHideFlags: 0
7 | m_PrefabParentObject: {fileID: 0}
8 | m_PrefabInternal: {fileID: 0}
9 | m_Name: Player
10 | m_Shader: {fileID: 7, guid: 0000000000000000e000000000000000, type: 0}
11 | m_SavedProperties:
12 | serializedVersion: 2
13 | m_TexEnvs:
14 | data:
15 | first:
16 | name: _MainTex
17 | second:
18 | m_Texture: {fileID: 2800000, guid: 820cbf700cff7a94f975ee1e81bcfd8d, type: 1}
19 | m_Scale: {x: 10, y: 10}
20 | m_Offset: {x: 0, y: 0}
21 | m_Floats: {}
22 | m_Colors:
23 | data:
24 | first:
25 | name: _Color
26 | second: {r: .300699234, g: 1, b: 0, a: 1}
27 | --- !u!1002 &2100001
28 | EditorExtensionImpl:
29 | serializedVersion: 6
30 |
--------------------------------------------------------------------------------
/Assets/Materials/Player.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a5a0b46ff739af34586f2dc499c7ac81
3 |
--------------------------------------------------------------------------------
/Assets/Materials/Target.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 3
6 | m_ObjectHideFlags: 0
7 | m_PrefabParentObject: {fileID: 0}
8 | m_PrefabInternal: {fileID: 0}
9 | m_Name: Target
10 | m_Shader: {fileID: 7, guid: 0000000000000000e000000000000000, type: 0}
11 | m_SavedProperties:
12 | serializedVersion: 2
13 | m_TexEnvs:
14 | data:
15 | first:
16 | name: _MainTex
17 | second:
18 | m_Texture: {fileID: 2800000, guid: 820cbf700cff7a94f975ee1e81bcfd8d, type: 1}
19 | m_Scale: {x: 10, y: 10}
20 | m_Offset: {x: 0, y: 0}
21 | m_Floats: {}
22 | m_Colors:
23 | data:
24 | first:
25 | name: _Color
26 | second: {r: 1, g: .265871406, b: 0, a: 1}
27 | --- !u!1002 &2100001
28 | EditorExtensionImpl:
29 | serializedVersion: 6
30 |
--------------------------------------------------------------------------------
/Assets/Materials/Target.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3eadc38d40fb3574092db708d4e41a19
3 |
--------------------------------------------------------------------------------
/Assets/Materials/proto_blue.tga:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/Assets/Materials/proto_blue.tga
--------------------------------------------------------------------------------
/Assets/Materials/proto_blue.tga.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 820cbf700cff7a94f975ee1e81bcfd8d
3 | TextureImporter:
4 | serializedVersion: 2
5 | mipmaps:
6 | mipMapMode: 0
7 | enableMipMap: 1
8 | linearTexture: 0
9 | correctGamma: 0
10 | fadeOut: 0
11 | borderMipMap: 0
12 | mipMapFadeDistanceStart: 1
13 | mipMapFadeDistanceEnd: 3
14 | bumpmap:
15 | convertToNormalMap: 0
16 | externalNormalMap: 0
17 | heightScale: .25
18 | normalMapFilter: 0
19 | isReadable: 0
20 | grayScaleToAlpha: 0
21 | generateCubemap: 0
22 | textureFormat: -1
23 | maxTextureSize: 1024
24 | textureSettings:
25 | filterMode: -1
26 | aniso: -1
27 | mipBias: -1
28 | wrapMode: -1
29 | nPOTScale: 1
30 | lightmap: 0
31 | compressionQuality: 50
32 | textureType: -1
33 | buildTargetSettings: []
34 |
--------------------------------------------------------------------------------
/Assets/Resources.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3955387f0e35fea409b35146ac95e67c
3 |
--------------------------------------------------------------------------------
/Assets/Resources/Player.prefab:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1 &100000
4 | GameObject:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 100100000}
8 | serializedVersion: 3
9 | m_Component:
10 | - 4: {fileID: 400000}
11 | - 33: {fileID: 3300000}
12 | - 23: {fileID: 2300000}
13 | - 114: {fileID: 11400004}
14 | - 114: {fileID: 11400002}
15 | - 114: {fileID: 11400000}
16 | - 65: {fileID: 6500000}
17 | - 54: {fileID: 5400000}
18 | m_Layer: 0
19 | m_Name: Player
20 | m_TagString: Untagged
21 | m_Icon: {fileID: 0}
22 | m_NavMeshLayer: 0
23 | m_StaticEditorFlags: 0
24 | m_IsActive: 0
25 | --- !u!1002 &100001
26 | EditorExtensionImpl:
27 | serializedVersion: 6
28 | --- !u!4 &400000
29 | Transform:
30 | m_ObjectHideFlags: 1
31 | m_PrefabParentObject: {fileID: 0}
32 | m_PrefabInternal: {fileID: 100100000}
33 | m_GameObject: {fileID: 100000}
34 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
35 | m_LocalPosition: {x: 0, y: 1, z: 0}
36 | m_LocalScale: {x: 2, y: .5, z: 3}
37 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
38 | m_Children: []
39 | m_Father: {fileID: 0}
40 | --- !u!1002 &400001
41 | EditorExtensionImpl:
42 | serializedVersion: 6
43 | --- !u!23 &2300000
44 | Renderer:
45 | m_ObjectHideFlags: 1
46 | m_PrefabParentObject: {fileID: 0}
47 | m_PrefabInternal: {fileID: 100100000}
48 | m_GameObject: {fileID: 100000}
49 | m_Enabled: 1
50 | m_CastShadows: 1
51 | m_ReceiveShadows: 1
52 | m_LightmapIndex: 255
53 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
54 | m_Materials:
55 | - {fileID: 2100000, guid: a5a0b46ff739af34586f2dc499c7ac81, type: 2}
56 | m_SubsetIndices:
57 | m_StaticBatchRoot: {fileID: 0}
58 | m_UseLightProbes: 0
59 | m_LightProbeAnchor: {fileID: 0}
60 | m_ScaleInLightmap: 1
61 | --- !u!1002 &2300001
62 | EditorExtensionImpl:
63 | serializedVersion: 6
64 | --- !u!33 &3300000
65 | MeshFilter:
66 | m_ObjectHideFlags: 1
67 | m_PrefabParentObject: {fileID: 0}
68 | m_PrefabInternal: {fileID: 100100000}
69 | m_GameObject: {fileID: 100000}
70 | m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
71 | --- !u!1002 &3300001
72 | EditorExtensionImpl:
73 | serializedVersion: 6
74 | --- !u!54 &5400000
75 | Rigidbody:
76 | m_ObjectHideFlags: 1
77 | m_PrefabParentObject: {fileID: 0}
78 | m_PrefabInternal: {fileID: 100100000}
79 | m_GameObject: {fileID: 100000}
80 | serializedVersion: 2
81 | m_Mass: 1
82 | m_Drag: 5
83 | m_AngularDrag: 2.5
84 | m_UseGravity: 0
85 | m_IsKinematic: 0
86 | m_Interpolate: 0
87 | m_Constraints: 84
88 | m_CollisionDetection: 1
89 | --- !u!1002 &5400001
90 | EditorExtensionImpl:
91 | serializedVersion: 6
92 | --- !u!65 &6500000
93 | BoxCollider:
94 | m_ObjectHideFlags: 1
95 | m_PrefabParentObject: {fileID: 0}
96 | m_PrefabInternal: {fileID: 100100000}
97 | m_GameObject: {fileID: 100000}
98 | m_Material: {fileID: 0}
99 | m_IsTrigger: 0
100 | m_Enabled: 1
101 | serializedVersion: 2
102 | m_Size: {x: 1, y: 1, z: 1}
103 | m_Center: {x: 0, y: 0, z: 0}
104 | --- !u!1002 &6500001
105 | EditorExtensionImpl:
106 | serializedVersion: 6
107 | --- !u!114 &11400000
108 | MonoBehaviour:
109 | m_ObjectHideFlags: 1
110 | m_PrefabParentObject: {fileID: 0}
111 | m_PrefabInternal: {fileID: 100100000}
112 | m_GameObject: {fileID: 100000}
113 | m_Enabled: 1
114 | m_EditorHideFlags: 0
115 | m_Script: {fileID: 11500000, guid: ada15181318091f499db5164be42d4e7, type: 1}
116 | m_Name:
117 | net_actor: {fileID: 0}
118 | --- !u!1002 &11400001
119 | EditorExtensionImpl:
120 | serializedVersion: 6
121 | --- !u!114 &11400002
122 | MonoBehaviour:
123 | m_ObjectHideFlags: 1
124 | m_PrefabParentObject: {fileID: 0}
125 | m_PrefabInternal: {fileID: 100100000}
126 | m_GameObject: {fileID: 100000}
127 | m_Enabled: 1
128 | m_EditorHideFlags: 0
129 | m_Script: {fileID: 11500000, guid: 30e860830c8112648aa58bbf4934556c, type: 1}
130 | m_Name:
131 | net_actor: {fileID: 0}
132 | --- !u!1002 &11400003
133 | EditorExtensionImpl:
134 | serializedVersion: 6
135 | --- !u!114 &11400004
136 | MonoBehaviour:
137 | m_ObjectHideFlags: 1
138 | m_PrefabParentObject: {fileID: 0}
139 | m_PrefabInternal: {fileID: 100100000}
140 | m_GameObject: {fileID: 100000}
141 | m_Enabled: 1
142 | m_EditorHideFlags: 0
143 | m_Script: {fileID: 11500000, guid: bf328010b03e1cb49a5394695d8e4daf, type: 1}
144 | m_Name:
145 | host_id: 0
146 | actor_id: 0
147 | is_owner: 0
148 | prefab_name:
149 | --- !u!1002 &11400005
150 | EditorExtensionImpl:
151 | serializedVersion: 6
152 | --- !u!1001 &100100000
153 | Prefab:
154 | m_ObjectHideFlags: 1
155 | serializedVersion: 2
156 | m_Modification:
157 | m_TransformParent: {fileID: 0}
158 | m_Modifications: []
159 | m_RemovedComponents: []
160 | m_ParentPrefab: {fileID: 0}
161 | m_RootGameObject: {fileID: 100000}
162 | m_IsPrefabParent: 1
163 | m_IsExploded: 1
164 | --- !u!1002 &100100001
165 | EditorExtensionImpl:
166 | serializedVersion: 6
167 |
--------------------------------------------------------------------------------
/Assets/Resources/Player.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2746c04b52dfd584a84c745427e6e274
3 |
--------------------------------------------------------------------------------
/Assets/Resources/Target.prefab:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1 &100000
4 | GameObject:
5 | m_ObjectHideFlags: 0
6 | m_PrefabParentObject: {fileID: 0}
7 | m_PrefabInternal: {fileID: 100100000}
8 | serializedVersion: 3
9 | m_Component:
10 | - 4: {fileID: 400000}
11 | - 33: {fileID: 3300000}
12 | - 23: {fileID: 2300000}
13 | m_Layer: 0
14 | m_Name: Target
15 | m_TagString: Untagged
16 | m_Icon: {fileID: 0}
17 | m_NavMeshLayer: 0
18 | m_StaticEditorFlags: 0
19 | m_IsActive: 0
20 | --- !u!1002 &100001
21 | EditorExtensionImpl:
22 | serializedVersion: 6
23 | --- !u!4 &400000
24 | Transform:
25 | m_ObjectHideFlags: 1
26 | m_PrefabParentObject: {fileID: 0}
27 | m_PrefabInternal: {fileID: 100100000}
28 | m_GameObject: {fileID: 100000}
29 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
30 | m_LocalPosition: {x: -4.57878256, y: 5.45138741, z: -5.82492542}
31 | m_LocalScale: {x: 1, y: 1, z: 1}
32 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
33 | m_Children: []
34 | m_Father: {fileID: 0}
35 | --- !u!1002 &400001
36 | EditorExtensionImpl:
37 | serializedVersion: 6
38 | --- !u!23 &2300000
39 | Renderer:
40 | m_ObjectHideFlags: 1
41 | m_PrefabParentObject: {fileID: 0}
42 | m_PrefabInternal: {fileID: 100100000}
43 | m_GameObject: {fileID: 100000}
44 | m_Enabled: 1
45 | m_CastShadows: 1
46 | m_ReceiveShadows: 1
47 | m_LightmapIndex: 255
48 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
49 | m_Materials:
50 | - {fileID: 2100000, guid: 3eadc38d40fb3574092db708d4e41a19, type: 2}
51 | m_SubsetIndices:
52 | m_StaticBatchRoot: {fileID: 0}
53 | m_UseLightProbes: 0
54 | m_LightProbeAnchor: {fileID: 0}
55 | m_ScaleInLightmap: 1
56 | --- !u!1002 &2300001
57 | EditorExtensionImpl:
58 | serializedVersion: 6
59 | --- !u!33 &3300000
60 | MeshFilter:
61 | m_ObjectHideFlags: 1
62 | m_PrefabParentObject: {fileID: 0}
63 | m_PrefabInternal: {fileID: 100100000}
64 | m_GameObject: {fileID: 100000}
65 | m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
66 | --- !u!1002 &3300001
67 | EditorExtensionImpl:
68 | serializedVersion: 6
69 | --- !u!1001 &100100000
70 | Prefab:
71 | m_ObjectHideFlags: 1
72 | serializedVersion: 2
73 | m_Modification:
74 | m_TransformParent: {fileID: 0}
75 | m_Modifications: []
76 | m_RemovedComponents: []
77 | m_ParentPrefab: {fileID: 0}
78 | m_RootGameObject: {fileID: 100000}
79 | m_IsPrefabParent: 1
80 | m_IsExploded: 1
81 | --- !u!1002 &100100001
82 | EditorExtensionImpl:
83 | serializedVersion: 6
84 |
--------------------------------------------------------------------------------
/Assets/Resources/Target.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0bbe60fd7ad851945928a8851434b30c
3 |
--------------------------------------------------------------------------------
/Assets/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 34b4da7f3931e294998e67ff12c23e0a
3 |
--------------------------------------------------------------------------------
/Assets/Scenes/Example.unity:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!29 &1
4 | Scene:
5 | m_ObjectHideFlags: 0
6 | m_PVSData:
7 | m_QueryMode: 1
8 | m_PVSObjectsArray: []
9 | m_PVSPortalsArray: []
10 | m_OcclusionBakeSettings:
11 | viewCellSize: 1
12 | bakeMode: 2
13 | memoryUsage: 10485760
14 | --- !u!104 &2
15 | RenderSettings:
16 | m_Fog: 0
17 | m_FogColor: {r: .5, g: .5, b: .5, a: 1}
18 | m_FogMode: 3
19 | m_FogDensity: .00999999978
20 | m_LinearFogStart: 0
21 | m_LinearFogEnd: 300
22 | m_AmbientLight: {r: .200000003, g: .200000003, b: .200000003, a: 1}
23 | m_SkyboxMaterial: {fileID: 0}
24 | m_HaloStrength: .5
25 | m_FlareStrength: 1
26 | m_HaloTexture: {fileID: 0}
27 | m_SpotCookie: {fileID: 0}
28 | m_ObjectHideFlags: 0
29 | --- !u!127 &3
30 | GameManager:
31 | m_ObjectHideFlags: 0
32 | --- !u!157 &4
33 | LightmapSettings:
34 | m_ObjectHideFlags: 0
35 | m_LightProbes: {fileID: 0}
36 | m_Lightmaps: []
37 | m_LightmapsMode: 1
38 | m_BakedColorSpace: 0
39 | m_UseDualLightmapsInForward: 0
40 | m_LightmapEditorSettings:
41 | m_Resolution: 50
42 | m_LastUsedResolution: 0
43 | m_TextureWidth: 1024
44 | m_TextureHeight: 1024
45 | m_BounceBoost: 1
46 | m_BounceIntensity: 1
47 | m_SkyLightColor: {r: .860000014, g: .930000007, b: 1, a: 1}
48 | m_SkyLightIntensity: 0
49 | m_Quality: 0
50 | m_Bounces: 1
51 | m_FinalGatherRays: 1000
52 | m_FinalGatherContrastThreshold: .0500000007
53 | m_FinalGatherGradientThreshold: 0
54 | m_FinalGatherInterpolationPoints: 15
55 | m_AOAmount: 0
56 | m_AOMaxDistance: .100000001
57 | m_AOContrast: 1
58 | m_LODSurfaceMappingDistance: 1
59 | m_Padding: 0
60 | m_TextureCompression: 0
61 | m_LockAtlas: 0
62 | --- !u!1 &5
63 | GameObject:
64 | m_ObjectHideFlags: 0
65 | m_PrefabParentObject: {fileID: 0}
66 | m_PrefabInternal: {fileID: 0}
67 | serializedVersion: 3
68 | m_Component:
69 | - 4: {fileID: 12}
70 | - 33: {fileID: 23}
71 | - 65: {fileID: 27}
72 | - 23: {fileID: 20}
73 | m_Layer: 0
74 | m_Name: Cube
75 | m_TagString: Untagged
76 | m_Icon: {fileID: 0}
77 | m_NavMeshLayer: 0
78 | m_StaticEditorFlags: 0
79 | m_IsActive: 1
80 | --- !u!1 &6
81 | GameObject:
82 | m_ObjectHideFlags: 0
83 | m_PrefabParentObject: {fileID: 0}
84 | m_PrefabInternal: {fileID: 0}
85 | serializedVersion: 3
86 | m_Component:
87 | - 4: {fileID: 13}
88 | - 33: {fileID: 24}
89 | - 23: {fileID: 21}
90 | m_Layer: 0
91 | m_Name: Cube
92 | m_TagString: Untagged
93 | m_Icon: {fileID: 0}
94 | m_NavMeshLayer: 0
95 | m_StaticEditorFlags: 0
96 | m_IsActive: 1
97 | --- !u!1 &7
98 | GameObject:
99 | m_ObjectHideFlags: 0
100 | m_PrefabParentObject: {fileID: 0}
101 | m_PrefabInternal: {fileID: 0}
102 | serializedVersion: 3
103 | m_Component:
104 | - 4: {fileID: 14}
105 | m_Layer: 0
106 | m_Name: Respawn
107 | m_TagString: Respawn
108 | m_Icon: {fileID: 0}
109 | m_NavMeshLayer: 0
110 | m_StaticEditorFlags: 0
111 | m_IsActive: 1
112 | --- !u!1 &8
113 | GameObject:
114 | m_ObjectHideFlags: 0
115 | m_PrefabParentObject: {fileID: 0}
116 | m_PrefabInternal: {fileID: 0}
117 | serializedVersion: 3
118 | m_Component:
119 | - 4: {fileID: 15}
120 | - 108: {fileID: 30}
121 | m_Layer: 0
122 | m_Name: Directional light
123 | m_TagString: Untagged
124 | m_Icon: {fileID: 0}
125 | m_NavMeshLayer: 0
126 | m_StaticEditorFlags: 0
127 | m_IsActive: 1
128 | --- !u!1 &9
129 | GameObject:
130 | m_ObjectHideFlags: 0
131 | m_PrefabParentObject: {fileID: 0}
132 | m_PrefabInternal: {fileID: 0}
133 | serializedVersion: 3
134 | m_Component:
135 | - 4: {fileID: 16}
136 | - 33: {fileID: 25}
137 | - 64: {fileID: 26}
138 | - 23: {fileID: 22}
139 | m_Layer: 0
140 | m_Name: Plane
141 | m_TagString: Untagged
142 | m_Icon: {fileID: 0}
143 | m_NavMeshLayer: 0
144 | m_StaticEditorFlags: 0
145 | m_IsActive: 1
146 | --- !u!1 &10
147 | GameObject:
148 | m_ObjectHideFlags: 0
149 | m_PrefabParentObject: {fileID: 0}
150 | m_PrefabInternal: {fileID: 0}
151 | serializedVersion: 3
152 | m_Component:
153 | - 4: {fileID: 17}
154 | - 114: {fileID: 35}
155 | - 114: {fileID: 34}
156 | - 114: {fileID: 33}
157 | m_Layer: 0
158 | m_Name: Network
159 | m_TagString: Untagged
160 | m_Icon: {fileID: 0}
161 | m_NavMeshLayer: 0
162 | m_StaticEditorFlags: 0
163 | m_IsActive: 1
164 | --- !u!1 &11
165 | GameObject:
166 | m_ObjectHideFlags: 0
167 | m_PrefabParentObject: {fileID: 0}
168 | m_PrefabInternal: {fileID: 0}
169 | serializedVersion: 3
170 | m_Component:
171 | - 4: {fileID: 18}
172 | - 20: {fileID: 19}
173 | - 92: {fileID: 29}
174 | - 124: {fileID: 31}
175 | - 81: {fileID: 28}
176 | - 114: {fileID: 32}
177 | m_Layer: 0
178 | m_Name: Main Camera
179 | m_TagString: MainCamera
180 | m_Icon: {fileID: 0}
181 | m_NavMeshLayer: 0
182 | m_StaticEditorFlags: 0
183 | m_IsActive: 1
184 | --- !u!4 &12
185 | Transform:
186 | m_ObjectHideFlags: 0
187 | m_PrefabParentObject: {fileID: 0}
188 | m_PrefabInternal: {fileID: 0}
189 | m_GameObject: {fileID: 5}
190 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
191 | m_LocalPosition: {x: -10.8461361, y: 1.66418743, z: 1.16474915}
192 | m_LocalScale: {x: 4.25980282, y: 4.25980282, z: 4.25980282}
193 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
194 | m_Children: []
195 | m_Father: {fileID: 0}
196 | --- !u!4 &13
197 | Transform:
198 | m_ObjectHideFlags: 0
199 | m_PrefabParentObject: {fileID: 0}
200 | m_PrefabInternal: {fileID: 0}
201 | m_GameObject: {fileID: 6}
202 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
203 | m_LocalPosition: {x: 0, y: 5, z: 0}
204 | m_LocalScale: {x: .100000001, y: 10, z: .100000001}
205 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
206 | m_Children: []
207 | m_Father: {fileID: 14}
208 | --- !u!4 &14
209 | Transform:
210 | m_ObjectHideFlags: 0
211 | m_PrefabParentObject: {fileID: 0}
212 | m_PrefabInternal: {fileID: 0}
213 | m_GameObject: {fileID: 7}
214 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
215 | m_LocalPosition: {x: 0, y: 1, z: 0}
216 | m_LocalScale: {x: 1, y: 1, z: 1}
217 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
218 | m_Children:
219 | - {fileID: 13}
220 | m_Father: {fileID: 0}
221 | --- !u!4 &15
222 | Transform:
223 | m_ObjectHideFlags: 0
224 | m_PrefabParentObject: {fileID: 0}
225 | m_PrefabInternal: {fileID: 0}
226 | m_GameObject: {fileID: 8}
227 | m_LocalRotation: {x: .161521539, y: 0, z: 0, w: .986869276}
228 | m_LocalPosition: {x: -14.5156851, y: 9.58809757, z: 1.09368014}
229 | m_LocalScale: {x: 1, y: 1, z: 1}
230 | m_LocalEulerAnglesHint: {x: 18.5904388, y: 0, z: 0}
231 | m_Children: []
232 | m_Father: {fileID: 0}
233 | --- !u!4 &16
234 | Transform:
235 | m_ObjectHideFlags: 0
236 | m_PrefabParentObject: {fileID: 0}
237 | m_PrefabInternal: {fileID: 0}
238 | m_GameObject: {fileID: 9}
239 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
240 | m_LocalPosition: {x: 0, y: 0, z: 0}
241 | m_LocalScale: {x: 10, y: 10, z: 10}
242 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
243 | m_Children: []
244 | m_Father: {fileID: 0}
245 | --- !u!4 &17
246 | Transform:
247 | m_ObjectHideFlags: 0
248 | m_PrefabParentObject: {fileID: 0}
249 | m_PrefabInternal: {fileID: 0}
250 | m_GameObject: {fileID: 10}
251 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
252 | m_LocalPosition: {x: 0, y: 0, z: 0}
253 | m_LocalScale: {x: 1, y: 1, z: 1}
254 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
255 | m_Children: []
256 | m_Father: {fileID: 0}
257 | --- !u!4 &18
258 | Transform:
259 | m_ObjectHideFlags: 0
260 | m_PrefabParentObject: {fileID: 0}
261 | m_PrefabInternal: {fileID: 0}
262 | m_GameObject: {fileID: 11}
263 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
264 | m_LocalPosition: {x: 0, y: .5, z: -5}
265 | m_LocalScale: {x: 1, y: 1, z: 1}
266 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
267 | m_Children: []
268 | m_Father: {fileID: 0}
269 | --- !u!20 &19
270 | Camera:
271 | m_ObjectHideFlags: 0
272 | m_PrefabParentObject: {fileID: 0}
273 | m_PrefabInternal: {fileID: 0}
274 | m_GameObject: {fileID: 11}
275 | m_Enabled: 1
276 | serializedVersion: 2
277 | m_ClearFlags: 1
278 | m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
279 | m_NormalizedViewPortRect:
280 | serializedVersion: 2
281 | x: 0
282 | y: 0
283 | width: 1
284 | height: 1
285 | near clip plane: .300000012
286 | far clip plane: 1000
287 | field of view: 60
288 | orthographic: 0
289 | orthographic size: 100
290 | m_Depth: -1
291 | m_CullingMask:
292 | serializedVersion: 2
293 | m_Bits: 4294967295
294 | m_RenderingPath: -1
295 | m_TargetTexture: {fileID: 0}
296 | m_HDR: 0
297 | --- !u!23 &20
298 | Renderer:
299 | m_ObjectHideFlags: 0
300 | m_PrefabParentObject: {fileID: 0}
301 | m_PrefabInternal: {fileID: 0}
302 | m_GameObject: {fileID: 5}
303 | m_Enabled: 1
304 | m_CastShadows: 1
305 | m_ReceiveShadows: 1
306 | m_LightmapIndex: 255
307 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
308 | m_Materials:
309 | - {fileID: 10302, guid: 0000000000000000e000000000000000, type: 0}
310 | m_SubsetIndices:
311 | m_StaticBatchRoot: {fileID: 0}
312 | m_UseLightProbes: 0
313 | m_LightProbeAnchor: {fileID: 0}
314 | m_ScaleInLightmap: 1
315 | --- !u!23 &21
316 | Renderer:
317 | m_ObjectHideFlags: 0
318 | m_PrefabParentObject: {fileID: 0}
319 | m_PrefabInternal: {fileID: 0}
320 | m_GameObject: {fileID: 6}
321 | m_Enabled: 1
322 | m_CastShadows: 1
323 | m_ReceiveShadows: 1
324 | m_LightmapIndex: 255
325 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
326 | m_Materials:
327 | - {fileID: 10302, guid: 0000000000000000e000000000000000, type: 0}
328 | m_SubsetIndices:
329 | m_StaticBatchRoot: {fileID: 0}
330 | m_UseLightProbes: 0
331 | m_LightProbeAnchor: {fileID: 0}
332 | m_ScaleInLightmap: 1
333 | --- !u!23 &22
334 | Renderer:
335 | m_ObjectHideFlags: 0
336 | m_PrefabParentObject: {fileID: 0}
337 | m_PrefabInternal: {fileID: 0}
338 | m_GameObject: {fileID: 9}
339 | m_Enabled: 1
340 | m_CastShadows: 1
341 | m_ReceiveShadows: 1
342 | m_LightmapIndex: 255
343 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
344 | m_Materials:
345 | - {fileID: 2100000, guid: 03e4dd0cafeef3449a2d8c689cc71795, type: 2}
346 | m_SubsetIndices:
347 | m_StaticBatchRoot: {fileID: 0}
348 | m_UseLightProbes: 0
349 | m_LightProbeAnchor: {fileID: 0}
350 | m_ScaleInLightmap: 1
351 | --- !u!33 &23
352 | MeshFilter:
353 | m_ObjectHideFlags: 0
354 | m_PrefabParentObject: {fileID: 0}
355 | m_PrefabInternal: {fileID: 0}
356 | m_GameObject: {fileID: 5}
357 | m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
358 | --- !u!33 &24
359 | MeshFilter:
360 | m_ObjectHideFlags: 0
361 | m_PrefabParentObject: {fileID: 0}
362 | m_PrefabInternal: {fileID: 0}
363 | m_GameObject: {fileID: 6}
364 | m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
365 | --- !u!33 &25
366 | MeshFilter:
367 | m_ObjectHideFlags: 0
368 | m_PrefabParentObject: {fileID: 0}
369 | m_PrefabInternal: {fileID: 0}
370 | m_GameObject: {fileID: 9}
371 | m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
372 | --- !u!64 &26
373 | MeshCollider:
374 | m_ObjectHideFlags: 0
375 | m_PrefabParentObject: {fileID: 0}
376 | m_PrefabInternal: {fileID: 0}
377 | m_GameObject: {fileID: 9}
378 | m_Material: {fileID: 0}
379 | m_IsTrigger: 0
380 | m_Enabled: 1
381 | serializedVersion: 2
382 | m_SmoothSphereCollisions: 0
383 | m_Convex: 0
384 | m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
385 | --- !u!65 &27
386 | BoxCollider:
387 | m_ObjectHideFlags: 0
388 | m_PrefabParentObject: {fileID: 0}
389 | m_PrefabInternal: {fileID: 0}
390 | m_GameObject: {fileID: 5}
391 | m_Material: {fileID: 0}
392 | m_IsTrigger: 0
393 | m_Enabled: 1
394 | serializedVersion: 2
395 | m_Size: {x: 1, y: 1, z: 1}
396 | m_Center: {x: 0, y: 0, z: 0}
397 | --- !u!81 &28
398 | AudioListener:
399 | m_ObjectHideFlags: 0
400 | m_PrefabParentObject: {fileID: 0}
401 | m_PrefabInternal: {fileID: 0}
402 | m_GameObject: {fileID: 11}
403 | m_Enabled: 1
404 | --- !u!92 &29
405 | Behaviour:
406 | m_ObjectHideFlags: 0
407 | m_PrefabParentObject: {fileID: 0}
408 | m_PrefabInternal: {fileID: 0}
409 | m_GameObject: {fileID: 11}
410 | m_Enabled: 1
411 | --- !u!108 &30
412 | Light:
413 | m_ObjectHideFlags: 0
414 | m_PrefabParentObject: {fileID: 0}
415 | m_PrefabInternal: {fileID: 0}
416 | m_GameObject: {fileID: 8}
417 | m_Enabled: 1
418 | serializedVersion: 3
419 | m_Type: 1
420 | m_Color: {r: 1, g: 1, b: 1, a: 1}
421 | m_Intensity: .5
422 | m_Range: 10
423 | m_SpotAngle: 30
424 | m_CookieSize: 10
425 | m_Shadows:
426 | m_Type: 0
427 | m_Resolution: -1
428 | m_Strength: 1
429 | m_Bias: .0500000007
430 | m_Softness: 4
431 | m_SoftnessFade: 1
432 | m_Cookie: {fileID: 0}
433 | m_DrawHalo: 0
434 | m_ActuallyLightmapped: 0
435 | m_Flare: {fileID: 0}
436 | m_RenderMode: 0
437 | m_CullingMask:
438 | serializedVersion: 2
439 | m_Bits: 4294967295
440 | m_Lightmapping: 1
441 | m_ShadowSamples: 1
442 | m_ShadowRadius: 0
443 | m_ShadowAngle: 0
444 | m_IndirectIntensity: 1
445 | m_AreaSize: {x: 1, y: 1}
446 | --- !u!124 &31
447 | Behaviour:
448 | m_ObjectHideFlags: 0
449 | m_PrefabParentObject: {fileID: 0}
450 | m_PrefabInternal: {fileID: 0}
451 | m_GameObject: {fileID: 11}
452 | m_Enabled: 1
453 | --- !u!114 &32
454 | MonoBehaviour:
455 | m_ObjectHideFlags: 0
456 | m_PrefabParentObject: {fileID: 0}
457 | m_PrefabInternal: {fileID: 0}
458 | m_GameObject: {fileID: 11}
459 | m_Enabled: 1
460 | m_EditorHideFlags: 0
461 | m_Script: {fileID: 11500000, guid: bb0a2d3379da8c24bbc6b36e8ffbb0da, type: 1}
462 | m_Name:
463 | Target: {fileID: 0}
464 | --- !u!114 &33
465 | MonoBehaviour:
466 | m_ObjectHideFlags: 0
467 | m_PrefabParentObject: {fileID: 0}
468 | m_PrefabInternal: {fileID: 0}
469 | m_GameObject: {fileID: 10}
470 | m_Enabled: 1
471 | m_EditorHideFlags: 0
472 | m_Script: {fileID: 11500000, guid: 458593095d801bc488139c82f06f6e1b, type: 1}
473 | m_Name:
474 | --- !u!114 &34
475 | MonoBehaviour:
476 | m_ObjectHideFlags: 0
477 | m_PrefabParentObject: {fileID: 0}
478 | m_PrefabInternal: {fileID: 0}
479 | m_GameObject: {fileID: 10}
480 | m_Enabled: 0
481 | m_EditorHideFlags: 0
482 | m_Script: {fileID: 11500000, guid: 199a6c3a9ecf93e4e930be89da986e37, type: 1}
483 | m_Name:
484 | --- !u!114 &35
485 | MonoBehaviour:
486 | m_ObjectHideFlags: 0
487 | m_PrefabParentObject: {fileID: 0}
488 | m_PrefabInternal: {fileID: 0}
489 | m_GameObject: {fileID: 10}
490 | m_Enabled: 0
491 | m_EditorHideFlags: 0
492 | m_Script: {fileID: 11500000, guid: 8569878d8cc6d32498d083ad909a0b7b, type: 1}
493 | m_Name:
494 | --- !u!196 &36
495 | NavMeshSettings:
496 | m_ObjectHideFlags: 0
497 | m_BuildSettings:
498 | agentRadius: .5
499 | agentHeight: 2
500 | agentSlope: 45
501 | agentClimb: .400000006
502 | ledgeDropHeight: 0
503 | maxJumpAcrossDistance: 0
504 | accuratePlacement: 0
505 | minRegionArea: 2
506 | widthInaccuracy: 16.666666
507 | heightInaccuracy: 10
508 | m_NavMesh: {fileID: 0}
509 |
--------------------------------------------------------------------------------
/Assets/Scenes/Example.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ff03af5deeda6b34886949fb2083f3a8
3 |
--------------------------------------------------------------------------------
/Assets/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: aca6f987321b1294d9d1b99bfea39961
3 |
--------------------------------------------------------------------------------
/Assets/Scripts/LocalCamera.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | public class LocalCamera : MonoBehaviour {
5 |
6 | [HideInInspector]
7 | public Transform Target;
8 |
9 | void LateUpdate () {
10 | if(Target != null) {
11 | transform.position = Target.position;
12 | transform.position += new Vector3(0, 20, -13);
13 | transform.LookAt(Target.position);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Assets/Scripts/LocalCamera.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bb0a2d3379da8c24bbc6b36e8ffbb0da
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/MathUtils.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | public class MathUtils {
5 | public static float AngledSigned(Vector3 v1, Vector3 v2, Vector3 n) {
6 | return Mathf.Atan2(Vector3.Dot(n, Vector3.Cross(v1, v2)), Vector3.Dot(v1, v2)) * Mathf.Rad2Deg;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/Assets/Scripts/MathUtils.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7d926d2bee5e7474fb544fa7e072efdc
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkActions.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System;
4 | using Lidgren.Network;
5 |
6 | public class NetworkActions : NetworkState {
7 |
8 | GameObject target;
9 |
10 | public override void Receive(NetIncomingMessage msg)
11 | {
12 |
13 | }
14 |
15 | public override void Send(NetOutgoingMessage msg)
16 | {
17 |
18 | }
19 |
20 | public override void Init()
21 | {
22 | target = (GameObject)GameObject.Instantiate(Resources.Load("Target"), Vector3.zero, Quaternion.identity);
23 | target.renderer.enabled = false;
24 | }
25 |
26 | public override void NetworkFixedUpdateClient()
27 | {
28 | if (!net_actor.is_owner && (UserInput.cmd.keystate & UserInput.FIRE) != 0)
29 | {
30 | SetTargetPosition();
31 | }
32 | }
33 |
34 | public override void NetworkFixedUpdateServer()
35 | {
36 | if (net_actor.owner.cmd_queue.Count > 0)
37 | {
38 | var cmd = net_actor.owner.cmd_queue.Peek();
39 |
40 | if ((cmd.keystate & UserInput.FIRE) != 0)
41 | {
42 | foreach (var actor in net_actor.owner.proximity_set)
43 | {
44 | if (actor != net_actor)
45 | {
46 | var f = actor.gameObject.GetComponent();
47 | var p = actor.gameObject.GetComponent();
48 |
49 | p.SetPosition(cmd.client_time - 0.1f);
50 | f.SetTargetPosition();
51 | p.SetPosition();
52 | }
53 | }
54 | }
55 | }
56 | }
57 |
58 | void SetTargetPosition()
59 | {
60 | target.transform.position = transform.position;
61 | target.transform.Translate(Vector3.up);
62 | target.renderer.enabled = true;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkActions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 30e860830c8112648aa58bbf4934556c
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkActor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using Lidgren.Network;
5 | using UnityEngine;
6 |
7 | public class NetworkActor : MonoBehaviour
8 | {
9 | public const int MaxId = UInt16.MaxValue;
10 |
11 | [HideInInspector]
12 | public byte host_id = 0;
13 |
14 | [HideInInspector]
15 | public int actor_id = 0;
16 |
17 | [HideInInspector]
18 | public NetworkClientInfo owner = null;
19 |
20 | [HideInInspector]
21 | public bool is_owner = false;
22 |
23 | [HideInInspector]
24 | public string prefab_name = null;
25 |
26 | List net_states = new List();
27 |
28 | public void Send(NetOutgoingMessage msg)
29 | {
30 | msg.Write(actor_id);
31 |
32 | for (var i = 0; i < net_states.Count; ++i)
33 | {
34 | net_states[i].Send(msg);
35 | }
36 | }
37 |
38 | public void Receive(NetIncomingMessage msg)
39 | {
40 | for (var i = 0; i < net_states.Count; ++i)
41 | {
42 | net_states[i].Receive(msg);
43 | }
44 | }
45 |
46 | public void NetworkFixedUpdate()
47 | {
48 | for (var i = 0; i < net_states.Count; ++i)
49 | {
50 | if (NetworkPeer.is_server)
51 | {
52 | net_states[i].NetworkFixedUpdateServer();
53 | }
54 | else
55 | {
56 | net_states[i].NetworkFixedUpdateClient();
57 | }
58 | }
59 | }
60 |
61 | public override int GetHashCode()
62 | {
63 | return actor_id;
64 | }
65 |
66 | public virtual void Init()
67 | {
68 |
69 | }
70 |
71 | void LocateAndSortScripts()
72 | {
73 | var components = GetComponents();
74 |
75 | for (var i = 0; i < components.Length; ++i)
76 | {
77 | var state = components[i];
78 | state.net_actor = this;
79 | state.Init();
80 | net_states.Add(state);
81 | }
82 |
83 | net_states.Sort(SortNetworkStates);
84 | }
85 |
86 | int SortNetworkStates(NetworkState x, NetworkState y)
87 | {
88 | if (System.Object.ReferenceEquals(x, y))
89 | return 0;
90 |
91 | var cmp = x.GetType().FullName.CompareTo(y.GetType().FullName);
92 | if (cmp == 0)
93 | {
94 | throw new Exception("Two instances of the same network state are attached to the same actor (" + x.GetType().FullName + " and " + y.GetType().FullName + ")");
95 | }
96 |
97 | return cmp;
98 | }
99 |
100 | void Start()
101 | {
102 | LocateAndSortScripts();
103 | NetworkActorRegistry.RegisterActor(this);
104 | Init();
105 | }
106 |
107 | void Update()
108 | {
109 | NetworkTime.Update();
110 |
111 | for (var i = 0; i < net_states.Count; ++i)
112 | {
113 | if (NetworkPeer.is_server)
114 | {
115 | net_states[i].NetworkUpdateServer();
116 | }
117 | else
118 | {
119 | net_states[i].NetworkUpdateClient();
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkActor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d61d9a776cba7734aa90bcaa42768538
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkActorRegistry.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using Lidgren.Network;
5 | using UnityEngine;
6 |
7 | public static class NetworkActorRegistry
8 | {
9 | public static NetworkActor[] Objects = new NetworkActor[256];
10 | public static int[] DeliveryMethods = new int[256];
11 | public static int MaxIndex = -1;
12 | public static int Count = 0;
13 |
14 | public static void RegisterActor(NetworkActor obj)
15 | {
16 | var index = obj.actor_id;
17 |
18 | if (index >= Objects.Length)
19 | {
20 | var size = Math.Min(Objects.Length * 2, NetworkActor.MaxId);
21 | var newObjects = new NetworkActor[size];
22 | Array.Copy(Objects, newObjects, Objects.Length);
23 | Objects = newObjects;
24 | }
25 |
26 | MaxIndex = Math.Max(MaxIndex, index);
27 | Objects[index] = obj;
28 | ++Count;
29 | }
30 |
31 | public static NetworkActor GetById(int id)
32 | {
33 | if (id < Objects.Length)
34 | {
35 | return Objects[id];
36 | }
37 |
38 | return null;
39 | }
40 |
41 | public static void UnregisterActor(NetworkActor obj)
42 | {
43 | Objects[obj.actor_id] = null;
44 | --Count;
45 | }
46 |
47 | public static void RegisterDeliveryMethod(NetDeliveryMethod deliveryMethod)
48 | {
49 | DeliveryMethods[(int)deliveryMethod]++;
50 | }
51 |
52 | public static void UnregisterDeliveryMethod(NetDeliveryMethod deliveryMethod)
53 | {
54 | DeliveryMethods[(int)deliveryMethod]--;
55 | }
56 |
57 | public static bool HasDeliveryMethod(NetDeliveryMethod deliveryMethod)
58 | {
59 | return DeliveryMethods[(int)deliveryMethod] > 0;
60 | }
61 | }
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkActorRegistry.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cac2c5698e1a1ef4f823fa6d0662f0d2
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Lidgren.Network;
6 | using UnityEngine;
7 |
8 | class NetworkClient : NetworkPeer
9 | {
10 | public const int SEND_RATE = 2;
11 | public const float SEND_TIME = 0.030f;
12 | public readonly NetClient net_client;
13 | public bool has_spawned;
14 |
15 | public float rtt
16 | {
17 | get
18 | {
19 | if (net_client == null || net_client.ServerConnection == null)
20 | return -1.0f;
21 |
22 | return net_client.ServerConnection.AverageRoundtripTime;
23 | }
24 | }
25 |
26 | public NetworkClient()
27 | : base(SEND_RATE)
28 | {
29 | instance = this;
30 | is_server = false;
31 | is_client = true;
32 |
33 | net_peer = net_client = new NetClient(CreateConfig());
34 | net_client.Start();
35 | net_client.Connect("127.0.0.1", NetworkPeer.APP_PORT);
36 | }
37 |
38 | [RPC]
39 | public void Hello(NetIncomingMessage msg, byte host_id)
40 | {
41 | this.host_id = host_id;
42 | NetworkRemoteCall.CallOnServer("RequestObjects");
43 | }
44 |
45 | [RPC]
46 | public void Spawn(NetIncomingMessage msg, byte hostId, int objectId, string prefabName, Vector3 pos, Quaternion rot)
47 | {
48 | var game_object = (GameObject)GameObject.Instantiate(Resources.Load(prefabName), pos, rot);
49 | var net_actor = game_object.GetComponent();
50 | net_actor.host_id = hostId;
51 | net_actor.actor_id = objectId;
52 | net_actor.is_owner = NetworkPeer.instance.host_id == hostId;
53 | net_actor.prefab_name = prefabName;
54 |
55 | NetworkRemoteCall.CallOnServer("RequestObjectRegistration", net_actor.actor_id);
56 | NetworkActorRegistry.RegisterActor(net_actor);
57 | }
58 |
59 | protected override void OnDataMessage(NetIncomingMessage msg)
60 | {
61 | // Update estimated local time
62 | NetworkTime.step = msg.ReadInt32();
63 | NetworkTime.SetOffset(NetworkTime.step / 66.66666666f, rtt);
64 |
65 | Debug.Log("local: " + NetworkTime.gameTime);
66 | Debug.Log("remote: " + (NetworkTime.step / 66.66666666f));
67 |
68 | // Read message flag
69 | switch (msg.ReadByte())
70 | {
71 | case NetworkPeer.REMOTE_CALL_FLAG:
72 | NetworkRemoteCallReceiver.ReceiveRemoteCall(msg);
73 | break;
74 |
75 | case NetworkPeer.ACTOR_EVENT_FLAG:
76 | ReceiveObjectState(msg);
77 | break;
78 | }
79 | }
80 |
81 | private void ReceiveObjectState(NetIncomingMessage msg)
82 | {
83 | while (msg.Position < msg.LengthBits)
84 | {
85 | var objectId = msg.ReadInt32();
86 | NetworkActorRegistry.GetById(objectId).Receive(msg);
87 | }
88 | }
89 |
90 | protected override void AfterSimulate()
91 | {
92 | if (has_spawned)
93 | {
94 | UserInput.QueueCurrent();
95 | }
96 | }
97 |
98 | protected override void BeforePump()
99 | {
100 | NetworkTime.Update();
101 |
102 | if (has_spawned)
103 | {
104 | UserInput.Read();
105 |
106 | if (ticks == send_rate)
107 | {
108 | SendCommands();
109 | }
110 | }
111 | }
112 |
113 | void SendCommands()
114 | {
115 | var msg = CreateMessage();
116 | msg.Write(NetworkPeer.USER_COMMAND_FLAG);
117 | msg.Write((byte)UserInput.unsent_cmds);
118 |
119 | for (var i = (UserInput.unsent_cmds - 1); i >= 0; --i)
120 | {
121 | var cmd = UserInput.cmd_buffer[i];
122 |
123 | msg.Write(cmd.commandid);
124 | msg.Write(cmd.keystate);
125 | msg.Write(cmd.actionstate);
126 | msg.Write(cmd.client_time);
127 | }
128 |
129 | UserInput.unsent_cmds = 0;
130 | net_client.SendMessage(msg, NetDeliveryMethod.UnreliableSequenced);
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkClient.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a9fdcb18f981f444e8b173dc18a3a487
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkClientBehaviour.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | class NetworkClientBehaviour : MonoBehaviour
4 | {
5 | public NetworkClient client;
6 |
7 | void Start()
8 | {
9 | client = new NetworkClient();
10 | }
11 |
12 | void FixedUpdate()
13 | {
14 | client.MessagePump();
15 | }
16 |
17 | public bool is_running
18 | {
19 | get
20 | {
21 | return enabled && client != null;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkClientBehaviour.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 199a6c3a9ecf93e4e930be89da986e37
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkClientInfo.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using Lidgren.Network;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | public class NetworkClientInfo
7 | {
8 | public const int CMD_BUFFER_SIZE = 20;
9 |
10 | public bool has_spawned;
11 | public readonly byte host_id = 0;
12 | public readonly NetConnection connection = null;
13 | public readonly HashSet proximity_set = new HashSet();
14 | public readonly Queue cmd_queue = new Queue();
15 |
16 | public NetworkClientInfo(byte id, NetConnection conn)
17 | {
18 | host_id = id;
19 | connection = conn;
20 | connection.Tag = this;
21 | }
22 |
23 | public bool has_cmd
24 | {
25 | get
26 | {
27 | return cmd_queue.Count > 0;
28 | }
29 | }
30 |
31 | public UserCommand cmd
32 | {
33 | get
34 | {
35 | return cmd_queue.Peek();
36 | }
37 | }
38 |
39 | public float rtt
40 | {
41 | get
42 | {
43 | return connection.AverageRoundtripTime;
44 | }
45 | }
46 |
47 | public override int GetHashCode()
48 | {
49 | return (int)host_id;
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkClientInfo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1695887238824964fa044bf47bccb513
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkController.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | public class NetworkController : MonoBehaviour
5 | {
6 | bool has_spawned = false;
7 |
8 | NetworkServerBehaviour srv;
9 | NetworkClientBehaviour clt;
10 |
11 | void Start()
12 | {
13 | srv = (NetworkServerBehaviour)gameObject.GetComponent(typeof(NetworkServerBehaviour));
14 | clt = (NetworkClientBehaviour)gameObject.GetComponent(typeof(NetworkClientBehaviour));
15 | }
16 |
17 | void OnGUI()
18 | {
19 | if (SystemInfo.graphicsDeviceID == 0)
20 | {
21 | srv.enabled = true;
22 | }
23 |
24 | if (!srv.is_running && !clt.is_running)
25 | {
26 | if (GUI.Button(new Rect(10, 10, 100, 25), "Start Server"))
27 | {
28 | srv.enabled = true;
29 | }
30 |
31 | if (GUI.Button(new Rect(10, 45, 100, 25), "Start Client"))
32 | {
33 | clt.enabled = true;
34 | }
35 | }
36 | else
37 | {
38 | GUI.TextArea(new Rect(300, 10, 150, 45), "Gametime: " + NetworkTime.gameTime);
39 | }
40 |
41 | if (srv.is_running)
42 | {
43 | GUI.TextArea(new Rect(10, 10, 125, 25), "Running As Server");
44 | GUI.TextArea(new Rect(10, 45, 125, 25), "Clients: " + srv.server.connected_clients.Count);
45 | }
46 |
47 | if (clt.is_running)
48 | {
49 | GUI.TextArea(new Rect(10, 10, 225, 25), "Running As Client (ping: " + Mathf.Round(clt.client.rtt * 1000.0f) + "ms)");
50 | GUI.TextArea(new Rect(10, 45, 225, 25), "Client Id: " + clt.client.host_id);
51 |
52 | if (!has_spawned && GUI.Button(new Rect(10, 80, 125, 25), "Spawn"))
53 | {
54 | has_spawned = true;
55 | var respawn = GameObject.FindGameObjectWithTag("Respawn");
56 | NetworkRemoteCall.CallOnServer("RequestSpawn", "Player", respawn.transform.position, Quaternion.identity);
57 | }
58 |
59 | if (has_spawned)
60 | {
61 | // Auto turn left
62 | if (GUI.Button(new Rect(10, 80, 25, 25), "Q"))
63 | {
64 | UserInput.auto_keys = (byte)(UserInput.auto_keys ^ UserInput.TURNLEFT);
65 | }
66 |
67 | // Auto walk forward
68 | if (GUI.Button(new Rect(40, 80, 25, 25), "W"))
69 | {
70 | UserInput.auto_keys = (byte)(UserInput.auto_keys ^ UserInput.FORWARD);
71 | }
72 |
73 | // Auto turn right
74 | if (GUI.Button(new Rect(70, 80, 25, 25), "E"))
75 | {
76 | UserInput.auto_keys = (byte)(UserInput.auto_keys ^ UserInput.TURNRIGHT);
77 | }
78 |
79 | // Auto walk backward
80 | if (GUI.Button(new Rect(40, 110, 25, 25), "S"))
81 | {
82 | UserInput.auto_keys = (byte)(UserInput.auto_keys ^ UserInput.BACKWARD);
83 | }
84 |
85 | // Auto walk left
86 | if (GUI.Button(new Rect(10, 110, 25, 25), "A"))
87 | {
88 | UserInput.auto_keys = (byte)(UserInput.auto_keys ^ UserInput.LEFT);
89 | }
90 |
91 | // Auto walk right
92 | if (GUI.Button(new Rect(70, 110, 25, 25), "D"))
93 | {
94 | UserInput.auto_keys = (byte)(UserInput.auto_keys ^ UserInput.RIGHT);
95 | }
96 |
97 | // Auto action 1
98 | if (GUI.Button(new Rect(10, 140, 25, 25), "1"))
99 | {
100 | UserInput.auto_actions = (byte)(UserInput.auto_actions ^ UserInput.ACTION1);
101 | }
102 |
103 | // Auto action 2
104 | if (GUI.Button(new Rect(40, 140, 25, 25), "2"))
105 | {
106 | UserInput.auto_actions = (byte)(UserInput.auto_actions ^ UserInput.ACTION2);
107 | }
108 |
109 | // Auto action 3
110 | if (GUI.Button(new Rect(70, 140, 25, 25), "3"))
111 | {
112 | UserInput.auto_actions = (byte)(UserInput.auto_actions ^ UserInput.ACTION3);
113 | }
114 |
115 | // Auto action 4
116 | if (GUI.Button(new Rect(100, 140, 25, 25), "4"))
117 | {
118 | UserInput.auto_actions = (byte)(UserInput.auto_actions ^ UserInput.ACTION4);
119 | }
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 458593095d801bc488139c82f06f6e1b
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkPeer.cs:
--------------------------------------------------------------------------------
1 | using Lidgren.Network;
2 | using UnityEngine;
3 |
4 | public abstract class NetworkPeer
5 | {
6 | // Message flags
7 | public const byte REMOTE_CALL_FLAG = 0;
8 | public const byte USER_COMMAND_FLAG = 1;
9 | public const byte ACTOR_STATE_FLAG = 2;
10 | public const byte ACTOR_EVENT_FLAG = 3;
11 |
12 | // Tick options
13 | public const float TICK_TIME = 0.015f;
14 |
15 | // Configuration options
16 | public const int APP_PORT = 14000;
17 | public const string APP_IDENTIFIER = "mobax";
18 | public const float SIMULATED_LOSS = 0.0f;
19 | public const float SIMULATED_MIN_LATENCY = 0.0f;
20 | public const float SIMULATDE_RANDOM_LATENCY = 0.0f;
21 |
22 | // Static variables
23 | public static bool is_server;
24 | public static bool is_client;
25 | public static NetworkPeer instance;
26 |
27 | // Instance variables
28 | public byte host_id;
29 | public NetPeer net_peer;
30 | public int ticks;
31 | public readonly int send_rate;
32 |
33 | public NetworkPeer(int send_rate)
34 | : base()
35 | {
36 | this.send_rate = send_rate;
37 | }
38 |
39 | public void MessagePump()
40 | {
41 | NetIncomingMessage msg;
42 |
43 | ticks += 1;
44 | BeforePump();
45 |
46 | while ((msg = net_peer.ReadMessage()) != null)
47 | {
48 | switch (msg.MessageType)
49 | {
50 | case NetIncomingMessageType.Data:
51 | OnDataMessage(msg);
52 | break;
53 |
54 | case NetIncomingMessageType.VerboseDebugMessage:
55 | case NetIncomingMessageType.DebugMessage:
56 | case NetIncomingMessageType.WarningMessage:
57 | case NetIncomingMessageType.ErrorMessage:
58 | OnDebugMessage(msg);
59 | break;
60 |
61 | case NetIncomingMessageType.StatusChanged:
62 | OnStatusChanged(msg);
63 | break;
64 |
65 | default:
66 | OnUnknownMessage(msg);
67 | break;
68 | }
69 |
70 | net_peer.Recycle(msg);
71 | }
72 |
73 | Simulate();
74 |
75 | if (ticks == send_rate)
76 | {
77 | OnSend();
78 | ticks = 0;
79 | }
80 | }
81 |
82 | public virtual NetOutgoingMessage CreateMessage()
83 | {
84 | return net_peer.CreateMessage();
85 | }
86 |
87 | protected NetPeerConfiguration CreateConfig()
88 | {
89 | var config = new NetPeerConfiguration(APP_IDENTIFIER);
90 | config.SimulatedMinimumLatency = SIMULATED_MIN_LATENCY;
91 | config.SimulatedRandomLatency = SIMULATDE_RANDOM_LATENCY;
92 | config.SimulatedLoss = SIMULATED_LOSS;
93 | return config;
94 | }
95 |
96 | protected virtual void OnDataMessage(NetIncomingMessage msg)
97 | {
98 | Debug.Log("Data message: " + msg.LengthBytes + " bytes");
99 | }
100 |
101 | protected virtual void OnDebugMessage(NetIncomingMessage msg)
102 | {
103 | Debug.Log("Debug message: " + msg.ReadString());
104 | }
105 |
106 | protected virtual void OnStatusChanged(NetIncomingMessage msg)
107 | {
108 | Debug.Log("Status changed: " + msg.SenderConnection.Status);
109 | }
110 |
111 | protected virtual void OnUnknownMessage(NetIncomingMessage msg)
112 | {
113 | Debug.Log("Unhandled message type: " + msg.MessageType);
114 | }
115 |
116 | protected virtual void BeforePump()
117 | {
118 |
119 | }
120 |
121 | protected virtual void AfterSimulate()
122 | {
123 |
124 | }
125 |
126 | protected virtual void OnSend()
127 | {
128 |
129 | }
130 |
131 | void Simulate()
132 | {
133 | NetworkActor obj;
134 |
135 | for (var i = 0; i <= NetworkActorRegistry.MaxIndex; ++i)
136 | {
137 | if ((obj = NetworkActorRegistry.Objects[i]) != null)
138 | {
139 | obj.NetworkFixedUpdate();
140 | }
141 | }
142 |
143 | AfterSimulate();
144 | }
145 | }
146 |
147 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkPeer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1c15ff1135da2f643bc2389747add93b
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkPosition.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using Lidgren.Network;
3 | using System;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | public class NetworkPosition : NetworkState
8 | {
9 | public struct State
10 | {
11 | public Vector3 pos;
12 | public Quaternion rot;
13 | public float timestamp;
14 | }
15 |
16 | const int STATE_BUFFER_SIZE = 20;
17 |
18 | Vector3 pos_to;
19 | Vector3 pos_from;
20 | Vector3 verified_pos;
21 |
22 | Quaternion rot_to;
23 | Quaternion rot_from;
24 | Quaternion verified_rot;
25 |
26 | float interp_start;
27 | byte last_cmd_id;
28 |
29 | int state_count;
30 | State[] state_buffer;
31 |
32 | void FreeStateSlot()
33 | {
34 | for (var i = (STATE_BUFFER_SIZE - 2); i >= 0; --i)
35 | {
36 | state_buffer[i + 1] = state_buffer[i];
37 | }
38 |
39 | state_count = Math.Min(state_count + 1, STATE_BUFFER_SIZE);
40 | }
41 |
42 | public override void Send(NetOutgoingMessage msg)
43 | {
44 | msg.Write(last_cmd_id);
45 | NetworkUtils.Write(msg, transform.position);
46 | NetworkUtils.Write(msg, transform.rotation);
47 |
48 | FreeStateSlot();
49 | state_buffer[0].pos = transform.position;
50 | state_buffer[0].rot = transform.rotation;
51 | state_buffer[0].timestamp = NetworkTime.step / 66.6666666f;
52 | }
53 |
54 |
55 | public override void Receive(NetIncomingMessage msg)
56 | {
57 | var command_id = msg.ReadByte();
58 | var position = NetworkUtils.ReadVector3(msg);
59 | var rotation = NetworkUtils.ReadQuaternion(msg);
60 |
61 | if (net_actor.is_owner)
62 | {
63 | verified_pos = position;
64 | verified_rot = rotation;
65 | last_cmd_id = command_id;
66 | }
67 | else
68 | {
69 | FreeStateSlot();
70 | state_buffer[0].pos = position;
71 | state_buffer[0].rot = rotation;
72 | state_buffer[0].timestamp = NetworkTime.step / 66.66666666f;
73 | }
74 | }
75 |
76 | public override void NetworkFixedUpdateServer()
77 | {
78 | if (net_actor.owner.cmd_queue.Count > 0)
79 | {
80 | var cmd = net_actor.owner.cmd_queue.Peek();
81 | last_cmd_id = cmd.commandid;
82 | transform.rotation *= UserInput.KeyStateToRotation(cmd.keystate);
83 | transform.Translate(UserInput.KeyStateToVelocity(cmd.keystate));
84 | }
85 | }
86 | public override void NetworkFixedUpdateClient()
87 | {
88 | // Owning client
89 | if (net_actor.is_owner)
90 | {
91 | ((NetworkClient)NetworkPeer.instance).has_spawned = true;
92 |
93 | interp_start = Time.time;
94 | pos_from = pos_to;
95 | pos_to = verified_pos;
96 | rot_from = rot_to;
97 | rot_to = verified_rot;
98 |
99 | for (var i = 0; i < UserInput.cmd_buffer.Length; ++i)
100 | {
101 | var cmd = UserInput.cmd_buffer[i];
102 | if (cmd.commandid != 0 && cmd.commandid == last_cmd_id)
103 | {
104 | for (var j = (i - 1); j >= 0; --j)
105 | {
106 | rot_to *= UserInput.KeyStateToRotation(UserInput.cmd_buffer[j].keystate);
107 | pos_to += rot_to * UserInput.KeyStateToVelocity(UserInput.cmd_buffer[j].keystate);
108 | }
109 |
110 | break;
111 | }
112 | }
113 |
114 | rot_to *= UserInput.KeyStateToRotation(UserInput.cmd.keystate);
115 | pos_to += rot_to * UserInput.KeyStateToVelocity(UserInput.cmd.keystate);
116 | }
117 | }
118 |
119 | public override void Init()
120 | {
121 | state_buffer = new State[STATE_BUFFER_SIZE];
122 | pos_to = pos_from = verified_pos = transform.position;
123 | rot_to = rot_from = verified_rot = transform.rotation;
124 | }
125 |
126 | public bool SetPosition(float time)
127 | {
128 | for (var i = 0; i < state_count; ++i)
129 | {
130 | if (state_buffer[i].timestamp <= time || i == state_count - 1)
131 | {
132 | var rhs = state_buffer[Math.Max(i - 1, 0)];
133 | var lhs = state_buffer[i];
134 | var length = rhs.timestamp - lhs.timestamp;
135 | var t = 0.0f;
136 |
137 | if (length > 0.0001f)
138 | {
139 | t = (float)((time - lhs.timestamp) / length);
140 | }
141 |
142 | transform.rotation = Quaternion.Slerp(lhs.rot, rhs.rot, t);
143 | transform.position = Vector3.Lerp(lhs.pos, rhs.pos, t);
144 | return true;
145 | }
146 | }
147 |
148 | return false;
149 | }
150 |
151 | public bool SetPosition()
152 | {
153 | return SetPosition(NetworkTime.gameTime - 0.1f);
154 | }
155 |
156 | public override void NetworkUpdateClient()
157 | {
158 | if (NetworkPeer.is_client)
159 | {
160 | if (!net_actor.is_owner)
161 | {
162 | if (!SetPosition())
163 | {
164 | // If we failed to set position, we need to extrapolate...
165 | Debug.LogWarning("Need extrapolation", this);
166 | }
167 | }
168 | else
169 | {
170 | var t = (Time.time - interp_start) / NetworkPeer.TICK_TIME;
171 | transform.rotation = Quaternion.Slerp(rot_from, rot_to, t);
172 | transform.position = Vector3.Lerp(pos_from, pos_to, t);
173 | }
174 | }
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkPosition.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ada15181318091f499db5164be42d4e7
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkRemoteCall.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Lidgren.Network;
4 | using UnityEngine;
5 |
6 | public static class NetworkRemoteCall
7 | {
8 | const NetDeliveryMethod deliveryMethod = NetDeliveryMethod.ReliableOrdered;
9 |
10 | public static void CallOnClient(NetworkClientInfo client, string method_name, params object[] args)
11 | {
12 | CallOnClients(new[] { client }, method_name, args);
13 | }
14 |
15 | public static void CallOnAllClients(string method_name, params object[] args)
16 | {
17 | var server = (NetworkServer)NetworkPeer.instance;
18 | CallOnClients(new List(server.connected_clients), method_name, args);
19 | }
20 |
21 | public static void CallOnClients(IList clients, string method_name, params object[] args)
22 | {
23 | if (!NetworkPeer.is_server)
24 | {
25 | throw new Exception();
26 | }
27 |
28 | var connections = new List(clients.Count);
29 | for (var i = 0; i < clients.Count; ++i)
30 | {
31 | connections.Add(clients[i].connection);
32 | }
33 |
34 | CallOnConnections(connections, method_name, args);
35 | }
36 |
37 | public static void CallOnServer(string method_name, params object[] args)
38 | {
39 | var msg = BuildMessage(0, method_name, args);
40 | var client = (NetworkClient)NetworkPeer.instance;
41 | client.net_client.SendMessage(msg, deliveryMethod, 0);
42 | }
43 |
44 | static void CallOnConnections(IList connections, string method_name, params object[] args)
45 | {
46 | var msg = BuildMessage(0, method_name, args);
47 | NetworkPeer.instance.net_peer.SendMessage(msg, connections, deliveryMethod, 1);
48 | }
49 |
50 | static NetOutgoingMessage BuildMessage(int id, string method_name, params object[] args)
51 | {
52 | var msg = NetworkPeer.instance.CreateMessage();
53 | msg.Write(NetworkPeer.REMOTE_CALL_FLAG);
54 | msg.Write(id);
55 | msg.Write(method_name);
56 |
57 | for (var i = 0; i < args.Length; ++i)
58 | {
59 | WriteArgument(msg, args[i]);
60 | }
61 |
62 | return msg;
63 | }
64 |
65 | static void WriteArgument(NetOutgoingMessage msg, object a)
66 | {
67 | if (a is byte)
68 | {
69 | msg.Write((byte)a);
70 |
71 | }
72 | else if (a is int)
73 | {
74 | msg.Write((int)a);
75 |
76 | }
77 | else if (a is float)
78 | {
79 | msg.Write((float)a);
80 |
81 | }
82 | else if (a is Vector3)
83 | {
84 | NetworkUtils.Write(msg, (Vector3)a);
85 |
86 | }
87 | else if (a is Quaternion)
88 | {
89 | NetworkUtils.Write(msg, (Quaternion)a);
90 |
91 | }
92 | else if (a is string)
93 | {
94 | msg.Write((string)a);
95 |
96 | }
97 | else
98 | {
99 | throw new Exception("Unsupported remote call argument type '" + a.GetType() + "'");
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkRemoteCall.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d63d3163de8b1e74da3b2cf4bcd61628
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkRemoteCallReceiver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Lidgren.Network;
4 | using UnityEngine;
5 |
6 | internal static class NetworkRemoteCallReceiver
7 | {
8 | public static void ReceiveRemoteCall(NetIncomingMessage msg)
9 | {
10 | var instance = GetCallTargetInstance(msg.ReadInt32());
11 | if (instance == null)
12 | {
13 | return;
14 | }
15 |
16 | var instanceType = instance.GetType();
17 | var methodName = msg.ReadString();
18 | var method = instanceType.GetMethod(methodName);
19 |
20 | Debug.Log("RPC: " + instanceType.Name + "." + methodName);
21 |
22 | if (method == null)
23 | {
24 | throw new Exception("Found no method named '" + methodName + "' on type '" + instance.GetType() + "'");
25 | }
26 |
27 | var parms = method.GetParameters();
28 | var args = new object[parms.Length];
29 |
30 | args[0] = msg;
31 |
32 | for (var i = 1; i < args.Length; ++i)
33 | {
34 | args[i] = ReadArgument(msg, parms[i].ParameterType);
35 | }
36 |
37 | method.Invoke(instance, args);
38 | }
39 |
40 | static object GetCallTargetInstance(int id)
41 | {
42 | if (id == 0)
43 | {
44 | return NetworkPeer.instance;
45 | }
46 | else
47 | {
48 | return NetworkActorRegistry.GetById(id);
49 | }
50 | }
51 |
52 | static object ReadArgument(NetIncomingMessage msg, Type type)
53 | {
54 | if (type == typeof(int))
55 | {
56 | return msg.ReadInt32();
57 | }
58 | else if (type == typeof(byte))
59 | {
60 | return msg.ReadByte();
61 | }
62 | else if (type == typeof(float))
63 | {
64 | return msg.ReadFloat();
65 | }
66 | else if (type == typeof(Vector3))
67 | {
68 | return NetworkUtils.ReadVector3(msg);
69 | }
70 | else if (type == typeof(Quaternion))
71 | {
72 | return NetworkUtils.ReadQuaternion(msg);
73 | }
74 | else if (type == typeof(string))
75 | {
76 | return msg.ReadString();
77 | }
78 | else
79 | {
80 | throw new Exception("Unsupported argument type " + type);
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkRemoteCallReceiver.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 96e6c9b08934ac54f89dd4ac8e7f6df5
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkServer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Lidgren.Network;
6 | using UnityEngine;
7 |
8 | class NetworkServer : NetworkPeer
9 | {
10 | public const int SEND_RATE = 3;
11 | public const float SEND_TIME = 0.045f;
12 |
13 | public readonly NetServer netServer;
14 | public readonly HashSet connected_clients = new HashSet();
15 |
16 | byte host_id_counter;
17 | int actor_id_counter;
18 |
19 | NetOutgoingMessage out_msg;
20 |
21 | public NetworkServer()
22 | : base(SEND_RATE)
23 | {
24 | instance = this;
25 | is_server = true;
26 | is_client = false;
27 |
28 | host_id = 0;
29 | host_id_counter = 0;
30 | actor_id_counter = 0;
31 |
32 | var config = CreateConfig();
33 | config.Port = NetworkPeer.APP_PORT;
34 |
35 | net_peer = netServer = new NetServer(config);
36 | netServer.Start();
37 | }
38 |
39 | public NetworkClientInfo GetClientInfo(NetIncomingMessage msg)
40 | {
41 | var connection = msg.SenderConnection;
42 |
43 | if (connection.Tag == null)
44 | {
45 | connection.Tag = new NetworkClientInfo(++host_id_counter, connection);
46 | }
47 |
48 | return ((NetworkClientInfo)connection.Tag);
49 | }
50 |
51 | protected override void OnStatusChanged(NetIncomingMessage msg)
52 | {
53 | switch (msg.SenderConnection.Status)
54 | {
55 | case NetConnectionStatus.Connected:
56 | var new_client = GetClientInfo(msg);
57 | connected_clients.Add(new_client);
58 | NetworkRemoteCall.CallOnClient(new_client, "Hello", new_client.host_id);
59 | break;
60 |
61 | case NetConnectionStatus.Disconnecting:
62 | case NetConnectionStatus.Disconnected:
63 | connected_clients.Remove(GetClientInfo(msg));
64 | break;
65 | }
66 | }
67 |
68 | protected override void OnDataMessage(NetIncomingMessage msg)
69 | {
70 | while (msg.Position < msg.LengthBits)
71 | {
72 | // Read message flag
73 | switch (msg.ReadByte())
74 | {
75 | case NetworkPeer.USER_COMMAND_FLAG:
76 | ReceiveUserCommand(msg);
77 | break;
78 |
79 | case NetworkPeer.REMOTE_CALL_FLAG:
80 | NetworkRemoteCallReceiver.ReceiveRemoteCall(msg);
81 | break;
82 | }
83 | }
84 | }
85 |
86 | private void ReceiveUserCommand(NetIncomingMessage msg)
87 | {
88 | var client = GetClientInfo(msg);
89 | var commandCount = (int)msg.ReadByte();
90 |
91 | for (var i = 0; i < commandCount; ++i)
92 | {
93 | UserCommand cmd = new UserCommand();
94 |
95 | cmd.commandid = msg.ReadByte();
96 | cmd.keystate = msg.ReadByte();
97 | cmd.actionstate = msg.ReadByte();
98 | cmd.client_time = msg.ReadFloat();
99 |
100 | if(client.has_spawned) {
101 | client.cmd_queue.Enqueue(cmd);
102 | }
103 | }
104 | }
105 |
106 | protected override void AfterSimulate()
107 | {
108 | foreach (var client in connected_clients)
109 | {
110 | // Make sure we remove the current command, if any exist
111 | if (client.cmd_queue.Count > 0)
112 | {
113 | client.cmd_queue.Dequeue();
114 | }
115 | }
116 | }
117 |
118 | protected override void BeforePump ()
119 | {
120 | NetworkTime.Update();
121 | NetworkTime.UpdateServerStep();
122 | }
123 |
124 | public override NetOutgoingMessage CreateMessage()
125 | {
126 | var msg = base.CreateMessage();
127 | msg.Write(NetworkTime.step);
128 | return msg;
129 | }
130 |
131 | protected override void OnSend()
132 | {
133 | foreach (var client in connected_clients)
134 | {
135 | if (client.proximity_set.Count > 0)
136 | {
137 | var msg = CreateMessage();
138 | msg.Write(NetworkPeer.ACTOR_EVENT_FLAG);
139 |
140 | foreach (var obj in client.proximity_set)
141 | {
142 | obj.Send(msg);
143 | }
144 |
145 | netServer.SendMessage(msg, client.connection, NetDeliveryMethod.UnreliableSequenced, 0);
146 | }
147 | }
148 | }
149 |
150 | [RPC]
151 | public void RequestObjects(NetIncomingMessage msg)
152 | {
153 | var client = GetClientInfo(msg);
154 |
155 | foreach (var obj in NetworkActorRegistry.Objects)
156 | {
157 | if (obj != null)
158 | {
159 | NetworkRemoteCall.CallOnClient(
160 | client, "Spawn",
161 | obj.host_id, obj.actor_id, obj.prefab_name,
162 | obj.transform.position, obj.transform.rotation
163 | );
164 | }
165 | }
166 | }
167 |
168 | [RPC]
169 | public void RequestObjectRegistration(NetIncomingMessage msg, int actor_id)
170 | {
171 | var client = GetClientInfo(msg);
172 | var obj = NetworkActorRegistry.GetById(actor_id);
173 | client.proximity_set.Add(obj);
174 | }
175 |
176 | [RPC]
177 | public void RequestSpawn(NetIncomingMessage msg, string prefab_name, Vector3 pos, Quaternion rot)
178 | {
179 | var client_info = GetClientInfo(msg);
180 | var game_object = (GameObject)GameObject.Instantiate(Resources.Load(prefab_name), pos, rot);
181 | var obj = game_object.GetComponent();
182 |
183 | obj.host_id = client_info.host_id;
184 | obj.actor_id = actor_id_counter++;
185 | obj.is_owner = false;
186 | obj.owner = client_info;
187 | obj.prefab_name = prefab_name;
188 |
189 | client_info.has_spawned = true;
190 |
191 | NetworkRemoteCall.CallOnAllClients(
192 | "Spawn",
193 | obj.host_id, obj.actor_id, obj.prefab_name,
194 | obj.transform.position, obj.transform.rotation
195 | );
196 | }
197 | }
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkServer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1aa4b7724a81e954baae08d45361c287
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkServerBehaviour.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | class NetworkServerBehaviour : MonoBehaviour
4 | {
5 | public NetworkServer server;
6 |
7 | void Start()
8 | {
9 | server = new NetworkServer();
10 | }
11 |
12 | void FixedUpdate()
13 | {
14 | server.MessagePump();
15 | }
16 |
17 | public bool is_running
18 | {
19 | get
20 | {
21 | return enabled && server != null;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkServerBehaviour.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8569878d8cc6d32498d083ad909a0b7b
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkState.cs:
--------------------------------------------------------------------------------
1 | using Lidgren.Network;
2 | using UnityEngine;
3 |
4 | public abstract class NetworkState : MonoBehaviour
5 | {
6 | [HideInInspector]
7 | public NetworkActor net_actor = null;
8 |
9 | public NetworkClientInfo owner { get { return net_actor.owner; } }
10 |
11 | public virtual void Init() { }
12 | public abstract void Send(NetOutgoingMessage msg);
13 | public abstract void Receive(NetIncomingMessage msg);
14 |
15 | public virtual void NetworkUpdateClient() { }
16 | public virtual void NetworkUpdateServer() { }
17 |
18 | public virtual void NetworkFixedUpdateClient() { }
19 | public virtual void NetworkFixedUpdateServer() { }
20 | }
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkState.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2ecc1f7fae755a24e8d7f6af4cca34be
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkTime.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using UnityEngine;
4 | using System.Runtime.InteropServices;
5 |
6 | public static class NetworkTime
7 | {
8 | static float lastRemoteTime;
9 |
10 | public static int step = 0;
11 | public static float offset = 0.0f;
12 | public static float gameTime = 0.0f;
13 |
14 | public static void Update()
15 | {
16 | if (NetworkPeer.is_server)
17 | {
18 | gameTime = step / 66.66666666f;
19 | return;
20 | }
21 |
22 | gameTime = Time.time + offset;
23 | }
24 |
25 | public static void UpdateServerStep()
26 | {
27 | var newStep = Mathf.FloorToInt(Time.time * 66.66666666f);
28 |
29 | if(newStep-1 != step)
30 | {
31 | step += 1;
32 | }
33 | else
34 | {
35 | step = newStep;
36 | }
37 | }
38 |
39 | public static void SetOffset(float remoteTime, float rtt)
40 | {
41 | if (lastRemoteTime != remoteTime)
42 | {
43 | var newOffset = remoteTime - Time.time;
44 |
45 | if (offset == 0.0f)
46 | {
47 | offset = newOffset;
48 | }
49 | else
50 | {
51 | offset = (offset * 0.95f) + (newOffset * 0.05f);
52 | }
53 |
54 | lastRemoteTime = remoteTime;
55 | Update();
56 | }
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkTime.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c5171d0dbd1a84641bc75bcf114fddc6
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkUtils.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using Lidgren.Network;
4 |
5 | public class NetworkUtils
6 | {
7 | public static void Write(NetOutgoingMessage msg, Vector3 data)
8 | {
9 | msg.Write(data.x);
10 | msg.Write(data.y);
11 | msg.Write(data.z);
12 | }
13 |
14 | public static Vector3 ReadVector3(NetIncomingMessage msg)
15 | {
16 | Vector3 data;
17 |
18 | data.x = msg.ReadFloat();
19 | data.y = msg.ReadFloat();
20 | data.z = msg.ReadFloat();
21 |
22 | return data;
23 | }
24 |
25 | public static void Write(NetOutgoingMessage msg, Quaternion data)
26 | {
27 | msg.Write(data.x);
28 | msg.Write(data.y);
29 | msg.Write(data.z);
30 | msg.Write(data.w);
31 | }
32 |
33 | public static Quaternion ReadQuaternion(NetIncomingMessage msg)
34 | {
35 | Quaternion data;
36 |
37 | data.x = msg.ReadFloat();
38 | data.y = msg.ReadFloat();
39 | data.z = msg.ReadFloat();
40 | data.w = msg.ReadFloat();
41 |
42 | return data;
43 | }
44 |
45 | public static void WritePositionRotation(NetOutgoingMessage msg, Transform transform)
46 | {
47 | Write(msg, transform.position);
48 | Write(msg, transform.rotation);
49 | }
50 | }
--------------------------------------------------------------------------------
/Assets/Scripts/NetworkUtils.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 73cabce174c9a19438371632f8e1e47f
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/PlayerActor.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using Lidgren.Network;
4 |
5 | public class PlayerActor : NetworkActor
6 | {
7 | public override void Init ()
8 | {
9 | if (is_owner)
10 | {
11 | Camera.main.GetComponent().Target = transform;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Assets/Scripts/PlayerActor.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bf328010b03e1cb49a5394695d8e4daf
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/RecyclableObjectPool.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | public interface IRecyclableObject {
6 | void Recycle();
7 | }
8 |
9 | public class RecyclableObjectPool where T : IRecyclableObject, new() {
10 |
11 | Stack reusable = new Stack();
12 |
13 | public T Get() {
14 | if(reusable.Count > 0) {
15 | return reusable.Pop();
16 | }
17 |
18 | return new T();
19 | }
20 |
21 | public void Recycle(T o) {
22 | o.Recycle();
23 | reusable.Push(o);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/Assets/Scripts/RecyclableObjectPool.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4ec5fb1aaf9c840498a82d246fdb0db0
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/UserCommand.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public struct UserCommand
4 | {
5 | // Serialized to server
6 | public byte commandid;
7 | public byte keystate;
8 | public byte actionstate;
9 | public float client_time;
10 | }
11 |
--------------------------------------------------------------------------------
/Assets/Scripts/UserCommand.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6e7af159a26e45c4090779effd30fc78
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/Assets/Scripts/UserInput.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using Lidgren.Network;
6 | using UnityEngine;
7 |
8 | static class UserInput
9 | {
10 | public const byte FORWARD = 1;
11 | public const byte BACKWARD = 2;
12 | public const byte LEFT = 4;
13 | public const byte RIGHT = 8;
14 | public const byte FIRE = 16;
15 | public const byte TURNLEFT = 32;
16 | public const byte TURNRIGHT = 64;
17 |
18 | public const byte ACTION1 = 1;
19 | public const byte ACTION2 = 2;
20 | public const byte ACTION3 = 4;
21 | public const byte ACTION4 = 8;
22 |
23 | static byte cmd_id = 0;
24 |
25 | public static byte auto_keys;
26 | public static byte auto_actions;
27 |
28 | public static int unsent_cmds;
29 | public static UserCommand cmd;
30 | public static UserCommand[] cmd_buffer = new UserCommand[256];
31 |
32 | public static void Read()
33 | {
34 | cmd.commandid = ++cmd_id;
35 | cmd.actionstate = GetActionState();
36 | cmd.keystate = GetKeyState();
37 |
38 | if (cmd.commandid == 0)
39 | {
40 | cmd.commandid = cmd_id = 1;
41 | }
42 | }
43 |
44 | public static void QueueCurrent()
45 | {
46 | ++unsent_cmds;
47 |
48 | for (var i = 254; i >= 0; --i)
49 | {
50 | cmd_buffer[i + 1] = cmd_buffer[i];
51 | }
52 |
53 | cmd_buffer[0] = cmd;
54 | cmd_buffer[0].client_time = NetworkTime.gameTime;
55 | }
56 |
57 | public static Vector3 KeyStateToVelocity(byte state)
58 | {
59 | var vector = Vector3.zero;
60 |
61 | if ((state & FORWARD) > 0) vector += Vector3.forward;
62 | if ((state & BACKWARD) > 0) vector += Vector3.back;
63 | if ((state & LEFT) > 0) vector += Vector3.left;
64 | if ((state & RIGHT) > 0) vector += Vector3.right;
65 |
66 | return vector.normalized * 0.1f;
67 | }
68 |
69 | public static Quaternion KeyStateToRotation(byte state)
70 | {
71 | var quaternion = Quaternion.identity;
72 |
73 | if ((state & TURNLEFT) > 0) quaternion *= Quaternion.Euler(0, -2, 0);
74 | if ((state & TURNRIGHT) > 0) quaternion *= Quaternion.Euler(0, 2, 0);
75 |
76 | return quaternion;
77 | }
78 |
79 | static byte GetKeyState()
80 | {
81 | byte state = auto_keys;
82 |
83 | if (Input.GetKey(KeyCode.W)) state |= FORWARD;
84 | if (Input.GetKey(KeyCode.S)) state |= BACKWARD;
85 | if (Input.GetKey(KeyCode.A)) state |= LEFT;
86 | if (Input.GetKey(KeyCode.D)) state |= RIGHT;
87 | if (Input.GetKey(KeyCode.Q)) state |= TURNLEFT;
88 | if (Input.GetKey(KeyCode.E)) state |= TURNRIGHT;
89 | if (Input.GetMouseButton(0)) state |= FIRE;
90 |
91 | return state;
92 | }
93 |
94 | static byte GetActionState()
95 | {
96 | byte state = auto_actions;
97 |
98 | if (Input.GetKey(KeyCode.Alpha1)) state |= ACTION1;
99 | if (Input.GetKey(KeyCode.Alpha2)) state |= ACTION2;
100 | if (Input.GetKey(KeyCode.Alpha3)) state |= ACTION3;
101 | if (Input.GetKey(KeyCode.Alpha4)) state |= ACTION4;
102 |
103 | return state;
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/Assets/Scripts/UserInput.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4dd16e4987badab468acb1e5f4e75db5
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 |
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 1
7 | m_ExternalVersionControlSupport: 1
8 | m_SerializationMode: 2
9 | m_WebSecurityEmulationEnabled: 0
10 | m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d
11 |
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/NavMeshLayers.asset
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!129 &1
4 | PlayerSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | AndroidProfiler: 0
8 | defaultScreenOrientation: 0
9 | targetDevice: 2
10 | targetPlatform: 1
11 | targetResolution: 0
12 | accelerometerFrequency: 60
13 | companyName: Fredrik
14 | productName: LidgrenExample
15 | AndroidLicensePublicKey:
16 | defaultScreenWidth: 1024
17 | defaultScreenHeight: 768
18 | defaultScreenWidthWeb: 600
19 | defaultScreenHeightWeb: 450
20 | m_RenderingPath: 1
21 | m_ActiveColorSpace: 0
22 | m_MTRendering: 1
23 | iosShowActivityIndicatorOnLoading: -1
24 | androidShowActivityIndicatorOnLoading: -1
25 | displayResolutionDialog: 1
26 | allowedAutorotateToPortrait: 1
27 | allowedAutorotateToPortraitUpsideDown: 1
28 | allowedAutorotateToLandscapeRight: 1
29 | allowedAutorotateToLandscapeLeft: 1
30 | useOSAutorotation: 1
31 | use32BitDisplayBuffer: 0
32 | use24BitDepthBuffer: 0
33 | defaultIsFullScreen: 0
34 | runInBackground: 1
35 | captureSingleScreen: 0
36 | Override IPod Music: 0
37 | usePlayerLog: 1
38 | useMacAppStoreValidation: 0
39 | xboxSkinOnGPU: 1
40 | xboxEnableAvatar: 0
41 | xboxEnableKinect: 0
42 | xboxEnableKinectAutoTracking: 0
43 | xboxEnableSpeech: 0
44 | wiiHio2Usage: -1
45 | wiiLoadingScreenRectPlacement: 0
46 | wiiLoadingScreenBackground: {r: 1, g: 1, b: 1, a: 1}
47 | wiiLoadingScreenPeriod: 1000
48 | wiiLoadingScreenFileName:
49 | wiiLoadingScreenRect:
50 | serializedVersion: 2
51 | x: 0
52 | y: 0
53 | width: 0
54 | height: 0
55 | m_SupportedAspectRatios:
56 | 4:3: 1
57 | 5:4: 1
58 | 16:10: 1
59 | 16:9: 1
60 | Others: 1
61 | iPhoneBundleIdentifier: com.Company.ProductName
62 | iPhoneBundleVersion: 1.0
63 | AndroidBundleVersionCode: 1
64 | AndroidMinSdkVersion: 6
65 | AndroidPreferredInstallLocation: 1
66 | aotOptions:
67 | apiCompatibilityLevel: 2
68 | iPhoneStrippingLevel: 0
69 | iPhoneScriptCallOptimization: 0
70 | ForceInternetPermission: 0
71 | ForceSDCardPermission: 0
72 | CreateWallpaper: 0
73 | StripUnusedMeshChannels: 0
74 | iPhoneSdkVersion: 988
75 | iPhoneTargetOSVersion: 4
76 | uIPrerenderedIcon: 0
77 | uIRequiresPersistentWiFi: 0
78 | uIStatusBarHidden: 1
79 | uIExitOnSuspend: 0
80 | uIStatusBarStyle: 0
81 | iPhoneSplashScreen: {fileID: 0}
82 | iPhoneHighResSplashScreen: {fileID: 0}
83 | iPadPortraitSplashScreen: {fileID: 0}
84 | iPadLandscapeSplashScreen: {fileID: 0}
85 | AndroidTargetDevice: 0
86 | AndroidTargetGraphics: 0
87 | AndroidSplashScreenScale: 0
88 | AndroidKeystoreName:
89 | AndroidKeyaliasName:
90 | resolutionDialogBanner: {fileID: 0}
91 | m_BuildTargetIcons:
92 | - m_BuildTarget:
93 | m_Icons:
94 | - m_Icon: {fileID: 0}
95 | m_Size: 128
96 | m_BuildTargetBatching: []
97 | webPlayerTemplate: APPLICATION:Default
98 | m_TemplateCustomTags: {}
99 | wiiRegion: 1
100 | wiiGameCode: RABA
101 | wiiGameVersion:
102 | wiiCompanyCode: ZZ
103 | wiiSupportsNunchuk: 0
104 | wiiSupportsClassicController: 0
105 | wiiSupportsBalanceBoard: 0
106 | wiiSupportsMotionPlus: 0
107 | wiiControllerCount: 1
108 | wiiFloatingPointExceptions: 0
109 | wiiScreenCrashDumps: 1
110 | wiiMemoryLabelCount: 147
111 | wiiMemorySetup: 5effbee7ffffff75f70100000000000000000000
112 | XboxTitleId:
113 | XboxImageXexPath:
114 | XboxSpaPath:
115 | XboxGenerateSpa: 0
116 | XboxDeployKinectResources: 0
117 | XboxSplashScreen: {fileID: 0}
118 | xboxSpeechDB: 0
119 | ps3TitleConfigPath:
120 | ps3DLCConfigPath:
121 | ps3ThumbnailPath:
122 | ps3BackgroundPath:
123 | ps3SoundPath:
124 | ps3TrophyCommId:
125 | ps3TrophyPackagePath:
126 | ps3ReservedMemorySizeMB: 2
127 | flashStrippingLevel: 2
128 | firstStreamedLevelWithResources: 0
129 | unityRebuildLibraryVersion: 9
130 | unityForwardCompatibleVersion: 36
131 | unityStandardAssetsVersion: 0
132 |
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gohla/unity3d-fps-networking-prototype/5a2f30564a4c93945869380afd9e47b7c31f8b92/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------