// for pick up / throw behavior - one method that encapsulates all the things you do when you release a held object public void GetDropped(bool applyThrowForce) { // don't do this if i'm not currently held, // important since this method can be called externally, ie - by an inventory slot or when this obj gets broken, and there might be race conditions to handle if (currentInteractor != null) { UnattachHeldObject(applyThrowForce); SnapToPosition snap = GetComponent <SnapToPosition>(); if (snap != null) { snap.StopCheckingForSnapTargets(); } UnpairWithInteractor(currentInteractor); } // else // { // Debug.Log("Race condition handled correctly by "+this.gameObject); // } }
// for pick up / throw behavior - one method that encapsulates all the things you do when you pick up a held object private void GetPickedUp(WandController interactor) { if (currentInteractor != null) { Debug.LogError(interactor.gameObject + " is picking up " + this.gameObject + ", but it's already paired with " + currentInteractor.gameObject); } PairWithInteractor(interactor); AttachHeldObject(); // TODO - should the following types of things be inside or at least dependant on the return value of PairWithInteractor() ? SnapToPosition snap = GetComponent <SnapToPosition>(); if (snap != null) { snap.StartCheckingForSnapTargets(); } if (inventorySlot != null) { inventorySlot.whoLastHadMyInventoryItem = interactor; } }
void Update() { if (Time.time < timeNextBlock) { return; } timeNextBlock = Time.time + timeBetweenBlocks; WallBlockType nextBlockType; if (DEBUG_blockType1 != WallBlockType.NONE) { if (Random.Range(0, 2) == 0) { nextBlockType = DEBUG_blockType1; } else { nextBlockType = DEBUG_blockType2; } } else { if (Random.Range(1, (trapCount + alcoveCount + 3)) < (trapCount + 1)) { nextBlockType = WallBlockType.Alcove; } else { nextBlockType = WallBlockType.ArrowTrap; } } bool weirdTrapThisTime = (Random.Range(0f, 1f) < 0.8f) ? true : false; DEBUG_angledTopArrow = weirdTrapThisTime; RelativeDirection wallDir = EnvironmentManager.RandomRelativeDirection(); WallBlockPosition blockPos = EnvironmentManager.RandomWallBlockPosition(); if ((!weirdTrapThisTime) && (nextBlockType == WallBlockType.ArrowTrap) && (TempleWall.PositionIsBottom(blockPos))) { while (TempleWall.PositionIsBottom(blockPos)) { blockPos = EnvironmentManager.RandomWallBlockPosition(); } } int tries = 0; while ((!environmentManager.DoesItFit(nextBlockType, wallDir, blockPos)) && (tries < 100)) { wallDir = EnvironmentManager.RandomRelativeDirection(); blockPos = EnvironmentManager.RandomWallBlockPosition(); if ((!weirdTrapThisTime) && (nextBlockType == WallBlockType.ArrowTrap) && (TempleWall.PositionIsBottom(blockPos))) { while (TempleWall.PositionIsBottom(blockPos)) { blockPos = EnvironmentManager.RandomWallBlockPosition(); } } tries++; } if (tries == 100) { return; } // decide whether to impose any prop spawns // this is super TMP chance for now float percentChance = ((Time.time - timeOfLastGoalObject) / (timeOfLastGoalObject + maxTimeTilGoalObject)); if ((nextBlockType == WallBlockType.Alcove) && (Random.Range(0f, 1f) < percentChance)) { if (!NothingInLimbo()) { readyForInsertion = RandomAvailableGoalPiece(); timeOfLastGoalObject = Time.time; } // else // Debug.Log("Can't impose goal spawns because nothing is in limbo."); } environmentManager.SpawnBlock(nextBlockType, wallDir, blockPos); trapCount = environmentManager.BlockCount(WallBlockType.ArrowTrap); alcoveCount = environmentManager.BlockCount(WallBlockType.Alcove); }
private bool IsInLimbo(SnapToPosition piece) { return(limbo.bounds.Contains(piece.transform.position)); }