Beispiel #1
0
    // 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);
        }
    }
Beispiel #2
0
    void Start()
    {
        if (audioSource == null)
        {
            audioSource = GetComponent <AudioSource>();
        }

        if (audioSource == null)
        {
            Debug.LogError("No AudioSource assigned or detected.");
        }

        if (clips.Length == 0)
        {
            Debug.LogError("No AudioClips assigned.");
        }

        if (
            (clips.Length != clips_randomWeights.Length) ||
            (clips.Length != clips_randPitchRanges.Length) ||
            (clips_randomWeights.Length != clips_randPitchRanges.Length)
            )
        {
            Debug.LogError("Arrays whose names start with the word 'clips' are parallel arrays and must have the name number of elements.");
        }


        CodeTools.ValidateWeightedRandomArray(clips_randomWeights, clips.Length);

        MinMaxValues minmax = new MinMaxValues(-3f, 3f);

        CodeTools.ValidateMinMaxArray(clips_randPitchRanges, minmax, minmax);

        lastTriggerTime = dontTriggerUntil;  // this is how dontTriggerUntil is implemented
    }
Beispiel #3
0
    protected override void Start()
    {
        base.Start();

        if ((randomizedAngle.Length != 0) && (randomizedAngle.Length != 3))
        {
            Debug.Log("randomizedAngle should either be empty or it should have exactly 3 elements corresponding to the X, Y, and Z angles to offset by that amount.");
        }

        CodeTools.ValidateMinMaxArray(randomizedAngle, new MinMaxValues(-20f, 0f), new MinMaxValues(0f, 20f));

        SpawnArrow();

        if (randomizedAngle.Length == 3)
        {
            RandomizeArrowAngle();
        }

        if (triggerSFX == null)
        {
            triggerSFX = GetComponent <RandomizedSFX>();
        }
        if (triggerSFX == null)
        {
            Debug.LogError("triggerSFX not assigned and no RandomizedSFX component detected.");
        }
    }
Beispiel #4
0
    protected override void StartEmerging()
    {
        base.StartEmerging();

        // pick one of the configurations at random
        currentConfig = configurations[CodeTools.WeightedRandomSelection(config_randomWeights)];
        currentConfig.gameObject.SetActive(true);
        currentConfig.InitializeContainerConfiguration();
    }
Beispiel #5
0
    void Start()
    {
        if (treasures.Length == 0)
        {
            Debug.LogError("treasures list not assigned.");
        }

        CodeTools.ValidateWeightedRandomArray(treasure_randWeights, treasures.Length);
    }
Beispiel #6
0
    public void IntegrateNewBlock(TempleWallBlock newBlock, WallBlockType blockType, WallBlockPosition wallPos)
    {
        Transform oldBlockTransform = GetBlockTransform(wallPos);

        CodeTools.CopyTransform(oldBlockTransform, newBlock.transform, true, true, false);

        DisableBlock(wallPos);

        AssignBlockToPosition(newBlock, wallPos);
    }
Beispiel #7
0
    // change the angle of the arrow and make sure the triggervolume is modified to match (it won't follow automatically since it's a rigidBody)
    // do this without any parenting, because with scale that'll cause all kinds of kooky misbehavior
    private void RandomizeArrowAngle()
    {
        // rotate myArrow by the random values expressed in randomizedAngle
        Vector3 angle = Vector3.zero;

        CodeTools.RandomizeVector3WithMinMaxArray(ref angle, randomizedAngle);
        myArrow.transform.Rotate(angle, Space.World);
        triggerVolume.transform.Rotate(angle, Space.World);

//        Debug.Log("Arrowtrap rotation angle = "+angle);
    }
Beispiel #8
0
    // 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!");
            }
        }
    }
Beispiel #9
0
    void Start()
    {
        if (targetTransform == null)
        {
            Debug.LogError("targetTransform not assigned.");
        }

        if (targetSlot == null)
        {
            targetSlot = targetTransform.gameObject.GetComponent <Slot>();
        }

        if (targetSlot == null)
        {
            Debug.LogError("targetSlot not assigned, and no Slot component found on targetTransform object.");
        }

        if (positionTolerance.Length != 3)
        {
            Debug.LogError("positionTolerance must be an array of size 3, where element 0 defines X tolerance, element 1 defines Y tolerance, and element 2 defines Z tolerance.");
        }

        MinMaxValues notMoreThanZero = new MinMaxValues(-999f, 0f);
        MinMaxValues notLessThanZero = new MinMaxValues(0f, 999f);

        CodeTools.ValidateMinMaxArray(positionTolerance, notMoreThanZero, notLessThanZero);

        if (rotationTolerance < 0)
        {
            Debug.LogError("rotationTolerance must be great than 0.");
        }

        if (checkPeriod < 0)
        {
            Debug.LogError("checkPeriod must be greater than 0 and should be much less than 1 (try 0.03 maybe).");
        }

        if (startSlotted)
        {
            // TODO - this code is pretty much duplicate copy/pasted from below
            SnapToTargetPosition();
            if (targetSlot != null)
            {
                targetSlot.ObjectHasSlotted(this);
            }
            if (becomeNonphysicalWhenSlotted)
            {
                BecomePhysical(false);   // do this last, because by default at present VRInteractable will make the object physical again when dropped when CommunicateSnapToOtherScripts() is called
            }
        }
    }
Beispiel #10
0
    // 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);
        }
    }
Beispiel #11
0
    // 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!");
        }
    }
Beispiel #12
0
    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;
        }
    }
Beispiel #13
0
    public bool PlaySFX(float vol)
    {
        if ((Time.time - lastTriggerTime) < dontRetriggerTime)
        {
            return(false);
        }

        lastTriggerTime = Time.time;

        int index = CodeTools.WeightedRandomSelection(clips_randomWeights);

        audioSource.pitch = Random.Range(clips_randPitchRanges[index].min, clips_randPitchRanges[index].max);

        audioSource.clip = clips[index];  // this stricly shouldn't be necessary

        audioSource.PlayOneShot(clips[index], vol);

        return(true);
    }
Beispiel #14
0
    protected virtual void StartEmerging()
    {
        blockState    = WallBlockState.Emerging;
        nextStateTime = Time.time + GameplayManager.blockEmergeDuration;

        // EmergeFX are assumed to be on&animating by default when they spawn
        GameObject fx = (GameObject)Instantiate(emergeFXPrefab) as GameObject;

        CodeTools.CopyTransform(transform, fx.transform, true, true, false);
        fx.transform.parent = transform;
        Destroy(fx, (GameplayManager.blockEmergeDuration + 2f));

        AudioSource audio = GetComponent <AudioSource>();

        if ((emergeSFX != null) && (audio != null))
        {
            audio.clip = emergeSFX;
            audio.PlayOneShot(emergeSFX, 0.3f);
        }
    }
Beispiel #15
0
    // change the Player root object's position and rotation
    // change the playerCollider's scale (and only change that scale, no other scales)
    private void UpdateCollider()
    {
        // copy them over, but we're going to modify them from there
        CodeTools.CopyTransform(hmd, transform, true, true, false);

        // used for both y position and y scale
        float top = hmd.position.y + playerHeightOffset;

        transform.position = new Vector3(transform.position.x, (top / 2f), transform.position.z);
        playerCollider.transform.localScale = new Vector3(playerCollider.transform.localScale.x, top, playerCollider.transform.localScale.z);

        // don't rotate around X or Z, only Y
        Quaternion rotQ = transform.rotation;
        Vector3    rotE = rotQ.eulerAngles;

        rotE.x             = 0;
        rotE.z             = 0;
        transform.rotation = Quaternion.Euler(rotE.x, rotE.y, rotE.z);

        // move player Eyes to be the height of the hmd
        playerEyes.transform.position = new Vector3(transform.position.x, hmd.position.y, transform.position.z);
    }
Beispiel #16
0
 // returns an index into objectSpots[] appropriate for a goalObject to be placed
 private int GetIndexForGoalObject()
 {
     return(CodeTools.WeightedRandomSelection(goalSpots_randWeights));
 }
Beispiel #17
0
 public GameObject GetRandomTreasure()
 {
     return(treasures[CodeTools.WeightedRandomSelection(treasure_randWeights)]);
 }
Beispiel #18
0
    // 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);
                }
            }
        }
    }
Beispiel #19
0
    protected override void Start()
    {
        base.Start();

        CodeTools.ValidateWeightedRandomArray(config_randomWeights, configurations.Length);
    }