当前位置: 首页>>代码示例>>C#>>正文


C# SerializedProperty.InsertArrayElementAtIndex方法代码示例

本文整理汇总了C#中UnityEditor.SerializedProperty.InsertArrayElementAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedProperty.InsertArrayElementAtIndex方法的具体用法?C# SerializedProperty.InsertArrayElementAtIndex怎么用?C# SerializedProperty.InsertArrayElementAtIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEditor.SerializedProperty的用法示例。


在下文中一共展示了SerializedProperty.InsertArrayElementAtIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
 }
开发者ID:cyberimp,项目名称:Dark-Invaders,代码行数:28,代码来源:EditorList.cs

示例2: UpdateTransformMask

 public static void UpdateTransformMask(SerializedProperty transformMask, string[] refTransformsPath, string[] humanTransforms)
 {
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey89 maskCAnonStorey89 = new AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey89();
   // ISSUE: reference to a compiler-generated field
   maskCAnonStorey89.refTransformsPath = refTransformsPath;
   transformMask.ClearArray();
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey8A maskCAnonStorey8A = new AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey8A();
   // ISSUE: reference to a compiler-generated field
   maskCAnonStorey8A.\u003C\u003Ef__ref\u0024137 = maskCAnonStorey89;
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   for (maskCAnonStorey8A.i = 0; maskCAnonStorey8A.i < maskCAnonStorey89.refTransformsPath.Length; maskCAnonStorey8A.i = maskCAnonStorey8A.i + 1)
   {
     // ISSUE: reference to a compiler-generated field
     transformMask.InsertArrayElementAtIndex(maskCAnonStorey8A.i);
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated field
     transformMask.GetArrayElementAtIndex(maskCAnonStorey8A.i).FindPropertyRelative("m_Path").stringValue = maskCAnonStorey89.refTransformsPath[maskCAnonStorey8A.i];
     // ISSUE: reference to a compiler-generated method
     bool flag = humanTransforms == null || ArrayUtility.FindIndex<string>(humanTransforms, new Predicate<string>(maskCAnonStorey8A.\u003C\u003Em__14A)) != -1;
     // ISSUE: reference to a compiler-generated field
     transformMask.GetArrayElementAtIndex(maskCAnonStorey8A.i).FindPropertyRelative("m_Weight").floatValue = !flag ? 0.0f : 1f;
   }
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:32,代码来源:AvatarMaskUtility.cs

示例3: 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--;
        }
开发者ID:cupsster,项目名称:Klak,代码行数:25,代码来源:ValueAnimationEditor.cs

示例4: ShowStateList

        void ShowStateList(SerializedProperty stateList, string label)
        {
            var count = stateList.arraySize;

            // FIXME: should be replaced with DelayedIntField in 5.3
            count = EditorGUILayout.IntField("State Count", count);
            count = Mathf.Max(count, 1);

            // enlarge/shrink the list when the size is changed
            while (count > stateList.arraySize)
                stateList.InsertArrayElementAtIndex(stateList.arraySize - 1);
            while (count < stateList.arraySize)
                stateList.DeleteArrayElementAtIndex(stateList.arraySize - 1);

            EditorGUI.indentLevel ++;

            for (var i = 0; i < stateList.arraySize; i++)
            {
                var data = stateList.GetArrayElementAtIndex(i);
                var label_i = new GUIContent(label + " " + i);
                EditorGUILayout.PropertyField(data, label_i);
            }

            EditorGUI.indentLevel --;
        }
开发者ID:cupsster,项目名称:Klak,代码行数:25,代码来源:MultiStateToggleEditor.cs

示例5: 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);
     }
 }
开发者ID:james7132,项目名称:Hysteria,代码行数:44,代码来源:BossEditor.cs

示例6: AddArrayElement

        /// <summary>Add a new array element at the end of an array.</summary>
        /// <param name="array">The array to add a new element to.</param>
        /// <param name="index">Index position where to add the array element.</param>
        /// <returns><see cref="SerializedProperty"/> for the new array element.</returns>
        public static SerializedProperty AddArrayElement(SerializedProperty array, int index)
        {
            if (!array.isArray) {
                Debug.LogError("Specified property is not an array");
                return null;
            }
            array.InsertArrayElementAtIndex(index);

            return array.GetArrayElementAtIndex(index - 1);
        }
开发者ID:petereichinger,项目名称:unity-helpers,代码行数:14,代码来源:ArrayHelpers.cs

示例7: LoadQuests

    private void LoadQuests()
    {
        // Reset properties
        actProperty = serializedObject.FindProperty("act");
        sceneProperty = serializedObject.FindProperty("scene");
        questListProperty = serializedObject.FindProperty("questList");

        TextAsset[] questsList=ParleyMenu.GetActSceneQuests(ParleyMenu.GetActs()[actProperty.intValue],ParleyMenu.GetActsScenes()[ParleyMenu.GetActs()[actProperty.intValue]][sceneProperty.intValue]).ToArray();

        questListProperty.ClearArray();

        for (int x=0;x<questsList.Length;x++){
            questListProperty.InsertArrayElementAtIndex(x);
            questListProperty.GetArrayElementAtIndex(x).objectReferenceValue=questsList[x];
        }
    }
开发者ID:ChristianHoj,项目名称:home_nursing,代码行数:16,代码来源:ParleyEditor.cs

示例8: 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);
         }
     }
 }
开发者ID:SethSR,项目名称:Mech-Game,代码行数:16,代码来源:EditorList.cs

示例9: 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--;
 }
开发者ID:tdroesch,项目名称:Trials-of-the-Damned,代码行数:42,代码来源:EditorUtilities.cs

示例10: ShowButtons

    private static void ShowButtons(SerializedProperty list, int index)
    {
        if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonLeft, miniButtonWidth))
        {
            list.InsertArrayElementAtIndex(index);
            if (index < list.arraySize - 2)
            {
                Vector3 vector1 = list.GetArrayElementAtIndex(index).vector3Value;
                Vector3 vector2 = list.GetArrayElementAtIndex(index+2).vector3Value;
                Vector3 newVector = (vector2 + vector1)/2;
                newVector.z = vector1.z;
                list.GetArrayElementAtIndex(index + 1).vector3Value = newVector;
            }

        }
        if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth))
        {
            list.DeleteArrayElementAtIndex(index);
        }
    }
开发者ID:cyberimp,项目名称:Dark-Invaders,代码行数:20,代码来源:EditorList.cs

示例11: OnGUI

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label = EditorGUI.BeginProperty(position, label, property);
        property.isExpanded = EditorGUILayout.Foldout( property.isExpanded, label );
        if( property.isExpanded )
        {

            EditorGUI.indentLevel += 1;
            place = property.FindPropertyRelative("UnityPlaces");
            number = property.FindPropertyRelative("Number");
            /*if(place.arraySize == 0){
                place.InsertArrayElementAtIndex(0);
            }*/

            for( int i = 0 ; i < place.arraySize; ++i )
            {
                name = "Place "+(i+1);
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent( name));
                GUILayout.Space(-22);
                EditorGUILayout.PropertyField( place.GetArrayElementAtIndex(i));
                GUILayout.Space(5);
                if( GUILayout.Button ("-", EditorStyles.miniButton, GUILayout.ExpandWidth(false) ) )
                {
                    if(i >= 0){
                        List<GameObject> listDelete = new List<GameObject>();
                        for (int j = 0; j < PlacesNPC.Count; j++)
                        {
                            if (PlacesNPC[j] != null && place.GetArrayElementAtIndex(i).objectReferenceValue != null && PlacesNPC[j].name == place.GetArrayElementAtIndex(i).objectReferenceValue.name)
                                listDelete.Add(PlacesNPC[j]);

                        }
                        for(int j = 0; j < listDelete.Count; j++)
                            GameObject.DestroyImmediate(listDelete[j]);

         						place.GetArrayElementAtIndex(i).objectReferenceValue = null;
                        place.DeleteArrayElementAtIndex(i);
                        //PlacesNPC.RemoveAt(i);

                    }
                    //GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    break;
                }

                GUILayout.Space(5);
                //GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

            }

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if( GUILayout.Button("Generate Place", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false), GUILayout.Width(100) ) )
            {
                GeneratePlaces();

            }
            if( GUILayout.Button("Add Existing Place", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false), GUILayout.Width(125) ) )
            {
                place.InsertArrayElementAtIndex(place.arraySize);
                place.GetArrayElementAtIndex(place.arraySize-1 ).objectReferenceValue = null;
                PlacesNPC.Add(null);
                number.intValue += 1;

            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel -= 1;

        }
        EditorGUI.EndProperty();
    }
开发者ID:NunezG,项目名称:villeEmergente,代码行数:75,代码来源:PlaceParametersDrawer.cs

示例12: showVector2IntList

        private bool showVector2IntList(SerializedProperty list, bool foldout)
        {
            int listSize = list.arraySize;
            listSize = EditorGUILayout.IntField("Count", listSize);

            if(listSize != list.arraySize)
            {
                while(listSize > list.arraySize)
                {
                    list.InsertArrayElementAtIndex(list.arraySize);
                }
                while(listSize < list.arraySize)
                {
                    list.DeleteArrayElementAtIndex(list.arraySize - 1);
                }
            }

            if (listSize > 0)
            {
                EditorGUI.indentLevel++;
                foldout = EditorGUILayout.Foldout(foldout, "Point List");
                if (foldout)
                {
                    for(int i = 0; i < list.arraySize; i++)
                    {
                        SerializedProperty element = list.GetArrayElementAtIndex(i);
                        SerializedProperty x = element.FindPropertyRelative("x");
                        SerializedProperty y = element.FindPropertyRelative("y");

                        EditorGUILayout.LabelField("Point " + (i + 1));
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(x);
                        EditorGUILayout.PropertyField(y);
                        EditorGUI.indentLevel--;
                    }
                }
                EditorGUI.indentLevel--;
            }

            return foldout;
        }
开发者ID:TheHolodeckProject,项目名称:HolodeckNavigationTask,代码行数:41,代码来源:QMazeEngineInspector.cs

示例13: 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;
        }
开发者ID:groov0v,项目名称:edriven-gui,代码行数:77,代码来源:StyleSheetPropertyDrawer.cs

示例14: CopyArrayToSerialized

 static void CopyArrayToSerialized( SerializedProperty dest, GameObject[] sources )
 {
     if( dest.arraySize != sources.Length )
     {
         dest.ClearArray();
         for( int i = 0; i < sources.Length; ++i )
         {
             dest.InsertArrayElementAtIndex( i );
         }
     }
     for( int i = 0; i < sources.Length; ++i )
     {
         if( dest.GetArrayElementAtIndex( i ).objectReferenceValue != sources[i] )
             dest.GetArrayElementAtIndex( i ).objectReferenceValue = sources[i];
     }
 }
开发者ID:InvitationToDeath,项目名称:InvitationToDeath-Ver3,代码行数:16,代码来源:ExporterWindow.cs

示例15: ArrayList

 protected void ArrayList(SerializedProperty property, string title, Runnable1<SerializedProperty> renderer) {
     if (Foldout(title, false)) {
         Indent(() => {
             if (property.arraySize == 0) {
                 GUILayout.Label("   Use 'Add' button to add items");
             } else {
                 int arrSize = property.arraySize;
                 Separator();
                 for (int i = 0; i < arrSize; ++i) {
                     var go = property.GetArrayElementAtIndex(i);
                     EditorGUILayout.BeginHorizontal();
                     
                     EditorGUILayout.BeginVertical();
                     renderer(go);
                     EditorGUILayout.EndVertical();
                     
                     GUI.color = Color.red;
                     if (GUILayout.Button("X", GUILayout.ExpandWidth(false))) {
                         property.DeleteArrayElementAtIndex(i);
                         arrSize--;
                     }
                     GUI.color = Color.white;
                     EditorGUILayout.EndHorizontal();
                     
                     if (i + 1 < arrSize) {
                         EditorGUILayout.Space();
                     }
                     Separator();
                 }
             }
             
             GUI.color = Color.green;
             EditorGUILayout.BeginHorizontal();
             GUILayout.FlexibleSpace();
             if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) {
                 property.InsertArrayElementAtIndex(property.arraySize);
   
                 // when creating new array element like this, the color will be initialized with
                 // (0, 0, 0, 0) - zero aplha. This may be confusing for end user so this workaround looks
                 // for color fields and sets them to proper values                  
                 var element = property.GetArrayElementAtIndex(property.arraySize - 1);                  
                 var enumerator = element.GetEnumerator();
                 while (enumerator.MoveNext()) {
                     var el = enumerator.Current as SerializedProperty;
                     if (el.type == "ColorRGBA") {
                         el.colorValue = Color.white;
                     }
                 }
             }
             GUI.color = Color.white;
             EditorGUILayout.EndHorizontal();
         });
     }
 }
开发者ID:darajad,项目名称:Lethal-Pursuit,代码行数:54,代码来源:EditorBase.cs


注:本文中的UnityEditor.SerializedProperty.InsertArrayElementAtIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。