Actual









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

Featured Snippets


File name: GUICustomAuth.cs Copy
81     void OnGUI()
82     {
83         if (PhotonNetwork.connected)
84         {
85             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
86             return;
87         }
88
89
90         GUILayout.BeginArea(GuiRect);
91         switch (guiState)
92         {
93             case GuiState.AuthFailed:
94                 GUILayout.Label("Authentication Failed");
95
96                 GUILayout.Space(10);
97
98                 GUILayout.Label("Error message:\n'" + this.authDebugMessage + "'");
99
100                 GUILayout.Space(10);
101
102                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
103                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
104                 GUILayout.Label("The error message comes from that service and can be customized.");
105
106                 GUILayout.Space(10);
107
108                 GUILayout.BeginHorizontal();
109                 if (GUILayout.Button("Back"))
110                 {
111                     SetStateAuthInput();
112                 }
113                 if (GUILayout.Button("Help"))
114                 {
115                     SetStateAuthHelp();
116                 }
117                 GUILayout.EndHorizontal();
118                 break;
119
120             case GuiState.AuthHelp:
121
122                 GUILayout.Label("By default, any player can connect to Photon.\n'Custom Authentication' can be enabled to reject players without valid user-account.");
123
124                 GUILayout.Label("The actual authentication must be done by a web-service which you host and customize. Example sourcecode for these services is available on the docs page.");
125
126                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
127                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
128
129                 GUILayout.Space(10);
130                 if (GUILayout.Button("Configure Authentication (Dashboard)"))
131                 {
132                     Application.OpenURL("https://cloud.exitgames.com/dashboard");
133                 }
134                 if (GUILayout.Button("Authentication Docs"))
135                 {
136                     Application.OpenURL("https://doc.exitgames.com/en/pun/current/tutorials/pun-and-facebook-custom-authentication");
137                 }
138
139
140                 GUILayout.Space(10);
141                 if (GUILayout.Button("Back to input"))
142                 {
143                     SetStateAuthInput();
144                 }
145                 break;
146
147             case GuiState.AuthInput:
148
149                 GUILayout.Label("Authenticate yourself");
150
151                 GUILayout.BeginHorizontal();
152                 this.authName = GUILayout.TextField(this.authName, GUILayout.Width(Screen.width/4 - 5));
153                 GUILayout.FlexibleSpace();
154                 this.authToken = GUILayout.TextField(this.authToken, GUILayout.Width(Screen.width/4 - 5));
155                 GUILayout.EndHorizontal();
156
157
158                 if (GUILayout.Button("Authenticate"))
159                 {
160                     PhotonNetwork.AuthValues = new AuthenticationValues();
161                     PhotonNetwork.AuthValues.SetAuthParameters(this.authName, this.authToken);
162                     PhotonNetwork.ConnectUsingSettings("1.0");
163                 }
164
165                 GUILayout.Space(10);
166
167                 if (GUILayout.Button("Help", GUILayout.Width(100)))
168                 {
169                     SetStateAuthHelp();
170                 }
171
172                 break;
173         }
174
175         GUILayout.EndArea();
176     }
File name: LoadbalancingPeer.cs Copy
86         public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
87         {
88             if (this.DebugOut >= DebugLevel.INFO)
89             {
90                 this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
91             }
92
93             Dictionary op = new Dictionary();
94
95             if (!string.IsNullOrEmpty(roomName))
96             {
97                 op[ParameterCode.RoomName] = roomName;
98             }
99             if (lobby != null)
100             {
101                 op[ParameterCode.LobbyName] = lobby.Name;
102                 op[ParameterCode.LobbyType] = (byte)lobby.Type;
103             }
104
105             if (onGameServer)
106             {
107                 if (playerProperties != null && playerProperties.Count > 0)
108                 {
109                     op[ParameterCode.PlayerProperties] = playerProperties;
110                     op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
111                 }
112
113
114                 if (roomOptions == null)
115                 {
116                     roomOptions = new RoomOptions();
117                 }
118
119                 Hashtable gameProperties = new Hashtable();
120                 op[ParameterCode.GameProperties] = gameProperties;
121                 gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
122
123                 gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
124                 gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
125                 gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
126                 if (roomOptions.maxPlayers > 0)
127                 {
128                     gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
129                 }
130                 if (roomOptions.cleanupCacheOnLeave)
131                 {
132                     op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
133                     gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
134                 }
135             }
136
137             // UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
138             return this.OpCustom(OperationCode.CreateGame, op, true);
139         }
File name: LoadbalancingPeer.cs Copy
143         public virtual bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, bool createIfNotExists, Hashtable playerProperties, bool onGameServer)
144         {
145             Dictionary op = new Dictionary();
146
147             if (!string.IsNullOrEmpty(roomName))
148             {
149                 op[ParameterCode.RoomName] = roomName;
150             }
151             if (createIfNotExists)
152             {
153                 op[ParameterCode.CreateIfNotExists] = true;
154                 if (lobby != null)
155                 {
156                     op[ParameterCode.LobbyName] = lobby.Name;
157                     op[ParameterCode.LobbyType] = (byte)lobby.Type;
158                 }
159             }
160
161             if (onGameServer)
162             {
163                 if (playerProperties != null && playerProperties.Count > 0)
164                 {
165                     op[ParameterCode.PlayerProperties] = playerProperties;
166                     op[ParameterCode.Broadcast] = true; // broadcast actor properties
167                 }
168
169
170                 if (createIfNotExists)
171                 {
172                     if (roomOptions == null)
173                     {
174                         roomOptions = new RoomOptions();
175                     }
176
177                     Hashtable gameProperties = new Hashtable();
178                     op[ParameterCode.GameProperties] = gameProperties;
179                     gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
180
181                     gameProperties[GameProperties.IsOpen] = roomOptions.isOpen;
182                     gameProperties[GameProperties.IsVisible] = roomOptions.isVisible;
183                     gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
184                     if (roomOptions.maxPlayers > 0)
185                     {
186                         gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
187                     }
188                     if (roomOptions.cleanupCacheOnLeave)
189                     {
190                         op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
191                         gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
192                     }
193                 }
194             }
195
196             // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
197             return this.OpCustom(OperationCode.JoinGame, op, true);
198         }
File name: NetworkingPeer.cs Copy
757     internal protected bool SetMasterClient(int playerId, bool sync)
758     {
759         bool masterReplaced = this.mMasterClient != null && this.mMasterClient.ID != playerId;
760         if (!masterReplaced || !this.mActors.ContainsKey(playerId))
761         {
762             return false;
763         }
764
765         if (sync)
766         {
767             bool sent = this.OpRaiseEvent(PunEvent.AssignMaster, new Hashtable() { { (byte)1, playerId } }, true, null);
768             if (!sent)
769             {
770                 return false;
771             }
772         }
773
774         this.hasSwitchedMC = true;
775         this.mMasterClient = this.mActors[playerId];
776         SendMonoMessage(PhotonNetworkingMessage.OnMasterClientSwitched, this.mMasterClient); // we only callback when an actual change is done
777         return true;
778     }
File name: NetworkingPeer.cs Copy
2493     protected internal void RemoveInstantiatedGO(GameObject go, bool localOnly)
2494     {
2495         if (go == null)
2496         {
2497             Debug.LogError("Failed to 'network-remove' GameObject because it's null.");
2498             return;
2499         }
2500
2501         // Don't remove the GO if it doesn't have any PhotonView
2502         PhotonView[] views = go.GetComponentsInChildren(true);
2503         if (views == null || views.Length <= 0)
2504         {
2505             Debug.LogError("Failed to 'network-remove' GameObject because has no PhotonView components: " + go);
2506             return;
2507         }
2508
2509         PhotonView viewZero = views[0];
2510         int creatorId = viewZero.CreatorActorNr; // creatorId of obj is needed to delete EvInstantiate (only if it's from that user)
2511         int instantiationId = viewZero.instantiationId; // actual, live InstantiationIds start with 1 and go up
2512
2513         // Don't remove GOs that are owned by others (unless this is the master and the remote player left)
2514         if (!localOnly)
2515         {
2516             if (!viewZero.isMine)
2517             {
2518                 Debug.LogError("Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: " + viewZero);
2519                 return;
2520             }
2521
2522             // Don't remove the Instantiation from the server, if it doesn't have a proper ID
2523             if (instantiationId < 1)
2524             {
2525                 Debug.LogError("Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: " + viewZero + ". Not Destroying GameObject or PhotonViews!");
2526                 return;
2527             }
2528         }
2529
2530
2531         // cleanup instantiation (event and local list)
2532         if (!localOnly)
2533         {
2534             this.ServerCleanInstantiateAndDestroy(instantiationId, creatorId, viewZero.isRuntimeInstantiated); // server cleaning
2535         }
2536
2537
2538         // cleanup PhotonViews and their RPCs events (if not localOnly)
2539         for (int j = views.Length - 1; j >= 0; j--)
2540         {
2541             PhotonView view = views[j];
2542             if (view == null)
2543             {
2544                 continue;
2545             }
2546
2547             // we only destroy/clean PhotonViews that were created by PhotonNetwork.Instantiate (and those have an instantiationId!)
2548             if (view.instantiationId >= 1)
2549             {
2550                 this.LocalCleanPhotonView(view);
2551             }
2552             if (!localOnly)
2553             {
2554                 this.OpCleanRpcBuffer(view);
2555             }
2556         }
2557
2558         if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2559             Debug.Log("Network destroy Instantiated GO: " + go.name);
2560
2561         GameObject.Destroy(go);
2562     }
File name: NetworkingPeer.cs Copy
3271     // calls OnPhotonSerializeView (through ExecuteOnSerialize)
3273     private Hashtable OnSerializeWrite(PhotonView view)
3274     {
3275         PhotonStream pStream = new PhotonStream( true, null );
3276         PhotonMessageInfo info = new PhotonMessageInfo( this.mLocalActor, this.ServerTimeInMilliSeconds, view );
3277
3278         // each view creates a list of values that should be sent
3279         view.SerializeView( pStream, info );
3280
3281         if( pStream.Count == 0 )
3282         {
3283             return null;
3284         }
3285
3286         object[] dataArray = pStream.data.ToArray();
3287
3288         if (view.synchronization == ViewSynchronization.UnreliableOnChange)
3289         {
3290             if (AlmostEquals(dataArray, view.lastOnSerializeDataSent))
3291             {
3292                 if (view.mixedModeIsReliable)
3293                 {
3294                     return null;
3295                 }
3296
3297                 view.mixedModeIsReliable = true;
3298                 view.lastOnSerializeDataSent = dataArray;
3299             }
3300             else
3301             {
3302                 view.mixedModeIsReliable = false;
3303                 view.lastOnSerializeDataSent = dataArray;
3304             }
3305         }
3306
3307         // EVDATA:
3308         // 0=View ID (an int, never compressed cause it's not in the data)
3309         // 1=data of observed type (different per type of observed object)
3310         // 2=compressed data (in this case, key 1 is empty)
3311         // 3=list of values that are actually null (if something was changed but actually IS null)
3312         Hashtable evData = new Hashtable();
3313         evData[(byte)0] = (int)view.viewID;
3314         evData[(byte)1] = dataArray; // this is the actual data (script or observed object)
3315
3316
3317         if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
3318         {
3319             // compress content of data set (by comparing to view.lastOnSerializeDataSent)
3320             // the "original" dataArray is NOT modified by DeltaCompressionWrite
3321             // if something was compressed, the evData key 2 and 3 are used (see above)
3322             bool somethingLeftToSend = this.DeltaCompressionWrite(view, evData);
3323
3324             // buffer the full data set (for next compression)
3325             view.lastOnSerializeDataSent = dataArray;
3326
3327             if (!somethingLeftToSend)
3328             {
3329                 return null;
3330             }
3331         }
3332
3333         return evData;
3334     }
File name: NetworkingPeer.cs Copy
3425     private bool DeltaCompressionWrite(PhotonView view, Hashtable data)
3426     {
3427         if (view.lastOnSerializeDataSent == null)
3428         {
3429             return true; // all has to be sent
3430         }
3431
3432         // We can compress as we sent a full update previously (readers can re-use previous values)
3433         object[] lastData = view.lastOnSerializeDataSent;
3434         object[] currentContent = data[(byte)1] as object[];
3435
3436         if (currentContent == null)
3437         {
3438             // no data to be sent
3439             return false;
3440         }
3441
3442         if (lastData.Length != currentContent.Length)
3443         {
3444             // if new data isn't same length as before, we send the complete data-set uncompressed
3445             return true;
3446         }
3447
3448         object[] compressedContent = new object[currentContent.Length];
3449         int compressedValues = 0;
3450
3451         List valuesThatAreChangedToNull = new List();
3452         for (int index = 0; index < compressedContent.Length; index++)
3453         {
3454             object newObj = currentContent[index];
3455             object oldObj = lastData[index];
3456             if (this.ObjectIsSameWithInprecision(newObj, oldObj))
3457             {
3458                 // compress (by using null, instead of value, which is same as before)
3459                 compressedValues++;
3460                 // compressedContent[index] is already null (initialized)
3461             }
3462             else
3463             {
3464                 compressedContent[index] = currentContent[index];
3465
3466                 // value changed, we don't replace it with null
3467                 // new value is null (like a compressed value): we have to mark it so it STAYS null instead of being replaced with previous value
3468                 if (newObj == null)
3469                 {
3470                     valuesThatAreChangedToNull.Add(index);
3471                 }
3472             }
3473         }
3474
3475         // Only send the list of compressed fields if we actually compressed 1 or more fields.
3476         if (compressedValues > 0)
3477         {
3478             data.Remove((byte)1); // remove the original data (we only send compressed data)
3479
3480             if (compressedValues == currentContent.Length)
3481             {
3482                 // all values are compressed to null, we have nothing to send
3483                 return false;
3484             }
3485
3486             data[(byte)2] = compressedContent; // current, compressted data is moved to key 2 to mark it as compressed
3487             if (valuesThatAreChangedToNull.Count > 0)
3488             {
3489                 data[(byte)3] = valuesThatAreChangedToNull.ToArray(); // data that is actually null (not just cause we didn't want to send it)
3490             }
3491         }
3492
3493         return true; // some data was compressed but we need to send something
3494     }
File name: TableLayoutGroup.cs Copy
107         public override void CalculateLayoutInputHorizontal()
108         {
109             base.CalculateLayoutInputHorizontal();
110
111             float horizontalSize = padding.horizontal;
112
113             // We calculate the actual cell count for cases where the number of children is lesser than the number of columns
114             int actualCellCount = Mathf.Min(rectChildren.Count, columnWidths.Length);
115
116             for (int i = 0; i < actualCellCount; i++)
117             {
118                 horizontalSize += columnWidths[i];
119                 horizontalSize += columnSpacing;
120             }
121
122             horizontalSize -= columnSpacing;
123
124             SetLayoutInputForAxis(horizontalSize, horizontalSize, 0, 0);
125         }
File name: TableLayoutGroup.cs Copy
189         public override void SetLayoutHorizontal()
190         {
191             // If no column width is defined, then assign a reasonable default
192             if (columnWidths.Length == 0)
193                 columnWidths = new float[1] { 0f };
194
195             int columnCount = columnWidths.Length;
196             int cornerX = (int)startCorner % 2;
197
198             float startOffset = 0;
199             float requiredSizeWithoutPadding = 0;
200
201             // We calculate the actual cell count for cases where the number of children is lesser than the number of columns
202             int actualCellCount = Mathf.Min(rectChildren.Count, columnWidths.Length);
203
204             for (int i = 0; i < actualCellCount; i++)
205             {
206                 requiredSizeWithoutPadding += columnWidths[i];
207                 requiredSizeWithoutPadding += columnSpacing;
208             }
209
210             requiredSizeWithoutPadding -= columnSpacing;
211
212             startOffset = GetStartOffset(0, requiredSizeWithoutPadding);
213
214             if (cornerX == 1)
215                 startOffset += requiredSizeWithoutPadding;
216
217             float positionX = startOffset;
218
219             for (int i = 0; i < rectChildren.Count; i++)
220             {
221                 int currentColumnIndex = i % columnCount;
222
223                 // If it's the first cell in the row, reset positionX
224                 if (currentColumnIndex == 0)
225                     positionX = startOffset;
226
227                 if (cornerX == 1)
228                     positionX -= columnWidths[currentColumnIndex];
229
230                 SetChildAlongAxis(rectChildren[i], 0, positionX, columnWidths[currentColumnIndex]);
231
232                 if (cornerX == 1)
233                     positionX -= columnSpacing;
234                 else
235                     positionX += columnWidths[currentColumnIndex] + columnSpacing;
236             }
237         }
File name: ScrollSnap.cs Copy
33  protected override void Awake() {
34   base.Awake();
35   actualIndex = startingIndex;
36   cellIndex = startingIndex;
37   this.onLerpComplete = new OnLerpCompleteEvent();
38   this.onRelease = new OnReleaseEvent();
39   this.scrollRect = GetComponent();
40   this.canvasGroup = GetComponent();
41   this.content = scrollRect.content;
42   this.cellSize = content.GetComponent().cellSize;
43   content.anchoredPosition = new Vector2(-cellSize.x * cellIndex, content.anchoredPosition.y);
44   int count = LayoutElementCount();
45   SetContentSize(count);
46
47   if(startingIndex < count) {
48    MoveToIndex(startingIndex);
49   }
50  }

Actual 160 lượt xem

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