using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
public class SceneEventCmptLogic : MonoBehaviour
{
public enum SceneCmptDropType
{
///
/// 空的
///
Empty,
///
/// 掉落 拾取获得
///
Drop,
///
/// 更改 修改数据
///
Alter,
}
GameObject interactiveObj;
Button btnInteractive;
Scrollbar loadingBar;
float nowCollectTime = 0;
///
/// 使用该组件 交互
///
bool isUse = false;
private bool isLive = true;
///
/// 功能 名称
///
/// [Header("机关组件")]
public string sceneCmptName = "";
///
/// 功能 描述
///
public string sceneCmptDesc = "";
///
/// 机关自身 播放动画名称
///
public string sceneCmptAnim = "";
///
/// 机关动画是否循环
///
public bool isCmptAnimLoop = false;
[Header("掉落类型")]
public SceneCmptDropType dropType = SceneCmptDropType.Alter;
///
/// 道具ID
///
public int itemDropId;
///
/// 最小数量
///
[Tooltip("DropType为Drop时生效")]
public int mindNumber;
///
/// 最大数量
///
[Tooltip("DropType为Drop时生效")]
public int maxNumber;
///
/// 给予概率
///
[Tooltip("DropType为Drop时生效")]
public float probability = 1;
public float liveTime = 3.5f;
public int dialogIndex = 0;
// 完成后是否销毁
public bool isDestroy = false;
///
/// 角色播放动画
///
[Header("角色控制")]
public string palyAnim = "";
///
/// 是否循环
///
public bool isLoop = false;
///
/// 是否可以移动
///
public bool isMove = false;
///
/// 是否可以用技能
///
public bool isSkill = false;
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
SceneEventCmpt info = this.gameObject.GetComponent();
this.sceneCmptAnim = info.sceneCmptAnim;
this.sceneCmptDesc = info.sceneCmptDesc;
this.sceneCmptName = info.sceneCmptName;
this.dropType = (SceneEventCmptLogic.SceneCmptDropType)info.dropType;
this.isCmptAnimLoop = info.isCmptAnimLoop;
this.itemDropId = info.itemDropId;
this.mindNumber = info.mindNumber;
this.maxNumber = info.maxNumber;
this.probability = info.probability;
this.liveTime = info.liveTime;
this.dialogIndex = info.dialogIndex;
this.isDestroy = info.isDestroy;
this.palyAnim = info.palyAnim;
this.isLoop = info.isLoop;
this.isMove = info.isMove;
this.isSkill = info.isSkill;
}
// Update is called once per frame
void Update()
{
if(isUse)
{
nowCollectTime += Time.deltaTime;
loadingBar.size = nowCollectTime / liveTime;
if (loadingBar.size >= 1)
{
loadingBar.size = 1;
CmptTrigger();
}
}
}
public void OnCollisionEnter(Collision collision)
{
}
public void OnCollisionExit(Collision collision)
{
}
public void OnCollisionStay(Collision collision)
{
}
public void OnTriggerEnter(Collider collider)
{
if(!isLive)
{
return;
}
Role role = collider.GetComponent();
BattleCanvas battlePanel = UI_BaseMainWindow.Instance().battleCanvas;
interactiveObj = battlePanel.transform.Find("Main/Interactive").gameObject;
interactiveObj.SetActive(true);
GameObject interactiveBtnObj = battlePanel.transform.Find("Main/Interactive/collect").gameObject;
loadingBar = battlePanel.transform.Find("Main/Interactive/collectBar").gameObject.GetComponent();
loadingBar.gameObject.SetActive(false);
loadingBar.size = 0;
isUse = false;
nowCollectTime = 0;
UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.NpcDialog, (_btn) =>
{
OnClickInteractive();
});
}
public void OnTriggerExit(Collider collider)
{
UI_BaseMainWindow.Instance().HideInteractive();
}
public void OnClickInteractive()
{
loadingBar.gameObject.SetActive(true);
isUse = true;
}
public void CmptTrigger()
{
isUse = false;
isLive = false;
loadingBar.gameObject.SetActive(false);
switch(dropType)
{
case SceneCmptDropType.Empty:
return;
case SceneCmptDropType.Alter:
if (itemDropId != 0 && Random.Range(probability, 1) >= 1.0f)
{
ItemProxy.Instance.AddItem(itemDropId, Random.Range(mindNumber, maxNumber));
}
break;
case SceneCmptDropType.Drop:
DropManager.Instance.DropItems(itemDropId, this.transform.position);
break;
}
btnInteractive.onClick.RemoveAllListeners();
btnInteractive.gameObject.SetActive(false);
interactiveObj.gameObject.SetActive(false);
PanelHelper.Instance.ShowPanel("UI_TipsWindow",(panel)=> {
UI_TipsWindow.InitStaticDialog(this.sceneCmptName, this.sceneCmptDesc, null);
});
if (isDestroy)
{
Destroy(this.gameObject);
}
}
}