/************************************************************************************************************************/
            #endregion
            /************************************************************************************************************************/
            #region Models
            /************************************************************************************************************************/

            private static void DoModelsGUI()
            {
                var property = ModelsProperty;
                var count = property.arraySize = EditorGUILayout.DelayedIntField(nameof(Models), property.arraySize);

                // Drag and Drop to add model.
                var area = GUILayoutUtility.GetLastRect();
                AnimancerGUI.HandleDragAndDrop<GameObject>(area,
                    (gameObject) =>
                    {
                        return
                            EditorUtility.IsPersistent(gameObject) &&
                            !Models.Contains(gameObject) &&
                            gameObject.GetComponentInChildren<Animator>() != null;
                    },
                    (gameObject) =>
                    {
                        var modelsProperty = ModelsProperty;// Avoid Closure.
                        modelsProperty.serializedObject.Update();

                        var i = modelsProperty.arraySize;
                        modelsProperty.arraySize = i + 1;
                        modelsProperty.GetArrayElementAtIndex(i).objectReferenceValue = gameObject;
                        modelsProperty.serializedObject.ApplyModifiedProperties();
                    });

                if (count == 0)
                    return;

                property.isExpanded = EditorGUI.Foldout(area, property.isExpanded, GUIContent.none, true);
                if (!property.isExpanded)
                    return;

                EditorGUI.indentLevel++;

                var model = property.GetArrayElementAtIndex(0);
                for (int i = 0; i < count; i++)
                {
                    GUILayout.BeginHorizontal();

                    EditorGUILayout.ObjectField(model);

                    if (GUILayout.Button("x", AnimancerGUI.MiniButton))
                    {
                        Serialization.RemoveArrayElement(property, i);
                        property.serializedObject.ApplyModifiedProperties();

                        AnimancerGUI.Deselect();
                        GUIUtility.ExitGUI();
                        return;
                    }

                    GUILayout.Space(EditorStyles.objectField.margin.right);
                    GUILayout.EndHorizontal();
                    model.Next(false);
                }

                EditorGUI.indentLevel--;
            }
Exemple #2
0
 /// <summary>
 /// If <see cref="Sprite"/>s are dropped into the `area`, this method assigns them as the
 /// <see cref="_NewSprites"/>.
 /// </summary>
 private void HandleDragAndDrop(Rect area)
 {
     _DropIndex = 0;
     AnimancerGUI.HandleDragAndDrop <Sprite>(area, (sprite) => true, (sprite) =>
     {
         if (_DropIndex < _NewSprites.Count)
         {
             RecordUndo();
             _NewSprites[_DropIndex++] = sprite;
         }
     });
 }
Exemple #3
0
 /// <summary>Adds any objects dropped in the `area` to the `list`.</summary>
 protected void HandleDragAndDropIntoList <T>(Rect area, IList <T> list, bool overwrite,
                                              Func <T, bool> validate = null) where T : Object
 {
     if (overwrite)
     {
         _DropIndex = 0;
         AnimancerGUI.HandleDragAndDrop(area, validate, (drop) =>
         {
             if (_DropIndex < list.Count)
             {
                 RecordUndo();
                 list[_DropIndex++] = drop;
             }
         });
     }
     else
     {
         AnimancerGUI.HandleDragAndDrop(area, validate, (drop) =>
         {
             list.Add(drop);
         });
     }
 }