Super Knight : Enter the Dungeon
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.
 
 
 
 

226 lines
5.7 KiB

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
[System.Serializable]
public class DropItemData
{
public string idx;
[Space(10)]
[OnlyRead]
public int value = 1;
public int minValue = 1;
public int maxValue = 1;
[Space(10)]
public int dropRate = 1000;
public int Get()
{
int random1 = Random.Range(0, 1001);
//Debug.LogWarning($"{random1} < dropRate");
value = random1 < dropRate ? Random.Range(minValue, maxValue + 1) : 0;
return value;
}
static public DropItemData Create(string idx, int value)
{
DropItemData data = new DropItemData();
data.idx = idx;
data.value = value;
return data;
}
}
[System.Serializable]
public class DropItemShadow
{
public string type = "default";
public Projector projector;
}
public class DropItem : MonoBehaviour
{
public SpriteRenderer sprite;
public Material matDefault;
public Material matOutLine;
public ShaderControlValue scvShine;
public Material matShine;
public ShaderControlValue scvHit;
public Material matHit;
public TextMeshPro text;
[Space(10)]
Projector projector;
public List<DropItemShadow> shadows;
[Space(10)]
public ItemData item;
[Space(10)]
public bool PRODUCT = false;//상점 아이템
Rigidbody rigidbody;
Collider col;
Vector3 pos;
/// <summary>
/// 해당 아이템을 처음으로 드랍 했습니다.
/// 테이블에서 해당 아이템을 새로 생성합니다.
/// </summary>
/// <param name="data"></param>
public void Drop_First(DropItemData data, bool LOCK = false)
{
this.LOCK = LOCK;
item = ItemData.Copy(DataManager.Instance.dataItem.Search(data.idx), data.value);
OnInitialized();
if(this.LOCK)
Invoke("LockRelease", 1f);
}
/// <summary>
/// 보유 중이던 아이템을 드랍 했습니다.
/// </summary>
/// <param name="item"></param>
public void Drop_Again(ItemData item)
{
LOCK = true;
//this.item = item;
this.item = ItemData.Copy(item, 1);
OnInitialized();
Invoke("LockRelease", 1f);
}
public void OnInitialized(bool PRODUCT = false)
{
this.PRODUCT = PRODUCT;
text.text = $"{item.price}";
text.gameObject.SetActive(PRODUCT);
//sprite.sprite = SpriteManager.Instance.SpriteGet($"AtlasIngame", $"item{item.idx}");
sprite.sprite = SpriteManager.Instance.SpriteGet($"Item/item{item.idx}");
sprite.gameObject.SetActive(true);
switch (item.type)
{
case "Weapon":
case "Armor":
case "Accessory":
sprite.material = matOutLine;
break;
case "Pickup":
case "Use":
sprite.material = matShine;
scvShine.Init(matShine, true, true);
scvShine.gameObject.SetActive(true);
break;
default:
sprite.material = matDefault;
break;
}
if (0 < shadows.Count)
{
if (projector != null)
projector.gameObject.SetActive(false);
DropItemShadow shadow = shadows.Find(a => a.type.Equals(item.type));
projector = shadow == null ? shadows[0].projector : shadow.projector;
projector.gameObject.SetActive(true);
}
if (rigidbody == null)
rigidbody = GetComponent<Rigidbody>();
if (rigidbody != null)
{
pos = transform.position;
Vector3 pos2 = Util.PointCreate(0.1f, 0.5f);
pos += pos2;
pos.y = 2f;
transform.position = pos;
pos = Util.PointCreate(30f, 100f);
pos.y = 450;
rigidbody.constraints = RigidbodyConstraints.None;
rigidbody.freezeRotation = true;
rigidbody.AddForce(pos);
}
DropSound(item.type);
}
private void OnDisable()
{
//OnGain = null;
//LOCK = true;
//item = null;
scvShine.gameObject.SetActive(false);
}
public bool SOUND = true;
public void DropSound(string type)
{
if (SOUND)
{
SoundPlayer sp = SoundManager.Instance.PrefabGet($"Sound/SFX item_drop_{type.ToLower()}");
if (sp != null)
SoundManager.Instance.EffectPlay(sp.gameObject);
}
}
[Space(10)]
public bool LOCK = false;
void LockRelease()
{
LOCK = false;
}
public System.Action<GameObject, DropItem> OnGain;
//private void OnCollisionEnter(Collision collision)
//{
// if (LOCK)
// return;
// if (OnGain != null)
// OnGain(collision.gameObject, this);
//}
private void OnTriggerEnter(Collider other)
{
if (LOCK)
return;
if (OnGain != null)
OnGain(other.gameObject, this);
}
public Animation anim;
public System.Action OnApply;
public void OnAnimaionStart(System.Action OnApply)
{
if (col == null)
col = GetComponent<Collider>();
rigidbody.velocity = Vector3.zero;
col.enabled = false;
rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
rigidbody.freezeRotation = true;
sprite.material = matHit;
scvHit.Init(matHit, true);
scvHit.gameObject.SetActive(true);
anim.Play();
this.OnApply = OnApply;
}
public void OnAnimationEnd()
{
if (col == null)
col = GetComponent<Collider>();
col.enabled = true;
if (OnApply != null)
OnApply();
}
}