void OnDragging(DragInfo dragInfo) { //タイル上 var targetPosition = TileBase.GetArrayFromRay(dragInfo.pos); if (targetPosition == null) { return; } //まだ未通過 if (IntVect2D.IsEqual(targetPosition, nowTraceTiles.LastOrDefault())) { return; } //まだ未完成 if (skillTiles.Count == nowTraceTiles.Count) { return; } //次のタイル if (IntVect2D.IsEqual(targetPosition, IntVect2D.Add(skillTiles[nowTraceTiles.Count], nowTraceTiles[0])) == false) { FailAciton(); return; } nowTraceTiles.Add(targetPosition); BattleStage.Instance.ChangeColor(targetPosition, TileState.Skill); }
//実際に移動 protected void UpdatePosition(IntVect2D newPosition) { //移動方向 var direction = IntVect2D.GetDirection(character.positionArray, newPosition); //移動先のタイル位置 var toTilePostion = BBattleStage.Instance.GetTileXAndZPosition(newPosition); var table = GetMoveTable(toTilePostion); //現在のタイルの実座標 var oldTilePosition = BBattleStage.Instance.GetTileXAndZPosition(character.positionArray); //カメラをアップデート BCameraMove.Instance.FollowCharacter(toTilePostion - oldTilePosition, animator.moveTime); //座標変更 iTween.MoveTo(gameObject, table); isDone = true; isNowAction = true; //配列値変更 character.positionArray = newPosition; StartRotateAnimation(direction); StartAnimation(); UpdateInManualState(); //UI UIBottomCommandParent.UICommandState = EUICommandState.Action; UIBottomAllParent.Instance.UpdateUI(); }
public void OnEndDrag(PointerEventData e) { //タイルの取得 var tile=GameObject.FindGameObjectsWithTag("Tile") .Where(x=>RectTransformUtility.RectangleContainsScreenPoint(x.GetComponent<RectTransform>(),e.position)==true &&x.GetComponent<ETile>().isAttachable==true) .Select(x=>x.GetComponent<ETile>()) .FirstOrDefault(); //タイル外 if (tile == null) { rectTransform.position = oldPosition; return; } //他キャラクターの取得 var otherTile=GameObject.FindGameObjectsWithTag("Edit/Character") .Where(x=>x.GetComponent<ECharacterIcon>().vect2D==tile.vect) .FirstOrDefault(); //既にいる if(otherTile!=null){ rectTransform.position = oldPosition; return; } rectTransform.position = CSTransform.CopyVector3(tile.GetComponent<RectTransform>().position); oldPosition = CSTransform.CopyVector3(rectTransform.position); vect2D = tile.vect; }
public void OnEndDrag(PointerEventData e) { //タイルの取得 var tile = GameObject.FindGameObjectsWithTag("Tile") .Where(x => RectTransformUtility.RectangleContainsScreenPoint(x.GetComponent <RectTransform>(), e.position) == true && x.GetComponent <ETile>().isAttachable == true) .Select(x => x.GetComponent <ETile>()) .FirstOrDefault(); //タイル外 if (tile == null) { rectTransform.position = oldPosition; return; } //他キャラクターの取得 var otherTile = GameObject.FindGameObjectsWithTag("Edit/Character") .Where(x => x.GetComponent <ECharacterIcon>().vect2D == tile.vect) .FirstOrDefault(); //既にいる if (otherTile != null) { rectTransform.position = oldPosition; return; } rectTransform.position = CSTransform.CopyVector3(tile.GetComponent <RectTransform>().position); oldPosition = CSTransform.CopyVector3(rectTransform.position); vect2D = tile.vect; }
//なぞり開始 void OnDraggingStart(DragInfo dragInfo) { isNowAttackable = false; //タイル上 var tilePosition = TileBase.GetArrayFromRay(dragInfo.pos); if (tilePosition == null) { return; } //キャラクターの上 if (IntVect2D.IsEqual(tilePosition, character.positionArray) == false) { return; } BattleStage.Instance.ResetAllTileColor(); nowTraceTiles = new List <IntVect2D>(); nowTraceTiles.Add(tilePosition); BattleStage.Instance.ChangeColor(tilePosition, TileState.Skill); IT_Gesture.onDraggingE += OnDragging; IT_Gesture.onDraggingEndE += OnDraggingEnd; isNowCharge = true; ActionSelect.Instance.DisableMoveAttackButton(); }
//攻撃範囲に近づくように移動 void MoveForApproach() { var toVect2D = new IntVect2D[] { new IntVect2D(movableCount, 0), new IntVect2D(-movableCount, 0), new IntVect2D(0, movableCount), new IntVect2D(0, -movableCount) }; toVect2D = toVect2D.Shuffle(); List <VectAndDistance> vectAndDistance = new List <VectAndDistance>(); //各移動後における攻撃範囲と敵キャラとの最小距離取得 foreach (var toV in toVect2D) { vectAndDistance.Add(new VectAndDistance(GetDistanceInAttackRange(IntVect2D.Add(character.positionArray, toV)), toV)); } //距離が小さい順に移動試行 foreach (var toV in vectAndDistance.OrderBy(v => v.distance).Select(v => v.vect)) { RequestMoveFromVect2D(toV); if (isDone == true) { break; } } }
void RandamMove() { var toVect2D = new IntVect2D[] { new IntVect2D(movableCount, 0), new IntVect2D(-movableCount, 0), new IntVect2D(0, movableCount), new IntVect2D(0, -movableCount) }; //移動可能範囲を取得 toVect2D = toVect2D.Shuffle(); foreach (var toV in toVect2D) { RequestMoveFromVect2D(toV); if (isDone == true) { break; } } if (isDone == false) { isDone = true; if (OnCompleteMove != null) { OnCompleteMove(); } } }
//攻撃範囲と敵キャラとの距離 float GetDistanceInAttackRange(IntVect2D position) { //攻撃可能位置の設定 var attackablePosition = attackParameter.attackRanges.Select(x => IntVect2D.Add(x, position)).ToList(); //攻撃取得失敗 if (attackablePosition == null) { return(-1); } //攻撃可能位置にいるキャラクターとの距離,不可能=100 float distance = 100; foreach (var pos in attackablePosition) { //攻撃位置と敵キャラとの距離比較 //最小を設定 var dis = BCharacterManager.Instance.GetOpponentCharacters(character.isEnemy) .Min(x => IntVect2D.Distance(x.positionArray, pos)); distance = Mathf.Min(distance, dis); } //一番近い位置がターゲット return(distance); }
void OnDragging(DragInfo dragInfo) { //もうなぞれない if (nowTraceTiles.Count == moveRange) { return; } //タイル上 var tilePosition = TileBase.GetArrayFromRay(dragInfo.pos); if (tilePosition == null) { return; } //まだ未通過 if (IntVect2D.IsEqual(tilePosition, nowTraceTiles.LastOrDefault())) { return; } //まだ未完成 if (moveRange == nowTraceTiles.Count) { return; } //次のタイル if (IntVect2D.IsNeighbor(tilePosition, nowTraceTiles.LastOrDefault()) == false) { return; } nowTraceTiles.Add(tilePosition); BattleStage.Instance.ChangeColor(tilePosition, TileState.Skill); }
public override void Init(IntVect2D array) { base.Init(array); isEnemy = false; OnActivePlayerE += BCharacterManager.Instance.SetActivePlayer; }
bool SetTarget() { //攻撃可能位置の設定 var attackablePosition = selectAttackParameter.attackRanges.Select(x => IntVect2D.Add(x, character.positionArray)).ToList(); if (attackablePosition == null) { return(false); } //デバッグ出力 //攻撃可能位置にいるキャラクター var opponentCharacters = new List <BCharacterBase>(); foreach (var pos in attackablePosition) { var chara = BCharacterManager.Instance.GetOpponentCharacterOnTileFormVect2D(pos, character.isEnemy); if (chara != null) { opponentCharacters.Add(chara); } } if (opponentCharacters.Count == 0) { return(false); } //一番近い位置がターゲット attackTarget.Add(opponentCharacters.OrderBy(c => IntVect2D.Distance(c.positionArray, character.positionArray)).First()); return(true); }
void OnDragging(DragInfo dragInfo) { //もうなぞれない if (nowTraceTiles.Count == selectAttackParameter.moveRange) { return; } //タイル上 var tilePosition = BBattleStage.Instance.GetTilePositionFromScreenPosition(dragInfo.pos); if (tilePosition == null) { return; } //まだ未通過 if (IntVect2D.IsEqual(tilePosition, nowTraceTiles.LastOrDefault())) { return; } //まだ未完成 if (selectAttackParameter.moveRange == nowTraceTiles.Count) { return; } //次のタイル if (IntVect2D.IsNeighbor(tilePosition, nowTraceTiles.LastOrDefault()) == false) { return; } nowTraceTiles.Add(tilePosition); BBattleStage.Instance.ChangeColor(tilePosition, TileState.Skill); }
void StartRotateAnimation(IntVect2D vect) { float angleX = vect.x * 90; float angleY = Mathf.Sign(vect.y) > 0 ? 0 : 180; float isEnemyAngle = character.isEnemy == false ? 1 : -1; transform.eulerAngles = new Vector3(0, angleX + isEnemyAngle * angleY, 0); }
//一連の移動判定処理の開始 void RequestMove(Vector2 delta) { //カメラから方向取得 var toVect = BCameraMove.Instance.GetMoveDirection(delta); //Vect2D化 var toVect2D = IntVect2D.GetDirectionFromVector2(toVect); RequestMoveFromVect2D(toVect2D); }
public override void Init(IntVect2D array) { base.Init(array); isEnemy = true; //回転 transform.rotation = Quaternion.Euler(0, 180, 0); OnActiveEnemyE += BCharacterManager.Instance.SetActiveEnemy; }
public virtual void Init(IntVect2D array) { positionArray.x = array.x; positionArray.y = array.y; //ライフ設定 life.Init(characterParameter); OnEndActiveStaticE += BCharacterManager.Instance.ResetActiveCharacter; }
//タイルのVect2Dを返す public IntVect2D GetTilePosition(IntVect2D position) { var tile = GetTile(position); if (tile == null) { return(null); } return(GetTile(position).positionArray); }
public void Init(IntVect2D array, bool isEne) { isEnemy = isEne; if (isEnemy == true) { transform.rotation = Quaternion.Euler(0, 180, 0); } positionArray.x = array.x; positionArray.y = array.y; }
//攻撃選択 public void OnSlectWaza(BCharacterBase chara, SingleAttackParameter selectWaza) { ResetAllTileColor(); //攻撃範囲取得 foreach (var range in selectWaza.attackRanges) { var pos = IntVect2D.Clone(chara.positionArray); pos = IntVect2D.Add(pos, range); ChangeColor(pos, TileState.Attack); } }
public void Init(IntVect2D v, bool _isAttachable, ETileCreater _tileCreater) { vect = v; tileCreater = _tileCreater; isAttachable = _isAttachable; if (isAttachable == true) { var sprite = GetComponent <Image>(); sprite.sprite = Resources.Load <Sprite>("EditScene/mass_attack_sprite"); } }
public void ChangeTilesColorFromDistance(IntVect2D position, TileState toState, float distance, bool reset = false) { if (reset) { ResetAllTileColor(); } foreach (var tile in GetTilesFormDistance(position, distance)) { tile.ChangeColor(toState); } }
//上下左右のタイル色変更 public void ChangeNeighborTilesColor(IntVect2D position, TileState toState, bool reset = false) { if (reset) { ResetAllTileColor(); } foreach (var tile in GetVerticalHorizontalTiles(position)) { tile.ChangeColor(toState); } }
public void Init(IntVect2D v, bool _isAttachable, ETileCreater _tileCreater) { vect = v; tileCreater = _tileCreater; isAttachable = _isAttachable; if (isAttachable == true) { var sprite = GetComponent<Image>(); sprite.sprite = Resources.Load<Sprite>("EditScene/mass_attack_sprite"); } }
//実際に移動 void UpdatePosition(IntVect2D newPosition) { //移動先のタイル位置 var toTilePostion = BBattleStage.Instance.GetTileXAndZPosition(newPosition); var table = GetMoveTable(toTilePostion); //座標変更 iTween.MoveTo(gameObject, table); //配列値変更 character.positionArray = newPosition; }
//一連の移動判定処理の開始 public void RequestMoveFromVect2D(IntVect2D toVect2D) { //新しいタイルポジション var newPosition = new IntVect2D( Mathf.Clamp(character.positionArray.x + toVect2D.x, -BBattleStage.stageSizeX, BBattleStage.stageSizeX), Mathf.Clamp(character.positionArray.y + toVect2D.y, -BBattleStage.stageSizeY, BBattleStage.stageSizeY)); //移動先が空いている if (BCharacterManager.Instance.IsExistCharacterOnTile(newPosition) == true) return; //移動実行 UpdatePosition(newPosition); }
public void ChangeColor(IntVect2D position, TileState state, bool reset = false) { if (reset) { ResetAllTileColor(); } var tile = GetTile(position); if (tile == null) { return; } tile.ChangeColor(state); }
//Vect2Dからキャラクター取得 public BCharacterBase GetCharacterOnTile(IntVect2D vect) { //タイル以外 if (vect == null) { return(null); } //ターゲットの検索 var target = GetCharacterFromVect2D(vect); ////ターゲットが存在しないマスをタップ //if (target == null) return null; return(target); }
//タイル上のキャラが自身にとっての敵キャラなら取得 public BCharacterBase GetOpponentCharacterOnTileFormVect2D(IntVect2D toPos, bool isEnemy) { var chara = GetCharacterOnTile(toPos); if (chara == null) { return(null); } if (chara.isEnemy != isEnemy) { return(chara); } return(null); }
//一連の移動判定処理の開始 public void RequestMoveFromVect2D(IntVect2D toVect2D) { //新しいタイルポジション var newPosition = new IntVect2D( Mathf.Clamp(character.positionArray.x + toVect2D.x, -BBattleStage.stageSizeX, BBattleStage.stageSizeX), Mathf.Clamp(character.positionArray.y + toVect2D.y, -BBattleStage.stageSizeY, BBattleStage.stageSizeY)); //移動先が空いている if (BCharacterManager.Instance.IsExistCharacterOnTile(newPosition) == true) { return; } //移動実行 UpdatePosition(newPosition); }
//タイル上のキャラを取得 //呼ばれる場所の統一化が必要 public static Character GetCharacterOnTile(IntVect2D toPos) { var objects = GameObject.FindGameObjectsWithTag("BattleCharacter"); var characters = new List <Character>(); Debug.Log(objects.Length); foreach (var obj in objects) { if (obj == null) { Debug.Log("Error"); } else { characters.Add(obj.GetComponent <Character>()); } } Debug.Log(objects.Length); foreach (var ob in objects) { Debug.Log(ob.name); } foreach (var obj in characters) { if (IntVect2D.IsEqual(obj.positionArray, toPos) == true) { return(obj); } } return(null); //Linqが止まる原因か検証 /* * return GameObject.FindGameObjectsWithTag("BattleCharacter"). * Select(t => t.GetComponent<Character>()). * Where(t => IntVect2D.IsEqual(toPos, t.positionArray)). * FirstOrDefault(); */ }
//なぞり開始 void OnDraggingStart(DragInfo dragInfo) { if (isDone == true) { return; } //タイル上 var tilePosition = BBattleStage.Instance.GetTilePositionFromScreenPosition(dragInfo.pos); if (tilePosition == null) { return; } //キャラクターの上 if (IntVect2D.IsEqual(tilePosition, character.positionArray) == false) { return; } BBattleStage.Instance.ResetAllTileColor(); nowTraceTiles = new List <IntVect2D>(); nowTraceTiles.Add(tilePosition); foreach (var target in attackTarget) { target.SetTargeted(false); } attackTarget = new List <BCharacterBase>(); UIBottomCommandParent.UICommandState = EUICommandState.ExecuteAttack; UIBottomCommandParent.Instance.UpdateUI(); //タイル BBattleStage.Instance.OnSelecSkillTarget(tilePosition); IT_Gesture.onDraggingE += OnDragging; IT_Gesture.onDraggingEndE += OnDraggingEnd; //ActionSelect.Instance.DisableMoveAttackButton(); }
//移動後攻撃範囲にいたら移動 bool TryMoveInAttackRange() { var toVect2D = new IntVect2D[] { new IntVect2D(movableCount, 0), new IntVect2D(-movableCount, 0), new IntVect2D(0, movableCount), new IntVect2D(0, -movableCount) }; //移動可能範囲を取得 toVect2D = toVect2D.Shuffle(); foreach (var toV in toVect2D) { if (CheckExistInAttackRange(IntVect2D.Add(character.positionArray, toV))) { RequestMoveFromVect2D(toV); } if (isDone == true) { return(true); } } return(false); }
void RandamMove() { var toVect2D = new IntVect2D[] { new IntVect2D(movableCount, 0), new IntVect2D(-movableCount, 0), new IntVect2D(0, movableCount), new IntVect2D(0, -movableCount) }; //移動可能範囲を取得 toVect2D = toVect2D.Shuffle(); foreach (var toV in toVect2D) { RequestMoveFromVect2D(toV); if (isDone == true) { break; } } if (isDone == false) { isDone = true; if (OnCompleteMove != null) OnCompleteMove(); } }
//攻撃範囲に近づくように移動 void MoveForApproach() { var toVect2D = new IntVect2D[] { new IntVect2D(movableCount, 0), new IntVect2D(-movableCount, 0), new IntVect2D(0, movableCount), new IntVect2D(0, -movableCount) }; toVect2D = toVect2D.Shuffle(); List<VectAndDistance> vectAndDistance = new List<VectAndDistance>(); //各移動後における攻撃範囲と敵キャラとの最小距離取得 foreach (var toV in toVect2D) { vectAndDistance.Add(new VectAndDistance(GetDistanceInAttackRange(IntVect2D.Add(character.positionArray, toV)), toV)); } //距離が小さい順に移動試行 foreach (var toV in vectAndDistance.OrderBy(v => v.distance).Select(v=>v.vect)) { RequestMoveFromVect2D(toV); if (isDone == true) { break; } } }
bool IsInAttackRange(IntVect2D targetPositionArray) { return selectAttackParameter.attackRanges.Any(x => x.IsEqual(IntVect2D.Sub(targetPositionArray, character.positionArray))); }
//タイル上のキャラを取得 //呼ばれる場所の統一化が必要 public static Character GetCharacterOnTile(IntVect2D toPos) { var objects = GameObject.FindGameObjectsWithTag("BattleCharacter"); var characters=new List<Character>(); Debug.Log(objects.Length); foreach (var obj in objects) { if (obj == null) { Debug.Log("Error"); } else { characters.Add(obj.GetComponent<Character>()); } } Debug.Log(objects.Length); foreach (var ob in objects) { Debug.Log(ob.name); } foreach (var obj in characters) { if (IntVect2D.IsEqual(obj.positionArray, toPos) == true) { return obj; } } return null; //Linqが止まる原因か検証 /* return GameObject.FindGameObjectsWithTag("BattleCharacter"). Select(t => t.GetComponent<Character>()). Where(t => IntVect2D.IsEqual(toPos, t.positionArray)). FirstOrDefault(); */ }
//移動後攻撃範囲にいたら移動 bool TryMoveInAttackRange() { var toVect2D = new IntVect2D[] { new IntVect2D(movableCount, 0), new IntVect2D(-movableCount, 0), new IntVect2D(0, movableCount), new IntVect2D(0, -movableCount) }; //移動可能範囲を取得 toVect2D = toVect2D.Shuffle(); foreach (var toV in toVect2D) { if (CheckExistInAttackRange(IntVect2D.Add(character.positionArray,toV))) { RequestMoveFromVect2D(toV); } if (isDone == true)return true; } return false; }
//攻撃範囲に敵がいる bool CheckExistInAttackRange(IntVect2D position) { return GetDistanceInAttackRange(position) == 0; }
//ターゲット解除 public void OnCancelSkillTarget(IntVect2D targetPosition) { ChangeColor(targetPosition, TileState.Default); }
// Use this for initialization void Start() { vect2D = new IntVect2D(IntVect2D.nullNumber, IntVect2D.nullNumber); rectTransform = GetComponent<RectTransform>(); oldPosition = CSTransform.CopyVector3(rectTransform.position); }
public VectAndDistance(float dis, IntVect2D v) { distance = dis; vect = v; }
public void Init(IntVect2D array) { positionArray.x = array.x; positionArray.y = array.y; }
//攻撃範囲と敵キャラとの距離 float GetDistanceInAttackRange(IntVect2D position) { //攻撃可能位置の設定 var attackablePosition = attackParameter.attackRanges.Select(x => IntVect2D.Add(x, position)).ToList(); //攻撃取得失敗 if (attackablePosition == null) return -1; //攻撃可能位置にいるキャラクターとの距離,不可能=100 float distance = 100; foreach (var pos in attackablePosition) { //攻撃位置と敵キャラとの距離比較 //最小を設定 var dis=BCharacterManager.Instance.GetOpponentCharacters(character.isEnemy) .Min(x => IntVect2D.Distance(x.positionArray, pos)); distance = Mathf.Min(distance, dis); } //一番近い位置がターゲット return distance; }