333 lines
14 KiB
C#
333 lines
14 KiB
C#
using CG.Framework;
|
|
using CG.UTility;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 部件拆装-顺序拆装控制
|
|
*******************************************************************************/
|
|
namespace ZXK.GYJQR
|
|
{
|
|
public class OrderSplitCtrl : MonoBehaviour
|
|
{
|
|
private Dictionary<string, GameObject> _selectGeoDic = new Dictionary<string, GameObject>();
|
|
|
|
private string _curShowModelName;
|
|
private BJCJ_SXCJ _curStep;
|
|
|
|
private TimelineDirectorCtrl _curTimeLineCtrl = null;
|
|
|
|
public TimelineDirectorCtrl _timeLineJXZTCtrl = null;
|
|
public TimelineDirectorCtrl _timeLineKZGCtrl = null;
|
|
|
|
//鼠标按下后没有位移才触发点击操作
|
|
private bool _mouseDown = false;
|
|
private Vector2 _mouseMove = Vector2.zero;
|
|
|
|
|
|
public void Enter()
|
|
{
|
|
if (GameManager.Instance._StateContext.GetState().Name.Equals("ExamState"))
|
|
{
|
|
PopUpMng.PopToast("请根据任务提示,进行部件拆解", -1, UIGroup.Main);
|
|
}
|
|
else
|
|
{
|
|
PopUpMng.PopToast("可在左侧操作栏中按顺序或逆序点选环节,进行拆拼", -1, UIGroup.Main);
|
|
}
|
|
transform.GetChild(0).gameObject.SetActive(false);
|
|
transform.GetChild(1).gameObject.SetActive(false);
|
|
gameObject.SetActive(true);
|
|
_curShowModelName = GameManager.Instance._DataBJCJHandler._ShowPartsName.Value;
|
|
transform.Find(_curShowModelName).gameObject.SetActive(true);
|
|
if (_curShowModelName.Equals(ConstCtrl.BJCZ_MAINMODEL1_NAME))
|
|
{
|
|
_curTimeLineCtrl = _timeLineJXZTCtrl;
|
|
}
|
|
else if (_curShowModelName.Equals(ConstCtrl.BJCZ_MAINMODEL2_NAME))
|
|
{
|
|
_curTimeLineCtrl = _timeLineKZGCtrl;
|
|
}
|
|
_curTimeLineCtrl?.PlayForward();
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.OnValueChanged += OnDismountStepChanged;
|
|
_selectGeoDic = new Dictionary<string, GameObject>();
|
|
AddHightCol();
|
|
}
|
|
public void End()
|
|
{
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.OnValueChanged -= OnDismountStepChanged;
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.SetDefault();
|
|
_curTimeLineCtrl?.Stop();
|
|
gameObject.SetActive(false);
|
|
}
|
|
private void Update()
|
|
{
|
|
if (!PopUpMng._TriAble) return;
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
_mouseDown = true;
|
|
_mouseMove = Vector2.zero;
|
|
}
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
if (_mouseDown)
|
|
{
|
|
float mouse_x = Input.GetAxis("Mouse X");
|
|
float mouse_y = Input.GetAxis("Mouse Y");
|
|
_mouseMove += new Vector2(mouse_x, mouse_y);
|
|
}
|
|
}
|
|
if (Input.GetMouseButtonUp(0)&&_mouseMove==Vector2.zero)
|
|
{
|
|
_mouseDown = false;
|
|
_mouseMove = Vector2.zero;
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit rayHit;
|
|
|
|
if (PopUpMng._TriAble && Physics.Raycast(ray, out rayHit, Mathf.Infinity))
|
|
{
|
|
System.Action<GameObject> myaction = (geo) =>
|
|
{
|
|
|
|
if (GameManager.Instance._StateContext.GetState().Name.Equals("ExamState"))
|
|
{
|
|
BJCJ_SXCJ curBJCJ = GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName];
|
|
if (GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName].itemGeo.Contains(geo.name))
|
|
{//考核模式点击对了得分
|
|
GameManager.Instance._DataBJCJHandler.AddScore(curBJCJ.stepName, curBJCJ.stepNameChild, curBJCJ.score);
|
|
}
|
|
else
|
|
{//点击错了提示错误
|
|
GameObject examPanelGeo = UI_Manage.Instance.GetPanel("BJCZExamPanel");
|
|
examPanelGeo?.GetComponent<BJCZExamPanel>().ErroTipShow(curBJCJ.caoZuo);
|
|
}
|
|
}
|
|
if (GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName].itemGeo.Contains(geo.name))
|
|
{
|
|
BJCJ_SXCJ nextBJCJ = GameManager.Instance._DataBJCJHandler.GetSXCJNextInfo(GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName].id.ToString());
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.SetValue(_curShowModelName, nextBJCJ);
|
|
}
|
|
};
|
|
if (rayHit.transform.GetComponent<OutLineRender>())
|
|
{
|
|
rayHit.transform.SendMessage("TriCallAction", myaction);
|
|
}
|
|
else
|
|
{
|
|
rayHit.transform.SendMessageUpwards("TriCallAction", myaction);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
End();
|
|
}
|
|
private void OnDismountStepChanged(Dictionary<string, BJCJ_SXCJ> obj)
|
|
{
|
|
Show(obj[_curShowModelName]);
|
|
}
|
|
private void Show(BJCJ_SXCJ partData)
|
|
{
|
|
if (_curStep == null) _curStep = partData;
|
|
if (_curStep.stepNameChild == partData.stepNameChild)
|
|
{//跳转相同步骤,可能是展示物体之间跳转,不涉及正反播放
|
|
BJCZSceneCtrl._Instance._isPlaySplitAnm = true;
|
|
_curTimeLineCtrl.ContinuePlayForwardByPausePoint(partData.AnmStartTime, () =>
|
|
{
|
|
BJCZSceneCtrl._Instance._isPlaySplitAnm = false;
|
|
if (partData.caoZuo.Equals("over"))
|
|
{
|
|
BJCJ_SXCJ firstBJCJ = GameManager.Instance._DataBJCJHandler._SXCJDataArray[_curShowModelName][0];
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.SetValue(_curShowModelName, firstBJCJ);
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName] = firstBJCJ;
|
|
SetModelLightCol(GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName], true);
|
|
_curStep = firstBJCJ;
|
|
}
|
|
else
|
|
{
|
|
SetModelLightCol(_curStep, false);
|
|
GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName] = partData;
|
|
SetModelLightCol(GameManager.Instance._DataBJCJHandler._CurDismountStephandler.GetValue()[_curShowModelName], true);
|
|
_curStep = partData;
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{//跳转不同步骤,可能是点击上下步产生的,每次点击上下步对应的跳转是上下步里面的第一个小步骤
|
|
BJCZSceneCtrl._Instance._isPlaySplitAnm = true;
|
|
if (_curStep.id > partData.id)
|
|
{//逆序跳转,倒播
|
|
if (CheckTwoStepInterval(partData, _curStep))
|
|
{
|
|
_curTimeLineCtrl.ContinuePlayBackwardByPausePoint(partData.AnmStartTime, () =>
|
|
{
|
|
NegativeJumpStep(partData);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_curTimeLineCtrl.StopInTime(partData.AnmStartTime);
|
|
NegativeJumpStep(partData);
|
|
}
|
|
}
|
|
else if (_curStep.id < partData.id)
|
|
{//顺序跳转,正播
|
|
if (CheckTwoStepInterval(_curStep, partData))
|
|
{
|
|
_curTimeLineCtrl.ContinuePlayForwardByPausePoint(partData.AnmStartTime, () =>
|
|
{
|
|
PositiveJumpStep(partData);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_curTimeLineCtrl.StopInTime(partData.AnmStartTime);
|
|
PositiveJumpStep(partData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 正向跳转步骤
|
|
/// </summary>
|
|
/// <param name="partData"></param>
|
|
private void PositiveJumpStep(BJCJ_SXCJ partData)
|
|
{
|
|
_curTimeLineCtrl.StopInTime(partData.AnmStartTime);
|
|
List<BJCJ_SXCJ> modelInfos = GameManager.Instance._DataBJCJHandler._SXCJDataArray[_curShowModelName];
|
|
for (int a = 0; a < modelInfos.Count; a++)
|
|
{
|
|
if (modelInfos[a].id < partData.id)
|
|
{
|
|
SetModelLightCol(modelInfos[a], false);
|
|
}
|
|
}
|
|
SetModelLightCol(partData, true);
|
|
BJCZSceneCtrl._Instance._isPlaySplitAnm = false;
|
|
_curStep = partData;
|
|
}
|
|
/// <summary>
|
|
/// 反向跳转步骤
|
|
/// </summary>
|
|
/// <param name="partData"></param>
|
|
private void NegativeJumpStep(BJCJ_SXCJ partData)
|
|
{
|
|
List<BJCJ_SXCJ> modelInfos = GameManager.Instance._DataBJCJHandler._SXCJDataArray[_curShowModelName];
|
|
for (int a = 0; a < modelInfos.Count; a++)
|
|
{
|
|
if (modelInfos[a].id > partData.id && modelInfos[a].id <= _curStep.id)
|
|
{
|
|
SetModelLightCol(modelInfos[a], false);
|
|
}
|
|
}
|
|
SetModelLightCol(partData, true);
|
|
BJCZSceneCtrl._Instance._isPlaySplitAnm = false;
|
|
_curStep = partData;
|
|
}
|
|
/// <summary>
|
|
/// 判断两个步骤是否相邻
|
|
/// </summary>
|
|
/// <param name="step1"></param>
|
|
/// <param name="step2"></param>
|
|
/// <returns>相邻-true;不相邻-false</returns>
|
|
private bool CheckTwoStepInterval(BJCJ_SXCJ step1, BJCJ_SXCJ step2)
|
|
{
|
|
List<BJCJ_SXCJ> sxcjInfos = GameManager.Instance._DataBJCJHandler._SXCJDataArray[_curShowModelName];
|
|
int indexPositive = 0;
|
|
for (int i = 0; i < sxcjInfos.Count; i++)
|
|
{
|
|
if (sxcjInfos[i].stepNameChild.Equals(step1.stepNameChild))
|
|
{
|
|
indexPositive = 0;
|
|
}
|
|
else if (sxcjInfos[i].stepNameChild.Equals(step2.stepNameChild) && indexPositive == 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
indexPositive++;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
/// <summary>
|
|
/// 设置某个步骤内模型高亮
|
|
/// </summary>
|
|
/// <param name="anmInfo"></param>
|
|
/// <param name="showable"></param>
|
|
public void SetModelLightCol(BJCJ_SXCJ anmInfo, bool showable)
|
|
{
|
|
if (GameManager.Instance._StateContext.GetState().Name.Equals("ExamState")) return;
|
|
string[] items = anmInfo.itemGeo.Split("|");
|
|
for (int i = 0; i < items.Length; i++)
|
|
{
|
|
GameObject curGeo = _selectGeoDic[items[i]];
|
|
//高亮
|
|
curGeo.GetComponent<OutLineRender>().enabled = showable;
|
|
MeshFilter[] meshes = curGeo.GetComponentsInChildren<MeshFilter>();
|
|
for (int a = 0; a < meshes.Length; a++)
|
|
{
|
|
MeshCollider col = meshes[a].gameObject.GetComponent<MeshCollider>();
|
|
col.enabled = showable;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 给所有可点击的物体添加碰撞体和高光
|
|
/// </summary>
|
|
private void AddHightCol()
|
|
{
|
|
foreach (var item in GameManager.Instance._DataBJCJHandler._SXCJDataArray)
|
|
{
|
|
Transform childrenContain = _curTimeLineCtrl.transform;
|
|
if (!item.Key.Equals(_curShowModelName)) continue;
|
|
List<BJCJ_SXCJ> allStep = item.Value;
|
|
for (int i = 0; i < allStep.Count; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(allStep[i].itemGeo)) continue;
|
|
string[] GeosName = allStep[i].itemGeo.Split("|");
|
|
for (int j = 0; j < GeosName.Length; j++)
|
|
{//每个小步骤可点击的物体可能有很多
|
|
if (_selectGeoDic.ContainsKey(GeosName[j])) continue;
|
|
GameObject geo = UtilitiesMng.GetGeoByName(childrenContain, GeosName[j],true);
|
|
//添加高光
|
|
OutLineRender outLine;
|
|
if (!geo.TryGetComponent(out outLine))
|
|
{
|
|
outLine = geo.AddComponent<OutLineRender>();
|
|
}
|
|
outLine.enabled = false;
|
|
//添加碰撞器
|
|
ItemTriCtrl triCtrl;
|
|
if (!geo.TryGetComponent(out triCtrl))
|
|
{
|
|
triCtrl = geo.AddComponent<ItemTriCtrl>();
|
|
}
|
|
MeshFilter[] meshes = geo.GetComponentsInChildren<MeshFilter>();
|
|
for (int a = 0; a < meshes.Length; a++)
|
|
{
|
|
MeshCollider col;
|
|
if (!meshes[a].gameObject.TryGetComponent(out col))
|
|
{
|
|
col = meshes[a].gameObject.AddComponent<MeshCollider>();
|
|
}
|
|
if (GameManager.Instance._StateContext.GetState().Name.Equals("ExamState"))
|
|
{
|
|
col.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
col.enabled = false;
|
|
}
|
|
}
|
|
_selectGeoDic.Add(GeosName[j], geo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |