반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 집 정리
- Collection Framework
- 나지보
- 아이폰
- 자바
- 안드로이드 Application Lifecycle
- 벨팡
- 안드로이드
- 스랄 특성
- 비행기 모드
- 리눅스
- 아이패드
- 소캣(Socket)
- 명령어
- TCP 네트워크 방식의 연결
- 게임
- 변경된 정보
- 컬렉션 프레임
- tcp
- 에셋
- unity
- 포트(Port)
- game
- 히오스
- 어플
- End of Darkness
- php 홈디렉토리 변경방법
- 기업의 행포
- tcp네트워크
- 나지보 특성
Archives
- Today
- Total
Do Something IT
Unity TweenMaterialColor 본문
반응형
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TweenMaterialColor : MonoBehaviour { public enum ETweenType { Pingpong, Ones } public ETweenType Type; public AnimationCurve Corve; public string TargetColorName; public Color ColorStart = Color.white; public Color ColorEnd = Color.clear; public float Duration = 1.0f; public Action EndAction; private readonly List_materialList = new List (); private readonly List _rendererList = new List (); protected bool Flag = false; protected float TempDuration; // Use this for initialization private void Start() { TempDuration = Duration; RecurSetFixedRenderQueue(transform, _materialList); SetColor(ColorStart); } internal void Action(bool p, float duration = 0) { if (Flag == p) return; if (0 < duration) { TempDuration = Duration; Duration = duration; } Flag = p; if (p) PlayForward(); else PlayReverse(); } public void PlayForward() { if (Type != ETweenType.Ones) return; StartCoroutine(Play(ColorStart, ColorEnd)); } public void PlayReverse() { if (Type != ETweenType.Ones) return; StartCoroutine(Play(ColorEnd, ColorStart)); } private IEnumerator Play(Color starColor, Color endColor) { var playTime = 0f; while (playTime < Duration) { playTime += Time.deltaTime; var value = Corve.Evaluate(playTime); SetColor(Color.Lerp(starColor, endColor, value)); yield return null; } SetColor(endColor); if (Math.Abs(Duration - TempDuration) > 0) Duration = TempDuration; if (EndAction != null) EndAction(); } public bool IsActive() { return Flag; } public void Update() { if (Type != ETweenType.Pingpong) return; var lerp = Mathf.PingPong(Time.time, Duration)/Duration; var value = Corve.Evaluate(lerp); SetColor(Color.Lerp(ColorStart, ColorEnd, value)); } private void SetColor(Color col) { for (var i = 0; i < _rendererList.Count; i++) { _rendererList[i].material.SetColor(TargetColorName, col); } for (var i = 0; i < _materialList.Count; i++) { _materialList[i].SetColor(TargetColorName, col); } } private void RecurSetFixedRenderQueue(Transform t, List materialList) { var ren = t.renderer; if (ren != null) { if (ren.enabled) { _rendererList.Add(ren); } var mats = ren.materials; if (mats != null) { for (int i = 0; i < mats.Length; i++) { var mat = mats[i]; materialList.Add(mat); } } } var particles = t.GetComponents (); if (particles != null) { for (int i = 0; i < particles.Length; i++) { if (particles[i].renderer.enabled) { _rendererList.Add(particles[i].renderer); } var mats = particles[i].renderer.materials; for (int m = 0; m < mats.Length; m++) { materialList.Add(mats[m]); } } } for (int i = 0; i < t.childCount; i++) { var child = t.GetChild(i); RecurSetFixedRenderQueue(child, materialList); } } }
반응형
'Unity3D' 카테고리의 다른 글
Unity plugin Didn't find class "com.unity3d.player.UnityPlayerNativeActivity (0) | 2020.04.05 |
---|---|
ugui 마우스 포인트 RectTransform에 위치해있는지 확인 (0) | 2020.03.04 |
UniRx Mouse Drag (0) | 2018.11.15 |
[Unity] Multiple Camera One RenderTexture Capture (여러대 카메라 한장으로 캡쳐하기) (0) | 2018.03.08 |
유니티 Ngui 체팅창 bbcord 이벤트 받기 (0) | 2018.01.10 |
Comments