Files
TaiWan/Assets/Roaming/Extenders/ModelPlayerEx/Scripts/ModelPlayerEx.cs

136 lines
2.8 KiB
C#
Raw Normal View History

2025-10-31 15:20:38 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ModelPlayerEx : MonoBehaviour
{
public static ModelPlayerEx Instance;
private void Awake()
{
Instance = this;
}
public ModelController ctrlModel;
public GameObject objPanelModel;
public Transform tranModelParent;
public Text txtTitle;
public Text txtDetails;
public Transform imgModel;
public bool ModelSeted;
public bool IsDetailShow;
GameObject tmp;
static bool FirstShow = true;
Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
}
public void ShowModel(Data info, GameObject obj)
{
if (FirstShow)
{
OnBtnHelpClick();
FirstShow = false;
}
BaseController.CanControl = false;
AudioManager.Instance.PauseBackgroundMusic();
objPanelModel.SetActive(true);
tmp = Instantiate(obj, tranModelParent);
tmp.transform.localPosition = new Vector3(0, 0, 0);
tmp.transform.localRotation = Quaternion.identity;
// tmp.transform.localScale = Vector3.one * 3;
tmp.layer = LayerMask.NameToLayer("Model");
foreach (var item in tmp.GetComponentsInChildren<Transform>())
{
item.gameObject.layer = LayerMask.NameToLayer("Model");
}
ctrlModel.model = tmp;
ctrlModel.imgModel = imgModel;
txtTitle.text = info.Title;
txtDetails.text = info.DataDetails[0];
Invoke("SetModel", 1f);
}
void SetModel()
{
ModelSeted = true;
}
public void OnBtnCloseClick()
{
BaseController.CanControl = true;
objPanelModel.SetActive(false);
IsDetailShow = false;
Destroy(tmp);
imgModel.transform.localScale = Vector3.one;
AudioManager.Instance.ResumeBackgroundMusic();
if (anim.GetCurrentAnimatorClipInfo(0).Length > 0)
{
AnimationClip clip = anim.GetCurrentAnimatorClipInfo(0)[0].clip;
anim.Play(clip.name, 0, 1);
}
}
public void OnBtnAnimClick()
{
if (tmp != null)
{
Animator anim = tmp.GetComponentInChildren<Animator>();
if(anim != null)
{
anim.SetTrigger("Show");
}
}
}
public GameObject pnlDetail;
public void OnBtnDetailClick()
{
pnlDetail.SetActive(!pnlDetail.activeSelf);
IsDetailShow = pnlDetail.activeSelf;
}
bool isShowHelp;
public void OnBtnHelpClick()
{
if (!isShowHelp)
{
anim.SetTrigger("ShowHelp");
isShowHelp = true;
}
}
public void OnShowHelpEnded()
{
isShowHelp = false;
}
}