Ejemplo n.º 1
0
            public TreeView(string[] groups, SerializedObject serializedObject)
                : base(new TreeViewState())
            {
                _groups = groups;
                _list   = new SerializePropertyAssetList(serializedObject, "_assets");

                rowHeight += Offset + 1;
            }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            if (_groups == null)
            {
                DrawEmpty();
                return;
            }

            var source = (SingleSource)target;

            if (source.Groups == null)
            {
                DrawEmpty();
                return;
            }

            if (source.Groups.Length != _groups.Length)
            {
                var assets = new TextAsset[_groups.Length];
                for (var i = 0; i < _groups.Length; i++)
                {
                    assets[i] = source.GetAsset(_groups[i]);
                }

                var groupsList = new SerializePropertyStringList(serializedObject, "_groups");
                groupsList.AddRange(_groups);
                groupsList.End();

                var assetsList = new SerializePropertyAssetList(serializedObject, "_assets");
                assetsList.AddRange(assets);
                assetsList.End();

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
            }

            if (Event.current.type == EventType.Layout)
            {
                if (_searchText != _treeView.state.searchString)
                {
                    _reloadOnLayout = false;
                    _treeView.state.searchString = _searchText;
                    _treeView.Reload();
                }

                if (_reloadOnLayout)
                {
                    _reloadOnLayout = false;
                    _treeView.Reload();
                }
            }

            using (new GUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
            {
                _searchText = _searchField.OnGUI(_searchText);
                GUILayout.Space(8);

                EditorGUI.BeginChangeCheck();
                _treeView.OnGUILayout(GUILayout.ExpandWidth(true));
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();

                    AssetDatabase.ImportAsset(target.GetAssetPath());

                    _reloadOnLayout = true;
                }
            }
        }