Created
March 24, 2020 13:05
-
-
Save mtytheone/be496c53fc37d21c55f37eb13f78f578 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEngine.UI; | |
public class Slide : MonoBehaviour | |
{ | |
[SerializeField] string _texturePropertyName; | |
[SerializeField] List<Texture2D> _slideTextureList; | |
[SerializeField] MeshRenderer _leftSlide; | |
[SerializeField] MeshRenderer _rightSlide; | |
int _propertyID; | |
[SerializeField] InputField _field; | |
Text _placeholder; | |
Animator _animator; | |
int _index; | |
void Start() | |
{ | |
//取得 | |
_animator = this.gameObject.GetComponent<Animator>(); | |
_propertyID = Shader.PropertyToID(_texturePropertyName); | |
_placeholder = _field.placeholder.GetComponent<Text>(); | |
//初期化 | |
_index = 0; | |
_leftSlide.sharedMaterial = null; | |
_rightSlide.material.SetTexture(_propertyID, _slideTextureList[_index]); | |
//index番号を送信 | |
int displayindex = _index + 1; | |
_placeholder.text = displayindex.ToString(); | |
} | |
void Update() | |
{ | |
} | |
public void OnBack() //戻る処理 | |
{ | |
if (_index > 0) | |
{ | |
_index--; | |
_leftSlide.material.SetTexture(_propertyID, _slideTextureList[_index + 1]); | |
_rightSlide.material.SetTexture(_propertyID, _slideTextureList[_index]); | |
_animator.Play("Back", 0, 0); | |
//index番号を送信 | |
int displayindex = _index + 1; | |
_placeholder.text = displayindex.ToString(); | |
} | |
} | |
public void OnNext() //進む処理 | |
{ | |
if (_index < _slideTextureList.Count - 1) | |
{ | |
_index++; | |
_leftSlide.material.SetTexture(_propertyID, _slideTextureList[_index]); | |
_rightSlide.material.SetTexture(_propertyID, _slideTextureList[_index - 1]); | |
_animator.Play("Next", 0, 0); | |
//index番号を送信 | |
int displayindex = _index + 1; | |
_placeholder.text = displayindex.ToString(); | |
} | |
} | |
public void OnIndex() //直接数値を入力する処理 | |
{ | |
int index = int.Parse(_field.text); | |
if (0 <= index - 1 && index - 1 <= _slideTextureList.Count - 1) | |
{ | |
if (index > _index) | |
{ | |
_leftSlide.material.SetTexture(_propertyID, _slideTextureList[index - 1]); | |
_rightSlide.material.SetTexture(_propertyID, _slideTextureList[_index]); | |
_index = index - 1; | |
_animator.Play("Next", 0, 0); | |
} | |
else if (index < _index) | |
{ | |
_leftSlide.material.SetTexture(_propertyID, _slideTextureList[_index]); | |
_rightSlide.material.SetTexture(_propertyID, _slideTextureList[index - 1]); | |
_index = index - 1; | |
_animator.Play("Back", 0, 0); | |
} | |
} | |
_field.text = null; | |
int displayindex = _index + 1; | |
_placeholder.text = displayindex.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment