void IComponentChoiceSelector.BeforeGUI(SelectableComponentPropertyDrawer drawer, SerializedProperty property, System.Type restrictionType, bool allowProxy) { _drawer = drawer; _property = property; _restrictionType = restrictionType; _allowProxy = allowProxy; _components = this.DoGetComponents(); this.OnBeforeGUI(); }
public void DrawClip(Rect area, SerializedProperty property, GUIContent label, float labelWidth, GUIStyle labelStyle, bool nameIsReadonly) { //Draw Name var nameProp = property.FindPropertyRelative(PROP_NAME); var labelRect = new Rect(area.xMin, area.yMin, labelWidth, EditorGUIUtility.singleLineHeight); var textRect = new Rect(labelRect.xMax, area.yMin, (area.width - labelWidth) * 0.4f, EditorGUIUtility.singleLineHeight); EditorGUI.BeginProperty(area, label, nameProp); //EditorGUI.LabelField(labelRect, label, labelStyle); GUI.Label(labelRect, label, labelStyle); if (nameIsReadonly || _nameIsReadOnly || Application.isPlaying) { //EditorGUI.LabelField(textRect, nameProp.stringValue, GUI.skin.textField); GUI.Label(textRect, nameProp.stringValue, GUI.skin.textField); } else { //nameProp.stringValue = EditorGUI.TextField(textRect, nameProp.stringValue); nameProp.stringValue = GUI.TextField(textRect, nameProp.stringValue); } //EditorGUI.EndProperty(); var cache = SPGUI.DisableIfPlaying(); //Draw Animation Clip Reference var clipProp = property.FindPropertyRelative(PROP_CLIP); var xmin = textRect.xMax + 2f; var clipRect = new Rect(xmin, area.yMin, area.xMax - xmin, EditorGUIUtility.singleLineHeight); var clipLabel = GUIContent.none; //EditorGUI.BeginProperty(clipRect, clipLabel, clipProp); //clipProp.objectReferenceValue = EditorGUI.ObjectField(clipRect, clipProp.objectReferenceValue, typeof(AnimationClip), false); var obj = clipProp.objectReferenceValue; if (GameObjectUtil.IsGameObjectSource(obj)) { if (_selectComponentDrawer == null) { _selectComponentDrawer = new SelectableComponentPropertyDrawer(); _selectComponentDrawer.RestrictionType = typeof(IScriptableAnimationClip); _selectComponentDrawer.ShowXButton = true; } _selectComponentDrawer.OnGUI(clipRect, clipProp, GUIContent.none); } else { obj = EditorGUI.ObjectField(clipRect, obj, typeof(UnityEngine.Object), true); if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip) { clipProp.objectReferenceValue = obj; } else if (GameObjectUtil.IsGameObjectSource(obj)) { clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object; } } EditorGUI.EndProperty(); cache.Reset(); if (Application.isPlaying && !property.hasMultipleDifferentValues && property.serializedObject.targetObject is SPLegacyAnimController) { if (GUI.Button(new Rect(area.xMin, area.yMin, 20f, EditorGUIUtility.singleLineHeight), ">")) { var targ = property.serializedObject.targetObject as SPLegacyAnimController; targ.Play(nameProp.stringValue); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { this.Init(property); EditorGUI.BeginProperty(position, label, property); //################################ //FIRST LINE var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); rect = EditorGUI.PrefixLabel(rect, label); var targetProp = property.FindPropertyRelative(PROP_TARGET); var w0 = Mathf.Min(rect.width * 0.3f, 80f); var w1 = rect.width - w0; var r0 = new Rect(rect.xMin, rect.yMin, w0, EditorGUIUtility.singleLineHeight); var r1 = new Rect(r0.xMax, rect.yMin, w1, EditorGUIUtility.singleLineHeight); var searchProp = property.FindPropertyRelative(PROP_SEARCHBY); var queryProp = property.FindPropertyRelative(PROP_QUERY); var eSearchBy = (SearchByAlt)searchProp.GetEnumValue <SearchBy>(); EditorGUI.BeginChangeCheck(); eSearchBy = (SearchByAlt)EditorGUI.EnumPopup(r0, eSearchBy); if (EditorGUI.EndChangeCheck()) { searchProp.SetEnumValue((SearchBy)eSearchBy); } switch (eSearchBy) { case SearchByAlt.Direct: { //SPEditorGUI.PropertyField(r1, targetProp, GUIContent.none); if (_selectableDrawer == null) { _selectableDrawer = new SelectableComponentPropertyDrawer(); } _selectableDrawer.AllowSceneObjects = true; _selectableDrawer.RestrictionType = _inheritsFromType; _selectableDrawer.AllowProxy = _allowProxy; _selectableDrawer.OnGUI(r1, targetProp, GUIContent.none); } break; case SearchByAlt.Tag: { queryProp.stringValue = EditorGUI.TagField(r1, queryProp.stringValue); targetProp.objectReferenceValue = null; } break; case SearchByAlt.Name: { queryProp.stringValue = EditorGUI.TextField(r1, queryProp.stringValue); targetProp.objectReferenceValue = null; } break; case SearchByAlt.Type: { var tp = TypeUtil.FindType(queryProp.stringValue); if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object))) { tp = null; } tp = SPEditorGUI.TypeDropDown(r1, GUIContent.none, typeof(UnityEngine.Object), tp); queryProp.stringValue = (tp != null) ? tp.FullName : null; targetProp.objectReferenceValue = null; } break; } EditorGUI.EndProperty(); }