Created
April 24, 2020 02:22
-
-
Save DongguemYoo/98e687edff4c90927b9cd38b52c307df to your computer and use it in GitHub Desktop.
unity getter setter 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System; | |
public class TextShift : MonoBehaviour | |
{ | |
public Material material; | |
public GameObject RootObj; | |
public CapsuleCollider[] allCoilliders; | |
float firstvalue = 0; | |
float centerValue = 0.34f; | |
float lastValue = 0.7f; | |
/// <summary> | |
/// 특정값(회전값)이 들어오면 회전값 만큼 텍스쳐를 시프팅 하는 기능 | |
/// </summary> | |
private float currentOffsetValue; | |
public float CurrentOffsetValue | |
{ | |
get { return currentOffsetValue; } | |
set | |
{ | |
OnShifting(value);//해당 변수가 set 되면 시프팅 함수 실행 | |
currentOffsetValue = value; | |
} | |
} | |
private void Start() | |
{ | |
CollistionInit(); | |
} | |
void CollistionInit() | |
{ | |
if (RootObj == null) | |
return; | |
allCoilliders = RootObj.GetComponentsInChildren<CapsuleCollider>(); | |
this.GetComponent<Cloth>().capsuleColliders = allCoilliders; | |
} | |
//원하는 값으로 텍스쳐를 시프팅 하는 함수 | |
public void OnShifting(float value) | |
{ | |
if (cor_shifting != null) | |
{ | |
StopCoroutine(cor_shifting); | |
cor_shifting = null; | |
} | |
cor_shifting = textureShifting(value); | |
StartCoroutine(cor_shifting); | |
} | |
IEnumerator cor_shifting; | |
IEnumerator textureShifting(float value) | |
{ | |
float addvalue = 0.00005f; | |
while (material.mainTextureOffset.y < value) | |
{ | |
material.mainTextureOffset = new Vector2(1f, material.mainTextureOffset.y + addvalue); | |
addvalue += 0.00005f; | |
yield return new WaitForEndOfFrame(); | |
} | |
while (material.mainTextureOffset.y > value) | |
{ | |
material.mainTextureOffset = new Vector2(1f, material.mainTextureOffset.y - addvalue); | |
addvalue += 0.00005f; | |
yield return new WaitForEndOfFrame(); | |
} | |
material.mainTextureOffset = new Vector2(1f, value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment