コード例 #1
0
ファイル: GameInit.cs プロジェクト: slt5309616/Village
    private void LoadGameObject(XmlElement node, Transform parent = null)
    {
        GoConfig config = new GoConfig();

        config.name      = node.GetAttribute("name");
        config.occid     = node.GetAttribute("occid");
        config.isPerLoad = node.GetAttribute("isPerLoad") == "True" ? true : false;
        config.isSurface = node.GetAttribute("isSurface") == "True" ? true : false;
        config.asset     = node.GetAttribute("asset");
        config.parent    = parent;
        config.id        = node.GetAttribute("id");
        config.unitType  = node.GetAttribute("unitType");
        config.node      = node;
        config.tag       = node.GetAttribute("tag");
        List <string> temp;

        temp            = FuncUtil.GetInstance().StrToStrList(node.GetAttribute("position"));
        config.position = new Vector3(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]));
        temp            = FuncUtil.GetInstance().StrToStrList(node.GetAttribute("rotation"));
        config.rotation = new Quaternion(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]), float.Parse(temp[3]));
        temp            = FuncUtil.GetInstance().StrToStrList(node.GetAttribute("scale"));
        config.scale    = new Vector3(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]));
        configDict.Add(config.occid, config);
        //Debug.Log("Load GO " + config.occid);
        LoadAsset(config.asset, config.occid);
    }
コード例 #2
0
ファイル: GameInit.cs プロジェクト: slt5309616/Village
    void InitialGameObject()
    {
        foreach (var www in wwwDone)
        {
            www.Value.assetBundle.LoadAllAssetsAsync();
        }

        var itr = configDict.GetEnumerator();

        while (itr.MoveNext())
        {
            GoConfig config = itr.Current.Value;
            if (mainAsseturlDict.ContainsKey(config.asset))
            {
                //从mainAsseturlDict得到需要创建的go的prefab的url
                string assetUrl = mainAsseturlDict[config.asset];
                //从wwwDine中得到对应url的www
                var obj = wwwDone[assetUrl].assetBundle.LoadAsset(config.name);


                //Debug.Log("Initial|" + config.asset + "|" + occid + "|" + assetUrl);
                GameObject gameObj = (GameObject)Instantiate(obj, config.position, config.rotation);
                var        occid   = itr.Current.Key;
                goDict.Add(occid, gameObj);
                //Debug.Log("Add occid to goDic " + occid);

                gameObj.transform.localScale = config.scale;
                gameObj.name = config.name;
                gameObj.tag  = config.tag;
                if (config.isSurface)
                {
                    gameObj.transform.parent = surfaceLayer.transform;
                }
                else
                {
                    if (config.isPerLoad)
                    {
                        gameObj.transform.parent = preloadLayer.transform;
                    }
                    else
                    {
                        gameObj.transform.parent = otherLayer.transform;
                    }
                }
                if (config.parent != null)
                {
                    gameObj.transform.parent = config.parent;
                }

                if (config.node.ChildNodes.Count > 0)
                {
                    foreach (XmlElement property in config.node.ChildNodes)
                    {
                        if (property.Name == "Renderers")
                        {
                            LoadRenderToObj(property, gameObj);
                        }
                        if (property.Name == "Effects")
                        {
                        }
                    }
                }
            }
            else
            {
                Debug.Log(config.asset + "is not in mainAsseturlLst");
            }
        }
        totalAssetNum = 0;
        var itrWWW = wwwDone.GetEnumerator();

        while (itrWWW.MoveNext())
        {
            itrWWW.Current.Value.assetBundle.Unload(false);
        }
    }