Пример #1
0
 public virtual void Load(BinaryHelper helper)
 {
     PropertyInfo[] propInfo = GetType().GetProperties();
     foreach (PropertyInfo info in propInfo)
     {
         if (info.PropertyType == typeof(string))
         {
             info.SetValue(this, helper.ReadString(), null);
         }
         else if (info.PropertyType == typeof(int))
         {
             info.SetValue(this, helper.ReadInt(), null);
         }
         else if (info.PropertyType == typeof(float))
         {
             info.SetValue(this, helper.ReadFloat(), null);
         }
         else if (info.PropertyType == typeof(bool))
         {
             info.SetValue(this, helper.ReadBool(), null);
         }
         else if (info.PropertyType == typeof(short))
         {
             info.SetValue(this, (short)helper.ReadInt(), null);
         }
         else if (info.PropertyType == typeof(List <int>))
         {
             info.SetValue(this, ConvertorTool.StringToList_Int(helper.ReadString()), null);
         }
         else if (info.PropertyType == typeof(List <float>))
         {
             info.SetValue(this, ConvertorTool.StringToList_Float(helper.ReadString()), null);
         }
         else if (info.PropertyType == typeof(List <string>))
         {
             info.SetValue(this, ConvertorTool.StringToList_String(helper.ReadString()), null);
         }
         else
         {
             Debug.Log("不支持的类型:" + info.PropertyType.ToString() + " " + info.Name);
         }
     }
 }
Пример #2
0
 public void Load(BinaryHelper helper)
 {
     ID                   = helper.ReadInt();
     StrName              = helper.ReadString();
     ModelId              = helper.ReadInt();
     ModelScale           = helper.ReadFloat();
     WeaponID             = helper.ReadInt();
     RaceType             = helper.ReadInt();
     IsPush               = helper.ReadBool();
     AIType               = helper.ReadInt();
     Type                 = helper.ReadInt();
     BossAIXmlName        = helper.ReadString();
     BossAIXmlSubName     = helper.ReadString();
     InterSubType         = helper.ReadInt();
     NpcSay               = helper.ReadInt();
     Level                = helper.ReadInt();
     HPMax                = helper.ReadFloat();
     HPCount              = helper.ReadInt();
     PhyAttack            = helper.ReadFloat();
     MagAttack            = helper.ReadFloat();
     PhyDefend            = helper.ReadFloat();
     MagDefend            = helper.ReadFloat();
     HitRate              = helper.ReadFloat();
     Avoid                = helper.ReadFloat();
     CritRate             = helper.ReadFloat();
     CritParam            = helper.ReadFloat();
     Resist               = helper.ReadFloat();
     WoundParam           = helper.ReadFloat();
     AnitInterfereRate    = helper.ReadFloat();
     AnitInterruptRate    = helper.ReadFloat();
     AnitRepelRate        = helper.ReadFloat();
     AnitLauncherRate     = helper.ReadFloat();
     RotateSpeed          = helper.ReadFloat();
     SwitchRotateSpeed    = helper.ReadFloat();
     MoveSpeed            = helper.ReadFloat();
     AnimationSpeed       = helper.ReadFloat();
     AttackRange          = helper.ReadFloat();
     CallNpcRange         = helper.ReadFloat();
     AlertRange           = helper.ReadFloat();
     CancelAlertRange     = helper.ReadFloat();
     AlertPeriod          = helper.ReadFloat();
     LargeRate            = helper.ReadFloat();
     SmallRate            = helper.ReadFloat();
     VisionRange          = helper.ReadFloat();
     MaxChaseRange        = helper.ReadFloat();
     RetreatDistance      = helper.ReadFloat();
     RetreatSpeed         = helper.ReadFloat();
     RetreatTime          = helper.ReadFloat();
     StaminaMax           = helper.ReadInt();
     StaminaRestoreValue  = helper.ReadFloat();
     StaminaRestorePeriod = helper.ReadFloat();
     StaminaEvent         = helper.ReadInt();
     StaminaSkillID       = helper.ReadInt();
     StaminaReset         = helper.ReadFloat();
     GiftBuffIDList       = ConvertorTool.StringToList_Float(helper.ReadString());
     DropID               = helper.ReadInt();
     SkillList            = ConvertorTool.StringToList_Int(helper.ReadString());
     PassiveSkillList     = ConvertorTool.StringToList_Int(helper.ReadString());
     functionNum          = helper.ReadInt(); // NpcFuncArgs 的数量
     if (functionNum > 0)
     {
         NpcFuncArgs = new List <NpcFuncArg>();
         for (int i = 0; i < functionNum; ++i)
         {
             NpcFuncArg val = new NpcFuncArg();
             val.Load(helper);
             NpcFuncArgs.Add(val);
         }
     }
 }
Пример #3
0
 public static bool SetValue <T>(PropertyInfo info, T obj, ICell cell)
 {
     if (info.PropertyType == typeof(string))
     {
         if ((cell != null) && (cell.CellType == CellType.STRING))
         {
             info.SetValue(obj, cell.StringCellValue, null);
         }
         else
         {
             info.SetValue(obj, "", null);
         }
     }
     else if (info.PropertyType == typeof(int))
     {
         if ((cell != null) && (cell.CellType == CellType.NUMERIC))
         {
             info.SetValue(obj, (int)cell.NumericCellValue, null);
         }
         else
         {
             info.SetValue(obj, 0, null);
         }
     }
     else if (info.PropertyType == typeof(float))
     {
         if ((cell != null) && (cell.CellType == CellType.NUMERIC))
         {
             info.SetValue(obj, (float)cell.NumericCellValue, null);
         }
         else
         {
             info.SetValue(obj, 0.0f, null);
         }
     }
     else if (info.PropertyType == typeof(bool))
     {
         if ((cell != null) && (cell.CellType == CellType.NUMERIC))
         {
             info.SetValue(obj, cell.NumericCellValue != 0, null);
         }
         else
         {
             info.SetValue(obj, false, null);
         }
     }
     else if (info.PropertyType == typeof(short))
     {
         if ((cell != null) && (cell.CellType == CellType.NUMERIC))
         {
             info.SetValue(obj, (short)cell.NumericCellValue, null);
         }
         else
         {
             info.SetValue(obj, 0, null);
         }
     }
     else if (info.PropertyType == typeof(List <int>))
     {
         string s = "";
         if (cell != null && cell.CellType == CellType.STRING)
         {
             s = cell.StringCellValue;
         }
         info.SetValue(obj, ConvertorTool.StringToList_Int(s), null);
     }
     else if (info.PropertyType == typeof(List <float>))
     {
         string s = "";
         if (cell != null && cell.CellType == CellType.STRING)
         {
             s = cell.StringCellValue;
         }
         info.SetValue(obj, ConvertorTool.StringToList_Float(s), null);
     }
     else if (info.PropertyType == typeof(List <string>))
     {
         string s = "";
         if (cell != null && cell.CellType == CellType.STRING)
         {
             s = cell.StringCellValue;
         }
         info.SetValue(obj, ConvertorTool.StringToList_String(s), null);
     }
     else
     {
         Debug.LogError("不支持的类型:" + info.PropertyType.ToString() + " " + info.Name);
         return(false);
     }
     return(true);
 }
Пример #4
0
    public static T GenericObj <T>(IRow row) where T : new()
    {
        int index = 0;
        T   obj   = new T();

        PropertyInfo[] propInfo = typeof(T).GetProperties();
        foreach (PropertyInfo info in propInfo)
        {
            ICell cell = row.GetCell(index++);
            if (info.PropertyType == typeof(string))
            {
                if (cell != null && cell.CellType == CellType.STRING)
                {
                    info.SetValue(obj, cell.StringCellValue, null);
                }
            }
            else if (info.PropertyType == typeof(int))
            {
                if (cell != null && cell.CellType == CellType.NUMERIC)
                {
                    info.SetValue(obj, (int)cell.NumericCellValue, null);
                }
            }
            else if (info.PropertyType == typeof(float))
            {
                if (cell != null && cell.CellType == CellType.NUMERIC)
                {
                    info.SetValue(obj, (float)cell.NumericCellValue, null);
                }
            }
            else if (info.PropertyType == typeof(bool))
            {
                if (cell != null && cell.CellType == CellType.NUMERIC)
                {
                    info.SetValue(obj, cell.NumericCellValue != 0, null);
                }
            }
            else if (info.PropertyType == typeof(short))
            {
                if (cell != null && cell.CellType == CellType.NUMERIC)
                {
                    info.SetValue(obj, (short)cell.NumericCellValue, null);
                }
            }
            else if (info.PropertyType == typeof(List <int>))
            {
                string s = "";
                if (cell != null && cell.CellType == CellType.STRING)
                {
                    s = cell.StringCellValue;
                }
                info.SetValue(obj, ConvertorTool.StringToList_Int(s), null);
            }
            else if (info.PropertyType == typeof(List <float>))
            {
                string s = "";
                if (cell != null && cell.CellType == CellType.STRING)
                {
                    s = cell.StringCellValue;
                }
                info.SetValue(obj, ConvertorTool.StringToList_Float(s), null);
            }
            else if (info.PropertyType == typeof(List <string>))
            {
                string s = "";
                if (cell != null && cell.CellType == CellType.STRING)
                {
                    s = cell.StringCellValue;
                }
                info.SetValue(obj, ConvertorTool.StringToList_String(s), null);
            }
            else
            {
                Debug.LogError("不支持的类型:" + info.PropertyType.ToString() + " " + info.Name);
            }
        }
        return(obj);
    }