123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- using Cysharp.Threading.Tasks;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace WS
- {
- [ObjectSystem]
- public class ProgressPopControllerUpdateSystem : UpdateSystem<ProgressPopController>
- {
- public override void Update(ProgressPopController self)
- {
- //self.LateUpdate();
- ////侧面布局
- //if (FacadeComponent.Instance.GetController<ProgressPopController>() != null)
- //{
- // self.playerPos = Player.instance.transform.position;
- // float angle = Mathf.DeltaAngle(self.VRCameraRotY, Player.instance.hmdTransform.localEulerAngles.y);
- // float num = Mathf.Abs(angle) / self.angle;
- // if (num > 1)
- // {
- // self.VRCameraRotY += (int)num * 2 * self.angle * Mathf.Sign(angle);
- // if (self.VRCameraRotY > 360)
- // {
- // self.VRCameraRotY -= 360;
- // }
- // Vector3 uiToPlayer = self.GetUITranfrom().position - self.playerPos;
- // self.startDir = Quaternion.Euler(0, Mathf.Sign(angle) * 2 * self.angle, 0) * uiToPlayer;
- // self.uiRot = Quaternion.Euler(0, self.GetUITranfrom().rotation.eulerAngles.y + 2 * self.angle * Mathf.Sign(angle), 0);
- // }
- // else
- // {
- // if (self.startRotY != Player.instance.transform.localEulerAngles.y)
- // {
- // self.GetUITranfrom().LookAt(self.playerPos);
- // float angleValue = Mathf.DeltaAngle(self.startRotY, Player.instance.transform.localEulerAngles.y);
- // self.startDir = Quaternion.Euler(0, angleValue, 0) * self.startDir;
- // float uiAngle = self.uiRot.eulerAngles.y + angleValue;
- // if (uiAngle >= 180)
- // {
- // uiAngle -= 360;
- // }
- // self.uiRot = Quaternion.Euler(new Vector3(0, uiAngle, 0));
- // self.startRotY = Player.instance.transform.localEulerAngles.y;
- // }
- // else
- // {
- // self.uiRot = self.GetUITranfrom().localRotation;
- // }
- // }
- // self.uiPos = self.startDir + self.playerPos;
- // self.SetView(self.uiPos / self.canvasScale, self.uiRot);
- //}
- }
- }
- [ObjectSystem]
- public class ProgressPopControllerLateUpdateSystem : LateUpdateSystem<ProgressPopController>
- {
- public override void LateUpdate(ProgressPopController self)
- {
- self.LateUpdate();
- }
- }
- public class ProgressPopController : Controller<ProgressPopView, ProgressPopModel>
- {
- ProcessManager processMgr;
- /// <summary> 限制角度 </summary>
- public float limitAngle = 90;
- /// <summary> VR相机Y轴旋转 </summary>
- public float VRCameraRotY;
- /// <summary> Y轴距离 </summary>
- public float uiDistanceY = 500;
- /// <summary> Z轴距离 </summary>
- public float uiDistanceZ = 800;
- /// <summary> ui到玩家的向量 </summary>
- public Vector3 startDir;
- /// <summary> UI位置 </summary>
- public Vector3 uiPos;
- /// <summary> UI旋转 </summary>
- public Quaternion uiRot;
- /// <summary> 画布缩放(用于计算世界坐标) </summary>
- public float canvasScale = 0.001f;
- /// <summary> 玩家位置 </summary>
- public Vector3 playerPos;
- /// <summary> 玩家初始旋转 </summary>
- public float startRotY;
- /// <summary> UI页面是否隐藏 </summary>
- public bool isHide;
- /// <summary> 页面禁用 </summary>
- public bool isForbidden = false;
- /// <summary> 快捷键提示页 </summary>
- //private NoticeViewController noticeView;
- /// <summary> 当前任务分数 </summary>
- public float currentTaskScore;
- protected override void BindingViewModel()
- {
- //_Model.Bind(_View.ifJump, _Model.InputPassWord, (a) =>
- //{
- // if (int.TryParse(a, out int r))
- // {
- // PlayerPrefs.SetInt("Test_Jump", r);
- // string str = $"增加{r}步";
- // _View.TestJumpBtn.GetComponentInChildren<Text>().text = str;
- // }
- //});
- _Model.Bind(_View.TestJumpBtn, TestJumpBtnClick);
- _Model.Bind(_View.ReturnBtn, ReturnBtnClick);
- _Model.Bind(_View.LastBtn, LastBtnClick);
- _Model.Bind(_View.NextBtn, NextBtnClick);
- _Model.Bind(_View.HintBtn, HintBtnClick);
- _Model.Bind(_View.Progress, _Model.Progress);
- _Model.Bind(_View.Message, _Model.Message);
- }
- public override void OpenView()
- {
- base.OpenView();
- isHide = false;
- isForbidden = false;
- //noticeView = FacadeComponent.Instance.CreateController<NoticeViewController>();
- //noticeView.OpenView();
- processMgr = GameManager.Instance.ProcessManager;
- _Model.WSTaskLists = processMgr.GetVTaskList();
- RefreshMessage(0);
- processMgr.OnCompleteVTaskCallback += RefreshMessage;
- processMgr.OnEndProcessCallback += OnProcessCompletCallBack;
- currentTaskScore = processMgr.GetVTask(processMgr.GetCurrentModule().VTaskId).Score;
- VRCameraRotY = 0;
- startRotY = 0;
- var playerPos = Player.Inst.transform.position;
- uiPos = playerPos / canvasScale + new Vector3(0, uiDistanceY, uiDistanceZ);
- var Z = Player.Inst.transform.forward * uiDistanceZ;
- var Y = Player.Inst.transform.up * uiDistanceY;
- uiRot = Quaternion.Euler(new Vector3(70, 0, 0));
- _View.SetPosition(uiPos, uiRot);
- startDir = _View.UIGameObject.transform.position - playerPos;
- }
- public override void Dispose()
- {
- processMgr.OnCompleteVTaskCallback -= RefreshMessage;
- processMgr.OnEndProcessCallback -= OnProcessCompletCallBack;
- //noticeView?.CloseView();
- base.Dispose();
- }
- public void LateUpdate()
- {
- ViewLayout();
- //if (VRInputComponent.Instance.GetKeyDown(VRKey.侧卧, VRHand.右) && !isForbidden)
- //{
- // isHide = !isHide;
- // ViewStatus(isHide);
- //}
- SetNoticeView();
- }
- /// <summary> 页面位置布局 </summary>
- private void ViewLayout()
- {
- //正面布局
- if (FacadeComponent.Instance.GetController<ProgressPopController>() != null)
- {
- playerPos = Player.Inst.transform.position;
- float angle = Mathf.DeltaAngle(
- VRCameraRotY,
- Player.Inst.hmdTransform.localEulerAngles.y
- );
- float num = Mathf.Abs(angle) / limitAngle;
- if (num > 1)
- {
- VRCameraRotY += (int)num * 2 * limitAngle * Mathf.Sign(angle);
- if (VRCameraRotY > 360)
- {
- VRCameraRotY -= 360;
- }
- startDir =
- Quaternion.Euler(0, Mathf.Sign(angle) * 2 * limitAngle, 0) * startDir;
- uiRot = Quaternion.Euler(
- 70,
- GetUITranfrom().rotation.eulerAngles.y + 2 * limitAngle * Mathf.Sign(angle),
- 0
- );
- }
- else
- {
- if (startRotY != Player.Inst.transform.localEulerAngles.y)
- {
- GetUITranfrom().LookAt(playerPos);
- float angleValue = Mathf.DeltaAngle(
- startRotY,
- Player.Inst.transform.localEulerAngles.y
- );
- startDir = Quaternion.Euler(0, angleValue, 0) * startDir;
- float uiAngle = uiRot.eulerAngles.y + angleValue;
- if (uiAngle >= 180)
- {
- uiAngle -= 360;
- }
- uiRot = Quaternion.Euler(new Vector3(70, uiAngle, 0));
- startRotY = Player.Inst.transform.localEulerAngles.y;
- }
- else
- {
- uiRot = GetUITranfrom().localRotation;
- }
- }
- uiPos = startDir + playerPos;
- SetView(uiPos / canvasScale, uiRot);
- }
- }
- /// <summary> 流程结束回调 </summary>
- private void OnProcessCompletCallBack()
- {
- EndTeachController endTeach =
- FacadeComponent.Instance.CreateController<EndTeachController>();
- endTeach.OpenView();
- bool isReturnMain;
- if (
- GameManager.Instance.Data.Pattern == PatternType.教学
- || GameManager.Instance.Data.Pattern == PatternType.引导
- )
- {
- isReturnMain = true;
- }
- else
- {
- isReturnMain = false;
- }
- endTeach.SetViewMesg("检查以上操作无误,汇报操作完毕", false, isReturnMain);
- SceneDataSaveComponent.Instance.RestAllScene();
- CloseView();
- }
- /// <summary> 获取UI的Transform </summary>
- public Transform GetUITranfrom()
- {
- return _View.UIGameObject.transform;
- }
- /// <summary> 设置UI页面 </summary>
- public void SetView(Vector3 pos, Quaternion quaternion)
- {
- _View.SetPosition(pos, quaternion);
- }
- /// <summary>返回 </summary>
- public void ReturnBtnClick()
- {
- isForbidden = true;
- ViewStatus(isForbidden);
- EndTeachController endTeach =
- FacadeComponent.Instance.CreateController<EndTeachController>();
- endTeach.OpenView();
- bool isReturnMain;
- if (
- GameManager.Instance.Data.Pattern == PatternType.教学
- || GameManager.Instance.Data.Pattern == PatternType.引导
- )
- {
- isReturnMain = true;
- }
- else
- {
- isReturnMain = false;
- }
- endTeach.SetViewMesg(
- $"您还未完成操作{GameManager.Instance.Data.Pattern},现在退出不保留操作进度,是否确定退出",
- true,
- isReturnMain
- );
- }
- /// <summary> 设置进度栏显隐 </summary>
- public void ViewStatus(bool active)
- {
- _View.UIGameObject.SetActive(!active);
- }
- /// <summary> 手臂提示 </summary>
- private void SetNoticeView()
- {
- //Vector3 pos = Player.Inst.rightHand.transform.position / canvasScale;
- //Quaternion quaternion =
- // Player.Inst.rightHand.transform.rotation
- // * Quaternion.Euler(new Vector3(70, 0, 0));
- //noticeView.SetView(pos, quaternion);
- }
- /// <summary> 警告提示 </summary>
- public async void WarningHint()
- {
- _View.WarningHint.gameObject.SetActive(true);
- await TimerComponent.Instance.WaitAsync(1.5f);
- _View.WarningHint.gameObject.SetActive(false);
- }
- public async void TestJumpBtnClick()
- {
- int len = PlayerPrefs.GetInt("Test_Jump", 0);
- for (int i = 0; i < len; i++)
- {
- var isscne = processMgr.IsScene();
- await processMgr.NextProcess();
- if (isscne)
- {
- await TimerComponent.Instance.WaitAsync(1);
- }
- }
- }
- /// <summary> 上一步按钮 </summary>
- public async void LastBtnClick()
- {
- await processMgr.LastProcess();
- RefreshMessage(processMgr.GetCurrentModule().VTaskId - 1);
- }
- /// <summary>下一步按钮</summary>
- public async void NextBtnClick()
- {
- await processMgr.NextProcess();
- }
- /// <summary>提示按钮</summary>
- public void HintBtnClick()
- {
- _View.Message.gameObject.SetActive(true);
- currentTaskScore = 0;
- processMgr.GetCurrentModule().Prompt();
- }
- /// <summary> 刷新页面上的任务信息</summary>
- public void RefreshMessage(int taskId)
- {
- taskId += 1;
- WSTaskList record = _Model.WSTaskLists.Find(t => t.Id == taskId);
- if (record == null)
- {
- Log.LogError($"任务{taskId}为空");
- return;
- }
- currentTaskScore = processMgr.GetVTaskRecord(taskId).Score;
- _Model.Progress.Value =
- "大岗山10kV厂用电系统I段停电检修做措施"
- + $"(<size=32>{record.Id}</size>/{processMgr.GetAllVTaskRecord().Count})";
- switch (GameManager.Instance.Data.Pattern)
- {
- case PatternType.教学:
- _Model.Message.Value = record.Name.Replace(" ", "\u00A0").Replace("\\n", "\n");
- _View.LastBtn.interactable = (taskId == 1) ? false : true;
- _View.NextBtn.interactable =
- (taskId == processMgr.GetVTaskList().Count) ? false : true;
- _View.HintBtn.gameObject.SetActive(false);
- break;
- case PatternType.练习:
- _Model.Message.Value = record.Name.Replace(" ", "\u00A0").Replace("\\n", "\n");
- _View.Message.gameObject.SetActive(false);
- _View.LastBtn.gameObject.SetActive(false);
- _View.NextBtn.gameObject.SetActive(false);
- _View.HintBtn.gameObject.SetActive(true);
- break;
- case PatternType.考核:
- _View.LastBtn.gameObject.SetActive(false);
- _View.NextBtn.gameObject.SetActive(false);
- _View.HintBtn.gameObject.SetActive(false);
- break;
- }
- }
- /// <summary>
- /// 结果提示
- /// </summary>
- /// <param name="isSuccess">操作是否正确</param>
- public async UniTask ResultHint(bool isSuccess)
- {
- if (isSuccess)
- {
- GameManager.Instance.currentAllScore += currentTaskScore;
- }
- else
- {
- currentTaskScore = 0;
- }
- _View.SuccessIcon.gameObject.SetActive(isSuccess);
- _View.FailIcon.gameObject.SetActive(!isSuccess);
- await TimerComponent.Instance.WaitAsync(2);
- _View.SuccessIcon.gameObject.SetActive(false);
- _View.FailIcon.gameObject.SetActive(false);
- }
- }
- public class ProgressPopView : View
- {
- public InputField ifJump;
- public Button TestJumpBtn;
- public Button ReturnBtn;
- public Button LastBtn;
- public Button NextBtn;
- public Button HintBtn;
- public Text Progress;
- public Text Message;
- public Text WarningHint;
- public Image FailIcon;
- public Image SuccessIcon;
- public override void LoadInit()
- {
- ShowModeType = ViewShowModeType.World;
- ReferenceCollector rc = UIGameObject.GetComponent<ReferenceCollector>();
- ifJump = rc.GetComponent<InputField>("ifJump");
- ReturnBtn = rc.GetComponent<Button>("ReturnBtn");
- TestJumpBtn = rc.GetComponent<Button>("TestJumpBtn");
- LastBtn = rc.GetComponent<Button>("LastBtn");
- NextBtn = rc.GetComponent<Button>("NextBtn");
- HintBtn = rc.GetComponent<Button>("HintBtn");
- Progress = rc.GetComponent<Text>("Progress");
- Message = rc.GetComponent<Text>("Message");
- WarningHint = rc.GetComponent<Text>("WarningHint");
- FailIcon = rc.GetComponent<Image>("FailIcon");
- SuccessIcon = rc.GetComponent<Image>("SuccessIcon");
- }
- }
- public class ProgressPopModel : Model
- {
- public BindableProperty<string> Progress;
- public BindableProperty<string> Message;
- public BindableProperty<string> InputPassWord;
- /// <summary> 任务列表 </summary>
- public List<WSTaskList> WSTaskLists;
- /// <summary> 转头角度 </summary>
- public float angle = 90;
- public override void InitProperty()
- {
- Progress = CreateProperty<string>();
- Message = CreateProperty<string>();
- InputPassWord = CreateProperty<string>();
- }
- }
- }
|