using System.Collections; using System.Collections.Generic; using UnityEngine; using XFramework.NetOuter; //一区九厂标记旗帜 public class AreaFlageCtrl : MonoBehaviour,IPicked,IBindIcon { public Text3DCtrl [] text3DCtrl; private bool canPick; private StudentButtonIcon buttonIcon; private string areaName; private IconBase thisIcon; bool firstSet = true; float radius = 50;//厂区半径 public string AreaName { get { return areaName; } } public float Radius { get { return radius; } } private void Start() { canPick = true;//默认物体能被捡起 } public bool CanPickDown() { return true; } //改变当前物体是否能够被捡起 public void ChangePicked(bool can) { canPick = can; } //不一定所有的时候都能捡起 public bool CanPickUpByRay() { return canPick; } public void InitFlage(StudentButtonIcon studentButtonIcon) { if (buttonIcon&&buttonIcon != studentButtonIcon)//未完成放置时 又发起了新的生成指令 不做任何处理 { //buttonIcon.SetInteractable(true); return; } buttonIcon = studentButtonIcon; buttonIcon.SetInteractable(false); areaName = studentButtonIcon.text_IconName.text; for (int i = 0; i < text3DCtrl.Length; i++) { text3DCtrl[i].SetName(areaName); } } //同步生成时调用 public void SyncInitFlage(string areaName, XFramework.TransGesture trans) { this.areaName = areaName; this.transform.position = trans.GetPos(); for (int i = 0; i < text3DCtrl.Length; i++) { text3DCtrl[i].SetName(areaName); } PickDown();//同步生产默认在地上 this.gameObject.AddComponent(); } //同步更新位置 public void SyncUpdatePos(Vector3 postion) { this.transform.position = postion; thisIcon?.SetUpdateIconMsg(this.transform.position, "UpdatePos");//更新UI位置 } //同步更新位置 public void SyncDestory() { Destroy(this.gameObject); } //放置在地上 public void PickDown() { GameObjectManager.Instance.AddPlannedArea(this);//添加安置记录 if (firstSet)//首次放置在地上 { firstSet = false; EventCenter.Instance.EventTrigger("CreatAreaFlageIcon", this);//发起创建UI指令 if (GroupLearnHelper.isMaster)//分组训练时只有组长可以操作 { AreaFlagSyncProtoBuilder protoBuilder = new AreaFlagSyncProtoBuilder(AreaFlagActionType.Creat, areaName, new XFramework.TransGesture(this.transform.position, Vector3.zero)); NetUDPManager.Instance.SendNetMess(protoBuilder.GetProto()); } } else if(GroupLearnHelper.isMaster)//分组训练时 改变位置发送位置更新消息 { AreaFlagSyncProtoBuilder protoBuilder = new AreaFlagSyncProtoBuilder(AreaFlagActionType.UpdatePos, areaName, new XFramework.TransGesture(this.transform.position, Vector3.zero)); NetUDPManager.Instance.SendNetMess(protoBuilder.GetProto()); } thisIcon?.SetUpdateIconMsg(this.transform.position, "UpdatePos");//更新UI位置 } //捡起 public void PickUp() { GameObjectManager.Instance.RemoveArea(this);//移除安置记录 } private void OnDestroy() { buttonIcon?.SetInteractable(true); GameObjectManager.Instance.RemoveArea(this); if (thisIcon) Destroy(thisIcon.gameObject);//删除对应的UI } //中途放弃拾取 则自动删除该物体 public void StopPick() { if (GroupLearnHelper.isMaster)//分组训练时只有组长可以操作 { AreaFlagSyncProtoBuilder protoBuilder = new AreaFlagSyncProtoBuilder(AreaFlagActionType.Destory, areaName, new XFramework.TransGesture(this.transform.position, Vector3.zero)); NetUDPManager.Instance.SendNetMess(protoBuilder.GetProto()); } Destroy(this.gameObject); } //任意情况下都能中止 public bool CanStopPick() { return true; } public GameObject GetGameObject() { return this.gameObject; } //绑定UI 根据物体初始化UI public void BindIcon(IconBase icon) { thisIcon = icon; icon.SetName(areaName); icon.SetUpdateIconMsg(radius); } }