using UnityEngine; using System.Collections; using CommonAI.Zone.ZoneEditor; using CommonAIClient.Unity.Utils; using CommonAI.ZoneClient; using System.Collections.Generic; using CommonLang; namespace CommonAIClient.Unity.Battle { public class BattleDecoration : BattleFlag { private GameObject mDecrationRoot; public ZoneEditorDecoration ZDecoration { get { return base.ZFlag as ZoneEditorDecoration; } } public BattleDecoration(BattleScene battleScene, ZoneEditorDecoration zf) : base(battleScene, zf) { this.ObjectRoot.ZonePos2NavPos(BattleScene.Terrain.TotalHeight , zf.X, zf.Y, 0f); this.ObjectRoot.ZoneRot2UnityRot(zf.Data.StripDirection); mDecrationRoot = new GameObject("DecrationRoot"); using (var pts = ListObjectPool.AllocAutoRelease()) { ZDecoration.Data.GetResourcePoints(pts); foreach(var pos in pts) { GameObject cell = new GameObject("cell"); cell.ParentRoot(mDecrationRoot); cell.Position(new Vector3(pos.X, 0, pos.Y)); cell.transform.localScale *= ZDecoration.Data.Scale; } } mDecrationRoot.ParentRoot(ObjectRoot); } protected override void OnDispose() { AssetObjectExt[] aoes = mDecrationRoot.GetComponentsInChildren(); foreach (var aoe in aoes) { BattleFactroy.Instance.GameObjectAdapter.Unload(aoe); } base.OnDispose(); } internal void OnChanged() { if (this.ZDecoration.Enable) { AssetObjectExt[] aoes = mDecrationRoot.GetComponentsInChildren(); foreach (var aoe in aoes) { BattleFactroy.Instance.GameObjectAdapter.Unload(aoe); } for (int i = 0; i < mDecrationRoot.transform.childCount; i++) { LoadCellModel(mDecrationRoot.transform.GetChild(i).gameObject , ZDecoration.Data.ResourceID); } } else { AssetObjectExt[] aoes = mDecrationRoot.GetComponentsInChildren(); foreach (var aoe in aoes) { BattleFactroy.Instance.GameObjectAdapter.Unload(aoe); } for (int i = 0; i < mDecrationRoot.transform.childCount; i++) { LoadCellModel(mDecrationRoot.transform.GetChild(i).gameObject , ZDecoration.Data.ResourceID_Disabled); } } } private void LoadCellModel(GameObject root, string name) { //加载模型 if (!string.IsNullOrEmpty(name)) { BattleFactroy.Instance.GameObjectAdapter.Load( name, System.IO.Path.GetFileNameWithoutExtension(name), (succ, o) => { if (succ) { if (this.IsDisposed) { BattleFactroy.Instance.GameObjectAdapter.Unload(o); } else { o.gameObject.ParentRoot(root); } } }); } } } }