Container









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

Featured Snippets


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     }
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
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
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: PhotonTransformViewEditor.cs Copy
401     private void DrawHeader(string label, SerializedProperty property)
402     {
403         if (property == null)
404         {
405             return;
406         }
407
408         bool newValue = PhotonGUI.ContainerHeaderToggle(label, property.boolValue);
409
410         if (newValue != property.boolValue)
411         {
412             Undo.RecordObject(this.m_Target, "Change " + label);
413             property.boolValue = newValue;
414             EditorUtility.SetDirty(this.m_Target);
415         }
416     }
File name: PhotonGUI.cs Copy
33     {
34         get
35         {
36             if( m_DefaultContainerStyle == null )
37             {
38                 m_DefaultContainerStyle = new GUIStyle();
39                 m_DefaultContainerStyle.border = new RectOffset( 2, 2, 1, 2 );
40                 m_DefaultContainerStyle.margin = new RectOffset( 5, 5, 5, 5 );
41                 m_DefaultContainerStyle.padding = new RectOffset( 1, 1, 2, 2 );
42                 m_DefaultContainerStyle.normal.background = ReorderableListResources.texContainerBackground;
43             }
44
45             return m_DefaultContainerStyle;
46         }
47     }
File name: PhotonGUI.cs Copy
88     {
89         get
90         {
91             if( m_DefaultContainerRowStyle == null )
92             {
93                 m_DefaultContainerRowStyle = new GUIStyle();
94                 m_DefaultContainerRowStyle.border = new RectOffset( 2, 2, 2, 2 );
95
96                 m_DefaultContainerRowStyle.margin = new RectOffset( 5, 5, 5, 5 );
97                 m_DefaultContainerRowStyle.padding = new RectOffset( 1, 1, 2, 2 );
98                 m_DefaultContainerRowStyle.normal.background = ReorderableListResources.texContainerBackground;
99             }
100
101             return m_DefaultContainerRowStyle;
102         }
103     }

Download file with original file name:Container

Container 122 lượt xem

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