public SimpleFishBehaviour(ICatchable obj) { this.catchable = obj; this.obj = obj.GameObject.transform; this.sea = obj.Sea; //this.speed = obj.GameObject.GetComponent<Fish>().speed; }
// Update is called once per frame void Update() { if (isInvincible) { invicibilityTimer += Time.deltaTime; if (invicibilityTimer > invincibilityDuration) { CanvasManager.Instance.PlayerHit(false); isInvincible = false; invicibilityTimer = 0; } } if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = myCamera.ScreenPointToRay(transform.forward); //Debug.DrawRay(transform.position, myCamera.transform.forward * 10, Color.green,10); //Check if raycast touch something catchable if (Physics.Raycast(transform.position, myCamera.transform.forward, out hit, Mathf.Infinity)) { ICatchable objectCaught = hit.transform.gameObject.GetComponent <ICatchable>(); if (objectCaught != null) { objectCaught.Catch(); if (currentLifeNumber < lifeNumber) { RecoverLife(); } } } } }
private void ReceivedHookHitMsg(NetIncomingMessage msg) { long hookId = msg.ReadInt64(); long asteroidId = msg.ReadInt64(); Vector position = msg.ReadVector(); Vector hitVector = msg.ReadVector(); Hook hook = null; ICatchable g = null; foreach (ISceneObject obj in objects) { if (obj.Id == hookId) { hook = obj as Hook; } else if (obj.Id == asteroidId) { g = obj as ICatchable; obj.Position = position; } if (g != null && hook != null && hook.Owner != currentPlayer) { hook.GetControlOfType <HookControl>().CatchObject(g, hitVector); break; } } }
void Foo(ICatchable catchable) { if (this.fishAmount.ContainsKey (catchable.Name)) { if (this.fishAmount [catchable.Name] > 0) { this.fishAmount [catchable.Name]--; this.totalFishToCatch--; } } }
protected override void TryToCatchCollidedObject(ICatchable caught) { base.TryToCatchCollidedObject(caught); if (caughtObjects.Count == 1) { Returning = true; } }
public SimpleStarBehaviour(ICatchable obj) { this.catchable = obj; this.obj = obj.GameObject.transform; this.sea = obj.Sea; // this.speed = obj.GameObject.GetComponent<Fish>().speed; this.moveDirection = (UnityEngine.Random.Range (0, 2) == 1 ? MoveDirection.Up : MoveDirection.Down); }
public SimpleSurpriseBottleBehaviour(ICatchable obj) { this.catchable = obj; this.obj = obj.GameObject.transform; this.sea = obj.Sea; //this.speed = obj.GameObject.GetComponent<SurpriseBottle>().speed; this.moveDirection = (UnityEngine.Random.Range (0, 2) == 1 ? MoveDirection.Right : MoveDirection.Left); if (this.moveDirection == MoveDirection.Left) { this.obj.transform.Rotate (new Vector3 (0, 180, 0)); } }
public void PutStaff(ICatchable staff) { this.capacity += staff.Weight; if (this.onPutStaff != null) { this.onPutStaff (staff); } if (this.capacity > this.maxCapacity) { if (this.onOverload != null) { this.onOverload.Invoke (); } } }
public SimpleBombBehaviour(ICatchable obj) { /* this.catchable = obj; this.sea = obj.Sea; this.obj = obj.GameObject.transform; this.verticalSpeed = obj.GameObject.GetComponent<Bomb>().verticalSpeed; this.horizontalSpeed = obj.GameObject.GetComponent<Bomb>().horizontalSpeed; this.verticalDeviation = obj.GameObject.GetComponent<Bomb>().verticalDeviation; startVerticalPosition = obj.GameObject.transform.position; moveHorizontalDirection = (Random.Range(0, 2) == 0 ? MoveHorizontalDirection.Left : MoveHorizontalDirection.Right); moveVerticalDirection = (Random.Range(0, 2) == 0 ? MoveVerticalDirection.Down : MoveVerticalDirection.Up); */ }
/// <summary> /// tato metoda je volana kud po kolizi, pokud je vlastnikem soucasny hrac nebo zpravou, pokud neni /// </summary> public void CatchObject(ICatchable caught, Vector hitVector) { if (caught is IDestroyable) { (caught as IDestroyable).TakeDamage(0, hook); } if (caught is UnstableAsteroid) { return; } caughtObjects.Add(caught); caught.Enabled = false; // toto je potreba, protoze vektor muze prijit zpravou od jineho hrace HitVector = hitVector; }
private void ProcessScore(ICatchable caught) { if (caught is IContainsGold) { if (hook.Owner.IsCurrentPlayer()) { hook.SceneMgr.FloatingTextMgr.AddFloatingText(ScoreDefines.HOOK_HIT, hook.Center, FloatingTextManager.TIME_LENGTH_1, FloatingTextType.SCORE); } hook.Owner.AddScoreAndShow(ScoreDefines.HOOK_HIT); } if (!reportedStatistics && GetDistanceFromOriginPct() > 0.9) { hook.SceneMgr.FloatingTextMgr.AddFloatingText(Strings.ft_score_hook_max, hook.Center, FloatingTextManager.TIME_LENGTH_4, FloatingTextType.BONUS_SCORE, FloatingTextManager.SIZE_BIG, false, true); hook.Owner.AddScoreAndShow(ScoreDefines.HOOK_CAUGHT_OBJECT_AFTER_90PCT_DISTANCE); } }
private ICatchable GetHookTarget() { ICatchable nearest = null; double nearestDistSqr = 100000000; double objDistantSqr = 100000000; foreach (ISceneObject obj in objects) { if (obj is StatPowerUp || (obj is Asteroid && (obj as Asteroid).AsteroidType == AsteroidType.GOLDEN)) { objDistantSqr = (obj.Position - baseLauncherPosition).LengthSquared; if (objDistantSqr < nearestDistSqr) { nearestDistSqr = objDistantSqr; nearest = obj as ICatchable; } } } return(nearest); }
private void ProccesObjectsJustPulledToBase(ICatchable caught) { if (caught != null && !caught.Dead) { if (caught is IContainsGold) { me.SceneMgr.FloatingTextMgr.AddFloatingText((caught as IContainsGold).Gold, hook.Center, FloatingTextManager.TIME_LENGTH_3, FloatingTextType.GOLD, FloatingTextManager.SIZE_BIG); AddGoldToOwner((caught as IContainsGold).Gold); caught.DoRemoveMe(); } else { caught.Enabled = true; if (caught is IMovable) { (caught as IMovable).Direction = new Vector(0, 1); } } } me.DoRemoveMe(); }
protected virtual void TryToCatchCollidedObject(ICatchable caught) { if (caught == null) { return; } if (!caught.Enabled) { return; } if (!hook.Owner.IsCurrentPlayerOrBot()) { return; } HitVector = (hook.Position - caught.Position) * 0.9; CatchObject(caught, HitVector); SendHookHitMsg(caught as ISceneObject); if (caught is UnstableAsteroid) { return; } // za unstable se nedostava vubec zadne score ProcessScore(caught); if (!reportedStatistics) { reportedStatistics = true; (me as Hook).Owner.Statistics.HookHit++; } }
public void AddObject(ICatchable catchableObject) { if (!this.createdCatchableObjects.Contains(catchableObject)) { this.createdCatchableObjects.Add(catchableObject); catchableObject.OnUsed += (ICatchable obj) => { //this.createdCatchableObjects.Remove(obj); //GameObject.Destroy(obj.GameObject); this.DestroyObject(obj); }; } }
void Foo(ICatchable catchable) { this.totalObjectForDestroying--; }
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; } }
// 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); }; }
//public override void Cancel(object context, object id) //{ // MonoBehaviour unity = unityScheduler; // if (id is UnityEngine.Coroutine) // { // var co = (UnityEngine.Coroutine)id; // unity.StopCoroutine(co); // } // else if (id is string) // { // unity.StopCoroutine((string)id); // } // else if (id is IEnumerator) // { // unity.StopCoroutine((IEnumerator)id); // } //} //public override void CancelAll(object context) //{ // MonoBehaviour unity = unityScheduler; // unity.StopAllCoroutines(); //} private IEnumerator AsCoroutine(COROUTINE coroutine, IEnumerator routine) { object yieldReturn; bool hasNext; Exception exception = null; COROUTINE waitForCoroutine = null; CancellationToken cancellationToken = GetCancelToken(coroutine); while (true) { if (!coroutine.IsDone) { waitForCoroutine = GetWaitForCoroutine(coroutine); if (waitForCoroutine != null) { //wait done while (!waitForCoroutine.IsDone && !coroutine.IsDone) { if (cancellationToken != null && cancellationToken.IsCancellationRequested) { SetCoroutineCanceled(coroutine); break; } yield return(null); } SetWaitForCoroutine(coroutine, null); var ex = waitForCoroutine.Exception; if (!coroutine.IsDone) { if (ex != null) { ICatchable catchable = waitForCoroutine as ICatchable; if (catchable != null) { try { catchable.HandleException(ex); } catch (Exception ex2) { var newEx = new CoroutineAggregateException(ex2); newEx = newEx.Flatten(); SetCoroutineException(coroutine, newEx, true); break; } } else { SetCoroutineException(coroutine, ex, false); break; } } } else { break; } } else { hasNext = false; if (cancellationToken != null && cancellationToken.IsCancellationRequested) { SetCoroutineCanceled(coroutine); break; } lock (lockObj) { PushCurrent(); try { hasNext = routine.MoveNext(); if (!hasNext) { CheckReturnValue(coroutine); } } catch (Exception ex) { exception = ex; } finally { PopCurrent(); } } if (exception != null) { var aggEx = new CoroutineAggregateException(exception); aggEx = aggEx.Flatten(); SetCoroutineException(coroutine, aggEx, true); break; } if (!hasNext) { break; } yieldReturn = routine.Current; //if (yieldReturn != null) //{ // IEnumerator convertRoutine; // if (ConvertToRoutine(yieldReturn, out convertRoutine)) // yieldReturn = convertRoutine; //} if (yieldReturn != null) { if (yieldReturn is IYield) { if (yieldReturn is COROUTINE) { waitForCoroutine = (COROUTINE)yieldReturn; SetWaitForCoroutine(coroutine, waitForCoroutine); } else if (yieldReturn is WaitForMilliseconds) { float atTime = (float)(Time + ((WaitForMilliseconds)yieldReturn).Milliseconds * 0.001f); while (Time < atTime) { if (cancellationToken != null && cancellationToken.IsCancellationRequested) { SetCoroutineCanceled(coroutine); break; } yield return(null); } } else if (yieldReturn is WaitForFrame) { int frameCount = ((WaitForFrame)yieldReturn).FrameCount; if (frameCount <= 0) { yield return(null); } else { for (int i = 0; i < frameCount; i++) { if (cancellationToken != null && cancellationToken.IsCancellationRequested) { SetCoroutineCanceled(coroutine); break; } yield return(null); } } } else if (yieldReturn is YieldReturn) { YieldReturn ret = (YieldReturn)yieldReturn; SetCoroutineReturnValue(coroutine, ret); } else if (yieldReturn is CustomYield) { CustomYield customYield = (CustomYield)yieldReturn; SetWaitForCoroutine(coroutine, QueueRoutine(customYield)); } else { throw new CoroutineUnknownYieldTypeException(yieldReturn.GetType()); } } else if (yieldReturn is IEnumerable) { SetWaitForCoroutine(coroutine, QueueRoutine(((IEnumerable)yieldReturn).GetEnumerator())); } else if (yieldReturn is IEnumerator) { SetWaitForCoroutine(coroutine, QueueRoutine((IEnumerator)yieldReturn)); } else { IEnumerator tmp; if (ConvertToRoutine(yieldReturn, out tmp)) { SetWaitForCoroutine(coroutine, QueueRoutine(tmp)); } else { // ignore handle yield return(yieldReturn); } } } else { yield return(null); } } } if (coroutine.IsDone) { break; } } if (!coroutine.IsDone) { SetCoroutineDone(coroutine); } else { if (!coroutine.IsRanToCompletion) { exception = coroutine.Exception; if (exception != null && !IsCoroutineHandleException(coroutine)) { if (!IsReady(coroutine)) { yield return(null); } if (!IsCoroutineHandleException(coroutine)) { throw exception; } } } } }
private void MoveWithObject(ICatchable obj) { obj.Position = hook.Position - HitVector; }
public bool Catch(ICatchable catchable) { return(catchable.CatchAtempt()); }
public void DestroyObject(ICatchable catchableObject) { if (this.createdCatchableObjects.Contains(catchableObject)) { this.createdCatchableObjects.Remove(catchableObject); if (this.onDestroyCatchableObject != null) { this.onDestroyCatchableObject.Invoke (catchableObject); } GameObject.Destroy(catchableObject.GameObject); } }