本文整理汇总了C#中UnityEditor.SerializedProperty.MoveArrayElement方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedProperty.MoveArrayElement方法的具体用法?C# SerializedProperty.MoveArrayElement怎么用?C# SerializedProperty.MoveArrayElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedProperty
的用法示例。
在下文中一共展示了SerializedProperty.MoveArrayElement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowButtons
private static bool ShowButtons(SerializedProperty _list, int _index)
{
EditorGUILayout.BeginHorizontal();
{
if (GUILayout.Button(moveUpBtn, EditorStyles.miniButton))
{
_list.MoveArrayElement(_index, _index - 1);
return true;
}
if (GUILayout.Button(moveDnBtn, EditorStyles.miniButton))
{
_list.MoveArrayElement(_index, _index + 1);
return true;
}
if (GUILayout.Button(deleteBtn, EditorStyles.miniButton))
{
_list.DeleteArrayElementAtIndex(_index);
return true;
}
if (GUILayout.Button(dupeBtn, EditorStyles.miniButton))
{
AddNewArrayElement(_list, _index);
return true;
}
}
EditorGUILayout.EndHorizontal();
return false;
}
示例2: AttackPatternField
public void AttackPatternField(SerializedProperty attackPatterns)
{
Vector3 moveRemove = new Vector3(-1f, -1f, 0f);
int c = attackPatterns.FindPropertyRelative ("Array.size").intValue;
if(c < 1)
{
attackPatterns.InsertArrayElementAtIndex(0);
attackPatterns.GetArrayElementAtIndex(0).objectReferenceValue = gameObject.GetComponent<AbstractAttackPattern>();
}
for(int i = 0; i < c; i++)
{
EditorGUILayout.BeginHorizontal();
SerializedProperty arrayElement = attackPatterns.GetArrayElementAtIndex(i);
AbstractAttackPattern ap = (AbstractAttackPattern)arrayElement.objectReferenceValue;
EditorGUILayout.PropertyField(arrayElement, new GUIContent((ap != null) ? GetAttackPatternName(ap) : i.ToString()));
moveRemove = DanmakuEditorUtils.UpDownRemoveButtons(moveRemove, c, i, false);
EditorGUILayout.EndHorizontal();
}
if (moveRemove.y >= 0)
{
int removeIndex = (int)moveRemove.y;
if(attackPatterns.GetArrayElementAtIndex(removeIndex).objectReferenceValue != null)
{
attackPatterns.DeleteArrayElementAtIndex(removeIndex);
}
attackPatterns.DeleteArrayElementAtIndex(removeIndex);
}
if (moveRemove.x >= 0)
{
int moveIndex = (int)moveRemove.x;
if (moveRemove.z > 0)
{
attackPatterns.MoveArrayElement (moveIndex, moveIndex + 1);
}
if (moveRemove.z < 0)
{
attackPatterns.MoveArrayElement (moveIndex, moveIndex - 1);
}
}
if (GUILayout.Button("Add"))
{
attackPatterns.InsertArrayElementAtIndex(c);
}
}
示例3: ShowButtons
static void ShowButtons(SerializedProperty list, int index)
{
if (GUILayout.Button(moveButtonContent, EditorStyles.miniButtonLeft, miniButtonWidth)) {
list.MoveArrayElement(index, index + 1);
}
if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonMid, miniButtonWidth)) {
list.InsertArrayElementAtIndex(index);
}
if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth)) {
int oldSize = list.arraySize;
list.DeleteArrayElementAtIndex(index);
if (list.arraySize == oldSize) {
list.DeleteArrayElementAtIndex(index);
}
}
}
示例4: DrawList
public static void DrawList(ref Rect position, SerializedProperty property)
{
position.height = 16;
EditorGUI.PropertyField (position, property);
position.y += 18;
EditorGUI.indentLevel++;
if (property.isExpanded) {
Rect buttonPosition;
for (int i = 0; i < property.arraySize; i++) {
buttonPosition = position;
buttonPosition.height = 16;
buttonPosition.width = 20;
buttonPosition.x += position.width - 62;
if (GUI.Button (buttonPosition, moveButtonContent, EditorStyles.miniButtonLeft)) {
property.MoveArrayElement (i, i + 1);
}
buttonPosition.x += 20;
if (GUI.Button (buttonPosition, duplicateButtonContent, EditorStyles.miniButtonMid)) {
property.InsertArrayElementAtIndex (i);
}
buttonPosition.x += 20;
if (GUI.Button (buttonPosition, deleteButtonContent, EditorStyles.miniButtonRight)) {
int oldsize = property.arraySize;
property.DeleteArrayElementAtIndex (i);
if (oldsize == property.arraySize) {
property.DeleteArrayElementAtIndex (i);
}
} else {
DrawProperty (ref position, property.GetArrayElementAtIndex (i), true);
}
}
buttonPosition = position;
buttonPosition.height = 16;
buttonPosition.width -= EditorGUI.indentLevel * 16;
buttonPosition.x += EditorGUI.indentLevel * 16;
if (GUI.Button (buttonPosition, addButtonContent, EditorStyles.miniButton)) {
property.arraySize += 1;
}
position.y += 18;
}
EditorGUI.indentLevel--;
}
示例5: ShowButtons
//private static Color _oldColor;
private static bool ShowButtons(Rect position, SerializedProperty property, int index)
{
var result = false;
var pos = new Rect(position);
pos.y += 4;
if (GUI.Button(pos, GuiContentCache.Instance.EditSelector, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonMid
{
//EditorUtility.DisplayDialog("Editing selector", "Not implemented.", "Close");
SerializedProperty declaration = property.GetArrayElementAtIndex(index);
EditStyleDeclarationCommand.Execute(declaration);
}
pos.x += ButtonWidth;
if (GUI.Button(pos, GuiContentCache.Instance.Duplicate, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonMid
{
bool expanded = property.GetArrayElementAtIndex(index).isExpanded;
property.InsertArrayElementAtIndex(index);
SerializedProperty newItem = property.GetArrayElementAtIndex(index);
newItem.Reset();
newItem.isExpanded = expanded;
}
pos.x += ButtonWidth;
if (GUI.Button(pos, GuiContentCache.Instance.Delete, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonRight
{
if (EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to remove this style declaration?", "OK", "Cancel"))
result = true;
}
// move buttons
if (index == 0)
GUI.enabled = false;
pos.x += ButtonWidth;
if (GUI.Button(pos, GuiContentCache.Instance.MoveUp, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonLeft
{
if (index > 0)
{
bool expanded1 = property.GetArrayElementAtIndex(index).isExpanded;
bool expanded2 = property.GetArrayElementAtIndex(index - 1).isExpanded;
property.MoveArrayElement(index, index - 1);
property.GetArrayElementAtIndex(index).isExpanded = expanded1;
property.GetArrayElementAtIndex(index - 1).isExpanded = expanded2;
ShouldProcessStyles = true;
}
}
pos.x += ButtonWidth;
if (index == 0)
GUI.enabled = true;
if (index == _size - 1)
GUI.enabled = false;
if (GUI.Button(pos, GuiContentCache.Instance.MoveDown, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonLeft
{
bool expanded1 = property.GetArrayElementAtIndex(index).isExpanded;
bool expanded2 = property.GetArrayElementAtIndex(index + 1).isExpanded;
property.MoveArrayElement(index, index + 1);
property.GetArrayElementAtIndex(index).isExpanded = expanded1;
property.GetArrayElementAtIndex(index + 1).isExpanded = expanded2;
ShouldProcessStyles = true;
}
if (index == _size - 1)
GUI.enabled = true;
pos.x += ButtonWidth;
return result;
}
示例6: 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--;
}
示例7: ShowButtons
private static bool ShowButtons(Rect position, SerializedProperty property, int index)
{
var result = false;
var pos = new Rect(position);
pos.y -= 4;
if (GUI.Button(pos, GuiContentCache.Instance.Delete, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonRight
{
result = true; // removed //property.DeleteArrayElementAtIndex(index);
}
// move buttons
if (index == 0)
GUI.enabled = false;
pos.x += ButtonWidth;
if (GUI.Button(pos, GuiContentCache.Instance.MoveUp, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonLeft
{
if (index > 0)
{
bool expanded1 = property.GetArrayElementAtIndex(index).isExpanded;
bool expanded2 = property.GetArrayElementAtIndex(index - 1).isExpanded;
property.MoveArrayElement(index, index - 1);
property.GetArrayElementAtIndex(index).isExpanded = expanded1;
property.GetArrayElementAtIndex(index - 1).isExpanded = expanded2;
}
}
pos.x += ButtonWidth;
if (index == 0)
GUI.enabled = true;
if (index == _size - 1)
GUI.enabled = false;
if (GUI.Button(pos, GuiContentCache.Instance.MoveDown, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonLeft
{
bool expanded1 = property.GetArrayElementAtIndex(index).isExpanded;
bool expanded2 = property.GetArrayElementAtIndex(index + 1).isExpanded;
property.MoveArrayElement(index, index + 1);
property.GetArrayElementAtIndex(index).isExpanded = expanded1;
property.GetArrayElementAtIndex(index + 1).isExpanded = expanded2;
}
if (index == _size - 1)
GUI.enabled = true;
pos.x += ButtonWidth;
//GUI.color = _oldColor;
return result;
}
示例8: AddArray
public static void AddArray(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, bool changeOrder, DrawArrayElement drawArrayElement = null, OnAddToArray onAddToArray = null, DrawArrayElementLabel drawArrayElementLabel = null, bool showHeading = true) {
int resetIndent = EditorGUI.indentLevel;
// Array heading
if (showHeading) {
GUILayout.BeginHorizontal();
GUILayout.Space(EditorGUI.indentLevel * indent);
if (drawArrayElement == null) {
GUILayout.Label(guiContent.text + " (" + prop.arraySize.ToString() + ")", GUILayout.Width(150));
} else {
EditorGUILayout.PropertyField(prop, new GUIContent(guiContent.text + " (" + prop.arraySize.ToString() + ")", string.Empty), false, GUILayout.Width(150));
}
GUILayout.EndHorizontal();
}
int deleteIndex = -1;
if (drawArrayElement == null || !showHeading) prop.isExpanded = true;
// Draw Array elements
if (prop.isExpanded) {
for(int i = 0; i < prop.arraySize; i++) {
GUILayout.BeginHorizontal(); // Main
GUILayout.Space(((EditorGUI.indentLevel + 1) * indent));
GUILayout.BeginVertical();
element = prop.GetArrayElementAtIndex(i);
// Label
GUILayout.BeginHorizontal();
if (editHierarchy && GUILayout.Button(new GUIContent("-", "Remove"), changeOrder? EditorStyles.miniButtonLeft: EditorStyles.miniButton, GUILayout.Width(20))){
deleteIndex = i;
}
if (changeOrder) {
if (GUILayout.Button(new GUIContent("<", "Move up"), editHierarchy? EditorStyles.miniButtonMid: EditorStyles.miniButtonLeft, GUILayout.Width(20))) {
int moveTo = i == 0? prop.arraySize - 1: i - 1;
prop.MoveArrayElement(i, moveTo);
prop.isExpanded = true;
}
if (GUILayout.Button(new GUIContent(">", "Move down"), EditorStyles.miniButtonRight, GUILayout.Width(20))) {
int moveTo = i == prop.arraySize - 1? 0: i + 1;
prop.MoveArrayElement(i, moveTo);
prop.isExpanded = true;
}
}
// Calling the DrawArrayElementLabel delegate
if (drawArrayElementLabel != null) {
drawArrayElementLabel(element, editHierarchy);
}
GUILayout.EndHorizontal(); // End Label
// Array Element
GUILayout.BeginVertical();
if (element.isExpanded && drawArrayElement != null) {
drawArrayElement(element, editHierarchy);
}
GUILayout.EndVertical();
GUILayout.Space(5);
GUILayout.EndVertical(); // End Style
GUILayout.EndHorizontal(); // End Main
}
// Deleting array elements
if (deleteIndex != -1) prop.DeleteArrayElementAtIndex(deleteIndex);
// Adding array elements
GUILayout.BeginHorizontal();
GUILayout.Space(((EditorGUI.indentLevel + 1) * indent) + 4);
GUILayout.BeginVertical();
if (editHierarchy && GUILayout.Button(new GUIContent("+", "Add"), EditorStyles.miniButton, GUILayout.Width(20))) {
prop.arraySize ++;
if (onAddToArray != null) onAddToArray(prop.GetArrayElementAtIndex(prop.arraySize - 1));
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
EditorGUI.indentLevel = resetIndent;
}
示例9: MoveDown
private void MoveDown(SerializedProperty property, int i) {
property.MoveArrayElement(i, i + 1);
}
示例10: MoveUp
private void MoveUp(SerializedProperty property, int i) {
property.MoveArrayElement(i, i - 1);
}