Ejemplo n.º 1
0
    public void Init(string parasStr)
    {
        effectParasList = new List <float[]>();
        if (parasStr == "")
        {
            return;
        }
        string[] tmpStrs0 = parasStr.Split(';');
        // 基础参数
        string[] tmpStrs1 = tmpStrs0[0].Split(',');
        atlasName  = tmpStrs1[0];
        spriteName = tmpStrs1[1];
        blendMode  = (eBlendMode)int.Parse(tmpStrs1[2]);
        int tmpInt = int.Parse(tmpStrs1[3]);

        layerId = tmpInt == -1 ? LayerId.STGNormalEffect : (LayerId)tmpInt;
        // 参数列表
        int paraListLen = tmpStrs0.Length - 1;

        for (int i = 0; i < paraListLen; i++)
        {
            string[] paraStr    = tmpStrs0[i + 1].Split(',');
            int      len        = paraStr.Length;
            float[]  paraIntArr = new float[len];
            for (int j = 0; j < len; j++)
            {
                paraIntArr[j] = float.Parse(paraStr[j]);
            }
            effectParasList.Add(paraIntArr);
        }
    }
 public void parse(XmlElement xmlElement)
 {
     id               = xmlElement.GetAttribute("id");
     spriteName       = xmlElement.GetAttribute("spriteName");
     aniFrameCount    = int.Parse(xmlElement.GetAttribute("aniFrameCount"));
     aniFrameInterval = int.Parse(xmlElement.GetAttribute("aniFrameInterval"));
     appearEffectName = xmlElement.GetAttribute("appearEffectName");
     string[] sizeStrs = xmlElement.GetAttribute("size").Split(',');
     if (sizeStrs.Length == 1)
     {
         appearEffectSizeFrom = appearEffectSizeTo = 0;
     }
     else
     {
         appearEffectSizeFrom = float.Parse(sizeStrs[0]);
         appearEffectSizeTo   = float.Parse(sizeStrs[1]);
     }
     blendMode         = (eBlendMode)int.Parse(xmlElement.GetAttribute("materialType"));
     isRotatedByVAngle = int.Parse(xmlElement.GetAttribute("isRotatedByVAngle")) == 1 ? true : false;
     selfRotationAngle = float.Parse(xmlElement.GetAttribute("selfRotationAngle"));
     grazeHalfWidth    = float.Parse(xmlElement.GetAttribute("grazeHalfWidth"));
     grazeHalfHeight   = float.Parse(xmlElement.GetAttribute("grazeHalfHeight"));
     collisionRadius   = float.Parse(xmlElement.GetAttribute("collisionRadius"));
     string[] colorStrs = (xmlElement.GetAttribute("eliminateColor")).Split(',');
     eliminateColor = new Color(float.Parse(colorStrs[0]), float.Parse(colorStrs[1]), float.Parse(colorStrs[2]));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Set a tile color using a tilemap local position
        /// </summary>
        /// <param name="vLocalPos"></param>
        /// <param name="c0">Bottom left corner</param>
        /// <param name="c1">Bottom right corner</param>
        /// <param name="c2">Top left corner</param>
        /// <param name="c3">Top right corner</param>
        public void SetTileColor(Vector2 vLocalPos, TileColor32 tileColor, eBlendMode blendMode = eBlendMode.AlphaBlending)
        {
            int gridX = BrushUtil.GetGridX(vLocalPos, CellSize);
            int gridY = BrushUtil.GetGridY(vLocalPos, CellSize);

            SetTileColor(gridX, gridY, tileColor, blendMode);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// 设置混合模式
    /// <para>effect</para>
    /// <para>blendMode</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int SetSpriteEffectBlendMode(ILuaState luaState)
    {
        STGSpriteEffect effect    = luaState.ToUserData(-2) as STGSpriteEffect;
        eBlendMode      blendMode = (eBlendMode)luaState.ToInteger(-1);

        effect.SetBlendMode(blendMode);
        return(0);
    }
Ejemplo n.º 5
0
    public static int SetSTGObjectProps(ILuaState luaState)
    {
        STGSpriteEffect effect     = luaState.ToUserData(-6) as STGSpriteEffect;
        string          atlasName  = luaState.ToString(-5);
        string          spriteName = luaState.ToString(-4);
        eBlendMode      blendMode  = (eBlendMode)luaState.ToInteger(-3);
        LayerId         layerId    = (LayerId)luaState.ToInteger(-2);
        bool            cached     = luaState.ToBoolean(-1);

        effect.SetSprite(atlasName, spriteName, blendMode, layerId, cached);
        return(0);
    }
Ejemplo n.º 6
0
    void BlendModePopup()
    {
        eBlendMode mode = (eBlendMode)_blendMode.floatValue;

        EditorGUI.BeginChangeCheck();
        mode = (eBlendMode)EditorGUILayout.Popup("Blend Mode", (int)mode, Enum.GetNames(typeof(eBlendMode)));
        if (EditorGUI.EndChangeCheck())
        {
            _materialEditor.RegisterPropertyChangeUndo("Blend Mode");
            _blendMode.floatValue = (float)mode;
        }
    }
 public void parse(XmlElement xmlElement)
 {
     id                 = xmlElement.GetAttribute("id");
     laserAtlasName     = xmlElement.GetAttribute("laserAtlasName");
     laserTexName       = xmlElement.GetAttribute("laserTexName");
     texDefaultRotation = float.Parse(xmlElement.GetAttribute("texDefaultRotation"));
     blendMode          = (eBlendMode)int.Parse(xmlElement.GetAttribute("materialType"));
     laserHeadTexName   = xmlElement.GetAttribute("laserHeadTexName");
     laserSourceTexId   = xmlElement.GetAttribute("laserSourceTexId");
     string[] colorStrs = (xmlElement.GetAttribute("eliminateColor")).Split(',');
     eliminateColor = new Color(float.Parse(colorStrs[0]), float.Parse(colorStrs[1]), float.Parse(colorStrs[2]));
 }
Ejemplo n.º 8
0
    void BlendModePopup()
    {
        var        material  = _materialEditor.target as Material;
        eBlendMode blendMode = GetMaterialBlendMode(material);

        EditorGUI.BeginChangeCheck();
        blendMode = (eBlendMode)EditorGUILayout.Popup("Blend Mode", (int)blendMode, Enum.GetNames(typeof(eBlendMode)));

        if (EditorGUI.EndChangeCheck())
        {
            SetBlendMode(material, blendMode);
        }
    }
Ejemplo n.º 9
0
 public void SetTileColor(int locGridX, int locGridY, TileColor32 tileColor, eBlendMode blendMode = eBlendMode.AlphaBlending)
 {
     if (locGridX >= 0 && locGridX < m_width && locGridY >= 0 && locGridY < m_height)
     {
         int tileIdx = locGridY * m_width + locGridX;
         if (m_tileColorList == null || m_tileColorList.Count == 0)
         {
             m_tileColorList = Enumerable.Repeat(new TileColor32(new Color32(0xff, 0xff, 0xff, 0xff)), m_tileDataList.Count).ToList();
         }
         m_tileColorList[tileIdx] = TileColor32.BlendColors(m_tileColorList[tileIdx], tileColor, blendMode);
         m_needsRebuildMeshColor  = true;
     }
 }
Ejemplo n.º 10
0
        public static Color32 BlendColor(Color32 colorA, Color32 colorB, eBlendMode blendMode)
        {
            if ((colorB.r | colorB.g | colorB.b | colorB.a) == 0) //NOTE: if all the values are 0, this color blend is skipped
            {
                return(colorA);
            }
            switch (blendMode)
            {
            case eBlendMode.Normal:
                return(colorB);

            case eBlendMode.AlphaBlending:
                int outA = (colorB.a + (colorA.a * (255 - colorB.a)) / 255);
                if (outA > 0f)
                {
                    colorA.r = (byte)((colorB.r * colorB.a + colorA.r * (255 - colorB.a)) / outA);
                    colorA.g = (byte)((colorB.g * colorB.a + colorA.g * (255 - colorB.a)) / outA);
                    colorA.b = (byte)((colorB.b * colorB.a + colorA.b * (255 - colorB.a)) / outA);
                }
                colorA.a = (byte)outA;
                return(colorA);

            case eBlendMode.Additive:
            {
                byte r = (byte)Mathf.Min(255, colorA.r + colorB.r);
                byte g = (byte)Mathf.Min(255, colorA.g + colorB.g);
                byte b = (byte)Mathf.Min(255, colorA.b + colorB.b);
                return(new Color32(r, g, b, colorA.a));
            }

            case eBlendMode.Subtractive:
            {
                byte r = (byte)Mathf.Max(0, colorA.r - colorB.r);
                byte g = (byte)Mathf.Max(0, colorA.g - colorB.g);
                byte b = (byte)Mathf.Max(0, colorA.b - colorB.b);
                return(new Color32(r, g, b, colorA.a));
            }

            case eBlendMode.Multiply:
            {
                byte r = (byte)(colorA.r * colorB.r / 255);
                byte g = (byte)(colorA.g * colorB.g / 255);
                byte b = (byte)(colorA.b * colorB.b / 255);
                return(new Color32(r, g, b, colorA.a));
            }

            default:
                return(colorB);
            }
        }
Ejemplo n.º 11
0
    /// <summary>
    /// 根据属性创建指定的SpriteEffect
    /// <para>atlasName</para>
    /// <para>spriteName</para>
    /// <para>cached 是否缓存</para>
    /// <para>layerId 层级</para>
    /// <para>在层级中的顺序</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateSpriteEffectWithProps(ILuaState luaState)
    {
        string          atlasName    = luaState.ToString(-6);
        string          spriteName   = luaState.ToString(-5);
        eBlendMode      blendMode    = (eBlendMode)luaState.ToInteger(-4);
        LayerId         layerId      = (LayerId)luaState.ToInteger(-3);
        bool            cached       = luaState.ToBoolean(-2);
        int             orderInLayer = luaState.ToInteger(-1);
        STGSpriteEffect effect       = EffectsManager.GetInstance().CreateEffectByType(EffectType.SpriteEffect) as STGSpriteEffect;

        effect.SetSprite(atlasName, spriteName, blendMode, layerId, cached);
        effect.SetOrderInLayer(orderInLayer);
        luaState.PushLightUserData(effect);
        return(1);
    }
        /// <summary>
        /// Creates a fill overlay with BlendMode = Over
        /// </summary>
        public void Create()
        {
            if (Fill == null)
            {
                Fill = new ExcelDrawingFill(_pictureRelationDocument, NameSpaceManager, TopNode, _path, SchemaNodeOrder);
                if (Fill._fillTypeNode == null)
                {
                    Fill.Style = eFillStyle.NoFill;
                }
            }

            if (!ExistNode($"{_path}/@blend"))
            {
                Blend = eBlendMode.Over;
            }
        }
Ejemplo n.º 13
0
 public void SetSprite(string atlasName, string spName, eBlendMode blendMode = eBlendMode.Normal, LayerId layerId = LayerId.STGNormalEffect, bool isUsingCache = false)
 {
     _isUsingCache = isUsingCache;
     // 不使用缓存,直接创建
     if (!isUsingCache)
     {
         _effectGo = ResourceManager.GetInstance().GetPrefab("Prefab/Effects", "SpriteEffect");
         _effectTf = _effectGo.transform;
         _text     = _effectTf.Find("Text").GetComponent <Text>();
         if (blendMode != eBlendMode.Normal)
         {
             _text.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(blendMode);
         }
         //_text.sprite = ResourceManager.GetInstance().GetSprite(atlasName, spName);
         UIManager.GetInstance().AddGoToLayer(_effectGo, layerId);
     }
     else
     {
         _effectGoName = "SpriteEffect_" + atlasName + "_" + spName + "_" + blendMode;
         _effectGo     = ObjectsPool.GetInstance().GetPrefabAtPool(_effectGoName);
         if (_effectGo == null)
         {
             GameObject protoType = ObjectsPool.GetInstance().GetProtoType(_effectGoName);
             if (protoType == null)
             {
                 protoType      = ResourceManager.GetInstance().GetPrefab("Prefab/Effects", "SpriteEffect");
                 protoType.name = _effectGoName;
                 Transform tf = protoType.transform;
                 tf.localPosition = new Vector3(2000, 2000, 0);
                 SpriteRenderer sr = tf.Find("Sprite").GetComponent <SpriteRenderer>();
                 if (blendMode != eBlendMode.Normal)
                 {
                     sr.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(blendMode);
                 }
                 sr.sprite = ResourceManager.GetInstance().GetSprite(atlasName, spName);
                 UIManager.GetInstance().AddGoToLayer(protoType, LayerId.STGNormalEffect);
                 ObjectsPool.GetInstance().AddProtoType(_effectGoName, protoType);
             }
             _effectGo = GameObject.Instantiate <GameObject>(protoType);
             UIManager.GetInstance().AddGoToLayer(_effectGo, layerId);
         }
         _effectTf = _effectGo.transform;
         _text     = _effectTf.Find("Text").GetComponent <Text>();
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Set a tile color in the grid position
        /// </summary>
        /// <param name="gridX"></param>
        /// <param name="gridY"></param>
        /// <param name="c0">Bottom left corner</param>
        /// <param name="c1">Bottom right corner</param>
        /// <param name="c2">Top left corner</param>
        /// <param name="c3">Top right corner</param>
        public void SetTileColor(int gridX, int gridY, TileColor32 tileColor, eBlendMode blendMode = eBlendMode.AlphaBlending)
        {
            TilemapChunk chunk      = GetOrCreateTileChunk(gridX, gridY, true);
            int          chunkGridX = (gridX < 0 ? -gridX - 1 : gridX) % k_chunkSize;
            int          chunkGridY = (gridY < 0 ? -gridY - 1 : gridY) % k_chunkSize;

            if (gridX < 0)
            {
                chunkGridX = k_chunkSize - 1 - chunkGridX;
            }
            if (gridY < 0)
            {
                chunkGridY = k_chunkSize - 1 - chunkGridY;
            }
            if (m_allowPaintingOutOfBounds || (gridX >= m_minGridX && gridX <= m_maxGridX && gridY >= m_minGridY && gridY <= m_maxGridY))
            {
                chunk.SetTileColor(chunkGridX, chunkGridY, tileColor, blendMode);
            }
        }
Ejemplo n.º 15
0
    private void SetMaterialKeywords(Material material)
    {
        eBlendMode blendMode = GetMaterialBlendMode(material);

        SetBlendMode(material, blendMode);

        bool zWrite    = material.GetFloat("_ZWrite") > 0.0f;
        bool clipAlpha = zWrite && blendMode != eBlendMode.Opaque && material.GetFloat("_Cutoff") > 0.0f;

        SetKeyword(material, "_ALPHA_CLIP", clipAlpha);

        bool normalMap = material.HasProperty("_BumpMap") && material.GetTexture("_BumpMap") != null;

        SetKeyword(material, "_NORMALMAP", normalMap);

        bool diffuseRamp = material.HasProperty("_DiffuseRamp") && material.GetTexture("_DiffuseRamp") != null;

        SetKeyword(material, "_DIFFUSE_RAMP", diffuseRamp);

        bool blendTexture = material.HasProperty("_BlendTex") && material.GetTexture("_BlendTex") != null;

        SetKeyword(material, "_TEXTURE_BLEND", blendTexture);
    }
Ejemplo n.º 16
0
    private void SetBlendMode(Material material, eBlendMode blendMode)
    {
        SetKeyword(material, "_ALPHABLEND_ON", blendMode == eBlendMode.StandardAlpha);
        SetKeyword(material, "_ALPHAPREMULTIPLY_ON", blendMode == eBlendMode.PreMultipliedAlpha);
        SetKeyword(material, "_MULTIPLYBLEND", blendMode == eBlendMode.Multiply);
        SetKeyword(material, "_MULTIPLYBLEND_X2", blendMode == eBlendMode.Multiplyx2);
        SetKeyword(material, "_ADDITIVEBLEND", blendMode == eBlendMode.Additive);
        SetKeyword(material, "_ADDITIVEBLEND_SOFT", blendMode == eBlendMode.SoftAdditive);

        int  renderQueue;
        bool useCustomRenderQueue = material.GetFloat("_CustomRenderQueue") > 0.0f;

        switch (blendMode)
        {
        case eBlendMode.Opaque:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            SetRenderType(material, "Opaque", useCustomRenderQueue);
            renderQueue = kSolidQueue;
        }
        break;

        case eBlendMode.Additive:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderQueue);
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;

        case eBlendMode.SoftAdditive:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderQueue);
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;

        case eBlendMode.Multiply:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderQueue);
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;

        case eBlendMode.Multiplyx2:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderQueue);
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;

        case eBlendMode.PreMultipliedAlpha:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderQueue);
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;

        case eBlendMode.StandardAlpha:
        default:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderQueue);
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;
        }

        material.renderQueue = (_renderQueueAbsolute ? 0 : renderQueue) + material.GetInt("_RenderQueue");
        material.SetOverrideTag("IgnoreProjector", blendMode == eBlendMode.Opaque ? "False" : "True");
    }
Ejemplo n.º 17
0
        /// <summary>
        /// 根据混合模式获取对应的精灵的材质
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public Material GetSpriteMatByBlendMode(eBlendMode mode)
        {
            int index = (int)mode;

            return(_spriteMatList[index]);
        }
Ejemplo n.º 18
0
        public static Color32 BlendColor(Color32 colorA, Color32 colorB, eBlendMode blendMode)
        {
            if ((colorB.r | colorB.g | colorB.b | colorB.a) == 0) //NOTE: if all the values are 0, this color blend is skipped
            {
                return(colorA);
            }
            switch (blendMode)
            {
            case eBlendMode.None:
                return(colorB);

            case eBlendMode.AlphaBlending:
            {
                if (colorB.a == 255)
                {
                    return(colorB);
                }

                /*Ref: https://en.wikipedia.org/wiki/Alpha_compositing
                 * Not working properly if ColorA.a is not 255
                 * int outA = (colorB.a + (colorA.a * (255 - colorB.a)) / 255);
                 * int invAlpha = 255 - colorB.a;
                 * if (outA > 0f)
                 * {
                 *  colorA.r = (byte)((colorB.r * colorB.a + colorA.r * colorA.a * invAlpha / 255) / outA);
                 *  colorA.g = (byte)((colorB.g * colorB.a + colorA.g * colorA.a * invAlpha / 255) / outA);
                 *  colorA.b = (byte)((colorB.b * colorB.a + colorA.b * colorA.a * invAlpha / 255) / outA);
                 *  if(colorA.r + colorA.g + colorA.b == 0)
                 *      Debug.Log("outA: " + outA + " cA " + colorA + " cB " + colorB);
                 * }
                 * colorA.a = (byte)outA;
                 * return colorA;
                 */
                int  invAlpha = 255 - colorB.a;
                byte r        = (byte)((colorA.r * invAlpha + colorB.r * colorB.a) / 255);
                byte g        = (byte)((colorA.g * invAlpha + colorB.g * colorB.a) / 255);
                byte b        = (byte)((colorA.b * invAlpha + colorB.b * colorB.a) / 255);
                return(new Color32(r, g, b, colorA.a));
            }

            case eBlendMode.Additive:
            {
                byte r = (byte)Mathf.Min(255, colorA.r + colorB.r * colorB.a / 255);
                byte g = (byte)Mathf.Min(255, colorA.g + colorB.g * colorB.a / 255);
                byte b = (byte)Mathf.Min(255, colorA.b + colorB.b * colorB.a / 255);
                return(new Color32(r, g, b, colorA.a));
            }

            case eBlendMode.Subtractive:
            {
                byte r = (byte)Mathf.Max(0, colorA.r - colorB.r * colorB.a / 255);
                byte g = (byte)Mathf.Max(0, colorA.g - colorB.g * colorB.a / 255);
                byte b = (byte)Mathf.Max(0, colorA.b - colorB.b * colorB.a / 255);
                return(new Color32(r, g, b, colorA.a));
            }

            case eBlendMode.Multiply:
            {
                int  invAlpha = 255 - colorB.a;
                byte r        = (byte)(colorA.r * invAlpha / 255 + colorA.r * colorB.r * colorB.a / 65025);  //65025 = 255 * 255
                byte g        = (byte)(colorA.g * invAlpha / 255 + colorA.g * colorB.g * colorB.a / 65025);  //65025 = 255 * 255
                byte b        = (byte)(colorA.b * invAlpha / 255 + colorA.b * colorB.b * colorB.a / 65025);  //65025 = 255 * 255
                return(new Color32(r, g, b, colorA.a));
            }

            case eBlendMode.Divide:
            {
                int  invAlpha = 255 - colorB.a;
                byte r        = (byte)(colorA.r * invAlpha / 255 + (colorA.r > colorB.r? colorB.a : colorA.r * colorB.a / (colorB.r + 1)));
                byte g        = (byte)(colorA.g * invAlpha / 255 + (colorA.g > colorB.g ? colorB.a : colorA.g * colorB.a / (colorB.g + 1)));
                byte b        = (byte)(colorA.b * invAlpha / 255 + (colorA.b > colorB.b ? colorB.a : colorA.b * colorB.a / (colorB.b + 1)));
                return(new Color32(r, g, b, colorA.a));
            }

            default:
                return(colorB);
            }
        }
Ejemplo n.º 19
0
 public static TileColor32 BlendColors(TileColor32 tileColorA, TileColor32 tileColorB, eBlendMode blendMode)
 {
     if (tileColorA.singleColor && tileColorB.singleColor)
     {
         return(new TileColor32(BlendColor(tileColorA.c0, tileColorB.c0, blendMode)));
     }
     else
     {
         return(new TileColor32(BlendColor(tileColorA.c0, tileColorB.c0, blendMode), BlendColor(tileColorA.c1, tileColorB.c1, blendMode), BlendColor(tileColorA.c2, tileColorB.c2, blendMode), BlendColor(tileColorA.c3, tileColorB.c3, blendMode)));
     }
 }
Ejemplo n.º 20
0
    protected virtual bool RenderModes()
    {
        bool dataChanged = false;

        //Lighting Mode
        {
            EditorGUI.BeginChangeCheck();

            eLightMode lightMode = GetMaterialLightMode((Material)_materialEditor.target);
            EditorGUI.showMixedValue = false;
            foreach (Material material in _materialEditor.targets)
            {
                if (lightMode != GetMaterialLightMode(material))
                {
                    EditorGUI.showMixedValue = true;
                    break;
                }
            }

            lightMode = (eLightMode)EditorGUILayout.Popup(_lightingModeText, (int)lightMode, _lightingModeOptions);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material material in _materialEditor.targets)
                {
                    switch (lightMode)
                    {
                    case eLightMode.VertexLit:
                        if (material.shader.name != kShaderVertexLit)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderVertexLit), false);
                        }
                        break;

                    case eLightMode.PixelLit:
                        if (material.shader.name != kShaderPixelLit)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderPixelLit), false);
                        }
                        break;

                    case eLightMode.Unlit:
                        if (material.shader.name != kShaderUnlit)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderUnlit), false);
                        }
                        break;

                    case eLightMode.LitLightweight:
                        if (material.shader.name != kShaderLitLW)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderLitLW), false);
                        }
                        break;
                    }
                }

                dataChanged = true;
            }
        }

        //Blend Mode
        {
            eBlendMode blendMode = GetMaterialBlendMode((Material)_materialEditor.target);
            EditorGUI.showMixedValue = false;
            foreach (Material material in _materialEditor.targets)
            {
                if (blendMode != GetMaterialBlendMode(material))
                {
                    EditorGUI.showMixedValue = true;
                    break;
                }
            }

            EditorGUI.BeginChangeCheck();
            blendMode = (eBlendMode)EditorGUILayout.Popup(_blendModeText, (int)blendMode, _blendModeOptions);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _materialEditor.targets)
                {
                    SetBlendMode(mat, blendMode);
                }

                dataChanged = true;
            }

            if (QualitySettings.activeColorSpace == ColorSpace.Linear &&
                !EditorGUI.showMixedValue && blendMode == eBlendMode.PreMultipliedAlpha)
            {
                EditorGUILayout.HelpBox(MaterialChecks.kPMANotSupportedLinearMessage, MessageType.Error, true);
            }
        }

        //	GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel);
        //	m_MaterialEditor.RenderQueueField();
        //	m_MaterialEditor.EnableInstancingField();

        EditorGUI.BeginChangeCheck();
        EditorGUI.showMixedValue = _renderQueue.hasMixedValue;
        int renderQueue = EditorGUILayout.IntSlider(_rendererQueueText, (int)_renderQueue.floatValue, 0, 49);

        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_RenderQueue", renderQueue);
            dataChanged = true;
        }

        EditorGUI.BeginChangeCheck();
        var culling = (eCulling)Mathf.RoundToInt(_culling.floatValue);

        EditorGUI.showMixedValue = _culling.hasMixedValue;
        culling = (eCulling)EditorGUILayout.Popup(_cullingModeText, (int)culling, _cullingModeOptions);
        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_Cull", (int)culling);
            dataChanged = true;
        }

        EditorGUI.showMixedValue = false;

        EditorGUI.BeginChangeCheck();
        _materialEditor.ShaderProperty(_pixelSnap, _pixelSnapText);
        dataChanged |= EditorGUI.EndChangeCheck();

        return(dataChanged);
    }
Ejemplo n.º 21
0
 /// <summary>
 /// Set a tile color using a tilemap local position
 /// </summary>
 /// <param name="vLocalPos"></param>
 /// <param name="color"></param>
 public void SetTileColor(Vector2 vLocalPos, Color32 color, eBlendMode blendMode = eBlendMode.AlphaBlending)
 {
     SetTileColor(vLocalPos, new TileColor32(color), blendMode);
 }
	static void SetBlendMode (Material material, eBlendMode blendMode) {
		SetKeyword(material, PremultipledAlpha, blendMode == eBlendMode.PreMultipliedAlpha);
		SetKeyword(material, Multiply, blendMode == eBlendMode.Multiply);
		SetKeyword(material, Multiply2x, blendMode == eBlendMode.Multiplyx2);
		SetKeyword(material, Additive, blendMode == eBlendMode.Additive);
		SetKeyword(material, SoftAdditive, blendMode == eBlendMode.SoftAdditive);

		int renderQueue;

		switch (blendMode) {
		case eBlendMode.Solid:
			{
				material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
				material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
				SetRenderQueue(material, "Opaque");
				renderQueue = SolidQueue;
			}
			break;
		case eBlendMode.Additive:
			{ 
				material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
				material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
				SetRenderQueue(material, "Transparent");
				renderQueue = TransparentQueue;
			}
			break;
		case eBlendMode.SoftAdditive:
			{
				material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
				material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
				SetRenderQueue(material, "Transparent");
				renderQueue = TransparentQueue;
			}
			break;
		case eBlendMode.Multiply:
			{
				material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
				material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
				SetRenderQueue(material, "Transparent");
				renderQueue = TransparentQueue;
			}
			break;
		case eBlendMode.Multiplyx2:
			{
				material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
				material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
				SetRenderQueue(material, "Transparent");
				renderQueue = TransparentQueue;
			}
			break;
		case eBlendMode.PreMultipliedAlpha:
		case eBlendMode.StandardAlpha:
		default:
			{
				bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
				material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
				material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
				SetRenderQueue(material, zWrite ? "TransparentCutout" : "Transparent");
				renderQueue = zWrite ? AlphaTestQueue : TransparentQueue;
			}
			break;
		}

		material.renderQueue = renderQueue + material.GetInt("_RenderQueue");
	}
Ejemplo n.º 23
0
    static void SetBlendMode(Material material, eBlendMode blendMode)
    {
        SetKeyword(material, PremultipledAlpha, blendMode == eBlendMode.PreMultipliedAlpha);
        SetKeyword(material, Multiply, blendMode == eBlendMode.Multiply);
        SetKeyword(material, Multiply2x, blendMode == eBlendMode.Multiplyx2);
        SetKeyword(material, Additive, blendMode == eBlendMode.Additive);
        SetKeyword(material, SoftAdditive, blendMode == eBlendMode.SoftAdditive);

        int renderQueue;

        switch (blendMode)
        {
        case eBlendMode.Solid:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            SetRenderQueue(material, "Opaque");
            renderQueue = SolidQueue;
        }
        break;

        case eBlendMode.Additive:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
            SetRenderQueue(material, "Transparent");
            renderQueue = TransparentQueue;
        }
        break;

        case eBlendMode.SoftAdditive:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
            SetRenderQueue(material, "Transparent");
            renderQueue = TransparentQueue;
        }
        break;

        case eBlendMode.Multiply:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
            SetRenderQueue(material, "Transparent");
            renderQueue = TransparentQueue;
        }
        break;

        case eBlendMode.Multiplyx2:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
            SetRenderQueue(material, "Transparent");
            renderQueue = TransparentQueue;
        }
        break;

        case eBlendMode.PreMultipliedAlpha:
        case eBlendMode.StandardAlpha:
        default:
        {
            bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            SetRenderQueue(material, zWrite ? "TransparentCutout" : "Transparent");
            renderQueue = zWrite ? AlphaTestQueue : TransparentQueue;
        }
        break;
        }

        material.renderQueue = renderQueue + material.GetInt("_RenderQueue");
    }
Ejemplo n.º 24
0
    protected virtual bool RenderModes()
    {
        bool dataChanged = false;

        //Lighting Mode
        {
            EditorGUI.BeginChangeCheck();

            eLightMode lightMode = GetMaterialLightMode((Material)_materialEditor.target);
            EditorGUI.showMixedValue = false;
            foreach (Material material in _materialEditor.targets)
            {
                if (lightMode != GetMaterialLightMode(material))
                {
                    EditorGUI.showMixedValue = true;
                    break;
                }
            }

            lightMode = (eLightMode)EditorGUILayout.Popup(_lightingModeText, (int)lightMode, _lightingModeOptions);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material material in _materialEditor.targets)
                {
                    switch (lightMode)
                    {
                    case eLightMode.VertexLit:
                        if (material.shader.name != kShaderVertexLit)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderVertexLit), false);
                        }
                        break;

                    case eLightMode.PixelLit:
                        if (material.shader.name != kShaderPixelLit)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderPixelLit), false);
                        }
                        break;

                    case eLightMode.Unlit:
                        if (material.shader.name != kShaderUnlit)
                        {
                            _materialEditor.SetShader(Shader.Find(kShaderUnlit), false);
                        }
                        break;
                    }
                }

                dataChanged = true;
            }
        }

        //Blend Mode
        {
            eBlendMode blendMode = GetMaterialBlendMode((Material)_materialEditor.target);
            EditorGUI.showMixedValue = false;
            foreach (Material material in _materialEditor.targets)
            {
                if (blendMode != GetMaterialBlendMode(material))
                {
                    EditorGUI.showMixedValue = true;
                    break;
                }
            }

            EditorGUI.BeginChangeCheck();
            blendMode = (eBlendMode)EditorGUILayout.Popup(_blendModeText, (int)blendMode, _blendModeOptions);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _materialEditor.targets)
                {
                    SetBlendMode(mat, blendMode);
                }

                dataChanged = true;
            }
        }

        //	GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel);
        //	m_MaterialEditor.RenderQueueField();
        //	m_MaterialEditor.EnableInstancingField();

        EditorGUI.BeginChangeCheck();
        EditorGUI.showMixedValue = _renderQueue.hasMixedValue;
        int renderQueue = EditorGUILayout.IntSlider(_rendererQueueText, (int)_renderQueue.floatValue, 0, 49);

        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_RenderQueue", renderQueue);
            dataChanged = true;
        }

        EditorGUI.BeginChangeCheck();
        eCulling culling = (eCulling)Mathf.RoundToInt(_culling.floatValue);

        EditorGUI.showMixedValue = _culling.hasMixedValue;
        culling = (eCulling)EditorGUILayout.Popup(_cullingModeText, (int)culling, _cullingModeOptions);
        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_Cull", (int)culling);
            dataChanged = true;
        }

        EditorGUI.showMixedValue = false;

        EditorGUI.BeginChangeCheck();
        _materialEditor.ShaderProperty(_pixelSnap, _pixelSnapText);
        if (EditorGUI.EndChangeCheck())
        {
            dataChanged = true;
        }

        return(dataChanged);
    }
Ejemplo n.º 25
0
    public void SetSprite(string atlasName, string spName, eBlendMode blendMode = eBlendMode.Normal, LayerId layerId = LayerId.STGNormalEffect, bool isUsingCache = false)
    {
        _isUsingCache = isUsingCache;
        // 不使用缓存,直接创建
        if (!isUsingCache)
        {
            _effectGo   = ResourceManager.GetInstance().GetPrefab("Prefab/Effects", "SpriteEffect");
            _effectTf   = _effectGo.transform;
            _spRenderer = _effectTf.Find("Sprite").GetComponent <SpriteRenderer>();
            if (blendMode != eBlendMode.Normal)
            {
                _spRenderer.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(blendMode);
            }
            _spRenderer.sprite = ResourceManager.GetInstance().GetSprite(atlasName, spName);
            UIManager.GetInstance().AddGoToLayer(_effectGo, layerId);
        }
        else
        {
            _effectGoName = "SpriteEffect_" + atlasName + "_" + spName + "_" + blendMode;
            _effectGo     = ObjectsPool.GetInstance().GetPrefabAtPool(_effectGoName);
            if (_effectGo == null)
            {
                GameObject protoType = ObjectsPool.GetInstance().GetProtoType(_effectGoName);
                if (protoType == null)
                {
                    protoType      = ResourceManager.GetInstance().GetPrefab("Prefab/Effects", "SpriteEffect");
                    protoType.name = _effectGoName;
                    Transform tf = protoType.transform;
                    tf.localPosition = new Vector3(2000, 2000, 0);
                    SpriteRenderer sr = tf.Find("Sprite").GetComponent <SpriteRenderer>();
                    if (blendMode != eBlendMode.Normal)
                    {
                        sr.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(blendMode);
                    }
                    sr.sprite = ResourceManager.GetInstance().GetSprite(atlasName, spName);
                    UIManager.GetInstance().AddGoToLayer(protoType, LayerId.STGNormalEffect);
                    ObjectsPool.GetInstance().AddProtoType(_effectGoName, protoType);
                }
                _effectGo = GameObject.Instantiate <GameObject>(protoType);
                UIManager.GetInstance().AddGoToLayer(_effectGo, layerId);
            }
            _effectTf   = _effectGo.transform;
            _spRenderer = _effectTf.Find("Sprite").GetComponent <SpriteRenderer>();
        }
        // 获取sprite对象的原始尺寸
        Sprite sp = _spRenderer.sprite;

        if (sp != null)
        {
            Vector3 size = sp.bounds.extents * 2 * sp.pixelsPerUnit;
            _originalWidth  = size.x;
            _originalHeight = size.y;
            // 计算实际尺寸
            _curWidth  = _originalWidth;
            _curHeight = _originalHeight;
        }
        else
        {
            _originalWidth  = 0;
            _originalHeight = 0;
            // 计算实际尺寸
            _curWidth  = 0;
            _curHeight = 0;
        }
    }
Ejemplo n.º 26
0
 public void SetBlendMode(eBlendMode mode)
 {
     _isUsingCache        = false;
     _spRenderer.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(mode);
 }
Ejemplo n.º 27
0
    protected virtual bool RenderModes()
    {
        bool dataChanged = false;

        //Lighting Mode
        dataChanged |= RenderLightingModes();

        //Blend Mode
        {
            eBlendMode blendMode = GetMaterialBlendMode((Material)_materialEditor.target);
            EditorGUI.showMixedValue = false;
            foreach (Material material in _materialEditor.targets)
            {
                if (blendMode != GetMaterialBlendMode(material))
                {
                    EditorGUI.showMixedValue = true;
                    break;
                }
            }

            EditorGUI.BeginChangeCheck();
            blendMode = (eBlendMode)EditorGUILayout.Popup(_blendModeText, (int)blendMode, _blendModeOptions);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _materialEditor.targets)
                {
                    SetBlendMode(mat, blendMode);
                }

                dataChanged = true;
            }
        }

        //	GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel);
        //	m_MaterialEditor.RenderQueueField();
        //	m_MaterialEditor.EnableInstancingField();

        EditorGUI.BeginChangeCheck();
        EditorGUI.showMixedValue = _renderQueue.hasMixedValue;

        _renderQueueAbsolute = EditorGUILayout.Toggle(_rendererQueueAbsoluteText, _renderQueueAbsolute);
        if (!_renderQueueAbsolute && _renderQueueWasAbsolute)
        {
            _renderQueueWasAbsolute = _renderQueueAbsolute;
            int val = ((Material)_materialEditor.targets[0]).renderQueue;
            val = Mathf.Clamp((int)_renderQueue.floatValue - val, 0, 49);
            _renderQueue.floatValue = val;
        }
        else if (_renderQueueAbsolute && !_renderQueueWasAbsolute)
        {
            _renderQueueWasAbsolute = _renderQueueAbsolute;
            _renderQueue.floatValue = ((Material)_materialEditor.targets[0]).renderQueue;
        }
        int renderQueue = _renderQueueAbsolute ? EditorGUILayout.IntSlider(_rendererQueueText, (int)_renderQueue.floatValue, -1, 5000)
                                  : EditorGUILayout.IntSlider(_rendererQueueText, (int)_renderQueue.floatValue, 0, 49);

        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_RenderQueue", renderQueue);
            dataChanged = true;
        }

        EditorGUI.BeginChangeCheck();
        eCulling culling = (eCulling)Mathf.RoundToInt(_culling.floatValue);

        EditorGUI.showMixedValue = _culling.hasMixedValue;
        culling = (eCulling)EditorGUILayout.Popup(_cullingModeText, (int)culling, _cullingModeOptions);
        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_Cull", (int)culling);
            dataChanged = true;
        }

        EditorGUI.showMixedValue = false;

        EditorGUI.BeginChangeCheck();
        _materialEditor.ShaderProperty(_pixelSnap, _pixelSnapText);
        if (EditorGUI.EndChangeCheck())
        {
            dataChanged = true;
        }

        return(dataChanged);
    }
Ejemplo n.º 28
0
    protected virtual bool RenderDepthProperties()
    {
        bool dataChanged = false;

        EditorGUI.BeginChangeCheck();

        bool mixedValue = _writeToDepth.hasMixedValue;

        EditorGUI.showMixedValue = mixedValue;
        bool writeTodepth = EditorGUILayout.Toggle(_depthText, _writeToDepth.floatValue != 0.0f);

        if (EditorGUI.EndChangeCheck())
        {
            SetInt("_ZWrite", writeTodepth ? 1 : 0);
            _depthAlphaCutoff.floatValue = writeTodepth ? 0.5f : 0.0f;
            mixedValue  = false;
            dataChanged = true;
        }

        if (writeTodepth && !mixedValue && GetMaterialBlendMode((Material)_materialEditor.target) != eBlendMode.Opaque)
        {
            EditorGUI.BeginChangeCheck();
            _materialEditor.RangeProperty(_depthAlphaCutoff, _depthAlphaCutoffText.text);
            dataChanged |= EditorGUI.EndChangeCheck();
        }

        {
            bool useCustomRenderType = _customRenderQueue.floatValue > 0.0f;
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = _customRenderQueue.hasMixedValue;
            useCustomRenderType      = EditorGUILayout.Toggle(_customRenderTypetagsText, useCustomRenderType);
            if (EditorGUI.EndChangeCheck())
            {
                dataChanged = true;

                _customRenderQueue.floatValue = useCustomRenderType ? 1.0f : 0.0f;

                foreach (Material material in _materialEditor.targets)
                {
                    eBlendMode blendMode = GetMaterialBlendMode(material);

                    switch (blendMode)
                    {
                    case eBlendMode.Opaque:
                    {
                        SetRenderType(material, "Opaque", useCustomRenderType);
                    }
                    break;

                    default:
                    {
                        bool zWrite = material.GetFloat("_ZWrite") > 0.0f;
                        SetRenderType(material, zWrite ? "TransparentCutout" : "Transparent", useCustomRenderType);
                    }
                    break;
                    }
                }
            }
        }

        EditorGUI.showMixedValue = false;

        return(dataChanged);
    }
Ejemplo n.º 29
0
 public void SetTileColor(Vector2 vLocalPos, TileColor32 tileColor, eBlendMode blendMode = eBlendMode.AlphaBlending)
 {
     SetTileColor((int)(vLocalPos.x / CellSize.x), (int)(vLocalPos.y / CellSize.y), tileColor, blendMode);
 }
Ejemplo n.º 30
0
    static void SetMaterialKeywords(Material material)
    {
        eBlendMode blendMode = (eBlendMode)material.GetFloat("_BlendMode");

        bool normalMap = material.HasProperty("_BumpMap") && material.GetTexture("_BumpMap") != null;

        SetKeyword(material, "_NORMALMAP", normalMap);

        bool zWrite    = material.GetFloat("_ZWrite") > 0.0f;
        bool clipAlpha = zWrite && material.GetFloat("_Cutoff") > 0.0f;

        SetKeyword(material, "_ALPHA_CLIP", clipAlpha);

        bool diffuseRamp = material.HasProperty("_DiffuseRamp") && material.GetTexture("_DiffuseRamp") != null;

        SetKeyword(material, "_DIFFUSE_RAMP", diffuseRamp);

        bool blendTexture = material.HasProperty("_BlendTex") && material.GetTexture("_BlendTex") != null;

        SetKeyword(material, "_TEXTURE_BLEND", blendTexture);

        SetKeyword(material, "_ALPHAPREMULTIPLY_ON", blendMode == eBlendMode.PreMultipliedAlpha);
        SetKeyword(material, "_MULTIPLYBLEND", blendMode == eBlendMode.Multiply);
        SetKeyword(material, "_MULTIPLYBLEND_X2", blendMode == eBlendMode.Multiplyx2);
        SetKeyword(material, "_ADDITIVEBLEND", blendMode == eBlendMode.Additive);
        SetKeyword(material, "_ADDITIVEBLEND_SOFT", blendMode == eBlendMode.SoftAdditive);

        int renderQueue;

        switch (blendMode)
        {
        case eBlendMode.Solid:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetOverrideTag("RenderType", "Opaque");
            renderQueue = kSolidQueue;
        }
        break;

        case eBlendMode.Additive:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetOverrideTag("RenderType", "Transparent");
            renderQueue = kTransparentQueue;
        }
        break;

        case eBlendMode.SoftAdditive:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
            material.SetOverrideTag("RenderType", "Transparent");
            renderQueue = kTransparentQueue;
        }
        break;

        case eBlendMode.Multiply:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
            material.SetOverrideTag("RenderType", "Transparent");
            renderQueue = kTransparentQueue;
        }
        break;

        case eBlendMode.Multiplyx2:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
            material.SetOverrideTag("RenderType", "Transparent");
            renderQueue = kTransparentQueue;
        }
        break;

        case eBlendMode.PreMultipliedAlpha:
        case eBlendMode.StandardAlpha:
        default:
        {
            material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            material.SetOverrideTag("RenderType", zWrite ? "TransparentCutout" : "Transparent");
            renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
        }
        break;
        }

        material.renderQueue = renderQueue + material.GetInt("_RenderQueue");
    }
Ejemplo n.º 31
0
 /// <summary>
 /// Set a tile color in the grid position
 /// </summary>
 /// <param name="gridX"></param>
 /// <param name="gridY"></param>
 /// <param name="color"></param>
 public void SetTileColor(int gridX, int gridY, Color32 color, eBlendMode blendMode = eBlendMode.AlphaBlending)
 {
     SetTileColor(gridX, gridY, new TileColor32(color), blendMode);
 }