370 lines
13 KiB
C#
370 lines
13 KiB
C#
using DefaultNamespace.ProcessMode;
|
|
using DG.Tweening;
|
|
using MotionFramework;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
/// <summary>
|
|
/// 集中器
|
|
/// </summary>
|
|
public class concentrator : MonoBehaviour
|
|
{
|
|
[Header("集中器")]
|
|
/// <summary>
|
|
/// 集中器
|
|
/// </summary>
|
|
public GameObject ConcentratorObj;
|
|
|
|
[Header("集线盒电线动画")]
|
|
/// <summary>
|
|
/// 集线盒电线动画
|
|
/// </summary>
|
|
public SkinnedMeshRenderer ElectricWireSMR;
|
|
|
|
[Header("电线碰撞")]
|
|
/// <summary>
|
|
/// 电线碰撞
|
|
/// </summary>
|
|
public BoxCollider TapeMarCol;
|
|
|
|
[Header("电线前段胶带材质动画")]
|
|
/// <summary>
|
|
/// 电线前段胶带材质动画
|
|
/// </summary>
|
|
public Material TapeMar;
|
|
|
|
/// <summary>
|
|
/// 螺丝是否全部显示
|
|
/// </summary>
|
|
int allls;
|
|
|
|
[Header("是否播放集线器螺丝拆完后电线动画")]
|
|
/// <summary>
|
|
/// 是否播放集线器螺丝拆完后电线动画
|
|
/// </summary>
|
|
public static bool isPlayAni = true;
|
|
|
|
[Header("集中器盖子")]
|
|
/// <summary>
|
|
/// 集中器盖子
|
|
/// </summary>
|
|
public GameObject Cover;
|
|
|
|
[Header("新集中器在电箱中的位置")]
|
|
/// <summary>
|
|
/// 新集中器在电箱中的位置
|
|
/// </summary>
|
|
public Transform oncentratorTrans;
|
|
|
|
[Header("新集中器盖子上左右两颗螺丝")]
|
|
/// <summary>
|
|
/// 新集中器盖子上左右两颗螺丝
|
|
/// </summary>
|
|
public GameObject[] screw;
|
|
|
|
[Header("集中器端子螺丝")]
|
|
/// <summary>
|
|
/// 集中器端子螺丝
|
|
/// </summary>
|
|
public GameObject[] ScrewObj;
|
|
|
|
|
|
public GameObject 透明盖子封印碰撞R;
|
|
public GameObject 透明盖子封印碰撞L;
|
|
|
|
|
|
bool isplaying = true;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
return;
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
bool raycast = Physics.Raycast(ray, out hit);
|
|
if (raycast)
|
|
{
|
|
if (hit.collider.gameObject.name == "新的集中器碰撞")
|
|
{
|
|
ConcentratorObj.gameObject.transform.SetParent(null);
|
|
StartCoroutine(Newconcentrator());
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
|
|
|
|
透明盖子封印碰撞R.GetComponent<BoxCollider>().enabled = true;
|
|
透明盖子封印碰撞L.GetComponent<BoxCollider>().enabled = true;
|
|
}
|
|
|
|
|
|
if (hit.collider.gameObject.name == "JZQ_螺丝1")
|
|
{
|
|
StartCoroutine(TapeBackFrist());
|
|
ScrewObj[0].GetComponent<MeshRenderer>().enabled = true;
|
|
ScrewObj[1].GetComponent<MeshRenderer>().enabled = true;
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
}
|
|
else if (hit.collider.gameObject.name == "JZQ_螺丝2")
|
|
{
|
|
StartCoroutine(TapeBackSecond());
|
|
ScrewObj[2].GetComponent<MeshRenderer>().enabled = true;
|
|
ScrewObj[3].GetComponent<MeshRenderer>().enabled = true;
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
}
|
|
else if (hit.collider.gameObject.name == "JZQ_螺丝3")
|
|
{
|
|
StartCoroutine(TapeBackThird());
|
|
ScrewObj[4].GetComponent<MeshRenderer>().enabled = true;
|
|
ScrewObj[5].GetComponent<MeshRenderer>().enabled = true;
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
}
|
|
else if (hit.collider.gameObject.name == "JZQ_螺丝4")
|
|
{
|
|
StartCoroutine(TapeBackFourth());
|
|
ScrewObj[6].GetComponent<MeshRenderer>().enabled = true;
|
|
ScrewObj[7].GetComponent<MeshRenderer>().enabled = true;
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
}
|
|
else if (hit.collider.gameObject.name == "JZQ_螺丝6")
|
|
{
|
|
StartCoroutine(TapeBackFifth());
|
|
ScrewObj[8].GetComponent<MeshRenderer>().enabled = true;
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
}
|
|
else if (hit.collider.gameObject.name == "JZQ_螺丝7")
|
|
{
|
|
StartCoroutine(TapeBackSixth());
|
|
ScrewObj[9].GetComponent<MeshRenderer>().enabled = true;
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
}
|
|
|
|
// for (int i = 0; i < ScrewObj.Length; i++)
|
|
// {
|
|
// if (hit.collider.gameObject.name == ScrewObj[i].name)
|
|
// {
|
|
// Debug.Log(hit.collider.gameObject.name);
|
|
// //StartCoroutine(IEHubSegmentRowScrews());
|
|
// ScrewObj[i].GetComponent<MeshRenderer>().enabled = true;
|
|
// if (ScrewObj[0].GetComponent<MeshRenderer>().enabled & ScrewObj[1].GetComponent<MeshRenderer>().enabled)
|
|
// {
|
|
// StartCoroutine(TapeBackFrist()); MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
// if (ScrewObj[2].GetComponent<MeshRenderer>().enabled & ScrewObj[3].GetComponent<MeshRenderer>().enabled)
|
|
// {
|
|
// StartCoroutine(TapeBackSecond()); MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
// if (ScrewObj[4].GetComponent<MeshRenderer>().enabled & ScrewObj[5].GetComponent<MeshRenderer>().enabled)
|
|
// {
|
|
// StartCoroutine(TapeBackThird()); MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
// if (ScrewObj[6].GetComponent<MeshRenderer>().enabled & ScrewObj[7].GetComponent<MeshRenderer>().enabled)
|
|
// {
|
|
// StartCoroutine(TapeBackFourth()); MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
// if (ScrewObj[8].GetComponent<MeshRenderer>().enabled)
|
|
// {
|
|
// StartCoroutine(TapeBackFifth()); MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
// if (ScrewObj[9].GetComponent<MeshRenderer>().enabled)
|
|
// {
|
|
// StartCoroutine(TapeBackSixth()); MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
// }
|
|
// }
|
|
if (AreAllObjectsHidden())
|
|
{
|
|
isPlayAni = false;
|
|
//StartCoroutine(IEElectricWire());
|
|
//MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// Debug.Log("所有螺丝都显示");
|
|
}
|
|
|
|
// if (hit.collider.gameObject.name == "JZQ_螺丝007")
|
|
// {
|
|
// MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// }
|
|
|
|
|
|
//if (hit.collider.gameObject.name == "pCylinder170")
|
|
//{
|
|
// if (isplaying)
|
|
// {
|
|
// StartCoroutine(IEElectricWire());// MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
|
// isplaying = false;
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新集中器螺丝全部安装上
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool AreAllObjectsHidden()
|
|
{
|
|
allls = 0;
|
|
for (int i = 0; i < ScrewObj.Length; i++)
|
|
{
|
|
if (ScrewObj[i].gameObject.GetComponent<MeshRenderer>().enabled == true)
|
|
{
|
|
//StartCoroutine(IEElectricWire());
|
|
allls++;
|
|
}
|
|
}
|
|
|
|
if (allls >= ScrewObj.Length)
|
|
{
|
|
StartCoroutine(IEElectricWire());
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新集中器更换动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator Newconcentrator()
|
|
{
|
|
ConcentratorObj.gameObject.transform.DOLocalMove(oncentratorTrans.gameObject.transform.localPosition, 1f); //3.0778f, 2.2149f, -1.4581f
|
|
yield return new WaitForSeconds(1f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器盖子后续动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IEElectricWire()
|
|
{
|
|
TapeMarCol.enabled = false;
|
|
yield return new WaitForSeconds(1f);
|
|
Cover.gameObject.SetActive(true);
|
|
yield return new WaitForSeconds(0.5f);
|
|
Cover.gameObject.transform.DOLocalMove(new Vector3(0, 0.01672375f, -0.09654188f), 1f);
|
|
yield return new WaitForSeconds(1.1f);
|
|
screw[0].gameObject.SetActive(true);
|
|
yield return new WaitForSeconds(1.0f);
|
|
screw[1].gameObject.SetActive(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 第一个螺丝和第二个安装完成后卸下胶带和电线安装的动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator TapeBackFrist()
|
|
{
|
|
TapeMar.SetFloat("_step_p1", 0);
|
|
if (ElectricWireSMR.GetBlendShapeWeight(0) != 0 && ElectricWireSMR.GetBlendShapeWeight(0) == 100)
|
|
{
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(0, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator TapeBackSecond()
|
|
{
|
|
TapeMar.SetFloat("_step_p2", 0);
|
|
if (ElectricWireSMR.GetBlendShapeWeight(1) != 0 && ElectricWireSMR.GetBlendShapeWeight(1) == 100)
|
|
{
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(1, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator TapeBackThird()
|
|
{
|
|
TapeMar.SetFloat("_step_p3", 0);
|
|
if (ElectricWireSMR.GetBlendShapeWeight(2) != 0 && ElectricWireSMR.GetBlendShapeWeight(2) == 100)
|
|
{
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(2, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator TapeBackFourth()
|
|
{
|
|
TapeMar.SetFloat("_step_p4", 0);
|
|
if (ElectricWireSMR.GetBlendShapeWeight(3) != 0 && ElectricWireSMR.GetBlendShapeWeight(3) == 100)
|
|
{
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(3, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator TapeBackFifth()
|
|
{
|
|
TapeMar.SetFloat("_step_p5", 0);
|
|
if (ElectricWireSMR.GetBlendShapeWeight(4) != 0 && ElectricWireSMR.GetBlendShapeWeight(4) == 100)
|
|
{
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(4, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator TapeBackSixth()
|
|
{
|
|
TapeMar.SetFloat("_step_p6", 0);
|
|
if (ElectricWireSMR.GetBlendShapeWeight(5) != 0 && ElectricWireSMR.GetBlendShapeWeight(5) == 100)
|
|
{
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(5, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 胶带还原&和电线还原动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//IEnumerator IETapeBackFrist()
|
|
//{
|
|
|
|
// yield return new WaitForSeconds(1f);
|
|
// TapeMar.SetFloat("_step_p6", 0);
|
|
// yield return new WaitForSeconds(1f);
|
|
// TapeMar.SetFloat("_step_p5", 0);
|
|
// yield return new WaitForSeconds(1f);
|
|
// TapeMar.SetFloat("_step_p4", 0);
|
|
// yield return new WaitForSeconds(1f);
|
|
// TapeMar.SetFloat("_step_p3", 0);
|
|
// yield return new WaitForSeconds(1f);
|
|
// TapeMar.SetFloat("_step_p2", 0);
|
|
// yield return new WaitForSeconds(1f);
|
|
// TapeMar.SetFloat("_step_p1", 0);
|
|
// yield return new WaitForSeconds(1f);
|
|
//}
|
|
} |