CodeBlocks.cs 321 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827
  1. using System;
  2. namespace BestHTTP.Examples
  3. {
  4. /// <summary>
  5. /// The html code for all the samples. These are used only in the WebPlayer demo.
  6. /// </summary>
  7. public static class CodeBlocks
  8. {
  9. #region TextureDownloadSample
  10. public static string TextureDownloadSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  11. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  12. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  13. <span style=""color:blue;"">using</span>&nbsp;BestHTTP;
  14. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">TextureDownloadSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  15. {
  16. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  17. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;URL&nbsp;of&nbsp;the&nbsp;server&nbsp;that&nbsp;will&nbsp;serve&nbsp;the&nbsp;image&nbsp;resources</span>
  18. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  19. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">const</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;BaseURL&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;http://besthttp.azurewebsites.net/Content/&quot;</span>;
  20. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  21. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  22. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;downloadable&nbsp;images</span>
  23. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  24. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>[]&nbsp;Images&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:blue;"">string</span>[9]&nbsp;{&nbsp;<span style=""color:#a31515;"">&quot;One.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Two.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Three.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Four.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Five.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Six.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Seven.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Eight.png&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Nine.png&quot;</span>&nbsp;};
  25. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  26. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;downloaded&nbsp;images&nbsp;will&nbsp;be&nbsp;stored&nbsp;as&nbsp;textures&nbsp;in&nbsp;this&nbsp;array</span>
  27. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  28. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Texture2D</span>[]&nbsp;Textures&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>[9];
  29. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  30. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;True&nbsp;if&nbsp;all&nbsp;images&nbsp;are&nbsp;loaded&nbsp;from&nbsp;the&nbsp;local&nbsp;cache&nbsp;instead&nbsp;of&nbsp;the&nbsp;server</span>
  31. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  32. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">bool</span>&nbsp;allDownloadedFromLocalCache;
  33. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  34. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;How&nbsp;many&nbsp;sent&nbsp;requests&nbsp;are&nbsp;finished</span>
  35. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  36. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;finishedCount;
  37. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  38. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;GUI&nbsp;scroll&nbsp;position</span>
  39. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  40. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Vector2</span>&nbsp;scrollPos;
  41. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  42. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  43. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Awake()
  44. &nbsp;&nbsp;&nbsp;&nbsp;{
  45. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;a&nbsp;well&nbsp;observable&nbsp;value</span>
  46. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;This&nbsp;is&nbsp;how&nbsp;many&nbsp;concurrent&nbsp;requests&nbsp;can&nbsp;be&nbsp;made&nbsp;to&nbsp;a&nbsp;server</span>
  47. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">HTTPManager</span>.MaxConnectionPerServer&nbsp;=&nbsp;1;
  48. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;placeholder&nbsp;textures</span>
  49. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;Images.Length;&nbsp;++i)
  50. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Textures[i]&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>(100,&nbsp;150);
  51. &nbsp;&nbsp;&nbsp;&nbsp;}
  52. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  53. &nbsp;&nbsp;&nbsp;&nbsp;{
  54. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;back&nbsp;to&nbsp;its&nbsp;defualt&nbsp;value.</span>
  55. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">HTTPManager</span>.MaxConnectionPerServer&nbsp;=&nbsp;4;
  56. &nbsp;&nbsp;&nbsp;&nbsp;}
  57. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  58. &nbsp;&nbsp;&nbsp;&nbsp;{
  59. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  60. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  61. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPos&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginScrollView(scrollPos);
  62. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;out&nbsp;the&nbsp;textures</span>
  63. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.SelectionGrid(0,&nbsp;Textures,&nbsp;3);
  64. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(finishedCount&nbsp;==&nbsp;Images.Length&nbsp;&amp;&amp;&nbsp;allDownloadedFromLocalCache)
  65. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawCenteredText(<span style=""color:#a31515;"">&quot;All&nbsp;images&nbsp;loaded&nbsp;from&nbsp;the&nbsp;local&nbsp;cache!&quot;</span>);
  66. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  67. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  68. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Max&nbsp;Connection/Server:&nbsp;&quot;</span>,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Width(150));
  69. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#2b91af;"">HTTPManager</span>.MaxConnectionPerServer.ToString(),&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Width(20));
  70. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">HTTPManager</span>.MaxConnectionPerServer&nbsp;=&nbsp;(<span style=""color:blue;"">byte</span>)<span style=""color:#2b91af;"">GUILayout</span>.HorizontalSlider(<span style=""color:#2b91af;"">HTTPManager</span>.MaxConnectionPerServer,&nbsp;1,&nbsp;10);
  71. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  72. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Start&nbsp;Download&quot;</span>))
  73. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DownloadImages();
  74. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndScrollView();
  75. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  76. &nbsp;&nbsp;&nbsp;&nbsp;}
  77. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  78. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Helper&nbsp;Functions
  79. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;DownloadImages()
  80. &nbsp;&nbsp;&nbsp;&nbsp;{
  81. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;these&nbsp;metadatas&nbsp;to&nbsp;its&nbsp;initial&nbsp;values</span>
  82. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allDownloadedFromLocalCache&nbsp;=&nbsp;<span style=""color:blue;"">true</span>;
  83. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finishedCount&nbsp;=&nbsp;0;
  84. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;Images.Length;&nbsp;++i)
  85. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  86. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;a&nbsp;blank&nbsp;placeholder&nbsp;texture,&nbsp;overriding&nbsp;previously&nbsp;downloaded&nbsp;texture</span>
  87. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Textures[i]&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>(100,&nbsp;150);
  88. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Construct&nbsp;the&nbsp;request</span>
  89. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequest</span>(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(BaseURL&nbsp;+&nbsp;Images[i]),&nbsp;ImageDownloaded);
  90. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;the&nbsp;Tag&nbsp;property,&nbsp;we&nbsp;can&nbsp;use&nbsp;it&nbsp;as&nbsp;a&nbsp;general&nbsp;storage&nbsp;bound&nbsp;to&nbsp;the&nbsp;request</span>
  91. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Tag&nbsp;=&nbsp;Textures[i];
  92. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Send&nbsp;out&nbsp;the&nbsp;request</span>
  93. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Send();
  94. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  95. &nbsp;&nbsp;&nbsp;&nbsp;}
  96. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  97. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Callback&nbsp;function&nbsp;of&nbsp;the&nbsp;image&nbsp;download&nbsp;http&nbsp;requests</span>
  98. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  99. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;ImageDownloaded(<span style=""color:#2b91af;"">HTTPRequest</span>&nbsp;req,&nbsp;<span style=""color:#2b91af;"">HTTPResponse</span>&nbsp;resp)
  100. &nbsp;&nbsp;&nbsp;&nbsp;{
  101. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Increase&nbsp;the&nbsp;finished&nbsp;count&nbsp;regardless&nbsp;of&nbsp;the&nbsp;state&nbsp;of&nbsp;our&nbsp;request</span>
  102. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finishedCount++;
  103. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>&nbsp;(req.State)
  104. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  105. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;finished&nbsp;without&nbsp;any&nbsp;problem.</span>
  106. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Finished:
  107. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(resp.IsSuccess)
  108. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  109. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Get&nbsp;the&nbsp;Texture&nbsp;from&nbsp;the&nbsp;Tag&nbsp;property</span>
  110. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Texture2D</span>&nbsp;tex&nbsp;=&nbsp;req.Tag&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>;
  111. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Load&nbsp;the&nbsp;texture</span>
  112. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tex.LoadImage(resp.Data);
  113. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Update&nbsp;the&nbsp;cache-info&nbsp;variable</span>
  114. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allDownloadedFromLocalCache&nbsp;=&nbsp;allDownloadedFromLocalCache&nbsp;&amp;&amp;&nbsp;resp.IsFromCache;
  115. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  116. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  117. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  118. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Request&nbsp;finished&nbsp;Successfully,&nbsp;but&nbsp;the&nbsp;server&nbsp;sent&nbsp;an&nbsp;error.&nbsp;Status&nbsp;Code:&nbsp;{0}-{1}&nbsp;Message:&nbsp;{2}&quot;</span>,
  119. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.StatusCode,
  120. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.Message,
  121. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.DataAsText));
  122. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  123. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  124. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;finished&nbsp;with&nbsp;an&nbsp;unexpected&nbsp;error.&nbsp;The&nbsp;request&#39;s&nbsp;Exception&nbsp;property&nbsp;may&nbsp;contain&nbsp;more&nbsp;info&nbsp;about&nbsp;the&nbsp;error.</span>
  125. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Error:
  126. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(<span style=""color:#a31515;"">&quot;Request&nbsp;Finished&nbsp;with&nbsp;Error!&nbsp;&quot;</span>&nbsp;+&nbsp;(req.Exception&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;?&nbsp;(req.Exception.Message&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;\n&quot;</span>&nbsp;+&nbsp;req.Exception.StackTrace)&nbsp;:&nbsp;<span style=""color:#a31515;"">&quot;No&nbsp;Exception&quot;</span>));
  127. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  128. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;aborted,&nbsp;initiated&nbsp;by&nbsp;the&nbsp;user.</span>
  129. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Aborted:
  130. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(<span style=""color:#a31515;"">&quot;Request&nbsp;Aborted!&quot;</span>);
  131. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  132. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Ceonnecting&nbsp;to&nbsp;the&nbsp;server&nbsp;is&nbsp;timed&nbsp;out.</span>
  133. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.ConnectionTimedOut:
  134. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(<span style=""color:#a31515;"">&quot;Connection&nbsp;Timed&nbsp;Out!&quot;</span>);
  135. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  136. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;didn&#39;t&nbsp;finished&nbsp;in&nbsp;the&nbsp;given&nbsp;time.</span>
  137. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.TimedOut:
  138. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(<span style=""color:#a31515;"">&quot;Processing&nbsp;the&nbsp;request&nbsp;Timed&nbsp;Out!&quot;</span>);
  139. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  140. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  141. &nbsp;&nbsp;&nbsp;&nbsp;}
  142. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  143. }</pre>";
  144. #endregion
  145. #region WebSocketSample
  146. public static string WebSocketSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  147. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  148. <span style=""color:blue;"">using</span>&nbsp;BestHTTP;
  149. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.WebSocket;
  150. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">WebSocketSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  151. {
  152. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  153. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  154. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;WebSocket&nbsp;address&nbsp;to&nbsp;connect</span>
  155. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  156. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;address&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;ws://echo.websocket.org&quot;</span>;
  157. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  158. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Default&nbsp;text&nbsp;to&nbsp;send</span>
  159. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  160. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;msgToSend&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Hello&nbsp;World!&quot;</span>;
  161. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  162. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Debug&nbsp;text&nbsp;to&nbsp;draw&nbsp;on&nbsp;the&nbsp;gui</span>
  163. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  164. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;Text&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  165. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  166. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Saved&nbsp;WebSocket&nbsp;instance</span>
  167. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  168. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">WebSocket</span>&nbsp;webSocket;
  169. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  170. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;GUI&nbsp;scroll&nbsp;position</span>
  171. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  172. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Vector2</span>&nbsp;scrollPos;
  173. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  174. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  175. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  176. &nbsp;&nbsp;&nbsp;&nbsp;{
  177. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(webSocket&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  178. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.Close();
  179. &nbsp;&nbsp;&nbsp;&nbsp;}
  180. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  181. &nbsp;&nbsp;&nbsp;&nbsp;{
  182. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  183. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  184. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPos&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginScrollView(scrollPos);
  185. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(Text);
  186. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndScrollView();
  187. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(5);
  188. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  189. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;address&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(address);
  190. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(webSocket&nbsp;==&nbsp;<span style=""color:blue;"">null</span>&nbsp;&amp;&amp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Open&nbsp;Web&nbsp;Socket&quot;</span>))
  191. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  192. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;WebSocket&nbsp;instance</span>
  193. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">WebSocket</span>(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(address));
  194. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">HTTPManager</span>.Proxy&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  195. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.InternalRequest.Proxy&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">HTTPProxy</span>(<span style=""color:#2b91af;"">HTTPManager</span>.Proxy.Address,&nbsp;<span style=""color:#2b91af;"">HTTPManager</span>.Proxy.Credentials,&nbsp;<span style=""color:blue;"">false</span>);
  196. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Subscribe&nbsp;to&nbsp;the&nbsp;WS&nbsp;events</span>
  197. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.OnOpen&nbsp;+=&nbsp;OnOpen;
  198. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.OnMessage&nbsp;+=&nbsp;OnMessageReceived;
  199. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.OnClosed&nbsp;+=&nbsp;OnClosed;
  200. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.OnError&nbsp;+=&nbsp;OnError;
  201. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;connecting&nbsp;to&nbsp;the&nbsp;server</span>
  202. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.Open();
  203. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;Opening&nbsp;Web&nbsp;Socket...\n&quot;</span>;
  204. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  205. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(webSocket&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;&amp;&amp;&nbsp;webSocket.IsOpen)
  206. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  207. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  208. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  209. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msgToSend&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(msgToSend);
  210. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Send&quot;</span>,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MaxWidth(70)))
  211. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  212. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;Sending&nbsp;message...\n&quot;</span>;
  213. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Send&nbsp;message&nbsp;to&nbsp;the&nbsp;server</span>
  214. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.Send(msgToSend);
  215. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  216. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  217. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  218. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Close&quot;</span>))
  219. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  220. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;the&nbsp;connection</span>
  221. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket.Close(1000,&nbsp;<span style=""color:#a31515;"">&quot;Bye!&quot;</span>);
  222. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  223. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  224. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  225. &nbsp;&nbsp;&nbsp;&nbsp;}
  226. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  227. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;WebSocket&nbsp;Event&nbsp;Handlers
  228. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  229. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;the&nbsp;web&nbsp;socket&nbsp;is&nbsp;open,&nbsp;and&nbsp;we&nbsp;are&nbsp;ready&nbsp;to&nbsp;send&nbsp;and&nbsp;receive&nbsp;data</span>
  230. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  231. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnOpen(<span style=""color:#2b91af;"">WebSocket</span>&nbsp;ws)
  232. &nbsp;&nbsp;&nbsp;&nbsp;{
  233. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;-WebSocket&nbsp;Open!\n&quot;</span>);
  234. &nbsp;&nbsp;&nbsp;&nbsp;}
  235. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  236. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;we&nbsp;received&nbsp;a&nbsp;text&nbsp;message&nbsp;from&nbsp;the&nbsp;server</span>
  237. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  238. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnMessageReceived(<span style=""color:#2b91af;"">WebSocket</span>&nbsp;ws,&nbsp;<span style=""color:blue;"">string</span>&nbsp;message)
  239. &nbsp;&nbsp;&nbsp;&nbsp;{
  240. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;-Message&nbsp;received:&nbsp;{0}\n&quot;</span>,&nbsp;message);
  241. &nbsp;&nbsp;&nbsp;&nbsp;}
  242. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  243. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;the&nbsp;web&nbsp;socket&nbsp;closed</span>
  244. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  245. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnClosed(<span style=""color:#2b91af;"">WebSocket</span>&nbsp;ws,&nbsp;<span style=""color:#2b91af;"">UInt16</span>&nbsp;code,&nbsp;<span style=""color:blue;"">string</span>&nbsp;message)
  246. &nbsp;&nbsp;&nbsp;&nbsp;{
  247. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;-WebSocket&nbsp;closed!&nbsp;Code:&nbsp;{0}&nbsp;Message:&nbsp;{1}\n&quot;</span>,&nbsp;code,&nbsp;message);
  248. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  249. &nbsp;&nbsp;&nbsp;&nbsp;}
  250. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  251. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;an&nbsp;error&nbsp;occured&nbsp;on&nbsp;client&nbsp;side</span>
  252. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  253. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnError(<span style=""color:#2b91af;"">WebSocket</span>&nbsp;ws,&nbsp;<span style=""color:#2b91af;"">Exception</span>&nbsp;ex)
  254. &nbsp;&nbsp;&nbsp;&nbsp;{
  255. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;errorMsg&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  256. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(ws.InternalRequest.Response&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  257. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errorMsg&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Status&nbsp;Code&nbsp;from&nbsp;Server:&nbsp;{0}&nbsp;and&nbsp;Message:&nbsp;{1}&quot;</span>,&nbsp;ws.InternalRequest.Response.StatusCode,&nbsp;ws.InternalRequest.Response.Message);
  258. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;-An&nbsp;error&nbsp;occured:&nbsp;{0}\n&quot;</span>,&nbsp;(ex&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;?&nbsp;ex.Message&nbsp;:&nbsp;<span style=""color:#a31515;"">&quot;Unknown&nbsp;Error&nbsp;&quot;</span>&nbsp;+&nbsp;errorMsg));
  259. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webSocket&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  260. &nbsp;&nbsp;&nbsp;&nbsp;}
  261. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  262. }</pre>";
  263. #endregion
  264. #region AssetBundleSample
  265. public static string AssetBundleSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  266. <span style=""color:blue;"">using</span>&nbsp;System.Collections;
  267. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  268. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  269. <span style=""color:blue;"">using</span>&nbsp;BestHTTP;
  270. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">AssetBundleSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  271. {
  272. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  273. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;url&nbsp;of&nbsp;the&nbsp;resource&nbsp;to&nbsp;download</span>
  274. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  275. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">const</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;URL&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;http://besthttp.azurewebsites.net/Content/AssetBundle.html&quot;</span>;
  276. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  277. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  278. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Debug&nbsp;status&nbsp;text</span>
  279. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  280. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Waiting&nbsp;for&nbsp;user&nbsp;interaction&quot;</span>;
  281. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  282. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;downloaded&nbsp;and&nbsp;cached&nbsp;AssetBundle</span>
  283. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  284. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">AssetBundle</span>&nbsp;cachedBundle;
  285. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  286. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;loaded&nbsp;texture&nbsp;from&nbsp;the&nbsp;AssetBundle</span>
  287. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  288. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Texture2D</span>&nbsp;texture;
  289. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  290. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;A&nbsp;flag&nbsp;that&nbsp;indicates&nbsp;that&nbsp;we&nbsp;are&nbsp;processing&nbsp;the&nbsp;request/bundle&nbsp;to&nbsp;hide&nbsp;the&nbsp;&quot;Start&nbsp;Download&quot;&nbsp;button.</span>
  291. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  292. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">bool</span>&nbsp;downloading;
  293. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  294. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  295. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  296. &nbsp;&nbsp;&nbsp;&nbsp;{
  297. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  298. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  299. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Status:&nbsp;&quot;</span>&nbsp;+&nbsp;status);
  300. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;the&nbsp;texture&nbsp;from&nbsp;the&nbsp;downloaded&nbsp;bundle</span>
  301. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(texture&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  302. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Box(texture,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MaxHeight(256));
  303. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(!downloading&nbsp;&amp;&amp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Start&nbsp;Download&quot;</span>))
  304. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  305. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UnloadBundle();
  306. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StartCoroutine(DownloadAssetBundle());
  307. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  308. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  309. &nbsp;&nbsp;&nbsp;&nbsp;}
  310. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  311. &nbsp;&nbsp;&nbsp;&nbsp;{
  312. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UnloadBundle();
  313. &nbsp;&nbsp;&nbsp;&nbsp;}
  314. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  315. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Helper&nbsp;Functions
  316. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">IEnumerator</span>&nbsp;DownloadAssetBundle()
  317. &nbsp;&nbsp;&nbsp;&nbsp;{
  318. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;downloading&nbsp;=&nbsp;<span style=""color:blue;"">true</span>;
  319. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;and&nbsp;send&nbsp;our&nbsp;request</span>
  320. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequest</span>(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(URL)).Send();
  321. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Download&nbsp;started&quot;</span>;
  322. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Wait&nbsp;while&nbsp;it&#39;s&nbsp;finishes&nbsp;and&nbsp;add&nbsp;some&nbsp;fancy&nbsp;dots&nbsp;to&nbsp;display&nbsp;something&nbsp;while&nbsp;the&nbsp;user&nbsp;waits&nbsp;for&nbsp;it.</span>
  323. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;A&nbsp;simple&nbsp;&quot;yield&nbsp;return&nbsp;StartCoroutine(request);&quot;&nbsp;would&nbsp;do&nbsp;the&nbsp;job&nbsp;too.</span>
  324. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">while</span>(request.State&nbsp;&lt;&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Finished)
  325. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  326. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">yield</span>&nbsp;<span style=""color:blue;"">return</span>&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">WaitForSeconds</span>(0.1f);
  327. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;.&quot;</span>;
  328. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  329. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Check&nbsp;the&nbsp;outcome&nbsp;of&nbsp;our&nbsp;request.</span>
  330. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>&nbsp;(request.State)
  331. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  332. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;finished&nbsp;without&nbsp;any&nbsp;problem.</span>
  333. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Finished:
  334. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(request.Response.IsSuccess)
  335. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  336. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;AssetBundle&nbsp;downloaded!&nbsp;Loaded&nbsp;from&nbsp;local&nbsp;cache:&nbsp;{0}&quot;</span>,&nbsp;request.Response.IsFromCache.ToString());
  337. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;creating&nbsp;the&nbsp;downloaded&nbsp;asset&nbsp;bundle</span>
  338. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">AssetBundleCreateRequest</span>&nbsp;async&nbsp;=&nbsp;<span style=""color:#2b91af;"">AssetBundle</span>.CreateFromMemory(request.Response.Data);
  339. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;wait&nbsp;for&nbsp;it</span>
  340. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">yield</span>&nbsp;<span style=""color:blue;"">return</span>&nbsp;async;
  341. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;And&nbsp;process&nbsp;the&nbsp;bundle</span>
  342. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">yield</span>&nbsp;<span style=""color:blue;"">return</span>&nbsp;StartCoroutine(ProcessAssetBundle(async.assetBundle));
  343. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  344. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  345. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  346. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Request&nbsp;finished&nbsp;Successfully,&nbsp;but&nbsp;the&nbsp;server&nbsp;sent&nbsp;an&nbsp;error.&nbsp;Status&nbsp;Code:&nbsp;{0}-{1}&nbsp;Message:&nbsp;{2}&quot;</span>,
  347. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Response.StatusCode,
  348. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Response.Message,
  349. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Response.DataAsText);
  350. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(status);
  351. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  352. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  353. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;finished&nbsp;with&nbsp;an&nbsp;unexpected&nbsp;error.&nbsp;The&nbsp;request&#39;s&nbsp;Exception&nbsp;property&nbsp;may&nbsp;contain&nbsp;more&nbsp;info&nbsp;about&nbsp;the&nbsp;error.</span>
  354. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Error:
  355. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Request&nbsp;Finished&nbsp;with&nbsp;Error!&nbsp;&quot;</span>&nbsp;+&nbsp;(request.Exception&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;?&nbsp;(request.Exception.Message&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;\n&quot;</span>&nbsp;+&nbsp;request.Exception.StackTrace)&nbsp;:&nbsp;<span style=""color:#a31515;"">&quot;No&nbsp;Exception&quot;</span>);
  356. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(status);
  357. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  358. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;aborted,&nbsp;initiated&nbsp;by&nbsp;the&nbsp;user.</span>
  359. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Aborted:
  360. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Request&nbsp;Aborted!&quot;</span>;
  361. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(status);
  362. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  363. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Ceonnecting&nbsp;to&nbsp;the&nbsp;server&nbsp;is&nbsp;timed&nbsp;out.</span>
  364. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.ConnectionTimedOut:
  365. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Connection&nbsp;Timed&nbsp;Out!&quot;</span>;
  366. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(status);
  367. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  368. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;didn&#39;t&nbsp;finished&nbsp;in&nbsp;the&nbsp;given&nbsp;time.</span>
  369. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.TimedOut:
  370. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Processing&nbsp;the&nbsp;request&nbsp;Timed&nbsp;Out!&quot;</span>;
  371. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(status);
  372. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  373. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  374. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;downloading&nbsp;=&nbsp;<span style=""color:blue;"">false</span>;
  375. &nbsp;&nbsp;&nbsp;&nbsp;}
  376. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  377. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;In&nbsp;this&nbsp;function&nbsp;we&nbsp;can&nbsp;do&nbsp;whatever&nbsp;we&nbsp;want&nbsp;with&nbsp;the&nbsp;freshly&nbsp;downloaded&nbsp;bundle.</span>
  378. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;In&nbsp;this&nbsp;example&nbsp;we&nbsp;will&nbsp;cache&nbsp;it&nbsp;for&nbsp;later&nbsp;use,&nbsp;and&nbsp;we&nbsp;will&nbsp;load&nbsp;a&nbsp;texture&nbsp;from&nbsp;it.</span>
  379. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  380. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">IEnumerator</span>&nbsp;ProcessAssetBundle(<span style=""color:#2b91af;"">AssetBundle</span>&nbsp;bundle)
  381. &nbsp;&nbsp;&nbsp;&nbsp;{
  382. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(bundle&nbsp;==&nbsp;<span style=""color:blue;"">null</span>)
  383. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">yield</span>&nbsp;<span style=""color:blue;"">break</span>;
  384. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Save&nbsp;the&nbsp;bundle&nbsp;for&nbsp;future&nbsp;use</span>
  385. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cachedBundle&nbsp;=&nbsp;bundle;
  386. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;loading&nbsp;the&nbsp;asset&nbsp;from&nbsp;the&nbsp;bundle</span>
  387. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;asyncAsset&nbsp;=&nbsp;cachedBundle.LoadAsync(<span style=""color:#a31515;"">&quot;9443182_orig&quot;</span>,&nbsp;<span style=""color:blue;"">typeof</span>(<span style=""color:#2b91af;"">Texture2D</span>));
  388. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;wait&nbsp;til&nbsp;load</span>
  389. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">yield</span>&nbsp;<span style=""color:blue;"">return</span>&nbsp;asyncAsset;
  390. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;get&nbsp;the&nbsp;texture</span>
  391. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;texture&nbsp;=&nbsp;asyncAsset.asset&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>;
  392. &nbsp;&nbsp;&nbsp;&nbsp;}
  393. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;UnloadBundle()
  394. &nbsp;&nbsp;&nbsp;&nbsp;{
  395. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(cachedBundle&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  396. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  397. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cachedBundle.Unload(<span style=""color:blue;"">true</span>);
  398. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cachedBundle&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  399. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  400. &nbsp;&nbsp;&nbsp;&nbsp;}
  401. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  402. }</pre>";
  403. #endregion
  404. #region LargeFileDownloadSample
  405. public static string LargeFileDownloadSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  406. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  407. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  408. <span style=""color:blue;"">using</span>&nbsp;BestHTTP;
  409. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">LargeFileDownloadSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  410. {
  411. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  412. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;url&nbsp;of&nbsp;the&nbsp;resource&nbsp;to&nbsp;download</span>
  413. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  414. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">const</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;URL&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;http://ipv4.download.thinkbroadband.com/100MB.zip&quot;</span>;
  415. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  416. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  417. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Cached&nbsp;request&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;abort&nbsp;it</span>
  418. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  419. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">HTTPRequest</span>&nbsp;request;
  420. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  421. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Debug&nbsp;status&nbsp;of&nbsp;the&nbsp;request</span>
  422. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  423. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;status&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  424. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  425. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Download(processing)&nbsp;progress.&nbsp;Its&nbsp;range&nbsp;is&nbsp;between&nbsp;[0..1]</span>
  426. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  427. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">float</span>&nbsp;progress;
  428. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  429. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;fragment&nbsp;size&nbsp;that&nbsp;we&nbsp;will&nbsp;set&nbsp;to&nbsp;the&nbsp;request</span>
  430. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  431. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;fragmentSize&nbsp;=&nbsp;<span style=""color:#2b91af;"">HTTPResponse</span>.MinBufferSize;
  432. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  433. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  434. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Awake()
  435. &nbsp;&nbsp;&nbsp;&nbsp;{
  436. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;If&nbsp;we&nbsp;have&nbsp;a&nbsp;non-finished&nbsp;download,&nbsp;set&nbsp;the&nbsp;progress&nbsp;to&nbsp;the&nbsp;value&nbsp;where&nbsp;we&nbsp;left&nbsp;it</span>
  437. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">PlayerPrefs</span>.HasKey(<span style=""color:#a31515;"">&quot;DownloadLength&quot;</span>))
  438. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;progress&nbsp;=&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>)&nbsp;/&nbsp;(<span style=""color:blue;"">float</span>)<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadLength&quot;</span>);
  439. &nbsp;&nbsp;&nbsp;&nbsp;}
  440. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  441. &nbsp;&nbsp;&nbsp;&nbsp;{
  442. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Stop&nbsp;the&nbsp;download&nbsp;if&nbsp;we&nbsp;are&nbsp;leaving&nbsp;this&nbsp;example</span>
  443. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(request&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;&amp;&amp;&nbsp;request.State&nbsp;&lt;&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Finished)
  444. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  445. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.OnProgress&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  446. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Callback&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  447. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Abort();
  448. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  449. &nbsp;&nbsp;&nbsp;&nbsp;}
  450. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  451. &nbsp;&nbsp;&nbsp;&nbsp;{
  452. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  453. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  454. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;the&nbsp;current&nbsp;status</span>
  455. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Request&nbsp;status:&nbsp;&quot;</span>&nbsp;+&nbsp;status);
  456. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(5);
  457. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;the&nbsp;current&nbsp;progress</span>
  458. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Progress:&nbsp;{0:P2}&nbsp;of&nbsp;{1:N0}Mb&quot;</span>,&nbsp;progress,&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadLength&quot;</span>)&nbsp;/&nbsp;1048576&nbsp;<span style=""color:green;"">/*1&nbsp;Mb*/</span>));
  459. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.HorizontalSlider(progress,&nbsp;0,&nbsp;1);
  460. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(50);
  461. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(request&nbsp;==&nbsp;<span style=""color:blue;"">null</span>)
  462. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  463. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;a&nbsp;slider&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;change&nbsp;the&nbsp;fragment&nbsp;size</span>
  464. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Desired&nbsp;Fragment&nbsp;Size:&nbsp;{0:N}&nbsp;KBytes&quot;</span>,&nbsp;fragmentSize&nbsp;/&nbsp;1024f));
  465. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fragmentSize&nbsp;=&nbsp;(<span style=""color:blue;"">int</span>)<span style=""color:#2b91af;"">GUILayout</span>.HorizontalSlider(fragmentSize,&nbsp;<span style=""color:#2b91af;"">HTTPResponse</span>.MinBufferSize,&nbsp;10&nbsp;*&nbsp;1024&nbsp;*&nbsp;1024);
  466. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(5);
  467. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;buttonStr&nbsp;=&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.HasKey(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>)&nbsp;?&nbsp;<span style=""color:#a31515;"">&quot;Continue&nbsp;Download&quot;</span>&nbsp;:&nbsp;<span style=""color:#a31515;"">&quot;Start&nbsp;Download&quot;</span>;
  468. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(buttonStr))
  469. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StreamLargeFileTest();
  470. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  471. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>&nbsp;<span style=""color:blue;"">if</span>&nbsp;(request.State&nbsp;==&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Processing&nbsp;&amp;&amp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Abort&nbsp;Download&quot;</span>))
  472. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  473. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Simulate&nbsp;a&nbsp;connection&nbsp;lost</span>
  474. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Abort();
  475. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  476. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  477. &nbsp;&nbsp;&nbsp;&nbsp;}
  478. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  479. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Helper&nbsp;Functions
  480. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Calling&nbsp;this&nbsp;function&nbsp;again&nbsp;when&nbsp;the&nbsp;&quot;DownloadProgress&quot;&nbsp;key&nbsp;in&nbsp;the&nbsp;PlayerPrefs&nbsp;present&nbsp;will&nbsp;</span>
  481. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">// continue&nbsp;the&nbsp;download</span>
  482. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;StreamLargeFileTest()
  483. &nbsp;&nbsp;&nbsp;&nbsp;{
  484. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequest</span>(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(URL),&nbsp;(req,&nbsp;resp)&nbsp;=&gt;
  485. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  486. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>&nbsp;(req.State)
  487. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  488. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;is&nbsp;currently&nbsp;processed.&nbsp;With&nbsp;UseStreaming&nbsp;==&nbsp;true,&nbsp;we&nbsp;can&nbsp;get&nbsp;the&nbsp;streamed&nbsp;fragments&nbsp;here</span>
  489. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Processing:
  490. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;the&nbsp;DownloadLength,&nbsp;so&nbsp;we&nbsp;can&nbsp;display&nbsp;the&nbsp;progress</span>
  491. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(!<span style=""color:#2b91af;"">PlayerPrefs</span>.HasKey(<span style=""color:#a31515;"">&quot;DownloadLength&quot;</span>))
  492. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  493. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;value&nbsp;=&nbsp;resp.GetFirstHeaderValue(<span style=""color:#a31515;"">&quot;content-length&quot;</span>);
  494. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(!<span style=""color:blue;"">string</span>.IsNullOrEmpty(value))
  495. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.SetInt(<span style=""color:#a31515;"">&quot;DownloadLength&quot;</span>,&nbsp;<span style=""color:blue;"">int</span>.Parse(value));
  496. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  497. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Get&nbsp;the&nbsp;fragments,&nbsp;and&nbsp;save&nbsp;them</span>
  498. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessFragments(resp.GetStreamedFragments());
  499. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Processing&quot;</span>;
  500. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  501. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;finished&nbsp;without&nbsp;any&nbsp;problem.</span>
  502. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Finished:
  503. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(resp.IsSuccess)
  504. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  505. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Save&nbsp;any&nbsp;remaining&nbsp;fragments</span>
  506. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessFragments(resp.GetStreamedFragments());
  507. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Completly&nbsp;finished</span>
  508. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(resp.IsStreamingFinished)
  509. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  510. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Streaming&nbsp;finished!&quot;</span>;
  511. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;We&nbsp;are&nbsp;done,&nbsp;delete&nbsp;the&nbsp;progress&nbsp;key</span>
  512. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.DeleteKey(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>);
  513. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.Save();
  514. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  515. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  516. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  517. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Processing&quot;</span>;
  518. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  519. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  520. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  521. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Request&nbsp;finished&nbsp;Successfully,&nbsp;but&nbsp;the&nbsp;server&nbsp;sent&nbsp;an&nbsp;error.&nbsp;Status&nbsp;Code:&nbsp;{0}-{1}&nbsp;Message:&nbsp;{2}&quot;</span>,
  522. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.StatusCode,
  523. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.Message,
  524. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.DataAsText);
  525. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(status);
  526. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  527. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  528. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  529. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;finished&nbsp;with&nbsp;an&nbsp;unexpected&nbsp;error.&nbsp;The&nbsp;request&#39;s&nbsp;Exception&nbsp;property&nbsp;may&nbsp;contain&nbsp;more&nbsp;info&nbsp;about&nbsp;the&nbsp;error.</span>
  530. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Error:
  531. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Request&nbsp;Finished&nbsp;with&nbsp;Error!&nbsp;&quot;</span>&nbsp;+&nbsp;(req.Exception&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;?&nbsp;(req.Exception.Message&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;\n&quot;</span>&nbsp;+&nbsp;req.Exception.StackTrace)&nbsp;:&nbsp;<span style=""color:#a31515;"">&quot;No&nbsp;Exception&quot;</span>);
  532. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(status);
  533. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  534. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  535. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;aborted,&nbsp;initiated&nbsp;by&nbsp;the&nbsp;user.</span>
  536. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.Aborted:
  537. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Request&nbsp;Aborted!&quot;</span>;
  538. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(status);
  539. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  540. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  541. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Ceonnecting&nbsp;to&nbsp;the&nbsp;server&nbsp;is&nbsp;timed&nbsp;out.</span>
  542. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.ConnectionTimedOut:
  543. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Connection&nbsp;Timed&nbsp;Out!&quot;</span>;
  544. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(status);
  545. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  546. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  547. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;request&nbsp;didn&#39;t&nbsp;finished&nbsp;in&nbsp;the&nbsp;given&nbsp;time.</span>
  548. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">HTTPRequestStates</span>.TimedOut:
  549. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Processing&nbsp;the&nbsp;request&nbsp;Timed&nbsp;Out!&quot;</span>;
  550. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(status);
  551. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  552. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  553. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  554. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  555. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Are&nbsp;there&nbsp;any&nbsp;progress,&nbsp;that&nbsp;we&nbsp;can&nbsp;continue?</span>
  556. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">PlayerPrefs</span>.HasKey(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>))
  557. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;the&nbsp;range&nbsp;header</span>
  558. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.SetRangeHeader(<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>));
  559. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  560. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;This&nbsp;is&nbsp;a&nbsp;new&nbsp;request</span>
  561. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.SetInt(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>,&nbsp;0);
  562. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;If&nbsp;we&nbsp;are&nbsp;writing&nbsp;our&nbsp;own&nbsp;file&nbsp;set&nbsp;it&nbsp;true(disable),&nbsp;so&nbsp;don&#39;t&nbsp;duplicate&nbsp;it&nbsp;on&nbsp;the&nbsp;filesystem</span>
  563. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.DisableCache&nbsp;=&nbsp;<span style=""color:blue;"">true</span>;
  564. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;We&nbsp;want&nbsp;to&nbsp;access&nbsp;the&nbsp;downloaded&nbsp;bytes&nbsp;while&nbsp;we&nbsp;are&nbsp;still&nbsp;downloading</span>
  565. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.UseStreaming&nbsp;=&nbsp;<span style=""color:blue;"">true</span>;
  566. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;a&nbsp;reasonable&nbsp;high&nbsp;fragment&nbsp;size.&nbsp;Here&nbsp;it&nbsp;is&nbsp;5&nbsp;megabytes.</span>
  567. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.StreamFragmentSize&nbsp;=&nbsp;fragmentSize;
  568. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;Processing&nbsp;the&nbsp;request</span>
  569. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Send();
  570. &nbsp;&nbsp;&nbsp;&nbsp;}
  571. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  572. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;In&nbsp;this&nbsp;function&nbsp;we&nbsp;can&nbsp;do&nbsp;whatever&nbsp;we&nbsp;want&nbsp;with&nbsp;the&nbsp;downloaded&nbsp;bytes.&nbsp;In&nbsp;this&nbsp;sample&nbsp;we&nbsp;will&nbsp;do&nbsp;nothing,&nbsp;just&nbsp;set&nbsp;the&nbsp;metadata&nbsp;to&nbsp;display&nbsp;progress.</span>
  573. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  574. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;ProcessFragments(<span style=""color:#2b91af;"">List</span>&lt;<span style=""color:blue;"">byte</span>[]&gt;&nbsp;fragments)
  575. &nbsp;&nbsp;&nbsp;&nbsp;{
  576. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(fragments&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>&nbsp;&amp;&amp;&nbsp;fragments.Count&nbsp;&gt;&nbsp;0)
  577. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  578. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">/*string&nbsp;dir&nbsp;=&nbsp;&quot;TODO!&quot;;</span>
  579. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;filename&nbsp;=&nbsp;&quot;TODO!&quot;;</span>
  580. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;using&nbsp;(System.IO.FileStream&nbsp;fs&nbsp;=&nbsp;new&nbsp;System.IO.FileStream(System.IO.Path.Combine(dir,&nbsp;filename),&nbsp;System.IO.FileMode.Append))</span>
  581. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;fragments.Count;&nbsp;++i)</span>
  582. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fs.Write(fragments[i],&nbsp;0,&nbsp;fragments[i].Length);*/</span>
  583. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;fragments.Count;&nbsp;++i)
  584. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  585. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Save&nbsp;how&nbsp;many&nbsp;bytes&nbsp;we&nbsp;wrote&nbsp;successfully</span>
  586. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;downloaded&nbsp;=&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>)&nbsp;+&nbsp;fragments[i].Length;
  587. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.SetInt(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>,&nbsp;downloaded);
  588. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  589. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.Save();
  590. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;the&nbsp;progress&nbsp;to&nbsp;the&nbsp;actually&nbsp;processed&nbsp;bytes</span>
  591. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;progress&nbsp;=&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadProgress&quot;</span>)&nbsp;/&nbsp;(<span style=""color:blue;"">float</span>)<span style=""color:#2b91af;"">PlayerPrefs</span>.GetInt(<span style=""color:#a31515;"">&quot;DownloadLength&quot;</span>);
  592. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  593. &nbsp;&nbsp;&nbsp;&nbsp;}
  594. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  595. }</pre>";
  596. #endregion
  597. #region SocketIOChatSample
  598. public static string SocketIOChatSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  599. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  600. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  601. <span style=""color:blue;"">using</span>&nbsp;BestHTTP;
  602. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SocketIO;
  603. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.JSON;
  604. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SocketIO.Events;
  605. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">SocketIOChatSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  606. {
  607. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">readonly</span>&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>&nbsp;TYPING_TIMER_LENGTH&nbsp;=&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>.FromMilliseconds(700);
  608. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">enum</span>&nbsp;<span style=""color:#2b91af;"">ChatStates</span>
  609. &nbsp;&nbsp;&nbsp;&nbsp;{
  610. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Login,
  611. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chat
  612. &nbsp;&nbsp;&nbsp;&nbsp;}
  613. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Fields
  614. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  615. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;Socket.IO&nbsp;manager&nbsp;instance.</span>
  616. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  617. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">SocketManager</span>&nbsp;Manager;
  618. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  619. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Current&nbsp;state&nbsp;of&nbsp;the&nbsp;chat&nbsp;demo.</span>
  620. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  621. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">ChatStates</span>&nbsp;State;
  622. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  623. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;selected&nbsp;nickname</span>
  624. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  625. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;userName&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  626. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  627. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Currently&nbsp;typing&nbsp;message</span>
  628. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  629. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;message&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  630. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  631. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Sent&nbsp;and&nbsp;received&nbsp;messages.</span>
  632. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  633. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;chatLog&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  634. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  635. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Position&nbsp;of&nbsp;the&nbsp;scroller</span>
  636. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  637. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">Vector2</span>&nbsp;scrollPos;
  638. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  639. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;True&nbsp;if&nbsp;the&nbsp;user&nbsp;is&nbsp;currently&nbsp;typing</span>
  640. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  641. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">bool</span>&nbsp;typing;
  642. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  643. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;When&nbsp;the&nbsp;message&nbsp;changed.</span>
  644. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  645. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">DateTime</span>&nbsp;lastTypingTime&nbsp;=&nbsp;<span style=""color:#2b91af;"">DateTime</span>.MinValue;
  646. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  647. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Users&nbsp;that&nbsp;typing.</span>
  648. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  649. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">List</span>&lt;<span style=""color:blue;"">string</span>&gt;&nbsp;typingUsers&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">List</span>&lt;<span style=""color:blue;"">string</span>&gt;();
  650. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  651. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  652. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  653. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  654. &nbsp;&nbsp;&nbsp;&nbsp;{
  655. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;current&nbsp;state&nbsp;is&nbsp;Login</span>
  656. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;State&nbsp;=&nbsp;<span style=""color:#2b91af;"">ChatStates</span>.Login;
  657. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Change&nbsp;an&nbsp;option&nbsp;to&nbsp;show&nbsp;how&nbsp;it&nbsp;should&nbsp;be&nbsp;done</span>
  658. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">SocketOptions</span>&nbsp;options&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">SocketOptions</span>();
  659. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.AutoConnect&nbsp;=&nbsp;<span style=""color:blue;"">false</span>;
  660. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  661. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;Socket.IO&nbsp;manager</span>
  662. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">SocketManager</span>(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;http://chat.socket.io/socket.io/&quot;</span>),&nbsp;options);
  663. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;up&nbsp;custom&nbsp;chat&nbsp;events</span>
  664. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#a31515;"">&quot;login&quot;</span>,&nbsp;OnLogin);
  665. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#a31515;"">&quot;new&nbsp;message&quot;</span>,&nbsp;OnNewMessage);
  666. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#a31515;"">&quot;user&nbsp;joined&quot;</span>,&nbsp;OnUserJoined);
  667. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#a31515;"">&quot;user&nbsp;left&quot;</span>,&nbsp;OnUserLeft);
  668. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#a31515;"">&quot;typing&quot;</span>,&nbsp;OnTyping);
  669. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#a31515;"">&quot;stop&nbsp;typing&quot;</span>,&nbsp;OnStopTyping);
  670. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;argument&nbsp;will&nbsp;be&nbsp;an&nbsp;Error&nbsp;object.</span>
  671. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.On(<span style=""color:#2b91af;"">SocketIOEventTypes</span>.Error,&nbsp;(socket,&nbsp;packet,&nbsp;args)&nbsp;=&gt;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogError(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Error:&nbsp;{0}&quot;</span>,&nbsp;args[0].ToString())));
  672. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;We&nbsp;set&nbsp;SocketOptions&#39;&nbsp;AutoConnect&nbsp;to&nbsp;false,&nbsp;so&nbsp;we&nbsp;have&nbsp;to&nbsp;call&nbsp;it&nbsp;manually.</span>
  673. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Open();
  674. &nbsp;&nbsp;&nbsp;&nbsp;}
  675. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  676. &nbsp;&nbsp;&nbsp;&nbsp;{
  677. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Leaving&nbsp;this&nbsp;sample,&nbsp;close&nbsp;the&nbsp;socket</span>
  678. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Close();
  679. &nbsp;&nbsp;&nbsp;&nbsp;}
  680. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Update()
  681. &nbsp;&nbsp;&nbsp;&nbsp;{
  682. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Go&nbsp;back&nbsp;to&nbsp;the&nbsp;demo&nbsp;selector</span>
  683. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">Input</span>.GetKeyDown(<span style=""color:#2b91af;"">KeyCode</span>.Escape))
  684. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">SampleSelector</span>.SelectedSample.DestroyUnityObject();
  685. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Stop&nbsp;typing&nbsp;if&nbsp;some&nbsp;time&nbsp;passed&nbsp;without&nbsp;typing</span>
  686. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(typing)
  687. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  688. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;typingTimer&nbsp;=&nbsp;<span style=""color:#2b91af;"">DateTime</span>.UtcNow;
  689. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;timeDiff&nbsp;=&nbsp;typingTimer&nbsp;-&nbsp;lastTypingTime;
  690. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(timeDiff&nbsp;&gt;=&nbsp;TYPING_TIMER_LENGTH)
  691. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  692. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.Emit(<span style=""color:#a31515;"">&quot;stop&nbsp;typing&quot;</span>);
  693. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typing&nbsp;=&nbsp;<span style=""color:blue;"">false</span>;
  694. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  695. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  696. &nbsp;&nbsp;&nbsp;&nbsp;}
  697. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  698. &nbsp;&nbsp;&nbsp;&nbsp;{
  699. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>(State)
  700. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  701. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">ChatStates</span>.Login:&nbsp;DrawLoginScreen();&nbsp;<span style=""color:blue;"">break</span>;
  702. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">ChatStates</span>.Chat:&nbsp;DrawChatScreen();&nbsp;<span style=""color:blue;"">break</span>;
  703. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  704. &nbsp;&nbsp;&nbsp;&nbsp;}
  705. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  706. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Chat&nbsp;Logic
  707. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  708. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;from&nbsp;an&nbsp;OnGUI&nbsp;event&nbsp;to&nbsp;draw&nbsp;the&nbsp;Login&nbsp;Screen.</span>
  709. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  710. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;DrawLoginScreen()
  711. &nbsp;&nbsp;&nbsp;&nbsp;{
  712. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  713. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  714. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  715. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  716. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawCenteredText(<span style=""color:#a31515;"">&quot;What&#39;s&nbsp;your&nbsp;nickname?&quot;</span>);
  717. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userName&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(userName);
  718. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Join&quot;</span>))
  719. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetUserName();
  720. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  721. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  722. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  723. &nbsp;&nbsp;&nbsp;&nbsp;}
  724. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  725. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;from&nbsp;an&nbsp;OnGUI&nbsp;event&nbsp;to&nbsp;draw&nbsp;the&nbsp;Chat&nbsp;Screen.</span>
  726. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  727. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;DrawChatScreen()
  728. &nbsp;&nbsp;&nbsp;&nbsp;{
  729. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  730. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  731. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  732. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPos&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginScrollView(scrollPos);
  733. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(chatLog,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.ExpandWidth(<span style=""color:blue;"">true</span>),&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.ExpandHeight(<span style=""color:blue;"">true</span>));
  734. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndScrollView();
  735. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;typing&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  736. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(typingUsers.Count&nbsp;&gt;&nbsp;0)
  737. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  738. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typing&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&quot;</span>,&nbsp;typingUsers[0]);
  739. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;1;&nbsp;i&nbsp;&lt;&nbsp;typingUsers.Count;&nbsp;++i)
  740. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typing&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;,&nbsp;{0}&quot;</span>,&nbsp;typingUsers[i]);
  741. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(typingUsers.Count&nbsp;==&nbsp;1)
  742. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typing&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;&nbsp;is&nbsp;typing!&quot;</span>;
  743. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  744. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typing&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;&nbsp;are&nbsp;typing!&quot;</span>;
  745. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  746. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(typing);
  747. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Type&nbsp;here:&quot;</span>);
  748. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  749. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(message);
  750. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Send&quot;</span>,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MaxWidth(100)))
  751. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendMessage();
  752. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  753. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUI</span>.changed)
  754. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateTyping();
  755. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  756. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  757. &nbsp;&nbsp;&nbsp;&nbsp;}
  758. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;SetUserName()
  759. &nbsp;&nbsp;&nbsp;&nbsp;{
  760. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:blue;"">string</span>.IsNullOrEmpty(userName))
  761. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">return</span>;
  762. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;State&nbsp;=&nbsp;<span style=""color:#2b91af;"">ChatStates</span>.Chat;
  763. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.Emit(<span style=""color:#a31515;"">&quot;add&nbsp;user&quot;</span>,&nbsp;userName);
  764. &nbsp;&nbsp;&nbsp;&nbsp;}
  765. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;SendMessage()
  766. &nbsp;&nbsp;&nbsp;&nbsp;{
  767. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:blue;"">string</span>.IsNullOrEmpty(message))
  768. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">return</span>;
  769. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.Emit(<span style=""color:#a31515;"">&quot;new&nbsp;message&quot;</span>,&nbsp;message);
  770. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}:&nbsp;{1}\n&quot;</span>,&nbsp;userName,&nbsp;message);
  771. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  772. &nbsp;&nbsp;&nbsp;&nbsp;}
  773. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;UpdateTyping()
  774. &nbsp;&nbsp;&nbsp;&nbsp;{
  775. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(!typing)
  776. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  777. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typing&nbsp;=&nbsp;<span style=""color:blue;"">true</span>;
  778. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Manager.Socket.Emit(<span style=""color:#a31515;"">&quot;typing&quot;</span>);
  779. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  780. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lastTypingTime&nbsp;=&nbsp;<span style=""color:#2b91af;"">DateTime</span>.UtcNow;
  781. &nbsp;&nbsp;&nbsp;&nbsp;}
  782. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;addParticipantsMessage(<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;&nbsp;data)
  783. &nbsp;&nbsp;&nbsp;&nbsp;{
  784. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;numUsers&nbsp;=&nbsp;<span style=""color:#2b91af;"">Convert</span>.ToInt32(data[<span style=""color:#a31515;"">&quot;numUsers&quot;</span>]);
  785. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(numUsers&nbsp;==&nbsp;1)
  786. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;there&#39;s&nbsp;1&nbsp;participant\n&quot;</span>;
  787. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  788. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;+=&nbsp;<span style=""color:#a31515;"">&quot;there&nbsp;are&nbsp;&quot;</span>&nbsp;+&nbsp;numUsers&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;&nbsp;participants\n&quot;</span>;
  789. &nbsp;&nbsp;&nbsp;&nbsp;}
  790. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;addChatMessage(<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;&nbsp;data)
  791. &nbsp;&nbsp;&nbsp;&nbsp;{
  792. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;username&nbsp;=&nbsp;data[<span style=""color:#a31515;"">&quot;username&quot;</span>]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  793. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;msg&nbsp;=&nbsp;data[<span style=""color:#a31515;"">&quot;message&quot;</span>]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  794. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}:&nbsp;{1}\n&quot;</span>,&nbsp;username,&nbsp;msg);
  795. &nbsp;&nbsp;&nbsp;&nbsp;}
  796. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;AddChatTyping(<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;&nbsp;data)
  797. &nbsp;&nbsp;&nbsp;&nbsp;{
  798. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;username&nbsp;=&nbsp;data[<span style=""color:#a31515;"">&quot;username&quot;</span>]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  799. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typingUsers.Add(username);
  800. &nbsp;&nbsp;&nbsp;&nbsp;}
  801. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;RemoveChatTyping(<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;&nbsp;data)
  802. &nbsp;&nbsp;&nbsp;&nbsp;{
  803. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;username&nbsp;=&nbsp;data[<span style=""color:#a31515;"">&quot;username&quot;</span>]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  804. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;idx&nbsp;=&nbsp;typingUsers.FindIndex((name)&nbsp;=&gt;&nbsp;name.Equals(username));
  805. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(idx&nbsp;!=&nbsp;-1)
  806. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typingUsers.RemoveAt(idx);
  807. &nbsp;&nbsp;&nbsp;&nbsp;}
  808. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  809. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Custom&nbsp;SocketIO&nbsp;Events
  810. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnLogin(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  811. &nbsp;&nbsp;&nbsp;&nbsp;{
  812. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Welcome&nbsp;to&nbsp;Socket.IO&nbsp;Chat&nbsp;—&nbsp;\n&quot;</span>;
  813. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addParticipantsMessage(args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;);
  814. &nbsp;&nbsp;&nbsp;&nbsp;}
  815. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnNewMessage(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  816. &nbsp;&nbsp;&nbsp;&nbsp;{
  817. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addChatMessage(args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;);
  818. &nbsp;&nbsp;&nbsp;&nbsp;}
  819. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnUserJoined(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  820. &nbsp;&nbsp;&nbsp;&nbsp;{
  821. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;data&nbsp;=&nbsp;args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;;
  822. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;username&nbsp;=&nbsp;data[<span style=""color:#a31515;"">&quot;username&quot;</span>]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  823. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;joined\n&quot;</span>,&nbsp;username);
  824. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addParticipantsMessage(data);
  825. &nbsp;&nbsp;&nbsp;&nbsp;}
  826. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnUserLeft(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  827. &nbsp;&nbsp;&nbsp;&nbsp;{
  828. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;data&nbsp;=&nbsp;args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;;
  829. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;username&nbsp;=&nbsp;data[<span style=""color:#a31515;"">&quot;username&quot;</span>]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  830. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chatLog&nbsp;+=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;left\n&quot;</span>,&nbsp;username);
  831. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addParticipantsMessage(data);
  832. &nbsp;&nbsp;&nbsp;&nbsp;}
  833. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnTyping(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  834. &nbsp;&nbsp;&nbsp;&nbsp;{
  835. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddChatTyping(args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;);
  836. &nbsp;&nbsp;&nbsp;&nbsp;}
  837. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnStopTyping(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  838. &nbsp;&nbsp;&nbsp;&nbsp;{
  839. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RemoveChatTyping(args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;);
  840. &nbsp;&nbsp;&nbsp;&nbsp;}
  841. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  842. }</pre>";
  843. #endregion
  844. #region SocketIOWePlaySample
  845. public static string SocketIOWePlaySample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  846. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  847. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  848. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SocketIO;
  849. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SocketIO.Events;
  850. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">SocketIOWePlaySample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  851. {
  852. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  853. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Possible&nbsp;states&nbsp;of&nbsp;the&nbsp;game.</span>
  854. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  855. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">enum</span>&nbsp;<span style=""color:#2b91af;"">States</span>
  856. &nbsp;&nbsp;&nbsp;&nbsp;{
  857. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connecting,
  858. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WaitForNick,
  859. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Joined
  860. &nbsp;&nbsp;&nbsp;&nbsp;}
  861. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  862. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Controls&nbsp;that&nbsp;the&nbsp;server&nbsp;understands&nbsp;as&nbsp;a&nbsp;parameter&nbsp;in&nbsp;the&nbsp;move&nbsp;event.</span>
  863. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  864. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>[]&nbsp;controls&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:blue;"">string</span>[]&nbsp;{&nbsp;<span style=""color:#a31515;"">&quot;left&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;right&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;a&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;b&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;up&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;down&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;select&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;start&quot;</span>&nbsp;};
  865. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  866. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Ratio&nbsp;of&nbsp;the&nbsp;drawn&nbsp;GUI&nbsp;texture&nbsp;from&nbsp;the&nbsp;screen</span>
  867. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  868. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">const</span>&nbsp;<span style=""color:blue;"">float</span>&nbsp;ratio&nbsp;=&nbsp;1.5f;
  869. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  870. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;How&nbsp;many&nbsp;messages&nbsp;to&nbsp;keep.</span>
  871. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  872. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">int</span>&nbsp;MaxMessages&nbsp;=&nbsp;50;
  873. &nbsp;&nbsp;&nbsp;&nbsp;
  874. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  875. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Current&nbsp;state&nbsp;of&nbsp;the&nbsp;game.</span>
  876. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  877. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">States</span>&nbsp;State;
  878. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  879. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;root(&quot;/&quot;)&nbsp;Socket&nbsp;instance.</span>
  880. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  881. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">Socket</span>&nbsp;Socket;
  882. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  883. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;user-selected&nbsp;nickname.</span>
  884. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  885. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;Nick&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  886. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  887. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;message&nbsp;that&nbsp;the&nbsp;user&nbsp;want&nbsp;to&nbsp;send&nbsp;to&nbsp;the&nbsp;chat.</span>
  888. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  889. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;messageToSend&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  890. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  891. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;How&nbsp;many&nbsp;user&nbsp;connected&nbsp;to&nbsp;the&nbsp;server.</span>
  892. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  893. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">int</span>&nbsp;connections;
  894. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  895. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Local&nbsp;and&nbsp;server&nbsp;sent&nbsp;messages.</span>
  896. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  897. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">List</span>&lt;<span style=""color:blue;"">string</span>&gt;&nbsp;messages&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">List</span>&lt;<span style=""color:blue;"">string</span>&gt;();
  898. &nbsp;&nbsp;&nbsp;&nbsp;
  899. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  900. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;chat&nbsp;scroll&nbsp;position.</span>
  901. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  902. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">Vector2</span>&nbsp;scrollPos;
  903. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  904. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;decoded&nbsp;texture&nbsp;from&nbsp;the&nbsp;server&nbsp;sent&nbsp;binary&nbsp;data</span>
  905. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  906. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>&nbsp;FrameTexture;
  907. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  908. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  909. &nbsp;&nbsp;&nbsp;&nbsp;{
  910. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Change&nbsp;an&nbsp;option&nbsp;to&nbsp;show&nbsp;how&nbsp;it&nbsp;should&nbsp;be&nbsp;done</span>
  911. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">SocketOptions</span>&nbsp;options&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">SocketOptions</span>();
  912. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options.AutoConnect&nbsp;=&nbsp;<span style=""color:blue;"">false</span>;
  913. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;SocketManager&nbsp;instance</span>
  914. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;manager&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">SocketManager</span>(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;http://io.weplay.io/socket.io/&quot;</span>),&nbsp;options);
  915. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Keep&nbsp;a&nbsp;reference&nbsp;to&nbsp;the&nbsp;root&nbsp;namespace</span>
  916. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket&nbsp;=&nbsp;manager.Socket;
  917. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;up&nbsp;our&nbsp;event&nbsp;handlers.</span>
  918. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#2b91af;"">SocketIOEventTypes</span>.Connect,&nbsp;OnConnected);
  919. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;joined&quot;</span>,&nbsp;OnJoined);
  920. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;connections&quot;</span>,&nbsp;OnConnections);
  921. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;join&quot;</span>,&nbsp;OnJoin);
  922. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;move&quot;</span>,&nbsp;OnMove);
  923. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;message&quot;</span>,&nbsp;OnMessage);
  924. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;reload&quot;</span>,&nbsp;OnReload);
  925. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Don&#39;t&nbsp;waste&nbsp;cpu&nbsp;cycles&nbsp;on&nbsp;decoding&nbsp;the&nbsp;payload,&nbsp;we&nbsp;are&nbsp;expecting&nbsp;only&nbsp;binary&nbsp;data&nbsp;with&nbsp;this&nbsp;event,</span>
  926. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;&nbsp;and&nbsp;we&nbsp;can&nbsp;access&nbsp;it&nbsp;through&nbsp;the&nbsp;packet&#39;s&nbsp;Attachments&nbsp;property.</span>
  927. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#a31515;"">&quot;frame&quot;</span>,&nbsp;OnFrame,&nbsp;<span style=""color:green;"">/*autoDecodePayload:*/</span>&nbsp;<span style=""color:blue;"">false</span>);
  928. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Add&nbsp;error&nbsp;handler,&nbsp;so&nbsp;we&nbsp;can&nbsp;display&nbsp;it</span>
  929. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.On(<span style=""color:#2b91af;"">SocketIOEventTypes</span>.Error,&nbsp;OnError);
  930. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;We&nbsp;set&nbsp;SocketOptions&#39;&nbsp;AutoConnect&nbsp;to&nbsp;false,&nbsp;so&nbsp;we&nbsp;have&nbsp;to&nbsp;call&nbsp;it&nbsp;manually.</span>
  931. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;manager.Open();
  932. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;We&nbsp;are&nbsp;connecting&nbsp;to&nbsp;the&nbsp;server.</span>
  933. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;State&nbsp;=&nbsp;<span style=""color:#2b91af;"">States</span>.Connecting;
  934. &nbsp;&nbsp;&nbsp;&nbsp;}
  935. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  936. &nbsp;&nbsp;&nbsp;&nbsp;{
  937. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Leaving&nbsp;this&nbsp;sample,&nbsp;close&nbsp;the&nbsp;socket</span>
  938. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.Manager.Close();
  939. &nbsp;&nbsp;&nbsp;&nbsp;}
  940. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Update()
  941. &nbsp;&nbsp;&nbsp;&nbsp;{
  942. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Go&nbsp;back&nbsp;to&nbsp;the&nbsp;demo&nbsp;selector</span>
  943. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">Input</span>.GetKeyDown(<span style=""color:#2b91af;"">KeyCode</span>.Escape))
  944. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">SampleSelector</span>.SelectedSample.DestroyUnityObject();
  945. &nbsp;&nbsp;&nbsp;&nbsp;}
  946. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  947. &nbsp;&nbsp;&nbsp;&nbsp;{
  948. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>(State)
  949. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  950. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">States</span>.Connecting:
  951. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  952. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  953. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  954. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  955. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawCenteredText(<span style=""color:#a31515;"">&quot;Connecting&nbsp;to&nbsp;the&nbsp;server...&quot;</span>);
  956. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  957. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  958. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  959. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  960. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  961. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">States</span>.WaitForNick:
  962. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  963. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  964. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DrawLoginScreen();
  965. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  966. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  967. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">States</span>.Joined:
  968. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  969. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  970. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;Texture</span>
  971. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(FrameTexture&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  972. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Box(FrameTexture);
  973. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DrawControls();
  974. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DrawChat();
  975. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  976. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  977. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  978. &nbsp;&nbsp;&nbsp;&nbsp;}
  979. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  980. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Helper&nbsp;Functions
  981. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  982. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;from&nbsp;an&nbsp;OnGUI&nbsp;event&nbsp;to&nbsp;draw&nbsp;the&nbsp;Login&nbsp;Screen.</span>
  983. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  984. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;DrawLoginScreen()
  985. &nbsp;&nbsp;&nbsp;&nbsp;{
  986. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  987. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  988. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawCenteredText(<span style=""color:#a31515;"">&quot;What&#39;s&nbsp;your&nbsp;nickname?&quot;</span>);
  989. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nick&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(Nick);
  990. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Join&quot;</span>))
  991. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Join();
  992. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  993. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  994. &nbsp;&nbsp;&nbsp;&nbsp;}
  995. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;DrawControls()
  996. &nbsp;&nbsp;&nbsp;&nbsp;{
  997. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  998. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Controls:&quot;</span>);
  999. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;controls.Length;&nbsp;++i)
  1000. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(controls[i]))
  1001. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.Emit(<span style=""color:#a31515;"">&quot;move&quot;</span>,&nbsp;controls[i]);
  1002. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;&nbsp;Connections:&nbsp;&quot;</span>&nbsp;+&nbsp;connections);
  1003. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1004. &nbsp;&nbsp;&nbsp;&nbsp;}
  1005. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;DrawChat(<span style=""color:blue;"">bool</span>&nbsp;withInput&nbsp;=&nbsp;<span style=""color:blue;"">true</span>)
  1006. &nbsp;&nbsp;&nbsp;&nbsp;{
  1007. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  1008. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;the&nbsp;messages</span>
  1009. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPos&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginScrollView(scrollPos,&nbsp;<span style=""color:blue;"">false</span>,&nbsp;<span style=""color:blue;"">false</span>);
  1010. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;messages.Count;&nbsp;++i)
  1011. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(messages[i],&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(<span style=""color:#2b91af;"">Screen</span>.width));
  1012. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndScrollView();
  1013. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(withInput)
  1014. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1015. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Your&nbsp;message:&nbsp;&quot;</span>);
  1016. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1017. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messageToSend&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(messageToSend);
  1018. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Send&quot;</span>,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MaxWidth(100)))
  1019. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendMessage();
  1020. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1021. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1022. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  1023. &nbsp;&nbsp;&nbsp;&nbsp;}
  1024. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1025. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Add&nbsp;a&nbsp;message&nbsp;to&nbsp;the&nbsp;message&nbsp;log</span>
  1026. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1027. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;param&nbsp;name=</span><span style=""color:gray;"">&quot;msg&quot;</span><span style=""color:gray;"">&gt;&lt;/param&gt;</span>
  1028. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;AddMessage(<span style=""color:blue;"">string</span>&nbsp;msg)
  1029. &nbsp;&nbsp;&nbsp;&nbsp;{
  1030. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Insert(0,&nbsp;msg);
  1031. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(messages.Count&nbsp;&gt;&nbsp;MaxMessages)
  1032. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.RemoveRange(MaxMessages,&nbsp;messages.Count&nbsp;-&nbsp;MaxMessages);
  1033. &nbsp;&nbsp;&nbsp;&nbsp;}
  1034. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1035. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Send&nbsp;a&nbsp;chat&nbsp;message.&nbsp;The&nbsp;message&nbsp;must&nbsp;be&nbsp;in&nbsp;the&nbsp;messageToSend&nbsp;field.</span>
  1036. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1037. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;SendMessage()
  1038. &nbsp;&nbsp;&nbsp;&nbsp;{
  1039. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:blue;"">string</span>.IsNullOrEmpty(messageToSend))
  1040. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">return</span>;
  1041. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.Emit(<span style=""color:#a31515;"">&quot;message&quot;</span>,&nbsp;messageToSend);
  1042. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}:&nbsp;{1}&quot;</span>,&nbsp;Nick,&nbsp;messageToSend));
  1043. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messageToSend&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1044. &nbsp;&nbsp;&nbsp;&nbsp;}
  1045. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1046. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Join&nbsp;to&nbsp;the&nbsp;game&nbsp;with&nbsp;the&nbsp;nickname&nbsp;stored&nbsp;in&nbsp;the&nbsp;Nick&nbsp;field.</span>
  1047. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1048. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Join()
  1049. &nbsp;&nbsp;&nbsp;&nbsp;{
  1050. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.SetString(<span style=""color:#a31515;"">&quot;Nick&quot;</span>,&nbsp;Nick);
  1051. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.Emit(<span style=""color:#a31515;"">&quot;join&quot;</span>,&nbsp;Nick);
  1052. &nbsp;&nbsp;&nbsp;&nbsp;}
  1053. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1054. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Reload&nbsp;the&nbsp;game.</span>
  1055. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1056. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Reload()
  1057. &nbsp;&nbsp;&nbsp;&nbsp;{
  1058. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameTexture&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  1059. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(Socket&nbsp;!=&nbsp;<span style=""color:blue;"">null</span>)
  1060. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1061. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket.Manager.Close();
  1062. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  1063. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start();
  1064. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1065. &nbsp;&nbsp;&nbsp;&nbsp;}
  1066. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1067. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;SocketIO&nbsp;Events
  1068. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1069. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Socket&nbsp;connected&nbsp;event.</span>
  1070. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1071. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnConnected(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1072. &nbsp;&nbsp;&nbsp;&nbsp;{
  1073. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">PlayerPrefs</span>.HasKey(<span style=""color:#a31515;"">&quot;Nick&quot;</span>))
  1074. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1075. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nick&nbsp;=&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.GetString(<span style=""color:#a31515;"">&quot;Nick&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;NickName&quot;</span>);
  1076. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Join();
  1077. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1078. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  1079. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;State&nbsp;=&nbsp;<span style=""color:#2b91af;"">States</span>.WaitForNick;
  1080. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(<span style=""color:#a31515;"">&quot;connected&quot;</span>);
  1081. &nbsp;&nbsp;&nbsp;&nbsp;}
  1082. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1083. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Local&nbsp;player&nbsp;joined&nbsp;after&nbsp;sending&nbsp;a&nbsp;&#39;join&#39;&nbsp;event</span>
  1084. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1085. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnJoined(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1086. &nbsp;&nbsp;&nbsp;&nbsp;{
  1087. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;State&nbsp;=&nbsp;<span style=""color:#2b91af;"">States</span>.Joined;
  1088. &nbsp;&nbsp;&nbsp;&nbsp;}
  1089. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1090. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Server&nbsp;sent&nbsp;us&nbsp;a&nbsp;&#39;reload&#39;&nbsp;event.</span>
  1091. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1092. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnReload(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1093. &nbsp;&nbsp;&nbsp;&nbsp;{
  1094. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reload();
  1095. &nbsp;&nbsp;&nbsp;&nbsp;}
  1096. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1097. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Someone&nbsp;wrote&nbsp;a&nbsp;message&nbsp;to&nbsp;the&nbsp;chat.</span>
  1098. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1099. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnMessage(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1100. &nbsp;&nbsp;&nbsp;&nbsp;{
  1101. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(args.Length&nbsp;==&nbsp;1)
  1102. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>);
  1103. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  1104. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}:&nbsp;{1}&quot;</span>,&nbsp;args[1],&nbsp;args[0]));
  1105. &nbsp;&nbsp;&nbsp;&nbsp;}
  1106. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1107. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Someone&nbsp;(including&nbsp;us)&nbsp;pressed&nbsp;a&nbsp;button.</span>
  1108. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1109. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnMove(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1110. &nbsp;&nbsp;&nbsp;&nbsp;{
  1111. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;pressed&nbsp;{1}&quot;</span>,&nbsp;args[1],&nbsp;args[0]));
  1112. &nbsp;&nbsp;&nbsp;&nbsp;}
  1113. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1114. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Someone&nbsp;joined&nbsp;to&nbsp;the&nbsp;game</span>
  1115. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1116. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnJoin(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1117. &nbsp;&nbsp;&nbsp;&nbsp;{
  1118. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;loc&nbsp;=&nbsp;args.Length&nbsp;&gt;&nbsp;1&nbsp;?&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;({0})&quot;</span>,&nbsp;args[1])&nbsp;:&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1119. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;joined&nbsp;{1}&quot;</span>,&nbsp;args[0],&nbsp;loc));
  1120. &nbsp;&nbsp;&nbsp;&nbsp;}
  1121. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1122. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;How&nbsp;many&nbsp;players&nbsp;are&nbsp;connected&nbsp;to&nbsp;the&nbsp;game.</span>
  1123. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1124. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnConnections(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1125. &nbsp;&nbsp;&nbsp;&nbsp;{
  1126. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connections&nbsp;=&nbsp;<span style=""color:#2b91af;"">Convert</span>.ToInt32(args[0]);
  1127. &nbsp;&nbsp;&nbsp;&nbsp;}
  1128. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1129. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;server&nbsp;sent&nbsp;us&nbsp;a&nbsp;new&nbsp;picture&nbsp;to&nbsp;draw&nbsp;the&nbsp;game.</span>
  1130. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1131. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnFrame(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1132. &nbsp;&nbsp;&nbsp;&nbsp;{
  1133. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(State&nbsp;!=&nbsp;<span style=""color:#2b91af;"">States</span>.Joined)
  1134. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">return</span>;
  1135. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(FrameTexture&nbsp;==&nbsp;<span style=""color:blue;"">null</span>)
  1136. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1137. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameTexture&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Texture2D</span>(0,&nbsp;0,&nbsp;<span style=""color:#2b91af;"">TextureFormat</span>.RGBA32,&nbsp;<span style=""color:blue;"">false</span>);
  1138. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameTexture.filterMode&nbsp;=&nbsp;<span style=""color:#2b91af;"">FilterMode</span>.Point;
  1139. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1140. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Binary&nbsp;data&nbsp;usage&nbsp;case&nbsp;1&nbsp;-&nbsp;using&nbsp;directly&nbsp;the&nbsp;Attachments&nbsp;property:</span>
  1141. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">byte</span>[]&nbsp;data&nbsp;=&nbsp;packet.Attachments[0];
  1142. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Binary&nbsp;data&nbsp;usage&nbsp;case&nbsp;2&nbsp;-&nbsp;using&nbsp;the&nbsp;packet&#39;s&nbsp;ReconstructAttachmentAsIndex()&nbsp;function</span>
  1143. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">/*packet.ReconstructAttachmentAsIndex();</span>
  1144. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;args&nbsp;=&nbsp;packet.Decode(socket.Manager.Encoder);</span>
  1145. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&nbsp;=&nbsp;packet.Attachments[Convert.ToInt32(args[0])];*/</span>
  1146. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Binary&nbsp;data&nbsp;usage&nbsp;case&nbsp;3&nbsp;-&nbsp;using&nbsp;the&nbsp;packet&#39;s&nbsp;ReconstructAttachmentAsBase64()&nbsp;function</span>
  1147. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">/*packet.ReconstructAttachmentAsBase64();</span>
  1148. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;args&nbsp;=&nbsp;packet.Decode(socket.Manager.Encoder);</span>
  1149. <span style=""color:green;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&nbsp;=&nbsp;Convert.FromBase64String(args[0]&nbsp;as&nbsp;string);*/</span>
  1150. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Load&nbsp;the&nbsp;server&nbsp;sent&nbsp;picture</span>
  1151. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrameTexture.LoadImage(data);
  1152. &nbsp;&nbsp;&nbsp;&nbsp;}
  1153. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1154. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;on&nbsp;local&nbsp;or&nbsp;remote&nbsp;error.</span>
  1155. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1156. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnError(<span style=""color:#2b91af;"">Socket</span>&nbsp;socket,&nbsp;<span style=""color:#2b91af;"">Packet</span>&nbsp;packet,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1157. &nbsp;&nbsp;&nbsp;&nbsp;{
  1158. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddMessage(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;--ERROR&nbsp;-&nbsp;{0}&quot;</span>,&nbsp;args[0].ToString()));
  1159. &nbsp;&nbsp;&nbsp;&nbsp;}
  1160. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1161. }</pre>";
  1162. #endregion
  1163. #region SignalR SimpleStreamingSample
  1164. public static string SignalR_SimpleStreamingSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  1165. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  1166. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR;
  1167. <span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">SimpleStreamingSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  1168. {
  1169. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">readonly</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>&nbsp;URI&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;http://besthttpsignalr.azurewebsites.net/streaming-connection&quot;</span>);
  1170. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1171. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Reference&nbsp;to&nbsp;the&nbsp;SignalR&nbsp;Connection</span>
  1172. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1173. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Connection</span>&nbsp;signalRConnection;
  1174. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1175. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Helper&nbsp;GUI&nbsp;class&nbsp;to&nbsp;handle&nbsp;and&nbsp;display&nbsp;a&nbsp;string-list</span>
  1176. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1177. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>&nbsp;messages&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>();
  1178. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  1179. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  1180. &nbsp;&nbsp;&nbsp;&nbsp;{
  1181. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;SignalR&nbsp;connection</span>
  1182. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Connection</span>(URI);
  1183. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;set&nbsp;event&nbsp;handlers</span>
  1184. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnNonHubMessage&nbsp;+=&nbsp;signalRConnection_OnNonHubMessage;
  1185. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnStateChanged&nbsp;+=&nbsp;signalRConnection_OnStateChanged;
  1186. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnError&nbsp;+=&nbsp;signalRConnection_OnError;
  1187. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;connecting&nbsp;to&nbsp;the&nbsp;server</span>
  1188. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  1189. &nbsp;&nbsp;&nbsp;&nbsp;}
  1190. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  1191. &nbsp;&nbsp;&nbsp;&nbsp;{
  1192. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;the&nbsp;connection&nbsp;when&nbsp;the&nbsp;sample&nbsp;is&nbsp;closed</span>
  1193. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  1194. &nbsp;&nbsp;&nbsp;&nbsp;}
  1195. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  1196. &nbsp;&nbsp;&nbsp;&nbsp;{
  1197. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  1198. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1199. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Messages&quot;</span>);
  1200. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1201. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1202. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Draw(<span style=""color:#2b91af;"">Screen</span>.width&nbsp;-&nbsp;20,&nbsp;0);
  1203. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1204. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  1205. &nbsp;&nbsp;&nbsp;&nbsp;}
  1206. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1207. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;SignalR&nbsp;Events
  1208. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1209. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Handle&nbsp;Server-sent&nbsp;messages</span>
  1210. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1211. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnNonHubMessage(<span style=""color:#2b91af;"">Connection</span>&nbsp;connection,&nbsp;<span style=""color:blue;"">object</span>&nbsp;data)
  1212. &nbsp;&nbsp;&nbsp;&nbsp;{
  1213. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:#a31515;"">&quot;[Server&nbsp;Message]&nbsp;&quot;</span>&nbsp;+&nbsp;data.ToString());
  1214. &nbsp;&nbsp;&nbsp;&nbsp;}
  1215. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1216. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Display&nbsp;state&nbsp;changes</span>
  1217. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1218. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnStateChanged(<span style=""color:#2b91af;"">Connection</span>&nbsp;connection,&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>&nbsp;oldState,&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>&nbsp;newState)
  1219. &nbsp;&nbsp;&nbsp;&nbsp;{
  1220. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[State&nbsp;Change]&nbsp;{0}&nbsp;=&gt;&nbsp;{1}&quot;</span>,&nbsp;oldState,&nbsp;newState));
  1221. &nbsp;&nbsp;&nbsp;&nbsp;}
  1222. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1223. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Display&nbsp;errors.</span>
  1224. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1225. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnError(<span style=""color:#2b91af;"">Connection</span>&nbsp;connection,&nbsp;<span style=""color:blue;"">string</span>&nbsp;error)
  1226. &nbsp;&nbsp;&nbsp;&nbsp;{
  1227. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:#a31515;"">&quot;[Error]&nbsp;&quot;</span>&nbsp;+&nbsp;error);
  1228. &nbsp;&nbsp;&nbsp;&nbsp;}
  1229. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1230. }</pre>";
  1231. #endregion
  1232. #region SignalR ConnectionAPISample
  1233. public static string SignalR_ConnectionAPISample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  1234. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  1235. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  1236. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR;
  1237. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.Cookies;
  1238. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">ConnectionAPISample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  1239. {
  1240. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">readonly</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>&nbsp;URI&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;http://besthttpsignalr.azurewebsites.net/raw-connection/&quot;</span>);
  1241. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1242. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Possible&nbsp;message&nbsp;types&nbsp;that&nbsp;the&nbsp;client&nbsp;can&nbsp;send&nbsp;to&nbsp;the&nbsp;server</span>
  1243. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1244. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">enum</span>&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>
  1245. &nbsp;&nbsp;&nbsp;&nbsp;{
  1246. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;0</span>
  1247. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Broadcast,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;1</span>
  1248. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Join,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;2</span>
  1249. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrivateMessage,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;3</span>
  1250. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddToGroup,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;4</span>
  1251. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RemoveFromGroup,&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;5</span>
  1252. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendToGroup,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;6</span>
  1253. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BroadcastExceptMe,&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;7</span>
  1254. &nbsp;&nbsp;&nbsp;&nbsp;}
  1255. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  1256. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1257. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Reference&nbsp;to&nbsp;the&nbsp;SignalR&nbsp;Connection</span>
  1258. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1259. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Connection</span>&nbsp;signalRConnection;
  1260. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Input&nbsp;strings</span>
  1261. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;ToEveryBodyText&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1262. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;ToMeText&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1263. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;PrivateMessageText&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1264. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;PrivateMessageUserOrGroupName&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1265. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>&nbsp;messages&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>();
  1266. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1267. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  1268. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  1269. &nbsp;&nbsp;&nbsp;&nbsp;{
  1270. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;a&nbsp;&quot;user&quot;&nbsp;cookie&nbsp;if&nbsp;we&nbsp;previously&nbsp;used&nbsp;the&nbsp;&#39;Enter&nbsp;Name&#39;&nbsp;button.</span>
  1271. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;The&nbsp;server&nbsp;will&nbsp;set&nbsp;this&nbsp;username&nbsp;to&nbsp;the&nbsp;new&nbsp;connection.</span>
  1272. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">PlayerPrefs</span>.HasKey(<span style=""color:#a31515;"">&quot;userName&quot;</span>))
  1273. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">CookieJar</span>.SaveLocal(URI,&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Cookie</span>(<span style=""color:#a31515;"">&quot;user&quot;</span>,&nbsp;<span style=""color:#2b91af;"">PlayerPrefs</span>.GetString(<span style=""color:#a31515;"">&quot;userName&quot;</span>)));
  1274. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Connection</span>(URI);
  1275. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;to&nbsp;serialize&nbsp;the&nbsp;Message&nbsp;class,&nbsp;set&nbsp;a&nbsp;more&nbsp;advanced&nbsp;json&nbsp;encoder</span>
  1276. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.JsonEncoder&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;BestHTTP.SignalR.JsonEncoders.<span style=""color:#2b91af;"">LitJsonEncoder</span>();
  1277. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;set&nbsp;up&nbsp;event&nbsp;handlers</span>
  1278. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnStateChanged&nbsp;+=&nbsp;signalRConnection_OnStateChanged;
  1279. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnNonHubMessage&nbsp;+=&nbsp;signalRConnection_OnGeneralMessage;
  1280. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;to&nbsp;connect&nbsp;to&nbsp;the&nbsp;server.</span>
  1281. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  1282. &nbsp;&nbsp;&nbsp;&nbsp;}
  1283. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1284. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Draw&nbsp;the&nbsp;gui.</span>
  1285. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Get&nbsp;input&nbsp;strings.</span>
  1286. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Handle&nbsp;function&nbsp;calls.</span>
  1287. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1288. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  1289. &nbsp;&nbsp;&nbsp;&nbsp;{
  1290. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  1291. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1292. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  1293. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;To&nbsp;Everybody
  1294. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;To&nbsp;Everybody&quot;</span>);
  1295. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1296. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1297. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ToEveryBodyText&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(ToEveryBodyText,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  1298. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Broadcast&quot;</span>))
  1299. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Broadcast(ToEveryBodyText);
  1300. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Broadcast&nbsp;(All&nbsp;Except&nbsp;Me)&quot;</span>))
  1301. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BroadcastExceptMe(ToEveryBodyText);
  1302. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Enter&nbsp;Name&quot;</span>))
  1303. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EnterName(ToEveryBodyText);
  1304. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Join&nbsp;Group&quot;</span>))
  1305. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JoinGroup(ToEveryBodyText);
  1306. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Leave&nbsp;Group&quot;</span>))
  1307. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LeaveGroup(ToEveryBodyText);
  1308. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1309. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1310. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;To&nbsp;Me
  1311. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;To&nbsp;Me&quot;</span>);
  1312. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1313. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ToMeText&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(ToMeText,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  1314. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Send&nbsp;to&nbsp;me&quot;</span>))
  1315. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendToMe(ToMeText);
  1316. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1317. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1318. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Message
  1319. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Private&nbsp;Message&quot;</span>);
  1320. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1321. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Message:&quot;</span>);
  1322. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrivateMessageText&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(PrivateMessageText,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  1323. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;User&nbsp;or&nbsp;Group&nbsp;name:&quot;</span>);
  1324. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrivateMessageUserOrGroupName&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(PrivateMessageUserOrGroupName,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  1325. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Send&nbsp;to&nbsp;user&quot;</span>))
  1326. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendToUser(PrivateMessageUserOrGroupName,&nbsp;PrivateMessageText);
  1327. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Send&nbsp;to&nbsp;group&quot;</span>))
  1328. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendToGroup(PrivateMessageUserOrGroupName,&nbsp;PrivateMessageText);
  1329. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1330. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1331. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1332. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(signalRConnection.State&nbsp;==&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>.Closed)
  1333. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1334. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Start&nbsp;Connection&quot;</span>))
  1335. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  1336. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1337. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Stop&nbsp;Connection&quot;</span>))
  1338. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  1339. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1340. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Draw&nbsp;the&nbsp;messages</span>
  1341. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Messages&quot;</span>);
  1342. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1343. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1344. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Draw(<span style=""color:#2b91af;"">Screen</span>.width&nbsp;-&nbsp;20,&nbsp;0);
  1345. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1346. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  1347. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  1348. &nbsp;&nbsp;&nbsp;&nbsp;}
  1349. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  1350. &nbsp;&nbsp;&nbsp;&nbsp;{
  1351. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;the&nbsp;connection&nbsp;when&nbsp;the&nbsp;sample&nbsp;is&nbsp;closed</span>
  1352. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  1353. &nbsp;&nbsp;&nbsp;&nbsp;}
  1354. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1355. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;SignalR&nbsp;Events
  1356. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1357. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Handle&nbsp;non-hub&nbsp;messages</span>
  1358. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1359. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnGeneralMessage(<span style=""color:#2b91af;"">Connection</span>&nbsp;manager,&nbsp;<span style=""color:blue;"">object</span>&nbsp;data)
  1360. &nbsp;&nbsp;&nbsp;&nbsp;{
  1361. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;For&nbsp;now,&nbsp;just&nbsp;create&nbsp;a&nbsp;Json&nbsp;string&nbsp;from&nbsp;the&nbsp;sent&nbsp;data&nbsp;again</span>
  1362. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;reencoded&nbsp;=&nbsp;BestHTTP.JSON.<span style=""color:#2b91af;"">Json</span>.Encode(data);
  1363. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1364. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;and&nbsp;display&nbsp;it</span>
  1365. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:#a31515;"">&quot;[Server&nbsp;Message]&nbsp;&quot;</span>&nbsp;+&nbsp;reencoded);
  1366. &nbsp;&nbsp;&nbsp;&nbsp;}
  1367. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnStateChanged(<span style=""color:#2b91af;"">Connection</span>&nbsp;manager,&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>&nbsp;oldState,&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>&nbsp;newState)
  1368. &nbsp;&nbsp;&nbsp;&nbsp;{
  1369. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;display&nbsp;state&nbsp;changes</span>
  1370. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[State&nbsp;Change]&nbsp;{0}&nbsp;=&gt;&nbsp;{1}&quot;</span>,&nbsp;oldState.ToString(),&nbsp;newState.ToString()));
  1371. &nbsp;&nbsp;&nbsp;&nbsp;}
  1372. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1373. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;To&nbsp;EveryBody&nbsp;Functions
  1374. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1375. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Broadcast&nbsp;a&nbsp;message&nbsp;to&nbsp;all&nbsp;connected&nbsp;clients</span>
  1376. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1377. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Broadcast(<span style=""color:blue;"">string</span>&nbsp;text)
  1378. &nbsp;&nbsp;&nbsp;&nbsp;{
  1379. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.Broadcast,&nbsp;Value&nbsp;=&nbsp;text&nbsp;});
  1380. &nbsp;&nbsp;&nbsp;&nbsp;}
  1381. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1382. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Broadcast&nbsp;a&nbsp;message&nbsp;to&nbsp;all&nbsp;connected&nbsp;clients,&nbsp;except&nbsp;this&nbsp;client</span>
  1383. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1384. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;BroadcastExceptMe(<span style=""color:blue;"">string</span>&nbsp;text)
  1385. &nbsp;&nbsp;&nbsp;&nbsp;{
  1386. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.BroadcastExceptMe,&nbsp;Value&nbsp;=&nbsp;text&nbsp;});
  1387. &nbsp;&nbsp;&nbsp;&nbsp;}
  1388. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1389. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;SaveLocal&nbsp;a&nbsp;name&nbsp;for&nbsp;this&nbsp;connection.</span>
  1390. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1391. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;EnterName(<span style=""color:blue;"">string</span>&nbsp;name)
  1392. &nbsp;&nbsp;&nbsp;&nbsp;{
  1393. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.Join,&nbsp;Value&nbsp;=&nbsp;name&nbsp;});
  1394. &nbsp;&nbsp;&nbsp;&nbsp;}
  1395. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1396. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Join&nbsp;to&nbsp;a&nbsp;group</span>
  1397. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1398. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;JoinGroup(<span style=""color:blue;"">string</span>&nbsp;groupName)
  1399. &nbsp;&nbsp;&nbsp;&nbsp;{
  1400. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.AddToGroup,&nbsp;Value&nbsp;=&nbsp;groupName&nbsp;});
  1401. &nbsp;&nbsp;&nbsp;&nbsp;}
  1402. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1403. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Leave&nbsp;a&nbsp;group</span>
  1404. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1405. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;LeaveGroup(<span style=""color:blue;"">string</span>&nbsp;groupName)
  1406. &nbsp;&nbsp;&nbsp;&nbsp;{
  1407. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.RemoveFromGroup,&nbsp;Value&nbsp;=&nbsp;groupName&nbsp;});
  1408. &nbsp;&nbsp;&nbsp;&nbsp;}
  1409. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1410. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;To&nbsp;Me&nbsp;Functions
  1411. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1412. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Send&nbsp;a&nbsp;message&nbsp;to&nbsp;the&nbsp;very&nbsp;same&nbsp;client&nbsp;through&nbsp;the&nbsp;server</span>
  1413. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1414. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;SendToMe(<span style=""color:blue;"">string</span>&nbsp;text)
  1415. &nbsp;&nbsp;&nbsp;&nbsp;{
  1416. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.Send,&nbsp;Value&nbsp;=&nbsp;text&nbsp;});
  1417. &nbsp;&nbsp;&nbsp;&nbsp;}
  1418. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1419. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Message&nbsp;Functions
  1420. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1421. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Send&nbsp;a&nbsp;private&nbsp;message&nbsp;to&nbsp;a&nbsp;user</span>
  1422. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1423. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;SendToUser(<span style=""color:blue;"">string</span>&nbsp;userOrGroupName,&nbsp;<span style=""color:blue;"">string</span>&nbsp;text)
  1424. &nbsp;&nbsp;&nbsp;&nbsp;{
  1425. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.PrivateMessage,&nbsp;Value&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}|{1}&quot;</span>,&nbsp;userOrGroupName,&nbsp;text)&nbsp;});
  1426. &nbsp;&nbsp;&nbsp;&nbsp;}
  1427. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1428. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Send&nbsp;a&nbsp;message&nbsp;to&nbsp;a&nbsp;group</span>
  1429. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1430. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;SendToGroup(<span style=""color:blue;"">string</span>&nbsp;userOrGroupName,&nbsp;<span style=""color:blue;"">string</span>&nbsp;text)
  1431. &nbsp;&nbsp;&nbsp;&nbsp;{
  1432. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Send(<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Type&nbsp;=&nbsp;<span style=""color:#2b91af;"">MessageTypes</span>.SendToGroup,&nbsp;Value&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}|{1}&quot;</span>,&nbsp;userOrGroupName,&nbsp;text)&nbsp;});
  1433. &nbsp;&nbsp;&nbsp;&nbsp;}
  1434. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1435. }</pre>";
  1436. #endregion
  1437. #region SignalR ConnectionStatusSample
  1438. public static string SignalR_ConnectionStatusSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  1439. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  1440. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  1441. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR;
  1442. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.Hubs;
  1443. <span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">ConnectionStatusSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  1444. {
  1445. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">readonly</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>&nbsp;URI&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;http://besthttpsignalr.azurewebsites.net/signalr&quot;</span>);
  1446. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1447. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Reference&nbsp;to&nbsp;the&nbsp;SignalR&nbsp;Connection</span>
  1448. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1449. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Connection</span>&nbsp;signalRConnection;
  1450. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>&nbsp;messages&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>();
  1451. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  1452. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  1453. &nbsp;&nbsp;&nbsp;&nbsp;{
  1454. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;StatusHub&nbsp;hub</span>
  1455. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Connection</span>(URI,&nbsp;<span style=""color:#a31515;"">&quot;StatusHub&quot;</span>);
  1456. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;General&nbsp;events</span>
  1457. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnNonHubMessage&nbsp;+=&nbsp;signalRConnection_OnNonHubMessage;
  1458. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnError&nbsp;+=&nbsp;signalRConnection_OnError;
  1459. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnStateChanged&nbsp;+=&nbsp;signalRConnection_OnStateChanged;
  1460. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;up&nbsp;a&nbsp;Callback&nbsp;for&nbsp;Hub&nbsp;events</span>
  1461. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection[<span style=""color:#a31515;"">&quot;StatusHub&quot;</span>].OnMethodCall&nbsp;+=&nbsp;statusHub_OnMethodCall;
  1462. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;server</span>
  1463. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  1464. &nbsp;&nbsp;&nbsp;&nbsp;}
  1465. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  1466. &nbsp;&nbsp;&nbsp;&nbsp;{
  1467. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;the&nbsp;connection&nbsp;when&nbsp;we&nbsp;are&nbsp;closing&nbsp;the&nbsp;sample</span>
  1468. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  1469. &nbsp;&nbsp;&nbsp;&nbsp;}
  1470. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  1471. &nbsp;&nbsp;&nbsp;&nbsp;{
  1472. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  1473. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1474. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1475. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;START&quot;</span>)&nbsp;&amp;&amp;&nbsp;signalRConnection.State&nbsp;!=&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>.Connected)
  1476. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  1477. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;STOP&quot;</span>)&nbsp;&amp;&amp;&nbsp;signalRConnection.State&nbsp;==&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>.Connected)
  1478. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1479. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  1480. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Clear();
  1481. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1482. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;PING&quot;</span>)&nbsp;&amp;&amp;&nbsp;signalRConnection.State&nbsp;==&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>.Connected)
  1483. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1484. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Call&nbsp;a&nbsp;Hub-method&nbsp;on&nbsp;the&nbsp;server.</span>
  1485. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection[<span style=""color:#a31515;"">&quot;StatusHub&quot;</span>].Call(<span style=""color:#a31515;"">&quot;Ping&quot;</span>);
  1486. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1487. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1488. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1489. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Connection&nbsp;Status&nbsp;Messages&quot;</span>);
  1490. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1491. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1492. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Draw(<span style=""color:#2b91af;"">Screen</span>.width&nbsp;-&nbsp;20,&nbsp;0);
  1493. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1494. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  1495. &nbsp;&nbsp;&nbsp;&nbsp;}
  1496. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1497. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;SignalR&nbsp;Events
  1498. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1499. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;on&nbsp;server-sent&nbsp;non-hub&nbsp;messages.</span>
  1500. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1501. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnNonHubMessage(<span style=""color:#2b91af;"">Connection</span>&nbsp;manager,&nbsp;<span style=""color:blue;"">object</span>&nbsp;data)
  1502. &nbsp;&nbsp;&nbsp;&nbsp;{
  1503. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:#a31515;"">&quot;[Server&nbsp;Message]&nbsp;&quot;</span>&nbsp;+&nbsp;data.ToString());
  1504. &nbsp;&nbsp;&nbsp;&nbsp;}
  1505. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1506. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;the&nbsp;SignalR&nbsp;Connection&#39;s&nbsp;state&nbsp;changes.</span>
  1507. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1508. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnStateChanged(<span style=""color:#2b91af;"">Connection</span>&nbsp;manager,&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>&nbsp;oldState,&nbsp;<span style=""color:#2b91af;"">ConnectionStates</span>&nbsp;newState)
  1509. &nbsp;&nbsp;&nbsp;&nbsp;{
  1510. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[State&nbsp;Change]&nbsp;{0}&nbsp;=&gt;&nbsp;{1}&quot;</span>,&nbsp;oldState,&nbsp;newState));
  1511. &nbsp;&nbsp;&nbsp;&nbsp;}
  1512. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1513. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;an&nbsp;error&nbsp;occures.&nbsp;The&nbsp;plugin&nbsp;may&nbsp;close&nbsp;the&nbsp;connection&nbsp;after&nbsp;this&nbsp;event.</span>
  1514. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1515. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnError(<span style=""color:#2b91af;"">Connection</span>&nbsp;manager,&nbsp;<span style=""color:blue;"">string</span>&nbsp;error)
  1516. &nbsp;&nbsp;&nbsp;&nbsp;{
  1517. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:#a31515;"">&quot;[Error]&nbsp;&quot;</span>&nbsp;+&nbsp;error);
  1518. &nbsp;&nbsp;&nbsp;&nbsp;}
  1519. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1520. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;the&nbsp;&quot;StatusHub&quot;&nbsp;hub&nbsp;wants&nbsp;to&nbsp;call&nbsp;a&nbsp;method&nbsp;on&nbsp;this&nbsp;client.</span>
  1521. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1522. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;statusHub_OnMethodCall(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:blue;"">string</span>&nbsp;method,&nbsp;<span style=""color:blue;"">params</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;args)
  1523. &nbsp;&nbsp;&nbsp;&nbsp;{
  1524. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;id&nbsp;=&nbsp;args.Length&nbsp;&gt;&nbsp;0&nbsp;?&nbsp;args[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;:&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1525. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;when&nbsp;=&nbsp;args.Length&nbsp;&gt;&nbsp;1&nbsp;?&nbsp;args[1].ToString()&nbsp;:&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1526. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>&nbsp;(method)
  1527. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1528. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#a31515;"">&quot;joined&quot;</span>:
  1529. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[{0}]&nbsp;{1}&nbsp;joined&nbsp;at&nbsp;{2}&quot;</span>,&nbsp;hub.Name,&nbsp;id,&nbsp;when));
  1530. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  1531. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#a31515;"">&quot;rejoined&quot;</span>:
  1532. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[{0}]&nbsp;{1}&nbsp;reconnected&nbsp;at&nbsp;{2}&quot;</span>,&nbsp;hub.Name,&nbsp;id,&nbsp;when));
  1533. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  1534. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#a31515;"">&quot;leave&quot;</span>:
  1535. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[{0}]&nbsp;{1}&nbsp;leaved&nbsp;at&nbsp;{2}&quot;</span>,&nbsp;hub.Name,&nbsp;id,&nbsp;when));
  1536. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  1537. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">default</span>:&nbsp;<span style=""color:green;"">//&nbsp;pong</span>
  1538. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;[{0}]&nbsp;{1}&quot;</span>,&nbsp;hub.Name,&nbsp;method));
  1539. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">break</span>;
  1540. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  1541. &nbsp;&nbsp;&nbsp;&nbsp;}
  1542. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1543. }</pre>";
  1544. #endregion
  1545. #region SignalR DemoHubSample
  1546. public static string SignalR_DemoHubSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  1547. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  1548. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR;
  1549. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.Hubs;
  1550. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.Messages;
  1551. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.JsonEncoders;
  1552. <span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">DemoHubSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  1553. {
  1554. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">readonly</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>&nbsp;URI&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;http://besthttpsignalr.azurewebsites.net/signalr&quot;</span>);
  1555. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1556. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;SignalR&nbsp;connection&nbsp;instance</span>
  1557. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1558. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Connection</span>&nbsp;signalRConnection;
  1559. &nbsp;&nbsp;&nbsp;&nbsp;
  1560. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1561. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;DemoHub&nbsp;client&nbsp;side&nbsp;implementation</span>
  1562. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1563. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">DemoHub</span>&nbsp;demoHub;
  1564. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1565. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;TypedDemoHub&nbsp;client&nbsp;side&nbsp;implementation</span>
  1566. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1567. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">TypedDemoHub</span>&nbsp;typedDemoHub;
  1568. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1569. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;&nbsp;VB&nbsp;.NET&nbsp;Hub</span>
  1570. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1571. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Hub</span>&nbsp;vbDemoHub;
  1572. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1573. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Result&nbsp;of&nbsp;the&nbsp;VB&nbsp;demo&#39;s&nbsp;ReadStateValue&nbsp;call</span>
  1574. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1575. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;vbReadStateResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1576. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Vector2</span>&nbsp;scrollPos;&nbsp;&nbsp;&nbsp;&nbsp;
  1577. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  1578. &nbsp;&nbsp;&nbsp;&nbsp;{
  1579. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;hubs</span>
  1580. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">DemoHub</span>();
  1581. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedDemoHub&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">TypedDemoHub</span>();
  1582. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vbDemoHub&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Hub</span>(<span style=""color:#a31515;"">&quot;vbdemo&quot;</span>);
  1583. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;SignalR&nbsp;connection,&nbsp;passing&nbsp;all&nbsp;the&nbsp;three&nbsp;hubs&nbsp;to&nbsp;it</span>
  1584. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Connection</span>(URI,&nbsp;demoHub,&nbsp;typedDemoHub,&nbsp;vbDemoHub);
  1585. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Switch&nbsp;from&nbsp;the&nbsp;default&nbsp;encoder&nbsp;to&nbsp;the&nbsp;LitJson&nbsp;Encoder&nbsp;becouse&nbsp;it&nbsp;can&nbsp;handle&nbsp;the&nbsp;complex&nbsp;types&nbsp;too.</span>
  1586. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.JsonEncoder&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">LitJsonEncoder</span>();
  1587. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Call&nbsp;the&nbsp;demo&nbsp;functions&nbsp;when&nbsp;we&nbsp;successfully&nbsp;connect&nbsp;to&nbsp;the&nbsp;server</span>
  1588. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnConnected&nbsp;+=&nbsp;(connection)&nbsp;=&gt;
  1589. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1590. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">var</span>&nbsp;person&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Name&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Foo&quot;</span>,&nbsp;Age&nbsp;=&nbsp;20,&nbsp;Address&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;{&nbsp;Street&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;One&nbsp;Microsoft&nbsp;Way&quot;</span>,&nbsp;Zip&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;98052&quot;</span>&nbsp;}&nbsp;};
  1591. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Call&nbsp;the&nbsp;demo&nbsp;functions</span>
  1592. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.ReportProgress(<span style=""color:#a31515;"">&quot;Long&nbsp;running&nbsp;job!&quot;</span>);
  1593. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.AddToGroups();
  1594. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.GetValue();
  1595. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.TaskWithException();
  1596. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.GenericTaskWithException();
  1597. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.SynchronousException();
  1598. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.DynamicTask();
  1599. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.PassingDynamicComplex(person);
  1600. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.SimpleArray(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:blue;"">int</span>[]&nbsp;{&nbsp;5,&nbsp;5,&nbsp;6&nbsp;});
  1601. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.ComplexType(person);
  1602. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.ComplexArray(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:blue;"">object</span>[]&nbsp;{&nbsp;person,&nbsp;person,&nbsp;person&nbsp;});
  1603. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.Overload();
  1604. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;set&nbsp;some&nbsp;state</span>
  1605. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.State[<span style=""color:#a31515;"">&quot;name&quot;</span>]&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Testing&nbsp;state!&quot;</span>;
  1606. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.ReadStateValue();
  1607. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.PlainTask();
  1608. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.GenericTaskWithContinueWith();
  1609. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedDemoHub.Echo(<span style=""color:#a31515;"">&quot;Typed&nbsp;echo&nbsp;Callback&quot;</span>);
  1610. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;vbDemo&nbsp;is&nbsp;not&nbsp;wrapped&nbsp;in&nbsp;a&nbsp;hub&nbsp;class,&nbsp;it&nbsp;would&nbsp;contain&nbsp;only&nbsp;one&nbsp;function</span>
  1611. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vbDemoHub.Call(<span style=""color:#a31515;"">&quot;readStateValue&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;vbReadStateResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Read&nbsp;some&nbsp;state&nbsp;from&nbsp;VB.NET!&nbsp;=&gt;&nbsp;{0}&quot;</span>,&nbsp;result.ReturnValue&nbsp;==&nbsp;<span style=""color:blue;"">null</span>&nbsp;?&nbsp;<span style=""color:#a31515;"">&quot;undefined&quot;</span>&nbsp;:&nbsp;result.ReturnValue.ToString()));
  1612. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};
  1613. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;opening&nbsp;the&nbsp;signalR&nbsp;connection</span>
  1614. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  1615. &nbsp;&nbsp;&nbsp;&nbsp;}
  1616. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  1617. &nbsp;&nbsp;&nbsp;&nbsp;{
  1618. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;the&nbsp;connection&nbsp;when&nbsp;we&nbsp;are&nbsp;closing&nbsp;this&nbsp;sample</span>
  1619. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  1620. &nbsp;&nbsp;&nbsp;&nbsp;}
  1621. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  1622. &nbsp;&nbsp;&nbsp;&nbsp;{
  1623. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  1624. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  1625. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPos&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginScrollView(scrollPos,&nbsp;<span style=""color:blue;"">false</span>,&nbsp;<span style=""color:blue;"">false</span>);
  1626. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  1627. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demoHub.Draw();
  1628. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedDemoHub.Draw();
  1629. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Read&nbsp;State&nbsp;Value&quot;</span>);
  1630. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1631. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1632. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(vbReadStateResult);
  1633. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1634. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1635. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  1636. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndScrollView();
  1637. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  1638. &nbsp;&nbsp;&nbsp;&nbsp;}
  1639. }
  1640. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1641. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Wrapper&nbsp;class&nbsp;of&nbsp;the&nbsp;&#39;TypedDemoHub&#39;&nbsp;hub</span>
  1642. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1643. <span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">TypedDemoHub</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">Hub</span>
  1644. {
  1645. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;typedEchoResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1646. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;typedEchoClientResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1647. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;TypedDemoHub()
  1648. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:<span style=""color:blue;"">base</span>(<span style=""color:#a31515;"">&quot;typeddemohub&quot;</span>)
  1649. &nbsp;&nbsp;&nbsp;&nbsp;{
  1650. &nbsp;&nbsp;&nbsp;&nbsp;}
  1651. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1652. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;by&nbsp;the&nbsp;Connection&nbsp;class&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;set&nbsp;up&nbsp;mappings.</span>
  1653. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1654. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">override</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Setup()
  1655. &nbsp;&nbsp;&nbsp;&nbsp;{
  1656. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Setup&nbsp;server-called&nbsp;functions</span>
  1657. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.On(<span style=""color:#a31515;"">&quot;Echo&quot;</span>,&nbsp;Echo);
  1658. &nbsp;&nbsp;&nbsp;&nbsp;}
  1659. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Server&nbsp;Called&nbsp;Functions
  1660. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1661. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Server-called,&nbsp;client&nbsp;side&nbsp;implementation&nbsp;of&nbsp;the&nbsp;Echo&nbsp;function</span>
  1662. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1663. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Echo(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  1664. &nbsp;&nbsp;&nbsp;&nbsp;{
  1665. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedEchoClientResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;#{1}&nbsp;triggered!&quot;</span>,&nbsp;methodCall.Arguments[0],&nbsp;methodCall.Arguments[1]);
  1666. &nbsp;&nbsp;&nbsp;&nbsp;}
  1667. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1668. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Client&nbsp;Called&nbsp;Function(s)
  1669. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1670. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Client-called,&nbsp;server&nbsp;side&nbsp;implementation&nbsp;of&nbsp;the&nbsp;Echo&nbsp;function.</span>
  1671. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;When&nbsp;the&nbsp;function&nbsp;successfully&nbsp;executed&nbsp;on&nbsp;the&nbsp;server&nbsp;the&nbsp;OnEcho_Done&nbsp;Callback&nbsp;function&nbsp;will&nbsp;be&nbsp;called.</span>
  1672. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1673. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Echo(<span style=""color:blue;"">string</span>&nbsp;msg)
  1674. &nbsp;&nbsp;&nbsp;&nbsp;{
  1675. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;echo&quot;</span>,&nbsp;OnEcho_Done,&nbsp;msg);
  1676. &nbsp;&nbsp;&nbsp;&nbsp;}
  1677. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1678. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;When&nbsp;the&nbsp;function&nbsp;successfully&nbsp;executed&nbsp;on&nbsp;the&nbsp;server&nbsp;this&nbsp;Callback&nbsp;function&nbsp;will&nbsp;be&nbsp;called.</span>
  1679. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1680. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnEcho_Done(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  1681. &nbsp;&nbsp;&nbsp;&nbsp;{
  1682. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedEchoResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;TypedDemoHub.Echo(string&nbsp;message)&nbsp;invoked!&quot;</span>;
  1683. &nbsp;&nbsp;&nbsp;&nbsp;}
  1684. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1685. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Draw()
  1686. &nbsp;&nbsp;&nbsp;&nbsp;{
  1687. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Typed&nbsp;Callback&quot;</span>);
  1688. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1689. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1690. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  1691. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(typedEchoResult);
  1692. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(typedEchoClientResult);
  1693. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  1694. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1695. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1696. &nbsp;&nbsp;&nbsp;&nbsp;}
  1697. }
  1698. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1699. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;A&nbsp;wrapper&nbsp;class&nbsp;for&nbsp;the&nbsp;&#39;DemoHub&#39;&nbsp;hub.</span>
  1700. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1701. <span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">DemoHub</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">Hub</span>
  1702. {
  1703. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;fields
  1704. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;These&nbsp;fields&nbsp;are&nbsp;here&nbsp;to&nbsp;store&nbsp;results&nbsp;of&nbsp;the&nbsp;function&nbsp;calls</span>
  1705. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">float</span>&nbsp;longRunningJobProgress&nbsp;=&nbsp;0f;
  1706. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;longRunningJobStatus&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Not&nbsp;Started!&quot;</span>;
  1707. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;fromArbitraryCodeResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1708. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;groupAddedResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1709. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;dynamicTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1710. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;genericTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1711. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;taskWithExceptionResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1712. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;genericTaskWithExceptionResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1713. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;synchronousExceptionResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1714. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;invokingHubMethodWithDynamicResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1715. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;simpleArrayResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1716. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;complexTypeResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1717. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;complexArrayResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1718. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;voidOverloadResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1719. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;intOverloadResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1720. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;readStateResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1721. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;plainTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1722. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;genericTaskWithContinueWithResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  1723. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>&nbsp;invokeResults&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>();
  1724. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1725. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;DemoHub()
  1726. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<span style=""color:blue;"">base</span>(<span style=""color:#a31515;"">&quot;demo&quot;</span>)
  1727. &nbsp;&nbsp;&nbsp;&nbsp;{
  1728. &nbsp;&nbsp;&nbsp;&nbsp;}
  1729. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1730. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;by&nbsp;the&nbsp;Connection&nbsp;class&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;set&nbsp;up&nbsp;mappings.</span>
  1731. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1732. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">override</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Setup()
  1733. &nbsp;&nbsp;&nbsp;&nbsp;{
  1734. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Setup&nbsp;server-called&nbsp;functions</span>
  1735. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.On(<span style=""color:#a31515;"">&quot;invoke&quot;</span>,&nbsp;Invoke);
  1736. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.On(<span style=""color:#a31515;"">&quot;signal&quot;</span>,&nbsp;Signal);
  1737. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.On(<span style=""color:#a31515;"">&quot;groupAdded&quot;</span>,&nbsp;GroupAdded);
  1738. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.On(<span style=""color:#a31515;"">&quot;fromArbitraryCode&quot;</span>,&nbsp;FromArbitraryCode);
  1739. &nbsp;&nbsp;&nbsp;&nbsp;}
  1740. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Client&nbsp;Called&nbsp;Functions
  1741. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;ReportProgress
  1742. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;ReportProgress(<span style=""color:blue;"">string</span>&nbsp;arg)
  1743. &nbsp;&nbsp;&nbsp;&nbsp;{
  1744. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call(<span style=""color:#a31515;"">&quot;reportProgress&quot;</span>,&nbsp;OnLongRunningJob_Done,&nbsp;<span style=""color:blue;"">null</span>,&nbsp;OnLongRunningJob_Progress,&nbsp;arg);
  1745. &nbsp;&nbsp;&nbsp;&nbsp;}
  1746. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnLongRunningJob_Progress(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originialMessage,&nbsp;<span style=""color:#2b91af;"">ProgressMessage</span>&nbsp;progress)
  1747. &nbsp;&nbsp;&nbsp;&nbsp;{
  1748. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;longRunningJobProgress&nbsp;=&nbsp;(<span style=""color:blue;"">float</span>)progress.Progress;
  1749. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;longRunningJobStatus&nbsp;=&nbsp;progress.Progress.ToString()&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;%&quot;</span>;
  1750. &nbsp;&nbsp;&nbsp;&nbsp;}
  1751. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnLongRunningJob_Done(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  1752. &nbsp;&nbsp;&nbsp;&nbsp;{
  1753. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;longRunningJobStatus&nbsp;=&nbsp;result.ReturnValue.ToString();
  1754. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MultipleCalls();
  1755. &nbsp;&nbsp;&nbsp;&nbsp;}
  1756. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1757. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;MultipleCalls()
  1758. &nbsp;&nbsp;&nbsp;&nbsp;{
  1759. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;multipleCalls&quot;</span>);
  1760. &nbsp;&nbsp;&nbsp;&nbsp;}
  1761. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;DynamicTask
  1762. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;DynamicTask()
  1763. &nbsp;&nbsp;&nbsp;&nbsp;{
  1764. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;dynamicTask&quot;</span>,&nbsp;OnDynamicTask_Done,&nbsp;OnDynamicTask_Failed);
  1765. &nbsp;&nbsp;&nbsp;&nbsp;}
  1766. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDynamicTask_Failed(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  1767. &nbsp;&nbsp;&nbsp;&nbsp;{
  1768. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dynamicTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;The&nbsp;dynamic&nbsp;task&nbsp;failed&nbsp;:(&nbsp;{0}&quot;</span>,&nbsp;result.ErrorMessage);
  1769. &nbsp;&nbsp;&nbsp;&nbsp;}
  1770. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDynamicTask_Done(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  1771. &nbsp;&nbsp;&nbsp;&nbsp;{
  1772. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dynamicTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;The&nbsp;dynamic&nbsp;task!&nbsp;{0}&quot;</span>,&nbsp;result.ReturnValue);
  1773. &nbsp;&nbsp;&nbsp;&nbsp;}
  1774. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1775. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;AddToGroups()
  1776. &nbsp;&nbsp;&nbsp;&nbsp;{
  1777. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;addToGroups&quot;</span>);
  1778. &nbsp;&nbsp;&nbsp;&nbsp;}
  1779. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;GetValue()
  1780. &nbsp;&nbsp;&nbsp;&nbsp;{
  1781. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;getValue&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;genericTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;The&nbsp;value&nbsp;is&nbsp;{0}&nbsp;after&nbsp;5&nbsp;seconds&quot;</span>,&nbsp;result.ReturnValue));
  1782. &nbsp;&nbsp;&nbsp;&nbsp;}
  1783. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;TaskWithException()
  1784. &nbsp;&nbsp;&nbsp;&nbsp;{
  1785. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;taskWithException&quot;</span>,&nbsp;<span style=""color:blue;"">null</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;taskWithExceptionResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Error:&nbsp;{0}&quot;</span>,&nbsp;result.ErrorMessage));
  1786. &nbsp;&nbsp;&nbsp;&nbsp;}
  1787. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;GenericTaskWithException()
  1788. &nbsp;&nbsp;&nbsp;&nbsp;{
  1789. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;genericTaskWithException&quot;</span>,&nbsp;<span style=""color:blue;"">null</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;genericTaskWithExceptionResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Error:&nbsp;{0}&quot;</span>,&nbsp;result.ErrorMessage));
  1790. &nbsp;&nbsp;&nbsp;&nbsp;}
  1791. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;SynchronousException()
  1792. &nbsp;&nbsp;&nbsp;&nbsp;{
  1793. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;synchronousException&quot;</span>,&nbsp;<span style=""color:blue;"">null</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;synchronousExceptionResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Error:&nbsp;{0}&quot;</span>,&nbsp;result.ErrorMessage));
  1794. &nbsp;&nbsp;&nbsp;&nbsp;}
  1795. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;PassingDynamicComplex(<span style=""color:blue;"">object</span>&nbsp;person)
  1796. &nbsp;&nbsp;&nbsp;&nbsp;{
  1797. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;passingDynamicComplex&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;invokingHubMethodWithDynamicResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;The&nbsp;person&#39;s&nbsp;age&nbsp;is&nbsp;{0}&quot;</span>,&nbsp;result.ReturnValue),&nbsp;person);
  1798. &nbsp;&nbsp;&nbsp;&nbsp;}
  1799. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;SimpleArray(<span style=""color:blue;"">int</span>[]&nbsp;array)
  1800. &nbsp;&nbsp;&nbsp;&nbsp;{
  1801. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;simpleArray&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;simpleArrayResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Simple&nbsp;array&nbsp;works!&quot;</span>,&nbsp;array);
  1802. &nbsp;&nbsp;&nbsp;&nbsp;}
  1803. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;ComplexType(<span style=""color:blue;"">object</span>&nbsp;person)
  1804. &nbsp;&nbsp;&nbsp;&nbsp;{
  1805. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;complexType&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;complexTypeResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Complex&nbsp;Type&nbsp;-&gt;&nbsp;{0}&quot;</span>,&nbsp;(<span style=""color:blue;"">this</span>&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">IHub</span>).Connection.JsonEncoder.Encode(<span style=""color:blue;"">this</span>.State[<span style=""color:#a31515;"">&quot;person&quot;</span>])),&nbsp;person);
  1806. &nbsp;&nbsp;&nbsp;&nbsp;}
  1807. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;ComplexArray(<span style=""color:blue;"">object</span>[]&nbsp;complexArray)
  1808. &nbsp;&nbsp;&nbsp;&nbsp;{
  1809. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;We&nbsp;need&nbsp;to&nbsp;cast&nbsp;the&nbsp;object&nbsp;array&nbsp;to&nbsp;object&nbsp;to&nbsp;keep&nbsp;it&nbsp;as&nbsp;an&nbsp;array</span>
  1810. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;http://stackoverflow.com/questions/36350/how-to-pass-a-single-object-to-a-params-object</span>
  1811. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;ComplexArray&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;complexArrayResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Complex&nbsp;Array&nbsp;Works!&quot;</span>,&nbsp;(<span style=""color:blue;"">object</span>)complexArray);
  1812. &nbsp;&nbsp;&nbsp;&nbsp;}
  1813. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Overloads
  1814. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Overload()
  1815. &nbsp;&nbsp;&nbsp;&nbsp;{
  1816. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;Overload&quot;</span>,&nbsp;OnVoidOverload_Done);
  1817. &nbsp;&nbsp;&nbsp;&nbsp;}
  1818. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnVoidOverload_Done(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  1819. &nbsp;&nbsp;&nbsp;&nbsp;{
  1820. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;voidOverloadResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Void&nbsp;Overload&nbsp;called&quot;</span>;
  1821. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Overload(101);
  1822. &nbsp;&nbsp;&nbsp;&nbsp;}
  1823. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Overload(<span style=""color:blue;"">int</span>&nbsp;number)
  1824. &nbsp;&nbsp;&nbsp;&nbsp;{
  1825. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;Overload&quot;</span>,&nbsp;OnIntOverload_Done,&nbsp;number);
  1826. &nbsp;&nbsp;&nbsp;&nbsp;}
  1827. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnIntOverload_Done(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  1828. &nbsp;&nbsp;&nbsp;&nbsp;{
  1829. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;intOverloadResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Overload&nbsp;with&nbsp;return&nbsp;value&nbsp;called&nbsp;=&gt;&nbsp;{0}&quot;</span>,&nbsp;result.ReturnValue.ToString());
  1830. &nbsp;&nbsp;&nbsp;&nbsp;}
  1831. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1832. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;ReadStateValue()
  1833. &nbsp;&nbsp;&nbsp;&nbsp;{
  1834. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;readStateValue&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;readStateResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Read&nbsp;some&nbsp;state!&nbsp;=&gt;&nbsp;{0}&quot;</span>,&nbsp;result.ReturnValue));
  1835. &nbsp;&nbsp;&nbsp;&nbsp;}
  1836. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;PlainTask()
  1837. &nbsp;&nbsp;&nbsp;&nbsp;{
  1838. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;plainTask&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;plainTaskResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Plain&nbsp;Task&nbsp;Result&quot;</span>);
  1839. &nbsp;&nbsp;&nbsp;&nbsp;}
  1840. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;GenericTaskWithContinueWith()
  1841. &nbsp;&nbsp;&nbsp;&nbsp;{
  1842. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;genericTaskWithContinueWith&quot;</span>,&nbsp;(hub,&nbsp;msg,&nbsp;result)&nbsp;=&gt;&nbsp;genericTaskWithContinueWithResult&nbsp;=&nbsp;result.ReturnValue.ToString());
  1843. &nbsp;&nbsp;&nbsp;&nbsp;}
  1844. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1845. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Server&nbsp;Called&nbsp;Functions
  1846. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;FromArbitraryCode(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  1847. &nbsp;&nbsp;&nbsp;&nbsp;{
  1848. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fromArbitraryCodeResult&nbsp;=&nbsp;methodCall.Arguments[0]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:blue;"">string</span>;
  1849. &nbsp;&nbsp;&nbsp;&nbsp;}
  1850. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;GroupAdded(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  1851. &nbsp;&nbsp;&nbsp;&nbsp;{
  1852. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(!<span style=""color:blue;"">string</span>.IsNullOrEmpty(groupAddedResult))
  1853. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;groupAddedResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Group&nbsp;Already&nbsp;Added!&quot;</span>;
  1854. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">else</span>
  1855. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;groupAddedResult&nbsp;=&nbsp;<span style=""color:#a31515;"">&quot;Group&nbsp;Added!&quot;</span>;
  1856. &nbsp;&nbsp;&nbsp;&nbsp;}
  1857. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Signal(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  1858. &nbsp;&nbsp;&nbsp;&nbsp;{
  1859. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dynamicTaskResult&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;The&nbsp;dynamic&nbsp;task!&nbsp;{0}&quot;</span>,&nbsp;methodCall.Arguments[0]);
  1860. &nbsp;&nbsp;&nbsp;&nbsp;}
  1861. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Invoke(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  1862. &nbsp;&nbsp;&nbsp;&nbsp;{
  1863. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;invokeResults.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;client&nbsp;state&nbsp;index&nbsp;-&gt;&nbsp;{1}&quot;</span>,&nbsp;methodCall.Arguments[0],&nbsp;<span style=""color:blue;"">this</span>.State[<span style=""color:#a31515;"">&quot;index&quot;</span>]));
  1864. &nbsp;&nbsp;&nbsp;&nbsp;}
  1865. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1866. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Draw
  1867. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1868. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Display&nbsp;the&nbsp;result&#39;s&nbsp;of&nbsp;the&nbsp;function&nbsp;calls.</span>
  1869. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1870. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Draw()
  1871. &nbsp;&nbsp;&nbsp;&nbsp;{
  1872. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Arbitrary&nbsp;Code&quot;</span>);
  1873. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1874. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1875. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;Sending&nbsp;{0}&nbsp;from&nbsp;arbitrary&nbsp;code&nbsp;without&nbsp;the&nbsp;hub&nbsp;itself!&quot;</span>,&nbsp;fromArbitraryCodeResult));
  1876. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1877. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1878. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Group&nbsp;Added&quot;</span>);
  1879. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1880. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1881. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(groupAddedResult);
  1882. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1883. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1884. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Dynamic&nbsp;Task&quot;</span>);
  1885. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1886. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1887. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(dynamicTaskResult);
  1888. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1889. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1890. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Report&nbsp;Progress&quot;</span>);
  1891. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1892. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1893. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  1894. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(longRunningJobStatus);
  1895. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.HorizontalSlider(longRunningJobProgress,&nbsp;0,&nbsp;100);
  1896. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  1897. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1898. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1899. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Generic&nbsp;Task&quot;</span>);
  1900. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1901. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1902. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(genericTaskResult);
  1903. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1904. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1905. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Task&nbsp;With&nbsp;Exception&quot;</span>);
  1906. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1907. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1908. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(taskWithExceptionResult);
  1909. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1910. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1911. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Generic&nbsp;Task&nbsp;With&nbsp;Exception&quot;</span>);
  1912. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1913. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1914. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(genericTaskWithExceptionResult);
  1915. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1916. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1917. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Synchronous&nbsp;Exception&quot;</span>);
  1918. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1919. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1920. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(synchronousExceptionResult);
  1921. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1922. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1923. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Invoking&nbsp;hub&nbsp;method&nbsp;with&nbsp;dynamic&quot;</span>);
  1924. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1925. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1926. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(invokingHubMethodWithDynamicResult);
  1927. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1928. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1929. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Simple&nbsp;Array&quot;</span>);
  1930. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1931. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1932. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(simpleArrayResult);
  1933. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1934. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1935. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Complex&nbsp;Type&quot;</span>);
  1936. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1937. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1938. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(complexTypeResult);
  1939. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1940. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1941. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Complex&nbsp;Array&quot;</span>);
  1942. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1943. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1944. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(complexArrayResult);
  1945. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1946. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1947. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Overloads&quot;</span>);
  1948. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1949. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1950. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  1951. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(voidOverloadResult);
  1952. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(intOverloadResult);
  1953. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  1954. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1955. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1956. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Read&nbsp;State&nbsp;Value&quot;</span>);
  1957. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1958. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1959. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(readStateResult);
  1960. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1961. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1962. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Plain&nbsp;Task&quot;</span>);
  1963. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1964. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1965. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(plainTaskResult);
  1966. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1967. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1968. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Generic&nbsp;Task&nbsp;With&nbsp;ContinueWith&quot;</span>);
  1969. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1970. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1971. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(genericTaskWithContinueWithResult);
  1972. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1973. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1974. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Message&nbsp;Pump&quot;</span>);
  1975. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  1976. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  1977. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;invokeResults.Draw(<span style=""color:#2b91af;"">Screen</span>.width&nbsp;-&nbsp;40,&nbsp;270);
  1978. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  1979. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  1980. &nbsp;&nbsp;&nbsp;&nbsp;}
  1981. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  1982. }</pre>";
  1983. #endregion
  1984. #region SignalR AuthenticationSample
  1985. public static string SignalR_AuthenticationSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  1986. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  1987. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  1988. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR;
  1989. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.Hubs;
  1990. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.Messages;
  1991. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.SignalR.Authentication;
  1992. <span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">AuthenticationSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  1993. {
  1994. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">readonly</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>&nbsp;URI&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Uri</span>(<span style=""color:#a31515;"">&quot;https://besthttpsignalr.azurewebsites.net/signalr&quot;</span>);
  1995. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  1996. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  1997. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Reference&nbsp;to&nbsp;the&nbsp;SignalR&nbsp;Connection</span>
  1998. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  1999. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Connection</span>&nbsp;signalRConnection;
  2000. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;userName&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  2001. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">string</span>&nbsp;role&nbsp;=&nbsp;<span style=""color:blue;"">string</span>.Empty;
  2002. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Vector2</span>&nbsp;scrollPos;
  2003. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2004. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  2005. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Start()
  2006. &nbsp;&nbsp;&nbsp;&nbsp;{
  2007. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Create&nbsp;the&nbsp;SignalR&nbsp;connection,&nbsp;and&nbsp;pass&nbsp;the&nbsp;hubs&nbsp;that&nbsp;we&nbsp;want&nbsp;to&nbsp;connect&nbsp;to</span>
  2008. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">Connection</span>(URI,&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;noauthhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&quot;</span>),
  2009. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;invokeauthhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&nbsp;Invoked&nbsp;By&nbsp;Admin&nbsp;or&nbsp;Invoker&quot;</span>),
  2010. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;authhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&nbsp;Requiring&nbsp;Authentication&nbsp;to&nbsp;Send&nbsp;or&nbsp;Receive&quot;</span>),
  2011. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;inheritauthhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&nbsp;Requiring&nbsp;Authentication&nbsp;to&nbsp;Send&nbsp;or&nbsp;Receive&nbsp;Because&nbsp;of&nbsp;Inheritance&quot;</span>),
  2012. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;incomingauthhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&nbsp;Requiring&nbsp;Authentication&nbsp;to&nbsp;Send&quot;</span>),
  2013. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;adminauthhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&nbsp;Requiring&nbsp;Admin&nbsp;Membership&nbsp;to&nbsp;Send&nbsp;or&nbsp;Receive&quot;</span>),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2014. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>(<span style=""color:#a31515;"">&quot;userandroleauthhub&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Messages&nbsp;Requiring&nbsp;Name&nbsp;to&nbsp;be&nbsp;\&quot;User\&quot;&nbsp;and&nbsp;Role&nbsp;to&nbsp;be&nbsp;\&quot;Admin\&quot;&nbsp;to&nbsp;Send&nbsp;or&nbsp;Receive&quot;</span>));
  2015. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2016. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;the&nbsp;authenticator&nbsp;if&nbsp;we&nbsp;have&nbsp;valid&nbsp;fields</span>
  2017. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(!<span style=""color:blue;"">string</span>.IsNullOrEmpty(userName)&nbsp;&amp;&amp;&nbsp;!<span style=""color:blue;"">string</span>.IsNullOrEmpty(role))
  2018. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.AuthenticationProvider&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">HeaderAuthenticator</span>(userName,&nbsp;role);
  2019. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;SaveLocal&nbsp;up&nbsp;event&nbsp;handler</span>
  2020. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnConnected&nbsp;+=&nbsp;signalRConnection_OnConnected;
  2021. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Start&nbsp;to&nbsp;connect&nbsp;to&nbsp;the&nbsp;server.</span>
  2022. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Open();
  2023. &nbsp;&nbsp;&nbsp;&nbsp;}
  2024. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnDestroy()
  2025. &nbsp;&nbsp;&nbsp;&nbsp;{
  2026. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;the&nbsp;connection&nbsp;when&nbsp;we&nbsp;are&nbsp;closing&nbsp;the&nbsp;sample</span>
  2027. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  2028. &nbsp;&nbsp;&nbsp;&nbsp;}
  2029. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  2030. &nbsp;&nbsp;&nbsp;&nbsp;{
  2031. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  2032. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  2033. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scrollPos&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginScrollView(scrollPos,&nbsp;<span style=""color:blue;"">false</span>,&nbsp;<span style=""color:blue;"">false</span>);
  2034. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginVertical();
  2035. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(signalRConnection.AuthenticationProvider&nbsp;==&nbsp;<span style=""color:blue;"">null</span>)
  2036. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  2037. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  2038. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Username&nbsp;(Enter&nbsp;&#39;User&#39;):&quot;</span>);
  2039. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userName&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(userName,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  2040. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  2041. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  2042. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Roles&nbsp;(Enter&nbsp;&#39;Invoker&#39;&nbsp;or&nbsp;&#39;Admin&#39;):&quot;</span>);
  2043. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;role&nbsp;=&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.TextField(role,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  2044. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  2045. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Log&nbsp;in&quot;</span>))
  2046. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Restart();
  2047. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  2048. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;signalRConnection.Hubs.Length;&nbsp;++i)
  2049. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(signalRConnection.Hubs[i]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>).Draw();
  2050. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndVertical();
  2051. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndScrollView();
  2052. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  2053. &nbsp;&nbsp;&nbsp;&nbsp;}
  2054. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2055. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2056. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;when&nbsp;we&nbsp;successfully&nbsp;connected&nbsp;to&nbsp;the&nbsp;server.</span>
  2057. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2058. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;signalRConnection_OnConnected(<span style=""color:#2b91af;"">Connection</span>&nbsp;manager)
  2059. &nbsp;&nbsp;&nbsp;&nbsp;{
  2060. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;call&nbsp;&#39;InvokedFromClient&#39;&nbsp;on&nbsp;all&nbsp;hubs</span>
  2061. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">for</span>&nbsp;(<span style=""color:blue;"">int</span>&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;signalRConnection.Hubs.Length;&nbsp;++i)
  2062. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(signalRConnection.Hubs[i]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>).InvokedFromClient();
  2063. &nbsp;&nbsp;&nbsp;&nbsp;}
  2064. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2065. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Helper&nbsp;function&nbsp;to&nbsp;do&nbsp;a&nbsp;hard-restart&nbsp;to&nbsp;the&nbsp;server.</span>
  2066. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2067. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;Restart()
  2068. &nbsp;&nbsp;&nbsp;&nbsp;{
  2069. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Clean&nbsp;up</span>
  2070. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.OnConnected&nbsp;-=&nbsp;signalRConnection_OnConnected;
  2071. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Close&nbsp;current&nbsp;connection</span>
  2072. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection.Close();
  2073. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;signalRConnection&nbsp;=&nbsp;<span style=""color:blue;"">null</span>;
  2074. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;start&nbsp;again,&nbsp;with&nbsp;authentication&nbsp;if&nbsp;we&nbsp;filled&nbsp;in&nbsp;all&nbsp;input&nbsp;fields</span>
  2075. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start();
  2076. &nbsp;&nbsp;&nbsp;&nbsp;}
  2077. }
  2078. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2079. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Hub&nbsp;implementation&nbsp;for&nbsp;the&nbsp;authentication&nbsp;demo.&nbsp;All&nbsp;hubs&nbsp;that&nbsp;we&nbsp;connect&nbsp;to&nbsp;has&nbsp;the&nbsp;same&nbsp;server&nbsp;and&nbsp;client&nbsp;side&nbsp;functions.</span>
  2080. <span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2081. <span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">BaseHub</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">Hub</span>
  2082. {
  2083. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  2084. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2085. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Hub&nbsp;specific&nbsp;title</span>
  2086. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2087. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">string</span>&nbsp;Title;
  2088. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>&nbsp;messages&nbsp;=&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">GUIMessageList</span>();
  2089. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2090. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;BaseHub(<span style=""color:blue;"">string</span>&nbsp;name,&nbsp;<span style=""color:blue;"">string</span>&nbsp;title)
  2091. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<span style=""color:blue;"">base</span>(name)
  2092. &nbsp;&nbsp;&nbsp;&nbsp;{
  2093. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">this</span>.Title&nbsp;=&nbsp;title;
  2094. &nbsp;&nbsp;&nbsp;&nbsp;}
  2095. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2096. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;Called&nbsp;by&nbsp;the&nbsp;Connection&nbsp;class&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;set&nbsp;up&nbsp;mappings.</span>
  2097. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2098. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">override</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Setup()
  2099. &nbsp;&nbsp;&nbsp;&nbsp;{
  2100. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Map&nbsp;the&nbsp;server-callable&nbsp;method&nbsp;names&nbsp;to&nbsp;the&nbsp;real&nbsp;functions.</span>
  2101. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On(<span style=""color:#a31515;"">&quot;joined&quot;</span>,&nbsp;Joined);
  2102. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On(<span style=""color:#a31515;"">&quot;rejoined&quot;</span>,&nbsp;Rejoined);
  2103. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On(<span style=""color:#a31515;"">&quot;left&quot;</span>,&nbsp;Left);
  2104. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On(<span style=""color:#a31515;"">&quot;invoked&quot;</span>,&nbsp;Invoked);
  2105. &nbsp;&nbsp;&nbsp;&nbsp;}
  2106. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Server&nbsp;Called&nbsp;Functions
  2107. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Joined(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  2108. &nbsp;&nbsp;&nbsp;&nbsp;{
  2109. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;&nbsp;AuthInfo&nbsp;=&nbsp;methodCall.Arguments[2]&nbsp;<span style=""color:blue;"">as</span>&nbsp;<span style=""color:#2b91af;"">Dictionary</span>&lt;<span style=""color:blue;"">string</span>,&nbsp;<span style=""color:blue;"">object</span>&gt;;
  2110. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;joined&nbsp;at&nbsp;{1}\n\tIsAuthenticated:&nbsp;{2}&nbsp;IsAdmin:&nbsp;{3}&nbsp;UserName:&nbsp;{4}&quot;</span>,&nbsp;methodCall.Arguments[0],&nbsp;methodCall.Arguments[1],&nbsp;AuthInfo[<span style=""color:#a31515;"">&quot;IsAuthenticated&quot;</span>],&nbsp;AuthInfo[<span style=""color:#a31515;"">&quot;IsAdmin&quot;</span>],&nbsp;AuthInfo[<span style=""color:#a31515;"">&quot;UserName&quot;</span>]));
  2111. &nbsp;&nbsp;&nbsp;&nbsp;}
  2112. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Rejoined(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  2113. &nbsp;&nbsp;&nbsp;&nbsp;{
  2114. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;reconnected&nbsp;at&nbsp;{1}&quot;</span>,&nbsp;methodCall.Arguments[0],&nbsp;methodCall.Arguments[1]));
  2115. &nbsp;&nbsp;&nbsp;&nbsp;}
  2116. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Left(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  2117. &nbsp;&nbsp;&nbsp;&nbsp;{
  2118. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;left&nbsp;at&nbsp;{1}&quot;</span>,&nbsp;methodCall.Arguments[0],&nbsp;methodCall.Arguments[1]));
  2119. &nbsp;&nbsp;&nbsp;&nbsp;}
  2120. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Invoked(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">MethodCallMessage</span>&nbsp;methodCall)
  2121. &nbsp;&nbsp;&nbsp;&nbsp;{
  2122. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Add(<span style=""color:blue;"">string</span>.Format(<span style=""color:#a31515;"">&quot;{0}&nbsp;invoked&nbsp;hub&nbsp;method&nbsp;at&nbsp;{1}&quot;</span>,&nbsp;methodCall.Arguments[0],&nbsp;methodCall.Arguments[1]));
  2123. &nbsp;&nbsp;&nbsp;&nbsp;}
  2124. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2125. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Client&nbsp;callable&nbsp;function&nbsp;implementation
  2126. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;InvokedFromClient()
  2127. &nbsp;&nbsp;&nbsp;&nbsp;{
  2128. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">base</span>.Call(<span style=""color:#a31515;"">&quot;invokedFromClient&quot;</span>,&nbsp;OnInvoked,&nbsp;OnInvokeFailed);
  2129. &nbsp;&nbsp;&nbsp;&nbsp;}
  2130. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnInvoked(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  2131. &nbsp;&nbsp;&nbsp;&nbsp;{
  2132. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.Log(hub.Name&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;&nbsp;invokedFromClient&nbsp;success!&quot;</span>);
  2133. &nbsp;&nbsp;&nbsp;&nbsp;}
  2134. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2135. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;This&nbsp;Callback&nbsp;function&nbsp;will&nbsp;be&nbsp;called&nbsp;every&nbsp;time&nbsp;we&nbsp;try&nbsp;to&nbsp;access&nbsp;a&nbsp;protected&nbsp;API&nbsp;while&nbsp;we&nbsp;are&nbsp;using&nbsp;an&nbsp;non-authenticated&nbsp;connection.</span>
  2136. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2137. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">private</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnInvokeFailed(<span style=""color:#2b91af;"">Hub</span>&nbsp;hub,&nbsp;<span style=""color:#2b91af;"">ClientMessage</span>&nbsp;originalMessage,&nbsp;<span style=""color:#2b91af;"">ResultMessage</span>&nbsp;result)
  2138. &nbsp;&nbsp;&nbsp;&nbsp;{
  2139. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">Debug</span>.LogWarning(hub.Name&nbsp;+&nbsp;<span style=""color:#a31515;"">&quot;&nbsp;&quot;</span>&nbsp;+&nbsp;result.ErrorMessage);
  2140. &nbsp;&nbsp;&nbsp;&nbsp;}
  2141. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2142. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">void</span>&nbsp;Draw()
  2143. &nbsp;&nbsp;&nbsp;&nbsp;{
  2144. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:blue;"">this</span>.Title);
  2145. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  2146. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(20);
  2147. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.Draw(<span style=""color:#2b91af;"">Screen</span>.width&nbsp;-&nbsp;20,&nbsp;100);
  2148. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  2149. &nbsp;&nbsp;&nbsp;&nbsp;}
  2150. }</pre>";
  2151. #endregion
  2152. #region CacheMaintenanceSample
  2153. public static string CacheMaintenanceSample = @"<pre style=""font-family:Consolas;font-size:13;color:black;background:silver;""><span style=""color:blue;"">using</span>&nbsp;System;
  2154. <span style=""color:blue;"">using</span>&nbsp;System.Collections.Generic;
  2155. <span style=""color:blue;"">using</span>&nbsp;UnityEngine;
  2156. <span style=""color:blue;"">using</span>&nbsp;BestHTTP;
  2157. <span style=""color:blue;"">using</span>&nbsp;BestHTTP.Caching;
  2158. <span style=""color:blue;"">public</span>&nbsp;<span style=""color:blue;"">sealed</span>&nbsp;<span style=""color:blue;"">class</span>&nbsp;<span style=""color:#2b91af;"">CacheMaintenanceSample</span>&nbsp;:&nbsp;<span style=""color:#2b91af;"">MonoBehaviour</span>
  2159. {
  2160. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2161. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;An&nbsp;enum&nbsp;for&nbsp;better&nbsp;readability</span>
  2162. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2163. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">enum</span>&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>
  2164. &nbsp;&nbsp;&nbsp;&nbsp;{
  2165. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Days,
  2166. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hours,
  2167. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mins,
  2168. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Secs
  2169. &nbsp;&nbsp;&nbsp;&nbsp;};
  2170. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Private&nbsp;Fields
  2171. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2172. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;What&nbsp;methode&nbsp;to&nbsp;call&nbsp;on&nbsp;the&nbsp;TimeSpan</span>
  2173. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2174. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>&nbsp;deleteOlderType&nbsp;=&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>.Secs;
  2175. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2176. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;The&nbsp;value&nbsp;for&nbsp;the&nbsp;TimeSpan.</span>
  2177. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2178. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;value&nbsp;=&nbsp;10;
  2179. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;summary&gt;</span>
  2180. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;What&#39;s&nbsp;our&nbsp;maximum&nbsp;cache&nbsp;size</span>
  2181. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:gray;"">///</span><span style=""color:green;"">&nbsp;</span><span style=""color:gray;"">&lt;/summary&gt;</span>
  2182. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">int</span>&nbsp;maxCacheSize&nbsp;=&nbsp;5&nbsp;*&nbsp;1024&nbsp;*&nbsp;1024;
  2183. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2184. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#region</span>&nbsp;Unity&nbsp;Events
  2185. &nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">void</span>&nbsp;OnGUI()
  2186. &nbsp;&nbsp;&nbsp;&nbsp;{
  2187. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUIHelper</span>.DrawArea(<span style=""color:#2b91af;"">GUIHelper</span>.ClientArea,&nbsp;<span style=""color:blue;"">true</span>,&nbsp;()&nbsp;=&gt;
  2188. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  2189. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  2190. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2191. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Delete&nbsp;cached&nbsp;entities&nbsp;older&nbsp;then&quot;</span>);
  2192. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(value.ToString(),&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(50));
  2193. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;=&nbsp;(<span style=""color:blue;"">int</span>)<span style=""color:#2b91af;"">GUILayout</span>.HorizontalSlider(value,&nbsp;1,&nbsp;60,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.MinWidth(100));
  2194. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  2195. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deleteOlderType&nbsp;=&nbsp;(<span style=""color:#2b91af;"">DeleteOlderTypes</span>)(<span style=""color:blue;"">int</span>)<span style=""color:#2b91af;"">GUILayout</span>.SelectionGrid((<span style=""color:blue;"">int</span>)deleteOlderType,&nbsp;<span style=""color:blue;"">new</span>&nbsp;<span style=""color:blue;"">string</span>[]&nbsp;{&nbsp;<span style=""color:#a31515;"">&quot;Days&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Hours&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Mins&quot;</span>,&nbsp;<span style=""color:#a31515;"">&quot;Secs&quot;</span>&nbsp;},&nbsp;4);
  2196. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.FlexibleSpace();
  2197. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  2198. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  2199. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.BeginHorizontal();
  2200. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(<span style=""color:#a31515;"">&quot;Max&nbsp;Cache&nbsp;Size&nbsp;(bytes):&nbsp;&quot;</span>,&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Width(150));
  2201. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Label(maxCacheSize.ToString(<span style=""color:#a31515;"">&quot;N0&quot;</span>),&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Width(70));
  2202. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxCacheSize&nbsp;=&nbsp;(<span style=""color:blue;"">int</span>)<span style=""color:#2b91af;"">GUILayout</span>.HorizontalSlider(maxCacheSize,&nbsp;1024,&nbsp;10&nbsp;*&nbsp;1024&nbsp;*&nbsp;1024);
  2203. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.EndHorizontal();
  2204. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">GUILayout</span>.Space(10);
  2205. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">if</span>&nbsp;(<span style=""color:#2b91af;"">GUILayout</span>.Button(<span style=""color:#a31515;"">&quot;Maintenance&quot;</span>))
  2206. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  2207. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>&nbsp;deleteOlder&nbsp;=&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>.FromDays(14);
  2208. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">switch</span>&nbsp;(deleteOlderType)
  2209. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
  2210. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>.Days:&nbsp;deleteOlder&nbsp;=&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>.FromDays(value);&nbsp;<span style=""color:blue;"">break</span>;
  2211. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>.Hours:&nbsp;deleteOlder&nbsp;=&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>.FromHours(value);&nbsp;<span style=""color:blue;"">break</span>;
  2212. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>.Mins:&nbsp;deleteOlder&nbsp;=&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>.FromMinutes(value);&nbsp;<span style=""color:blue;"">break</span>;
  2213. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:blue;"">case</span>&nbsp;<span style=""color:#2b91af;"">DeleteOlderTypes</span>.Secs:&nbsp;deleteOlder&nbsp;=&nbsp;<span style=""color:#2b91af;"">TimeSpan</span>.FromSeconds(value);&nbsp;<span style=""color:blue;"">break</span>;
  2214. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  2215. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:green;"">//&nbsp;Call&nbsp;the&nbsp;BeginMaintainence&nbsp;function.&nbsp;It&nbsp;will&nbsp;run&nbsp;on&nbsp;a&nbsp;thread&nbsp;to&nbsp;do&nbsp;not&nbsp;block&nbsp;the&nbsp;main&nbsp;thread.</span>
  2216. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=""color:#2b91af;"">HTTPCacheService</span>.BeginMaintainence(<span style=""color:blue;"">new</span>&nbsp;<span style=""color:#2b91af;"">HTTPCacheMaintananceParams</span>(deleteOlder,&nbsp;(<span style=""color:blue;"">ulong</span>)maxCacheSize));
  2217. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
  2218. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
  2219. &nbsp;&nbsp;&nbsp;&nbsp;}
  2220. <span style=""color:blue;"">&nbsp;&nbsp;&nbsp;&nbsp;#endregion</span>
  2221. }</pre>";
  2222. #endregion
  2223. }
  2224. }