|
|
|
@ -1,29 +1,229 @@ |
|
|
|
using System.Collections; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
using UnityEngine.EventSystems; |
|
|
|
|
|
|
|
using UnityEngine.UI; |
|
|
|
public class CharacterBehaviour : MonoBehaviour { |
|
|
|
public class CharacterBehaviour : MonoBehaviour { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
private bool standby = true; |
|
|
|
|
|
|
|
|
|
|
|
public Material mat; |
|
|
|
public Material mat; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Area area; |
|
|
|
|
|
|
|
public Vector2 WallROI; |
|
|
|
|
|
|
|
public float wallDistance = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
private RectTransform m_recttrans; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DShowClip standbyclip; |
|
|
|
|
|
|
|
public DShowClip TriggerClip; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
private DShowMoviePlayer[] players; |
|
|
|
|
|
|
|
private MeshRenderer m_meshRender; |
|
|
|
|
|
|
|
public Color color; |
|
|
|
|
|
|
|
private bool isSleep; |
|
|
|
private void Awake() |
|
|
|
private void Awake() |
|
|
|
{ |
|
|
|
{ |
|
|
|
mat = new Material(Shader.Find("Standard")); |
|
|
|
m_meshRender = GetComponent<MeshRenderer>(); |
|
|
|
GetComponent<MeshRenderer>().material = mat; |
|
|
|
mat = new Material(Shader.Find("Unlit/ColorTransparent")); |
|
|
|
|
|
|
|
m_meshRender.material = mat; |
|
|
|
List<Material> mats = new List<Material>(); |
|
|
|
List<Material> mats = new List<Material>(); |
|
|
|
mats.Add(mat); |
|
|
|
mats.Add(mat); |
|
|
|
GetComponent<MovieTextureApply>().materials = mats; |
|
|
|
InitialDSPlayer(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InitialDSPlayer() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GameObject TriggerObj = new GameObject("Trigger"); |
|
|
|
|
|
|
|
TriggerObj.transform.parent = this.transform; |
|
|
|
|
|
|
|
SetClip(TriggerObj.AddComponent<DShowMoviePlayer>(), TriggerClip); |
|
|
|
|
|
|
|
GameObject standbyObj = new GameObject("Standby"); |
|
|
|
|
|
|
|
standbyObj.transform.parent = this.transform; |
|
|
|
|
|
|
|
SetClip(standbyObj.AddComponent<DShowMoviePlayer>(), standbyclip); |
|
|
|
|
|
|
|
players = GetComponentsInChildren<DShowMoviePlayer>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SetClip(DShowMoviePlayer player,DShowClip clip) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
player.VideoAsset = clip; |
|
|
|
|
|
|
|
player.Load(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InitialTouchButton() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (m_recttrans != null) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
GameObject obj = new GameObject(gameObject.name); |
|
|
|
|
|
|
|
obj.transform.parent = GameObject.Find("Final Canvas").transform; |
|
|
|
|
|
|
|
m_recttrans = obj.AddComponent<RectTransform>(); |
|
|
|
|
|
|
|
m_recttrans.anchorMin = new Vector2(0, 0); |
|
|
|
|
|
|
|
m_recttrans.anchorMax = new Vector2(0, 0); |
|
|
|
|
|
|
|
m_recttrans.pivot = new Vector2(0.5f, 0.5f); |
|
|
|
|
|
|
|
m_recttrans.sizeDelta = new Vector2(transform.localScale.x, transform.localScale.y) * FrozenScreenToWorldSpace.Instance.finalPixelsByMeter; |
|
|
|
|
|
|
|
m_recttrans.gameObject.AddComponent<RawImage>(); |
|
|
|
|
|
|
|
m_recttrans.GetComponent<RawImage>().color = new Color(1, 1, 1, 0); |
|
|
|
|
|
|
|
TouchArea toucharea = m_recttrans.gameObject.AddComponent<TouchArea>(); |
|
|
|
|
|
|
|
toucharea.PointerDown.AddListener((data)=> { Trigger(data); }); |
|
|
|
|
|
|
|
toucharea.PointerDrag.AddListener((data) => { Trigger(data); }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use this for initialization |
|
|
|
// Use this for initialization |
|
|
|
void Start () { |
|
|
|
void Start () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
standby = true; |
|
|
|
|
|
|
|
isSleep = false; |
|
|
|
|
|
|
|
mat.mainTextureScale = new Vector2(1, -1); |
|
|
|
|
|
|
|
mat.mainTextureOffset = new Vector2(0,-1); |
|
|
|
|
|
|
|
StartCoroutine(PlayOnStart()); |
|
|
|
|
|
|
|
InitialTouchButton(); |
|
|
|
|
|
|
|
RandomAppearWall(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator PlayOnStart() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
DShowMoviePlayer player = currentPlayer; |
|
|
|
|
|
|
|
player.Loop = true; |
|
|
|
|
|
|
|
while (!player.IsPlaying) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
player.Play(); |
|
|
|
|
|
|
|
yield return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame |
|
|
|
// Update is called once per frame |
|
|
|
void Update () { |
|
|
|
void Update () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.R)) |
|
|
|
|
|
|
|
RandomAppearWall(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!isSleep) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!standby) |
|
|
|
|
|
|
|
CheckPlayFinished(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateMaterial() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mat.mainTexture = currentPlayer.Texture; |
|
|
|
|
|
|
|
mat.SetColor("_Color", color); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CheckPlayFinished() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(currentPlayer.IsFinished) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StartCoroutine(Sleep()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RandomAppearWall() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Vector3 newPos = Vector3.zero; |
|
|
|
|
|
|
|
area = (Area)Random.Range(0, 3); |
|
|
|
|
|
|
|
Quaternion q = new Quaternion(); |
|
|
|
|
|
|
|
if (area == Area.LeftWall) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
newPos.x = -FrozenScreenToWorldSpace.Instance.length / 2 + wallDistance; |
|
|
|
|
|
|
|
q.SetLookRotation(Vector3.left); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (area == Area.RightWall) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
newPos.x = FrozenScreenToWorldSpace.Instance.length / 2 - wallDistance; |
|
|
|
|
|
|
|
q.SetLookRotation(Vector3.right); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (area == Area.TopWall) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
newPos.z = FrozenScreenToWorldSpace.Instance.width / 2 - wallDistance; |
|
|
|
|
|
|
|
q.SetLookRotation(Vector3.forward); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
transform.rotation = q; |
|
|
|
|
|
|
|
transform.localPosition = newPos; |
|
|
|
|
|
|
|
RandomPos(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UpdatePos() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Vector3 n_pos = transform.localPosition; |
|
|
|
|
|
|
|
if (area == Area.TopWall) |
|
|
|
|
|
|
|
n_pos.x = Mathf.Lerp(-FrozenScreenToWorldSpace.Instance.length / 2, FrozenScreenToWorldSpace.Instance.length / 2, WallROI.x); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
n_pos.z = Mathf.Lerp(-FrozenScreenToWorldSpace.Instance.width / 2, FrozenScreenToWorldSpace.Instance.width / 2, WallROI.x); |
|
|
|
|
|
|
|
n_pos.y = Mathf.Lerp(0, (float)FrozenScreenToWorldSpace.Instance.height, WallROI.y); |
|
|
|
|
|
|
|
transform.localPosition = n_pos; |
|
|
|
|
|
|
|
SetButtonPos(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RandomPos() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Vector3 randomPos = transform.localPosition; |
|
|
|
|
|
|
|
float minX = transform.localScale.x / 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (randomPos.x == 0) |
|
|
|
|
|
|
|
WallROI.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.length - minX) / FrozenScreenToWorldSpace.Instance.length; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
WallROI.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.width - minX) / FrozenScreenToWorldSpace.Instance.width; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WallROI.y = Random.Range(0.5f, FrozenCharacterController.Instance.Maxheight) / (float)FrozenScreenToWorldSpace.Instance.height; |
|
|
|
|
|
|
|
UpdatePos(); |
|
|
|
|
|
|
|
SetButtonPos(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SetButtonPos() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Vector2 newScreenPos = FrozenScreenToWorldSpace.Instance.GetFinalScreenPos(area, WallROI); |
|
|
|
|
|
|
|
m_recttrans.anchoredPosition = newScreenPos; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Trigger(PointerEventData data) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!standby || isSleep) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
standby = false; |
|
|
|
|
|
|
|
currentPlayer.Play(); |
|
|
|
|
|
|
|
mat.mainTexture = currentPlayer.Texture; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Idle() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
standby = true; |
|
|
|
|
|
|
|
currentPlayer.Play(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DShowMoviePlayer currentPlayer { get { return players[System.Convert.ToInt32(standby)]; } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator Sleep() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
isSleep = true; |
|
|
|
|
|
|
|
currentPlayer.Pause(); |
|
|
|
|
|
|
|
currentPlayer.Frame = 0; |
|
|
|
|
|
|
|
yield return StartCoroutine(Fade(0)); |
|
|
|
|
|
|
|
m_meshRender.enabled = false; |
|
|
|
|
|
|
|
yield return new WaitForSeconds(FrozenCharacterController.Instance.GetDisAppear()); |
|
|
|
|
|
|
|
RandomAppearWall(); |
|
|
|
|
|
|
|
standby = true; |
|
|
|
|
|
|
|
currentPlayer.Play(); |
|
|
|
|
|
|
|
mat.mainTexture = currentPlayer.Texture; |
|
|
|
|
|
|
|
m_meshRender.enabled = true; |
|
|
|
|
|
|
|
yield return StartCoroutine(Fade(1)); |
|
|
|
|
|
|
|
isSleep = false; |
|
|
|
|
|
|
|
Idle(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator Fade(float targetA) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
float value = 0; |
|
|
|
|
|
|
|
float origin = color.a; |
|
|
|
|
|
|
|
while(value < 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
value = Mathf.Clamp(value + Time.deltaTime, 0,1); |
|
|
|
|
|
|
|
color.a = Mathf.Lerp(origin, targetA, value); |
|
|
|
|
|
|
|
yield return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|