public override float GetElementHeight(GUIContent label, UnityObject element, fiGraphMetadata metadata) { float height = FoldoutHeight; if (CanDisplayDropdown(element)) { DisableFoldoutByDefault(element, metadata); var foldoutState = metadata.GetMetadata <ObjectFoldoutStateGraphMetadata>(); if (foldoutState.IsActive || foldoutState.IsAnimating) { var faded = foldoutState.AnimPercentage; var editor = BehaviorEditor.Get(element.GetType()); DynamicItemHeight.SetHeight(editor.GetHeight(element)); float itemHeight = DisplayedItemLayout.Height; fiEditorGUI.UpdateFadeGroupHeight(ref itemHeight, 0, faded); height += itemHeight; DynamicItemHeight.SetHeight(0); } } return(height); }
public override void OnInspectorGUI() { if (fsPortableReflection.HasAttribute <fiInspectorOnlyAttribute>(target.GetType()) || target is tkCustomEditor) { BehaviorEditor.Get(target.GetType()).EditWithGUILayout(target); } else { base.OnInspectorGUI(); } }
private static bool CanDisplayDropdown(UnityObject obj) { if (obj == null) { return(false); } return (obj is CommonBaseBehavior || obj is CommonBaseScriptableObject || BehaviorEditor.Get(obj.GetType()) is DefaultBehaviorEditor == false); }
private static bool CanDisplayDropdown(UnityObject obj) { if (obj == null) { return(false); } if (fiSettings.ForceDisplayInlineObjectEditor) { return(true); } return (obj is CommonBaseBehavior || obj is CommonBaseScriptableObject || obj is tkCustomEditor || fsPortableReflection.HasAttribute <fiInspectorOnlyAttribute>(obj.GetType()) || BehaviorEditor.Get(obj.GetType()) is DefaultBehaviorEditor == false); }
public override UnityObject Edit(Rect region, GUIContent label, UnityObject element, fiGraphMetadata metadata) { if (CanDisplayDropdown(element) == false) { region.height = FoldoutHeight; return(fiEditorGUI.ObjectField(region, label, element, typeof(ObjectType), AllowSceneObjects(element))); } // We have to show a foldout. DisableFoldoutByDefault(element, metadata); // The rect for the foldout Rect foldoutRect = region; foldoutRect.height = FoldoutHeight; if (string.IsNullOrEmpty(label.text) == false) { foldoutRect.width = EditorGUIUtility.labelWidth; } else { foldoutRect.width = 15; } Rect objectRect = region; objectRect.x += foldoutRect.width; objectRect.width -= foldoutRect.width; objectRect.height = FoldoutHeight; var foldoutState = metadata.GetMetadata <ObjectFoldoutStateGraphMetadata>(); bool updatedActive = EditorGUI.Foldout(foldoutRect, foldoutState.IsActive, label, /*toggleOnLabelClick:*/ true); if (updatedActive != foldoutState.IsActive && foldoutState.IsAnimating == false) { foldoutState.IsActive = updatedActive; } element = fiEditorGUI.ObjectField(objectRect, GUIContent.none, element, typeof(ObjectType), AllowSceneObjects(element)); if (element != null && (foldoutState.IsActive || foldoutState.IsAnimating)) { Rect subRect = new Rect(region); subRect.y += FoldoutHeight; subRect.height -= FoldoutHeight; fiEditorGUI.BeginFadeGroup(0, ref subRect, foldoutState.AnimPercentage); // Reuse the height calculation from GetHeight from the BehaviorEditor by // calculating the base height of the layout when the dynamic item does not // contribute. DynamicItemHeight.SetHeight(0); DynamicItemHeight.SetHeight(subRect.height - DisplayedItemLayout.Height); Rect boxRect = DisplayedItemLayout.GetSectionRect("Box", subRect); Rect propertyRect = DisplayedItemLayout.GetSectionRect("Item", subRect); GUI.Box(boxRect, GUIContent.none); fiEditorGUI.PushHierarchyMode(false); var editor = BehaviorEditor.Get(element.GetType()); editor.Edit(propertyRect, element); fiEditorGUI.PopHierarchyMode(); fiEditorGUI.EndFadeGroup(); if (foldoutState.IsAnimating) { fiEditorUtility.RepaintAllEditors(); } } return(element); }
public void OnGUI() { // If we went through an serialization cycle, then the types will be null so we have to close the selection // window. if (_sharedInstanceType == null || _instanceType == null) { // we have to close the window *outside* of OnGUI otherwise Unity will // report cleanup errors EditorApplication.delayCall += () => { if (this != null) { Close(); } }; return; } GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); if (GUILayout.Button("Create New Instance", EditorStyles.toolbarButton, GUILayout.Width(125))) { CreateNewScriptableObject(); } GUILayout.FlexibleSpace(); GUILayout.Label("Filter", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)); _searchString = GUILayout.TextField(_searchString, EditorStyles.toolbarTextField, GUILayout.MaxWidth(250), GUILayout.MinWidth(125)); GUILayout.EndHorizontal(); List <UnityObject> availableInstances = fiEditorUtility.GetAllAssetsOfType(_sharedInstanceType); GUILayout.BeginHorizontal(); GUILayout.Label("Select Existing Instance (" + availableInstances.Count + " available)", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); GUILayout.Space(5); if (GUILayout.Button("Select null", GUILayout.MaxWidth(125))) { _onSelected(null); Close(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); _scroll = EditorGUILayout.BeginScrollView(_scroll); for (int i = 0; i < availableInstances.Count; ++i) { if (_foldouts.ContainsKey(i) == false) { _foldouts[i] = false; } if (availableInstances[i] == null) { continue; } if (availableInstances[i].name.Contains(_searchString) == false) { continue; } EditorGUILayout.BeginHorizontal(); var foldoutRect = EditorGUILayout.GetControlRect(GUILayout.Width(11)); foldoutRect.y += 2; _foldouts[i] = EditorGUI.Foldout(foldoutRect, _foldouts[i], GUIContent.none); if (GUILayout.Button(availableInstances[i].name)) { _onSelected(availableInstances[i]); Close(); } string assetPath = AssetDatabase.GetAssetPath(availableInstances[i]); if (string.IsNullOrEmpty(assetPath) == false) { GUI.color = Color.red; if (GUILayout.Button(new GUIContent("X"), GUILayout.Width(18))) { if (EditorUtility.DisplayDialog("Confirm Deletion", "Are you sure that you want to delete \"" + availableInstances[i].name + "\"?", "Yes", "No")) { AssetDatabase.DeleteAsset(assetPath); fiEditorUtilityCache.ClearCache(); } } GUI.color = Color.white; } EditorGUILayout.EndHorizontal(); if (_foldouts[i]) { GUILayout.BeginHorizontal(); GUILayout.Space(20f); var editor = BehaviorEditor.Get(availableInstances[i].GetType()); editor.EditWithGUILayout(availableInstances[i]); GUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); }