void TryCatchBehaviour() { if (this.directionHookMove == DirectionHookMove.forward) { this.fishingHookGameObject.transform.localPosition += this.destinationNormalVector * Time.deltaTime * this.catchSpeed; } else if (this.directionHookMove == DirectionHookMove.back) { this.fishingHookGameObject.transform.localPosition -= this.destinationNormalVector * Time.deltaTime * this.catchSpeed; } if (Vector3.Distance ( this.fishingHookGameObject.transform.position, this.fishingHookPivotPoint.transform.position) >= this.maxLength && this.directionHookMove == DirectionHookMove.forward ) { this.directionHookMove = DirectionHookMove.back; } else if (Vector3.Distance ( this.fishingHookPivotPoint.transform.position, this.fishingHookGameObject.transform.position) < 0.1f && this.directionHookMove == DirectionHookMove.back ) { this.directionHookMove = DirectionHookMove.forward; this.fishingHookGameObject.transform.position = this.fishingHookPivotPoint.transform.position; if (this.onEndTryCatch != null) { this.onEndTryCatch.Invoke (this.catchedStuff); } this.ChangeState (SpinningState.LookingFor); } }
// Use this for initialization void Start() { // Устанавливаем крючок, в соответствии с заданной позицией if (Mathf.Approximately (this.length, 0.0f)) { // Если длина крючка равна 0, то используем расположение, заданное в редакторе this.length = Vector3.Distance(this.fishingHookPivotPoint.transform.position, this.fishingHookCenterOfRotation.transform.position); } else { if (this.length < 0) { this.length = SimpleSpinning.lengthByDefault; } this.fishingHookPivotPoint.transform.position = new Vector3 ( this.fishingHookCenterOfRotation.transform.position.x, this.fishingHookCenterOfRotation.transform.position.y - this.length, // минус, потому что крючок направлен вниз this.fishingHookCenterOfRotation.transform.position.z ); } if (this.maxLength <= this.length) { this.maxLength = SimpleSpinning.maxLengthByDefault; } if (this.angleSpeed <= 0) { this.angleSpeed = SimpleSpinning.angleSpeedByDefault; } if (this.maxAngleDeviation < 0.0f || this.maxAngleDeviation > 90.0f) { this.maxAngleDeviation = SimpleSpinning.maxAngleDeviationByDefault; } if (this.catchSpeed < 0) { this.catchSpeed = SimpleSpinning.catchSpeedByDefault; } this.directionHookMove = DirectionHookMove.nowhere; this.fishingHook = this.fishingHookGameObject.GetComponent<IHook> (); this.fishingHook.SetOwner (this); this.fishingHook.OnCatchStaff += (ICatchable obj) => { this.catchedStuff = obj; this.ChangeState(SpinningState.PullStuff); }; }
void ChangeState(SpinningState spinningState) { switch (spinningState) { case SpinningState.Nothing: this.spinningBehaviour = this.EmptyBehaviour; this.spinningState = SpinningState.Nothing; this.directionHookMove = DirectionHookMove.nowhere; this.fishingHookGameObject.transform.position = this.fishingHookPivotPoint.transform.position; this.fishingHookPivotPoint.transform.position = this.startPivotPointHookPosition; this.currentAngleDeviation = 0; break; case SpinningState.LookingFor: this.spinningBehaviour = this.LookingForBehaviour; this.catchedStuff = null; this.directionHookMove = DirectionHookMove.nowhere; this.spinningState = SpinningState.LookingFor; break; case SpinningState.TryCatch: this.destinationNormalVector = (this.fishingHookPivotPoint.transform.position - this.fishingHookCenterOfRotation.transform.position).normalized /* *this.maxLength*/; this.spinningBehaviour = this.TryCatchBehaviour; this.spinningState = SpinningState.TryCatch; if (this.onStartTryCatch != null) { this.onStartTryCatch.Invoke(); } break; case SpinningState.PullStuff: this.spinningBehaviour = this.PullStaffBehaviour; this.spinningState = SpinningState.PullStuff; break; } }
void PullStaffBehaviour() { if (this.catchedStuff == null) { // Если движется нулевой подцеп (например после взрыва бомбы, или если рыба сорвалась, то просто возвращаем крючок) this.fishingHookGameObject.transform.localPosition -= this.destinationNormalVector * Time.deltaTime * this.catchSpeed; this.directionHookMove = DirectionHookMove.back; if (Vector3.Distance (this.fishingHookPivotPoint.transform.position, this.fishingHookGameObject.transform.position) < 0.1f) { this.directionHookMove = DirectionHookMove.forward; this.fishingHookGameObject.transform.position = this.fishingHookPivotPoint.transform.position; if (this.onEndTryCatch != null) { this.onEndTryCatch.Invoke (this.catchedStuff); } this.ChangeState (SpinningState.LookingFor); } return; } this.directionHookMove = DirectionHookMove.back; float resultCatchSpeed = this.catchSpeed * this.owner.Power / this.catchedStuff.Weight; this.fishingHookGameObject.transform.localPosition -= this.destinationNormalVector * Time.deltaTime * resultCatchSpeed; this.catchedStuff.GameObject.transform.position = this.fishingHookGameObject.transform.position; if (Vector3.Distance ( this.fishingHookCenterOfRotation.transform.position, this.fishingHookGameObject.transform.position) < 0.1f) { this.directionHookMove = DirectionHookMove.forward; this.fishingHookGameObject.transform.position = this.fishingHookPivotPoint.transform.position; if (this.onEndTryCatch != null) { this.onEndTryCatch.Invoke (this.catchedStuff); } } }
public void TryCatch() { this.directionHookMove = DirectionHookMove.forward; this.ChangeState (SpinningState.TryCatch); }