ActorMgr.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [System.Serializable]
  5. public struct PreviewNpcActor
  6. {
  7. public int id;
  8. public GameObject go;
  9. }
  10. public class ActorMgr : SingletonMono<ActorMgr>
  11. {
  12. private GameObject actorRoot;
  13. public GameObject ActorRoot
  14. {
  15. get { return ActorRoot; }
  16. }
  17. //story preview
  18. public List<PreviewNpcActor> previewNpcActorsList;
  19. public List<PreviewNpcActor> previewHeroActorsList;
  20. private Dictionary<int, GameObject> heroActorDic;
  21. private Dictionary<int, GameObject> npcActorDic;
  22. public override void InitMgr()
  23. {
  24. actorRoot = GameObject.Find("ActorRoot");
  25. if (actorRoot == null)
  26. {
  27. actorRoot = new GameObject("ActorRoot");
  28. }
  29. heroActorDic = new Dictionary<int, GameObject>();
  30. npcActorDic = new Dictionary<int, GameObject>();
  31. }
  32. GameObject GetPreviewActor(List<PreviewNpcActor> list, int id)
  33. {
  34. foreach(var actor in list)
  35. {
  36. if (actor.id == id)
  37. {
  38. return actor.go;
  39. }
  40. }
  41. return null;
  42. }
  43. public GameObject GetPreviewActorById(int type, int id)
  44. {
  45. GameObject actor = null;
  46. if (type == 0)
  47. {
  48. //actor = GetPreviewActor(previewHeroActorsList, id);
  49. actor = previewHeroActorsList[0].go;
  50. }
  51. else
  52. {
  53. actor = GetPreviewActor(previewNpcActorsList, id);
  54. }
  55. if (actor == null)
  56. {
  57. DebugHelper.LogError(id + " actor is null");
  58. }
  59. return actor;
  60. }
  61. }