EventDelegate.ToString C# (CSharp) Method

ToString() public method

Convert the delegate to its string representation.
public ToString ( ) : string
return string
	public override string ToString ()
	{
		if (mTarget != null)
		{
			string typeName = mTarget.GetType().ToString();
			int period = typeName.LastIndexOf('.');
			if (period > 0) typeName = typeName.Substring(period + 1);

			if (!string.IsNullOrEmpty(methodName)) return typeName + "." + methodName;
			else return typeName + ".[delegate]";
		}
		return mRawDelegate ? "[delegate]" : null;
	}

Usage Example

	public override void OnGUI (Rect position, SerializedProperty prop, GUIContent label)
	{
		Undo.RecordObject(prop.serializedObject.targetObject, "Delegate Selection");

		SerializedProperty targetProp = prop.FindPropertyRelative("mTarget");
		SerializedProperty methodProp = prop.FindPropertyRelative("mMethodName");

		MonoBehaviour target = targetProp.objectReferenceValue as MonoBehaviour;
		string methodName = methodProp.stringValue;

		EditorGUI.indentLevel = prop.depth;
		EditorGUI.LabelField(position, label);

		Rect line = position;
		line.yMin = position.yMin + lineHeight;
		line.yMax = line.yMin + lineHeight;

		EditorGUI.indentLevel = targetProp.depth;
		target = EditorGUI.ObjectField(line, "Notify", target, typeof(MonoBehaviour), true) as MonoBehaviour;

		if (target != null && target.gameObject != null)
		{
			GameObject go = target.gameObject;
			List<Entry> list = EventDelegateEditor.GetMethods(go);

			int index = 0;
			int choice = 0;

			EventDelegate del = new EventDelegate();
			del.target = target;
			del.methodName = methodName;
			string[] names = PropertyReferenceDrawer.GetNames(list, del.ToString(), out index);

			line.yMin += lineHeight;
			line.yMax += lineHeight;
			choice = EditorGUI.Popup(line, "Method", index, names);

			if (choice > 0)
			{
				if (choice != index)
				{
					Entry entry = list[choice - 1];
					target = entry.target as MonoBehaviour;
					methodName = entry.name;
				}
			}
		}

		targetProp.objectReferenceValue = target;
		methodProp.stringValue = methodName;
	}
All Usage Examples Of EventDelegate::ToString