コード例 #1
0
 public DType Accept(TInt type, string x)
 {
     if (int.TryParse(x, out var b))
     {
         return(DInt.ValueOf(b));
     }
     else
     {
         throw new Exception($"{x} 不是int类型");
     }
 }
コード例 #2
0
ファイル: Hero.cs プロジェクト: Maksims/gh12-server
        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;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
    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);
    }
コード例 #5
0
        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));
        }
コード例 #6
0
 public void SetData(string key, DInt data) => intData[key] = data;
コード例 #7
0
 public void AddData(string key, DInt data) => intData.Add(key, data);
コード例 #8
0
    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);
    }
コード例 #9
0
 public void Accept(DInt type, StringBuilder x)
 {
     x.Append(type.Value);
 }
コード例 #10
0
 public void Accept(DInt type, TType x, List <ResourceInfo> y)
 {
 }
コード例 #11
0
 public void Accept(DInt type, RawTextTable x)
 {
 }
コード例 #12
0
 public void Accept(DInt type, ByteBuf x)
 {
     x.WriteInt(type.Value);
 }
コード例 #13
0
 public string Accept(DInt type)
 {
     return(type.Value.ToString());
 }
コード例 #14
0
ファイル: Mob.cs プロジェクト: yonglehou/gh12-server
 public Mob()
 {
     this.Speed  = 10;
     this.health = new DInt(5);
 }
コード例 #15
0
 public DType Accept(TInt type, object x, DefAssembly ass)
 {
     return(DInt.ValueOf((int)x));
 }
コード例 #16
0
ファイル: ValidatorVisitor.cs プロジェクト: zhangga/luban
 public void Accept(DInt type, DefAssembly x)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
ファイル: LuaExportor.cs プロジェクト: zhangga/luban
 public void Accept(DInt type, StringBuilder line)
 {
     line.Append(type.Value);
 }
コード例 #18
0
ファイル: Mob.cs プロジェクト: Maksims/gh12-server
 public Mob()
 {
     this.Speed = 10;
     this.health = new DInt(5);
 }
コード例 #19
0
ファイル: JsonExportor.cs プロジェクト: zhangga/luban
 public void Accept(DInt type, Utf8JsonWriter x)
 {
     x.WriteNumberValue(type.Value);
 }
コード例 #20
0
 public bool Accept(DInt type)
 {
     return(type.Value == 0);
 }
コード例 #21
0
ファイル: ResourceExportor.cs プロジェクト: zhangga/luban
 public void Accept(DInt type, DefField x, List <ResourceInfo> y)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
 public int Accept(DInt data, TType type, Title x)
 {
     SetTitleValue(x, data.Value);
     return(1);
 }
コード例 #23
0
 public DType Accept(TInt type, XElement x, DefAssembly ass)
 {
     return(DInt.ValueOf(int.Parse(x.Value.Trim())));
 }
コード例 #24
0
        /// <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);
            }
        }
コード例 #25
0
 public DType Accept(TInt type, JsonElement x, DefAssembly ass)
 {
     return(DInt.ValueOf(x.GetInt32()));
 }