Content









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

Featured Snippets


File name: DemoMecanimGUI.cs Copy
61     public void OnGUI()
62     {
63         GUI.skin = Skin;
64
65         string[] synchronizeTypeContent = new string[] { "Disabled", "Discrete", "Continuous" };
66
67         GUILayout.BeginArea( new Rect( Screen.width - 200 * m_FoundPlayerSlideIn - 400 * m_SlideIn, 0, 600, Screen.height ), GUI.skin.box );
68         {
69             GUILayout.Label( "Mecanim Demo", GUI.skin.customStyles[ 0 ] );
70
71             GUI.color = Color.white;
72             string label = "Settings";
73
74             if( m_IsOpen == true )
75             {
76                 label = "Close";
77             }
78
79             if( GUILayout.Button( label, GUILayout.Width( 110 ) ) )
80             {
81                 m_IsOpen = !m_IsOpen;
82             }
83
84             string parameters = "";
85
86             if( m_AnimatorView != null )
87             {
88                 parameters += "Send Values:\n";
89
90                 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
91                 {
92                     PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
93
94                     try
95                     {
96                         switch( parameter.Type )
97                         {
98                         case PhotonAnimatorView.ParameterType.Bool:
99                             parameters += parameter.Name + " (" + ( m_AnimatorView.GetComponent().GetBool( parameter.Name ) ? "True" : "False" ) + ")\n";
100                             break;
101                         case PhotonAnimatorView.ParameterType.Int:
102                             parameters += parameter.Name + " (" + m_AnimatorView.GetComponent().GetInteger( parameter.Name ) + ")\n";
103                             break;
104                         case PhotonAnimatorView.ParameterType.Float:
105                             parameters += parameter.Name + " (" + m_AnimatorView.GetComponent().GetFloat( parameter.Name ).ToString( "0.00" ) + ")\n";
106                             break;
107                         }
108                     }
109                     catch
110                     {
111                         Debug.Log( "derrrr for " + parameter.Name );
112                     }
113                 }
114             }
115
116             if( m_RemoteAnimator != null )
117             {
118                 parameters += "\nReceived Values:\n";
119
120                 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
121                 {
122                     PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
123
124                     try
125                     {
126                         switch( parameter.Type )
127                         {
128                         case PhotonAnimatorView.ParameterType.Bool:
129                             parameters += parameter.Name + " (" + ( m_RemoteAnimator.GetBool( parameter.Name ) ? "True" : "False" ) + ")\n";
130                             break;
131                         case PhotonAnimatorView.ParameterType.Int:
132                             parameters += parameter.Name + " (" + m_RemoteAnimator.GetInteger( parameter.Name ) + ")\n";
133                             break;
134                         case PhotonAnimatorView.ParameterType.Float:
135                             parameters += parameter.Name + " (" + m_RemoteAnimator.GetFloat( parameter.Name ).ToString( "0.00" ) + ")\n";
136                             break;
137                         }
138                     }
139                     catch
140                     {
141                         Debug.Log( "derrrr for " + parameter.Name );
142                     }
143                 }
144             }
145
146             GUIStyle style = new GUIStyle( GUI.skin.label );
147             style.alignment = TextAnchor.UpperLeft;
148
149             GUI.color = new Color( 1f, 1f, 1f, 1 - m_SlideIn );
150             GUI.Label( new Rect( 10, 100, 600, Screen.height ), parameters, style );
151
152             if( m_AnimatorView != null )
153             {
154                 GUI.color = new Color( 1f, 1f, 1f, m_SlideIn );
155
156                 GUILayout.Space( 20 );
157                 GUILayout.Label( "Synchronize Parameters" );
158
159                 for( int i = 0; i < m_AnimatorView.GetSynchronizedParameters().Count; ++i )
160                 {
161                     GUILayout.BeginHorizontal();
162                     {
163                         PhotonAnimatorView.SynchronizedParameter parameter = m_AnimatorView.GetSynchronizedParameters()[ i ];
164
165                         GUILayout.Label( parameter.Name, GUILayout.Width( 100 ), GUILayout.Height( 36 ) );
166
167                         int selectedValue = (int)parameter.SynchronizeType;
168                         int newValue = GUILayout.Toolbar( selectedValue, synchronizeTypeContent );
169
170                         if( newValue != selectedValue )
171                         {
172                             m_AnimatorView.SetParameterSynchronized( parameter.Name, parameter.Type, (PhotonAnimatorView.SynchronizeType)newValue );
173                         }
174                     }
175                     GUILayout.EndHorizontal();
176                 }
177             }
178         }
179         GUILayout.EndArea();
180     }
File name: WorkerMenu.cs Copy
65     public void OnGUI()
66     {
67         if (this.Skin != null)
68         {
69             GUI.skin = this.Skin;
70         }
71
72         if (!PhotonNetwork.connected)
73         {
74             if (PhotonNetwork.connecting)
75             {
76                 GUILayout.Label("Connecting to: " + PhotonNetwork.ServerAddress);
77             }
78             else
79             {
80                 GUILayout.Label("Not connected. Check console output. Detailed connection state: " + PhotonNetwork.connectionStateDetailed + " Server: " + PhotonNetwork.ServerAddress);
81             }
82
83             if (this.connectFailed)
84             {
85                 GUILayout.Label("Connection failed. Check setup and use Setup Wizard to fix configuration.");
86                 GUILayout.Label(String.Format("Server: {0}", new object[] {PhotonNetwork.ServerAddress}));
87                 GUILayout.Label("AppId: " + PhotonNetwork.PhotonServerSettings.AppID);
88
89                 if (GUILayout.Button("Try Again", GUILayout.Width(100)))
90                 {
91                     this.connectFailed = false;
92                     PhotonNetwork.ConnectUsingSettings("0.9");
93                 }
94             }
95
96             return;
97         }
98
99         Rect content = new Rect((Screen.width - WidthAndHeight.x)/2, (Screen.height - WidthAndHeight.y)/2, WidthAndHeight.x, WidthAndHeight.y);
100         GUI.Box(content,"Join or Create Room");
101         GUILayout.BeginArea(content);
102
103         GUILayout.Space(40);
104
105         // Player name
106         GUILayout.BeginHorizontal();
107         GUILayout.Label("Player name:", GUILayout.Width(150));
108         PhotonNetwork.playerName = GUILayout.TextField(PhotonNetwork.playerName);
109         GUILayout.Space(158);
110         if (GUI.changed)
111         {
112             // Save name
113             PlayerPrefs.SetString("playerName", PhotonNetwork.playerName);
114         }
115         GUILayout.EndHorizontal();
116
117         GUILayout.Space(15);
118
119         // Join room by title
120         GUILayout.BeginHorizontal();
121         GUILayout.Label("Roomname:", GUILayout.Width(150));
122         this.roomName = GUILayout.TextField(this.roomName);
123
124         if (GUILayout.Button("Create Room", GUILayout.Width(150)))
125         {
126             PhotonNetwork.CreateRoom(this.roomName, new RoomOptions() { maxPlayers = 10 }, null);
127         }
128
129         GUILayout.EndHorizontal();
130
131         // Create a room (fails if exist!)
132         GUILayout.BeginHorizontal();
133         GUILayout.FlexibleSpace();
134         //this.roomName = GUILayout.TextField(this.roomName);
135         if (GUILayout.Button("Join Room", GUILayout.Width(150)))
136         {
137             PhotonNetwork.JoinRoom(this.roomName);
138         }
139
140         GUILayout.EndHorizontal();
141
142
143         if (!string.IsNullOrEmpty(this.ErrorDialog))
144         {
145             GUILayout.Label(this.ErrorDialog);
146
147             if (timeToClearDialog < Time.time)
148             {
149                 timeToClearDialog = 0;
150                 this.ErrorDialog = "";
151             }
152         }
153
154         GUILayout.Space(15);
155
156         // Join random room
157         GUILayout.BeginHorizontal();
158
159         GUILayout.Label(PhotonNetwork.countOfPlayers + " users are online in " + PhotonNetwork.countOfRooms + " rooms.");
160         GUILayout.FlexibleSpace();
161         if (GUILayout.Button("Join Random", GUILayout.Width(150)))
162         {
163             PhotonNetwork.JoinRandomRoom();
164         }
165
166
167         GUILayout.EndHorizontal();
168
169         GUILayout.Space(15);
170         if (PhotonNetwork.GetRoomList().Length == 0)
171         {
172             GUILayout.Label("Currently no games are available.");
173             GUILayout.Label("Rooms will be listed here, when they become available.");
174         }
175         else
176         {
177             GUILayout.Label(PhotonNetwork.GetRoomList().Length + " rooms available:");
178
179             // Room listing: simply call GetRoomList: no need to fetch/poll whatever!
180             this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
181             foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
182             {
183                 GUILayout.BeginHorizontal();
184                 GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers);
185                 if (GUILayout.Button("Join", GUILayout.Width(150)))
186                 {
187                     PhotonNetwork.JoinRoom(roomInfo.name);
188                 }
189
190                 GUILayout.EndHorizontal();
191             }
192
193             GUILayout.EndScrollView();
194         }
195
196         GUILayout.EndArea();
197     }
File name: PhotonRigidbody2DViewEditor.cs Copy
7     public override void OnInspectorGUI()
8     {
9         PhotonGUI.ContainerHeader("Options");
10
11         Rect containerRect = PhotonGUI.ContainerBody(EditorGUIUtility.singleLineHeight*2 + 10);
12
13         Rect propertyRect = new Rect(containerRect.xMin + 5, containerRect.yMin + 5, containerRect.width, EditorGUIUtility.singleLineHeight);
14         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeVelocity"), new GUIContent("Synchronize Velocity"));
15
16         propertyRect.y += EditorGUIUtility.singleLineHeight;
17         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeAngularVelocity"), new GUIContent("Synchronize Angular Velocity"));
18     }
File name: PhotonRigidbodyViewEditor.cs Copy
7     public override void OnInspectorGUI()
8     {
9         PhotonGUI.ContainerHeader("Options");
10
11         Rect containerRect = PhotonGUI.ContainerBody(EditorGUIUtility.singleLineHeight*2 + 10);
12
13         Rect propertyRect = new Rect(containerRect.xMin + 5, containerRect.yMin + 5, containerRect.width, EditorGUIUtility.singleLineHeight);
14         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeVelocity"), new GUIContent("Synchronize Velocity"));
15
16         propertyRect.y += EditorGUIUtility.singleLineHeight;
17         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeAngularVelocity"), new GUIContent("Synchronize Angular Velocity"));
18     }
File name: PhotonTransformViewEditor.cs Copy
163     private float GetInterpolateHelpBoxHeight()
164     {
165         return PhotonGUI.RichLabel.CalcHeight(new GUIContent(INTERPOLATE_HELP), Screen.width - 54) + 35;
166     }
File name: PhotonTransformViewEditor.cs Copy
168     private float GetExtrapolateHelpBoxHeight()
169     {
170         return PhotonGUI.RichLabel.CalcHeight(new GUIContent(EXTRAPOLATE_HELP), Screen.width - 54) + 35;
171     }
File name: PhotonTransformViewEditor.cs Copy
181     private void DrawSynchronizePositionDataGizmos(ref Rect propertyRect)
182     {
183         GUI.enabled = true;
184         /*PhotonGUI.DrawGizmoOptions(propertyRect, "Synchronized Position Gizmo",
185             serializedObject.FindProperty("m_PositionModel.DrawNetworkGizmo"),
186             serializedObject.FindProperty("m_PositionModel.NetworkGizmoColor"),
187             serializedObject.FindProperty("m_PositionModel.NetworkGizmoType"),
188             serializedObject.FindProperty("m_PositionModel.NetworkGizmoSize"));
189         propertyRect.y += EDITOR_LINE_HEIGHT;
190
191         PhotonGUI.DrawGizmoOptions(propertyRect, "Extrapolated Position Gizmo",
192             serializedObject.FindProperty("m_PositionModel.DrawExtrapolatedGizmo"),
193             serializedObject.FindProperty("m_PositionModel.ExtrapolatedGizmoColor"),
194             serializedObject.FindProperty("m_PositionModel.ExtrapolatedGizmoType"),
195             serializedObject.FindProperty("m_PositionModel.ExtrapolatedGizmoSize"));
196         propertyRect.y += EDITOR_LINE_HEIGHT;*/
197
198         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.DrawErrorGizmo"),
199             new GUIContent("Draw synchronized position error"));
200         propertyRect.y += EDITOR_LINE_HEIGHT;
201     }
File name: PhotonTransformViewEditor.cs Copy
220     private void DrawPropertyWithHelpIcon(ref Rect propertyRect, ref bool isHelpOpen, SerializedProperty property, string tooltip)
221     {
222         Rect propertyFieldRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 20, propertyRect.height);
223         string propertyName = ObjectNames.NicifyVariableName(property.name);
224         EditorGUI.PropertyField(propertyFieldRect, property, new GUIContent(propertyName, tooltip));
225
226         Rect helpIconRect = new Rect(propertyFieldRect.xMax + 5, propertyFieldRect.yMin, 20, propertyFieldRect.height);
227         isHelpOpen = GUI.Toggle(helpIconRect, isHelpOpen, PhotonGUI.HelpIcon, GUIStyle.none);
228
229         propertyRect.y += EDITOR_LINE_HEIGHT;
230     }
File name: PhotonTransformViewEditor.cs Copy
252     private void DrawTeleport(ref Rect propertyRect)
253     {
254         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.TeleportEnabled"),
255             new GUIContent("Enable teleport for great distances"));
256         propertyRect.y += EDITOR_LINE_HEIGHT;
257
258         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.TeleportIfDistanceGreaterThan"),
259             new GUIContent("Teleport if distance greater than"));
260         propertyRect.y += EDITOR_LINE_HEIGHT;
261     }
File name: PhotonTransformViewEditor.cs Copy
264         PhotonTransformViewPositionModel.InterpolateOptions interpolateOption)
265     {
266         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateHelpOpen, interpolatePositionProperty, INTERPOLATE_TOOLTIP);
267         DrawHelpBox(ref propertyRect, this.m_InterpolateHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
268
269         switch (interpolateOption)
270         {
271             case PhotonTransformViewPositionModel.InterpolateOptions.FixedSpeed:
272                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsSpeed"),
273                     new GUIContent("MoveTowards Speed"));
274                 propertyRect.y += EDITOR_LINE_HEIGHT;
275                 break;
276
277             case PhotonTransformViewPositionModel.InterpolateOptions.Lerp:
278                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
279                 propertyRect.y += EDITOR_LINE_HEIGHT;
280                 break;
281
282             /*case PhotonTransformViewPositionModel.InterpolateOptions.MoveTowardsComplex:
283                 Rect curveRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 100, propertyRect.height);
284                 EditorGUI.PropertyField(curveRect, serializedObject.FindProperty("m_PositionModel.InterpolateSpeedCurve"), new GUIContent("MoveTowards Speed Curve"));
285
286                 Rect labelRect = new Rect(propertyRect.xMax - 95, propertyRect.yMin, 10, propertyRect.height);
287                 GUI.Label(labelRect, "x");
288
289                 Rect multiplierRect = new Rect(propertyRect.xMax - 80, propertyRect.yMin, 80, propertyRect.height);
290                 EditorGUI.PropertyField(multiplierRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsSpeed"), GUIContent.none);
291                 propertyRect.y += EDITOR_LINE_HEIGHT;
292
293                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsAcceleration"),
294                     new GUIContent("Acceleration"));
295                 propertyRect.y += EDITOR_LINE_HEIGHT;
296
297                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsDeceleration"),
298                     new GUIContent("Deceleration"));
299                 propertyRect.y += EDITOR_LINE_HEIGHT;
300                 break;*/
301         }
302     }

Download file with original file name:Content

Content 145 lượt xem

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