ProcedureStateGraphController.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using ChivaVR.State;
  2. using ChivaXR;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class ProcedureStateGraphController : MonoBehaviour
  7. {
  8. [Header("是否使用原ProcedureManager的线性执行")]
  9. public bool linerRunning = true; //线性执行,
  10. public bool orderRunGraph = false;
  11. public List<StateGraphBase> stateGraphBases = new List<StateGraphBase>();
  12. private int currentStateGraphID = 0;
  13. private bool stateGraphRuning = false;
  14. #region StateGraph
  15. public void InitStateGraphBases()
  16. {
  17. if (stateGraphBases.Count == 0)
  18. {
  19. Debug.LogError("暂无流程图,退出流程执行");
  20. return;
  21. }
  22. currentStateGraphID = 0;
  23. EnterStateGraphByIndex(currentStateGraphID);
  24. }
  25. public void EnterStateGraphByIndex(int index)
  26. {
  27. if (index >= stateGraphBases.Count) return;
  28. if (stateGraphRuning)
  29. {
  30. stateGraphBases[currentStateGraphID].stateGraph.OnStateExit -= FinishedStateGraph;
  31. }
  32. stateGraphRuning = true;
  33. Debug.Log("进入流程图:" + stateGraphBases[index].description);
  34. stateGraphBases[index].stateGraph.InitState();
  35. stateGraphBases[index].stateGraph.EnterStateGraph();
  36. stateGraphBases[index].stateGraph.OnStateExit += FinishedStateGraph;
  37. }
  38. public void EnterStateGraphByStateGraph(StateGraphBase stateGraphBase)
  39. {
  40. if (stateGraphRuning)
  41. {
  42. stateGraphBases[currentStateGraphID].stateGraph.OnStateExit -= FinishedStateGraph;
  43. }
  44. stateGraphRuning = true;
  45. Debug.Log("进入流程图:" + stateGraphBase.description);
  46. stateGraphBase.stateGraph.InitState();
  47. stateGraphBase.stateGraph.EnterStateGraph();
  48. stateGraphBase.stateGraph.OnStateExit += FinishedStateGraph;
  49. }
  50. public void FinishedStateGraph(StateGraph stateGraph)
  51. {
  52. stateGraphRuning = false;
  53. //获取未完成步骤描述
  54. string info = stateGraph.GetUnFinishedDescription();
  55. //ExamManager.Instance.SubExamInfo(stateGraph);
  56. stateGraphBases[currentStateGraphID].stateGraph.OnStateExit -= FinishedStateGraph;
  57. Debug.Log("完成流程图:" + stateGraphBases[currentStateGraphID].description);
  58. //是否依次执行
  59. if (!orderRunGraph) return;
  60. currentStateGraphID++;
  61. if (currentStateGraphID <= stateGraphBases.Count)
  62. {
  63. EnterStateGraphByIndex(currentStateGraphID);
  64. }
  65. else
  66. {
  67. Debug.Log("完成所有流程图列表");
  68. }
  69. }
  70. public void EnterTargetGraphBase(StateGraphBase stateGraphBase)
  71. {
  72. //ProcessManagement.Instance.InitStepState(false);
  73. //ProcedureManager.Instance.JumpStep(stateGraphBase.startInitStep, false);
  74. EnterStateGraphByStateGraph(stateGraphBase);
  75. }
  76. #endregion
  77. }