Esempio n. 1
0
        public override object Show(string name, object value, Type t, FieldInfo fieldInfo, object instance, bool withName = true)
        {
            string textField = "";

            if (withName)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(name, GUILayout.Width(146));
            }
            var dateTime = value is DateTime ? (DateTime)value : new DateTime();

            if (GUILayout.Button(dateTime.ToString("yyyy-MM-dd HH:mm:ss")))
            {
                string str             = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                var    popCustomWindow = new PopCustomWindow();
                popCustomWindow.DrawGUI = () =>
                {
                    str = EditorGUILayout.TextField(str, GUILayout.Width(200));
                    try
                    {
                        value = Convert.ToDateTime(str);
                        fieldInfo.SetValue(instance, value);
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e);
                    }
                };
                popCustomWindow.PopWindow();
            }

            if (withName)
            {
                GUILayout.EndHorizontal();
            }

//            if (withName)
//            {
//                textField = EditorGUILayout.TextField(name,value.ToString());
//            }
//            else
//            {
//                textField = EditorGUILayout.TextField(value.ToString());
//            }
//            try
//            {
//                value = Convert.ToDateTime(textField);
//            }
//            catch (Exception e)
//            {
//
//            }


            return(value);
        }
        /// <summary>
        /// 筛选列表
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>List&lt;T&gt;.</returns>
        private List <T> Filter(List <T> source)
        {
            if (GUILayout.Button("F", EditorStyles.toolbarButton, GUILayout.Width(20)))
            {
                PopCustomWindow customWindow = new PopCustomWindow();
                customWindow.DrawGUI = () =>
                {
                    GUILayout.BeginHorizontal("flow overlay box");
                    GUITool.Button("筛选", Color.clear);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginVertical();
                    foreach (var searchFilter in filters)
                    {
                        var show = searchFilter.Show();
                        if (show)
                        {
                            this.SetDirty();
                        }
                    }
                    GUILayout.EndVertical();
                };
                customWindow.PopWindow();
            }

            if (research)
            {
                var list = new List <T>();

                //检索数据,必须满足所有的筛选器
                foreach (var data in source)
                {
                    bool enable = this.filters.All(filter => !filter.IsActive() || filter.RunFilter(data));
                    if (enable)
                    {
                        list.Add(data);
                    }
                }
                return(list);
            }
            return(source);
        }
        private void OpenSelectWindow(FieldInfo fieldInfo, object instance, string[] imgFolderPaths)
        {
            List <Texture2D> texture2Ds   = new List <Texture2D>();
            List <Texture2D> texture2Dss  = new List <Texture2D>();
            List <Texture2D> texture2Dsss = new List <Texture2D>();
            var findAssets = AssetDatabase.FindAssets("", imgFolderPaths);
            Dictionary <string, string>    loaded            = new Dictionary <string, string>();
            Dictionary <Texture2D, string> loadedTextureName = new Dictionary <Texture2D, string>();
            Dictionary <Texture2D, string> loadedTexturePath = new Dictionary <Texture2D, string>();

            foreach (var asset in findAssets)
            {
                var guidToAssetPath = AssetDatabase.GUIDToAssetPath(asset);
                if (!loaded.ContainsKey(guidToAssetPath))
                {
                    var loadAssetAtPath = AssetDatabase.LoadAssetAtPath <Texture2D>(guidToAssetPath);
                    var pathSplit       = guidToAssetPath.Split('/');
                    var imgName         = pathSplit[pathSplit.Length - 1];

                    loaded[guidToAssetPath] = imgName;
                    if (loadAssetAtPath != null)
                    {
                        loadedTextureName[loadAssetAtPath] = imgName;
                        loadedTexturePath[loadAssetAtPath] = guidToAssetPath;
                        texture2Ds.Add(loadAssetAtPath);
                    }
                }
            }

            var popCustomWindow = new PopCustomWindow();

            popCustomWindow.DefaultSize = new Vector2(600, 400);

            popCustomWindow.DrawGUI = () =>
            {
                texture2Dsss = searchBar2.Draw(texture2Ds, item => item.name);
                if (searchBar2.SearchContent.IsNOTNullOrEmpty())
                {
                    texture2Dss = texture2Dsss;
                }
                else
                {
                    texture2Dss = texture2Ds;
                }
                string selectPath = null;
                int    i          = 0;
                while (i < texture2Dss.Count)
                {
                    GUILayout.BeginHorizontal();
                    for (int lineCount = 0; lineCount < 5 && i < texture2Dss.Count; lineCount++)
                    {
                        bool select    = false;
                        var  texture2D = texture2Dss[i];
                        GUILayout.BeginVertical();
                        select = GUILayout.Button(new GUIContent(texture2D), GUILayout.Width(100), GUILayout.Height(100));
                        GUITool.Button(loadedTextureName[texture2D], Color.clear, GUILayout.MaxWidth(100));
                        GUILayout.EndVertical();
                        i++;

                        if (select)
                        {
                            selectPath = loadedTexturePath[texture2D];
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                if (selectPath.IsNOTNullOrEmpty())
                {
                    var assetDatabasePathToFieldValue = this.AssetDatabasePathToFieldValue(selectPath);
//                        Debug.Log(assetDatabasePathToFieldValue);
                    fieldInfo.SetValue(instance, this.AssetDatabasePathToFieldValue(selectPath));
                    popCustomWindow.CloseWindow();
                }
            };
            popCustomWindow.PopWindow();
        }