Exemple #1
0
        /// <summary>
        /// 创建一个显示隐藏组
        /// </summary>
        /// <param name="key">用于存取上下文数据</param>
        /// <param name="visible">是否可见</param>
        /// <param name="drawFunc">组内绘制函数</param>
        /// <param name="speed">动画速度</param>
        /// <returns></returns>
        public static void FadeGroup(string key, bool visible, Action drawFunc, float speed = 1)
        {
            if (!GUIHelper.TryGetContextData <AnimFloat>(key, out var contextData))
            {
                contextData.value = new AnimFloat(visible ? 1 : 0);
            }
            contextData.value.speed  = speed * (visible ? 1 : 2);
            contextData.value.target = visible ? 1 : 0;
            float t = contextData.value.value;

            if (visible)
            {
                t--;
                t = -(t * t * t * t - 1);
            }
            else
            {
                t = t * t;
            }

            GUIExtension.SetAlpha(t, () =>
            {
                if (EditorGUILayout.BeginFadeGroup(t))
                {
                    drawFunc?.Invoke();
                }
                EditorGUILayout.EndFadeGroup();
            });
        }
Exemple #2
0
        /// <summary>
        /// 绘制一个目录选择窗口
        /// </summary>
        /// <param name="label">提示名</param>
        /// <param name="folderPath">目录路径</param>
        /// <returns></returns>
        public static string FolderPath(string label, string folderPath)
        {
            EditorGUILayout.BeginHorizontal();
            folderPath = EditorGUILayout.TextField(label, folderPath);
            Rect        rect = GUILayoutUtility.GetLastRect();
            UnityObject uObj = GUIExtension.DragDropAreaSingle(rect, DragAndDropVisualMode.Copy);

            if (uObj != null && AssetDatabase.IsMainAsset(uObj))
            {
                string p = AssetDatabase.GetAssetPath(uObj);
                if (AssetDatabase.IsValidFolder(p))
                {
                    folderPath = p;
                }
            }
            if (GUILayout.Button(EditorGUIUtility.FindTexture("FolderEmpty Icon"), EditorStylesExtension.OnlyIconButtonStyle, GUILayout.Width(18), GUILayout.Height(18)))
            {
                folderPath = EditorUtility.OpenFolderPanel($"{label}目录选择", Application.dataPath, string.Empty);
                if (!string.IsNullOrEmpty(folderPath))
                {
                    folderPath = folderPath.Substring(folderPath.IndexOf("Assets"));
                }
            }
            EditorGUILayout.EndHorizontal();
            return(folderPath);
        }
Exemple #3
0
        /// <summary>
        /// 绘制单个元素
        /// </summary>
        /// <param name="value">数据</param>
        /// <param name="label">名</param>
        /// <returns></returns>
        static object DrawSingleField(Type objType, object value, GUIContent label = null)
        {
            if (GUIExtension.IsBasicType(objType))
            {
                if (label == null)
                {
                    label = new GUIContent(objType.Name);
                }
                float tmpHeight = GUIExtension.GetHeight(objType, label);
                return(GUIExtension.DrawField(EditorGUILayout.GetControlRect(true, tmpHeight), value, label));
            }

            Type type = objType;

            //如果类型是类 或者 是值类型并且不是基元类型
            if (type.IsClass || (type.IsValueType && !type.IsPrimitive))
            {
                if (label == null)
                {
                    label = new GUIContent(objType.Name);
                }

                //委托类型
                if (typeof(Delegate).IsAssignableFrom(type))
                {
                    return(null);
                }
                //基础类型并且为空
                if (typeof(object).IsAssignableFrom(type) && value == null)
                {
                    return(null);
                }
                int hashCode = value.GetHashCode();

                //值为空
                if (value == null)
                {
                    //泛型
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        type = Nullable.GetUnderlyingType(type);
                    }
                    value = Activator.CreateInstance(type, true);
                }

                //遍历类型字段
                GUILayout.BeginVertical();
                if (DrawFoldout(hashCode, label))
                {
                    EditorGUI.indentLevel++;
                    foreach (var field in ReflectionHelper.GetFieldInfos(type))
                    {
                        if (!CanDraw(field))
                        {
                            continue;
                        }

                        GUIContent fileLable = new GUIContent(field.Name);
                        if (AttributeHelper.TryGetFieldAttribute(field, out HeaderAttribute attr))
                        {
                            fileLable = new GUIContent(attr.header);
                        }
                        if (GUIExtension.IsBasicType(type))
                        {
                            float tmpHeight = GUIExtension.GetHeight(type, fileLable);
                            return(GUIExtension.DrawField(EditorGUILayout.GetControlRect(true, tmpHeight), field.GetValue(value), fileLable));
                        }
                        else
                        {
                            DrawField(field, value, fileLable);
                        }
                    }
                    EditorGUI.indentLevel--;
                }
                GUILayout.EndVertical();
                return(value);
            }

            float height = GUIExtension.GetHeight(type, label);

            return(GUIExtension.DrawField(EditorGUILayout.GetControlRect(true, height), value, label));
        }
Exemple #4
0
        /// <summary>
        /// 绘制一个可接收一个拖拽资源的区域
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static UnityObject DragDropAreaSingle(DragAndDropVisualMode dropVisualMode, Color hightlightColor, params GUILayoutOption[] options)
        {
            Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.label, options);

            return(GUIExtension.DragDropAreaSingle(rect, dropVisualMode, hightlightColor));
        }
Exemple #5
0
        /// <summary>
        /// 绘制一个可接收一个拖拽资源的区域
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static UnityObject DragDropAreaSingle(params GUILayoutOption[] options)
        {
            Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.label, options);

            return(GUIExtension.DragDropAreaSingle(rect));
        }
Exemple #6
0
        /// <summary>
        /// 绘制一个可接收多个拖拽资源的区域
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static UnityObject[] DragDropAreaMulti(Color hightlightColor, params GUILayoutOption[] options)
        {
            Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.label, options);

            return(GUIExtension.DragDropAreaMulti(rect, hightlightColor));
        }
Exemple #7
0
        /// <summary>
        /// 绘制一个可接收多个拖拽资源的区域
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static UnityObject[] DragDropAreaMulti(DragAndDropVisualMode dropVisualMode, params GUILayoutOption[] options)
        {
            Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.label, options);

            return(GUIExtension.DragDropAreaMulti(rect, dropVisualMode));
        }