private void DrawRuntimeObject(Rect position, RuntimeSerializedObject runtimeSerializedObject) { var prop = runtimeSerializedObject.GetIterator(); var height = RuntimeEasyGUI.GetSinglePropertyHeight(prop, new GUIContent(prop.DisplayName)); var headerPosition = new Rect(position.x, position.y, position.width, height); headerPosition.xMin += Space; prop.IsExpanded = EditorGUI.Foldout(headerPosition, prop.IsExpanded, prop.DisplayName); RuntimeEasyGUI.PropertyField(headerPosition, prop, null); if (prop.IsExpanded) { var y = RuntimeEasyGUI.GetPropertyHeight(prop, null); EditorGUI.indentLevel++; while (prop.NextVisible(false)) { var mainPosition = new Rect(position.x, position.y + y, position.width, height); mainPosition.xMin += Space; height = RuntimeEasyGUI.GetPropertyHeight(prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null); RuntimeEasyGUI.PropertyField(mainPosition, prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null); y += height; } EditorGUI.indentLevel--; } }
private float GetRuntimeObjectHeight(RuntimeSerializedObject runtimeSerializedObject) { var height = 0f; var prop = runtimeSerializedObject.GetIterator(); height += RuntimeEasyGUI.GetSinglePropertyHeight(prop, new GUIContent(prop.DisplayName)); if (prop.IsExpanded) { while (prop.NextVisible(false)) { height += RuntimeEasyGUI.GetPropertyHeight(prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null); } } return(height); }
private static RuntimeSerializedObject GetRuntimeSerializedObject(object obj, object target, int id) { if (RuntimeSerializedObjectDict.ContainsKey(id)) { return(RuntimeSerializedObjectDict[id]); } var runtimeSerializedObject = new RuntimeSerializedObject(obj, target, id); RuntimeSerializedObjectDict.Add(id, runtimeSerializedObject); //Debug.Log("Cached RuntimeSerializedObjects : " + RuntimeSerializedObjectDict.Count); //foreach (var kvp in RuntimeSerializedObjectDict) //{ // Debug.Log(kvp.Key + " : " + kvp.Value.Name); //} return(runtimeSerializedObject); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { var height = 0f; if (string.IsNullOrEmpty(property.stringValue)) { height += EditorGUIUtility.singleLineHeight; } else { runtimeSerializedObject = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(property); height += GetRuntimeObjectHeight(); } return(height); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (string.IsNullOrEmpty(property.stringValue)) { var style = new GUIStyle(); style.richText = true; EditorGUI.LabelField(position, "<color=red>Missing</color>", style); } else { runtimeSerializedObject = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(property); DrawRuntimeObject(position); runtimeSerializedObject.ApplyModifiedProperties(); } }
public RuntimeNativeSerializedProperty(RuntimeSerializedObject runtimeSerializedObject, FieldInfo propertyField, System.Type type, string propertyPath, string name, int depth, System.Func <object> getValueCallback, System.Action <object> setValueCallback) { Editable = true; RuntimeSerializedObject = runtimeSerializedObject; PropertyType = type; PropertyPath = propertyPath; Name = name; DisplayName = name; DisplayName = Regex.Replace(DisplayName, UppercasePattern, match => { var str = match.ToString(); return(char.ToUpperInvariant(str[0]) + str.Substring(1)); }); DisplayName = Regex.Replace(DisplayName, SeparatePattern, match => { var str = match.ToString(); return(str + SpaceStr); }); Depth = depth; Type = type.ToString(); this.GetValueCallback += getValueCallback; this.SetValueCallback += setValueCallback; if (propertyField != null) { var attrs = propertyField.GetCustomAttributes(typeof(FixedBufferAttribute), false); if (attrs != null && attrs.Length > 0) { var attr = (FixedBufferAttribute)attrs[0]; var property = new RuntimeNativeSerializedProperty(RuntimeSerializedObject, null, RuntimeSerializedPropertyType.FixedBufferSize, string.Format(CombinePathLayout, PropertyPath, SizeStr), SizeStr, Depth + 1, () => { return(attr.Length); }, null); IsFixedBuffer = true; property.Editable = false; property.IsFixedBuffer = true; Properties = new List <RuntimeNativeSerializedProperty>() { property }; VisibleProperties = new List <RuntimeNativeSerializedProperty>() { property }; var elementType = attr.ElementType; for (int i = 0; i < attr.Length; i++) { var index = i; var elementName = string.Format(CombineNameLayout, ElementStr, i); var element = new RuntimeNativeSerializedProperty(RuntimeSerializedObject, null, elementType, string.Format(CombinePathLayout, PropertyPath, elementName), elementName, Depth + 1, () => { return(FixedBufferUtility.GetValue(Value, attr, index)); }, (val) => { Value = FixedBufferUtility.SetValue(Value, PropertyType, attr, index, val); }); Properties.Add(element); VisibleProperties.Add(element); } } } if (!IsFixedBuffer && PropertyType.HasChildren()) { var fields = PropertyType.GetAllInstanceFieldsFromCached(); if (fields != null) { Properties = new List <RuntimeNativeSerializedProperty>(); foreach (var field in fields) { var property = new RuntimeNativeSerializedProperty(RuntimeSerializedObject, field, field.FieldType, string.Format(CombinePathLayout, PropertyPath, field.Name), field.Name, Depth + 1, () => { return(field.GetValue(Value)); }, (val) => { var obj = Value; field.SetValue(obj, val); Value = obj; }); Properties.Add(property); if (field.IsVisible()) { if (VisibleProperties == null) { VisibleProperties = new List <RuntimeNativeSerializedProperty>(); } VisibleProperties.Add(property); } } } } if (IsArray) { ArraySizeChanged += OnArraySizeChanged; var property = new RuntimeNativeSerializedProperty(RuntimeSerializedObject, null, RuntimeSerializedPropertyType.ArraySize, string.Format(CombinePathLayout, PropertyPath, SizeStr), SizeStr, Depth + 1, () => { return((int)getCountMethod.Invoke(Value, null)); }, (val) => { ArraySizeChanged.Invoke((int)val); }); property.ArraySizeChanged += OnArraySizeChanged; foreach (var method in PropertyType.GetMethods()) { if (PropertyType.IsArray) { if (method.Name.ToLower() == Get_LengthStr) { getCountMethod = method; property.getCountMethod = method; } else if (method.Name.ToLower() == GetStr) { getMethod = method; property.getMethod = method; } else if (method.Name.ToLower() == SetStr) { setMethod = method; property.setMethod = method; } } else { if (method.Name.ToLower() == Get_CountStr) { getCountMethod = method; property.getCountMethod = method; } else if (method.Name.ToLower() == Get_ItemStr) { getMethod = method; property.getMethod = method; } else if (method.Name.ToLower() == Set_ItemStr) { setMethod = method; property.setMethod = method; } else if (method.Name.ToLower() == AddStr) { addMethod = method; property.addMethod = method; } else if (method.Name.ToLower() == RemoveRangeStr) { removerangeMethod = method; property.removerangeMethod = method; } } } Properties = new List <RuntimeNativeSerializedProperty>() { property }; VisibleProperties = new List <RuntimeNativeSerializedProperty>() { property }; ApplyModifiedArray(); } }