Every texture and shader combination has a MaterialManager.
Example #1
0
        public static MaterialManager GetInstance(NTexture texture, string shaderName)
        {
            NTexture rootTexture = texture.root;
            if (rootTexture.materialManagers == null)
                rootTexture.materialManagers = new Dictionary<string, MaterialManager>();

            MaterialManager mm;
            if (!rootTexture.materialManagers.TryGetValue(shaderName, out mm))
            {
                mm = new MaterialManager(rootTexture);
                rootTexture.materialManagers.Add(shaderName, mm);
            }

            if (mm.sharedMaterial == null)
            {
                Shader shader = ShaderConfig.Get(shaderName);
                if (shader == null)
                {
                    Debug.LogWarning("FairyGUI: shader not found: " + shaderName);
                    shader = Shader.Find("Transparent/Diffuse");
                }
                mm.sharedMaterial = new Material(shader);
                mm.sharedMaterial.mainTexture = rootTexture.nativeTexture;
                if (rootTexture.alphaTexture != null)
                    mm.sharedMaterial.SetTexture("_AlphaTex", rootTexture.alphaTexture);
            }

            return mm;
        }
Example #2
0
 public void Dispose()
 {
     if (mesh != null)
     {
         Mesh.Destroy(mesh);
         mesh = null;
     }
     _manager     = null;
     _material    = null;
     meshRenderer = null;
     meshFilter   = null;
 }
Example #3
0
 static public int get_shaderName(IntPtr l)
 {
     try {
         FairyGUI.MaterialManager self = (FairyGUI.MaterialManager)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.shaderName);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #4
0
 static public int Release(IntPtr l)
 {
     try {
         FairyGUI.MaterialManager self = (FairyGUI.MaterialManager)checkSelf(l);
         self.Release();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #5
0
 void UpdateManager()
 {
     if (_texture != null)
     {
         _manager = _texture.GetMaterialManager(_shader);
     }
     else
     {
         _manager = null;
     }
     UpdateMaterialFlags();
 }
Example #6
0
 static public int CreateMaterial(IntPtr l)
 {
     try {
         FairyGUI.MaterialManager self = (FairyGUI.MaterialManager)checkSelf(l);
         var ret = self.CreateMaterial();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #7
0
 static public int constructor(IntPtr l)
 {
     try {
         FairyGUI.MaterialManager o;
         FairyGUI.NTexture        a1;
         checkType(l, 2, out a1);
         o = new FairyGUI.MaterialManager(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #8
0
        void UpdateManager()
        {
            if (_manager != null)
            {
                _manager.Release();
            }

            if (_texture != null)
            {
                _manager = MaterialManager.GetInstance(_texture, _shader, _materialKeywords);
            }
            else
            {
                _manager = null;
            }
        }
Example #9
0
 static int GetMaterialManager(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         FairyGUI.NTexture        obj  = (FairyGUI.NTexture)ToLua.CheckObject <FairyGUI.NTexture>(L, 1);
         string                   arg0 = ToLua.CheckString(L, 2);
         FairyGUI.MaterialManager o    = obj.GetMaterialManager(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #10
0
 static public int GetMaterial(IntPtr l)
 {
     try {
         FairyGUI.MaterialManager self = (FairyGUI.MaterialManager)checkSelf(l);
         FairyGUI.NGraphics       a1;
         checkType(l, 2, out a1);
         FairyGUI.UpdateContext a2;
         checkType(l, 3, out a2);
         var ret = self.GetMaterial(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #11
0
        void UpdateManager()
        {
            MaterialManager mm;

            if (_texture != null)
            {
                mm = _texture.GetMaterialManager(_shader, _materialKeywords);
            }
            else
            {
                mm = null;
            }
            if (_manager != null && _manager != mm)
            {
                _manager.Release();
            }
            _manager = mm;
        }
Example #12
0
 public void Dispose()
 {
     if (mesh != null)
     {
         if (Application.isPlaying)
         {
             Mesh.Destroy(mesh);
         }
         else
         {
             Mesh.DestroyImmediate(mesh);
         }
         mesh = null;
     }
     _manager     = null;
     _material    = null;
     meshRenderer = null;
     meshFilter   = null;
 }
Example #13
0
        void Release()
        {
            if (_manager != null)
            {
                _manager.onCreateNewMaterial -= OnCreateNewMaterial;
                _manager = null;
            }

            if (mainTexture != null)
            {
                mainTexture.Dispose();
                mainTexture = null;
            }

            if (_material != null)
            {
                Material.DestroyImmediate(_material);
                _material = null;
            }
        }
Example #14
0
 public void SetShaderAndTexture(string shader, NTexture texture)
 {
     _shader  = shader;
     _texture = texture;
     if (_texture != null)
     {
         _manager = MaterialManager.GetInstance(_texture, _shader);
         if (_material != null)
         {
             _material.mainTexture = _texture.nativeTexture;
         }
     }
     else
     {
         if (_material != null)
         {
             _material.mainTexture = null;
         }
         _manager = null;
     }
 }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        public MaterialManager GetMaterialManager(string shaderName, string[] keywords)
        {
            if (_root != this)
            {
                if (_root == null)
                {
                    return(null);
                }
                else
                {
                    return(_root.GetMaterialManager(shaderName, keywords));
                }
            }

            if (_materialManagers == null)
            {
                _materialManagers = new Dictionary <string, MaterialManager>();
            }

            string key = shaderName;

            if (keywords != null)
            {
                //对于带指定关键字的,目前的设计是不参加共享材质了,因为逻辑会变得更复杂
                key = shaderName + "_" + _gCounter++;
            }

            MaterialManager mm;

            if (!_materialManagers.TryGetValue(key, out mm))
            {
                mm             = new MaterialManager(this, ShaderConfig.GetShader(shaderName), keywords);
                mm._managerKey = key;
                _materialManagers.Add(key, mm);
            }

            return(mm);
        }
Example #16
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     if (mesh != null)
     {
         if (Application.isPlaying)
         {
             Mesh.Destroy(mesh);
         }
         else
         {
             Mesh.DestroyImmediate(mesh);
         }
         mesh = null;
     }
     if (_manager != null)
     {
         _manager.Release();
         _manager = null;
     }
     if (_customMatarial && _material != null)
     {
         if (Application.isPlaying)
         {
             Material.Destroy(_material);
         }
         else
         {
             Material.DestroyImmediate(_material);
         }
     }
     _material      = null;
     meshRenderer   = null;
     meshFilter     = null;
     _stencilEraser = null;
     meshModifier   = null;
 }
Example #17
0
        void Init()
        {
            Release();

            mainTexture = new NTexture(_fontAsset.atlasTexture);
            mainTexture.destroyMethod = DestroyMethod.None;

            _manager = mainTexture.GetMaterialManager(this.shader);
            _manager.onCreateNewMaterial += OnCreateNewMaterial;

            _material = new Material(_fontAsset.material); //copy
            _material.SetFloat(ShaderUtilities.ID_TextureWidth, mainTexture.width);
            _material.SetFloat(ShaderUtilities.ID_TextureHeight, mainTexture.height);
            _material.SetFloat(ShaderUtilities.ID_GradientScale, fontAsset.atlasPadding + 1);
            _material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
            _material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);

            // _ascent = _fontAsset.faceInfo.ascentLine;
            // _lineHeight = _fontAsset.faceInfo.lineHeight;
            _ascent     = _fontAsset.faceInfo.pointSize;
            _lineHeight = _fontAsset.faceInfo.pointSize * 1.25f;

            _lineChar = GetCharacterFromFontAsset('_', FontStyles.Normal);
        }
        public static MaterialManager GetInstance(NTexture texture, string shaderName, string[] keywords)
        {
            NTexture rootTexture = texture.root;
            if (rootTexture.materialManagers == null)
                rootTexture.materialManagers = new Dictionary<string, MaterialManager>();

            string key = shaderName;
            if (keywords != null)
            {
                //对于带指定关键字的,目前的设计是不参加共享材质了,因为逻辑会变得更复杂
                key = shaderName + "_" + _gCounter++;
            }

            MaterialManager mm;
            if (!rootTexture.materialManagers.TryGetValue(key, out mm))
            {
                mm = new MaterialManager(rootTexture);
                mm.shaderName = shaderName;
                mm._keywords = keywords;
                rootTexture.materialManagers.Add(key, mm);
            }

            return mm;
        }
Example #19
0
 public MaterialPool(MaterialManager manager, string[] variants)
 {
     _manager = manager;
     _variants = variants;
 }
Example #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="manager"></param>
 public void DestroyMaterialManager(MaterialManager manager)
 {
     _materialManagers.Remove(manager._managerKey);
     manager.DestroyMaterials();
 }
Example #21
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="variants"></param>
 /// <param name="notShared"></param>
 public MaterialPool(MaterialManager manager, string[] variants, bool notShared)
 {
     _manager = manager;
     _variants = variants;
     _notShared = notShared;
 }
Example #22
0
 /// <summary>
 /// 
 /// </summary>
 public void Dispose()
 {
     if (mesh != null)
     {
         if (Application.isPlaying)
             Mesh.Destroy(mesh);
         else
             Mesh.DestroyImmediate(mesh);
         mesh = null;
     }
     if (_manager != null)
     {
         _manager.Release();
         _manager = null;
     }
     if (_customMatarial && _material != null)
     {
         if (Application.isPlaying)
             Material.Destroy(_material);
         else
             Material.DestroyImmediate(_material);
     }
     _material = null;
     meshRenderer = null;
     meshFilter = null;
     _stencilEraser = null;
     meshModifier = null;
 }
Example #23
0
        void UpdateManager()
        {
            if (_manager != null)
                _manager.Release();

            if (_texture != null)
                _manager = MaterialManager.GetInstance(_texture, _shader, _materialKeywords);
            else
                _manager = null;
        }
Example #24
0
 public void Dispose()
 {
     if (mesh != null)
     {
         Mesh.Destroy(mesh);
         mesh = null;
     }
     _manager = null;
     _material = null;
     meshRenderer = null;
     meshFilter = null;
 }
 public MaterialPool(MaterialManager manager, string[] variants)
 {
     _manager  = manager;
     _variants = variants;
 }
Example #26
0
 public MaterialPool(MaterialManager manager, string[] variants, bool notShared)
 {
     _manager   = manager;
     _variants  = variants;
     _notShared = notShared;
 }