void OnTextFieldValueChange(ChangeEvent <string> evt) { value = evt.newValue; evt.StopImmediatePropagation(); evt.PreventDefault(); }
void OnPopupFieldValueChange(ChangeEvent <string> evt) { // There's a bug in UIE that makes the PopupField send a ChangeEvent<string> even // if you called SetValueWithoutNotify(). It's the PopupTextElement.text that // sends it. Hence, this check. if (evt.leafTarget != optionsPopup) { evt.StopImmediatePropagation(); evt.PreventDefault(); return; } value = evt.newValue; evt.StopImmediatePropagation(); evt.PreventDefault(); }
private void UpdateList(ChangeEvent <int> changeEvent) { ListElement.Unbind(); ListElement.ListProperty.serializedObject.UpdateIfRequiredOrScript(); ListElement.ListProperty.serializedObject.ApplyModifiedProperties(); ListElement.Bind(ListElement.ListProperty.serializedObject); changeEvent.StopImmediatePropagation(); }
void CountChanged(ChangeEvent <int> evt) { evt.StopImmediatePropagation(); evt.PreventDefault(); var count = evt.newValue; if (count < 0) { m_Size.SetValueWithoutNotify(0); count = 0; } var iList = GetValue(); if (null == iList) { return; } var constructContext = GetAttribute <CreateElementOnAddAttribute>(); switch (iList) { case TElement[] array: var newArray = new TElement[count]; for (var i = 0; i < Math.Min(array.Length, count); ++i) { newArray[i] = array[i]; } for (var i = array.Length; i < newArray.Length; ++i) { newArray[i] = CreateInstance(constructContext); } Root.SetValue(Path, newArray); break; case List <TElement> list: while (list.Count > count) { list.RemoveAt(list.Count - 1); } while (list.Count < count) { list.Add(CreateInstance(constructContext)); } break; } Root.NotifyChanged(Path); Reload(); }
private void UpdateArrayFoldout( ChangeEvent <int> changeEvent, PropertyField targetPropertyField, PropertyField parentPropertyField) { if (targetPropertyField == null || targetPropertyField.m_SerializedProperty == null) { return; } // We need to unbind *first* before we change the array size property value. // If we don't, the binding system could try to sync properties that no longer // exist - if the array shrunk. var parentSerializedObject = parentPropertyField?.m_SerializedProperty?.serializedObject; if (parentSerializedObject != null) { parentPropertyField.Unbind(); } // We're forcefully updating the SerializedProperty value here, even // though we have a binding on it, because the very next step is to // Rebind() it. The Rebind() will regenerate the field (this field) and // bind it to another copy of this property. We need the value to be correct // on that copy of this property. var serialiedObject = targetPropertyField.m_SerializedProperty.serializedObject; serialiedObject.UpdateIfRequiredOrScript(); targetPropertyField.m_SerializedProperty.intValue = changeEvent.newValue; serialiedObject.ApplyModifiedProperties(); // We rebind the parent property field (which should be the foldout expanded field) // so that it regenerates (and rebinds) all array property fields (the new // number of them). if (parentSerializedObject != null) { parentPropertyField.Bind(parentSerializedObject); } // Very important that we stop immediate propagation here. If we don't, // the next handler will be FieldValueChanged() in the IBinding which // will be operating on a stale [this target] field // (we just killed it in our Unbind()/Bind() above). // In turn, because we share the IBinding, this event handling will // essentially call Unbind() one more time on the array size field // [this.target] and the array size field will no longer work. // See: case 1141787 changeEvent.StopImmediatePropagation(); }
void OnObjectValueChange(ChangeEvent <Object> evt) { value = evt.newValue; evt.StopImmediatePropagation(); evt.PreventDefault(); }