ComAISpell.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using UnityEngine;
  2. using CommonAI.ZoneClient;
  3. using CommonAI.Zone;
  4. using CommonAIClient.Unity.Utils;
  5. namespace CommonAIClient.Unity.Battle
  6. {
  7. public partial class ComAISpell : ComAICell
  8. {
  9. private ComAICell mLauncher;
  10. private ComAICell mTarget;
  11. protected ZoneSpell ZSpell { get { return ZObject as ZoneSpell; } }
  12. protected ComAICell Launcher { get { return mLauncher; } }
  13. protected ComAICell Target { get { return mTarget; } }
  14. public ComAISpell(BattleScene battleScene, ZoneSpell obj)
  15. : base(battleScene, obj)
  16. {
  17. if (ZSpell.Sender != null)
  18. {
  19. mLauncher = BattleScene.GetBattleObject(ZSpell.Sender.ObjectID);
  20. }
  21. if (ZSpell.Target != null)
  22. {
  23. mTarget = BattleScene.GetBattleObject(ZSpell.Target.ObjectID);
  24. }
  25. SyncState();
  26. if (!string.IsNullOrEmpty(ZSpell.Info.FileName))
  27. {
  28. BattleFactroy.Instance.GameObjectAdapter.Load(
  29. ZSpell.Info.FileName,
  30. System.IO.Path.GetFileNameWithoutExtension(ZSpell.Info.FileName),
  31. (succ, aoe) =>
  32. {
  33. if (succ)
  34. {
  35. if (IsDisposed)
  36. {
  37. BattleFactroy.Instance.GameObjectAdapter.Unload(aoe);
  38. return;
  39. }
  40. OnLoadModelSuccess(aoe);
  41. }
  42. });
  43. }
  44. }
  45. protected virtual GameObject GetBindingPart(ComAICell unit)
  46. {
  47. DummyNode node = unit.GetDummyNode("chest_buff");
  48. if (node == null)
  49. return unit.EffectRoot;
  50. return node.gameObject;
  51. }
  52. protected virtual void OnLoadModelSuccess(AssetObjectExt aoe)
  53. {
  54. DisplayCell.Model = aoe;
  55. if (this.ZSpell.Info.FileBodyScale != 0)
  56. {
  57. aoe.transform.localScale = new Vector3(
  58. this.ZSpell.Info.FileBodyScale,
  59. this.ZSpell.Info.FileBodyScale,
  60. this.ZSpell.Info.FileBodyScale);
  61. }
  62. SyncState();
  63. if (!string.IsNullOrEmpty(ZSpell.Info.FileNameSpawn))
  64. {
  65. LaunchEffect effect = new LaunchEffect();
  66. effect.Name = ZSpell.Info.FileNameSpawn;
  67. PlayEffect(effect, EffectRoot.Position(), EffectRoot.Rotation());
  68. }
  69. if (ZSpell.Info.BodyShape == SpellTemplate.Shape.LineToTarget
  70. && Launcher != null && !Launcher.IsDisposed
  71. && Target != null && !Target.IsDisposed)
  72. {
  73. //必须自己实现连接
  74. GameObject from = GetBindingPart(Launcher);
  75. GameObject to = GetBindingPart(Target);
  76. BattleFactroy.Instance.MakeDamplingJoint(aoe.gameObject, from, to);
  77. }
  78. }
  79. protected override void SyncState()
  80. {
  81. Vector3 pos = Extensions.ZonePos2NavPos(ZObject.Parent.Terrain.TotalHeight
  82. , ZObject.X, ZObject.Y, ZObject.Z);
  83. ObjectRoot.Position(new Vector3(pos.x, pos.y + ZSpell.LaunchHeight, pos.z));
  84. ObjectRoot.ZoneRot2UnityRot(ZObject.Direction);
  85. }
  86. protected override void OnDispose()
  87. {
  88. if (!string.IsNullOrEmpty(ZSpell.Info.FileNameDestory))
  89. {
  90. LaunchEffect effect = new LaunchEffect();
  91. effect.Name = ZSpell.Info.FileNameDestory;
  92. PlayEffect(effect, EffectRoot.Position(), EffectRoot.Rotation());
  93. }
  94. base.OnDispose();
  95. }
  96. }
  97. }