コード例 #1
0
        /// <summary>
        /// Draws the GUI for a list of Unity.Object. Allows users to add/remove/modify a specific type
        /// deriving from Unity.Object (such as GameObject, or a Component type)
        /// </summary>
        /// <param name="header">A descriptive header</param>
        /// <param name="objects">The object list to edit</param>
        /// <param name="allowedSelectionTypes">The types of objects that are allowed to be selected</param>
        /// <typeparam name="T">The type of object in the list</typeparam>
        public static void DrawObjectList <T>(GUIContent header, IList <T> objects, GameObjectSelectionTypes allowedSelectionTypes) where T : UnityEngine.Object
        {
            bool allowSceneSelection  = (allowedSelectionTypes & GameObjectSelectionTypes.InScene) == GameObjectSelectionTypes.InScene;
            bool allowPrefabSelection = (allowedSelectionTypes & GameObjectSelectionTypes.Prefab) == GameObjectSelectionTypes.Prefab;

            GUILayout.BeginVertical("box");
            EditorGUILayout.LabelField(header, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 0;

            int toDeleteIndex = -1;

            GUILayout.BeginVertical("box");

            for (int i = 0; i < objects.Count; i++)
            {
                T obj = objects[i];
                EditorGUILayout.BeginHorizontal();

                T tempObj = (T)EditorGUILayout.ObjectField("", obj, typeof(T), allowSceneSelection);

                if (tempObj != null)
                {
                    bool isAsset = EditorUtility.IsPersistent(tempObj);

                    if ((isAsset && allowPrefabSelection) || (!isAsset && allowSceneSelection))
                    {
                        objects[i] = tempObj;
                    }
                }
                else
                {
                    objects[i] = null;
                }

                if (GUILayout.Button("x", EditorStyles.miniButton, InspectorConstants.SmallButtonWidth))
                {
                    toDeleteIndex = i;
                }

                EditorGUILayout.EndHorizontal();
            }

            if (toDeleteIndex >= 0)
            {
                objects.RemoveAt(toDeleteIndex);
            }

            if (GUILayout.Button("Add New"))
            {
                objects.Add(default(T));
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();
        }
コード例 #2
0
        /// <summary>
        /// Draws the GUI for a list of Unity.Object. Allows users to add/remove/modify a specific type
        /// deriving from Unity.Object (such as GameObject, or a Component type)
        /// </summary>
        /// <param name="header">A descriptive header</param>
        /// <param name="objects">The object list to edit</param>
        /// <param name="allowedSelectionTypes">The types of objects that are allowed to be selected</param>
        /// <typeparam name="T">The type of object in the list</typeparam>
        public static void DrawObjectList <T>(string header, IList <T> objects, GameObjectSelectionTypes allowedSelectionTypes) where T : UnityEngine.Object
        {
            bool allowSceneSelection  = (allowedSelectionTypes & GameObjectSelectionTypes.InScene) == GameObjectSelectionTypes.InScene;
            bool allowPrefabSelection = (allowedSelectionTypes & GameObjectSelectionTypes.Prefab) == GameObjectSelectionTypes.Prefab;

            EditorGUILayout.PrefixLabel(header);
            EditorGUI.indentLevel = 0;

            int toDeleteIndex = -1;

            GUILayout.BeginVertical("box");

            for (int i = 0; i < objects.Count; i++)
            {
                T obj = objects[i];
                EditorGUILayout.BeginHorizontal();

                T tempObj = (T)EditorGUILayout.ObjectField("", obj, typeof(T), allowSceneSelection);

                if (tempObj != null)
                {
                    var prefabType = PrefabUtility.GetPrefabType(tempObj);

                    if ((prefabType == PrefabType.Prefab && allowPrefabSelection) || (prefabType != PrefabType.Prefab && allowSceneSelection))
                    {
                        objects[i] = tempObj;
                    }
                }

                if (GUILayout.Button("x", EditorStyles.miniButton, EditorConstants.SmallButtonWidth))
                {
                    toDeleteIndex = i;
                }

                EditorGUILayout.EndHorizontal();
            }

            if (toDeleteIndex >= 0)
            {
                objects.RemoveAt(toDeleteIndex);
            }

            if (GUILayout.Button("Add New"))
            {
                objects.Add(default(T));
            }

            EditorGUILayout.EndVertical();
        }
コード例 #3
0
 /// <summary>
 /// Draws the GUI for a list of Unity.Object. Allows users to add/remove/modify a specific type
 /// deriving from Unity.Object (such as GameObject, or a Component type)
 /// </summary>
 /// <param name="header">A descriptive header</param>
 /// <param name="objects">The object list to edit</param>
 /// <param name="allowedSelectionTypes">The types of objects that are allowed to be selected</param>
 /// <typeparam name="T">The type of object in the list</typeparam>
 public static void DrawObjectList <T>(string header, IList <T> objects, GameObjectSelectionTypes allowedSelectionTypes) where T : UnityEngine.Object
 {
     DrawObjectList(new GUIContent(header), objects, allowedSelectionTypes);
 }