public DType Accept(TInt type, string x) { if (int.TryParse(x, out var b)) { return(DInt.ValueOf(b)); } else { throw new Exception($"{x} 不是int类型"); } }
public Hero() { this.Speed = 10; this.health = new DInt(Rand.Next(4,10)); this.evil = new DBool(); this.kind = new DByte(); this.attacking = new DBool(); this.attackSpeed = new DByte((byte)Rand.Next(5,12)); this.attackDamage = new DByte((byte)Rand.Next(1,4)); this.type = 10; }
public Hero() { this.Speed = 10; this.health = new DInt(Rand.Next(4, 10)); this.evil = new DBool(); this.kind = new DByte(); this.attacking = new DBool(); this.attackSpeed = new DByte((byte)Rand.Next(5, 12)); this.attackDamage = new DByte((byte)Rand.Next(1, 4)); this.type = 10; }
public static float GetPropertyHeight(DInt dInt) { dInt = dInt ?? new DInt(); float height = LINE_HEIGHT; if (!dInt.isExpanded) { return(height); } height += LINE_HEIGHT; height += LINE_HEIGHT * dInt.DecoratorCount; return(height); }
public DType Accept(TInt type, ExcelStream x) { var d = x.Read(); if (CheckNull(type.IsNullable, d)) { return(null); } var ds = d.ToString(); //if (field?.Remapper is TEnum te) //{ // if (te.DefineEnum.TryValueByNameOrAlias(ds, out var c)) // { // return DInt.ValueOf(c); // } //} if (!int.TryParse(ds, out var v)) { throw new InvalidExcelDataException($"{d} 不是 int 类型值"); } return(DInt.ValueOf(v)); }
public void SetData(string key, DInt data) => intData[key] = data;
public void AddData(string key, DInt data) => intData.Add(key, data);
public static DInt OnGUI(Rect position, DInt dInt, GUIContent label, SerializedObject serializedObject) { Rect pos = position; dInt = dInt ?? new DInt(); string text = label.text + " = " + dInt.Value; pos.height = FIELD_HEIGHT; pos.width = text.Length * CHARACTER_WIDTH; EditorGUI.BeginChangeCheck(); dInt.isExpanded = EditorGUI.Foldout(pos, dInt.isExpanded, text); bool sizeChanged = EditorGUI.EndChangeCheck(); pos.x += pos.width + 3 * SPACE; pos.width = position.width - pos.width; pos.xMax -= 3 * SPACE; EditorGUI.BeginChangeCheck(); int result = EditorGUI.DelayedIntField(pos, "[Real Value]", dInt.realValue); if (EditorGUI.EndChangeCheck()) { dInt.Value = result; dInt.Refresh(); } pos.x = position.x + SPACE; pos.xMax = position.xMax - 2 * SPACE; if (dInt.isExpanded) { pos.height = FIELD_HEIGHT; int delete = -1; for (int i = 0, l = dInt.DecoratorCount; i < l; i++) { IntDecorator decorator = dInt.variableDecorators[i]; pos.y += LINE_HEIGHT; Rect rect = new Rect(pos) { xMax = pos.xMax - 4 * CHARACTER_WIDTH }; EditorGUI.BeginChangeCheck(); VariableDecoratorDrawer.OnGUI(rect, decorator, GUIContent.none); if (EditorGUI.EndChangeCheck()) { dInt.Sort(); dInt.Refresh(); } rect.x = rect.xMax + 2 * SPACE; rect.xMax = pos.xMax; if (GUI.Button(rect, "X")) { delete = i; } } if (delete != -1) { dInt.Remove(delete); sizeChanged = true; } pos.y += LINE_HEIGHT; if (GUI.Button(pos, "Add Decorator")) { pos.height = LINE_HEIGHT * 5; dInt.Add(new IntDecorator()); EditorUtility.SetDirty(serializedObject.targetObject); sizeChanged = false; } } if (sizeChanged) { EditorUtility.SetDirty(serializedObject.targetObject); } return(dInt); }
public void Accept(DInt type, StringBuilder x) { x.Append(type.Value); }
public void Accept(DInt type, TType x, List <ResourceInfo> y) { }
public void Accept(DInt type, RawTextTable x) { }
public void Accept(DInt type, ByteBuf x) { x.WriteInt(type.Value); }
public string Accept(DInt type) { return(type.Value.ToString()); }
public Mob() { this.Speed = 10; this.health = new DInt(5); }
public DType Accept(TInt type, object x, DefAssembly ass) { return(DInt.ValueOf((int)x)); }
public void Accept(DInt type, DefAssembly x) { throw new NotImplementedException(); }
public void Accept(DInt type, StringBuilder line) { line.Append(type.Value); }
public void Accept(DInt type, Utf8JsonWriter x) { x.WriteNumberValue(type.Value); }
public bool Accept(DInt type) { return(type.Value == 0); }
public void Accept(DInt type, DefField x, List <ResourceInfo> y) { throw new NotImplementedException(); }
public int Accept(DInt data, TType type, Title x) { SetTitleValue(x, data.Value); return(1); }
public DType Accept(TInt type, XElement x, DefAssembly ass) { return(DInt.ValueOf(int.Parse(x.Value.Trim()))); }
/// <summary> /// Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format. /// </summary> /// <param name="varType"></param> /// <param name="bytes"></param> /// <param name="varCount"></param> /// <param name="bitAdr"></param> /// <returns></returns> private object ParseBytes(VarType varType, byte[] bytes, int varCount, byte bitAdr = 0) { if (bytes == null || bytes.Length == 0) { return(null); } switch (varType) { case VarType.Byte: if (varCount == 1) { return(bytes[0]); } else { return(bytes); } case VarType.Word: if (varCount == 1) { return(Word.FromByteArray(bytes)); } else { return(Word.ToArray(bytes)); } case VarType.Int: if (varCount == 1) { return(Int.FromByteArray(bytes)); } else { return(Int.ToArray(bytes)); } case VarType.DWord: if (varCount == 1) { return(DWord.FromByteArray(bytes)); } else { return(DWord.ToArray(bytes)); } case VarType.DInt: if (varCount == 1) { return(DInt.FromByteArray(bytes)); } else { return(DInt.ToArray(bytes)); } case VarType.Real: if (varCount == 1) { return(Types.Single.FromByteArray(bytes)); } else { return(Types.Single.ToArray(bytes)); } case VarType.String: return(Types.String.FromByteArray(bytes)); case VarType.StringEx: return(StringEx.FromByteArray(bytes)); case VarType.Timer: if (varCount == 1) { return(Timer.FromByteArray(bytes)); } else { return(Timer.ToArray(bytes)); } case VarType.Counter: if (varCount == 1) { return(Counter.FromByteArray(bytes)); } else { return(Counter.ToArray(bytes)); } case VarType.Bit: if (varCount == 1) { if (bitAdr > 7) { return(null); } else { return(Bit.FromByte(bytes[0], bitAdr)); } } else { return(Bit.ToBitArray(bytes)); } default: return(null); } }
public DType Accept(TInt type, JsonElement x, DefAssembly ass) { return(DInt.ValueOf(x.GetInt32())); }