Ejemplo n.º 1
0
    protected virtual void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_Menu"));
        }

        if (Input.GetKeyDown(KeyCode.Menu) || Input.GetKeyDown(KeyCode.Return))
        {
            visible = !visible;
        }
    }
Ejemplo n.º 2
0
    private void OnGUI()
    {
        if (!visible)
        {
            return;
        }

        const float initWidth      = 275f;
        float       initHeight     = 70f;
        const float initItemHeight = 30f;

        SS_GUILayout.itemWidth  = initWidth - 20f;
        SS_GUILayout.itemHeight = initItemHeight;
        SS_GUILayout.yPos       = 0f;
        SS_GUILayout.hovered    = false;

        if (SS_GUILayout.IsRuntimePlatformMobile())
        {
            SS_GUILayout.UpdateScaleMobile();
        }
        else
        {
            SS_GUILayout.UpdateScaleDesktop(initHeight + 30f);
        }

        string levelName = Application.loadedLevelName;
        string sceneName = string.Empty;
        string text      = string.Empty;

        switch (levelName)
        {
        case "SS_DiscoLights":
            sceneName = "Disco Lights Scene";
            text      = "    This is an example of a more creative use of Swift Shadows, with hundreds " +
                        "of shadow objects calculated and drawn at the same. All light spots " +
                        "use a special \"light\" material and are rendered within a single draw call.";
            break;

        case "SS_Helicopter":
            sceneName = "Animated Shadows Scene";
            text      = "    This scene demonstrates shadows following the transform of object they " +
                        "are attached to. In this scene, the blades and body of helicopter, as " +
                        "well as the platform and dish of the radar station, are actually two " +
                        "different overlayed shadows. Nevertheless, the shadows are still drawn in a single " +
                        "draw call by using a texture atlas.";
            break;

        case "SS_MovingCubes":
            sceneName = "Moving Cubes Scene";
            text      = "    This is a generic demonstration of what Swift Shadows can do.\n" +
                        "    A raycast from the light source to the cubes determines the position of shadow, " +
                        "and a projected quad is rendered in place. All shadows are drawn with a single " +
                        "draw call, which is especially useful for mobile devices.\n" +
                        "    You can also notice the limitation: shadows are casted on one surface at time and " +
                        "can extend beyond the surface they are projected on. Shadows can be set to fade away " +
                        "as they fall at extreme angles to make this effect less noticeable.";
            break;

        case "SS_MultipleShadows":
            sceneName = "Multiple Shadows Demo";
            text      = "    Multiple shadows components can be set for a single object. " +
                        "There are 4 light sources in this scene, each resulting in a separate shadow of the object.";
            break;

        case "SS_TerrainInteraction":
            initHeight += 25f;
            sceneName   = "Terrain Interaction Demo";
            text        = "    This demonstrates how Swift Shadows can be used on uneven surfaces like terrain.\n" +
                          "    \"Use two cameras\" enables drawing the character and shadow on a separate pass, " +
                          "which eliminates the effect of shadow being clipped with terrain. This comes with the cost " +
                          "of some possible artifacts that aren't noticeable for most situations.\n";
            break;
        }

        if (levelName != "SS_TerrainInteraction")
        {
            if (SS_GUILayout.IsRuntimePlatformMobile())
            {
                text += "\n    You can rotate the camera with two fingers.\n";
            }
            else
            {
                if (levelName == "SS_DiscoLights")
                {
                    text += "\n    You can rotate the camera by holding the right mouse button.\n";
                }
                else
                {
                    text += "\n    You can rotate the camera by holding the right mouse button and zoom with mouse wheel.\n";
                }
            }
        }


        foreach (SS_ShadowMeshManager meshManager in SS_ShadowManager.Instance.ShadowManagers)
        {
            text += string.Format((meshManager.IsStatic ? "\nTotal shadows (static): " : "\nTotal shadows: ") + "{0}, drawn: {1}",
                                  meshManager.ShadowsCount,
                                  meshManager.VisibleShadowsCount);
        }

        var centeredStyle = GUI.skin.label;

        centeredStyle.alignment = TextAnchor.MiddleLeft;

        float textHeight = centeredStyle.CalcHeight(new GUIContent(text, ""), SS_GUILayout.itemWidth);

        initHeight += textHeight;

        GUI.BeginGroup(new Rect(15f, 15f, initWidth, initHeight), sceneName, GUI.skin.window);

        SS_GUILayout.yPos = 20f;

        SS_GUILayout.itemHeight = centeredStyle.CalcHeight(new GUIContent(text, ""), SS_GUILayout.itemWidth);

        SS_GUILayout.Label(text);
        SS_GUILayout.itemHeight = initItemHeight;

        if (levelName == "SS_TerrainInteraction" && TerrainDemoPrimaryCamera != null)
        {
            bool changed;
            _terrainDemoSecondaryCameraOn = SS_GUILayout.Toggle(_terrainDemoSecondaryCameraOn, "Use two cameras", out changed);
            if (changed)
            {
                if (_terrainDemoSecondaryCameraOn)
                {
                    SS_Extensions.SetActive(TerrainDemoSecondaryCamera.gameObject, true);
                    TerrainDemoPrimaryCamera.cullingMask = _terrainDemoPrimaryCameraLayersDefault;
                }
                else
                {
                    SS_Extensions.SetActive(TerrainDemoSecondaryCamera.gameObject, false);
                    TerrainDemoPrimaryCamera.cullingMask = TerrainDemoPrimaryCameraLayers;
                }

                SS_ShadowManager.Instance.UpdateCameraEvents(TerrainDemoSecondaryCamera);
            }
        }

        GUI.color = new Color(1f, 0.6f, 0.6f, 1f);
        if (GUI.Button(new Rect(SS_GUILayout.paddingLeft, initHeight - 40f, SS_GUILayout.itemWidth, 30f), "Back to Main Menu"))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_Menu"));
        }

        GUI.EndGroup();

        GUI.color = Color.white;
        SS_GUILayout.DrawLogo(Logo);
    }
Ejemplo n.º 3
0
 private void OnLevelWasLoaded(int level)
 {
     Screen.sleepTimeout = SleepTimeout.SystemSetting;
     SS_CameraFade.StartAlphaFade(Color.black, true, 0.5f, 0.5f);
 }
Ejemplo n.º 4
0
    private void OnGUI()
    {
        var centeredStyle = GUI.skin.label;

        const float width        = 250f;
        const float buttonHeight = 35f;

        float height     = 155f + buttonHeight * 3f;
        float logoHeight = Logo.height;

        if (Application.isWebPlayer)
        {
            height -= 25f + buttonHeight;
        }

        float totalHeight = height + logoHeight;

        if (SS_GUILayout.IsRuntimePlatformMobile())
        {
            SS_GUILayout.UpdateScaleMobile();
        }
        else
        {
            SS_GUILayout.UpdateScaleDesktop(totalHeight);
        }

        Rect totalRect = new Rect(
            Screen.width / 2f / SS_GUILayout.scaleFactor - width / 2f,
            Screen.height / 2f / SS_GUILayout.scaleFactor - totalHeight / 2f,
            width,
            totalHeight
            );

        Rect logoRect = totalRect;

        logoRect.height = logoHeight;

        Rect rect = totalRect;

        rect.yMin += logoHeight;

        GUILayout.BeginArea(
            logoRect,
            "", ""
            );
        GUILayout.Label(Logo);
        GUILayout.EndArea();

        GUILayout.BeginArea(
            rect,
            "",
            GUI.skin.textArea
            );
        GUILayout.BeginVertical();

        if (GUILayout.Button("Moving cubes", GUILayout.Height(buttonHeight)))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_MovingCubes"));
        }
        if (GUILayout.Button("Animated shadows", GUILayout.Height(buttonHeight)))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_Helicopter"));
        }

        if (GUILayout.Button("Terrain interaction", GUILayout.Height(buttonHeight)))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_TerrainInteraction"));
        }

        if (GUILayout.Button("Disco lights", GUILayout.Height(buttonHeight)))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_DiscoLights"));
        }
        if (GUILayout.Button("Multiple shadows", GUILayout.Height(buttonHeight)))
        {
            SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, () => Application.LoadLevel("SS_MultipleShadows"));
        }

        if (!Application.isWebPlayer)
        {
            GUILayout.Space(20);
            GUI.color = new Color(1f, 0.6f, 0.6f, 1f);
            if (GUILayout.Button("Quit", GUILayout.Height(buttonHeight)))
            {
                SS_CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0f, Application.Quit);
            }
        }

        GUILayout.EndVertical();
        GUILayout.EndArea();

        GUI.color = Color.black;
        centeredStyle.alignment = TextAnchor.UpperLeft;

        if (!SS_GUILayout.IsRuntimePlatformMobile() && !Application.isEditor)
        {
            Screen.fullScreen = GUI.Toggle(
                new Rect(rect.xMin - 90f,
                         rect.yMin,
                         100f, 400f), Screen.fullScreen, " Fullscreen");
        }
        //GUI.Label(new Rect(rect.xMax + 10f,
        //    rect.yMin, Mathf.Min(200f, Screen.width - rect.xMax - 10f), 400f),
        //          "You can press Enter/Menu button to disable GUI (as Unity GUI may cause slowdown, especially on mobile)");
    }
Ejemplo n.º 5
0
 protected virtual void OnLevelWasLoaded(int level)
 {
     Application.targetFrameRate = 10000;
     Screen.sleepTimeout         = SleepTimeout.NeverSleep;
     SS_CameraFade.StartAlphaFade(Color.black, true, 0.5f, 0.5f);
 }