//Encode string. private void writeString(byte[] buffer, ref int offset, IJsonNode value) { int le = Encoding.UTF8.GetByteCount(value.AsString()); offset = writeBytes(buffer, offset, Encoder.encodeUInt32((uint)le)); byte[] bytes = Encoding.UTF8.GetBytes(value.ToString()); this.writeBytes(buffer, offset, bytes); offset += le; }
public void DisplayContent() { var color = GUI.color; EditorGUILayout.BeginHorizontal(); { GUI.color = Color.grey; if (GUILayout.Button("※", EditorStyles.largeLabel, GUILayout.Width(20))) { } if (GUILayout.Button("☑", EditorStyles.largeLabel, GUILayout.Width(20))) { } GUI.color = color; if (jsonType == EJsonType.Object || value.type == EJsonType.Array) { if (value.type == EJsonType.Object || value.type == EJsonType.Array) { GUILayout.Space(layer * 20); string content = open ? "▲" : "▼"; if (GUILayout.Button(content, EditorStyles.largeLabel, GUILayout.Width(20))) { open = !open; } if (string.IsNullOrEmpty(key)) { GUI.color = Color.grey; EditorGUILayout.LabelField(index + " {" + childs.Count + "}"); GUI.color = color; } else { EditorGUILayout.LabelField(key); } } else { GUILayout.Space((layer + 1) * 20); GUILayout.Label(key + " : "); var va = value.AsString(); GUILayout.Label(va); if (value.AsString() != va) { value = new JsonString(va); } } } else if (jsonType == EJsonType.Number) { GUILayout.Space((layer + 1) * 20); EditorGUILayout.LabelField(key + " : "); var va = (float)value.AsDouble(); va = EditorGUILayout.FloatField(va); if ((float)value.AsDouble() != va) { value = new JsonNumber(va); } } else { GUILayout.Space((layer + 1) * 20); EditorGUILayout.LabelField(key + " : "); var va = value.AsString(); va = EditorGUILayout.TextField(va); if (value.AsString() != va) { value = new JsonString(va); } } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); if (open) { for (int i = 0; i < childs.Count; i++) { childs[i].DisplayContent(); } } }