/// <inheritdoc /> protected override void DoBuildMembers() { #if DEV_MODE && DEBUG_BUILD_MEMBERS Debug.Log(ToString() + ".DoBuildMembers called with invocationList " + StringUtils.ToString(invocationList)); #endif int count = invocationList.Length; if (count == 0) { DrawerArrayPool.Resize(ref members, 1); members[0] = NullToggleDrawer.Create(AddNewItemToInvocationList, InspectorPreferences.Styles.AddButton, this, ReadOnly); } else { DrawerArrayPool.Resize(ref members, count); var type = Type; for (int n = count - 1; n >= 0; n--) { var invocationMember = invocationList[n]; members[n] = DelegateItemDrawer.Create(invocationMember, type, this, GUIContentPool.Create("Delegate #" + StringUtils.ToString(n + 1)), ReadOnly); members[n].OnKeyboardInputBeingGiven += OnMemberKeyboardInputBeingGiven; } } }
/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="onClicked"> Action to invoke every time the button is clicked. </param> /// <param name="guiStyle"> GUIStyle specifying how the toggle control should look. </param> /// <param name="parent"> /// The parent drawers of created drawers. This can NOT be null because the state of the toggle /// control is determined by whether or not the the value of the parent drawers is null or not. /// </param> /// <param name="readOnly"> True if drawer should be read only. </param> /// <returns> The drawer instance, ready to be used. </returns> public static NullToggleDrawer Create(Action onClicked, GUIStyle guiStyle, [NotNull] IParentDrawer parent, bool readOnly) { NullToggleDrawer result; if (!DrawerPool.TryGet(out result)) { result = new NullToggleDrawer(); } result.Setup(onClicked, guiStyle, parent, readOnly); result.LateSetup(); return(result); }
/// <inheritdoc /> protected override void DoBuildMembers() { #if DEV_MODE && DEBUG_BUILD_MEMBERS Debug.Log(StringUtils.ToColorizedString(ToString(), ".DoBuildMembers called with memberBuildList=", memberBuildList, ", IsNull = ", IsNull, ", CanBeUnityObject=", CanBeUnityObject, ", DrawToggleNullButton=", DrawToggleNullButton, ", memberInfo=", memberInfo, ", memberInfo.Data=", (memberInfo == null ? "n/a" : StringUtils.ToString(memberInfo.Data)))); #endif var typeForValue = TypeForValue; if (typeForValue == null) { if (CanBeUnityObject) { var referenceField = ObjectReferenceDrawer.Create(null, memberInfo, GetTypeForObjectReferenceField(), this, GUIContent.none, AllowSceneObjects(), false, ReadOnly); if (DrawToggleNullButton) { DrawerArrayPool.Resize(ref members, 2); members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly); members[1] = referenceField; } else { DrawerArrayPool.Resize(ref members, 1); members[0] = referenceField; } } else if (DrawToggleNullButton) { DrawerArrayPool.Resize(ref members, 1); members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly); } else { DrawerArrayPool.Resize(ref members, 1); members[0] = ReadOnlyTextDrawer.Create("null", null, this, GUIContent.none); } } else { #if DEV_MODE && PI_ASSERTATIONS Assert(typeForValue != null, ToString(), ".BuildMembers was called with isNull=false but with userSelectedType=", null, ".\nDrawInSingleRow=", DrawInSingleRow, ", Value=", Value, ", Value.Type=", StringUtils.TypeToString(Value)); Assert(!typeForValue.IsAbstract, ToString(), ".BuildMembers was called with isNull=false but with userSelectedType ", userSelectedType, " IsAbstract=" + true + ".\nDrawInSingleRow=", DrawInSingleRow, ", Value=", Value, ", Value.Type=", StringUtils.TypeToString(Value)); #endif var valueDrawer = BuildDrawerForValue(typeForValue); #if DEV_MODE && PI_ASSERTATIONS Assert(valueDrawer.GetType() != GetType()); #endif valueDrawer.OnValueChanged += (changed, setValue) => SetValue(setValue); if (DrawToggleNullButton) { DrawerArrayPool.Resize(ref members, 2); members[0] = NullToggleDrawer.Create(OnNullToggleButtonClicked, this, ReadOnly); members[1] = valueDrawer; } else { DrawerArrayPool.Resize(ref members, 1); members[0] = valueDrawer; } #if DRAW_VALUE_IN_SINGLE_ROW_IF_POSSIBLE if (DrawerUtility.CanDrawInSingleRow(valueDrawer)) { valueDrawer.Label = GUIContentPool.Empty(); } #endif } }
/// <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); } } }