예제 #1
0
 SDefAttribute GetAttr(FieldInfo fi)
 {
     object[] cas = fi.GetCustomAttributes(typeof(SDefAttribute), false);
     if (cas.Length > 0)
     {
         SDefAttribute ca = cas[0] as SDefAttribute;
         return(ca);
     }
     return(null);
 }
예제 #2
0
    protected override void Read()
    {
        Type t = this.GetType();

        FieldInfo[] infos = t.GetFields();
        SBase       tmp   = null;

        for (int i = 0; i < infos.Length; i++)
        {
            FieldInfo fi = infos[i];

            if (fi.FieldType == typeof(SInt))
            {
                tmp = new SInt();
                SDefAttribute ca = GetAttr(fi);
                if (ca != null)
                {
                    (tmp as SInt).Def = ca.intv;
                }
            }
            else if (fi.FieldType == typeof(SFloat))
            {
                tmp = new SFloat();
                SDefAttribute ca = GetAttr(fi);
                if (ca != null)
                {
                    (tmp as SFloat).Def = ca.floatv;
                }
            }
            else if (fi.FieldType == typeof(SString))
            {
                tmp = new SString();
                SDefAttribute ca = GetAttr(fi);
                if (ca != null)
                {
                    (tmp as SString).Def = ca.stringv;
                }
            }
            else if (IsBaseType(fi.FieldType, typeof(SBase)))
            {
                tmp = Activator.CreateInstance(fi.FieldType) as SBase;
            }
            else
            {
                Debug.LogError(string.Format("{0} no suppot!", fi.Name));
                continue;
            }
            tmp.Init(sb, string.Format(ConnctFormat, key, fi.Name));
            fi.SetValue(this, tmp);
        }
    }