public override void load(string save) { string[] saveStrings = save.Split(DataSimulator.DS_SAVELOAD_SEPERATOR); actionType = (DSFloatCalType)int.Parse(saveStrings [4]); targetAString = saveStrings [5]; if (!string.IsNullOrEmpty(targetAString)) { string[] splitTargetAStrings = targetAString.Split('/'); targetA = (DSFloat)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1])); } withValue = bool.Parse(saveStrings [6]); if (withValue) { input = int.Parse(saveStrings [7]); } else { targetBString = saveStrings [7]; if (!string.IsNullOrEmpty(targetBString)) { string[] splitTargetBStrings = targetBString.Split('/'); targetB = (DSFloat)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1])); } } resultString = saveStrings [8]; if (!string.IsNullOrEmpty(resultString)) { string[] splitResultStrings = resultString.Split('/'); result = (DSFloat)ds.datas.Find(x => x.name.Equals(splitResultStrings [0])).fields.Find(x => x.name.Equals(splitResultStrings [1])); } }
public void chooseTargetB(DSIfStatement statement) { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == statement.targetType) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; switch (statement.targetType) { case DSDataType.Int: DSInt intItem = (DSInt)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { statement.intTargetB = intItem; statement.targetBString = itemName; }); break; case DSDataType.Float: DSFloat floatItem = (DSFloat)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { statement.floatTargetB = floatItem; statement.targetBString = itemName; }); break; case DSDataType.Bool: DSBool boolItem = (DSBool)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { statement.boolTargetB = boolItem; statement.targetBString = itemName; }); break; case DSDataType.String: DSString stringItem = (DSString)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { statement.stringTargetB = stringItem; statement.targetBString = itemName; }); break; } } } } dropDownMenu.ShowAsContext(); }
public override void load(string save) { string[] saveStrings = save.Split(DataSimulator.DS_SAVELOAD_SEPERATOR); targetString = saveStrings [4]; if (!string.IsNullOrEmpty(targetString)) { string[] splitTargetStrings = targetString.Split('/'); target = (DSInt)ds.datas.Find(x => x.name.Equals(splitTargetStrings [0])).fields.Find(x => x.name.Equals(splitTargetStrings [1])); } resultString = saveStrings [5]; if (!string.IsNullOrEmpty(resultString)) { string[] splitResultStrings = resultString.Split('/'); result = (DSFloat)ds.datas.Find(x => x.name.Equals(splitResultStrings [0])).fields.Find(x => x.name.Equals(splitResultStrings [1])); } }
public void chooseResultWithDropDown() { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Float) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSFloat item = (DSFloat)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { result = item; resultString = itemName; }); } } } dropDownMenu.ShowAsContext(); }
public void updateFieldType(int dataIndex, DSDataType type) { if (_fields [dataIndex].type != type) { IDSData toReplace = _fields [dataIndex]; _fields.RemoveAt(dataIndex); switch (type) { case DSDataType.Bool: DSBool newBool = new DSBool(); newBool.name = toReplace.name; newBool.type = DSDataType.Bool; _fields.Insert(dataIndex, newBool); break; case DSDataType.Float: DSFloat newFloat = new DSFloat(); newFloat.name = toReplace.name; newFloat.type = DSDataType.Float; _fields.Insert(dataIndex, newFloat); break; case DSDataType.Int: DSInt newInt = new DSInt(); newInt.name = toReplace.name; newInt.type = DSDataType.Int; _fields.Insert(dataIndex, newInt); break; case DSDataType.String: DSString newString = new DSString(); newString.name = toReplace.name; newString.type = DSDataType.String; _fields.Insert(dataIndex, newString); break; } } }
public void chooseTargetAWithDropDown() { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Float) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSFloat item = (DSFloat)ds.datas [i].fields [j]; if (actionType == DSFloatCalType.Random ? item.isRandom : true) { dropDownMenu.AddItem(new GUIContent(itemName), false, () => { targetA = item; targetAString = itemName; }); } } } } dropDownMenu.ShowAsContext(); }
public override void draw() { drawInOutPoint(); titleRect = rect; titleRect.height = 20f; extendedRect = rect; extendedRect.y = rect.y + titleRect.height - 1f; extendedRect.height = rect.height - titleRect.height; GUILayout.BeginArea(titleRect, title, GUI.skin.box); GUILayout.EndArea(); GUILayout.BeginArea(extendedRect, GUI.skin.box); GUILayout.BeginVertical(); GUILayout.Space(5f); GUILayout.BeginHorizontal(); GUILayout.Label("Type:", GUILayout.Width(50f)); actionType = (DSDataType)EditorGUILayout.EnumPopup(actionType); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(assignValue ? "Target:" : "Target A:", GUILayout.Width(60f)); if (GUILayout.Button(targetAString)) { chooseTargetAWithDropDown(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Assign Value:", GUILayout.Width(100f)); assignValue = EditorGUILayout.Toggle(assignValue); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(assignValue ? "Value:" : "Target B:", GUILayout.Width(60f)); switch (actionType) { case DSDataType.Int: if (assignValue) { intInput = EditorGUILayout.IntField(intInput); } else { if (GUILayout.Button(targetBString)) { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Int) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSInt item = (DSInt)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { intTargetB = item; targetBString = itemName; }); } } } dropDownMenu.ShowAsContext(); } } break; case DSDataType.Float: if (assignValue) { floatInput = EditorGUILayout.FloatField(floatInput); } else { if (GUILayout.Button(targetBString)) { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Float) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSFloat item = (DSFloat)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { floatTargetB = item; targetBString = itemName; }); } } } dropDownMenu.ShowAsContext(); } } break; case DSDataType.Bool: if (assignValue) { boolInput = EditorGUILayout.Toggle(boolInput); } else { if (GUILayout.Button(targetBString)) { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Bool) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSBool item = (DSBool)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { boolTargetB = item; targetBString = itemName; }); } } } dropDownMenu.ShowAsContext(); } } break; case DSDataType.String: if (assignValue) { stringInput = EditorGUILayout.TextField(stringInput); } else { if (GUILayout.Button(targetBString)) { GenericMenu dropDownMenu = new GenericMenu(); for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.String) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSString item = (DSString)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { stringTargetB = item; targetBString = itemName; }); } } } dropDownMenu.ShowAsContext(); } } break; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndArea(); }
public override void load(string save) { string[] saveStrings = save.Split(DataSimulator.DS_SAVELOAD_SEPERATOR); actionType = (DSDataType)int.Parse(saveStrings [4]); targetAString = saveStrings [5]; assignValue = bool.Parse(saveStrings [6]); if (!string.IsNullOrEmpty(targetAString)) { string[] splitTargetAStrings = targetAString.Split('/'); string[] splitTargetBStrings = null; switch (actionType) { case DSDataType.Int: intTargetA = (DSInt)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1])); if (assignValue) { intInput = int.Parse(saveStrings [7]); } else { targetBString = saveStrings [7]; splitTargetBStrings = targetBString.Split('/'); intTargetB = (DSInt)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1])); } break; case DSDataType.Float: floatTargetA = (DSFloat)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1])); if (assignValue) { floatInput = float.Parse(saveStrings [7]); } else { targetBString = saveStrings [7]; splitTargetBStrings = targetBString.Split('/'); floatTargetB = (DSFloat)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1])); } break; case DSDataType.Bool: boolTargetA = (DSBool)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1])); if (assignValue) { boolInput = bool.Parse(saveStrings [7]); } else { targetBString = saveStrings [7]; splitTargetBStrings = targetBString.Split('/'); boolTargetB = (DSBool)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1])); } break; case DSDataType.String: stringTargetA = (DSString)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1])); if (assignValue) { stringInput = saveStrings [7]; } else { targetBString = saveStrings [7]; splitTargetBStrings = targetBString.Split('/'); stringTargetB = (DSString)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1])); } break; } } }
public void chooseTargetAWithDropDown() { GenericMenu dropDownMenu = new GenericMenu(); switch (actionType) { case DSDataType.Int: for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Int) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSInt item = (DSInt)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { intTargetA = item; targetAString = itemName; }); } } } break; case DSDataType.Float: for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Float) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSFloat item = (DSFloat)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { floatTargetA = item; targetAString = itemName; }); } } } break; case DSDataType.Bool: for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.Bool) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSBool item = (DSBool)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { boolTargetA = item; targetAString = itemName; }); } } } break; case DSDataType.String: for (int i = 0; i < ds.datas.Count; i++) { for (int j = 0; j < ds.datas [i].fields.Count; j++) { if (ds.datas [i].fields [j].type == DSDataType.String) { string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name; DSString item = (DSString)ds.datas [i].fields [j]; dropDownMenu.AddItem(new GUIContent(itemName), false, () => { stringTargetA = item; targetAString = itemName; }); } } } break; } dropDownMenu.ShowAsContext(); }
private void drawDataField(DSDataField data) { for (int i = 0; i < data.fields.Count; i++) { try { GUILayout.BeginHorizontal(); data.fields [i].name = GUILayout.TextField(data.fields [i].name, GUILayout.Width(80f)); DSDataType dataType = data.fields [i].type; dataType = (DSDataType)EditorGUILayout.EnumPopup(dataType, GUILayout.Width(50f)); data.updateFieldType(i, dataType); switch (data.fields [i].type) { case DSDataType.Bool: GUILayout.Space(70f); DSBool boolField = (DSBool)data.fields[i]; boolField.value = EditorGUILayout.Toggle(boolField.value); break; case DSDataType.Float: DSFloat floatField = (DSFloat)data.fields[i]; GUILayout.Label("Random", GUILayout.Width(50f)); floatField.isRandom = EditorGUILayout.Toggle(floatField.isRandom, GUILayout.Width(20f)); if (floatField.isRandom) { floatField.minValue = EditorGUILayout.FloatField(floatField.minValue, GUILayout.Width(50f)); GUILayout.Label(" -", GUILayout.Width(20f)); floatField.maxValue = EditorGUILayout.FloatField(floatField.maxValue, GUILayout.Width(50f)); } else { floatField.value = EditorGUILayout.FloatField(floatField.value, GUILayout.Width(50f)); } break; case DSDataType.Int: DSInt intField = (DSInt)data.fields[i]; GUILayout.Label("Random", GUILayout.Width(50f)); intField.isRandom = EditorGUILayout.Toggle(intField.isRandom, GUILayout.Width(20f)); if (intField.isRandom) { intField.minValue = EditorGUILayout.IntField(intField.minValue, GUILayout.Width(50f)); GUILayout.Label(" -", GUILayout.Width(20f)); intField.maxValue = EditorGUILayout.IntField(intField.maxValue, GUILayout.Width(50f)); } else { intField.value = EditorGUILayout.IntField(intField.value, GUILayout.Width(50f)); } break; case DSDataType.String: DSString stringField = (DSString)data.fields[i]; if (string.IsNullOrEmpty(stringField.value)) { stringField.value = ""; } stringField.value = GUILayout.TextField(stringField.value); break; } if (GUILayout.Button("-", GUILayout.Width(20))) { data.removeField(i); } GUILayout.EndHorizontal(); } catch (ArgumentOutOfRangeException ex) { // do nothing } catch (Exception ex) { Debug.Log(ex.Message); } } }