// tracks currentInteractable as the wand passes through qualifying objects void OnTriggerEnter(Collider other) { VRInteractable collidedInteractable = CodeTools.GetComponentFromNearestAncestor <VRInteractable>(other.gameObject); if (collidedInteractable != null) { // if we don't already have this interactable on our list of ones we're selecting, then add it if (!currentSelection.Contains(collidedInteractable)) { currentSelection.Add(collidedInteractable); } if (currentInteractable != null) { if (collidedInteractable != currentInteractable) { Debug.Log(this + " just selected " + collidedInteractable.gameObject + ", but my currentInteractable is " + currentInteractable.gameObject + ", probably you just pushed the current interactable through something else."); } } } else { // if (other.gameObject != null) // Debug.Log("WandController collided with a non-VRInteractable object, so ignoring it; it's "+ other.gameObject); } }
// tracks currentInteractable as the wand passes through qualifying objects void OnTriggerStay(Collider other) { VRInteractable collidedInteractable = CodeTools.GetComponentFromNearestAncestor <VRInteractable>(other.gameObject); if (collidedInteractable != null) { if (!currentSelection.Contains(collidedInteractable)) { Debug.LogError(this.gameObject + " wand is OnTriggerStay() colliding with " + collidedInteractable.gameObject + " but it's not on the currentSelection list, but it should be!"); } } }
// finds the nearest ancestor with the ArrowTrap component, and assumes that to be the ArrowTrap construction that this Arrow is a part of // then finds all the children (and later descendants) of that ArrowTrap that have a Collider and turns on/off (based on the passed-in ignore) the collion between this arrow and those colliders private void IgnoreAllArrowTrapChildren(bool ignore) { ArrowTrap myTrap = CodeTools.GetComponentFromNearestAncestor <ArrowTrap>(this.gameObject); if (myTrap == null) { Debug.LogError(this.gameObject + " does not have an ancestor that contains the ArrowTrap component."); return; } Component[] colliders = myTrap.gameObject.GetComponentsInChildren <Collider>(); foreach (Collider col in colliders) { Physics.IgnoreCollision(col, mc, ignore); } }
// tracks currentInteractable as the wand passes through qualifying objects void OnTriggerExit(Collider other) { VRInteractable collidedInteractable = CodeTools.GetComponentFromNearestAncestor <VRInteractable>(other.gameObject); if (collidedInteractable == null) { return; } if (currentSelection.Contains(collidedInteractable)) { currentSelection.Remove(collidedInteractable); } else { Debug.LogError(this.gameObject + " wand called OnTriggerExit() with " + collidedInteractable.gameObject + " but it's not on the currentSelection list, but it should be!"); } }
void Awake() { CodeTools.ValidateWeightedRandomArray(spots_randWeights, objectSpots.Length); CodeTools.ValidateWeightedRandomArray(goalSpots_randWeights, objectSpots.Length); if ((numSpotsToFill < 0) || (numSpotsToFill > objectSpots.Length)) { Debug.LogError("numSpotsToFill must be at least 0 and no more than the number of elements in objectSpots, but instead it is " + numSpotsToFill); } foreach (Transform spot in objectSpots) { if (CodeTools.GetComponentFromNearestAncestor <TreasureTable>(spot.gameObject) == null) { Debug.LogError("No TreasureTable found on " + spot.gameObject + " nor any of its ancestors."); } } environment = GameObject.FindObjectOfType <EnvironmentManager>(); if (environment == null) { Debug.LogError("EnvironmentManager not found."); } gameplayManager = GameObject.FindObjectOfType <GameplayManager>(); if (gameplayManager == null) { Debug.LogError("GameplayManager not found!"); } GameObject collisionMarkers; collisionMarkers = GameObject.Find("CollisionMarkers"); if (collisionMarkers == null) { collisionMarkers = new GameObject("CollisionMarkers"); } if (environment.propsFolder != null) { collisionMarkers.transform.parent = environment.propsFolder.transform; } }
// called by external scripts to select a procedural config for this container // TODO - this whole thing is garbage and needs to be rewritten, maybe when i know more about what GameplayManager wants to do public void InitializeContainerConfiguration() { // figure out which objectSpots we're going to use List <int> indices = CodeTools.MultipleWeightedRandomSelections(spots_randWeights, numSpotsToFill, false); if (indices.Count == 0) { return; } int usedByGoalObject = -1; if (gameplayManager.readyForInsertion != null) { usedByGoalObject = GetIndexForGoalObject(); CodeTools.CopyTransform(objectSpots[usedByGoalObject].transform, gameplayManager.readyForInsertion.transform, true, true, false); // Debug.Log(gameplayManager.readyForInsertion + " teleported to newly-emerging alcove."); gameplayManager.readyForInsertion = null; } // spawn treasures at each of those spots foreach (int index in indices) { if (index != usedByGoalObject) // if a goal object has been placed in this slot, then skip it { GameObject spot = objectSpots[index].gameObject; TreasureTable tt = CodeTools.GetComponentFromNearestAncestor <TreasureTable>(spot); if (tt == null) { Debug.LogError("No TreasureTable found on " + spot + " nor any of its ancestors."); } // pick a treasure that fits in the chosen spot // TODO - this logic should go more like: there's a method that finds an unused spot this treasure will fit and puts it there. iterating over treasures, not spots. GameObject treasurePrefab = null; bool itFitsHere = false; int tries = 0; GameObject newTreasure = null; while ((!itFitsHere) && (tries < 20)) // TODO - this is an unacceptable amount of sweeptests for performance { tries++; treasurePrefab = tt.GetRandomTreasure(); newTreasure = (GameObject)Instantiate(treasurePrefab) as GameObject; CodeTools.CopyTransform(spot.transform, newTreasure.transform, false, true, false); // rotate the object to match the spot itFitsHere = CodeTools.TestForCollision(newTreasure, spot.transform.position); if (itFitsHere) { Debug.Log(newTreasure + " fits without collision at " + spot.transform.position); if (spot.transform.position == Vector3.zero) { Debug.Log("Why is it zero?"); } } else { Debug.Log(newTreasure + " does not fit at " + spot.transform.position); DestroyImmediate(newTreasure); // TODO - needless to say this is terrible } } if (itFitsHere) { // now you can teleport it there CodeTools.CopyTransform(spot.transform, newTreasure.transform, true, true, false); newTreasure.transform.parent = (environment.propsFolder != null) ? environment.propsFolder.transform : null; } else { Debug.LogError("Couldn't find any treasures that will fit in spot " + spot.gameObject + " which is at " + spot.transform.position); } } } }