123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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<CommonLang.Geometry.Vector2>.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<AssetObjectExt>();
- foreach (var aoe in aoes)
- {
- BattleFactroy.Instance.GameObjectAdapter.Unload(aoe);
- }
- base.OnDispose();
- }
- internal void OnChanged()
- {
- if (this.ZDecoration.Enable)
- {
- AssetObjectExt[] aoes = mDecrationRoot.GetComponentsInChildren<AssetObjectExt>();
- 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<AssetObjectExt>();
- 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);
- }
- }
- });
- }
- }
- }
- }
|