public static void DrawDsgVarModel(Rect rect, DsgVarComponent.DsgVarEditableEntry dsgVarEntry, int?arrayIndex) { DsgVarComponent.DsgVarEditableEntry.Value value = dsgVarEntry.valueModel; if (value != null) { DrawDsgVarValue(rect, dsgVarEntry, value, arrayIndex); } }
private JSONObject GetDsgVarValueJSON(DsgVarComponent.DsgVarEditableEntry.Value value) { if (value == null) { return(null); } JSONObject dsgObj = new JSONObject(); dsgObj["string"] = value.ToString(); switch (value.type) { case DsgVarInfoEntry.DsgVarType.Perso: PersoBehaviour pb = value.AsPerso; if (pb != null) { Perso p = pb.perso; if (p != null) { JSONObject persoJSON = new JSONObject(); persoJSON["offset"] = p.offset.ToString(); persoJSON["nameFamily"] = p.nameFamily; persoJSON["nameModel"] = p.nameModel; persoJSON["nameInstance"] = p.namePerso; dsgObj["perso"] = persoJSON; } } break; case DsgVarInfoEntry.DsgVarType.SuperObject: SuperObjectComponent soc = value.AsSuperObject; if (soc != null) { SuperObject spo = soc.so; JSONObject soJSON = new JSONObject(); soJSON["offset"] = spo.offset.ToString(); soJSON["type"] = spo.type.ToString(); soJSON["offset"] = spo.offset.ToString(); if (spo.type == SuperObject.Type.Perso && spo.data != null) { Perso p = spo.data as Perso; if (p != null) { JSONObject persoJSON = new JSONObject(); persoJSON["offset"] = p.offset.ToString(); persoJSON["nameFamily"] = p.nameFamily; persoJSON["nameModel"] = p.nameModel; persoJSON["nameInstance"] = p.namePerso; soJSON["perso"] = persoJSON; } } dsgObj["value"] = soJSON; } break; } return(dsgObj); }
public static void DrawDsgVarValue(Rect rect, DsgVarComponent.DsgVarEditableEntry dsgVarEntry, DsgVarComponent.DsgVarEditableEntry.Value value, int?arrayIndex) { string stringVal; switch (value.type) { case DsgVarInfoEntry.DsgVarType.Boolean: value.AsBoolean = EditorGUI.Toggle(rect, value.AsBoolean); break; case DsgVarInfoEntry.DsgVarType.Int: value.AsInt = EditorGUI.IntField(rect, value.AsInt); break; case DsgVarInfoEntry.DsgVarType.UInt: stringVal = EditorGUI.TextField(rect, value.AsUInt.ToString()); if (UInt32.TryParse(stringVal, out uint r_uint)) { value.AsUInt = r_uint; } break; case DsgVarInfoEntry.DsgVarType.Caps: stringVal = EditorGUI.TextField(rect, value.AsCaps.ToString()); if (UInt32.TryParse(stringVal, out uint r_caps)) { value.AsCaps = r_caps; } break; case DsgVarInfoEntry.DsgVarType.Short: stringVal = EditorGUI.TextField(rect, value.AsShort.ToString()); if (Int16.TryParse(stringVal, out short r_short)) { value.AsShort = r_short; } break; case DsgVarInfoEntry.DsgVarType.UShort: stringVal = EditorGUI.TextField(rect, value.AsUShort.ToString()); if (UInt16.TryParse(stringVal, out ushort r_ushort)) { value.AsUShort = r_ushort; } break; case DsgVarInfoEntry.DsgVarType.Byte: stringVal = EditorGUI.TextField(rect, value.AsByte.ToString()); if (SByte.TryParse(stringVal, out sbyte r_sbyte)) { value.AsByte = r_sbyte; } break; case DsgVarInfoEntry.DsgVarType.UByte: stringVal = EditorGUI.TextField(rect, value.AsUByte.ToString()); if (Byte.TryParse(stringVal, out byte r_byte)) { value.AsUByte = r_byte; } break; case DsgVarInfoEntry.DsgVarType.Float: value.AsFloat = EditorGUI.FloatField(rect, value.AsFloat); break; case DsgVarInfoEntry.DsgVarType.Text: int?newTextID = DrawText(rect, value.AsText); if (newTextID.HasValue) { value.AsText = newTextID.Value; } //GUILayout.Label(MapLoader.Loader.localization.GetTextForHandleAndLanguageID((int)value.AsUInt, 0)); break; case DsgVarInfoEntry.DsgVarType.Vector: value.AsVector = EditorGUI.Vector3Field(rect, "", value.AsVector); break; case DsgVarInfoEntry.DsgVarType.Perso: if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader) { ROMPersoBehaviour currentPersoBehaviour = value.AsPersoROM != null ? value.AsPersoROM : null; ROMPersoBehaviour selectedPersoBehaviour = ((ROMPersoBehaviour)EditorGUI.ObjectField(rect, currentPersoBehaviour, typeof(ROMPersoBehaviour), true)); if (selectedPersoBehaviour != null && selectedPersoBehaviour.gameObject != null) { value.AsPersoROM = selectedPersoBehaviour; } } else { PersoBehaviour currentPersoBehaviour = value.AsPerso != null ? value.AsPerso : null; PersoBehaviour selectedPersoBehaviour = ((PersoBehaviour)EditorGUI.ObjectField(rect, currentPersoBehaviour, typeof(PersoBehaviour), true)); if (selectedPersoBehaviour != null && selectedPersoBehaviour.gameObject != null) { value.AsPerso = selectedPersoBehaviour; } } break; case DsgVarInfoEntry.DsgVarType.SuperObject: SuperObjectComponent currentGao = value.AsSuperObject != null ? value.AsSuperObject : null; SuperObjectComponent selectedGao = ((SuperObjectComponent)EditorGUI.ObjectField(rect, currentGao, typeof(SuperObjectComponent), true)); if (selectedGao != null && selectedGao.gameObject != null) { value.AsSuperObject = selectedGao; } break; case DsgVarInfoEntry.DsgVarType.WayPoint: WayPointBehaviour currentWaypointGao = value.AsWayPoint != null ? value.AsWayPoint : null; WayPointBehaviour selectedWaypointGao = ((WayPointBehaviour)EditorGUI.ObjectField(rect, currentWaypointGao, typeof(WayPointBehaviour), true)); if (selectedWaypointGao != null && selectedWaypointGao.gameObject != null) { value.AsWayPoint = selectedWaypointGao; } break; case DsgVarInfoEntry.DsgVarType.Graph: GraphBehaviour currentGraphGao = value.AsGraph != null ? value.AsGraph : null; GraphBehaviour selectedGraphGao = ((GraphBehaviour)EditorGUI.ObjectField(rect, currentGraphGao, typeof(GraphBehaviour), true)); if (selectedGraphGao != null && selectedGraphGao.gameObject != null) { value.AsGraph = selectedGraphGao; } break; case DsgVarInfoEntry.DsgVarType.ActionArray: case DsgVarInfoEntry.DsgVarType.FloatArray: case DsgVarInfoEntry.DsgVarType.Array11: case DsgVarInfoEntry.DsgVarType.GraphArray: case DsgVarInfoEntry.DsgVarType.Array9: case DsgVarInfoEntry.DsgVarType.IntegerArray: case DsgVarInfoEntry.DsgVarType.PersoArray: case DsgVarInfoEntry.DsgVarType.SoundEventArray: case DsgVarInfoEntry.DsgVarType.SuperObjectArray: case DsgVarInfoEntry.DsgVarType.TextArray: case DsgVarInfoEntry.DsgVarType.TextRefArray: case DsgVarInfoEntry.DsgVarType.VectorArray: case DsgVarInfoEntry.DsgVarType.WayPointArray: if (value.AsArray != null) { if (arrayIndex.HasValue) { if (value.AsArray[arrayIndex.Value] != null) { DrawDsgVarValue(rect, dsgVarEntry, value.AsArray[arrayIndex.Value], arrayIndex); } } else { EditorGUI.LabelField(rect, "Length: " + value.AsArray.Length); } } break; } }
private WebJSON.DsgVarValue GetDsgVarValueJSON(DsgVarComponent.DsgVarEditableEntry.Value value, bool isArray) { if (value == null) { return(null); } WebJSON.DsgVarValue dsgObj = new WebJSON.DsgVarValue() { Type = value.type }; if (isArray) { dsgObj.AsArray = value.AsArray.Select(a => GetDsgVarValueJSON(a, false)).ToArray(); } else { switch (value.type) { case DsgVarInfoEntry.DsgVarType.Boolean: dsgObj.AsBoolean = value.AsBoolean; break; case DsgVarInfoEntry.DsgVarType.Byte: dsgObj.AsByte = value.AsByte; break; case DsgVarInfoEntry.DsgVarType.UByte: dsgObj.AsUByte = value.AsUByte; break; case DsgVarInfoEntry.DsgVarType.Short: dsgObj.AsShort = value.AsShort; break; case DsgVarInfoEntry.DsgVarType.UShort: dsgObj.AsUShort = value.AsUShort; break; case DsgVarInfoEntry.DsgVarType.Int: dsgObj.AsInt = value.AsInt; break; case DsgVarInfoEntry.DsgVarType.UInt: dsgObj.AsUInt = value.AsUInt; break; case DsgVarInfoEntry.DsgVarType.Float: dsgObj.AsFloat = value.AsFloat; break; case DsgVarInfoEntry.DsgVarType.Caps: dsgObj.AsCaps = value.AsCaps; break; case DsgVarInfoEntry.DsgVarType.Text: dsgObj.AsText = value.AsText; break; case DsgVarInfoEntry.DsgVarType.Vector: dsgObj.AsVector = value.AsVector; break; case DsgVarInfoEntry.DsgVarType.Perso: if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader) { dsgObj.AsPerso = GetPersoJSON(value.AsPersoROM, includeDetails: false); } else { dsgObj.AsPerso = GetPersoJSON(value.AsPerso, includeDetails: false); } break; case DsgVarInfoEntry.DsgVarType.SuperObject: dsgObj.AsSuperObject = GetSuperObjectJSON(value.AsSuperObject, includeChildren: false); break; case DsgVarInfoEntry.DsgVarType.WayPoint: dsgObj.AsWayPoint = GetWayPointJSON(value.AsWayPoint, false); break; case DsgVarInfoEntry.DsgVarType.Graph: dsgObj.AsGraph = GetGraphJSON(value.AsGraph); break; case DsgVarInfoEntry.DsgVarType.Action: dsgObj.AsAction = new WebJSON.DsgState() { Name = value.AsAction?.ToString() }; break; } } return(dsgObj); }