CombatSenceController.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System.Collections.Generic;
  2. using Fort23.Core;
  3. using GameLogic.CombatScenesTool;
  4. using Unity.AI.Navigation;
  5. using UnityEngine;
  6. namespace GameLogic.Combat.CombatTool
  7. {
  8. public class CombatSenceController
  9. {
  10. private AssetHandle scenesHandle;
  11. private AssetHandle scenesHandle2;
  12. public GameObject scenes1;
  13. public GameObject scenes2;
  14. private NavMeshSurface _navMeshSurface;
  15. private float zoff;
  16. private int index = 0;
  17. private List<CombatScenesConfig> _allCombatScenesConfigs = new List<CombatScenesConfig>();
  18. public CombatScenesConfig _currConfig;
  19. private int nextConfigIndex;
  20. public async CTask InitScenes()
  21. {
  22. CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
  23. cTaskAwaitBuffer.AddTask(AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>("Chapter01.prefab",
  24. delegate(AssetHandle handle)
  25. {
  26. scenesHandle = handle;
  27. scenes1 = scenesHandle.AssetObject<GameObject>();
  28. scenes1.SetActive(true);
  29. CombatScenesConfig combatScenesConfig = scenes1.GetComponent<CombatScenesConfig>();
  30. _allCombatScenesConfigs.Add(combatScenesConfig);
  31. }));
  32. cTaskAwaitBuffer.AddTask(AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>("Chapter02.prefab",
  33. delegate(AssetHandle handle)
  34. {
  35. scenesHandle2 = handle;
  36. scenes2 = scenesHandle2.AssetObject<GameObject>();
  37. scenes2.SetActive(true);
  38. CombatScenesConfig combatScenesConfig = scenes2.GetComponent<CombatScenesConfig>();
  39. _allCombatScenesConfigs.Add(combatScenesConfig);
  40. }));
  41. cTaskAwaitBuffer.AddTask(AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>(
  42. "NavMeshTarget.prefab",
  43. delegate(AssetHandle handle)
  44. {
  45. GameObject go = handle.AssetObject<GameObject>();
  46. _navMeshSurface = go.GetComponent<NavMeshSurface>();
  47. }));
  48. await cTaskAwaitBuffer.WaitAll();
  49. for (int i = 0; i < _allCombatScenesConfigs.Count; i++)
  50. {
  51. zoff = -i * 54;
  52. // index = i;
  53. _allCombatScenesConfigs[i].transform.position = new Vector3(0, 0, zoff);
  54. }
  55. zoff = 0;
  56. index = 0;
  57. nextConfigIndex = 0;
  58. _currConfig = _allCombatScenesConfigs[0];
  59. Vector3 pos = _allCombatScenesConfigs[0].heroPoint[0].position;
  60. // _navMeshSurface.transform.position = pos;
  61. UpdateNavMesh(pos);
  62. //
  63. }
  64. public CombatScenesConfig MoveToNextConfig()
  65. {
  66. nextConfigIndex++;
  67. nextConfigIndex %= _allCombatScenesConfigs.Count;
  68. return _currConfig=_allCombatScenesConfigs[nextConfigIndex];
  69. }
  70. public void NextScenesShow()
  71. {
  72. index++;
  73. index %= _allCombatScenesConfigs.Count;
  74. zoff -= 54;
  75. _allCombatScenesConfigs[index].transform.position = new Vector3(0, 0, zoff);
  76. }
  77. public void UpdateNavMesh(Vector3 pos)
  78. {
  79. if (_navMeshSurface == null)
  80. {
  81. Debug.LogError("没有导航网格");
  82. return;
  83. }
  84. _navMeshSurface.transform.position = pos;
  85. _navMeshSurface.BuildNavMesh();
  86. }
  87. }
  88. }