/// <summary> /// Generate an the animator contoller. /// </summary> /// <returns>The animator contoller.</returns> /// <param name="triggersProperty">Triggers property.</param> /// <param name="preferredName">Preferred name.</param> public static UnityEditor.Animations.AnimatorController GenerateAnimatorContoller(SerializedProperty triggersProperty, string preferredName) { // Prepare the triggers list List<string> triggersList = new List<string>(); SerializedProperty serializedProperty = triggersProperty.Copy(); SerializedProperty endProperty = serializedProperty.GetEndProperty(); while (serializedProperty.NextVisible(true) && !SerializedProperty.EqualContents(serializedProperty, endProperty)) { triggersList.Add(!string.IsNullOrEmpty(serializedProperty.stringValue) ? serializedProperty.stringValue : serializedProperty.name); } // Generate the animator controller return UIAnimatorControllerGenerator.GenerateAnimatorContoller(triggersList, preferredName); }
/// <summary> /// Populate a reference map that goes SerializedProperty -> Object /// </summary> /// <param name="map">The map to populate entries into</param> /// <param name="allObjects">The objects to read in order to determine the references</param> private static void PopulateReferenceMap( List<KeyValuePair<SerializedProperty, Object>> map, IEnumerable<Object> allObjects ) { var unityEditorAssembly = typeof(UnityEditor.EditorApplication).Assembly; var userEditorAssembly = typeof(AmsCrossSceneReferenceProcessor).Assembly; foreach( var obj in allObjects ) { // Flags that indicate we aren't rooted in the scene if ( obj.hideFlags == HideFlags.HideAndDontSave ) continue; // Don't deal with any editor classes var assembly = obj.GetType().Assembly; if ( assembly == unityEditorAssembly || assembly == userEditorAssembly ) continue; SerializedObject so = new SerializedObject(obj); SerializedProperty sp = so.GetIterator(); bool bCanDispose = true; while ( sp.Next(true) ) { // Only care about object references if ( sp.propertyType != SerializedPropertyType.ObjectReference ) continue; // Skip the nulls if ( sp.objectReferenceInstanceIDValue == 0 ) continue; map.Add( new KeyValuePair<SerializedProperty,Object>(sp.Copy(), sp.objectReferenceValue) ); bCanDispose = false; } // This will help relieve memory pressure (thanks llde_chris) if ( bCanDispose ) { sp.Dispose(); so.Dispose(); } } }
bool TryUpdatePreNormalizedValues() { var iterator = m_VectorProperty.Copy(); var parentPath = m_VectorProperty.propertyPath; var i = 0; while (iterator.Next(true) && iterator.propertyPath.StartsWith(parentPath)) { if (i >= m_PreNormalizedValues.Length || iterator.propertyType != SerializedPropertyType.Float) { return(false); } m_PreNormalizedValues[i] = new KeyValuePair <string, double?>( iterator.propertyPath.Substring(parentPath.Length + 1), iterator.hasMultipleDifferentValues ? (double?)null : iterator.doubleValue ); ++i; } return(true); }
protected virtual void RecursiveProperty(SerializedProperty root) { var depth = root.depth; var iterator = root.Copy(); for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) { if (iterator.depth < depth) { // 前の要素よりも浅くなった。脱出 return; } depth = iterator.depth; using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) { EditorGUILayout.PropertyField(iterator, true); } } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { SerializedProperty origProp = property; bool backupFlag = isArrayElement; if (SerializedPropertyUtility.IsArrayElement(property)) { isArrayElement = true; arrayElementIndex = SerializedPropertyUtility.IndexOfArrayElement(property); origProp = SerializedPropertyUtility.GetArrayParentProperty(property); } else { origProp = property.Copy(); } float height = GetPropertyHeight(property, origProp, label) + (1) + ((showDebug)? debugTool: 0); isArrayElement = backupFlag; return(height); }
public SerializedProperty GetSiblingProperty(SerializedProperty property, string Name) { if (property.name == Name) { return(property); } SerializedProperty prop = property.Copy(); int depth = prop.depth; while (prop.Next(false) && prop.depth == depth) { if (prop.name == Name) { return(prop); } } Debug.LogError("Field not found"); return(null); }
private static bool AxisIndex(string axisName) { SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); indexCount = -1; axesProperty.Next(true); axesProperty.Next(true); while (axesProperty.Next(false)) { indexCount++; SerializedProperty axis = axesProperty.Copy(); axis.Next(true); if (axis.stringValue == axisName) { return(true); } } return(false); }
public static IEnumerable <SerializedProperty> GetTopLevelProperties( this SerializedObject serializedObject, bool skipScript = true, bool copy = true) { SerializedProperty property = serializedObject.GetIterator(); if (!property.NextVisible(true)) { yield break; } do { if (skipScript && property.name == "m_Script") { skipScript = false; continue; } yield return(copy ? property.Copy() : property); } while (property.NextVisible(false)); }
private bool FindMissingProperties(Component c, List <SerializedProperty> out_missingProperties) { bool result = false; SerializedObject serializedObject = new SerializedObject(c); SerializedProperty iterator = serializedObject.GetIterator(); while (iterator.NextVisible(true)) { if ((int)iterator.propertyType == 5 && iterator.objectReferenceValue == null && ((this.m_includeMissing && iterator.objectReferenceInstanceIDValue != 0) || (this.m_includeNull && iterator.objectReferenceInstanceIDValue == 0))) { if (out_missingProperties != null) { SerializedProperty item = iterator.Copy(); out_missingProperties.Add(item); } result = true; } } return(result); }
private void DrawProperty(Rect rect, SerializedProperty parent, SerializedProperty element) { if (HasCustomPropertyDrawer(element) || element.propertyType == SerializedPropertyType.String) { DoElement(rect, parent, element); } else { var iter = element.Copy(); iter.NextVisible(true); var depth = iter.depth; rect.height = 0; do { rect.y += rect.height; rect.height = GetHeight(element, iter); DoElement(rect, element, iter); } while (iter.NextVisible(false) && iter.depth == depth); } }
private void ForeachChildProperties(SerializedProperty property, Action <SerializedProperty> childAction) { if (childAction == null) { return; } var propertyIt = property.Copy(); if (!propertyIt.NextVisible(true)) { // no child or invisible return; } do { childAction(propertyIt); } while (propertyIt.NextVisible(false)); }
public void OnValidate(SerializedProperty property) { if (_visibleDrawer is PropertyModifier) { property = property.Copy(); var modifier = _visibleDrawer as PropertyModifier; if (_visibleDrawer is IArrayHandlingPropertyDrawer || !property.isArray) { modifier.OnValidate(property); } else { for (int i = 0; i < property.arraySize; i++) { modifier.OnValidate(property.GetArrayElementAtIndex(i)); } } } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float height = EditorGUIUtility.singleLineHeight; // for the label var propCopy = property.Copy(); // don't touch the original property var endProp = propCopy.GetEndProperty(); propCopy.NextVisible(true); while (!SerializedProperty.EqualContents(propCopy, endProp)) { height += EditorGUI.GetPropertyHeight(propCopy); height += EditorGUIUtility.standardVerticalSpacing; propCopy.NextVisible(false); } propCopy.Reset(); return(height); }
/// <summary> /// Gets the height of the property. /// </summary> /// <returns>The property height.</returns> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float result = 0f; SerializedProperty childProperty = property.Copy(); childProperty.NextVisible(true); Regex match = new Regex(string.Format("^{0}(?=\\.)", Regex.Escape(property.propertyPath))); while (match.IsMatch(childProperty.propertyPath)) { result += GetChildPropertyHeight(property, childProperty.Copy()) + EditorGUIUtility.standardVerticalSpacing; childProperty.NextVisible(false); } if (result > 0f) { result -= EditorGUIUtility.standardVerticalSpacing; } return(result); }
private static VisualElement ConfigureField <TField, TValue>( TField field, SerializedProperty property) where TField : BaseField <TValue> { string str = !string.IsNullOrEmpty(property.displayName) ? property.displayName : property.name; field.bindingPath = property.propertyPath; field.name = "unity-input-" + property.propertyPath; field.label = str; Label label = field.Q <Label>(null, BaseField <TValue> .labelUssClassName); if (label != null) { label.userData = property.Copy(); } field.labelElement.AddToClassList(PropertyField.labelUssClassName); return(field); }
bool AutoPropertyField(Rect position, SerializedProperty property, SerializedProperty origProp, GUIContent label, int level, out float yMax) { bool bNextVisible = true; // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. if (!isCalcHeight) { EditorGUI.BeginProperty(new Rect(position.x, position.y, position.width, normalHeight), label, property); } bNextVisible = AutoArrayField(position, property, origProp.Copy(), label, level, out yMax); if (!isCalcHeight) { EditorGUI.EndProperty(); } return(bNextVisible); }
/// <summary> /// Determines if an axis entry already exists /// </summary> /// <param name="axisName"></param> /// <returns></returns> public static bool IsDefined(string rName) { SerializedObject lSerializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); SerializedProperty lProperty = lSerializedObject.FindProperty("m_Axes"); lProperty.Next(true); lProperty.Next(true); while (lProperty.Next(false)) { SerializedProperty lAxis = lProperty.Copy(); lAxis.Next(true); if (lAxis.stringValue == rName) { return(true); } } return(false); }
private float GetFullHeight(SerializedProperty parent, SerializedProperty element) { var height = 0f; if (HasCustomPropertyDrawer(element) || element.propertyType == SerializedPropertyType.String) { height += GetHeight(parent, element); } else { var iter = element.Copy(); iter.NextVisible(true); var depth = iter.depth; do { height += GetHeight(element, iter); } while (iter.NextVisible(false) && iter.depth == depth); } return(height); }
public static void TryDrawPropertyField(Rect position, SerializedProperty property, GUIContent displayName, bool drawObjectReference = false) { position.height = GetObjectReferenceHeight(property, drawObjectReference); if (TryDrawObjectReference(position, property, displayName, drawObjectReference)) { } else { if (property.hasVisibleChildren && displayName == GUIContent.none) { var iterProp = property.Copy(); if (iterProp.NextVisible(true)) { int depth = iterProp.depth; do { if (depth != iterProp.depth) { break; } var label = new GUIContent(iterProp.displayName); position.yMin += position.height; position.height = GetObjectReferenceHeight(iterProp, drawObjectReference); if (TryDrawObjectReference(position, iterProp, label, drawObjectReference)) { } else { position.height = EditorGUI.GetPropertyHeight(iterProp, label, iterProp.isExpanded); EditorGUI.PropertyField(position, iterProp, label, iterProp.isExpanded); } } while (iterProp.NextVisible(false)); } } else { position.height = EditorGUI.GetPropertyHeight(property, displayName, property.isExpanded); EditorGUI.PropertyField(position, property, displayName, property.isExpanded); } } }
private VisualElement ConfigureField <TField, TValue>(TField field, SerializedProperty property) where TField : BaseField <TValue> { var fieldLabel = string.IsNullOrEmpty(label) ? property.localizedDisplayName : label; field.bindingPath = property.propertyPath; field.name = "unity-input-" + property.propertyPath; field.label = fieldLabel; var fieldLabelElement = field.Q <Label>(className: BaseField <TValue> .labelUssClassName); if (fieldLabelElement != null) { fieldLabelElement.userData = property.Copy(); fieldLabelElement.RegisterCallback <MouseUpEvent>(RightClickMenuEvent); } field.labelElement.AddToClassList(labelUssClassName); field.visualInput.AddToClassList(inputUssClassName); return(field); }
private bool AxisDefined(string axisName) { if (serializedObject == null) { serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]); } SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes"); axesProperty.Next(true); axesProperty.Next(true); while (axesProperty.Next(false)) { SerializedProperty axis = axesProperty.Copy(); axis.Next(true); if (axis.stringValue == axisName) { return(true); } } return(false); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { bool original = property.isExpanded; property.isExpanded = true; SerializedProperty copy = property.Copy(); int count = copy.CountInProperty(); property.isExpanded = original; if (count <= 2 && property.hasVisibleChildren) { property.NextVisible(true); EditorGUI.PropertyField(position, property, label, true); } else { EditorGUI.PropertyField(position, property, label, true); } }
private float GetListPropertyHeight(SerializedProperty parent, SerializedProperty property) { var list = ReorderableDrawer.GetList(parent, new ReorderableAttribute { labels = false }, property.name.GetHashCode(), property.name); if (list == null) { Debug.Log(parent.propertyPath + " " + property.propertyPath); return(0f); } list.elementLabels = false; if (!listWithCallback.ContainsKey(list)) { var originalP = property.Copy(); list.drawElementCallback += (r, e, l, s, f) => List_drawElementCallback(r, originalP, e, l, s, f); list.getElementHeightCallback += (e) => List_getElementHeightCallback(originalP, e); listWithCallback.Add(list, true); } return(list.GetHeight()); }
private void drawProp(SerializedProperty prop, Rect r) { if (prop.propertyType == SerializedPropertyType.Generic) { SerializedProperty copy = prop.Copy(); SerializedProperty endProp = copy.GetEndProperty(false); copy.NextVisible(true); while (!SerializedProperty.EqualContents(copy, endProp)) { r.height = EditorGUI.GetPropertyHeight(copy); EditorGUI.PropertyField(r, copy, true); r.y += r.height; copy.NextVisible(false); } } else { r.height = EditorGUI.GetPropertyHeight(prop); EditorGUI.PropertyField(r, prop, GUIContent.none, false); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // if the property is not an expandable type, then use its default drawer if (!s_ExpandableTypes.Contains(property.propertyType)) { EditorGUI.PropertyField(position, property, label, property.hasVisibleChildren && property.isExpanded); } else { var childProperty = property.Copy(); var endProperty = property.GetEndProperty(); childProperty.NextVisible(true); while (!SerializedProperty.EqualContents(childProperty, endProperty)) { position.height = GetChildPropertyHeight(property, childProperty); DisplayChildProperty(position, property, childProperty.Copy(), null); position.y += position.height + EditorGUIUtility.standardVerticalSpacing; childProperty.NextVisible(false); } } }
private static object GetPropertyValueGeneric(SerializedProperty property) { var dict = new Dictionary <string, object>(); SerializedProperty iterator = property.Copy(); if (!iterator.Next(true)) { return(dict); } SerializedProperty end = property.GetEndProperty(); do { string name = iterator.name; object value = GetPropertyValue(iterator); dict.Add(name, value); }while (iterator.Next(false) && iterator.propertyPath != end.propertyPath); return(dict); }
/// <summary> /// Draws property's children but only one level deep. /// </summary> public static void DrawPropertyChildren(SerializedProperty property, Action <SerializedProperty> drawElementAction) { var enterChildren = true; //cache all needed property references var targetProperty = property.Copy(); var endingProperty = property.GetEndProperty(); //iterate over all children (but only 1 level depth) while (targetProperty.NextVisible(enterChildren)) { if (SerializedProperty.EqualContents(targetProperty, endingProperty)) { break; } enterChildren = false; var childProperty = targetProperty.Copy(); //handle current property using Toolbox features drawElementAction(childProperty); } }
private void DoListProperty(Rect rect, SerializedProperty parent, SerializedProperty property) { var list = ReorderableDrawer.GetList(parent, new ReorderableAttribute { labels = false }, property.name.GetHashCode(), property.name); if (list == null) { Debug.Log(parent.propertyPath + " " + property.propertyPath); return; } list.elementLabels = false; if (!listWithCallback.ContainsKey(list)) { var originalP = property.Copy(); list.drawElementCallback += (r, e, l, s, f) => List_drawElementCallback(r, property, e, l, s, f); list.getElementHeightCallback += (e) => List_getElementHeightCallback(property, e); listWithCallback.Add(list, true); } list.DoList(rect, new GUIContent(property.displayName)); }
public static SerializedProperty[] GetChildProperties(this SerializedProperty property, bool visibleOnly, bool enterChildren) { SerializedProperty copy = property.Copy(); SerializedProperty endProperty = copy.GetEndProperty(true); List <SerializedProperty> childProperties = new List <SerializedProperty>(); bool enter = true; while (visibleOnly ? copy.NextVisible(enter) : copy.Next(enter)) { if (SerializedProperty.EqualContents(copy, endProperty)) { break; } enter = enterChildren; childProperties.Add(copy.Copy()); } return(childProperties.ToArray()); }
/// <summary> /// Raises the GUI event. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> /// <param name="label">Label.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // if the property is not an expandable type, then use its default drawer if (!s_ExpandableTypes.Contains(property.propertyType)) { EditorGUI.PropertyField(position, property, label, property.hasVisibleChildren && property.isExpanded); } else { SerializedProperty childProperty = property.Copy(); childProperty.NextVisible(true); Regex match = new Regex(string.Format("^{0}(?=\\.)", Regex.Escape(property.propertyPath))); while (match.IsMatch(childProperty.propertyPath)) { position.height = GetChildPropertyHeight(property, childProperty); DisplayChildProperty(position, property, childProperty.Copy(), null); position.y += position.height + EditorGUIUtility.standardVerticalSpacing; childProperty.NextVisible(false); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); property = property.Copy(); var pathStart = $"{property.propertyPath}."; if (property.NextVisible(true) && property.propertyPath.StartsWith(pathStart)) { do { position.height = EditorGUI.GetPropertyHeight(property, true); EditorGUI.PropertyField(position, property, true); position.y += position.height + heightMargin; }while (property.NextVisible(false) && property.propertyPath.StartsWith(pathStart)); } EditorGUI.EndProperty(); }