Esempio n. 1
0
    /// <summary>创建商铺模型, 并加载招牌/铺面贴图</summary>
    public void CreateShops(bool isForceCreate = true)
    {
        if (!isForceCreate)
        {
            if (_isShopCreated)
            {
                return;
            }
        }
        //Debug.Log("CreateShops");
        DestroyShops();
        Model2ShopSignDic.Clear();
        //Resources.UnloadUnusedAssets();

        if (ShopSignList == null)
        {
            ShopSignList = new List <ShopSignVO>();
        }

        float curCellWidth = 0;

        if (ShopSignList.Count != 0)
        {
            for (int iSS = 0, lenSS = ShopSignList.Count; iSS < lenSS; iSS++)
            {
                ShopSignVO ss = ShopSignList[iSS];

                GameObject shop = m_sm.CreateShopModel(ss.CellNum, ss.PrefabType);

                Model2ShopSignDic.AddRep(shop, ss);

                shop.transform.parent           = transform;
                shop.transform.localEulerAngles = new Vector3(-90, 0, 0);
                shop.transform.localPosition    = new Vector3(-curCellWidth, 0, 0);
                shop.transform.localScale       = new Vector3(1, 1, shopHeight / 3.35f);

                Utils.ForAllChildren(shop, child =>
                {
                    if (child.GetComponent <MeshFilter>() != null)
                    {
                        child.AddComponent <MeshCollider>();
                    }
                });


                curCellWidth += CellWidth * ss.CellNum;
                Material[] matArr  = shop.GetComponentInChildren <Renderer>().materials;
                Material   matShop = matArr.FindItem(mat => { return(mat.name.Contains("mat_context")); });
                Material   matSign = matArr.FindItem(mat => { return(mat.name.Contains("mat_zp")); });

                m_sm.GetSignTexByCode(ss.SignCode, ss.RouteID, tex =>
                {
                    if (this != null && tex != null && matSign != null)
                    {
                        matSign.mainTexture = tex;
                    }
                });
                m_sm.GetShopTexByCode(ss.ShopCode, ss.CellNum, tex =>
                {
                    if (this != null && tex != null && matShop != null)
                    {
                        matShop.mainTexture = tex;
                    }
                });
            }
        }
        else
        {
            //没有商铺的也要创建一间空白的作为占位显示
            ShopSignVO ss = new ShopSignVO(1);
            ss.PrefabType = ShopSignVO.PrefabTypeShopSign;
            GameObject shop = m_sm.CreateShopModel(ss.CellNum, ss.PrefabType);
            Model2ShopSignDic.AddRep(shop, ss);
            shop.transform.parent           = transform;
            shop.transform.localEulerAngles = new Vector3(-90, 0, 0);
            shop.transform.localPosition    = new Vector3(-curCellWidth, 0, 0);
            shop.transform.localScale       = new Vector3(1, 1, shopHeight / 3.35f);

            Utils.ForAllChildren(shop, child =>
            {
                if (child.GetComponent <MeshFilter>() != null)
                {
                    child.AddComponent <MeshCollider>();
                }
            });
            curCellWidth += CellWidth * ss.CellNum;
            Material[] matArr  = shop.GetComponentInChildren <Renderer>().materials;
            Material   matShop = matArr.FindItem(mat => { return(mat.name.Contains("mat_context")); });
            Material   matSign = matArr.FindItem(mat => { return(mat.name.Contains("mat_zp")); });
            matSign.mainTexture = Texture2D.whiteTexture;
            matShop.mainTexture = Texture2D.whiteTexture;
        }

        transform.localScale  = new Vector3(curCellWidth == 0 ? 1 : shopTotalWidth / curCellWidth, 1, 1);
        transform.eulerAngles = Vector3.up.GetScaledVector(Utils.GetRotateY(worldNormal));
        transform.position    = PointList[0] + worldNormal.normalized.GetScaledVector(0.1f);
        transform.parent      = m_sm.ShopModelFolder.transform;
        _isShopCreated        = true;
    }