public static bool Load([NotNull] this SerializedPropertyStorage obj, BinaryReader reader) { obj.StorageSize = reader.ReadInt32(); if (obj.StorageSize == 0) { return(true); } obj.Version = reader.ReadInt32(); obj.FormatID = reader.ReadGuid(); var ok = true; while (true) { // TODO // Error tolerance: // To be error tolerant, we will behave as if the binary sequence // was a string and we were to apply the following regex: // ^(ByName|ById)*$ // This means that we will backtrack to try to find alternatives. // At this moment what we have is: // - No backtracking // - Test by name, and if it fails, read by id var namedValue = new SerializedPropertyValueByName(); var ok2 = namedValue.Load(reader); SerializedPropertyValue value = namedValue; if (!ok2) { var identifiedValue = new SerializedPropertyValueById(); ok2 = identifiedValue.Load(reader); value = identifiedValue; } ok &= ok2; obj.SerializedPropertyValues.Add(value); if (value.ValueSize == 0) { break; } } return(ok); }
public static string DrawCopyPasteButtonArray(Rect p_position, SerializedProperty p_property) { string _click = ""; p_position.width = p_position.width / 2; if (GUI.Button(p_position, "Copy All")) { CopyPasteAttribute.sourceSerializedProperty = p_property; // // string _type = CopyPasteAttribute.sourceSerializedProperty.GetType().Name; // Debug.Log(p_property.arraySize); // if(_type == "Object[]"){ CopyPasteAttribute.sourceSerializedProperty = p_property; CopyPasteAttribute.propertyObj = p_property.serializedObject.targetObject; CopyPasteAttribute.propertyPath = p_property.propertyPath; // }else{ // CopyPasteAttribute.propertyObj = null; // CopyPasteAttribute.propertyPath = ""; // } CopyPasteAttribute.isArray = true; _click = "Copy"; } p_position.x += p_position.width; if ((CopyPasteAttribute.sourceSerializedProperty != null) && (CopyPasteAttribute.isArray)) { if (GUI.Button(p_position, "Paste All")) { if (CopyPasteAttribute.propertyObj != null) { CopyPasteAttribute.sourceSerializedProperty = GetSerializedProperty(CopyPasteAttribute.propertyObj, CopyPasteAttribute.propertyPath); } SerializedPropertyValue.SetValue( p_property, SerializedPropertyValue.GetValue( CopyPasteAttribute.sourceSerializedProperty ) ); _click = "Paste"; } } else { GUI.enabled = false; GUI.Button(p_position, "Paste All"); GUI.enabled = true; } return(_click); }
public override float GetPropertyHeight(SerializedProperty p_property, GUIContent p_label) { string _path = p_property.propertyPath; bool _isFirst = _path.EndsWith(".data[0]"); float _height = SerializedPropertyValue.GetPropertyHeight(p_property, p_label); if (_isFirst) { return(_height + 18); } else { return(_height); } }
public static float GetPropertyHeight(SerializedProperty p_property, GUIContent p_label) { float _height = EditorGUIUtility.singleLineHeight; if (p_property.isExpanded) { IEnumerator _enumerator = p_property.GetEnumerator(); SerializedProperty _nowProperty; string _hideProperty = ""; while (_enumerator.MoveNext()) { _nowProperty = (SerializedProperty)_enumerator.Current; // if((_nowProperty.propertyType == SerializedPropertyType.String) && (_nowProperty.stringValue == "@@@")){ // Debug.Log(""); // } string _nowPath = _nowProperty.propertyPath; if ((_hideProperty != "") && _nowPath.Contains(_hideProperty)) { continue; } else { _hideProperty = ""; } if (_nowProperty.isExpanded) { _hideProperty = ""; } else { _hideProperty = _nowPath + "."; } _height += SerializedPropertyValue.GetPropertyHeight(_nowProperty, GUIContent.none) + 2; } } return(_height); }
public override void OnGUI(Rect p_position, SerializedProperty p_property, GUIContent p_Label) { string _path = p_property.propertyPath; bool _isFirst = _path.EndsWith(".data[0]"); if (_isFirst) { Rect _butRect = new Rect(p_position); int _indent = EditorGUI.indentLevel * 15; _butRect.height = 16; _butRect.x += _indent; _butRect.width -= _indent + 160; GUI.Label(_butRect, " CopyPaste-Array"); _butRect.x += _butRect.width; _butRect.width = 160; SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property); SerializedPropertyValue.DrawCopyPasteArray(_butRect, _parentProperty); p_position.y += 18; } CopyPasteAttribute _copyPaste = attribute as CopyPasteAttribute; Rect _copyPasteRect = new Rect(p_position); _copyPasteRect.x += p_position.width - 120; _copyPasteRect.width = 120; _copyPasteRect.height = 18; SerializedPropertyValue.DrawCopyPaste(_copyPasteRect, p_property); if ((p_property.propertyType == SerializedPropertyType.Generic) || (p_property.isArray && (p_property.propertyType != SerializedPropertyType.String))) { EditorGUI.PropertyField(p_position, p_property, true); } else { p_position.width -= 120; EditorGUI.PropertyField(p_position, p_property); } }
public override void OnGUI(Rect p_position, SerializedProperty p_property, GUIContent p_Label) { object _obj = SerializedPropertyValue.GetValue(p_property); LessAlarmAttribute _Alarm = attribute as LessAlarmAttribute; if (SerializedPropertyValue.isNumber(p_property)) { float _number; if (p_property.propertyType == SerializedPropertyType.Float) { _number = (float)_obj; } else { _number = (int)_obj; } if (_number < _Alarm.floatTarget) { GUI.color = Color.red; if (_Alarm.floatNow != _number) { MonoBehaviour _Mono = (MonoBehaviour)p_property.serializedObject.targetObject; if (_Alarm.log) { Debug.LogWarning("Attribute Alarm: " + _Mono.name + " / " + p_property.name + " = " + _number + " , Less: " + _Alarm.floatTarget); } if (_Alarm.pause) { Debug.Break(); } } } _Alarm.floatNow = _number; EditorGUI.PropertyField(p_position, p_property, p_Label); GUI.color = Color.white; } else { EditorGUI.LabelField(p_position, p_Label.text, "[LessAlarm] Only for Number"); } }
public override float GetPropertyHeight(SerializedProperty p_property, GUIContent p_label) { string _path = p_property.propertyPath; float _height = 0; ReorderableListAttribute _reorderableList = attribute as ReorderableListAttribute; bool _isFirst = _path.EndsWith(".data[0]"); bool _isLast = false; if (_reorderableList.list != null) { _isLast = _path.EndsWith(".data[" + (_reorderableList.list.count - 1) + "]"); } if (useOrder && (_reorderableList.list != null)) { if (_isFirst) { _height = _reorderableList.list.GetHeight() + 18; } else { _height = -2; } } else { _height = SerializedPropertyValue.GetPropertyHeight(p_property, p_label); } if ((_reorderableList.list != null) && !useOrder && _isLast) { return(_height + 18); } else { return(_height); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType == SerializedPropertyType.Integer) { position.height /= 2; FlagAttribute _Flag = attribute as FlagAttribute; EditorGUI.PropertyField(position, property, label); position.y += position.height; if (_Flag.itemStrs == null && _Flag.strName != "") { SerializedProperty _itemStrsProperty = property.serializedObject.FindProperty(_Flag.strName); if (_itemStrsProperty != null) { _Flag.itemStrs = SerializedPropertyValue.GetArray <string>(_itemStrsProperty); } else { EditorGUI.LabelField(position, label.text, "Property : \"" + _Flag.strName + "\" Not Found"); return; } } if (_Flag.itemStrs == null) { EditorGUI.LabelField(position, label.text, "Property : \"" + _Flag.strName + "\" Not String Array"); } else { property.intValue = ExtendGUI.Flag(position, property.intValue, _Flag.itemStrs); } } else { EditorGUI.LabelField(position, label.text, "[Flag] Only for Int"); } }
public static object GetValue(SerializedProperty p_property) { // Debug.Log("Get : " + p_Property.propertyType.ToString() + " isArray:" + p_Property.isArray.ToString()); if (p_property.isArray) { if (p_property.propertyType == SerializedPropertyType.String) { return(p_property.stringValue); } else { return(GetArray <object>(p_property)); } } else { switch (p_property.propertyType) { case SerializedPropertyType.Integer: return(p_property.intValue); case SerializedPropertyType.Boolean: return(p_property.boolValue); case SerializedPropertyType.Float: return(p_property.floatValue); case SerializedPropertyType.String: return(p_property.stringValue); case SerializedPropertyType.Color: return(p_property.colorValue); case SerializedPropertyType.Gradient: return(GetValue <Gradient>(p_property, "gradientValue")); case SerializedPropertyType.ObjectReference: return(p_property.objectReferenceValue); case SerializedPropertyType.LayerMask: return(p_property.intValue); case SerializedPropertyType.Enum: return(p_property.enumValueIndex); case SerializedPropertyType.Vector2: return(p_property.vector2Value); case SerializedPropertyType.Vector3: return(p_property.vector3Value); case SerializedPropertyType.Rect: return(p_property.rectValue); case SerializedPropertyType.ArraySize: SerializedProperty _parent = SerializedPropertyValue.GetParent(p_property); return(_parent.arraySize); case SerializedPropertyType.Character: return((char)p_property.intValue); case SerializedPropertyType.AnimationCurve: return(p_property.animationCurveValue); case SerializedPropertyType.Bounds: return(p_property.boundsValue); case SerializedPropertyType.Quaternion: return(p_property.quaternionValue); case SerializedPropertyType.Generic: return(p_property.Copy()); default: Debug.LogError("Not support this type : " + p_property.propertyType.ToString()); return(null); } } }
public static void SetValue(SerializedProperty p_targetProperty, object p_sourceObj) { if (p_targetProperty.isArray) { if (p_targetProperty.propertyType == SerializedPropertyType.String) { p_targetProperty.stringValue = (string)p_sourceObj; } else { object[] _targetArr = ObjToArray(p_sourceObj); if (_targetArr != null) { int f; int len = _targetArr.Length; p_targetProperty.ClearArray(); for (f = 0; f < len; f++) { p_targetProperty.InsertArrayElementAtIndex(f); SerializedProperty _targetProperty = p_targetProperty.GetArrayElementAtIndex(f); SetValue(_targetProperty, _targetArr[f]); } } else { Debug.LogError("SetValue Type Wrong"); } } } else { try{ switch (p_targetProperty.propertyType) { case SerializedPropertyType.Integer: p_targetProperty.intValue = (int)p_sourceObj; break; case SerializedPropertyType.String: p_targetProperty.stringValue = (string)p_sourceObj; break; case SerializedPropertyType.Boolean: p_targetProperty.boolValue = (bool)p_sourceObj; break; case SerializedPropertyType.Float: p_targetProperty.floatValue = (float)p_sourceObj; break; case SerializedPropertyType.Enum: p_targetProperty.enumValueIndex = (int)p_sourceObj; break; case SerializedPropertyType.LayerMask: p_targetProperty.intValue = (int)p_sourceObj; break; case SerializedPropertyType.ObjectReference: p_targetProperty.objectReferenceValue = (Object)p_sourceObj; break; case SerializedPropertyType.Color: p_targetProperty.colorValue = (Color)p_sourceObj; break; case SerializedPropertyType.Gradient: SetValue <Gradient>(p_targetProperty, "gradientValue", (Gradient)p_sourceObj); break; case SerializedPropertyType.AnimationCurve: p_targetProperty.animationCurveValue = (AnimationCurve)p_sourceObj; break; case SerializedPropertyType.Rect: p_targetProperty.rectValue = (Rect)p_sourceObj; break; case SerializedPropertyType.Bounds: p_targetProperty.boundsValue = (Bounds)p_sourceObj; break; case SerializedPropertyType.Vector2: p_targetProperty.vector2Value = (Vector2)p_sourceObj; break; case SerializedPropertyType.Vector3: p_targetProperty.vector3Value = (Vector3)p_sourceObj; break; case SerializedPropertyType.Vector4: p_targetProperty.vector4Value = (Vector4)p_sourceObj; break; case SerializedPropertyType.ArraySize: SerializedProperty _parent = SerializedPropertyValue.GetParent(p_targetProperty); _parent.arraySize = (int)p_sourceObj; break; case SerializedPropertyType.Generic: SerializedProperty _sourceProperty = (SerializedProperty)p_sourceObj; SetValueByProperty(p_targetProperty, _sourceProperty.Copy()); break; default: Debug.LogError("SetValue Not support this type : " + p_targetProperty.propertyType.ToString()); break; } }catch (System.Exception e) { Debug.LogErrorFormat( "SerializedProperty SetValue Error, sourceObj is {0}, targetProperty [{1}] is {2}\n{3}", p_sourceObj.GetType().Name, p_targetProperty.name, p_targetProperty.propertyType, e.Message ); } } }
public override float GetPropertyHeight(SerializedProperty p_property, GUIContent p_label) { return(SerializedPropertyValue.GetPropertyHeight(p_property, p_label)); }
public override void OnGUI(Rect p_position, SerializedProperty p_property, GUIContent p_label) { string _path = p_property.propertyPath; if (!_path.EndsWith("]")) { EditorGUI.LabelField(p_position, p_label.text, "[ReorderableList] Only for Array Or Collection"); return; } ReorderableListAttribute _reorderableList = attribute as ReorderableListAttribute; bool _isFirst = _path.EndsWith(".data[0]"); if (_reorderableList.list != null) { if (_isFirst) { Rect _butRect = new Rect(p_position); int _indent = EditorGUI.indentLevel * 15; _butRect.height = 16; if (useOrder) { _butRect.x += _indent + 70; _butRect.width -= _indent + 70 + 160; if (GUI.Button(_butRect, "Finish Reorder")) { useOrder = false; } } else { _butRect.x += _indent; _butRect.width -= _indent + 160; if (GUI.Button(_butRect, "Start Reorder")) { useOrder = true; } } _butRect.x += _butRect.width; _butRect.width = 160; SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property); SerializedPropertyValue.DrawCopyPasteArray(_butRect, _parentProperty); } } SerializedObject _serializedObject = p_property.serializedObject; if (_isFirst) { if (_reorderableList.list == null) { SerializedProperty _parentProperty = SerializedPropertyValue.GetParent(p_property); _reorderableList.list = ReorderableListUtility.CreateAutoLayout(_parentProperty, 4, SerializedPropertyValue.DrawCopyPasteBehind); } } if (useOrder) { if (_isFirst) { p_position.width -= 120; ReorderableListUtility.DoListWithFoldout(_reorderableList.list, p_position); } } else { p_position.y += 16; Rect _copyPasteRect = new Rect(p_position); _copyPasteRect.x += p_position.width - 120; _copyPasteRect.width = 120; _copyPasteRect.height = 18; string _click = SerializedPropertyValue.DrawCopyPasteButton(_copyPasteRect, p_property); if (_click != "") { } else if ((p_property.propertyType == SerializedPropertyType.Generic) || (p_property.isArray && (p_property.propertyType != SerializedPropertyType.String))) { EditorGUI.PropertyField(p_position, p_property, p_label, true); } else { p_position.width -= 120; p_position.height = SerializedPropertyValue.GetPropertyHeight(p_property, p_label); EditorGUI.PropertyField(p_position, p_property); } } }