//在单位身上 播放一次性特效 public static void PlayEffectOnUnitEntity(string path, UnityEntity unit) { if (unit == null || path.Length <= 0) { return; } var modeeffect = (GameObject)(GameObject.Instantiate(Resources.Load(path))); if (modeeffect != null) { modeeffect.transform.parent = unit.Mode.transform; modeeffect.transform.position = unit.Mode.transform.position; //modeeffect.transform.rotation = ParentEntity.Mode.transform.rotation; var ps = modeeffect.GetComponent <ParticleSystem>(); if (ps != null) { GameObject.Destroy(modeeffect, ps.main.duration); } else { GameObject.Destroy(modeeffect, 2); } } }
public void ClickPos(Vector2 pos) { Debug.Log("click pos:" + pos); Ray ray = Camera.main.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Debug.Log("Raycast:"); //测试 UnityEntity unit = UnityEntityManager.Instance.GetUnityEntityFromObject(hit.transform.gameObject); if (unit != null && unit != m_MyMainUnit) { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); } m_TargetUnit = unit; //m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); //Protomsg.CS_PlayerAttack msg1 = new Protomsg.CS_PlayerAttack(); //msg1.IDs.AddRange(m_MyControlUnit); //msg1.TargetUnitID = unit.ID; //MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerAttack", msg1); } //Debug.Log(hit.collider.gameObject); } }
//获取离本单位最近的单位 public UnityEntity GetNearestUnityEntity(int id) { Debug.Log("GetNearestUnityEntity" + id); var myunityentity = m_UnityEntitys[id]; if (myunityentity == null) { Debug.Log("GetNearestUnityEntity null"); return(null); } var mindis = 100000000.0f; UnityEntity nearrestUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == id || item.Value.IsDeath == 1) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(myunityentity.X, myunityentity.Y)); if (mindis > dis) { Debug.Log("dis " + dis); mindis = dis; nearrestUnityEntity = item.Value; } } return(nearrestUnityEntity); }
internal UnityTransform(UnityEntity unityEntity, bool invisibleOnFirstTick = false) : base(unityEntity) { if (invisibleOnFirstTick) { renderer = unityEntity.gameObject.GetComponentInChildren <Renderer>(); } }
// Update is called once per frame void Update() { //Debug.Log("update time:" + Tool.GetTime()); MsgManager.Instance.UpdateMessage(); LogicUpdate(); //删除目标 if (m_TargetUnit != null) { if (m_TargetUnit.IsDeath == 1 || UnityEntityManager.Instance.GetUnityEntity(m_TargetUnit.ID) == null) { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); m_TargetUnit = null; } else { //距离我自己太远 } } UnityEntityManager.Instance.Update(Time.deltaTime); if (Time.deltaTime >= 0.033) { //Debug.Log("deltaTime:" + Time.deltaTime); } //AutoAttack(); }
//----------------------------------------------------------------------------*/ public static void SetFollowingTarget(UnityEntity Target) { if (singleton != null) { singleton.followingTarget = Target; } }
//public public BuffEffect(Protomsg.BuffDatas buffdata, UnityEntity parent) { Data = buffdata; TypeID = buffdata.TypeID; BIdata = ExcelManager.Instance.GetBuffIM().GetBIByID(buffdata.TypeID); ParentEntity = parent; Init(); }
public override void HitTop(UnityEntity e) { if (e is UnityMover && !(e is Player)) { base.HitTop(e); Land(); } }
//更改单位数据 public void ChangeUnityEntity(Protomsg.UnitDatas data) { UnityEntity unity = m_UnityEntitys[data.ID]; if (unity != null) { unity.Change(data); } }
//更改显示位置 public void ChangeShowPos(Protomsg.UnitDatas data, float scale) { UnityEntity unity = m_UnityEntitys[data.ID]; if (unity != null) { unity.ChangeShowPos(scale, data.X, data.Y); } }
//删除单位 public void DestroyUnityEntity(int id) { UnityEntity unity = m_UnityEntitys[id]; if (unity != null) { unity.Destroy(); m_UnityEntitys.Remove(id); } }
public static BuffEffect CreateBuffEffect(Protomsg.BuffDatas buffdata, UnityEntity parent) { var data = ExcelManager.Instance.GetBuffIM().GetBIByID(buffdata.TypeID); if (data == null || parent == null || parent.Mode == null) { return(null); } return(new BuffEffect(buffdata, parent)); }
//检查单位是否是 玩家的敌人 public bool CheckIsEnemy(UnityEntity target, UnityEntity my) { if (my == null || target == null) { return(false); } //同一个公会的不能成为敌人 if (target.GuildID > 0 && target.GuildID == my.GuildID) { return(false); } //同一小组的不能成为敌人 if (target.GroupID > 0 && target.GroupID == my.GroupID) { return(false); } //不同小组一定是敌人 if (target.GroupID > 0 && my.GroupID > 0 && target.GroupID != my.GroupID) { return(true); } //攻击模式(1:和平模式 2:组队模式 3:全体模式 4:阵营模式(玩家,NPC) 5:行会模式) if (my.AttackMode == 1) { //阵营不同 //阵营(1:玩家 2:NPC) if (target.Camp != my.Camp) { return(true); } else { //如果目标是全体模式 也是敌人 if (target.AttackMode == 3) { return(true); } } return(false); } else if (my.AttackMode == 3) { //不是玩家自己控制的单位 if (target.ControlID != my.ControlID) { return(true); } else { return(false); } } return(false); }
public override void HitSide(UnityEntity e, float side) { if (e is Goomba || e is Fire) { Die(); } else if (e is Coin) { e.gameObject.SetActive(false); GetCoin(); } }
public override void HitBottom(UnityEntity e) { if (e is Goomba || e is Fire) { Die(); } if (e is Coin) { e.gameObject.SetActive(false); GetCoin(); } }
public UnityEntity GetMinAngleEnemy(UnityEntity my, Vector2 dir, float maxDis) { if (my == null || dir == Vector2.zero || maxDis <= 0) { return(null); } float minangle = 0; UnityEntity minangelUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == my.ID || item.Value.IsDeath == 1) { continue; } //是否是敌人 if (CheckIsEnemy(item.Value, my) == false) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(my.X, my.Y)); if (maxDis > dis) { float angle1 = Vector2.Angle(dir, new Vector2(item.Value.X - my.X, item.Value.Y - my.Y)); //是否超过最大角度 if (angle1 > MaxAngle) { continue; } if (minangelUnityEntity == null) { minangelUnityEntity = item.Value; minangle = angle1; } else if (angle1 < minangle) { minangelUnityEntity = item.Value; minangle = angle1; } } } return(minangelUnityEntity); }
//获取离本单位 夹角最小的单位 满足技能释放目标条件 且夹角小于45度 public UnityEntity GetMinAngleUnitForSkillTarget(UnityEntity my, Vector2 dir, Protomsg.SkillDatas skilldata) { if (my == null || dir == Vector2.zero || skilldata.CastRange <= 0) { return(null); } float minangle = 0; UnityEntity minangelUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == my.ID || item.Value.IsDeath == 1) { continue; } if (CheckCastSkillTarget(item.Value, my, skilldata) == false) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(my.X, my.Y)); if (skilldata.CastRange > dis) { float angle1 = Vector2.Angle(dir, new Vector2(item.Value.X - my.X, item.Value.Y - my.Y)); //是否超过最大角度 if (angle1 > MaxAngle) { continue; } if (minangelUnityEntity == null) { minangelUnityEntity = item.Value; minangle = angle1; } else if (angle1 < minangle) { minangelUnityEntity = item.Value; minangle = angle1; } } } return(minangelUnityEntity); }
public void UpdateTopBar() { //头顶条显示 if (m_TopBar != null) { m_TopBar.GetComponent <UnityEntityTopBar>().SetHP((int)((float)HP / MaxHP * 100)); m_TopBar.GetComponent <UnityEntityTopBar>().SetMP((int)((float)MP / MaxMP * 100)); m_TopBar.GetComponent <UnityEntityTopBar>().SetName(Name); m_TopBar.GetComponent <UnityEntityTopBar>().SetLevel(Level); var ismyguild = false; UnityEntity mainunit = GameScene.Singleton.GetMyMainUnit(); if (mainunit != null && mainunit.GuildID == GuildID) { ismyguild = true; } m_TopBar.GetComponent <UnityEntityTopBar>().SetGuildName(GuildName, ismyguild); var isEnemy = UnityEntityManager.Instance.CheckIsEnemy(this, GameScene.Singleton.GetMyMainUnit()); if (isEnemy) { m_TopBar.GetComponent <UnityEntityTopBar>().SetIsEnemy(true); } else { m_TopBar.GetComponent <UnityEntityTopBar>().SetIsEnemy(false); } if (IsDeath == 1) { m_TopBar.GetComponent <UnityEntityTopBar>().SetVisible(false); } else { if (m_Camp == 2 && (int)((float)HP / MaxHP * 100) == 100 && m_TopBar.GetComponent <UnityEntityTopBar>().GetBuffCount() <= 0)//NPC { m_TopBar.GetComponent <UnityEntityTopBar>().SetVisible(false); } else { m_TopBar.GetComponent <UnityEntityTopBar>().SetVisible(true); } } } }
public override void HitTop(UnityEntity e) { if (e is Goomba) { e.gameObject.SetActive(false); BounceOffGoomba(); } else if (e is Coin) { e.gameObject.SetActive(false); GetCoin(); } else if (e is Fire) { Die(); } }
//获取离本单位最近的敌方英雄和BOSS 且距离小于 distanse public UnityEntity GetNearestBigUnitForSkillTarget(UnityEntity my, Protomsg.SkillDatas skilldata, float distanse) { var myunityentity = my; if (myunityentity == null) { Debug.Log("GetNearestEnemy null"); return(null); } var mindis = distanse; UnityEntity nearrestUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == myunityentity.ID || item.Value.IsDeath == 1) { continue; } ////单位类型(1:英雄 2:普通单位 3:远古 4:boss) if (item.Value.IsBigUnit() == false) { continue; } if (CheckCastSkillTarget(item.Value, myunityentity, skilldata) == false) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(myunityentity.X, myunityentity.Y)); if (mindis > dis) { Debug.Log("dis " + dis); mindis = dis; nearrestUnityEntity = item.Value; } } return(nearrestUnityEntity); }
//刷新buf void FreshBuf() { UnityEntity mainunit = UnityEntityManager.Instance.GetUnityEntity(id); if (mainunit == null || mainunit.BuffDatas == null || mainunit.BuffDatas.Length <= 0) { BufsRes.Clear(); Bufs.RemoveChildren(); return; } foreach (var item in mainunit.BuffDatas) { if (BufsRes.ContainsKey(item.TypeID)) { SetBufData(BufsRes[item.TypeID], item); } else { AddBuf(item); } } //删除多余的 foreach (int key in new List <int>(BufsRes.Keys)) { var isfind = false; foreach (var item1 in mainunit.BuffDatas) { if (key == item1.TypeID) { isfind = true; break; } } if (isfind == false) { RemoveBuf(key); } } }
//获取离本单位最近的敌方英雄和BOSS 且距离小于 distanse public UnityEntity GetNearestBigEnemy(UnityEntity my, float distanse) { var myunityentity = my; if (myunityentity == null) { Debug.Log("GetNearestEnemy null"); return(null); } var mindis = distanse; UnityEntity nearrestUnityEntity = null; foreach (var item in m_UnityEntitys) { if (item.Key == myunityentity.ID || item.Value.IsDeath == 1) { continue; } ////单位类型(1:英雄 2:普通单位 3:远古 4:boss) if (item.Value.IsBigUnit() == false) { continue; } //是否是敌人 if (CheckIsEnemy(item.Value, myunityentity) == false) { continue; } var dis = Vector2.Distance(new Vector2(item.Value.X, item.Value.Y), new Vector2(myunityentity.X, myunityentity.Y)); if (mindis >= dis) { //Debug.Log("dis " + dis); mindis = dis; nearrestUnityEntity = item.Value; } } return(nearrestUnityEntity); }
public void showHeadSelect(UnityEntity unit) { var headselect = UIPackage.CreateObject("GameUI", "HeadSelect").asCom; //GRoot.inst.AddChild(headselect); GRoot.inst.ShowPopup(headselect); headselect.xy = maininfo.xy; headselect.x += 50; headselect.y += 50; //注销组队功能 //headselect.GetChild("team").asButton.onClick.Add(() => //{ // if (GameScene.Singleton.m_MyMainUnit == null || unit == null) // { // GRoot.inst.HidePopup(headselect); // return; // } // Protomsg.CS_OrganizeTeam msg1 = new Protomsg.CS_OrganizeTeam(); // msg1.Player1 = GameScene.Singleton.m_MyMainUnit.ControlID; // msg1.Player2 = unit.ControlID; // MyKcp.Instance.SendMsg(GameScene.Singleton.m_ServerName, "CS_OrganizeTeam", msg1); // GRoot.inst.HidePopup(headselect); //}); headselect.GetChild("info").asButton.onClick.Add(() => { GRoot.inst.HidePopup(headselect); MyInfo myinfo = new MyInfo(unit); }); headselect.GetChild("siliao").asButton.onClick.Add(() => { ChatUI.SOpenChatBox("zonghe", unit.Name, unit.ControlID); GRoot.inst.HidePopup(headselect); }); }
public void FreshControl() { //System.Array.Clear(m_MyControlUnit,0, m_MyControlUnit.Length); m_MyControlUnit = new List <int>(); Dictionary <int, UnityEntity> all = UnityEntityManager.Instance.GetAllUnity(); foreach (var item in all) { if (item.Value.ControlID == LoginUI.UID) { m_MyControlUnit.Add(item.Key); if (item.Value.IsMain == 1) { m_MyMainUnit = item.Value; m_MyMainUnit.MySelefShowGreenCircle(true); DHCameraManager.SetFollowingTarget(item.Value); } } } }
public MyInfo(UnityEntity unit) { AudioManager.Am.Play2DSound(AudioManager.Sound_OpenUI); IsDestroy = false; this.unit = unit; this.InitNetData(); main = UIPackage.CreateObject("GameUI", "MyInfo").asCom; unitinfo = main.GetChild("heroInfo").asCom; baginfo = main.GetChild("bag").asCom; itemdropinfo = main.GetChild("drop").asCom; GRoot.inst.AddChild(main); //main.fairyBatching = true; Vector2 screenPos = new Vector2(Screen.width / 2, Screen.height / 2); Vector2 logicScreenPos = GRoot.inst.GlobalToLocal(screenPos); main.xy = logicScreenPos; //main.AddChild() Debug.Log("xy:" + main.xy + " screenxy:" + screenPos); Init(); //FreshData(); }
internal UnityComponent(UnityEntity unityEntity) { this.unityEntity = unityEntity; }
public override void HitBottom(UnityEntity e) { //DoNothing }
public override void HitSide(UnityEntity e, float side) { //DoNothing }
internal UnityLaserController(UnityEntity unityEntity) : base(unityEntity) { lineRenderer = unityEntity.gameObject.GetComponentInChildren <LineRenderer>(); lineMaterial = lineRenderer.material; }
float AttackSelectTargetDis = 8;//攻击目标选择范围 public void PressAttackBtn(int touchstate, Vector2 dir) { if (m_MyMainUnit == null) { return; } //AttackRange float showattackrange = AttackSelectTargetDis; if (m_MyMainUnit.AttackRange > showattackrange) { showattackrange = m_MyMainUnit.AttackRange; } if (touchstate == 1) { if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestBigEnemy(m_MyMainUnit, showattackrange); if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestEnemy(m_MyMainUnit); } } else { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); if (UnityEntityManager.Instance.CheckIsEnemy(m_TargetUnit, m_MyMainUnit) == false) { m_TargetUnit = UnityEntityManager.Instance.GetNearestBigEnemy(m_MyMainUnit, showattackrange); if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestEnemy(m_MyMainUnit); } } //不在范围内都重新寻找 //如果是普通单位且不在寻找攻击范围内 则重新寻找最近单位 var dis = Vector2.Distance(new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y), new Vector2(m_TargetUnit.X, m_TargetUnit.Y)); if (showattackrange < dis) { m_TargetUnit = UnityEntityManager.Instance.GetNearestBigEnemy(m_MyMainUnit, showattackrange); if (m_TargetUnit == null) { m_TargetUnit = UnityEntityManager.Instance.GetNearestEnemy(m_MyMainUnit); } } else { //单位类型(1:英雄 2:普通单位 3:远古 4:boss) //如果不是大仇恨敌方单位 if (m_TargetUnit.IsBigUnit() == false) { var bigenemy = UnityEntityManager.Instance.GetNearestBigEnemy(m_MyMainUnit, showattackrange); if (bigenemy != null) { m_TargetUnit = bigenemy; } else { //不在攻击范围内 if (m_MyMainUnit.AttackRange < dis) { m_TargetUnit = UnityEntityManager.Instance.GetNearestEnemy(m_MyMainUnit); } } } } } if (m_TargetUnit == null) { return; } m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); m_MyMainUnit.ShowSkillAreaLookAt(true, new Vector2(m_TargetUnit.X, m_TargetUnit.Y)); m_MyMainUnit.ShowOutCircle(true, showattackrange); } else if (touchstate == 2) { var target = UnityEntityManager.Instance.GetMinAngleEnemy(m_MyMainUnit, dir, showattackrange); if (target != null) { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(false); m_TargetUnit.TargetShowRedCircle(false); } m_TargetUnit = target; m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); var targetpos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (dir.normalized * showattackrange); //m_MyMainUnit.ShowSkillAreaLookAt(true, new Vector2(m_TargetUnit.X, m_TargetUnit.Y)); m_MyMainUnit.ShowSkillAreaLookAt(true, targetpos); } else { if (m_TargetUnit != null) { m_TargetUnit.TargetShow(true); m_TargetUnit.TargetShowRedCircle(true); var targetpos = new Vector2(m_MyMainUnit.X, m_MyMainUnit.Y) + (dir.normalized * showattackrange); m_MyMainUnit.ShowSkillAreaLookAt(true, targetpos); } } } else if (touchstate == 3) { if (m_TargetUnit == null) { return; } Protomsg.CS_PlayerAttack msg1 = new Protomsg.CS_PlayerAttack(); msg1.IDs.AddRange(m_MyControlUnit); msg1.TargetUnitID = m_TargetUnit.ID; MyKcp.Instance.SendMsg(m_ServerName, "CS_PlayerAttack", msg1); NextAutoAttackTime = 1; //Debug.Log("PressAttackBtn"); m_TargetUnit.TargetShow(false); m_MyMainUnit.ShowOutCircle(false, 10); m_MyMainUnit.ShowSkillAreaLookAt(false, Vector2.zero); } return; }