[Asset] [Unity Asset] Screen Flasher (chớp màn hình)

Dang_KhoaDang_Khoa Posts: 3,861Administrators
[chapter]Giới thiệu[/chapter]
Asset giúp tạo hiệu ứng chớp màn hình, có thể dùng để tạo hiệu ứng chớp màn hình khi sấm sét, hiệu ứng chớp màn hình khi chụp ảnh màn hình...

[chapter]Sử dụng[/chapter]
[thank]
Cú pháp:
ScreenFlasher.instance.StartFlashScreen (color,startDuration, holdDuration, endDuration);
Với:
  • color: màu, ví dụ Color.white là màu trắng
  • startDuration: khoảng thời gian sáng lên
  • holdDuration: khoảng thời gian màn hình sáng nhất
  • endDuration: khoảng thời gian màn hình tối lại
Ví dụ:
ScreenFlasher.instance.StartFlashScreen (Color.white, 0.2f, 0.2f, 0.2f);
[/thank]
[chapter]Asset[/chapter]
Bạn chịu khó trả lời bài viết mới nhìn thấy nha
:3 :3 :3
[hide]
using UnityEngine;
using System.Collections;

//====================================================================================================
/// <summary>
/// Screen flasher.
/// </summary>
//====================================================================================================
public class ScreenFlasher : MonoBehaviour
{

private static ScreenFlasher _instance;
public Color color = Color.white;
public Coroutine behaviorFlash;
private Texture2D sampleTexture;

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the instance.
/// </summary>
/// <value>The instance.</value>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public static ScreenFlasher instance {
get {
if (_instance == null) {
var obj = new GameObject ("ScreenFlasher");
_instance = obj.AddComponent<ScreenFlasher> ();
} 
return _instance;
}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Awake this instance.
/// </summary>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public void Awake ()
{
sampleTexture = new Texture2D (1, 1);
color.a = 0;
// Refresh ();
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Raises the destroy event.
/// </summary>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public void OnDestroy ()
{
Destroy (sampleTexture);
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Refresh this instance.
/// </summary>
//----------------------------------------------------------------------------------------------------------------------------------------------------
// private void Refresh ()
// {
// 
// }
//

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Raises the GU event.
/// </summary>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public void OnGUI ()
{
if (behaviorFlash != null) {
sampleTexture.SetPixel (0, 0, color);
sampleTexture.Apply ();
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), sampleTexture);
}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Starts the flash screen.
/// </summary>
/// <returns>The flash screen.</returns>
/// <param name="color">Color.</param>
/// <param name="flashInDuration">Flash in duration.</param>
/// <param name="holdDuration">Hold duration.</param>
/// <param name="flashOutDuration">Flash out duration.</param>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public Coroutine StartFlashScreen (Color color, float startDuration = 0.2f, float holdDuration = 0.2f, float endDuration = 0.2f)
{
return behaviorFlash = StartCoroutine (FlashScreen (color, startDuration, holdDuration, endDuration));
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Stops the flash screen.
/// </summary>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public void StopFlashScreen ()
{
if (behaviorFlash != null) {
StopCoroutine (behaviorFlash);
color.a = 0;
}
behaviorFlash = null;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Routines the flash screen.
/// </summary>
/// <returns>The flash screen.</returns>
//----------------------------------------------------------------------------------------------------------------------------------------------------
protected IEnumerator FlashScreen (Color color, float startDuration, float holdDuration, float endDuration)
{
this.color = color;
yield return StartCoroutine (FlashIn (startDuration));
yield return new WaitForSeconds (holdDuration);
yield return StartCoroutine (FlashOut (endDuration));
yield break;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Flashs the in.
/// </summary>
/// <returns>The in.</returns>
/// <param name="flashInDuration">Flash in duration.</param>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public IEnumerator FlashIn (float flashInDuration)
{
float t = 0;
color.a = 0;
// Refresh ();
while (t < 1) {
yield return 0;
t += Time.deltaTime / flashInDuration;
color.a = (Mathf.Lerp (0, 1, t));
// Refresh ();
}
yield break;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// Flashs the out.
/// </summary>
/// <returns>The out.</returns>
/// <param name="flashOutDuration">Flash out duration.</param>
//----------------------------------------------------------------------------------------------------------------------------------------------------
public IEnumerator FlashOut (float flashOutDuration)
{
float t = 0;
color.a = 1;
// Refresh ();
while (t < 1) {
yield return 0;
t += Time.deltaTime / flashOutDuration;
color.a = (Mathf.Lerp (1, 0, t));
// Refresh ();
}
yield break;
}
}
[/hide]

[chapter]Điều khoản sử dụng[/chapter]
Bạn có quyền thay đổi code mà không cần xin phép tác giả.
Vui lòng credit Dang_Khoa và http://taotrochoi.com trong sản phẩm của bạn khi sử dụng script này.

Comments

  • kumuzukumuzu Posts: 669Registered
  • heavenhell8899heavenhell8899 Posts: 2Registered
    tks ad rất hay
  • leequangsonleequangson Posts: 730Registered
    Ad chơi lầy thế :v
  • Black FaceBlack Face Posts: 424Registered
    Ko chơi, hư màn hình 6.png
  • Dang_KhoaDang_Khoa Posts: 3,861Administrators
    Black Face wrote:
    Ko chơi, hư màn hình 6.png

    Không xài thì thôi, để các bạn khác xài nghe hơm
    ;) ;) ;)
  • kOriskOris Posts: 153Registered
    Dang_Khoa wrote:
    [chapter]Giới thiệu[/chapter]
    Asset giúp tạo hiệu ứng chớp màn hình, có thể dùng để tạo hiệu ứng chớp màn hình khi sấm sét, hiệu ứng chớp màn hình khi chụp ảnh màn hình...

    [chapter]Sử dụng[/chapter]

    [chapter]Asset[/chapter]
    Bạn chịu khó trả lời bài viết mới nhìn thấy nha
    :3 :3 :3


    [chapter]Điều khoản sử dụng[/chapter]
    Bạn có quyền thay đổi code mà không cần xin phép tác giả.
    Vui lòng credit Dang_Khoa và http://taotrochoi.com trong sản phẩm của bạn khi sử dụng script này.

    Để tét coi sao đã :3
    Working as a freelancer. Currently holding a games project with 180k lines of code and still not finished yet (Just like YanDev)
  • Dang_KhoaDang_Khoa Posts: 3,861Administrators
    Dang_Khoa wrote:
    [chapter]Giới thiệu[/chapter]
    Asset giúp tạo hiệu ứng chớp màn hình, có thể dùng để tạo hiệu ứng chớp màn hình khi sấm sét, hiệu ứng chớp màn hình khi chụp ảnh màn hình...

    [chapter]Sử dụng[/chapter]

    [chapter]Asset[/chapter]
    Bạn chịu khó trả lời bài viết mới nhìn thấy nha
    :3 :3 :3


    [chapter]Điều khoản sử dụng[/chapter]
    Bạn có quyền thay đổi code mà không cần xin phép tác giả.
    Vui lòng credit Dang_Khoa và http://taotrochoi.com trong sản phẩm của bạn khi sử dụng script này.

    Để tét coi sao đã :3

    Từ VX nhảy qua Unity rồi sao
    :P :P :P
  • BướmBướm Posts: 1,220Registered
    Unity à, ngon
  • 0no012340no01234 Posts: 326Registered
    Mở khóa trc còn khi nào dùng đến lục lại sau :v
  • Dang_KhoaDang_Khoa Posts: 3,861Administrators
    Mòi người dùng Unity nhiều thế thì để post thêm vài cái hay hay
    :)) :)) :))
  • kOriskOris Posts: 153Registered
    0no01234 wrote:
    Mở khóa trc còn khi nào dùng đến lục lại sau :v

    :v Bác gần giống em, tuy code hay nhưng ram đang yếu nên sẽ lục lại khi ram đủ,
    giờ xài mỗi RPG MAKER thì không lag, sài Unity thì lagg vãi đái ý :v
    Mà sắp nâng ram rồi  xD
    Working as a freelancer. Currently holding a games project with 180k lines of code and still not finished yet (Just like YanDev)
  • Dang_KhoaDang_Khoa Posts: 3,861Administrators
    0no01234 wrote:
    Mở khóa trc còn khi nào dùng đến lục lại sau :v

    :v Bác gần giống em, tuy code hay nhưng ram đang yếu nên sẽ lục lại khi ram đủ,
    giờ xài mỗi RPG MAKER thì không lag, sài Unity thì lagg vãi đái ý :v
    Mà sắp nâng ram rồi  xD

    Có khi nào lag là do dùng Visual Studio không, thằng đấy nặng lắm
    :< :< :<
  • kOriskOris Posts: 153Registered
    Dang_Khoa wrote:

    :v Bác gần giống em, tuy code hay nhưng ram đang yếu nên sẽ lục lại khi ram đủ,
    giờ xài mỗi RPG MAKER thì không lag, sài Unity thì lagg vãi đái ý :v
    Mà sắp nâng ram rồi  xD

    Có khi nào lag là do dùng Visual Studio không, thằng đấy nặng lắm
    :< :< :<

    Chắc vậy ::v Mà nâng ram lên vẫn lag thì thôi em nghỉ làm Unity  :( :(
    Working as a freelancer. Currently holding a games project with 180k lines of code and still not finished yet (Just like YanDev)
Sign In or Register to comment.