bool AIUse_SelectUnit(SkillOperateData skillData) { skillData.receiveList.Clear(); List <UnitCtl> buildList = War.scene.buildList; //ai目标 SkillWarConf skillWarConf = War.model.GetSkillWarConf(skillData.skillId); if (skillWarConf.getTargetType() == (int)eSkillWarTargetType.eEffectTargetBuildBeHitMinHp)//正在被攻击&人口最少,没有被攻击则选人口最少的 { int unitType = 0; unitType = unitType.UBuild(true); int relation = 0; relation = relation.ROwn(true); List <UnitCtl> listTmp = War.scene.SearchUnit(unitType, legionData.legionId, relation); foreach (UnitCtl unit in listTmp) { if (unit.unitData.behit == true) { skillData.receiveList.Add(unit); return(true); } } //没有正在被攻击的城池,选择人口钌俚锰 UnitCtl unitMin = null; float hpTmp = 10000.0f; foreach (UnitCtl unit in listTmp) { if (unit.hp <= hpTmp) { hpTmp = unit.hp; unitMin = unit; } } if (unitMin != null) { if (skillData.EnableUse(unitMin)) { skillData.receiveList.Add(unitMin); return(true); } else { return(false); } } } List <UnitCtl> candidatesList = new List <UnitCtl> (); foreach (UnitCtl entity in buildList) { if (skillData.EnableUse(entity)) { candidatesList.Add(entity); } } UnitCtl select = null; foreach (UnitCtl entity in candidatesList) { select = entity; if (select.legionData.type != LegionType.Neutral) { break; } } if (select != null) { skillData.receiveList.Add(select); return(true); } return(false); }
/** 鼠标--拖动 */ public void OnDragHandler() { // Debug.Log("SkillOperateController OnDragHandler _isDrag=" + _isDrag); if (!interactable) { return; } ClearSelectCacheList(); rectTransform.anchoredPosition = Input.mousePosition * rate; SkillOperateState operateState = SkillOperateState.Drag_Object; Ray ray = uiCamera.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit2D = Physics2D.Raycast(ray.origin, ray.direction); if (hit2D.collider != null) { //如果射线检测到的gameobject为grid,就把当前Panel放在grid节点下 if (hit2D.collider.gameObject == buttonStateRect) { operateState = SkillOperateState.Drag_Button; } } if (data.skillConfig.operate == SkillOperateType.SelectUnit || data.skillConfig.operate == SkillOperateType.SelectCircle) { scaleNode.localScale = Vector3.one * Mathf.Lerp(1, 0f, operateState == SkillOperateState.Drag_Button ? Mathf.Abs(rectTransform.position.y - initPosition.y) / 2.5f : 1f); } else { scaleNode.localScale = Vector3.one * Mathf.Lerp(1, 0.5f, operateState == SkillOperateState.Drag_Button ? Mathf.Abs(rectTransform.position.y - initPosition.y) / 2.5f : 1f); } skillInfoNode.Visiable = operateState == SkillOperateState.Drag_Object; if (bezierArrow.useing) { if (data.operateState != operateState) { bezierArrow.Visiable = operateState == SkillOperateState.Drag_Object; } } data.operateState = operateState; bool hasTarget = true; if (data.skillConfig.operate == SkillOperateType.SelectUnit) { hasTarget = data.candidateReceiveCount > 0; } skillInfoNode.HasTarget = hasTarget; bool isSnap = data.skillConfig.operate == SkillOperateType.SelectUnit; RaycastHit hit3d; ray = Camera.main.ScreenPointToRay(Input.mousePosition); data.candidateEntity = null; if (isSnap && War.config.skillSnap && data.operateState == SkillOperateState.Drag_Object) { if (Physics.Raycast(ray, out hit3d, maxDistance, groundLayer.value)) { Vector3 hitPoint = hit3d.point.SetY(0F); float minDistance = float.MaxValue; UnitCtl minEntity = null; for (int i = 0; i < data.candidateReceiveList.Count; i++) { UnitCtl entity = data.candidateReceiveList [i]; float distance = Vector3.Distance(hitPoint, entity.transform.position); if (distance < minDistance) { minDistance = distance; minEntity = entity; } } data.candidateEntity = minEntity; } } else { if (isSnap) { if (Physics.Raycast(ray, out hit3d, maxDistance, unitLayer.value)) { UnitCtl entity = hit3d.collider.gameObject.GetComponent <UnitCtl> (); if (entity != null && data.EnableUse(entity)) { data.candidateEntity = entity; } } } else if (data.skillConfig.operate == SkillOperateType.SelectCircle) { if (Physics.Raycast(ray, out hit3d, maxDistance, groundLayer.value)) { obj.transform.position = hit3d.point.SetY(0F); List <UnitCtl> entityList = War.scene.SearchUnit(obj.transform.position, data.skillConfig.radius, data.skillConfig.unitType, data.legionId, data.skillConfig.relation); for (int i = 0; i < entityList.Count; i++) { AddSelectCache(entityList[i]); } helpPoint.anchoredPosition = Camera.main.WorldToScreenPoint(obj.transform.position) * rate; } } } if (isSnap) { if (data.candidateEntity != null) { rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(data.candidateEntity.transform.position) * rate; if (obj != null) { obj.transform.position = data.candidateEntity.transform.position; } AddSelectCache(data.candidateEntity); } else if (obj != null) { if (Physics.Raycast(ray, out hit3d, maxDistance, groundLayer.value)) { obj.transform.position = hit3d.point.SetY(0F); } } helpPoint.anchoredPosition = rectTransform.anchoredPosition; } else { helpPoint.anchoredPosition = rectTransform.anchoredPosition; } // if(obj != null) // { // // if(isSnap && Physics.Raycast(ray, out hit3d, maxDistance, unitLayer.value)) // { // UnitCtl entity = hit3d.collider.gameObject.GetComponent<UnitCtl>(); // if(entity != null && data.EnableUse(entity)) // { // obj.transform.position = hit3d.collider.transform.position; // // // AddSelectCache (entity); // } // // } // else if(Physics.Raycast(ray, out hit3d, maxDistance, groundLayer.value)) // { // obj.transform.position = hit3d.point.SetY(0F); // // // List<UnitCtl> entityList = War.scene.SearchUnit (obj.transform.position, data.skillConfig.radius, data.skillConfig.unitType, data.legionId, data.skillConfig.relation); //// List<UnitCtl> entityList = War.scene.SearchUnit (obj.transform.position, data.skillConfig.radius, 0.USolider(true), data.legionId, 0.REnemy(true)); // // // for(int i = 0; i < entityList.Count; i++) // { // AddSelectCache (entityList[i]); // } // } // // // helpPoint.anchoredPosition = Camera.main.WorldToScreenPoint(obj.transform.position) * rate; // // } // else // { // if(isSnap && Physics.Raycast(ray, out hit3d, maxDistance, unitLayer.value)) // { // UnitCtl entity = hit3d.collider.gameObject.GetComponent<UnitCtl>(); // if(entity != null && data.EnableUse(entity)) // { // rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(hit3d.collider.transform.position) * rate; // AddSelectCache (entity); // } // } // // helpPoint.anchoredPosition = rectTransform.anchoredPosition; // } if (bezierArrow.useing) { bezierArrow.endAnchor.position = helpPoint.position + new Vector3(0, 0, 5); } SetSelectCacheListEffect(); }