PhotonTransformView









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

Featured Snippets


File name: HubGui.cs Copy
28     void OnGUI()
29     {
30         GUI.skin = this.Skin;
31         GUILayout.Space(10);
32
33         GUILayout.BeginHorizontal();
34         GUILayout.Space(10);
35         scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(320));
36
37         GUILayout.Label("Basics", m_Headline);
38         if (GUILayout.Button("Demo Boxes", GUILayout.Width(280)))
39         {
40             demoDescription = "Demo Boxes\n\nUses ConnectAndJoinRandom script.\n(joins a random room or creates one)\n\nInstantiates simple prefab.\nSynchronizes positions without smoothing.";
41             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42         }
43         if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44         {
45             demoDescription = "Demo Worker\n\nJoins the default lobby and shows existing rooms.\nLets you create or join a room.\nInstantiates an animated character.\nSynchronizes position and animation state of character with smoothing.\nImplements simple in-room Chat via RPC calls.";
46             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47         }
48         if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49         {
50             demoDescription = "Movement Smoothing\n\nUses ConnectAndJoinRandom script.\nShows several basic ways to update positions of remote objects.";
51             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoSynchronization-Scene" };
52         }
53
54         GUILayout.Label("Advanced", m_Headline);
55         if (GUILayout.Button("Ownership Transfer", GUILayout.Width(280)))
56         {
57             demoDescription = "Ownership Transfer\n\nShows how to transfer the ownership of a PhotonView.\nThe owner will send position updates of the GameObject.\nTransfer can be edited per PhotonView and set to Fixed (no transfer), Request (owner has to agree) or Takeover (owner can't object).";
58             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChangeOwner-Scene" };
59             this.webLink = new DemoBtn();
60         }
61         if (GUILayout.Button("Pickup, Teams, Scores", GUILayout.Width(280)))
62         {
63             demoDescription = "Pickup, Teams, Scores\n\nUses ConnectAndJoinRandom script.\nImplements item pickup with RPCs.\nUses Custom Properties for Teams.\nCounts score per player and team.\nUses PhotonPlayer extension methods for easy Custom Property access.";
64             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoPickup-Scene" };
65             this.webLink = new DemoBtn();
66         }
67
68         GUILayout.Label("Feature Demos", m_Headline);
69         if (GUILayout.Button("Chat", GUILayout.Width(280)))
70         {
71             demoDescription = "Chat\n\nUses the Chat API (now part of PUN).\nSimple UI.\nYou can enter any User ID.\nAutomatically subscribes some channels.\nAllows simple commands via text.\n\nRequires configuration of Chat App ID in scene.";
72             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChat-Scene" };
73             this.webLink = new DemoBtn();
74         }
75         if (GUILayout.Button("RPG Movement", GUILayout.Width(280)))
76         {
77             demoDescription = "RPG Movement\n\nDemonstrates how to use the PhotonTransformView component to synchronize position updates smoothly using inter- and extrapolation.\n\nThis demo also shows how to setup a Mecanim Animator to update animations automatically based on received position updates (without sending explicit animation updates).";
78             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoRPGMovement-Scene" };
79             this.webLink = new DemoBtn();
80         }
81         if (GUILayout.Button("Mecanim Animations", GUILayout.Width(280)))
82         {
83             demoDescription = "Mecanim Animations\n\nThis demo shows how to use the PhotonAnimatorView component to easily synchronize Mecanim animations.\n\nIt also demonstrates another feature of the PhotonTransformView component which gives you more control how position updates are inter-/extrapolated by telling the component how fast the object moves and turns using SetSynchronizedValues().";
84             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoMecanim-Scene" };
85             this.webLink = new DemoBtn();
86         }
87         if (GUILayout.Button("2D Game", GUILayout.Width(280)))
88         {
89             demoDescription = "2D Game Demo\n\nSynchronizes animations, positions and physics in a 2D scene.";
90             this.demoBtn = new DemoBtn() { Text = "Start", Link = "Demo2DJumpAndRunWithPhysics-Scene" };
91             this.webLink = new DemoBtn();
92         }
93         if (GUILayout.Button("Friends & Authentication", GUILayout.Width(280)))
94         {
95             demoDescription = "Friends & Authentication\n\nShows connect with or without (server-side) authentication.\n\nAuthentication requires minor server-side setup (in Dashboard).\n\nOnce connected, you can find (made up) friends.\nJoin a room just to see how that gets visible in friends list.";
96             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoFriends-Scene" };
97             this.webLink = new DemoBtn();
98         }
99
100         GUILayout.Label("Tutorial", m_Headline);
101         if (GUILayout.Button("Marco Polo Tutorial", GUILayout.Width(280)))
102         {
103             demoDescription = "Marco Polo Tutorial\n\nFinal result you could get when you do the Marco Polo Tutorial.\nSlightly modified to be more compatible with this package.";
104             this.demoBtn = new DemoBtn() { Text = "Start", Link = "MarcoPolo-Scene" };
105             this.webLink = new DemoBtn() { Text = "Open Tutorial (www)", Link = "http://tinyurl.com/nmylf44" };
106         }
107         GUILayout.EndScrollView();
108
109         GUILayout.BeginVertical(GUILayout.Width(Screen.width - 345));
110         GUILayout.Label(demoDescription);
111         GUILayout.Space(10);
112         if (!string.IsNullOrEmpty(this.demoBtn.Text))
113         {
114             if (GUILayout.Button(this.demoBtn.Text))
115             {
116                 Application.LoadLevel(this.demoBtn.Link);
117             }
118         }
119         if (!string.IsNullOrEmpty(this.webLink.Text))
120         {
121             if (GUILayout.Button(this.webLink.Text))
122             {
123                 Application.OpenURL(this.webLink.Link);
124             }
125         }
126         GUILayout.EndVertical();
127
128
129         GUILayout.EndHorizontal();
130     }
File name: RPGMovement.cs Copy
22     void Start()
23     {
24         m_CharacterController = GetComponent();
25         m_Animator = GetComponent();
26         m_PhotonView = GetComponent();
27         m_TransformView = GetComponent();
28     }
File name: IdleRunJump.cs Copy
22     void Start ()
23     {
24         animator = GetComponent();
25         m_PhotonView = GetComponent();
26         m_TransformView = GetComponent();
27
28         if(animator.layerCount >= 2)
29             animator.SetLayerWeight(1, 1);
30     }
File name: PhotonTransformViewEditor.cs Copy
47     public override void OnInspectorGUI()
48     {
49         this.m_Target = (PhotonTransformView) target;
50
51         DrawIsPlayingWarning();
52         GUI.enabled = !Application.isPlaying;
53
54         DrawSynchronizePositionHeader();
55         DrawSynchronizePositionData();
56
57         GUI.enabled = !Application.isPlaying;
58         DrawSynchronizeRotationHeader();
59         DrawSynchronizeRotationData();
60
61         GUI.enabled = !Application.isPlaying;
62         DrawSynchronizeScaleHeader();
63         DrawSynchronizeScaleData();
64
65         serializedObject.ApplyModifiedProperties();
66
67         GUI.enabled = true;
68     }
File name: PhotonTransformViewEditor.cs Copy
96     private void DrawSynchronizePositionData()
97     {
98         if (this.m_SynchronizePositionProperty == null || this.m_SynchronizePositionProperty.boolValue == false)
99         {
100             return;
101         }
102
103         SerializedProperty interpolatePositionProperty = serializedObject.FindProperty("m_PositionModel.InterpolateOption");
104         PhotonTransformViewPositionModel.InterpolateOptions interpolateOption = (PhotonTransformViewPositionModel.InterpolateOptions)interpolatePositionProperty.enumValueIndex;
105
106         SerializedProperty extrapolatePositionProperty = serializedObject.FindProperty("m_PositionModel.ExtrapolateOption");
107         PhotonTransformViewPositionModel.ExtrapolateOptions extrapolateOption = (PhotonTransformViewPositionModel.ExtrapolateOptions)extrapolatePositionProperty.enumValueIndex;
108
109         float containerHeight = 155;
110
111         switch (interpolateOption)
112         {
113             case PhotonTransformViewPositionModel.InterpolateOptions.FixedSpeed:
114             case PhotonTransformViewPositionModel.InterpolateOptions.Lerp:
115                 containerHeight += EDITOR_LINE_HEIGHT;
116                 break;
117             /*case PhotonTransformViewPositionModel.InterpolateOptions.MoveTowardsComplex:
118                 containerHeight += EDITOR_LINE_HEIGHT*3;
119                 break;*/
120         }
121
122         if (extrapolateOption != PhotonTransformViewPositionModel.ExtrapolateOptions.Disabled)
123         {
124             containerHeight += EDITOR_LINE_HEIGHT;
125         }
126
127         switch (extrapolateOption)
128         {
129             case PhotonTransformViewPositionModel.ExtrapolateOptions.FixedSpeed:
130                 containerHeight += EDITOR_LINE_HEIGHT;
131                 break;
132         }
133
134         if (this.m_InterpolateHelpOpen == true)
135         {
136             containerHeight += GetInterpolateHelpBoxHeight();
137         }
138
139         if (this.m_ExtrapolateHelpOpen == true)
140         {
141             containerHeight += GetExtrapolateHelpBoxHeight();
142         }
143
144         // removed Gizmo Options. -3 lines, -1 splitter
145         containerHeight -= EDITOR_LINE_HEIGHT * 2;
146
147         Rect rect = PhotonGUI.ContainerBody(containerHeight);
148
149         Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
150
151         DrawTeleport(ref propertyRect);
152         DrawSplitter(ref propertyRect);
153
154         DrawSynchronizePositionDataInterpolation(ref propertyRect, interpolatePositionProperty, interpolateOption);
155         DrawSplitter(ref propertyRect);
156
157         DrawSynchronizePositionDataExtrapolation(ref propertyRect, extrapolatePositionProperty, extrapolateOption);
158         DrawSplitter(ref propertyRect);
159
160         DrawSynchronizePositionDataGizmos(ref propertyRect);
161     }
File name: PhotonTransformViewEditor.cs Copy
232     private void DrawSynchronizePositionDataExtrapolation(ref Rect propertyRect, SerializedProperty extrapolatePositionProperty, PhotonTransformViewPositionModel.ExtrapolateOptions extrapolateOption)
233     {
234         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_ExtrapolateHelpOpen, extrapolatePositionProperty, EXTRAPOLATE_TOOLTIP);
235         DrawHelpBox(ref propertyRect, this.m_ExtrapolateHelpOpen, GetExtrapolateHelpBoxHeight(), EXTRAPOLATE_HELP, EXTRAPOLATE_HELP_URL);
236
237         if (extrapolateOption != PhotonTransformViewPositionModel.ExtrapolateOptions.Disabled)
238         {
239             EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.ExtrapolateIncludingRoundTripTime"));
240             propertyRect.y += EDITOR_LINE_HEIGHT;
241         }
242
243         switch (extrapolateOption)
244         {
245             case PhotonTransformViewPositionModel.ExtrapolateOptions.FixedSpeed:
246                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.ExtrapolateSpeed"));
247                 propertyRect.y += EDITOR_LINE_HEIGHT;
248                 break;
249         }
250     }
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     }
File name: PhotonTransformViewEditor.cs Copy
309     private void DrawSynchronizeRotationData()
310     {
311         if (this.m_SynchronizeRotationProperty == null || this.m_SynchronizeRotationProperty.boolValue == false)
312         {
313             return;
314         }
315
316         SerializedProperty interpolateRotationProperty = serializedObject.FindProperty("m_RotationModel.InterpolateOption");
317         PhotonTransformViewRotationModel.InterpolateOptions interpolateOption =
318             (PhotonTransformViewRotationModel.InterpolateOptions) interpolateRotationProperty.enumValueIndex;
319
320         float containerHeight = 20;
321
322         switch (interpolateOption)
323         {
324             case PhotonTransformViewRotationModel.InterpolateOptions.RotateTowards:
325             case PhotonTransformViewRotationModel.InterpolateOptions.Lerp:
326                 containerHeight += EDITOR_LINE_HEIGHT;
327                 break;
328         }
329
330         if (this.m_InterpolateRotationHelpOpen == true)
331         {
332             containerHeight += GetInterpolateHelpBoxHeight();
333         }
334
335         Rect rect = PhotonGUI.ContainerBody(containerHeight);
336         Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
337
338         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateRotationHelpOpen, interpolateRotationProperty, INTERPOLATE_TOOLTIP);
339         DrawHelpBox(ref propertyRect, this.m_InterpolateRotationHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
340
341         switch (interpolateOption)
342         {
343             case PhotonTransformViewRotationModel.InterpolateOptions.RotateTowards:
344                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_RotationModel.InterpolateRotateTowardsSpeed"),
345                     new GUIContent("RotateTowards Speed"));
346                 break;
347             case PhotonTransformViewRotationModel.InterpolateOptions.Lerp:
348                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_RotationModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
349                 break;
350         }
351     }
File name: PhotonTransformViewEditor.cs Copy
358     private void DrawSynchronizeScaleData()
359     {
360         if (this.m_SynchronizeScaleProperty == null || this.m_SynchronizeScaleProperty.boolValue == false)
361         {
362             return;
363         }
364
365         SerializedProperty interpolateScaleProperty = serializedObject.FindProperty("m_ScaleModel.InterpolateOption");
366         PhotonTransformViewScaleModel.InterpolateOptions interpolateOption = (PhotonTransformViewScaleModel.InterpolateOptions) interpolateScaleProperty.enumValueIndex;
367
368         float containerHeight = EDITOR_LINE_HEIGHT;
369
370         switch (interpolateOption)
371         {
372             case PhotonTransformViewScaleModel.InterpolateOptions.MoveTowards:
373             case PhotonTransformViewScaleModel.InterpolateOptions.Lerp:
374                 containerHeight += EDITOR_LINE_HEIGHT;
375                 break;
376         }
377
378         if (this.m_InterpolateScaleHelpOpen == true)
379         {
380             containerHeight += GetInterpolateHelpBoxHeight();
381         }
382
383         Rect rect = PhotonGUI.ContainerBody(containerHeight);
384         Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
385
386         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateScaleHelpOpen, interpolateScaleProperty, INTERPOLATE_TOOLTIP);
387         DrawHelpBox(ref propertyRect, this.m_InterpolateScaleHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
388
389         switch (interpolateOption)
390         {
391             case PhotonTransformViewScaleModel.InterpolateOptions.MoveTowards:
392                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_ScaleModel.InterpolateMoveTowardsSpeed"),
393                     new GUIContent("MoveTowards Speed"));
394                 break;
395             case PhotonTransformViewScaleModel.InterpolateOptions.Lerp:
396                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_ScaleModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
397                 break;
398         }
399     }
File name: PhotonTransformView.cs Copy
38     void Awake()
39     {
40         m_PhotonView = GetComponent();
41
42         m_PositionControl = new PhotonTransformViewPositionControl( m_PositionModel );
43         m_RotationControl = new PhotonTransformViewRotationControl( m_RotationModel );
44         m_ScaleControl = new PhotonTransformViewScaleControl( m_ScaleModel );
45     }

Download file with original file name:PhotonTransformView

PhotonTransformView 124 lượt xem

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