示例#1
0
    public static void SaveConfig <V>(List <V> x, string file) where V : EXml
    {
        StringWriter stringWriter = new StringWriter();

        EXml.Write <V>(stringWriter, "Root", x);
        File.WriteAllText(file, stringWriter.ToString());
    }
示例#2
0
 public static void SaveSingleConfig <V>(V x, string file) where V : EXml
 {
     EXml.SaveConfig <V>(new List <V>
     {
         x
     }, file);
 }
示例#3
0
    public void Save(string file)
    {
        StringWriter stringWriter = new StringWriter();

        EXml.Write(stringWriter, "Root", this);
        File.WriteAllText(file, stringWriter.ToString());
    }
示例#4
0
 public virtual void Insert(int key, T obj)
 {
     EXml.Append(xmlPath, key, obj, keyType);
     if (dict != null)
     {
         dict[key] = obj;
     }
 }
示例#5
0
 public virtual void Delete(int key)
 {
     EXml.Delete(xmlPath, key, keyType);
     if (dict != null)
     {
         dict.Remove(key);
     }
 }
示例#6
0
 public void ClearAll()
 {
     EXml.ClearAll(xmlPath);
     if (dict != null)
     {
         dict.Clear();
     }
 }
示例#7
0
 public static void Write <V>(TextWriter os, string name, HashSet <V> x)
 {
     os.WriteLine("<{0}>", name);
     foreach (V current in x)
     {
         EXml.Write(os, NODENAME, current);
     }
     os.WriteLine("</{0}>", name);
 }
示例#8
0
 public static void WriteDynamicObject <T>(TextWriter os, string name, List <T> x) where T : EXml
 {
     os.WriteLine("<{0}>", name);
     x.ForEach(delegate(T v)
     {
         EXml.WriteDynamicObject(os, NODENAME, v);
     });
     os.WriteLine("</{0}>", name);
 }
示例#9
0
 public static void Write(TextWriter os, string name, EXml x)
 {
     if (x == null)
     {
         return;
     }
     os.WriteLine("<{0} Type=\"{1}\">", name, x.GetType().Name);
     x.Write(os);
     os.WriteLine("</{0}>", name);
 }
示例#10
0
    public static V LoadSingleConfig <V>(string file) where V : EXml
    {
        List <V> list = new List <V>();

        EXml.LoadConfig <V>(list, file);
        if (list.Count != 1)
        {
            throw new Exception(string.Format("SingleConfig type:{0} file:{1} size != 1", typeof(V).FullName, file));
        }
        return(list[0]);
    }
示例#11
0
 public static void Write(TextWriter os, string name, object x)
 {
     if (x == null)
     {
         return;
     }
     if (x is bool)
     {
         EXml.Write(os, name, (bool)x);
     }
     else
     {
         if (x is int)
         {
             EXml.Write(os, name, (int)x);
         }
         else
         {
             if (x is long)
             {
                 EXml.Write(os, name, (long)x);
             }
             else
             {
                 if (x is float)
                 {
                     EXml.Write(os, name, (float)x);
                 }
                 else
                 {
                     if (x is string)
                     {
                         EXml.Write(os, name, (string)x);
                     }
                     else
                     {
                         if (x is Vector3)
                         {
                             EXml.Write(os, name, (Vector3)x);
                         }
                         else
                         {
                             if (!(x is EXml))
                             {
                                 throw new Exception("unknown marshal type;" + x.GetType());
                             }
                             EXml.Write(os, name, (EXml)x);
                         }
                     }
                 }
             }
         }
     }
 }
示例#12
0
 public virtual void Update(int key, T obj)
 {
     if (dict.ContainsKey(key))
     {
         EXml.Update(xmlPath, key, obj, keyType);
     }
     else
     {
         Insert(key, obj);
     }
 }
示例#13
0
 public static void Write <V>(TextWriter os, string name, List <V> x)
 {
     if (x.Count == 0)
     {
         return;
     }
     os.WriteLine("<{0}>", name);
     x.ForEach(delegate(V v)
     {
         EXml.Write(os, NODENAME, v);
     });
     os.WriteLine("</{0}>", name);
 }
示例#14
0
    public static bool ReadBool(XmlNode node)
    {
        string text = EXml.ReadContent(node).ToLower();

        if (text == "true")
        {
            return(true);
        }
        if (text == "false")
        {
            return(false);
        }
        return(false);
    }
示例#15
0
    public static void LoadConfig <V>(List <V> x, string file) where V : EXml
    {
        XmlDocument xmlDocument = new XmlDocument();
        TextAsset   pAsset      = ZTResource.Instance.Load <TextAsset>(file);

        if (pAsset == null)
        {
            return;
        }
        xmlDocument.LoadXml(pAsset.text);
        foreach (XmlNode current in EXml.GetChilds(xmlDocument.DocumentElement))
        {
            V data = EXml.ReadObject <V>(current);
            x.Add(data);
        }
    }
示例#16
0
    public static void Write <K, V>(TextWriter os, KeyValuePair <K, V> x)
    {
        string key = x.Key.ToString();

        if (x.Value is EXml)
        {
            EXml   v     = x.Value as EXml;
            string pName = x.GetType().Name;
            os.WriteLine("<{0}  {1}=\"{2}\">", pName, KEYNAME, key);
            v.Write(os);
            os.WriteLine("</{0}>", pName);
        }
        else
        {
            os.WriteLine("<{0}  {1}=\"{2}\">{3}</{0}>", NODENAME, KEYNAME, key, x.Value);
        }
    }
示例#17
0
    public void ReadData <T>(DataReadBase <T> dataRead) where T : XModule, new ()
    {
        XmlNodeList nodeList = EXml.GetXmlNodeList(dataRead.xmlPath);

        for (int i = 0; i < nodeList.Count; i++)
        {
            XmlElement xe = nodeList.Item(i) as XmlElement;
            if (xe == null)
            {
                continue;
            }
            int key = xe.GetAttribute(dataRead.keyType.ToString()).ToInt32();
            for (int j = 0; j < xe.Attributes.Count; j++)
            {
                string name  = xe.Attributes[j].Name;
                string value = xe.Attributes[j].Value;
                dataRead.AppendAttribute(key, name, value);
            }
        }
    }
示例#18
0
    public void ReadDataExtend <T>(DataReadBase <T> dataRead) where T : XModule, new()
    {
        XmlNodeList nodeList = EXml.GetXmlNodeList(dataRead.xmlPath);

        for (int i = 0; i < nodeList.Count; i++)
        {
            XmlAttribute xa = (nodeList[i] as XmlElement).GetAttributeNode(dataRead.keyType.ToString());
            if (xa == null)
            {
                continue;
            }
            int key = Convert.ToInt32(xa.InnerText);
            for (int k = 0; k < xa.ChildNodes.Count; i++)
            {
                XmlElement xe    = (XmlElement)xa.ChildNodes[i];
                string     name  = xe.Name;
                string     value = xe.Value;
                dataRead.AppendAttribute(key, name, value);
            }
        }
    }
示例#19
0
        public override void Load(XmlElement xe)
        {
            base.Load(xe);
            switch (this.Region)
            {
            case ERegionType.Sphere:
            {
                Scope = new ScopeSphere();
                ScopeSphere v = Scope as ScopeSphere;
                v.Offset = EXml.ReadVector3(xe, "Offset");
                v.Euler  = EXml.ReadVector3(xe, "Euler");
                v.Radius = EXml.ReadFloat(xe, "Radius");
            }
            break;

            case ERegionType.Box:
            {
                Scope = new ScopeBox();
                ScopeBox v = Scope as ScopeBox;
                v.Offset = EXml.ReadVector3(xe, "Offset");
                v.Euler  = EXml.ReadVector3(xe, "Euler");
                v.H      = EXml.ReadFloat(xe, "H");
                v.L      = EXml.ReadFloat(xe, "L");
                v.W      = EXml.ReadFloat(xe, "W");
            }
            break;

            case ERegionType.Cylinder:
            {
                Scope = new ScopeCylinder();
                ScopeCylinder v = Scope as ScopeCylinder;
                v.Offset = EXml.ReadVector3(xe, "Offset");
                v.Euler  = EXml.ReadVector3(xe, "Euler");
                v.MaxDis = EXml.ReadFloat(xe, "MaxDis");
                v.HAngle = EXml.ReadFloat(xe, "HAngle");
                v.Height = EXml.ReadFloat(xe, "Height");
            }
            break;
            }
        }
示例#20
0
    private void LoadSkill()
    {
        string    pPath = string.Format("Text/Actor/{0}", Owner.Id);//50006
        TextAsset text  = ZTResource.Instance.Load <TextAsset>(pPath);

        if (text == null)
        {
            return;
        }
        XmlDocument doc = new XmlDocument();

        doc.LoadXml(text.text);

        XmlNode root = doc.FirstChild;

        if (root.Name.Equals("Actor") == false)
        {
            return;
        }
        XmlNode child = root.FirstChild;

        while (child != null)
        {
            if (child.Name.Equals("Skill"))
            {
                XmlElement xe = child as XmlElement;
                int        id = EXml.ReadInt32(xe, "Id");
                if (id > 0)
                {
                    SkillTree skillTree = new SkillTree(id, Owner);
                    Pool.Skills.Add(skillTree);
                    skillTree.Load(xe);
                }
            }
            child = child.NextSibling;
        }
    }
示例#21
0
    public static T ReadDynamicObject <T>(XmlNode node) where T : EXml
    {
        string typeName = EXml.ReadAttribute(node, TYPENAME);

        if (string.IsNullOrEmpty(typeName))
        {
            return(null);
        }
        string fullTypeName = typeof(T).Namespace + "." + typeName;

        try
        {
            Type   classType = Type.GetType(fullTypeName, true);
            object v         = Activator.CreateInstance(classType);
            T      result    = (T)v;
            result.Read(node);
            return(result);
        }
        catch
        {
            Debug.LogError("XmlElement is null:" + fullTypeName);
            return(null);
        }
    }
示例#22
0
 public override void Load(XmlElement xe)
 {
     base.Load(xe);
     Rate    = EXml.ReadFloat(xe, "Rate");
     Percent = EXml.ReadFloat(xe, "Percent");
 }
示例#23
0
 public static void SaveConfig <K, V>(Dictionary <K, V> x, string file) where V : EXml
 {
     EXml.SaveConfig <V>(x.Values.ToList <V>(), file);
 }
示例#24
0
 public static void WriteDynamicObject(TextWriter os, string name, EXml x)
 {
     os.WriteLine("<{0} {1}=\"{2}\">", name, TYPENAME, x.GetType().ToString());
     x.Write(os);
     os.WriteLine("</{0}>", name);
 }