本文整理汇总了C#中UnityEditor.SerializedProperty.GetArrayElementAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedProperty.GetArrayElementAtIndex方法的具体用法?C# SerializedProperty.GetArrayElementAtIndex怎么用?C# SerializedProperty.GetArrayElementAtIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedProperty
的用法示例。
在下文中一共展示了SerializedProperty.GetArrayElementAtIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoPicking
protected static void DoPicking(Rect rect, SerializedProperty bodyMask, int count)
{
if (!(bool) ((Object) BodyMaskEditor.styles.PickingTexture.image))
return;
int controlId = GUIUtility.GetControlID(BodyMaskEditor.s_Hint, FocusType.Native, rect);
Event current = Event.current;
if (current.GetTypeForControl(controlId) != EventType.MouseDown || !rect.Contains(current.mousePosition))
return;
current.Use();
int x = (int) current.mousePosition.x - (int) rect.x;
int y = BodyMaskEditor.styles.UnityDude.image.height - ((int) current.mousePosition.y - (int) rect.y);
Color pixel = (BodyMaskEditor.styles.PickingTexture.image as Texture2D).GetPixel(x, y);
bool flag1 = false;
for (int index = 0; index < count; ++index)
{
if (BodyMaskEditor.m_MaskBodyPartPicker[index] == pixel)
{
GUI.changed = true;
bodyMask.GetArrayElementAtIndex(index).intValue = bodyMask.GetArrayElementAtIndex(index).intValue != 1 ? 1 : 0;
flag1 = true;
}
}
if (flag1)
return;
bool flag2 = false;
for (int index = 0; index < count && !flag2; ++index)
flag2 = bodyMask.GetArrayElementAtIndex(index).intValue == 1;
for (int index = 0; index < count; ++index)
bodyMask.GetArrayElementAtIndex(index).intValue = flag2 ? 0 : 1;
GUI.changed = true;
}
示例2: Show
public static void Show(SerializedProperty bodyMask, int count)
{
if (styles.UnityDude.image != null)
{
GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth((float) styles.UnityDude.image.width) };
Rect position = GUILayoutUtility.GetRect(styles.UnityDude, GUIStyle.none, options);
position.x += (GUIView.current.position.width - position.width) / 2f;
Color color = GUI.color;
GUI.color = (bodyMask.GetArrayElementAtIndex(0).intValue != 1) ? Color.red : Color.green;
if (styles.BodyPart[0].image != null)
{
GUI.DrawTexture(position, styles.BodyPart[0].image);
}
GUI.color = new Color(0.2f, 0.2f, 0.2f, 1f);
GUI.DrawTexture(position, styles.UnityDude.image);
for (int i = 1; i < count; i++)
{
GUI.color = (bodyMask.GetArrayElementAtIndex(i).intValue != 1) ? Color.red : Color.green;
if (styles.BodyPart[i].image != null)
{
GUI.DrawTexture(position, styles.BodyPart[i].image);
}
}
GUI.color = color;
DoPicking(position, bodyMask, count);
}
}
示例3: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if(!property.isArray)
{
EditorGUI.PropertyField(position, property, label, false);
return;
}
if (property.arraySize == 0) property.arraySize = 1;
if (property.arraySize == 1)
{
var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(0), label) : EditorGUIUtility.singleLineHeight;
var propArea = new Rect(position.xMin, position.yMin, Mathf.Max(0f, position.width - BTN_WIDTH), elementHeight);
var btnArea = new Rect(propArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight);
if (_internalDrawer != null)
_internalDrawer.OnGUI(propArea, property.GetArrayElementAtIndex(0), label);
else
SPEditorGUI.DefaultPropertyField(propArea, property.GetArrayElementAtIndex(0), label);
if (GUI.Button(btnArea, _moreBtnLabel))
{
property.arraySize = 2;
}
}
else
{
var elementArea = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
//draw header
var leftOverArea = EditorGUI.PrefixLabel(elementArea, label ?? GUIContent.none);
var sizeArea = new Rect(Mathf.Max(leftOverArea.xMin, leftOverArea.xMax - BTN_WIDTH - SIZE_WIDTH),
leftOverArea.yMin,
Mathf.Min(SIZE_WIDTH, Mathf.Max(0f, leftOverArea.width - BTN_WIDTH)), EditorGUIUtility.singleLineHeight);
var btnArea = new Rect(sizeArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight);
property.arraySize = Mathf.Max(EditorGUI.IntField(sizeArea, property.arraySize), 1);
if(GUI.Button(btnArea, _oneBtnLabel))
{
property.arraySize = 1;
}
EditorGUI.indentLevel++;
for(int i = 0; i < property.arraySize; i++)
{
var lbl = EditorHelper.TempContent("Element " + i.ToString());
var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(i), lbl) : EditorGUIUtility.singleLineHeight;
elementArea = new Rect(position.xMin, elementArea.yMax, position.width, elementHeight);
if (_internalDrawer != null)
_internalDrawer.OnGUI(elementArea, property.GetArrayElementAtIndex(i), lbl);
else
SPEditorGUI.DefaultPropertyField(elementArea, property.GetArrayElementAtIndex(i), lbl);
}
EditorGUI.indentLevel--;
}
}
示例4: ShowAnimationList
void ShowAnimationList(SerializedProperty animations)
{
var count = animations.arraySize;
// FIXME: should be replaced with DelayedIntField in 5.3
count = EditorGUILayout.IntField("Animation Count", count);
count = Mathf.Max(count, 1);
// enlarge/shrink the list when the size is changed
while (count > animations.arraySize)
animations.InsertArrayElementAtIndex(animations.arraySize - 1);
while (count < animations.arraySize)
animations.DeleteArrayElementAtIndex(animations.arraySize - 1);
EditorGUI.indentLevel++;
for (var i = 0; i < animations.arraySize; i++)
{
var data = animations.GetArrayElementAtIndex(i);
var label_i = new GUIContent("Animation " + i);
EditorGUILayout.PropertyField(data, label_i);
}
EditorGUI.indentLevel--;
}
示例5: AddNewElementToProp
/// <summary>
/// Adds a new element to an array property.
/// </summary>
public static void AddNewElementToProp(SerializedProperty property)
{
if (property.isArray) {
property.arraySize++;
ClearPropValue(property.GetArrayElementAtIndex(property.arraySize - 1));
}
}
示例6: Show
public static void Show(SerializedProperty list)
{
EditorGUILayout.PropertyField(list);
EditorGUI.indentLevel += 1;
if (list.isExpanded)
{
EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
//EditorGUILayout.BeginHorizontal();
//EditorGUILayout.IntField("X", 0);
//EditorGUILayout.IntField("Y", 0);
//EditorGUILayout.IntField("Z", 0);
//EditorGUILayout.EndHorizontal();
if (list.arraySize>0)
for (int i = 0; i < list.arraySize; i++)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i),GUIContent.none);
ShowButtons(list,i);
EditorGUILayout.EndHorizontal();
}
else
{
if (GUILayout.Button(addButtonContent))
list.InsertArrayElementAtIndex(0);
}
}
EditorGUI.indentLevel -= 1;
}
示例7: DrawListLayout
public static void DrawListLayout(SerializedProperty property)
{
EditorGUILayout.PropertyField (property);
EditorGUI.indentLevel++;
if (property.isExpanded) {
for (int i = 0; i < property.arraySize; i++) {
EditorGUILayout.BeginHorizontal ();
EditorGUILayout.PropertyField (property.GetArrayElementAtIndex (i), true);
if (GUILayout.Button (moveButtonContent, EditorStyles.miniButtonLeft, GUILayout.Width(20))) {
property.MoveArrayElement (i, i + 1);
}
if (GUILayout.Button (duplicateButtonContent, EditorStyles.miniButtonMid, GUILayout.Width(20))) {
property.InsertArrayElementAtIndex (i);
}
if (GUILayout.Button (deleteButtonContent, EditorStyles.miniButtonRight, GUILayout.Width(20))) {
int oldsize = property.arraySize;
property.DeleteArrayElementAtIndex (i);
if (oldsize == property.arraySize) {
property.DeleteArrayElementAtIndex (i);
}
}
EditorGUILayout.EndHorizontal ();
}
if (GUILayout.Button (addButtonContent, EditorStyles.miniButton)) {
property.arraySize += 1;
}
}
EditorGUI.indentLevel--;
}
示例8: OnEnable
protected virtual void OnEnable()
{
hideFlags = HideFlags.HideAndDontSave;
instance = target as Gesture;
advanced = serializedObject.FindProperty("advancedProps");
friendlyGestures = serializedObject.FindProperty("friendlyGestures");
requireGestureToFail = serializedObject.FindProperty("requireGestureToFail");
combineTouches = serializedObject.FindProperty("combineTouches");
combineTouchesInterval = serializedObject.FindProperty("combineTouchesInterval");
useSendMessage = serializedObject.FindProperty("useSendMessage");
sendMessageTarget = serializedObject.FindProperty("sendMessageTarget");
sendStateChangeMessages = serializedObject.FindProperty("sendStateChangeMessages");
friendlyGesturesList = new ReorderableList(serializedObject, friendlyGestures, false, false, false, true);
friendlyGesturesList.headerHeight = 0;
friendlyGesturesList.drawElementCallback += (rect, index, active, focused) =>
{
rect.height = 16;
var gesture = friendlyGestures.GetArrayElementAtIndex(index).objectReferenceValue as Gesture;
if (gesture == null)
{
// Killing null elements.
indexToRemove = index;
EditorGUI.LabelField(rect, GUIContent.none);
return;
}
EditorGUI.LabelField(rect, string.Format("{0} @ {1}", gesture.GetType().Name, gesture.name), GUIElements.BoxLabelStyle);
};
friendlyGesturesList.onRemoveCallback += list => { indexToRemove = list.index; };
}
示例9: GetPropertyHeight
public static float GetPropertyHeight (SerializedProperty _arrayProperty, eArrayOptions _options)
{
int _count = _arrayProperty.arraySize;
bool _showArraySize = (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;
float _singleLineHeight = EditorGUIUtility.singleLineHeight;
float _totalHeight = 0f;
// Height for array name
_totalHeight += _singleLineHeight + kSpacingPixels;
// Is foldout enabled, then dont show the rest of the elements
if (_arrayProperty.isExpanded)
{
// If we showing array size then we need to consider it
if (_showArraySize && _count != 0)
_totalHeight += (EditorGUIUtility.singleLineHeight + kSpacingPixels);
// If there are no elements then we will show button to add elements
if (_count == 0)
{
// Add height of button and extra spacing
_totalHeight += (EditorGUIUtility.singleLineHeight + kSpacingPixels);
}
// We do have contents within array
else
{
// Includes height for each element, height of edit bar, spacing
for (int _iter = 0; _iter < _count; _iter++)
_totalHeight+= EditorGUI.GetPropertyHeight(_arrayProperty.GetArrayElementAtIndex(_iter)) + EditorGUIUtility.singleLineHeight + kSpacingPixels;
}
}
return _totalHeight;
}
示例10: DrawList
private void DrawList(SerializedProperty list)
{
for(int n = 0; n < list.arraySize; n++)
{
EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(n));
}
}
示例11: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
List1 = property.FindPropertyRelative("CharList1");
#region FORMATTING (IGNORE IT)
GUI.Box(position, "");
position.height = SINGLE_LINE_HEIGHT;
position.y += HALF_BORDER;
position.x += BUTTON_WIDTH + FULL_BORDER + HALF_BORDER;
position.width -= BUTTON_WIDTH + FULL_BORDER + FULL_BORDER;
#endregion
for (int i = 0; i < List1.arraySize; i++) {
Rect deleteButton = new Rect(position.x - BUTTON_WIDTH - FULL_BORDER, position.y, BUTTON_WIDTH, position.height);
if (GUI.Button(deleteButton, _deleteButtonContent)) {
List1.DeleteArrayElementAtIndex(i); //This is the line that breaks things...
return;
}
EditorGUI.PropertyField(position, List1.GetArrayElementAtIndex(i), new GUIContent(""));
position.y += position.height + HALF_BORDER;
}
#region Add new element (IGNORE)
position.x -= BUTTON_WIDTH + FULL_BORDER;
position.width += BUTTON_WIDTH + FULL_BORDER;
if (GUI.Button(position, "Add new element")) {
List1.arraySize++;
}
#endregion
}
示例12: GetHeight
public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
{
if (_visibleDrawer == null) this.Init();
property = property.Copy();
if (label == null) label = EditorHelper.TempContent(property.displayName);
if (_visibleDrawer is IArrayHandlingPropertyDrawer || !property.isArray)
{
return _visibleDrawer.GetPropertyHeight(property, label);
}
else
{
float h = SPEditorGUI.GetSinglePropertyHeight(property, label);
if (!includeChildren || !property.isExpanded) return h;
h += EditorGUIUtility.singleLineHeight + 2f;
for(int i = 0; i < property.arraySize; i++)
{
var pchild = property.GetArrayElementAtIndex(i);
h += _visibleDrawer.GetPropertyHeight(pchild, EditorHelper.TempContent(pchild.displayName)) + 2f;
}
return h;
}
}
示例13: ShowList
private static void ShowList(SerializedProperty list)
{
EditorGUILayout.PropertyField(list);
for (int i = 0; i < list.arraySize; i++)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));
if (GUILayout.Button("Remove"))
{
int oldSize = list.arraySize;
list.DeleteArrayElementAtIndex(i);
if (list.arraySize == oldSize)
{
list.DeleteArrayElementAtIndex(i);
}
}
EditorGUILayout.EndHorizontal();
}
if (GUILayout.Button("Add required Skill"))
{
list.arraySize += 1;
}
}
示例14: OnEnable
private void OnEnable()
{
instance = target as TouchManager;
layers = serializedObject.FindProperty("layers");
displayDevice = serializedObject.FindProperty("displayDevice");
useSendMessage = serializedObject.FindProperty("useSendMessage");
sendMessageTarget = serializedObject.FindProperty("sendMessageTarget");
sendMessageEvents = serializedObject.FindProperty("sendMessageEvents");
refresh();
layersList = new ReorderableList(serializedObject, layers, true, true, false, false);
layersList.drawHeaderCallback += rect => GUI.Label(rect, LAYERS_HEADER);
layersList.drawElementCallback += (rect, index, active, focused) =>
{
rect.height = 16;
rect.y += 2;
if (index >= layers.arraySize) return;
var layer = layers.GetArrayElementAtIndex(index).objectReferenceValue as TouchLayer;
if (layer == null)
{
EditorGUI.LabelField(rect, "null");
return;
}
EditorGUI.LabelField(rect, layer.Name);
};
}
示例15: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
position.height = 16f;
foldout = EditorGUI.Foldout(position, foldout, label);
if (foldout)
{
//EditorGUI.BeginChangeCheck();
//{
// Rect rect = EditorGUI.IndentedRect(position);
// int size = property.arraySize;
// size = EditorGUI.IntField(rect, size);
//}
//if (EditorGUI.EndChangeCheck())
//{
// property.
//}
string[] names = Enum.GetNames(nameListAttribute.enumType);
Rect rect = EditorGUI.IndentedRect(position);
//rect.height = GetPropertyHeight()
for (int i = 0; i < names.Length; i++)
{
rect.y += rect.height;
//rect.height = 15f;
EditorGUI.PropertyField(rect, property.GetArrayElementAtIndex(i), new GUIContent(i >= names.Length ? "" : names[i]));
}
}
}