PhotonAnimatorView









How do I use Photon Animator 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: DemoMecanimGUI.cs Copy
16     private PhotonAnimatorView m_AnimatorView; // local animatorView. set when we create our character in CreatePlayerObject()
17     private Animator m_RemoteAnimator; // to display the synchronized values on the right side in the GUI. A third player will simply be ignored (until the second player leaves)
28     public void Awake()
29     {
30
31     }
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: DemoMecanimGUI.cs Copy
192     private void CreatePlayerObject()
193     {
194         Vector3 position = new Vector3( -2, 0, 0 );
195         position.x += Random.Range( -3f, 3f );
196         position.z += Random.Range( -4f, 4f );
197
198         GameObject newPlayerObject = PhotonNetwork.Instantiate( "Robot Kyle Mecanim", position, Quaternion.identity, 0 );
199         m_AnimatorView = newPlayerObject.GetComponent();
200     }
File name: PhotonAnimatorViewEditor.cs Copy
54     private void OnEnable()
55     {
56         this.m_Target = (PhotonAnimatorView) target;
57         this.m_Animator = this.m_Target.GetComponent();
58
59#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
60         this.m_Controller = AnimatorController.GetEffectiveAnimatorController(this.m_Animator);
61#endif
62
63         CheckIfStoredParametersExist();
64     }
File name: PhotonAnimatorViewEditor.cs Copy
66     private void DrawWeightInspector()
67     {
68         SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowLayerWeightsInspector");
69         foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Layer Weights", foldoutProperty.boolValue);
70
71         if (foldoutProperty.boolValue == false)
72         {
73             return;
74         }
75
76         float lineHeight = 20;
77         Rect containerRect = PhotonGUI.ContainerBody(this.m_Animator.layerCount*lineHeight);
78
79         for (int i = 0; i < this.m_Animator.layerCount; ++i)
80         {
81             if (this.m_Target.DoesLayerSynchronizeTypeExist(i) == false)
82             {
83                 this.m_Target.SetLayerSynchronized(i, PhotonAnimatorView.SynchronizeType.Disabled);
84                 EditorUtility.SetDirty(this.m_Target);
85             }
86
87             PhotonAnimatorView.SynchronizeType value = this.m_Target.GetLayerSynchronizeType(i);
88
89             Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);
90
91             Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
92             GUI.Label(labelRect, "Layer " + i);
93
94             Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
95             value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);
96
97             if (i < this.m_Animator.layerCount - 1)
98             {
99                 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
100                 PhotonGUI.DrawSplitter(splitterRect);
101             }
102
103             if (value != this.m_Target.GetLayerSynchronizeType(i))
104             {
105                 Undo.RecordObject(target, "Modify Synchronize Layer Weights");
106                 this.m_Target.SetLayerSynchronized(i, value);
107
108                 EditorUtility.SetDirty(this.m_Target);
109             }
110         }
111     }
File name: PhotonAnimatorViewEditor.cs Copy
179     private void DrawParameterInspector()
180     {
181         SerializedProperty foldoutProperty = serializedObject.FindProperty("ShowParameterInspector");
182         foldoutProperty.boolValue = PhotonGUI.ContainerHeaderFoldout("Synchronize Parameters", foldoutProperty.boolValue);
183
184         if (foldoutProperty.boolValue == false)
185         {
186             return;
187         }
188
189         float lineHeight = 20;
190         Rect containerRect = PhotonGUI.ContainerBody(GetParameterCount()*lineHeight);
191
192         for (int i = 0; i < GetParameterCount(); i++)
193         {
194             AnimatorControllerParameter parameter = null;
195
196#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6
197             parameter = this.m_Controller.GetParameter(i);
198#else
199             parameter = m_Animator.parameters[ i ];
200#endif
201
202             string defaultValue = "";
203
204             if (parameter.type == AnimatorControllerParameterType.Bool)
205             {
206                 defaultValue += parameter.defaultBool.ToString();
207             }
208             else if (parameter.type == AnimatorControllerParameterType.Float)
209             {
210                 defaultValue += parameter.defaultFloat.ToString();
211             }
212             else if (parameter.type == AnimatorControllerParameterType.Int)
213             {
214                 defaultValue += parameter.defaultInt.ToString();
215             }
216
217             if (this.m_Target.DoesParameterSynchronizeTypeExist(parameter.name) == false)
218             {
219                 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, PhotonAnimatorView.SynchronizeType.Disabled);
220                 EditorUtility.SetDirty(this.m_Target);
221             }
222
223             PhotonAnimatorView.SynchronizeType value = this.m_Target.GetParameterSynchronizeType(parameter.name);
224
225             Rect elementRect = new Rect(containerRect.xMin, containerRect.yMin + i*lineHeight, containerRect.width, lineHeight);
226
227             Rect labelRect = new Rect(elementRect.xMin + 5, elementRect.yMin + 2, EditorGUIUtility.labelWidth - 5, elementRect.height);
228             GUI.Label(labelRect, parameter.name + " (" + defaultValue + ")");
229
230             Rect popupRect = new Rect(elementRect.xMin + EditorGUIUtility.labelWidth, elementRect.yMin + 2, elementRect.width - EditorGUIUtility.labelWidth - 5, EditorGUIUtility.singleLineHeight);
231             value = (PhotonAnimatorView.SynchronizeType) EditorGUI.EnumPopup(popupRect, value);
232
233             if (i < GetParameterCount() - 1)
234             {
235                 Rect splitterRect = new Rect(elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1);
236                 PhotonGUI.DrawSplitter(splitterRect);
237             }
238
239             if (value != this.m_Target.GetParameterSynchronizeType(parameter.name))
240             {
241                 Undo.RecordObject(target, "Modify Synchronize Parameter " + parameter.name);
242                 this.m_Target.SetParameterSynchronized(parameter.name, (PhotonAnimatorView.ParameterType) parameter.type, value);
243
244                 EditorUtility.SetDirty(this.m_Target);
245             }
246         }
247     }

Download file with original file name:PhotonAnimatorView

PhotonAnimatorView 172 lượt xem

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