void CreateDisplayFrom(TypeInfo type) { TreeViewState state = new TreeViewState(); GameObject tempGO = null; UnityEngine.Object temp; if (type.isScriptableObject) { temp = CreateInstance(type.type); } else { tempGO = new GameObject(); temp = tempGO.AddComponent(type.type); } SerializedObject tempObj = new SerializedObject(temp); SerializedProperty prop = tempObj.GetIterator(); //Count remainingwill count hte m_Script property (the type of script, like the 1st field in the inspector) //but we will replace it with the (hidden) propery that is the name, so it even out int propCount = prop.CountRemaining(); prop.Reset(); prop.Next(true); //do it once to "jump over" the script file, we don't want that property. prop.NextVisible(false); //add name MultiColumnHeaderState.Column[] columns = new MultiColumnHeaderState.Column[propCount]; columns[0] = new MultiColumnHeaderState.Column(); columns[0].headerContent = new GUIContent("Name"); columns[0].width = 64; for (int i = 1; i < propCount; ++i) { prop.NextVisible(false); columns[i] = new MultiColumnHeaderState.Column(); columns[i].allowToggleVisibility = false; columns[i].headerContent = new GUIContent(prop.displayName); columns[i].minWidth = GetPropertyWidthFromType(prop.propertyType); columns[i].width = columns[i].minWidth; columns[i].canSort = CanSort(prop.propertyType); } MultiColumnHeaderState headerstate = new MultiColumnHeaderState(columns); MultiColumnHeader header = new MultiColumnHeader(headerstate); _databaseDisplay = new DatabaseDisplayer(state, header, type); _databaseDisplay.Reload(); if (tempGO != null) { DestroyImmediate(tempGO); } }
private void OnEnable() { _databaseDisplay = null; RetrieveType(); if (_selectedIndex != -1 && _selectedIndex < _objectTypeNames.Length) { CreateDisplayFrom(_objectTypeInfos[_selectedIndex]); } }
public static DatabaseViewerItem CreateFromUnityObject(UnityEngine.Object unityObject, DatabaseDisplayer treeView) { SerializedObject so = new SerializedObject(unityObject); DatabaseViewerItem newItem = new DatabaseViewerItem(); newItem.children = new List <TreeViewItem>(); newItem.depth = 0; newItem.id = treeView.GetNewID(); newItem.obj = so; SerializedProperty prop = so.GetIterator(); prop.Next(true); prop.NextVisible(false); newItem.properties = new SerializedProperty[treeView.multiColumnHeader.state.columns.Length]; newItem.properties[0] = so.FindProperty("m_Name"); for (int k = 1; k < newItem.properties.Length; ++k) { prop.NextVisible(false); newItem.properties[k] = prop.Copy(); } return(newItem); }