public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var baseType = typeof(object); bool allowAbstractTypes = false; bool allowInterfaces = false; System.Type defaultType = null; System.Type[] excludedTypes = null; TypeDropDownListingStyle style = TypeDropDownListingStyle.Namespace; System.Predicate <System.Type> searchPredicate = null; if (_isManuallyConfigured) { baseType = _inheritsFromType ?? typeof(object); allowAbstractTypes = _allowAbstractTypes; allowInterfaces = _allowInterfaces; defaultType = _defaultType; excludedTypes = _excludedTypes; style = _dropDownStyle; searchPredicate = _searchPredicate; } else if (this.fieldInfo != null) { var attrib = this.fieldInfo.GetCustomAttributes(typeof(TypeReference.ConfigAttribute), true).FirstOrDefault() as TypeReference.ConfigAttribute; if (attrib != null) { baseType = attrib.inheritsFromType; allowAbstractTypes = attrib.allowAbstractClasses; allowInterfaces = attrib.allowInterfaces; defaultType = attrib.defaultType; excludedTypes = attrib.excludedTypes; style = attrib.dropDownStyle; searchPredicate = null; } } var tp = GetTypeFromTypeReference(property); EditorGUI.BeginChangeCheck(); tp = SPEditorGUI.TypeDropDown(position, label, baseType, tp, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, style, searchPredicate); if (EditorGUI.EndChangeCheck()) { SetTypeToTypeReference(property, tp); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var attrib = this.fieldInfo.GetCustomAttributes(typeof(TypeReference.ConfigAttribute), true).FirstOrDefault() as TypeReference.ConfigAttribute; var baseType = typeof(Object); bool allowAbstractTypes = false; bool allowInterfaces = false; System.Type defaultType = null; System.Type[] excludedTypes = null; TypeDropDownListingStyle style = TypeDropDownListingStyle.Namespace; if (attrib != null) { baseType = attrib.inheritsFromType; allowAbstractTypes = attrib.allowAbstractClasses; allowInterfaces = attrib.allowInterfaces; defaultType = attrib.defaultType; excludedTypes = attrib.excludedTypes; style = attrib.dropDownStyle; } //var tpref = EditorHelper.GetTargetObjectOfProperty(property) as TypeReference; //if(tpref == null) //{ // tpref = new TypeReference(); // EditorHelper.SetTargetObjectOfProperty(property, tpref); // property.serializedObject.ApplyModifiedProperties(); //} //EditorGUI.BeginChangeCheck(); //tpref.Type = SPEditorGUI.TypeDropDown(position, label, baseType, tpref.Type, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, style); //if (EditorGUI.EndChangeCheck()) // property.serializedObject.Update(); var tp = GetTypeFromTypeReference(property); EditorGUI.BeginChangeCheck(); tp = SPEditorGUI.TypeDropDown(position, label, baseType, tp, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, style); if (EditorGUI.EndChangeCheck()) { SetTypeToTypeReference(property, tp); } EditorGUI.EndProperty(); }
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); var configProp = property.FindPropertyRelative(PROP_CONFIGURED); var targetProp = property.FindPropertyRelative(PROP_TARGET); var findProp = property.FindPropertyRelative(PROP_FIND); //var r0 = new Rect(rect.xMin, rect.yMin, EditorGUIUtility.labelWidth, rect.height); //rect = new Rect(r0.xMax, rect.yMin, rect.width - r0.width, rect.height); //property.isExpanded = EditorGUI.Foldout(r0, property.isExpanded, label); if (!this.AlwaysExpanded) { property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(ref rect, property.isExpanded, label); } else { rect = EditorGUI.PrefixLabel(rect, label); } var r0 = new Rect(rect.xMin, rect.yMin, Mathf.Min(rect.width * 0.25f, 50f), rect.height); var e = (configProp.boolValue) ? TargetSource.Config : TargetSource.Arg; EditorGUI.BeginChangeCheck(); e = (TargetSource)EditorGUI.EnumPopup(r0, e); if (EditorGUI.EndChangeCheck()) { UpdateTargetFromSource(targetProp, e); configProp.boolValue = (e != TargetSource.Arg); if (e != TargetSource.Arg) { findProp.SetEnumValue(TriggerableTargetObject.FindCommand.Direct); } } else if (e == TargetSource.Config && !_defaultSet && targetProp.objectReferenceValue == null) { UpdateTargetFromSource(targetProp, e); _defaultSet = true; } else { _defaultSet = true; } var r1 = new Rect(rect.xMin + r0.width, rect.yMin, rect.width - r0.width, rect.height); if (!configProp.boolValue) { var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>(); switch (e0) { case TriggerableTargetObject.FindCommand.Direct: EditorGUI.LabelField(r1, "Target determined by activating trigger."); break; case TriggerableTargetObject.FindCommand.FindParent: case TriggerableTargetObject.FindCommand.FindInChildren: case TriggerableTargetObject.FindCommand.FindInEntity: EditorGUI.LabelField(r1, e0.ToString() + " of activating trigger arg."); break; case TriggerableTargetObject.FindCommand.FindInScene: case TriggerableTargetObject.FindCommand.FindEntityInScene: default: configProp.boolValue = false; targetProp.objectReferenceValue = null; EditorGUI.LabelField(r1, e0.ToString()); break; } targetProp.objectReferenceValue = null; } else { _objectDrawer.OnGUI(r1, targetProp, GUIContent.none); } //################################ //SECOND LINE if (this.AlwaysExpanded || property.isExpanded) { var indent = EditorGUIUtility.labelWidth * 0.5f; rect = new Rect(position.xMin + indent, position.yMin + EditorGUIUtility.singleLineHeight, Mathf.Max(0f, position.width - indent), EditorGUIUtility.singleLineHeight); var w0 = Mathf.Min(rect.width * 0.3f, 120f); var w1 = Mathf.Min(rect.width * 0.3f, 80f); var w2 = rect.width - w0 - w1; r0 = new Rect(rect.xMin, rect.yMin, w0, rect.height); r1 = new Rect(r0.xMax, rect.yMin, w1, rect.height); var r2 = new Rect(r1.xMax, rect.yMin, w2, rect.height); var resolveProp = property.FindPropertyRelative(PROP_RESOLVEBY); var queryProp = property.FindPropertyRelative(PROP_QUERY); var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>(); EditorGUI.BeginChangeCheck(); e0 = (TriggerableTargetObject.FindCommand)EditorGUI.EnumPopup(r0, e0); if (EditorGUI.EndChangeCheck()) { findProp.SetEnumValue(e0); } switch (e0) { case TriggerableTargetObject.FindCommand.FindInScene: case TriggerableTargetObject.FindCommand.FindEntityInScene: configProp.boolValue = false; targetProp.objectReferenceValue = null; break; } var e1 = resolveProp.GetEnumValue <TriggerableTargetObject.ResolveByCommand>(); EditorGUI.BeginChangeCheck(); e1 = (TriggerableTargetObject.ResolveByCommand)EditorGUI.EnumPopup(r1, e1); if (EditorGUI.EndChangeCheck()) { resolveProp.SetEnumValue(e1); } switch (e1) { case TriggerableTargetObject.ResolveByCommand.Nothing: { var cache = SPGUI.Disable(); EditorGUI.TextField(r2, string.Empty); queryProp.stringValue = string.Empty; cache.Reset(); } break; case TriggerableTargetObject.ResolveByCommand.WithTag: { queryProp.stringValue = EditorGUI.TagField(r2, queryProp.stringValue); } break; case TriggerableTargetObject.ResolveByCommand.WithName: { queryProp.stringValue = EditorGUI.TextField(r2, queryProp.stringValue); } break; case TriggerableTargetObject.ResolveByCommand.WithType: { var tp = TypeUtil.FindType(queryProp.stringValue); if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object))) { tp = null; } tp = SPEditorGUI.TypeDropDown(r2, GUIContent.none, typeof(UnityEngine.Object), tp); queryProp.stringValue = (tp != null) ? tp.FullName : null; } break; } } EditorGUI.EndProperty(); }
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(); }