You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
211 lines
5.6 KiB
211 lines
5.6 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class MapDoor : MonoBehaviour |
|
{ |
|
[System.Serializable] |
|
public class Teleport |
|
{ |
|
public MapBlock blk; |
|
public MapDoor door; |
|
} |
|
|
|
//private void OnEnable() |
|
//{ |
|
// if (anim != null) |
|
// { |
|
// anim.clip = clipOpen; |
|
// Util.AnimationPlay(null, anim, anim.clip.name, true, null); |
|
// } |
|
//} |
|
//private void OnDisable() |
|
//{ |
|
// if (anim != null) |
|
// Util.AnimationStop(anim, clipOpen.name); |
|
//} |
|
|
|
public GameObject doorModel; |
|
public Animation anim; |
|
public AnimationClip clipOpen; |
|
public AnimationClip clipClose; |
|
public Transform way; |
|
[Space(10)] |
|
public MapBlock doorBlock; |
|
public MapDoor doorConnect; |
|
public void Connect(MapBlock blk, MapDoor door) |
|
{ |
|
OPEN = false; |
|
|
|
doorBlock = blk; |
|
doorConnect = door; |
|
doorModel.SetActive(door != null); |
|
|
|
if (anim != null) |
|
Util.AnimationStop(anim, clipOpen.name); |
|
} |
|
public void OnEvent(int type, object value) |
|
{ |
|
switch ((MapEvent)type) |
|
{ |
|
case MapEvent.DoorInit: |
|
{ |
|
CHECK = OPEN = false; |
|
|
|
if (anim != null) |
|
Util.AnimationPlay(this, anim, clipOpen.name, true, null); |
|
//Util.AnimationStop(anim, clipOpen.name); |
|
} |
|
break; |
|
case MapEvent.DoorState: |
|
{ |
|
if (!(bool)value && OPEN) |
|
{ |
|
DoorClose(); |
|
} |
|
//아래 코드 실행 시 이동 했던 문만 열려있음 |
|
//else if ((bool)value && OPEN) |
|
//아래 코드 실행 시 일반 블럭의 문은 항상 열림 |
|
else if ((bool)value && !NEED_KEY) |
|
{ |
|
//OPEN = false; |
|
DoorOpen(null, null); |
|
} |
|
else if((bool)value && OPEN && NEED_KEY) |
|
{ |
|
DoorOpen(null, null); |
|
} |
|
|
|
CHECK = (bool)value; |
|
} |
|
break; |
|
case MapEvent.Register_OnItemUse: |
|
{ |
|
ItemUseRegister register = (ItemUseRegister)value; |
|
OnItemUse = register.OnItemUse; |
|
OnTeleport = register.OnTeleport; |
|
OnLock = register.OnLock; |
|
} |
|
break; |
|
} |
|
} |
|
[Space(10)] |
|
public Collider col; |
|
void DoorPass(bool PASS) |
|
{ |
|
if (col != null) |
|
col.enabled = !PASS; |
|
} |
|
void DoorClose() |
|
{ |
|
DoorPass(false); |
|
|
|
anim.clip = clipClose; |
|
Util.AnimationPlay(this, anim, anim.clip.name, false, null); |
|
} |
|
public void DoorOpen(GameObject target, System.Action OnEnd = null) |
|
{ |
|
if (!OPEN) |
|
{ |
|
anim.clip = clipOpen; |
|
Util.AnimationPlay(this, anim, anim.clip.name, false, () => |
|
{ |
|
DoorPass(true); |
|
OPEN = true; |
|
|
|
Teleport_Character(target, OnEnd); |
|
|
|
if (doorConnect == null && effectPortal != null) |
|
effectPortal.SetActive(true); |
|
}); |
|
|
|
if (doorConnect != null) |
|
{ |
|
doorConnect.OPEN = true; |
|
Util.AnimationStop(doorConnect.anim, doorConnect.clipClose.name); |
|
} |
|
} |
|
else |
|
{ |
|
if (anim.clip == clipClose) |
|
{ |
|
anim.clip = clipOpen; |
|
Util.AnimationPlay(this, anim, anim.clip.name, false, () => |
|
{ |
|
DoorPass(true); |
|
OPEN = true; |
|
|
|
Teleport_Character(target, OnEnd); |
|
|
|
if (doorConnect == null && effectPortal != null) |
|
effectPortal.SetActive(true); |
|
}); |
|
|
|
if (doorConnect != null) |
|
{ |
|
doorConnect.OPEN = true; |
|
Util.AnimationStop(doorConnect.anim, doorConnect.clipClose.name); |
|
} |
|
} |
|
else |
|
{ |
|
OPEN = true; |
|
|
|
Teleport_Character(target, OnEnd); |
|
} |
|
} |
|
} |
|
void Teleport_Character(GameObject target, System.Action OnEnd) |
|
{ |
|
if (target != null) |
|
{ |
|
tel.blk = doorBlock; |
|
tel.door = doorConnect; |
|
|
|
if (OnTeleport != null) |
|
OnTeleport(tel); |
|
} |
|
else |
|
{ |
|
if (OnEnd != null) |
|
OnEnd(); |
|
} |
|
} |
|
|
|
public GameObject effectPortal; |
|
public void PortalSetting(GameObject effect) |
|
{ |
|
doorBlock = null; |
|
doorConnect = null; |
|
|
|
effectPortal = effect; |
|
|
|
effectPortal.transform.SetParent(transform); |
|
effectPortal.transform.localPosition = new Vector3(0, 1, 2); |
|
|
|
effectPortal.SetActive(false); |
|
} |
|
|
|
[Space(10)] |
|
public bool CHECK = false; |
|
public bool OPEN = false; |
|
[Space(10)] |
|
public bool NEED_KEY = false; |
|
ItemUse OnItemUse; |
|
System.Action<Teleport> OnTeleport; |
|
System.Action<bool> OnLock; |
|
Teleport tel = new Teleport(); |
|
void OnTriggerEnter(Collider other) |
|
{ |
|
if (CHECK && other.CompareTag("Our")) |
|
{ |
|
if(!OPEN && NEED_KEY && !OnItemUse("Key", 1)) |
|
return; |
|
|
|
if (OnLock != null) |
|
OnLock(true); |
|
|
|
DoorOpen(other.gameObject); |
|
} |
|
} |
|
}
|
|
|