IEnumerator SwapTwoItemRoutine(Card a, Card b, bool force) { if (!Iteraction) { a.SetBorder(false); b.SetBorder(false); yield break; } // cancellation terms if (swaping) { a.SetBorder(false); b.SetBorder(false); yield break; // If the process is already running } if (!a || !b) { if (a) { a.SetBorder(false); } if (b) { b.SetBorder(false); } yield break; // If one of the chips is missing } if (a.destroying || b.destroying) { a.SetBorder(false); b.SetBorder(false); yield break; } if (a.Slot == null || a.Slot.Block != null || b.Slot == null || b.Slot.Block != null) { a.SetBorder(false); b.SetBorder(false); yield break; // If one of the chips is blocked } if (!FightMgr.Instance.CanIAnimate()) { a.SetBorder(false); b.SetBorder(false); yield break; // If the core prohibits animation } // if (FightMgr.Instance.movesCount <= 0) // { // a.SetBorder(false); // b.SetBorder(false); // // FightMgr.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves); // yield break; // If not enough moves // } if (FightMgr.Instance.timeLeft <= 0) { a.SetBorder(false); b.SetBorder(false); yield break; // If not enough time } //SessionControl.Mix mix = SessionControl.Instance.mixes.Find(x => x.Compare(a.chipType, b.chipType)); int move = 0; // Number of points movement which will be expend FightMgr.Instance.animate++; swaping = true; Vector3 posA = a.Slot.transform.position; Vector3 posB = b.Slot.transform.position; float progress = 0; Vector3 normal = a.Slot.Point.X == b.Slot.Point.X ? Vector3.right : Vector3.up; float time = 0; // Animation swapping 2 chips while (progress < swapDuration) { if (a == null || b == null) { FightMgr.Instance.animate--; swaping = false; if (a) { a.SetBorder(false); } if (b) { b.SetBorder(false); } yield break; } time = EasingFunctions.easeInOutQuad(progress / swapDuration); a.transform.position = Vector3.Lerp(posA, posB, time) + normal * Mathf.Sin(3.14f * time) * 0.05f; //if (mix == null) b.transform.position = Vector3.Lerp(posB, posA, time) - normal * Mathf.Sin(3.14f * time) * 0.05f; progress += Time.deltaTime; yield return(0); } a.transform.position = posB; //if (SessionControl.Instance.movesCount <= 0 || mix == null) b.transform.position = posA; a.movementID = FightMgr.Instance.GetMovementID(); b.movementID = FightMgr.Instance.GetMovementID(); // if (SessionControl.Instance.movesCount > 0 && mix != null) // { // Scenario mix effect // swaping = false; // SessionControl.Instance.MixChips(a, b); // a.SetBorder(false); // b.SetBorder(false); // // yield return new WaitForSeconds(0.3f); // SessionControl.Instance.movesCount--; // SessionControl.Instance.animate--; // // // // SessionControl.Instance.SuccessMoveCounter(); // yield break; // } // Scenario the effect of swapping two chips // SlotForCard slotA = a.parentSlot; // SlotForCard slotB = b.parentSlot; // slotB.SetChip(a); // slotA.SetChip(b); Slot slotA = a.Slot; Slot slotB = b.Slot; slotA.SetChip(b); slotB.SetChip(a); move++; // searching for solutions of matching int count = 0; Solution solution = null; //todo yangzj solution = slotA.MatchAnaliz(); if (solution != null && solution.count > 0) { count += solution.count; if (FightMgr.Instance.movesCount > 0) { FightMgr.Instance.ListSoution.Add(solution); } } // solution = slotA.MatchSquareAnaliz(); // if (solution != null) count += solution.count; solution = slotB.MatchAnaliz(); if (solution != null && solution.count > 0) { count += solution.count; if (FightMgr.Instance.movesCount > 0) { FightMgr.Instance.ListSoution.Add(solution); } } // solution = slotB.MatchSquareAnaliz(); // if (solution != null) count += solution.count; // Scenario canceling of changing places of chips if (FightMgr.Instance.movesCount <= 0 || (count == 0 && !force)) { if (FightMgr.Instance.movesCount <= 0) { //显示不能移动提示 FightMgr.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves); } // AudioAssistant.Shot("SwapFailed"); while (progress > 0) { time = EasingFunctions.easeInOutQuad(progress / swapDuration); a.transform.position = Vector3.Lerp(posA, posB, time) - normal * Mathf.Sin(3.14f * time) * 0.05f; b.transform.position = Vector3.Lerp(posB, posA, time) + normal * Mathf.Sin(3.14f * time) * 0.05f; progress -= Time.deltaTime; yield return(0); } a.transform.position = posA; b.transform.position = posB; a.movementID = FightMgr.Instance.GetMovementID(); b.movementID = FightMgr.Instance.GetMovementID(); slotB.SetChip(b); slotA.SetChip(a); a.SetBorder(false); b.SetBorder(false); move--; } else { // AudioAssistant.Shot("SwapSuccess"); FightMgr.Instance.swapEvent++; // SessionControl.Instance.SuccessMoveCounter(); FightMgr.Instance.NeedSaveFirstDamage = true; if (TouchMgr.Instance.AfterMoveHandler != null) { TouchMgr.Instance.AfterMoveHandler(a.Slot); } } // SessionControl.Instance.firstChipGeneration = false; FightMgr.Instance.movesCount -= move; FightMgr.Instance.EventCounter(); FightMgr.Instance.animate--; // Debug.Log("animation:" + FightMgr.Instance.animate); a.SetBorder(false); b.SetBorder(false); swaping = false; }
// Update is called once per frame void Update() { // return; if (!Slot) { if (!destroying) { DestroyChip(); } return; } if (FightMgr.Instance.IsIceBlcok) { return; } // if (!FightMgr.Instance.isPlaying) // { // //DebugUtil.Warning("cant update card,status:" + FightControl.Instance.IsFighting + "," + SessionControl.Instance.isPlaying); // return; // } // if(Slot && Slot.IsGenerator && Slot.slotGravity) // { // Card card = Slot[Slot.slotGravity.gravityDirection].Card; // this.gameObject.SetActive(!card.IsDrop); // } // // if (impulse != Vector3.zero && (parentSlot || impulsParent.z != -1)) // { // if (impulsParent.z == -1) // { // if (!parentSlot) // { // impulse = Vector3.zero; // return; // } // if (!move) gravity = true; // move = true; // impulsParent = parentSlot.transform.position; // } // if (impulse.sqrMagnitude > 36) // impulse = impulse.normalized * 6; // transform.position += impulse * Time.deltaTime; // transform.position += (impulsParent - transform.position) * Time.deltaTime; // impulse -= impulse * Time.deltaTime; // impulse -= 3f * (transform.position - impulsParent); // impulse *= 1 - 6 * Time.deltaTime; // if ((transform.position - impulsParent).magnitude < 2 * Time.deltaTime && impulse.magnitude < 2) { // // impulse = Vector3.zero; // transform.position = impulsParent; // impulsParent.z = -1; // if (move) { // gameObject.SendMessage("OnHit", SendMessageOptions.DontRequireReceiver); // gravity = false; // } // // move = false; // // } // return; // } // if (impulse != Vector3.zero && (parentSlot || impulsParent.z != -1)) // { // if (impulsParent.z == -1) // { // if (!parentSlot) // { // impulse = Vector3.zero; // return; // } // if (!move) gravity = true; // move = true; // impulsParent = Vector3.zero; // } // // transform.localPosition += impulse * Time.deltaTime; // // transform.localPosition += (impulsParent - transform.localPosition) * Time.deltaTime; // // impulse -= impulse * Time.deltaTime; // impulse -= 3f * (transform.localPosition - impulsParent); // impulse *= 1 - 6 * Time.deltaTime; // // if ((transform.localPosition - impulsParent).magnitude < 140 * Time.deltaTime && impulse.magnitude < 140) { // // impulse = Vector3.zero; // transform.localPosition = impulsParent; // impulsParent.z = -1; // if (move) { // gameObject.SendMessage("OnHit", SendMessageOptions.DontRequireReceiver); // gravity = false; // } // // move = false; // // } // return; // } if (destroying) { return; } if (!FightMgr.Instance.CanIGravity() || !can_move) { // if(IsDrop && move) // { // //DebugUtil.Debug("update card:" + this.gameObject.name); // IsDrop = false; // move = false; // velocity = 0; // movementID = FightMgr.Instance.GetMovementID(); // // gravity = false; // // if(helpCard != null) // helpCard.OnHit(); // // //再计算 // Solution solution = Slot.MatchAnaliz(); // if(solution != null && solution.count > 0) // { // FightMgr.Instance.ListSoution.Add(solution); // } // } return; } if (FightMgr.Instance.matching > 0 || !IsDrop) { return; } moveVector.x = 0; moveVector.y = 0; if (Slot && transform.localPosition != Vector3.zero) { if (!move) { move = true; gravity = true; velocity = iniVelocity; } velocity += acceleration * Time.deltaTime; if (velocity > velocityLimit) { velocity = velocityLimit; } lastPosition = transform.position; if (Mathf.Abs(transform.localPosition.x) < velocity * Time.deltaTime) { zVector = transform.localPosition; zVector.x = 0; transform.localPosition = zVector; } if (Mathf.Abs(transform.localPosition.y) < velocity * Time.deltaTime) { zVector = transform.localPosition; zVector.y = 0; transform.localPosition = zVector; } if (transform.localPosition == Vector3.zero) { IsDrop = false; if (Slot.slotGravity) { Slot.slotGravity.GravityReaction(); } IsDrop = true; if (transform.localPosition != Vector3.zero) { //还需要移动,还原 transform.position = lastPosition; } else { velocity = 0; } } else { if (transform.localPosition.x < 0) { moveVector.x = 10; } if (transform.localPosition.x > 0) { moveVector.x = -10; } if (transform.localPosition.y < 0) { moveVector.y = 10; } if (transform.localPosition.y > 0) { moveVector.y = -10; } moveVector = moveVector.normalized * velocity; transform.localPosition += moveVector * Time.deltaTime; } } else { IsDrop = false; //Debug.Log("At zero pos:" + Slot.key); if (move) { //DebugUtil.Debug("update card:" + this.gameObject.name); // DebugUtil.Debug("set isDrop = false:" + Slot.key); move = false; velocity = 0; movementID = FightMgr.Instance.GetMovementID(); gravity = false; if (helpCard != null) { helpCard.OnHit(); } // Debug.Log("begin"); //再计算 Solution solution = Slot.MatchAnaliz(); if (solution != null && solution.count > 0) { FightMgr.Instance.ListSoution.Add(solution); // Debug.Log("end"); } } } }