Ejemplo n.º 1
0
        public void InitByMgr(BaseSurfaceMgr mgr, string matName = "", bool isInstance = true)
        {
            IsInstance = isInstance;
            SurfaceMgr = mgr;
            SourceMats.Clear();
            SourceMatsArray.Clear();
            Shaders.Clear();

            var renders = GetRenderers();

            if (renders != null)
            {
                for (int i = 0; i < renders.Length; ++i)
                {
                    GetMaterial(renders[i], out Material material);
                    SourceMats.Add(renders[i], material);
                }

                for (int i = 0; i < renders.Length; ++i)
                {
                    GetMaterials(renders[i], out Material[] materials);
                    SourceMatsArray.Add(renders[i], materials);
                    if (materials != null)
                    {
                        foreach (var item in materials)
                        {
                            if (!Shaders.Contains(item.shader))
                            {
                                Shaders.Add(item.shader);
                            }
                        }
                    }
                }
                //获得材质
                string tempMatName = matName.IsInv() ? GetDefaultMatName() : matName;
                if (UsedMaterials.Count == 0 && !tempMatName.IsInv())
                {
                    foreach (var key in Shaders)
                    {
                        var mat = GRMgr.Material.Spawn(tempMatName);
                        if (DefaultUsedMaterial == null)
                        {
                            DefaultUsedMaterial = mat;
                        }
                        UsedMaterials.Add(key, mat);
                    }
                }
            }
            OnInit();
        }
Ejemplo n.º 2
0
        public virtual void Init(BaseSurfaceMgr mgr, string matName = "")
        {
            surfaceMgr = mgr;
            sourceMats.Clear();
            for (int i = 0; i < surfaceMgr.ModelRenders.Length; ++i)
            {
                sourceMats.Add(surfaceMgr.ModelRenders[i], surfaceMgr.ModelRenders[i].material);
            }
            string tempMatName = matName.IsInvStr() ? GetDefaultMatName() : matName;

            if (UseMaterial == null && !tempMatName.IsInvStr())
            {
                UseMaterial = surfaceMgr.SelfBaseGlobal.GRMgr.GetMaterial(tempMatName);
            }
        }