Auto disappears between scenes in unity, not working on OSX

I just imported my project into the unity of my mac. I have a Unity License and I use Unity 4.6.3 on both computers (windows 8 PC) and OS X yosemite. When I test my project on a computer (windows), automatic fading works fine, but when I do it on my mac, it waits for time between scenes, but it only puts the screen in black, without fading. This is the script:

using UnityEngine;
using System.Collections;

public class AutoFade : MonoBehaviour
{
    private static AutoFade m_Instance = null;
    private Material m_Material = null;
    private string m_LevelName = "";
    private int m_LevelIndex = 0;
    private bool m_Fading = false;

    private static AutoFade Instance
    {
        get
        {
            if (m_Instance == null)
            {
                m_Instance = (new GameObject("AutoFade")).AddComponent<AutoFade>();
            }
            return m_Instance;
        }
    }
    public static bool Fading
    {
        get { return Instance.m_Fading; }
    }

    private void Awake()
    {
        DontDestroyOnLoad(this);
        m_Instance = this;
        m_Material = new Material("Shader \"Plane/No zTest\" { SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Off Fog { Mode Off } BindChannels { Bind \"Color\",color } } } }");
    }

    private void DrawQuad(Color aColor,float aAlpha)
    {
        aColor.a = aAlpha;
        m_Material.SetPass(0);
        GL.Color(aColor);
        GL.PushMatrix();
        GL.LoadOrtho();
        GL.Begin(GL.QUADS);
        GL.Vertex3(0, 0, -1);
        GL.Vertex3(0, 1, -1);
        GL.Vertex3(1, 1, -1);
        GL.Vertex3(1, 0, -1);
        GL.End();
        GL.PopMatrix();
    }

    private IEnumerator Fade(float aFadeOutTime, float aFadeInTime, Color aColor)
    {
        float t = 0.0f;
        while (t<1.0f)
        {
            yield return new WaitForEndOfFrame();
            t = Mathf.Clamp01(t + Time.deltaTime / aFadeOutTime);
            DrawQuad(aColor,t);
        }
        if (m_LevelName != "")
            Application.LoadLevel(m_LevelName);
        else
            Application.LoadLevel(m_LevelIndex);
        while (t>0.0f)
        {
            yield return new WaitForEndOfFrame();
            t = Mathf.Clamp01(t - Time.deltaTime / aFadeInTime);
            DrawQuad(aColor,t);
        }
        m_Fading = false;
    }
    private void StartFade(float aFadeOutTime, float aFadeInTime, Color aColor)
    {
        m_Fading = true;
        StartCoroutine(Fade(aFadeOutTime, aFadeInTime, aColor));
    }

    public static void LoadLevel(string aLevelName,float aFadeOutTime, float aFadeInTime, Color aColor)
    {
        if (Fading) return;
        Instance.m_LevelName = aLevelName;
        Instance.StartFade(aFadeOutTime, aFadeInTime, aColor);
    }
    public static void LoadLevel(int aLevelIndex,float aFadeOutTime, float aFadeInTime, Color aColor)
    {
        if (Fading) return;
        Instance.m_LevelName = "";
        Instance.m_LevelIndex = aLevelIndex;
        Instance.StartFade(aFadeOutTime, aFadeInTime, aColor);
    }
}
+4
source share
3 answers

The problem is that Unity on Windows uses DirectX, not OpenGL, so it works there (as mentioned in the comments to your question).

Unity -force-opengl Windows, , .

. http://answers.unity3d.com/questions/447206/forcing-opengl-in-windows-editor.html

, . .

. http://answers.unity3d.com/questions/55392/why-my-glcolor-doesnt-work.html

:.

Shader "Unlit Transparent Vertex Colored" 
{
    Properties 
    {
        _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    }

    Category 
    {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
        ZWrite Off
        //Alphatest Greater 0
        Blend SrcAlpha OneMinusSrcAlpha 
        Fog { Color(0,0,0,0) }
        Lighting Off
        Cull Off //we can turn backface culling off because we know nothing will be facing backwards

        BindChannels 
        {
            Bind "Vertex", vertex
            Bind "texcoord", texcoord 
            Bind "Color", color 
        }

        SubShader   
        {
            Pass 
            {
                SetTexture [_MainTex] 
                {
                    Combine texture * primary
                }
            }
        } 
    }
}

https://github.com/edbartley/BombaFiesta-Unity3D-Futile/blob/master/Assets/Resources/Shaders/UnlitTransparentVertexColored.shader

- Assets/Resources, . test.shader Awake() :

private void Awake()
{
    DontDestroyOnLoad(this);
    m_Instance = this;
    var shader = Shader.Find("Unlit Transparent Vertex Colored"); // <= it some kind of best practise to put shaders in separate files, and load them like this
    m_Material = new Material(shader);
}

Shader.Find http://docs.unity3d.com/ScriptReference/Shader.Find.html

, GL.Begin() GL DrawQuad().

private void DrawQuad(Color aColor,float aAlpha)
{
    aColor.a = aAlpha;
    m_Material.SetPass(0);

    GL.Begin(GL.QUADS); // <= put it here
    GL.Color(aColor);
    GL.PushMatrix();
    GL.LoadOrtho();
    GL.Vertex3(0, 0, -1);
    GL.Vertex3(0, 1, -1);
    GL.Vertex3(1, 1, -1);
    GL.Vertex3(1, 0, -1);
    GL.End();
    GL.PopMatrix();
}

.: -)

, - !

:

, .

, OpenGL, Windows Unity 4.6.3, -force-opengl, ( , OpenGL).

. http://answers.unity3d.com/questions/447206/forcing-opengl-in-windows-editor.html

, , OpenGL, DirectX.

"DrawQuad" :

private void DrawQuad(Color aColor, float aAlpha)
{
    aColor.a = aAlpha;
    Texture2D texture = new Texture2D(1, 1);
    texture.SetPixel(0, 0, aColor);
    texture.Apply();
    GUI.skin.box.normal.background = texture;
    GUI.Box(new Rect(0, 0, Screen.width, Screen.height), GUIContent.none);
} 

. http://forum.unity3d.com/threads/draw-a-simple-rectangle-filled-with-a-color.116348/

0

API GL ES 2.0 . Metal Metal, Unity 4.6.3.

0

According to the documentation for GL.Color, it can only be called between the GL.Begin and GL.End functions. Your GL.Color call happens before GL.Begin.

0
source

All Articles