/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="value"> The initial cached value of the drawer. </param> /// <param name="memberInfo"> LinkedMemberInfo for the class member that the created drawer represents. Can be null. </param> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> The prefix label. </param> /// <param name="readOnly"> True if drawer should be read only. </param> /// <returns> The drawer instance, ready to be used. </returns> public static TypeDrawer Create(Type value, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly) { TypeDrawer result; if (!DrawerPool.TryGet(out result)) { result = new TypeDrawer(); } result.Setup(value, typeof(Type), memberInfo, parent, label, readOnly); result.LateSetup(); return(result); }
/// <inheritdoc /> protected override void DoBuildMembers() { int count = memberBuildList.Count; var genericTypeArguments = Value; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(count == genericTypeArguments.Length, "memberBuildList.Count=" + memberBuildList.Count + " != " + genericTypeArguments.Length); #endif #if DEV_MODE Debug.Log("GenericTypeArgumentDrawer.DoBuildMembers called with types.Length=" + genericTypeArguments.Length + ", memberBuildList.Count=" + memberBuildList.Count + ", drawInSingleRow=" + drawInSingleRow); #endif DrawerArrayPool.Resize(ref members, count); for (int n = count - 1; n >= 0; n--) { var argumentMemberInfo = memberBuildList[0]; var type = argumentMemberInfo.Type; var baseTypeConstraints = type.GetGenericParameterConstraints(); TypeConstraint typeCategoryConstraint; var specialConstraintMask = type.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask; if ((specialConstraintMask & GenericParameterAttributes.ReferenceTypeConstraint) != 0) { typeCategoryConstraint = TypeConstraint.Class; } else if ((specialConstraintMask & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) { typeCategoryConstraint = TypeConstraint.Struct; } else { typeCategoryConstraint = TypeConstraint.None; } if (baseTypeConstraints.Length > 0) { members[n] = ConstraintedTypeDrawer.Create(type, baseTypeConstraints, typeCategoryConstraint, argumentMemberInfo, this, GUIContent.none, ReadOnly); } else { members[n] = TypeDrawer.Create(type, argumentMemberInfo, this, GUIContent.none, ReadOnly); } } }
/// <inheritdoc /> protected override void DoBuildMembers() { int count = genericArguments.Length; drawInSingleRow = count == 1; DrawerArrayPool.Resize(ref members, count); if (count == 1) { var genericArgument = genericArguments[0]; label.text = GetLabel(genericArgument); label.tooltip = "Generic Argument"; members[0] = TypeDrawer.Create(GetDefaultValue(genericArgument), null, this, GUIContentPool.Empty(), false); } else { for (int n = count - 1; n >= 0; n--) { var genericArgument = genericArguments[n]; string labelText = GetLabel(genericArgument); string tooltip = string.Concat("Generic Argument ", StringUtils.ToString(n + 1), "/", StringUtils.ToString(count)); members[n] = TypeDrawer.Create(GetDefaultValue(genericArgument), null, this, GUIContentPool.Create(labelText, tooltip), false); } } #if DEV_MODE try { Debug.Log(ToString() + ".RebuildIntructionsInChildren() - now has " + members.Length + " members:\n" + StringUtils.ToString(members)); } catch (Exception e) //had a bug where even trying to access "this" resulted in a null reference exception { Debug.LogError("MethodDrawer.RebuildIntructionsInChildren() " + e); return; } for (int n = 0; n < members.Length; n++) { Debug.Log(GetType().Name + " Created #" + n + " " + members[n].GetType().Name); } #endif }
public override void TypePopup(Rect position, TypeDrawer popupField) { popupField.DrawControlVisuals(position, popupField.Value); }
/// <inheritdoc /> protected override void DoBuildMembers() { var value = Value; if (value == null) { DrawerArrayPool.Resize(ref members, 2); members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly); members[1] = ObjectReferenceDrawer.Create(null, Types.UnityObject, this, GUIContent.none, true, false, ReadOnly); } else { var target = value.Target; bool hasTarget = target != null; Object unityObject; bool isUnityObject; bool isAnonymous; string methodName; Type targetType; int methodIndex; var method = value.Method; if (hasTarget) { targetType = target.GetType(); UpdateMethodOptions(targetType, true); unityObject = target as Object; isUnityObject = unityObject != null; methodName = method.Name; isAnonymous = methodName[0] == '<'; if (isAnonymous) { string methodOrigin = methodName.Substring(1, methodName.IndexOf('>') - 1); methodName = string.Concat("Anonymous Method (", methodOrigin, ")"); } methodIndex = Array.IndexOf(methodOptionNames, methodName); if (methodIndex == -1) { methodOptions = methodOptions.InsertAt(0, method); methodOptionNames = methodOptionNames.InsertAt(0, methodName); methodIndex = 0; } } else { methodIndex = 0; if (method == null) { targetType = null; methodName = "{ }"; unityObject = null; isUnityObject = false; isAnonymous = false; ArrayPool <MethodInfo> .Resize(ref methodOptions, 1); methodOptions[0] = method; ArrayPool <string> .Resize(ref methodOptionNames, 1); methodOptionNames[0] = methodName; } else { targetType = method.ReflectedType; UpdateMethodOptions(targetType, false); methodName = method.Name; unityObject = null; isUnityObject = false; isAnonymous = methodName[0] == '<'; if (isAnonymous) { string methodOrigin = methodName.Substring(1, methodName.IndexOf('>') - 1); methodName = string.Concat("Anonymous Method (", methodOrigin, ")"); } methodIndex = Array.IndexOf(methodOptionNames, methodName); if (methodIndex == -1) { methodOptions = methodOptions.InsertAt(0, method); methodOptionNames = methodOptionNames.InsertAt(0, methodName); methodIndex = 0; } } } #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(methodOptions.Length == methodOptionNames.Length); #endif #if DEV_MODE Debug.Log(Msg(ToString() + ".DoBuildMembers with target=", target, ", type=", targetType, ", isUnityObject=", isUnityObject, ", methodName=", methodName, ", isAnonymous=", isAnonymous + ", methodNames=", StringUtils.ToString(methodOptionNames))); #endif if (isUnityObject) { DrawerArrayPool.Resize(ref members, 2); members[0] = ObjectReferenceDrawer.Create(unityObject, Types.UnityObject, this, GUIContentPool.Empty(), true, false, ReadOnly); members[1] = PopupMenuDrawer.Create(methodIndex, methodOptionNames, null, this, GUIContentPool.Empty(), ReadOnly); } else { DrawerArrayPool.Resize(ref members, 3); members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly); members[1] = TypeDrawer.Create(targetType, null, this, GUIContentPool.Empty(), ReadOnly); members[2] = PopupMenuDrawer.Create(methodIndex, methodOptionNames, null, this, GUIContentPool.Empty(), ReadOnly); } } }