/// <summary> /// /// </summary> /// <param name="buffer"></param> /// <param name="offset"></param> /// <param name="count"></param> /// <param name="callback"></param> /// <param name="state"></param> /// <returns></returns> public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { CBState cbs = new CBState(callback, state, buffer); cbs.result = base.BeginRead(buffer, offset, count, new AsyncCallback(ReadComplete), cbs); return(cbs); }
// MoveTo tells the card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { // Make new interpolation lists for the card. // Position and Rotation will each have only two points. bezierPts = new List <Vector3>(); bezierPts.Add(transform.localPosition); // Current position bezierPts.Add(ePos); // Current rotation bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); // New position bezierRots.Add(eRot); // New rotation if(timeStart == 0) { // c timeStart = Time.time; } // timeDuration always starts the same but can be overwritten later timeDuration = MOVE_DURATION; state = CBState.to; // d }
//MoveTo tells the card to interpolate to a new pos and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { // make a new interpolation lists for the card // pos and rot will each only have 2 pts // current bezierPts = new List <Vector3>(); bezierPts.Add(transform.localPosition); bezierPts.Add(ePos); // new bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); bezierRots.Add(eRot); if (timeStart == 0) { timeStart = Time.time; } // timeDuration always starts the same but can be overwritten timeDuration = MOVE_DURATION; state = CBState.to; }
public float timeStart, timeDuration; // declares 2 fields #endregion Fields #region Methods // MoveTo tells the card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { // Make new interpolation lists for the card. // Position and Rotation will each have only two points. bezierPts = new List<Vector3>(); bezierPts.Add ( transform.localPosition ); // Current position bezierPts.Add ( ePos ); // New position bezierRots = new List<Quaternion> (); bezierRots.Add ( transform.rotation ); // Current rotation bezierRots.Add ( eRot ); // New rotation // If timeStart is 0, then it's set to start immediately, // otherwise, it starts at timeStart. This way, if timeStart is // already set, it won't be overwritten. if (timeStart == 0) { timeStart = Time.time; } // timeDuration always starts the same but can be altered later timeDuration = MOVE_DURATION; //Setting state to either toHand or toTarget will be handled by the //calling method state = CBState.to; }
// MoveTo tells the card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { // Make new interpolation lists for the card. // Position and Rotation will each have only two points. bezierPts = new List <Vector3>(); bezierPts.Add(transform.localPosition); // Current position bezierPts.Add(ePos); // New position bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); // Current rotation bezierRots.Add(eRot); // New rotation // If timeStart is 0, then it's set to start immediately, // otherwise, it starts at timeStart. This way, if timeStart is // already set, it won't be overwritten. if (timeStart == 0) { timeStart = Time.time; } // timeDuration always starts the same but can be altered later timeDuration = MOVE_DURATION; // Setting state to either toHand or toTarget will be handled by the // calling method state = CBState.to; }
// Update is called once per frame void Update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { uC = 1; if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.to) { state = CBState.idle; } transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; timeStart = 0; if (reportFinishTo != null) { reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else { } } else { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; } break; } }
}//end of Awake() public void MoveTo(Vector3 ePos, Quaternion eRot){ bezierPts = new List<Vector3> (); bezierPts.Add (transform.localPosition); bezierPts.Add (ePos); bezierRots = new List<Quaternion> (); bezierRots.Add (transform.rotation); bezierRots.Add (eRot); if (timeStart == 0) timeStart = Time.time; timeDuration = MOVE_DURATION; state = CBState.to; }//end of MoveTo(Vector3 ePos, Quaternion eRot)
}//end of Start() void Update () { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease (u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts [0]; transform.localRotation = bezierRots [0]; return; }//end of if else if (u > 1) { uC = 1; if (state == CBState.toHand) state = CBState.hand; if (state == CBState.toTarget) state = CBState.target; if (state == CBState.to) state = CBState.idle; transform.localPosition = bezierPts [bezierPts.Count - 1]; transform.rotation = bezierRots [bezierPts.Count - 1]; timeStart = 0; if (reportFinishTo != null) { reportFinishTo.SendMessage ("CBCallback", this); reportFinishTo = null; }//end of if else if (callbackPlayer != null) { callbackPlayer.CBCallback (this); callbackPlayer = null; }//end of else if else { }///end of else }//end of else if else { Vector3 pos = Utils.Bezier (uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier (uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f && spriteRenderers [0].sortingOrder != eventualSortOrder) SetSortOrder(eventualSortOrder); if (u > 0.75f && spriteRenderers [0].sortingLayerName != eventualSortLayer) SetSortingLayerName(eventualSortLayer); }//end of else break; }//end of switch(state) }//end of Update()
public void MoveTo(Vector3 ePos, Quaternion eRot) { bezierPts = new List<Vector3>(); bezierPts.Add ( transform.localPosition ); bezierPts.Add ( ePos ); bezierRots = new List<Quaternion>(); bezierRots.Add ( transform.rotation ); bezierRots.Add ( eRot ); if (timeStart == 0) { timeStart = Time.time; } timeDuration = MOVE_DURATION; state = CBState.to; }
/// <summary> /// /// </summary> /// <param name="asyncResult"></param> /// <returns></returns> public override int EndRead(IAsyncResult asyncResult) { CBState cbs = (CBState)asyncResult.AsyncState; int bytesRead = base.EndRead(cbs.result); if (target == Target.Normal) { bf.Encipher(cbs.buffer, bytesRead); } else { bf.Decipher(cbs.buffer, bytesRead); } return(bytesRead); }
//Tells target card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { //An interpolation list specifically for the card bezierPts = new List <Vector3> (); bezierPts.Add(transform.localPosition); //Current position bezierPts.Add(ePos); //New position bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); bezierRots.Add(eRot); //If timeStart is 0, it starts immediately if (timeStart == 0) { timeStart = Time.time; } timeDuration = MOVE_DURATION; state = CBState.to; }
/// <summary> /// Запускает перемещение карты в новое местоположение с заданным поворотом /// </summary> public void MoveTo(Vector3 ePos, Quaternion eRot) { // Создать новые списки для интерполяциии. // Траектории перемещения и поворота определяются двумя точками каждая bezierPts = new List <Vector3>(); bezierPts.Add(transform.localPosition); // Текущие местоположение bezierPts.Add(ePos); // Новое местоположение bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); // Текущий угол поворота bezierRots.Add(eRot); // Новый угол поворота if (timeStart == 0) { timeStart = Time.time; } timeDuration = MOVE_DURATION; state = CBState.to; }
// MoveTo tells the card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { // Make new interpolation lists for the card // Position and Rotation will each have only two points bezierPts = new List <Vector3>(); bezierPts.Add(transform.localPosition); bezierPts.Add(ePos); bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); bezierRots.Add(eRot); if (timeStart == 0) { timeStart = Time.time; } // timeSuration always starts the same but can be overwritten later timeDuration = MOVE_DURATION; state = CBState.to; }
//moveTo tells the card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { //make new interpolation lists for the card //Position and Rotation will each have only two points bezierPts = new List <Vector3>(); bezierPts.Add(transform.localPosition); bezierPts.Add(ePos); bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); bezierRots.Add(eRot); if (timeStart == 0) { timeStart = Time.time; } timeDuration = MOVE_DURATION; //setting state to either toHand or toTarget will be handled by the calling method state = CBState.to; }
// MoveTo говорит карте переместиться в новую позицию и поворот public void MoveTo(Vector3 tPos, Quaternion tRot) { // Бизеровые кривые будут иметь только две точки // Создаём список bezierPts = new List <Vector3>(); bezierPts.Add(transform.position); // Добавляем стартовую позицию bezierPts.Add(tPos); // Добавляем конечную позицию // То же самое с поворотом bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); bezierRots.Add(tRot); // Если время старта не заданно, двигаем сразу же if (timeStart == 0) { timeStart = Time.time; } // Продолжительность всегда одинаковая но может дополниться позже timeDuration = MOVE_DURATION; // Установка положения toHand or toTarget будет делать вызывающий метод state = CBState.to; }
//moveto tells the card to interpolate to a new position and rotation public void MoveTo(Vector3 ePos, Quaternion eRot) { //make new interpolation lists for the card //position and rotation will each have only two points bezierPTS = new List <Vector3>(); bezierPTS.Add(transform.localPosition); //current positino bezierPTS.Add(ePos); //New Position bezierRots = new List <Quaternion>(); bezierRots.Add(transform.rotation); //current roattion bezierRots.Add(eRot); //new rotation //if timeStart is 0, then its set to start immediatly, //otherwise, it starts at timeStart. this way, if timestart is //already set, it wont be overwritten if (timeStart == 0) { timeStart = Time.time; } //timeDuration always starts the same but can be altered later timeDuration = MOVE_DURATION; //setting state to eaither tohand or totraget will be handled by //callijng methord state = CBState.to; }
void Update() { switch (state) { // All the to___ states are ones where the card is interpolating case CBState.toHand: case CBState.toTarget: case CBState.to: // Get u from the current time and duration // u ranges from 0 to 1 (usually) float u = (Time.time - timeStart) / timeDuration; // Use Easing class from Utils to curve the u value float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) // If u<0, then we shouldn't move yet. // Stay at the initial position { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) // If u>=1, we're finished moving { uC = 1; // Set uC=1 so we don't overshoot // Move from the to___ state to the following state if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.toTarget; } if (state == CBState.to) { state = CBState.idle; } // Move to the final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; // Reset timeStart to 0 so it gets overwritten next time timeStart = 0; if (reportFinishTo != null) //If there's a callback GameObject // ... then use SendMessage to call the CBCallback method // with this as the parameter. { reportFinishTo.SendMessage("CBCallback", this); // After calling SendMessage(), reportFinishTo must be set // to null so that it the card doesn't continue to report // to the same GameObject every subsequent time it moves. reportFinishTo = null; } else if (callbackPlayer != null) { // If there's a callback Player // then call CBCallback directly on the Player callbackPlayer.CBCallback(this); callbackPlayer = null; } else // If there is nothing to callback // Do nothing { } } else // 0<=u<1, which means that this is interpolating now // Use Bezier curve to move this to the right point { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f && spriteRenderers[0].sortingOrder != eventualSortOrder) { // Jump to the proper sort order SetSortOrder(eventualSortOrder); } if (u > 0.75f && spriteRenderers[0].sortingLayerName != eventualSortLayer) { // Jump to the proper sort layer SetSortingLayerName(eventualSortLayer); } } break; } }
// Update is called once per frame void Update() { switch (state) { // All the to__ states are ones where the card is interpolating case CBState.toHand: case CBState.toTarget: case CBState.to: // Get u from the current time and duration // u ranges from 0 to 1 (usually) float u = (Time.time-timeStart)/timeDuration; // Use Easing class from utils to curve the u value float uC = Easing.Ease(u, MOVE_EASING); if(u<0){ // if u less than 0, then we shouldn't move yet // stay at initial position transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; }else if (u>=1){ // if u >= 1, then we are finished moving uC = 1; // set uC so we don't overshoot // Move from the to_state to the following state if(state == CBState.toHand) state = CBState.hand; if(state == CBState.toTarget) state = CBState.toTarget; if(state == CBState.to) state = CBState.idle; // Move to the final position transform.localPosition = bezierPts[bezierPts.Count-1]; transform.rotation = bezierRots[bezierPts.Count-1]; // Reset timeStart to 0 so it gets overwritten next time timeStart = 0; if(reportFinishTo != null){ // If there's a callback GameObject //... then use SendMessage to call the CBCallback method //with this as the parameter. reportFinishTo.SendMessage("CBCallback", this); // After calling SendMessage(), reportFinishTo must be set // to null so that the card doesn't continue to report // to the same GameObject every subsequent time it moves reportFinishTo = null; }else if (callbackPlayer != null){ // If there is a callback Player // then call CBCallback directly on the player callbackPlayer.CBCallback(this); callbackPlayer = null; } else { // If there is nothing to callback // Just let it stay still } }else{ // 0<=u<1, which means that this is interpolating now // Use Bezier curve to move this to the right point Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u>0.5f && spriteRenderers[0].sortingOrder != eventualSortOrder) { // Jump to the proper sort order SetSortOrder(eventualSortOrder); } if (u>0.75f && spriteRenderers[0].sortingLayerName != eventualSortLayer) { // Jump to the proper sort layer SetSortingLayerName(eventualSortLayer); } } break; } }
void Update() { switch (state) { case CBState.toHand: break; case CBState.toTarget: break; case CBState.to: //get u from the current time and duration, u ranges from 0 to 1 usually float u = (Time.time - timeStart) / timeDuration; //use Easing class from Utils to curve the u value float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) // if u < 0 we shouldnt move yet { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) // wer'e finished moving { uC = 1; //move from the to____ state to the following state if (state == CBState.toHand) { state = CBState.toHand; } if (state == CBState.toTarget) { state = CBState.toTarget; } if (state == CBState.to) { state = CBState.idle; } //move to the final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierRots.Count - 1]; //reset timeStart to 0 so it gets overwritten next time timeStart = 0; if (reportFinishTo != null) // if there's a callback GameObject then use SendMessage to call the CBCallback method with this as the parameter { reportFinishTo.SendMessage("CBCallback", this); //after calling SendMessage(), reportFinishTo must be set to null so that the card dowsnt continue to report to the same GameObject every subsequent time it moves reportFinishTo = null; } } else // 0<=u<=1, which means that this is interpolating now. user Bezier curve to move this to the right point { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; } break; case CBState.drawpile: break; case CBState.hand: break; case CBState.target: break; case CBState.discard: break; case CBState.idle: break; default: break; } }
// Update is called once per frame void Update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.toDrawpile: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { uC = 1; //move from the "to" state to the proper state if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toDrawpile) { state = CBState.drawpile; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.to) { state = CBState.idle; } //move to final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierRots.Count - 1]; //reset timeStart to 0 so it gets rewritten next time it moves timeStart = 0; if (reportFinishTo != null) { reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { //if there is a callback player //call CBCallback directly on this player callbackPlayer.CBCallback(this); callbackPlayer = null; } else { //if nothing to callback then just stay still } } else //if u is not at 1 or less than 0 then just do normal interpolate behavior { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f) { SpriteRenderer sRend = spriteRenderers[0]; if (sRend.sortingOrder != eventualSortOrder) { SetSortOrder(eventualSortOrder); } if (sRend.sortingLayerName != eventualSortLayer) { SetSortingLayerName(eventualSortLayer); } } } break; } }
void Update() { switch(state) { // f case CBState.toHand: case CBState.toTarget: case CBState.toDrawpile: case CBState.to: float u = (Time.time - timeStart) / timeDuration; // g float uC = Easing.Ease(u, MOVE_EASING); if(u < 0) { // h transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { // i uC = 1; // Move from the to... state to the proper next state if(state == CBState.toHand) state = CBState.hand; if(state == CBState.toTarget) state = CBState.target; if(state == CBState.toDrawpile) state = CBState.drawpile; if(state == CBState.to) state = CBState.idle; // Move to the final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; // Reset timeStart to 0 so it gets overwritten next time timeStart = 0; if(reportFinishTo != null) { // j reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { // c // If there's a callback Player // Call CBCallback directly on the Player callbackPlayer.CBCallback(this); callbackPlayer = null; } else // If there is nothing to callback { // Just let it stay still. } } else // Normal interpolation behavior (0 <= u < 1) // k { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; // Quaternion rotQ = Utils.Bezier(uC, bezierRots); // transform.rotation = rotQ; if (u > 0.5f) { // a SpriteRenderer sRend = spriteRenderers[0]; if(sRend.sortingOrder != eventualSortOrder) { // Jump to the proper sort order SetSortOrder(eventualSortOrder); } if(sRend.sortingLayerName != eventualSortLayer) { // Jump to the proper sort layer SetSortingLayerName(eventualSortLayer); } } } break; } }
private void Update() { CardLostCities tCB = LostCities.S.CurrentCard(); switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.toDrawpile: case CBState.toRedDiscard: case CBState.toGreenDiscard: case CBState.toWhiteDiscard: case CBState.toBlueDiscard: case CBState.toYellowDiscard: case CBState.toRedPlayer1: case CBState.toRedPlayer2: case CBState.toGreenPlayer1: case CBState.toGreenPlayer2: case CBState.toWhitePlayer1: case CBState.toWhitePlayer2: case CBState.toBluePlayer1: case CBState.toBluePlayer2: case CBState.toYellowPlayer1: case CBState.toYellowPlayer2: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { uC = 1; // Move from the to... state to the proper next state if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.toRedDiscard) { state = CBState.redDiscard; } if (state == CBState.toGreenDiscard) { state = CBState.greenDiscard; } if (state == CBState.toWhiteDiscard) { state = CBState.whiteDiscard; } if (state == CBState.toBlueDiscard) { state = CBState.blueDiscard; } if (state == CBState.toYellowDiscard) { state = CBState.yellowDiscard; } if (state == CBState.toRedPlayer1) { state = CBState.redPlayer1; } if (state == CBState.toRedPlayer2) { state = CBState.redPlayer2; } if (state == CBState.toGreenPlayer1) { state = CBState.greenPlayer1; } if (state == CBState.toGreenPlayer2) { state = CBState.greenPlayer2; } if (state == CBState.toWhitePlayer1) { state = CBState.whitePlayer1; } if (state == CBState.toWhitePlayer2) { state = CBState.whitePlayer2; } if (state == CBState.toBluePlayer1) { state = CBState.bluePlayer1; } if (state == CBState.toBluePlayer2) { state = CBState.bluePlayer2; } if (state == CBState.toYellowPlayer1) { state = CBState.yellowPlayer1; } if (state == CBState.toYellowPlayer2) { state = CBState.yellowPlayer2; } if (state == CBState.toDrawpile) { state = CBState.drawpile; } if (state == CBState.to) { state = CBState.idle; } // Move to the final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; // Reset timeStart to 0 so it gets overwritten next time if (state == CBState.redDiscard) { LostCities.S.ArrangeDiscard(tCB); } if (state == CBState.greenDiscard) { LostCities.S.ArrangeDiscard(tCB); } if (state == CBState.whiteDiscard) { LostCities.S.ArrangeDiscard(tCB); } if (state == CBState.blueDiscard) { LostCities.S.ArrangeDiscard(tCB); } if (state == CBState.yellowDiscard) { LostCities.S.ArrangeDiscard(tCB); } //Invoke("LostCities.S.ArrangePlayerPile", 2); //Invoke("LostCities.S.ArrangePlayer2Pile", 2); timeStart = 0; //this code not used if (reportFinishTo != null) { reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { // If there's a callback Player // Call CBCallback directly on the Player callbackPlayer.CBCallback(this); callbackPlayer = null; } else { // If there is nothing to callback // Just let it stay still. } } else { // Normal interpolation behavior (0 <= u < 1) Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f) { SpriteRenderer sRend = spriteRenderers[0]; if (sRend.sortingOrder != eventualSortOrder) { // Jump to the proper sort order SetSortOrder(eventualSortOrder); } if (sRend.sortingLayerName != eventualSortLayer) { // Jump to the proper sort layer SetSortingLayerName(eventualSortLayer); } } } break; } }
private void Update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.to: // Вычисляем u из текущего времени и длительности float u = (Time.time - timeStart) / timeDuration; // Используем смягчающий класс float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) // Мы ещё не должны начать двигаться // Остаёмся в базовой позиции { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) // u >= 1, мы закончили движение { uC = 1; // Чтобы не перестараться // Меням состояние if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.to) { state = CBState.idle; } // Двигаем к финальной позиции transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierRots.Count - 1]; // Задаём timeStart к 0, так он перезапишется в след. раз timeStart = 0; if (reportFinishTo != null) // Если есть предмет для отчёта { reportFinishTo.SendMessage("CBCallback", this); // Обнуляем чтоб не посылать несколько команд подряд reportFinishTo = null; } else if (callbackPlayer != null) // Некому отправлять { callbackPlayer.CBCallback(this); callbackPlayer = null; // Чтобы не вызывать несколько раз } else { // Ничего не делаем } } else // 0<=u<1 Значит что мы движемся { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rot = Utils.Bezier(uC, bezierRots); transform.rotation = rot; // Проверяем правильно ли поставилось сортировка if (u > 0.5f && spriteRenderers[0].sortingOrder != eventualSortOrder) { SetSortOrder(eventualSortOrder); } if (u > 0.75f && spriteRenderers[0].sortingLayerName != eventualSortLayer) { SetSortingLayerName(eventualSortLayer); } } break; } }
/// <summary> /// The Read has completed. /// </summary> /// <param name="result">The result of the async write.</param> private void ReadComplete(IAsyncResult result) { CBState cbs = (CBState)result.AsyncState; cbs.callback(cbs); }
void Update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts [0]; transform.rotation = bezierRots [0]; return; } if (u >= 1) { uC = 1; if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.toTarget; } if (state == CBState.to) { state = CBState.idle; } transform.localPosition = bezierPts [bezierPts.Count - 1]; transform.rotation = bezierRots [bezierPts.Count - 1]; timeStart = 0; if (reportFinishTo != null) { reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { callbackPlayer.CBCallback(this); callbackPlayer = null; } else { //do nothing } } else { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); //This doesn't work because Utils.Bezier is looking for a list of floats, not a list of Quaternions. transform.rotation = rotQ; if (u > 0.5f && spriteRenderers[0].sortingOrder != eventualSortOrder) { setSortOrder(eventualSortOrder); } if (u > 0.75f && spriteRenderers[0].sortingLayerName != eventualSortLayer) { setSortingLayerName(eventualSortLayer); } } break; } }
void Update() { switch (state) { // f case CBState.toHand: case CBState.toTarget: case CBState.toDrawpile: case CBState.to: float u = (Time.time - timeStart) / timeDuration; // g float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { // h transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { // i uC = 1; // Move from the to... state to the proper next state if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.toDrawpile) { state = CBState.drawpile; } if (state == CBState.to) { state = CBState.idle; } // Move to the final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; // Reset timeStart to 0 so it gets overwritten next time timeStart = 0; if (reportFinishTo != null) { // j reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { // If there's a callback Player // Call CBCallback directly on the Player callbackPlayer.CBCallback(this); callbackPlayer = null; } else { // If there is nothing to callback // Just let it stay still. } } else { // Normal interpolation behavior (0 <= u < 1) // k Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f) { // a SpriteRenderer sRend = spriteRenderers[0]; if (sRend.sortingOrder != eventualSortOrder) { // Jump to the proper sort order SetSortOrder(eventualSortOrder); } if (sRend.sortingLayerName != eventualSortLayer) { // Jump to the proper sort layer SetSortingLayerName(eventualSortLayer); } } } break; } }
void Update() { switch (state) { //A to__ state is when a card is interpolating case CBState.toHand: case CBState.toTarget: case CBState.to: //Get u (0 <= u <= 1) from current time and duration float u = (Time.time - timeStart) / timeDuration; //Use Utils class to curve the u float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) //We shouldn't move yet { transform.localPosition = bezierPts [0]; transform.rotation = bezierRots [0]; return; } else if (u >= 1) //We're finished moving { if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.toTarget; } if (state == CBState.to) { state = CBState.idle; } //Move to final position transform.localPosition = bezierPts [bezierPts.Count - 1]; transform.rotation = bezierRots [bezierPts.Count - 1]; //Reset timeStart to 0 timeStart = 0; if (reportFinishTo != null) //If there's a callback GameObject // use SendMessage to call the CBCallback method with this as parameter { reportFinishTo.SendMessage("CBCallback", this); //reportFinishTo must be set to null so that //the card doesn't continue to report to the //same GO whenever it moves reportFinishTo = null; } else if (callbackPlayer != null) { callbackPlayer.CBCallback(this); callbackPlayer = null; } else { //Nothing } } else //0 <= u <= 1, so this is interpolating now { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; //Jump to the proper sort order if (u > 0.5f && spriteRenderers [0].sortingOrder != eventualSortOrder) { SetSortOrder(eventualSortOrder); } if (u > 0.75f && spriteRenderers [0].sortingLayerName != eventualSortLayer) { SetSortingLayerName(eventualSortLayer); } } break; } }
void Update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.to: float u = (Time.time - timeStart)/timeDuration; float uC = Easing.Ease(u,MOVE_EASING); if(u<0){ transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; }else if (u>=1){ uC = 1; if(state == CBState.toHand) state=CBState.hand; if(state == CBState.toTarget) state=CBState.toTarget; if(state == CBState.to) state=CBState.idle; transform.localPosition = bezierPts[bezierPts.Count -1]; transform.rotation = bezierRots[bezierPts.Count -1]; timeStart = 0; if(reportFinishTo != null){ reportFinishTo.SendMessage("CBCallback",this); reportFinishTo = null; }else if(callbackPlayer != null){ callbackPlayer.CBCallback(this); callbackPlayer = null; }else{ } }else{ Vector3 pos = Utils.Bezier(uC,bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if(u>0.5 && spriteRenderers[0].sortingOrder != eventualSortOrder){ SetSortOrder(eventualSortOrder); } if(u>0.75 && spriteRenderers[0].sortingLayerName != eventualSortLayer){ SetSortingLayerName(eventualSortLayer); } } break; } }
private void Update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.toDrawpile: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { uC = 1; // Перевести из состояния to в соответствующее if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.toDrawpile) { state = CBState.drawpile; } if (state == CBState.to) { state = CBState.idle; } // Переместить в конечное положение transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; // Сбросить time в 0, что бы в следующий раз можно было установить текущее время timeStart = 0; if (reportFinishTo != null) { reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { // Если имеется ссылка на экземпляр Player callbackPlayer.CBCallback(this); callbackPlayer = null; } else { // Оставить все как есть. } } else { // Нормальный режим интерполяции (0 <= u < 1) Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f) { SpriteRenderer sRend = spriteRenderers[0]; if (sRend.sortingOrder != eventualSortOrder) { // Установить конечный порядок сортировки SetSortOrder(eventualSortOrder); } if (sRend.sortingLayerName != eventualSortLayer) { // Установить конечный слой сортировки SetSortingLayerName(eventualSortLayer); } } } break; } }
/// <summary> /// /// </summary> /// <param name="buffer"></param> /// <param name="offset"></param> /// <param name="count"></param> /// <param name="callback"></param> /// <param name="state"></param> /// <returns></returns> public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { CBState cbs = new CBState(callback, state, buffer); cbs.result = base.BeginRead (buffer, offset, count, new AsyncCallback(ReadComplete), cbs); return cbs; }
// Update is called once per frame void Update() { switch (state) { //All he to__ states are ones where the card is interpolating case CBState.toHand: case CBState.toTarget: case CBState.to: //Get u from the current time and duration //u ranges from 0 to 1 (usually) float u = (Time.time - timeStart) / timeDuration; //use Easing class from utils to curve the u value float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { //if u<0, then we shouldn't move yet //stay at the initial position transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { // if u>=1, we're finished moving uC = 1; //Set uC=1 so we don't overshoot //move from to ___ state to the following state if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.to) { state = CBState.idle; } //Move to the final position transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; //Reset timeStart to 0 so it gets overwritten nexr time timeStart = 0; if (reportFinishTo != null) { // If there's a callback GameObject //..then use SendMessage to call the CBCallback method //with this as the parameter reportFinishTo.SendMessage("CBCallback", this); // after calling SendMessage (), reportFinishTo must be set //to null so that the card doesn't continue to report //to the same GameObject every subsequent time it moves. reportFinishTo = null; } else { //0<=u<1, which means that this is interpolating now //use Bezier curve to move this to the right point Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; } } break; } }
void update() { switch (state) { case CBState.toHand: case CBState.toTarget: case CBState.toDrawpile: case CBState.to: float u = (Time.time - timeStart) / timeDuration; float uC = Easing.Ease(u, MOVE_EASING); if (u < 0) { transform.localPosition = bezierPts[0]; transform.rotation = bezierRots[0]; return; } else if (u >= 1) { uC = 1; if (state == CBState.toHand) { state = CBState.hand; } if (state == CBState.toTarget) { state = CBState.target; } if (state == CBState.toDrawpile) { state = CBState.drawpile; } if (state == CBState.to) { state = CBState.idle; } transform.localPosition = bezierPts[bezierPts.Count - 1]; transform.rotation = bezierRots[bezierPts.Count - 1]; timeStart = 0; if (reportFinishTo != null) { reportFinishTo.SendMessage("CBCallback", this); reportFinishTo = null; } else if (callbackPlayer != null) { callbackPlayer.CBCallback(this); callbackPlayer = null; } else { // leave empty } } else { Vector3 pos = Utils.Bezier(uC, bezierPts); transform.localPosition = pos; Quaternion rotQ = Utils.Bezier(uC, bezierRots); transform.rotation = rotQ; if (u > 0.5f) { SpriteRenderer sRend = spriteRenderers[0]; if (sRend.sortingOrder != eventualSortOrder) { SetSortOrder(eventualSortOrder); } if (sRend.sortingLayerName != eventualSortLayer) { SetSortingLayerName(eventualSortLayer); } } } break; } }