Beispiel #1
0
    public IGDLoadingAsync LoadFromXmlAsync(IGDInstCreator instCreator, string xmlString)
    {
        var asyncData = new GDLoadingAsync();
        var thread    = new Thread(() => {
            try{
                LoadFromXml(instCreator, xmlString, asyncData);
            }catch (Exception e) {
                UnityEngine.Debug.Log(e.Message);
                UnityEngine.Debug.Log(e.StackTrace);
            }
        });

        thread.Start();
        return(asyncData);
    }
Beispiel #2
0
    void LoadFromXml(IGDInstCreator instCreator, string xmlString, GDLoadingAsync loadAsync)
    {
        if (IsLoaded == true)
        {
            return;
        }
        if (loadAsync != null)
        {
            loadAsync.SetDone(false);
            loadAsync.SetPerc(0);
            loadAsync.SetState("Initializing Data");
        }
        XElement xmlData    = XElement.Parse(xmlString);
        XElement contentDic = xmlData.Element("contentDic");

        objectDic = new Dictionary <int, GDDataBase>();
        Dictionary <GDDataBase, XElement> objectThatNeedsRefLink = new Dictionary <GDDataBase, XElement>();

        keyDic = new Dictionary <System.Type, Dictionary <string, GDDataBase> >();

        float totalCnt = 0;

        foreach (var item in contentDic.Elements())
        {
            totalCnt++;
        }
//		float totalCnt = contentDic.Elements().Count;
        float elementInterval = (1.0f / 3.0f) / totalCnt;
        float currentPerc     = 0.0f;

        foreach (var item in contentDic.Elements())
        {
            bool       needLink     = false;
            int        schemeTypeID = System.Convert.ToInt32(item.Attribute("schemeTypeID").Value);
            GDDataBase inst         = instCreator.CreateInstanceBySchemeID(schemeTypeID);
            inst.Manager = this;
            if (loadAsync != null)
            {
                loadAsync.SetPerc(currentPerc);
            }
            inst.LoadFromXml(item, out needLink);
            objectDic.Add(inst.id, inst);
            if (needLink == true)
            {
                objectThatNeedsRefLink.Add(inst, item);
            }

            if (inst.isStruct == false)
            {
                System.Type schemeType = instCreator.SchemeIDToType(inst.schemeTypeID);
                if (keyDic.ContainsKey(schemeType) == false)
                {
                    keyDic.Add(schemeType, new Dictionary <string, GDDataBase>());
                }
                var tempKeyDic = keyDic[schemeType];
                if (tempKeyDic.ContainsKey(inst.key) == true)
                {
                    throw new Exception("This cannot happen. Same key exists in same scheme!");
                }
                tempKeyDic.Add(inst.key, inst);
            }
            currentPerc += elementInterval;
        }
        if (loadAsync != null)
        {
            loadAsync.SetPerc(currentPerc);
            loadAsync.SetState("Linking Data");
        }
        //Link it
        foreach (var pair in objectThatNeedsRefLink)
        {
            pair.Key.LoadReferences(this, pair.Value);
        }
        cachedListDic = new Dictionary <Type, object>();
        currentPerc  += 1.0f / 3.0f;

        if (loadAsync != null)
        {
            loadAsync.SetPerc(currentPerc);
            loadAsync.SetState("Preparing Data");
        }
        //Prepare it
        foreach (var tempAction in PrepareFunctionList)
        {
            tempAction();
        }
        currentPerc += 1.0f / 3.0f;
        IsLoaded     = true;
        if (loadAsync != null)
        {
            loadAsync.SetDone(true);
            loadAsync.SetPerc(currentPerc);
            loadAsync.SetState("Done");
        }
    }
Beispiel #3
0
 public void LoadFromXml(IGDInstCreator instCreator, string xmlString)
 {
     LoadFromXml(instCreator, xmlString, null);
 }