/// <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; } } }
/// <inheritdoc /> protected override void DoBuildMembers() { #if DEV_MODE Debug.Log(ToString() + ".DoBuildMembers()"); #endif ParentDrawerUtility.BuildMembers(DrawerProvider, this, memberBuildList, ref members); if (inspector.Preferences.drawScriptReferenceFields || DebugMode) { var monoScript = MonoScript; if (monoScript != null) { DrawerArrayPool.InsertAt(ref members, 0, ScriptReferenceDrawer.Create(MonoScript, this, false), true); } } if (DebugMode && (members.Length == 0 || !(members[0] is DebugModeDisplaySettingsDrawer))) { #if DEV_MODE Debug.Log("InsertAt(0, DebugModeDisplaySettingsDrawer)"); #endif DrawerArrayPool.InsertAt(ref members, 0, SpaceDrawer.Create(7f, this), true); DrawerArrayPool.InsertAt(ref members, 0, DebugModeDisplaySettingsDrawer.Create(this, debugModeDisplaySettings), true); DrawerArrayPool.InsertAt(ref members, 0, SpaceDrawer.Create(7f, this), true); } #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(!members.ContainsNullMembers()); #endif }
public void RebuildIntructionsInChildren() { DisposeChildren(); AddComponentMenuItem[] values; if (activeItem == null) { values = AddComponentMenuItems.GetFiltered(FilterString); } else { values = activeItem.children; } int count = values.Length; DrawerArrayPool.Resize(ref members, count); for (int n = 0; n < count; n++) { members[n] = AddComponentMenuItemDrawer.Create(values[n]); } UpdateContentRect(); SetScrollPos(0f, false); SetSelectedMember(0, false); UpdateVisibleMembers(); }
/// <inheritdoc/> public override void AddComponentMember(int memberIndex, [NotNull] IComponentDrawer componentDrawer) { var category = ComponentCategories.Get(componentDrawer.Component); #if DEV_MODE Debug.Log("AddComponentMember(" + memberIndex + ", " + componentDrawer.GetType().Name + ") category=\"" + category + "\", members.Length=" + members.Length); #endif var categoryDrawer = GetOrCreateCategoryDrawer(category); if (categoryDrawer == null) { var setMembers = members; if (memberIndex == -1) { memberIndex = setMembers.Length - LastCollectionMemberCountOffset + 1; } DrawerArrayPool.InsertAt(ref setMembers, memberIndex, componentDrawer, false); SetMembers(setMembers); return; } var setCategoryMembers = categoryDrawer.Members; DrawerArrayPool.InsertAt(ref setCategoryMembers, setCategoryMembers.Length, componentDrawer, false); categoryDrawer.SetMembers(setCategoryMembers); }
/// <inheritdoc/> public void DeleteMember(IDrawer delete) { int index = Array.IndexOf(members, delete); if (index == -1) { Debug.LogError(ToString() + ".DeleteMemberValue - Unable to find item " + (delete == null ? "null" : delete.ToString()) + " among members"); return; } var setVisibleMembers = visibleMembers; int visibleMembersIndex = Array.IndexOf(visibleMembers, delete); if (visibleMembersIndex != -1) { DrawerArrayPool.RemoveAt(ref setVisibleMembers, visibleMembersIndex, false, false); } var setMembers = members; DrawerArrayPool.RemoveAt(ref setMembers, index, false, true); SetMembers(setMembers, setVisibleMembers, true); inspector.RefreshView(); }
/// <summary> /// Disposes all members and sets all visible members to null. /// It can be useful to call this before rebuilding members, so that the previous instances will be pooled and can be reused. /// </summary> public void DisposeMembersAndClearVisibleMembers() { DrawerArrayPool.Dispose(ref visibleMembers, false); visibleMembers = ArrayPool <IDrawer> .ZeroSizeArray; assumeVisibleMembersChangedDuringNextUpdateVisibleMembers = true; DrawerArrayPool.DisposeContent(ref members); updateCachedValuesFor.Clear(); }
public static TDrawerWindow Create <TDrawerWindow>([NotNull] GameObject[] targets, [NotNull] IInspector inspector, Action doOnClosed = null) where TDrawerWindow : DrawerToWindow { var drawers = DrawerGroup.Create(inspector); var members = drawers.Members; DrawerArrayPool.InsertAt(ref members, 0, GameObjectDrawer.Create(targets, drawers, inspector), false); drawers.SetMembers(members); return(Create <TDrawerWindow>(drawers, doOnClosed)); }
public static TDrawerWindow Create <TDrawerWindow>([NotNull] Component[] targets, [NotNull] IInspector inspector, Action doOnClosed = null) where TDrawerWindow : DrawerToWindow { var drawers = DrawerGroup.Create(inspector); var members = drawers.Members; DrawerArrayPool.InsertAt(ref members, 0, inspector.DrawerProvider.GetForComponents(inspector, targets, drawers), false); drawers.SetMembers(members); return(Create <TDrawerWindow>(drawers, doOnClosed)); }
/// <inheritdoc/> protected override void DoBuildMembers() { #if DEV_MODE && DEBUG_BUILD_MEMBERS Debug.Log(Msg(ToString(), ".DoBuildMembers with hasResult=", hasResult, ", hasParameters=", hasParameters, ", isGeneric=", isGeneric)); #endif if (!hasResult && !hasParameters && !isGeneric) { DrawerArrayPool.Resize(ref members, 0); } else { int size = 0; if (hasResult) { size++; } if (isGeneric) { size++; } if (hasParameters) { size++; } DrawerArrayPool.Resize(ref members, size); bool readOnly = ReadOnly; int index = 0; if (isGeneric) { members[0] = GenericsDrawer.Create(memberInfo, this, GUIContentPool.Create("Generics"), readOnly); index++; } if (hasParameters) { members[index] = ParameterDrawer.Create(MethodInfo.GetParameters(), memberInfo, this, GUIContentPool.Create("Parameters"), readOnly); index++; } if (hasResult) { string tooltip = LinkedMemberInfo.TooltipDatabase.GetTooltipFromParent(MethodInfo.ReturnParameter, memberInfo, "Returns"); if (tooltip.Length == 0) { tooltip = "Value returned by method."; } var resultMemberInfo = resultMemberHierarchy.Get(null, typeof(MethodDrawer).GetField("result", BindingFlags.Instance | BindingFlags.NonPublic), LinkedMemberParent.ClassInstance, null); members[index] = DrawerProvider.GetForField(result, Type, resultMemberInfo, this, GUIContentPool.Create("Result", tooltip), readOnly); } } }
/// <inheritdoc /> protected override void DoBuildMembers() { bool readOnly = memberInfo != null && !memberInfo.CanWrite; if (readOnly) { DrawerArrayPool.Resize(ref members, 0); } else { DrawerArrayPool.Resize(ref members, 2); var min = TimeSpan.MinValue; var max = TimeSpan.MaxValue; var group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Days / Hours"), ReadOnly); { var groupMembers = DrawerArrayPool.Create(2); var groupMember = ClampedIntDrawer.Create(Days, min.Days, max.Days, null, group, GUIContentPool.Create("D"), ReadOnly); groupMember.OnValueChanged += SetDays; groupMembers[0] = groupMember; groupMember = ClampedIntDrawer.Create(Hours, MinHours, MaxHours, null, group, GUIContentPool.Create("H"), ReadOnly); groupMember.OnValueChanged += SetHours; groupMember.OverrideValidateValue = ValidateHours; groupMembers[1] = groupMember; group.SetMembers(groupMembers, true); members[0] = group; } group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Minutes / Seconds"), ReadOnly); { var groupMembers = DrawerArrayPool.Create(2); var groupMember = ClampedIntDrawer.Create(Minutes, MinMinutes, MaxMinutes, null, group, GUIContentPool.Create("M"), ReadOnly); groupMember.OnValueChanged += SetMinutes; groupMember.OverrideValidateValue = ValidateMinutes; groupMembers[0] = groupMember; var secondsMember = ClampedFloatDrawer.Create(SecondsWithFractions, MinSeconds, MaxSeconds, null, group, GUIContentPool.Create("S"), ReadOnly); secondsMember.OnValueChanged += SetSeconds; secondsMember.OverrideValidateValue = ValidateSeconds; groupMembers[1] = secondsMember; group.SetMembers(groupMembers, true); members[1] = group; } } }
public void UpdateVisibleMembers() { GUI.changed = true; int count = lastVisibleIndex - firstVisibleIndex + 1; DrawerArrayPool.Resize(ref visibleMembers, count); for (int n = count - 1; n >= 0; n--) { var member = members[firstVisibleIndex + n]; visibleMembers[n] = member; visibleMembersHaveConflicts[n] = AddComponentUtility.HasConflictingMembers(member.Type, target); } }
/// <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 }
/// <inheritdoc /> protected override void DoBuildMembers() { #if DEV_MODE Debug.Log(ToString() + ".DoBuildMembers()"); #endif ParentDrawerUtility.BuildMembers(DrawerProvider, this, memberBuildList, ref members); #if UNITY_EDITOR if (Platform.EditorMode && (inspector.Preferences.drawScriptReferenceFields || DebugMode)) { var monoScript = MonoScript; if (monoScript != null) { DrawerArrayPool.InsertAt(ref members, 0, ScriptReferenceDrawer.Create(MonoScript, this, false), true); } } #endif }
/// <inheritdoc/> protected override void DoBuildMembers() { if (!hasResult && !hasParameters) { DrawerArrayPool.Resize(ref members, 0); } else { if (hasResult) { ResultDrawer = DrawerProvider.GetForField(base.Value, Type, memberInfo, this, GUIContentPool.Create("Value"), ReadOnly); } if (hasParameters) { IndexParameterDrawer = ParameterDrawer.Create(PropertyInfo.GetIndexParameters(), memberInfo, this, GUIContentPool.Create("Parameters"), false); } } }
/// <inheritdoc/> protected override void DoBuildMembers() { if (parent == null) { return; } #if UNITY_EDITOR DrawerArrayPool.Resize(ref members, 2); var scriptReference = ScriptReferenceDrawer.Create(monoScript, this, monoScript != null); scriptReference.OnValueChanged += SetMonoScript; members[0] = scriptReference; int index = 1; #else int index = 0; #endif DrawerArrayPool.Resize(ref members, index + 1); members[index] = BoxDrawer.Create(this, GUIContentPool.Create(GetWarningMessage()), MessageType.Warning, ReadOnly); }
/// <inheritdoc /> protected override void DoBuildMembers() { DrawerArrayPool.Resize(ref members, 2); // Making key be read-only for now until code has been added to handle on-the-fly changing of keys gracefully. // E.g. all keys should use delayed text fields and be marked with NotNull (e.g. using a custom DrawerProvider). var keyInfo = memberBuildList[0]; IDrawer keyMember; var keyValue = keyInfo.GetValue(0); var keyLabel = GUIContentPool.Create("K"); //var keyIsReadOnly = ReadOnly; const bool keyIsReadOnly = true; if (keyType == Types.Int) { keyMember = DelayedIntDrawer.Create((int)keyValue, keyInfo, this, keyLabel, keyIsReadOnly); } else if (keyType == Types.String) { keyMember = TextDrawer.Create((string)keyValue, keyInfo, this, keyLabel, keyIsReadOnly, false, true); } else if (keyType == Types.Float) { keyMember = DelayedFloatDrawer.Create((float)keyValue, keyInfo, this, keyLabel, keyIsReadOnly); } else { keyMember = DrawerProvider.GetForField(keyValue, keyType, keyInfo, this, keyLabel, keyIsReadOnly); } keyMember.OverrideValidateValue = ValidateKey; members[0] = keyMember; var valueInfo = memberBuildList[1]; var valueMember = DrawerProvider.GetForField(valueInfo.GetValue(0), valueType, valueInfo, this, GUIContentPool.Create("V"), ReadOnly); members[1] = valueMember; }
/// <inheritdoc /> protected override void DoBuildMembers() { bool readOnly = ReadOnly; DrawerArrayPool.Resize(ref members, 2); var keyInfo = memberBuildList[0]; members[0] = DrawerProvider.GetForField(keyInfo.GetValue(0), keyInfo.Type, keyInfo, this, GUIContentPool.Create("K"), readOnly); var valueInfo = memberBuildList[1]; members[1] = DrawerProvider.GetForField(valueInfo.GetValue(0), valueInfo.Type, valueInfo, this, GUIContentPool.Create("V"), readOnly); #if DEV_MODE && DEBUG_BUILD_MEMBERS Debug.Log(StringUtils.ToColorizedString(this + ".DoBuildMembers with readOnly=", readOnly, ", members[0].ReadOnly=", members[0].ReadOnly, ", members[1].ReadOnly=", members[1].ReadOnly)); #endif #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(members[0].ReadOnly == readOnly, StringUtils.ToColorizedString(this + " readOnly (", readOnly, ") != members[0].ReadOnly (", members[0].ReadOnly, ")")); Debug.Assert(members[1].ReadOnly == readOnly, StringUtils.ToColorizedString(this + " readOnly (", readOnly, ") != members[1].ReadOnly (", members[1].ReadOnly, ")")); #endif }
/// <inheritdoc/> protected override void DoBuildMembers() { if (DebugMode) { base.DoBuildMembers(); return; } DrawerArrayPool.Resize(ref members, 3); bool usingLocalSpace = UsingLocalSpace; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(memberBuildList.Count == (usingLocalSpace ? 3 : 2)); #endif var labels = Preferences.labels; var firstTransform = (Transform)Target; members[0] = PositionDrawer.Create(usingLocalSpace ? firstTransform.localPosition : firstTransform.position, memberBuildList[0], this, labels.Position, ReadOnly); members[1] = RotationDrawer.Create(usingLocalSpace ? firstTransform.localEulerAngles : firstTransform.eulerAngles, memberBuildList[1], this, labels.Rotation, ReadOnly); var scaleMember = ScaleDrawer.Create(usingLocalSpace ? firstTransform.localScale : firstTransform.lossyScale, memberBuildList[2], this, labels.Scale, ReadOnly); members[2] = scaleMember; }
/// <inheritdoc /> public override void UpdateVisibleMembers() { if (!DrawInSingleRow && !Unfolded) { if (DrawToggleNullButton && members[0].ShouldShowInInspector) { if (visibleMembers.Length != 1) { DrawerArrayPool.Resize(ref visibleMembers, 1); visibleMembers[0] = members[0]; OnVisibleMembersChanged(); OnChildLayoutChanged(); } #if DEV_MODE && DEBUG_UPDATE_VISIBLE_MEMBERS Debug.Log(ToString() + ".UpdateVisibleMembers() - " + visibleMembers.Length + " of " + members.Length + " now visible\nvisibleMembers=" + StringUtils.ToString(visibleMembers) + "\nmembers=" + StringUtils.ToString(members) + "\nUnfolded=" + Unfolded + ", MembersAreVisible=" + MembersAreVisible); #endif return; } if (visibleMembers.Length != 0) { DrawerArrayPool.Resize(ref visibleMembers, 0); OnVisibleMembersChanged(); OnChildLayoutChanged(); } #if DEV_MODE && DEBUG_UPDATE_VISIBLE_MEMBERS Debug.Log(ToString() + ".UpdateVisibleMembers() - " + visibleMembers.Length + " of " + members.Length + " now visible\nvisibleMembers=" + StringUtils.ToString(visibleMembers) + "\nmembers=" + StringUtils.ToString(members) + "\nUnfolded=" + Unfolded + ", MembersAreVisible=" + MembersAreVisible); #endif return; } base.UpdateVisibleMembers(); #if DEV_MODE && DEBUG_UPDATE_VISIBLE_MEMBERS Debug.Log(ToString() + ".UpdateVisibleMembers() - " + visibleMembers.Length + " of " + members.Length + " now visible\nvisibleMembers=" + StringUtils.ToString(visibleMembers) + "\nmembers=" + StringUtils.ToString(members) + "\nUnfolded=" + Unfolded + ", MembersAreVisible=" + MembersAreVisible + ", DrawInSingleRow=" + DrawInSingleRow + ", DrawToggleNullButton=" + DrawToggleNullButton); #endif }
/// <inheritdoc cref="IDrawer.Dispose" /> public override void Dispose() { inactive = true; ParentDrawerUtility.OnDisposing(Inspector, this); cachedValuesNeedUpdating = false; #if ENABLE_SPREADING lastUpdateCachedValuesMemberIndex = -1; #endif if (memberBuildState == MemberBuildState.MembersBuilt) { DisposeMembers(); } DrawerArrayPool.Resize(ref members, 0); DrawerArrayPool.Resize(ref visibleMembers, 0); updateCachedValuesFor.Clear(); memberBuildState = MemberBuildState.Unstarted; memberBuildList.Clear(); assumeVisibleMembersChangedDuringNextUpdateVisibleMembers = true; labelLastDrawPosition.y = -100f; labelLastDrawPosition.width = 0f; labelLastDrawPosition.height = 0f; bodyLastDrawPosition.y = -100f; bodyLastDrawPosition.width = 0f; bodyLastDrawPosition.height = 0f; base.Dispose(); }
/// <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); } } }
/// <inheritdoc/> public void OnMemberDragNDrop(MouseDownInfo mouseDownInfo, Object[] draggedObjects) { var reordering = mouseDownInfo.Reordering; int dropIndex = reordering.MouseoveredDropTarget.MemberIndex; if (dropIndex >= 0) { var draggedGameObjectDrawer = reordering.Drawer; //if only raw GameObject references are dragged, e.g. from the hierarchy view if (draggedGameObjectDrawer == null) { var gameObjects = draggedObjects as GameObject[]; if (gameObjects != null) { var inspector = Inspector; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(reordering.MouseoveredDropTarget.Inspector == inspector); #endif //create a new GameObjectGUIInstrutions to display the dragged GameObjects var gameObjectDrawer = inspector.DrawerProvider.GetForGameObjects(inspector, gameObjects, this); if (gameObjectDrawer != null) { var setMembers = Members; DrawerArrayPool.InsertAt(ref members, dropIndex, gameObjectDrawer, false); SetMembers(setMembers, true); } } } else { var sourceParent = reordering.Parent; int sourceIndex = reordering.MemberIndex; //if reordering GameObjects within the same DrawerGroup (e.g. stacked multi-editing mode) if (sourceParent == this) { if (dropIndex != sourceIndex) { inspector.State.ViewIsLocked = true; var setMembers = Members; DrawerArrayPool.RemoveAt(ref setMembers, sourceIndex, false, false); if (sourceIndex < dropIndex) { dropIndex--; } DrawerArrayPool.InsertAt(ref setMembers, dropIndex, draggedGameObjectDrawer, false); SetMembers(setMembers); } } //if cloning (or moving?) GameObjects from one DrawerGroup to another (e.g. between split views) else { var setMembers = Members; var clone = inspector.DrawerProvider.GetForGameObjects(reordering.MouseoveredDropTarget.Inspector, draggedGameObjectDrawer.GetValues() as GameObject[], this); DrawerArrayPool.InsertAt(ref setMembers, dropIndex, clone, false); SetMembers(setMembers); } } } }
/// <inheritdoc /> protected override void DoBuildMembers() { if (ReadOnly) { DrawerArrayPool.Resize(ref members, 0); } else { DrawerArrayPool.Resize(ref members, 2); var value = Value; asString = StringUtils.TimeToString(value); int year = value.Year; int month = value.Month; int day = value.Day; int hour = value.Hour; int minute = value.Minute; float second = value.Second + value.Millisecond * 0.001f; var min = DateTime.MinValue; var max = DateTime.MaxValue; var group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Date"), false); { var groupMembers = DrawerArrayPool.Create(3); var groupMember = ClampedIntDrawer.Create(year, min.Year, max.Year, null, group, GUIContentPool.Create("Y"), false); groupMember.OnValueChanged += SetYear; groupMember.OverrideValidateValue = ValidateYear; groupMember.overrideReset = ResetToOne; groupMembers[YearMemberIndex] = groupMember; groupMember = ClampedIntDrawer.Create(month, min.Month, max.Month, null, group, GUIContentPool.Create("M"), false); groupMember.OnValueChanged += SetMonth; groupMember.OverrideValidateValue = ValidateMonth; groupMember.overrideReset = ResetToOne; groupMembers[MonthMemberIndex] = groupMember; groupMember = ClampedIntDrawer.Create(day, min.Day, max.Day, null, group, GUIContentPool.Create("D"), false); groupMember.OnValueChanged += SetDay; groupMember.OverrideValidateValue = ValidateDay; groupMember.overrideReset = ResetToOne; groupMembers[DayMemberIndex] = groupMember; group.SetMembers(groupMembers, true); members[0] = group; } group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Time"), false); { var groupMembers = DrawerArrayPool.Create(3); var groupMember = ClampedIntDrawer.Create(hour, 0, 23, null, group, GUIContentPool.Create("H"), false); groupMember.OnValueChanged += SetHour; groupMember.OverrideValidateValue = ValidateHour; groupMembers[HourMemberIndex] = groupMember; groupMember = ClampedIntDrawer.Create(minute, 0, 59, null, group, GUIContentPool.Create("M"), false); groupMember.OnValueChanged += SetMinute; groupMember.OverrideValidateValue = ValidateMinute; groupMembers[MinuteMemberIndex] = groupMember; var secondsMember = ClampedFloatDrawer.Create(second, 0f, 60f - float.Epsilon, null, group, GUIContentPool.Create("S"), false); secondsMember.OnValueChanged += SetSeconds; secondsMember.OverrideValidateValue = ValidateSecond; groupMembers[SecondMemberIndex] = secondsMember; group.SetMembers(groupMembers, true); members[1] = group; } } }
/// <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() { DrawerArrayPool.Resize(ref members, 1); members[0] = ObjectReferenceDrawer.Create(Value, Types.MonoScript, this, GUIContent.none, false, false, ReadOnly); }
/// <inheritdoc /> protected override void DoBuildMembers() { int count = memberBuildList.Count; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(count == parameterInfos.Length, "memberBuildList.Count=" + memberBuildList.Count + " != " + parameterInfos.Length); #endif #if DEV_MODE Debug.Log("ParameterDrawer.DoBuildMembers called with parameterInfos.Length=" + parameterInfos.Length + ", memberBuildList.Count=" + memberBuildList.Count + ", drawInSingleRow=" + drawInSingleRow); #endif DrawerArrayPool.Resize(ref members, count); //If only has one parameter, can be drawn in a single row if (drawInSingleRow) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(memberBuildList.Count == 1); Debug.Assert(parameterInfos.Length == 1); #endif var memberFieldInfo = memberBuildList[0]; var parameterInfo = memberFieldInfo.ParameterInfo; var type = GetParameterTypeAndLabel(memberFieldInfo, ref label); var member = DrawerProvider.GetForField(ParameterValues.GetValue(parameterInfo), type, memberFieldInfo, this, GUIContent.none, ReadOnly); #if DEV_MODE || SAFE_MODE if (member == null) { Debug.LogError(ToString() + " Failed to create Drawer for member " + memberFieldInfo + " of type " + StringUtils.ToString(type) + ".\nparent=" + StringUtils.ToString(parent)); DrawerArrayPool.Resize(ref members, 0); return; } #endif //can't draw the member in a single row after all! if (!DrawerUtility.CanDrawInSingleRow(member)) { drawInSingleRow = false; member.Dispose(); DoBuildMembers(); return; } members[0] = member; } else { for (int n = count - 1; n >= 0; n--) { var memberFieldInfo = memberBuildList[n]; var parameterInfo = memberFieldInfo.ParameterInfo; var memberLabel = GUIContentPool.Empty(); var type = GetParameterTypeAndLabel(memberFieldInfo, ref memberLabel); var member = DrawerProvider.GetForField(ParameterValues.GetValue(parameterInfo), type, memberFieldInfo, this, memberLabel, ReadOnly); #if DEV_MODE || SAFE_MODE if (member == null) { for (int d = count - 1; d > n; d--) { members[d].Dispose(); } Debug.LogError(ToString() + " Failed to create Drawer for members[" + n + "] " + memberFieldInfo + " of type " + StringUtils.ToString(type) + ".\nparent=" + StringUtils.ToString(parent)); DrawerArrayPool.Resize(ref members, 0); return; } #endif members[n] = member; } } }
/// <inheritdoc/> protected override void DoBuildMembers() { #if DEV_MODE Debug.Log(ToString() + ".DoBuildMembers"); #endif int categoryCount = categorizedBuildList.Count; int newMemberCount = categoryCount; bool includeAddComponentButton = ShouldIncludeAddComponentButton(); if (includeAddComponentButton) { newMemberCount++; } if (componentsOnlyOnSomeObjectsFound) { newMemberCount++; } DrawerArrayPool.Resize(ref members, newMemberCount); int index = 0; var readOnly = ReadOnly; foreach (var categoryAndComponents in categorizedBuildList) { var category = categoryAndComponents.Key; var categoryComponents = categoryAndComponents.Value; int categoryMemberCount = categoryComponents.Count; if (category.Length == 0) { int increaseMemberCount = categoryMemberCount - 1; if (increaseMemberCount > 0) { newMemberCount += increaseMemberCount; DrawerArrayPool.Resize(ref members, newMemberCount); } for (int n = 0; n < categoryMemberCount; n++) { var memberComponents = categoryComponents[n]; var componentDrawer = DrawerProvider.GetForComponents(inspector, memberComponents, this); members[index] = componentDrawer; index++; } } else { var categoryDrawer = CategorizedComponentsDrawer.Create(this, GUIContentPool.Create(category)); var setMembers = DrawerArrayPool.Create(categoryMemberCount); for (int n = 0; n < categoryMemberCount; n++) { var memberComponents = categoryComponents[n]; var componentDrawer = DrawerProvider.GetForComponents(inspector, memberComponents, categoryDrawer); setMembers[n] = componentDrawer; } categoryDrawer.SetMembers(setMembers, true); members[index] = categoryDrawer; index++; } } if (componentsOnlyOnSomeObjectsFound) { members[index] = GameObjectBoxDrawer.Create(this, GUIContentPool.Create("Components found only on some selected objects can't be multi-edited.")); index++; } if (includeAddComponentButton) { members[index] = AddComponentButtonDrawer.Create(this, inspector); } }
protected CategorizedComponentsDrawer GetOrCreateCategoryDrawer(string category) { if (category.Length == 0) { #if DEV_MODE && DEBUG_ADD_COMPONENT Debug.Log(ToString() + ".GetOrCreateCategoryDrawer(" + StringUtils.ToString(category) + "): returning null"); #endif return(null); } // try to find existing CategorizedComponentsDrawer for (int n = members.Length - LastCollectionMemberCountOffset; n >= 0; n--) { var member = members[n]; if (string.Equals(member.Name, category, StringComparison.OrdinalIgnoreCase)) { var existingCategoryDrawer = member as CategorizedComponentsDrawer; if (existingCategoryDrawer != null) { #if DEV_MODE && DEBUG_ADD_COMPONENT Debug.Log(ToString() + ".GetOrCreateCategoryDrawer(" + StringUtils.ToString(category) + "): existing found @ members[" + n + "]"); #endif return(existingCategoryDrawer); } } } // create new CategorizedComponentsDrawer #if DEV_MODE && PI_ASSERTATIONS int assertCount = members.Length + 1; #endif var newCategoryDrawer = CategorizedComponentsDrawer.Create(this, GUIContentPool.Create(category)); var setMembers = members; // insert new category drawer at the end, but before the add component button int insertAt = setMembers.Length - LastCollectionMemberCountOffset + 1; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(insertAt <= setMembers.Length); Debug.Assert(insertAt >= 0); #endif DrawerArrayPool.InsertAt(ref setMembers, insertAt, newCategoryDrawer, false); #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(!setMembers.ContainsNullMembers()); Debug.Assert(!members.ContainsNullMembers()); Debug.Assert(!visibleMembers.ContainsNullMembers()); Debug.Assert(Array.IndexOf(setMembers, newCategoryDrawer) == insertAt); #endif SetMembers(setMembers); #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(members.Length == assertCount); Debug.Assert(setMembers.Length == assertCount); Debug.Assert(Array.IndexOf(members, newCategoryDrawer) == insertAt); #endif #if DEV_MODE && DEBUG_ADD_COMPONENT Debug.Log(ToString() + ".GetOrCreateCategoryDrawer(" + StringUtils.ToString(category) + "): created new and added @ members[" + insertAt + "]. members now:\n" + StringUtils.TypesToString(members, "\n")); #endif return(newCategoryDrawer); }