501 lines
14 KiB
C#
Raw Normal View History

2025-02-12 08:43:33 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ZXK.UTility;
/*******************************************************************************
*Create By CG
*Function
*******************************************************************************/
namespace ZXK.BYSS
{
public class AnmCtrl : MonoBehaviour
{
[Header("搬运输送专用")]
public Animation _animation;
[Header("搬运输送工件物体_pCylinder447")]
public GameObject pCylinder447;
[Header("搬运输送工件物体_pCylinder444")]
public GameObject pCylinder444;
public void Byss_pCylinder447_Show() {
Debug.Log("pCylinder4474315帧显示4315-46804315帧数之前隐藏");
pCylinder447.gameObject.SetActive(true);
}
public void Byss_pCylinder447_Hide() {
Debug.Log("pCylinder4474315帧显示4315-46804315帧数之前隐藏");
pCylinder447.gameObject.SetActive(false);
} public void Byss_pCylinder444_Show() {
Debug.Log("pCylinder4444672帧隐藏4672-结束4672帧数之前显示");
pCylinder444.gameObject.SetActive(true);
}
public void Byss_pCylinder444_Hide() {
Debug.Log("pCylinder4444672帧隐藏4672-结束4672帧数之前显示");
pCylinder444.gameObject.SetActive(false);
}
public AudioSource _qibengAudSrc2 = null;
private Animator _anmCtrl = null;
[SerializeField]//充气声音-停止声音
private AudioClip[] _gasAudClip = new AudioClip[2];
private AudioSource _qibengAudSrc = null;
[SerializeField]//四个小球
private GameObject[] _balls = new GameObject[4];
[SerializeField]//三个表针
private Transform[] _arrows = new Transform[3];
[SerializeField]//运行模式三个表针
private Transform[] Running_arrows = new Transform[3];
public void Play_ZDSJS_ReSet()
{
_anmCtrl.SetBool("Is_XHBY_ReSet", true);
_anmCtrl.SetBool("Is_XHBY_Start", false);
}
private void Start()
{
_anmCtrl = transform.GetComponent<Animator>();
_qibengAudSrc = transform.GetComponent<AudioSource>();
BallShowInAnm(3);
ArrowDir(true);
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ)
{
//材料分解模式,正播,反播的默认设置
_anmCtrl.SetFloat("daoSpeed", 1);
}
//材料分拣模式,气动冲压,循环搬运
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ || AppManagement.Instance._CurType == EnumCtrl.Type.QDCY ||
AppManagement.Instance._CurType == EnumCtrl.Type.XHBY || AppManagement.Instance._CurType == EnumCtrl.Type.ZNYD||
AppManagement.Instance._CurType == EnumCtrl.Type.BYSS
)
{
//表针朝上
ZhiZhenXiangHide();
}
}
/// <summary>
/// 关闭声音
/// </summary>
public void BYSS_PlayGasSound()
{
_qibengAudSrc2.clip = _gasAudClip[1];
_qibengAudSrc2.loop = false;
_qibengAudSrc2.Play();
}
///关闭充气1
public void BYSS_CloseGas1() {
_qibengAudSrc.clip = _gasAudClip[1];
_qibengAudSrc.loop = false;
_qibengAudSrc.Play();
_animation.Play("chongqi_1_Close");
Debug.Log("关闭充气1");
}
/// 关闭充气2
public void BYSS_CloseGas2()
{
_qibengAudSrc.clip = _gasAudClip[1];
_qibengAudSrc.loop = false;
_qibengAudSrc.Play();
_animation.Play("chongqi_2_Close");
Debug.Log("关闭充气2");
}
/// <summary>
/// 搬运输送
/// 播放充气1
/// </summary>
public void BYSS_PlayGas1() {
_qibengAudSrc.clip = _gasAudClip[0];
_qibengAudSrc.loop = true;
_qibengAudSrc.Play();
_animation.Play("chongqi_1");
}
/// 搬运输送
/// 播放充气2
/// </summary>
public void BYSS_PlayGas2() {
Debug.Log(this.transform.name+"!!!!!!!!!!!!!!");
_qibengAudSrc2.clip = _gasAudClip[0];
_qibengAudSrc2.loop = true;
_qibengAudSrc2.Play();
_animation.Play("chongqi_2");
// _anmCtrl.SetBool("Is_gas_2", true);
}
public void GasStart()
{
//Debug.Log("充气");
_qibengAudSrc.clip = _gasAudClip[0];
_qibengAudSrc.loop = true;
_qibengAudSrc.Play();
_anmCtrl.SetBool("gas", true);
}
public void AutoGas()
{
_anmCtrl.SetBool("gas", true);
//材料分拣模式,气动冲压
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ || AppManagement.Instance._CurType == EnumCtrl.Type.QDCY|| AppManagement.Instance._CurType == EnumCtrl.Type.XHBY|| AppManagement.Instance._CurType == EnumCtrl.Type.BYSS||
AppManagement.Instance._CurType == EnumCtrl.Type.ZNYD
)
{
//表针朝上
ZhiZhenXiangShang();
}
}
public void StopGasAbleAnm()
{
SendMessageUpwards("StopGasAble");
}
public void GasStop()
{
//Debug.Log("停止充气");
_qibengAudSrc.clip = _gasAudClip[1];
_qibengAudSrc.loop = false;
_qibengAudSrc.Play();
_anmCtrl.SetBool("gas", false);
ArrowDir(false);
//材料分拣模式,气动冲压
if (AppManagement.Instance._CurType == EnumCtrl.Type.CLFJ || AppManagement.Instance._CurType == EnumCtrl.Type.QDCY|| AppManagement.Instance._CurType == EnumCtrl.Type.XHBY
)
{
ZhiZhenXiangShang();
}
}
/// <summary>
/// 关闭动画
/// </summary>
public void CloseAudio() {
_qibengAudSrc.clip = null;
_qibengAudSrc.Stop();
}
//启动
public void RunPlayAnm()
{
//材料分拣模块,特殊设置,每一次啊都判断是正播还是倒播
if (AppManagement.Instance._CurType == UTility.EnumCtrl.Type.CLFJ)
{
if (isZhengBo == true)
{
_anmCtrl.SetBool("run", true);
_anmCtrl.SetFloat("daoSpeed", 1);
// _anmCtrl.speed = 1;
}
else
{
_anmCtrl.SetBool("run", true);
_anmCtrl.SetFloat("daoSpeed", -1);
// _anmCtrl.speed = 1;
}
}
else
{
_anmCtrl.SetBool("run", true);
}
}
//复位
public void RunResetAnm()
{
_anmCtrl.speed = 1;
}
//停止
public void RunStopAnm()
{
_anmCtrl.SetBool("gas", false);
_anmCtrl.SetBool("run", false);
}
//急停
public void RunPauseAnm()
{
_anmCtrl.speed = 0;
}
#region
private bool isZhengBo = false;
//设置为正播
public void RunZhengBo()
{
_anmCtrl.speed = 1;
isZhengBo = true;
_anmCtrl.SetBool("gas", false);
_anmCtrl.SetBool("run", false);
_anmCtrl.SetFloat("daoSpeed", 0);
_anmCtrl.Rebind();
int baseLayerIndex = _anmCtrl.GetLayerIndex("Base Layer");
_anmCtrl.Play("New State", baseLayerIndex);
}
//设置为倒播
public void RunDaoBo()
{
_anmCtrl.speed = 1;
isZhengBo = false;
_anmCtrl.SetBool("gas", false);
_anmCtrl.SetBool("run", false);
_anmCtrl.SetFloat("daoSpeed", 0);
_anmCtrl.Rebind();
int baseLayerIndex = _anmCtrl.GetLayerIndex("Base Layer");
_anmCtrl.Play("New State", baseLayerIndex);
}
#endregion
#region
public void Run_QDCY_ReSet()
{
_anmCtrl.enabled = false;
_anmCtrl.SetBool("IsAuto",true);
_anmCtrl.SetBool("IsShouDong",false);
_anmCtrl.SetBool("gas", false);
_anmCtrl.Rebind();
}
///自动模式-运行
public void Run_QDCY_Auto()
{
_anmCtrl.enabled = true;
_anmCtrl.SetBool("IsAuto",true);
_anmCtrl.SetBool("IsShouDong",false);
_anmCtrl.SetBool("gas", false);
}
///气动冲压-手动模式-运行
public void Run_QDCY_ShouDong()
{
_anmCtrl.enabled = true;
_anmCtrl.SetBool("IsShouDong",true);
_anmCtrl.SetBool("IsAuto",false);
_anmCtrl.SetBool("gas", false);
}
///气动冲压-手动模式-暂停
public void Stop_QDCY_ShouDong()
{
_anmCtrl.SetBool("IsShouDong",false);
_anmCtrl.SetBool("IsAuto",false);
}
///气动冲压-默认初始化
public void Run_QDCY_Init()
{
_anmCtrl.SetBool("IsShouDong",false);
_anmCtrl.SetBool("IsAuto",false);
}
///气动冲压动画要调用的事件
//显示
public void Show_Event()
{
Canvas.gameObject.SetActive(true);
}
//隐藏
public void Hide_Event()
{
Canvas.gameObject.SetActive(false);
}
public GameObject Canvas;
#endregion
public void ZhiZhenXiangHide() {
for (int i = 0; i < _arrows.Length; i++)
{
_arrows[i].gameObject.SetActive(true);
}
for (int i = 0; i < Running_arrows.Length; i++)
{
Running_arrows[i].gameObject.SetActive(false);
}
}
/// <summary>
/// 指针朝向上
/// 运行模式调用
/// </summary>
public void ZhiZhenXiangShang() {
for (int i = 0; i < _arrows.Length; i++) {
_arrows[i].gameObject.SetActive(false);
}
for (int i = 0; i < Running_arrows.Length; i++)
{
Running_arrows[i].gameObject.SetActive(true);
//Running_arrows[0].localRotation = Quaternion.Euler(new Vector3(-29, 0, 0));
//Running_arrows[1].localRotation = Quaternion.Euler(new Vector3(-210, 0, -90));
//Running_arrows[2].localRotation = Quaternion.Euler(new Vector3(-210, 0, -90));
}
}
private void ArrowDir( bool isInit)
{
//for (int i = 0; i < _arrows.Length; i++)
//{
// if (isInit)
// {
// switch (AppManagement.Instance._CurType)
// {
// case UTility.EnumCtrl.Type.XHBY:
// _arrows[0].localRotation = Quaternion.Euler(new Vector3(0, 0, 0));
// break;
// case UTility.EnumCtrl.Type.QDCY:
// _arrows[0].localRotation = Quaternion.Euler(new Vector3(90, 0, -122));
// break;
// }
// _arrows[1].localRotation = Quaternion.Euler(new Vector3(90, 0, -122));
// _arrows[2].localRotation = Quaternion.Euler(new Vector3(90, 0, -122));
// }
// else
// {
// switch (AppManagement.Instance._CurType)
// {
// case UTility.EnumCtrl.Type.XHBY:
// _arrows[0].localRotation = Quaternion.Euler(new Vector3(0, 0, 130));
// break;
// case UTility.EnumCtrl.Type.QDCY:
// _arrows[0].localRotation = Quaternion.Euler(new Vector3(90, 0, 0));
// break;
// }
// _arrows[1].localRotation = Quaternion.Euler(new Vector3(90, 0, 0));
// _arrows[2].localRotation = Quaternion.Euler(new Vector3(90, 0, 0));
// }
//}
}
//第几个球显示
public void BallShowInAnm(int index=-1)
{
for (int i = 0; i < _balls.Length; i++)
{
_balls[i].SetActive(false);
if (index == i)
{
_balls[i].SetActive(true);
}
}
}
public void Set_XHBY_Reset()
{
_anmCtrl.SetBool("Is_XHBY_ReSet", true);
}
public void Play_XHBY_Start()
{
_anmCtrl.SetBool("Is_XHBY_ReSet", false);
_anmCtrl.SetBool("Is_XHBY_Start", true);
}
public void Set_XHBY_Start()
{
_anmCtrl.SetBool("Is_XHBY_Start", false);
_anmCtrl.SetBool("Is_XHBY_ReSet", false);
} public void Set_XHBY_Gas()
{
_anmCtrl.SetBool("gas", false);
}
}
}