stevefsp / critterai

Archive of CAINav Project (Inactive)
MIT License
126 stars 75 forks source link

fix some problem on Unity 5.2,replace deprecated shader #28

Open wuxinwei opened 8 years ago

wuxinwei commented 8 years ago
public static Material SimpleMaterial
{
    get
    {
        if (!mSimpleMaterial)
        {
            /* /// Unity 5.2 DO NOT support Line/Colored Blended anymore
            mSimpleMaterial = new Material(
                "Shader \"Lines/Colored Blended\" {"
                + "SubShader { Pass { "
                + " BindChannels { Bind \"Color\",color } "
                + " Blend SrcAlpha OneMinusSrcAlpha "
                + " ZWrite Off Cull Off Fog { Mode Off } "
                + "} } }");
            */
            /// using Hidden/Internal-Colored to replace
            //////////////////////////////////////////////////////
            var drawLine = Shader.Find("Hidden/Internal-Colored");
            mSimpleMaterial = new Material(drawLine);
            //////////////////////////////////////////////////////
            mSimpleMaterial.hideFlags = HideFlags.HideAndDontSave;
            mSimpleMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
        }
        return mSimpleMaterial;
    }
}
KellanHiggins commented 8 years ago

The other option is to include a "Resources" file or point to a file with the AssetDatabase instead and load it from there. I had a similar problem with a Shader I could no longer use in Unity 5.

wuxinwei commented 8 years ago

@KellanHiggins ,yeah, that's another way to fix this, but I still use unity5.2 built-in shader may be better, anyway thany you for your advise.

stevefsp commented 8 years ago

Hi All,

Yeah, there is going to be a lot of small Unity incompatibilities building up in this old project. If your solution doesn't work in all situations, here is the full Unity recommended configuration. Found it somewhere when I was upgrading code in the utilities project:

        /// <summary>
        /// A shared material suitable for simple drawing operations. 
        /// </summary>
        public static Material SimpleMaterial
        {
            get
            {
                if (!mSimpleMaterial)
                {
                    var shader = Shader.Find("Hidden/Internal-Colored");
                    mSimpleMaterial = new Material(shader);
                    mSimpleMaterial.hideFlags = HideFlags.HideAndDontSave;
                    // Turn on alpha blending
                    mSimpleMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                    mSimpleMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    // Turn backface culling off
                    mSimpleMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
                    // Turn off depth writes
                    mSimpleMaterial.SetInt("_ZWrite", 0);
                }
                return mSimpleMaterial;
            }
        }
wuxinwei commented 8 years ago

ok, thanks again, Stephen