123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using CommonLang;
- using System.Collections.Generic;
- using UnityEngine;
- using CommonAIClient.Unity.Utils;
- namespace CommonAIClient.Unity.Battle
- {
- public partial class ComAIUnit
- {
- public class Avatar
- {
- private DisplayCell mDisplayCell;
- private object mTag;
- protected internal DisplayCell DisplayCell
- {
- get { return mDisplayCell; }
- internal set { mDisplayCell = value; }
- }
- public object Tag
- {
- get { return mTag; }
- set { mTag = value; }
- }
- }
- private List<Avatar> mAvatarStack = new List<Avatar>();
- private IComparer<Avatar> mAvatarComparer;
- public IComparer<Avatar> AvatarComparer { set { mAvatarComparer = value; } }
- protected override void CorrectDummyNode()
- {
- if (mAvatarStack.Count == 0)
- {
- base.CorrectDummyNode();
- return;
- }
- if (mAvatarStack[0].DisplayCell != null)
- {
- DisplayCell display = mAvatarStack[0].DisplayCell;
- foreach (var elem in this.Dummys)
- {
- GameObject trace = display.GetDummyNode(elem.Key);
- elem.Value.Init(elem.Key, trace);
- }
- }
- }
- /// <summary>
- /// 如果name不为空 绝对返回一个DummyNode
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- public override DummyNode GetDummyNode(string name)
- {
- if (mAvatarStack.Count == 0 || mAvatarStack[0].DisplayCell == null)
- {
- return base.GetDummyNode(name);
- }
- if (string.IsNullOrEmpty(name))
- {
- Debug.LogError("string.IsNullOrEmpty(name)");
- return null;
- }
- DisplayCell display = mAvatarStack[0].DisplayCell;
- DummyNode dummyNode = null;
- if (!this.Dummys.TryGetValue(name, out dummyNode))
- {
- GameObject node = display.GetDummyNode(name);
- if (node == null)
- {
- Debug.LogError("node not exist " + name);
- }
- GameObject tmp = new GameObject(name);
- tmp.ParentRoot(this.DummyRoot);
- dummyNode = tmp.AddComponent<DummyNode>();
- dummyNode.Init(name, node);
- this.Dummys.Add(name, dummyNode);
- }
- return dummyNode;
- }
- public override void PlayAnim(string name, bool crossFade,
- WrapMode wrapMode = WrapMode.Once, float speed = 1f)
- {
- if (mAvatarStack.Count == 0 || mAvatarStack[0].DisplayCell == null)
- {
- base.PlayAnim(name, crossFade, wrapMode, speed);
- }
- else
- {
- mAvatarStack[0].DisplayCell.PlayAnim(name, crossFade, wrapMode, speed);
- }
- }
- /// <summary>
- /// 增加一个avatar 返回在avatar列表中的顺序
- /// </summary>
- /// <param name="assetBundleName"></param>
- /// <param name="assetName"></param>
- /// <returns></returns>
- public Avatar AddAvatar(string assetBundleName, string assetName)
- {
- if (!string.IsNullOrEmpty(assetBundleName)
- && !string.IsNullOrEmpty(assetName))
- {
- Avatar info = new Avatar();
- mAvatarStack.Add(info);
- if (mAvatarComparer != null)
- {
- mAvatarStack.Sort(mAvatarComparer);
- }
- BattleFactroy.Instance.GameObjectAdapter.Load(assetBundleName, assetName
- , (succ, aoe) =>
- {
- if (succ)
- {
- if (IsDisposed || mAvatarStack.IndexOf(info) == -1)
- {
- BattleFactroy.Instance.GameObjectAdapter.Unload(aoe);
- return;
- }
- info.DisplayCell = BattleFactroy.Instance.CreateDisplayCell(mAvatarRoot);
- info.DisplayCell.Model = aoe;
- if (mAvatarStack[0] == info)
- {
- DisplayCell.ActiveSelf = false;
- //映射节点
- CorrectDummyNode();
- info.DisplayCell.PlayAnim(LastAnimName, false, LastWrapMode, LastSpeed);
- }
- else
- {
- mAvatarStack[0].DisplayCell.ActiveSelf = false;
- }
- }
- });
- return info;
- }
- return null;
- }
- public void RemoveAvatar(Avatar info)
- {
- int index = mAvatarStack.IndexOf(info);
- if (index == -1)
- return;
- if (info.DisplayCell != null)
- {
- info.DisplayCell.Dispose();
- }
- mAvatarStack.Remove(info);
- if (index == 0)
- {
- if (mAvatarStack.Count > 0)
- {
- CorrectDummyNode();
- mAvatarStack[0].DisplayCell.ActiveSelf = true;
- PlayAnim(LastAnimName, false, LastWrapMode, LastSpeed);
- }
- else
- {
- this.DisplayCell.ActiveSelf = true;
- CorrectDummyNode();
- }
- PlayAnim(LastAnimName, false, LastWrapMode, LastSpeed);
- }
- }
- }
- }
|