Beispiel #1
0
    void Interact()
    {
        // find object
        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 3, layerMask))
        {
            foreach (InteractiveObjectController interactiveObject in gm.interactiveObjects)
            {
                if (interactiveObject.gameObject == hit.collider.gameObject)
                {
                    if (selectedObject == null || interactiveObject.gameObject != selectedObject.gameObject)
                    {
                        if (selectedObject != null)
                        {
                            selectedObject.ToggleOutline(false);
                        }
                        selectedObject = interactiveObject;
                        selectedObject.ToggleOutline(true);
                    }
                }
            }
        }
        else if (selectedObject != null)
        {
            selectedObject.ToggleOutline(false);
            selectedObject = null;
        }

        if (Input.GetButtonDown("Interaction") && selectedObject != null)
        {
            ToggleCursor(true);
            selectedObject.interacting = true;
            StartCoroutine(MoveCamera(selectedObject.camHolder.position, selectedObject.camHolder.rotation, true));
        }
    }
    // Use this for initialization
    void Start()
    {
        fireWooshAudioSrc.enabled = true;
        sparkleAudioSrc.enabled   = true;
        flameAudioSrc.enabled     = true;
        jetAudioSrc.enabled       = true;
        objectController          = GetComponent <InteractiveObjectController>();

        spellSequence = new List <int>();
        //spellSequence[0] = 0;

        lastTracker        = new GameObject().transform;
        lastTracker.parent = head;

        sparksEM            = sparks.emission;
        sparksEM.enabled    = false;
        sparksLight.enabled = false;

        fireEM         = fire.emission;
        fireEM.enabled = false;

        flameEM         = flame.emission;
        flameEM.enabled = false;

        jetEM             = jet.emission;
        jetEM.enabled     = false;
        fireLight.enabled = false;

        smokeEM         = smoke.emission;
        smokeEM.enabled = false;
    }
Beispiel #3
0
    void Sort()
    {
        float minDistance = float.MaxValue;
        float distance;

        lastClosestObj = closestObj;

        //Goes through avialable objects and decides which one is closest to the manipulator, every frame that the manipuator has collided with one or more interactive objects
        foreach (InteractiveObjectController item in availableObjects)
        {
            //throwing in another check that there are actually items in available objects, because sometimes it seems there aren't by the time this functiong gets called
            if (availableObjects.Count > 0)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestObj  = item;
                }
            }
        }

        if (closestObj != grabbedObj && closestObj.highlightedStatus == false && closestObj.grabbedStatus == false)
        {
            Highlight(closestObj); //closest object is highlighted, so user knows what they're going to pick up with they initiate grab.
        }

        if (lastClosestObj != null && lastClosestObj.highlightedStatus == true && lastClosestObj != closestObj)
        {
            Unhighlight(lastClosestObj); //unhighlights objects that are no longer closest to the manipulator, or grabbed.
        }
    }
Beispiel #4
0
 // Use this for initialization
 void Start()
 {
     //lockTrigger = transform.FindChild("LockTrigger").GetComponent<ChestTriggerController>();
     lid      = transform.FindChild("Chest_Top_LOD0").GetComponent <InteractiveObjectController>();
     latch    = transform.FindChild("Chest_Top_LOD0/Chest_Latch_LOD0").GetComponent <InteractiveObjectController>();
     audioSrc = GetComponent <AudioSource>();
 }
    private void SetParents()
    {
        //parentObjects.Clear();

        foreach (AttachmentTriggerController trigger in triggers)
        {
            AttachmentPointController attachmentPoint = trigger.GetOverlappingAttachmentPoint();

            if (attachmentPoint)
            {
                InteractiveObjectController newParent = attachmentPoint.GetOwningObject();

                if (newParent && (newParent.grabbed || newParent.attached) && !parentObjects.Contains(newParent))
                {
                    newParent.AddObjects(this);
                    newParent.AddMass(mass);
                    parentObjects.Add(newParent);

                    //Debug.Log("Object: " + this.name + " adding object: " + attachmentPoint.GetOwningObject().name + " as a parent object.");
                    //Debug.Log("Parent objects count: " + parentObjects.Count);
                }
            }
        }

        if (attachedObjects.Count > 0)
        {
            foreach (InteractiveObjectController attached in attachedObjects)
            {
                attached.SetParents();
            }
        }

        //SayParents();
    }
Beispiel #6
0
 void Start()
 {
     trackedObj       = GetComponent <SteamVR_TrackedObject>();
     availableObjects = new HashSet <InteractiveObjectController>();
     grabbingStatus   = false;
     actionStatus     = false;
     grabbedObj       = null;
 }
 // Use this for initialization
 void Start()
 {
     owningObject = GetComponentInParent <InteractiveObjectController>();
     rend         = GetComponent <Renderer>();
     SetHighlightOff(false);
     highlightGrabbed  = false;
     highlightSelected = false;
     highlightAttached = false;
 }
Beispiel #8
0
    void Highlight(InteractiveObjectController colorObj)
    {
        Color    col = new Color(0.5f, 0.45f, 0);
        Renderer rend;

        rend = colorObj.GetComponent <Renderer>();
        rend.material.EnableKeyword("_EMISSION");
        rend.material.SetColor("_EmissionColor", col);
        colorObj.highlightedStatus = true;
    }
Beispiel #9
0
    public void Drop()
    {
        if (grabbedObj.secondaryManipulator)
        {
            if (this == grabbedObj.secondaryManipulator)
            {
                if (grabbedObj.twoHandEnhance)
                {
                    grabbedObj.velocityFactor = grabbedObj.velocityFactor / 2;
                    grabbedObj.rotationFactor = grabbedObj.rotationFactor / 4;
                }

                grabbedObj.handleTwo.transform.parent        = grabbedObj.transform;
                grabbedObj.handleTwo.transform.localPosition = grabbedObj.handleTwoInitPos;
                grabbedObj.handleTwo.transform.localRotation = Quaternion.identity;
                grabbedObj.handleTwo.transform.localRotation = grabbedObj.handleTwoInitRot;
                grabbedObj.secondaryManipulator = null;
                grabbedObj = null;
            }

            else
            {
                if (grabbedObj.twoHandEnhance)
                {
                    grabbedObj.velocityFactor = grabbedObj.velocityFactor / 2;
                    grabbedObj.rotationFactor = grabbedObj.rotationFactor / 4;
                }

                grabbedObj.attachedManipulator = null;
                grabbedObj.grabbedStatus       = false;
                Destroy(interactionPoint.gameObject);
                grabbedObj.secondaryManipulator.Grab(grabbedObj);
                grabbedObj.secondaryManipulator = null;
                grabbedObj = null;
            }
        }

        else
        {
            //if dropped object is plugged, but not locked, unplug the object before dropping
            if (grabbedObj.plugObj && !grabbedObj.lockedStatus)
            {
                grabbedObj.plugObj.Unplug(grabbedObj);
            }

            grabbedObj.attachedManipulator = null;
            Destroy(interactionPoint.gameObject);
            //tell the object it is no longer grabbed.
            grabbedObj.grabbedStatus = false;
            //clear out the grabbed object variable.
            grabbedObj = null;
            //no more object to track, so reset it
            resetTrackerRot = true;
        }
    }
Beispiel #10
0
    private void OnTriggerEnter(Collider other)
    {
        InteractiveObjectController otherObject = other.GetComponent <InteractiveObjectController>();

        if (otherObject && otherObject.attached && otherObject.breakMomentum <= GetMomentum())
        {
            AttachmentPointController otherAttachment = otherObject.parentAttachmentPoint;
            otherObject.Detach();
            otherAttachment.Deactivate();
        }
    }
Beispiel #11
0
 void Unhighlight(InteractiveObjectController colorObj)
 {
     if (colorObj)
     {
         Renderer rend;
         rend = colorObj.GetComponent <Renderer>();
         rend.material.EnableKeyword("_EMISSION");
         rend.material.SetColor("_EmissionColor", Color.black);
         colorObj.highlightedStatus = false;
     }
 }
Beispiel #12
0
    private void OnCollisionEnter(Collision collision)
    {
        InteractiveObjectController otherObject = collision.gameObject.GetComponent <InteractiveObjectController>();

        if (otherObject && otherObject.attached)
        {
            AttachmentPointController otherAttachment = otherObject.parentAttachmentPoint;
            otherObject.Detach();
            otherAttachment.Deactivate();
        }
    }
Beispiel #13
0
    void OnTriggerExit(Collider collided)
    {
        //if an object stops colliding with the manipulator, check to see if it is interactive
        InteractiveObjectController collidedObj = collided.GetComponent <InteractiveObjectController>();

        if (collidedObj)
        {
            //if the object is interactive, assume that it was already added to the list of available objects and remove it from that list
            Unhighlight(collidedObj);
            availableObjects.Remove(collidedObj);
        }
    }
Beispiel #14
0
    private InteractiveObjectController GetAttachingObject(AttachmentTriggerController trigger)
    {
        InteractiveObjectController attaching = trigger.GetOwningObject();

        if (attaching.rootObject)
        {
            //Debug.Log("Setting attaching object to object root!.");
            attaching = attaching.rootObject;
        }

        return(attaching);
    }
Beispiel #15
0
    void Start()
    {
        audioSrc = GetComponent <AudioSource>();

        objectController       = GetComponent <InteractiveObjectController>();
        trigger                = transform.FindChild("Trigger");
        tankName               = "SquirtGun_Tank";
        tankPlug.soughtForName = tankName;

        streamTrans      = transform.FindChild("Stream");
        stream           = streamTrans.GetComponent <ParticleSystem>();
        streamEM         = stream.emission;
        streamEM.enabled = false;

        sprayTrans      = transform.FindChild("Spray");
        spray           = sprayTrans.GetComponent <ParticleSystem>();
        sprayEM         = spray.emission;
        sprayEM.enabled = false;

        streamSprayTrans      = transform.FindChild("StreamSpray");
        streamSpray           = streamSprayTrans.GetComponent <ParticleSystem>();
        streamSprayEM         = streamSpray.emission;
        streamSprayEM.enabled = false;

        splash1Trans = transform.FindChild("Stream/Splash1");
        splash1      = splash1Trans.GetComponent <ParticleSystem>();
        splash1EM    = splash1.emission;

        splash2Trans = transform.FindChild("Stream/Splash2");
        splash2      = splash2Trans.GetComponent <ParticleSystem>();
        splash2EM    = splash2.emission;

        triggerPressPos   = new Vector3(0, 0, -0.01f);
        triggerPos        = new Vector3(0, 0, 0);
        triggerPressSpeed = 0.5f;

        waterLevel            = 1.0f;
        minWaterLevel         = 0.985f;
        waterDepletionRate    = 0.000005f;
        pressure              = 0;
        pressureDepletionRate = 0.000005f;
        minP = 0.75f;
        maxP = 10;
        rechargeMultiplier = 10.0f;

        handleTrans               = transform.FindChild("Handle");
        handle                    = handleTrans.GetComponent <InteractiveObjectController>();
        handle.minPos             = -0.1385f;
        handle.maxDistance        = 1.0f;
        handle.movementResistance = 10;
        squirtStatus              = false;
    }
 public void AttachTo(InteractiveObjectController otherObject, AttachmentPointController attachmentPoint)
 {
     parentObject          = otherObject;
     parentAttachmentPoint = attachmentPoint;
     //parentObject.AddObjects(this);
     Reroot(FindRoot(parentObject));
     parentObject.AddObjects(this);
     Destroy(this.GetComponent <Rigidbody>());
     this.GetComponent <Collider>().isTrigger = false;
     //parentObject.AddMass(mass);
     attached = true;
     //Debug.Log(this.name + " attached to " + parentObject.name + ", with root object " + rootObject.name);
     SetParents();
 }
Beispiel #17
0
    void OnTriggerEnter(Collider collided)
    {
        InteractiveObjectController collidedObj = collided.GetComponent <InteractiveObjectController>();

        if (collidedObj)
        {
            if (collidedObj.name == soughtForName)
            {
                if ((collidedObj.grabbedStatus && !oneHandPlug) || oneHandPlug)
                {
                    pluggedObj = collidedObj;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, maxInteractionDistance, interactiveLayer.value))
        {
            Debug.Log(hit.transform.name);
            InteractiveObjectController interactiveObjectController = hit.collider.GetComponent <InteractiveObjectController>();
            if (interactiveObjectController)
            {
                Debug.Log("I see " + interactiveObjectController.objectName + ". object info: " + hit.collider.gameObject);
            }
        }
        _interactiveObject = null;
    }
Beispiel #19
0
    private ManipulatorController GetAttachingController(AttachmentTriggerController trigger)
    {
        ManipulatorController       controller   = null;
        InteractiveObjectController triggerOwner = trigger.GetOwningObject();

        if (triggerOwner.attached)
        {
            controller = triggerOwner.rootObject.GetAttachedController();
        }
        else
        {
            controller = triggerOwner.GetAttachedController();
        }

        return(controller);
    }
Beispiel #20
0
    void OnParticleCollision(GameObject hitObj)
    {
        Rigidbody hitBody = hitObj.GetComponent <Rigidbody>();
        InteractiveObjectController hitIOC = hitObj.GetComponent <InteractiveObjectController>();

        if (hitBody)
        {
            Vector3 direction = (hitObj.transform.position - transform.position) * force;
            hitBody.AddForce(direction, ForceMode.Impulse);
        }

        if (hitIOC)
        {
            hitIOC.effectStatus = true;
        }
    }
Beispiel #21
0
    private void DetectSpawn()
    {
        //need to change this to some sort of event based system
        int currentCount = floorObject.GetAttachedObjects().Count;
        HashSet <GameObject> spawnedObjects = spawner.spawnedObjects;

        //Debug.Log("spawned objects: " + spawnedObjects.Count + ", minimum blocks: " + minimumSpawnedBlocks);

        if (spawnedObjects.Count < minimumSpawnedBlocks)
        {
            //Debug.Log("BELOW MINIMUM!");
            for (int i = 0; i < minimumSpawnedBlocks; i++)
            {
                spawner.SpawnRandom();
            }
        }
        else
        {
            if (lastCount != currentCount)
            {
                if (currentCount > lastCount)
                {
                    spawner.SpawnRandom();
                }

                if (currentCount < lastCount)
                {
                    if (spawnedObjects.Count - currentCount > allowableBlockOverflowAmount)
                    {
                        foreach (GameObject spawnedObject in spawnedObjects)
                        {
                            InteractiveObjectController interactiveObject = spawnedObject.GetComponent <InteractiveObjectController>();

                            if (!interactiveObject.grabbed && !interactiveObject.attached)
                            {
                                spawner.DeleteObject(spawnedObject);
                                break;
                            }
                        }
                    }
                }
            }
        }

        lastCount = currentCount;
    }
    private void Reroot(InteractiveObjectController newRoot)
    {
        this.rootObject = newRoot;

        if (rootObject != this)
        {
            this.transform.SetParent(rootObject.transform);
        }

        if (attachedObjects.Count > 0)
        {
            foreach (InteractiveObjectController attached in attachedObjects)
            {
                attached.Reroot(rootObject);
            }
        }
    }
    public void AddObjects(InteractiveObjectController objectToAdd)
    {
        attachedObjects.Add(objectToAdd);

        if (objectToAdd.attachedObjects.Count > 0)
        {
            foreach (InteractiveObjectController obj in objectToAdd.attachedObjects)
            {
                attachedObjects.Add(obj);
            }
        }

        if (parentObject)
        {
            parentObject.AddObjects(objectToAdd);
        }
    }
    public void RemoveObjects(InteractiveObjectController objectToRemove)
    {
        this.attachedObjects.Remove(objectToRemove);

        if (this != objectToRemove && objectToRemove.attachedObjects.Count > 0)
        {
            foreach (InteractiveObjectController obj in objectToRemove.attachedObjects)
            {
                this.attachedObjects.Remove(obj);
            }
        }

        if (parentObject)
        {
            parentObject.RemoveObjects(objectToRemove);
        }
    }
Beispiel #25
0
    void Start()
    {
        objectController = GetComponent <InteractiveObjectController>();
        trigger          = transform.FindChild("Trigger");

        streamTrans      = transform.FindChild("Stream");
        stream           = streamTrans.GetComponent <ParticleSystem>();
        streamEM         = stream.emission;
        streamEM.enabled = false;

        sprayTrans      = transform.FindChild("Spray");
        spray           = sprayTrans.GetComponent <ParticleSystem>();
        sprayEM         = spray.emission;
        sprayEM.enabled = false;

        streamSprayTrans      = transform.FindChild("StreamSpray");
        streamSpray           = streamSprayTrans.GetComponent <ParticleSystem>();
        streamSprayEM         = streamSpray.emission;
        streamSprayEM.enabled = false;

        splash1Trans = transform.FindChild("Stream/Splash1");
        splash1      = splash1Trans.GetComponent <ParticleSystem>();
        splash1EM    = splash1.emission;

        splash2Trans = transform.FindChild("Stream/Splash2");
        splash2      = splash2Trans.GetComponent <ParticleSystem>();
        splash2EM    = splash2.emission;

        triggerPressPos   = new Vector3(0, 0, -0.01f);
        triggerPos        = new Vector3(0, 0, 0);
        triggerPressSpeed = 0.5f;

        pressure           = 10;
        depletionRate      = 0.01f;
        minP               = 0.75f;
        maxP               = 10;
        rechargeMultiplier = 10.0f;

        handleTrans               = transform.FindChild("Handle");
        handle                    = handleTrans.GetComponent <AppendageController>();
        handle.minPos             = -0.1385f;
        handle.maxDistance        = 1.0f;
        handle.movementOffset     = -2.0f;
        handle.movementResistance = 10;
    }
Beispiel #26
0
    void OnTriggerEnter(Collider collided)
    {
        //when the manipulator collides with an object, check to see if the object is interactive
        InteractiveObjectController collidedObj = collided.GetComponent <InteractiveObjectController>();

        if (collidedObj)
        {
            //if the manipulator is grabbing, but hasn't grabbed anything, "catch" the colliding object
            if (grabbingStatus && !grabbedObj)
            {
                //if you're grabbing the child object of a larger assembly which has been dropped, grab the larger assembly instead
                if (collidedObj.orphanStatus)
                {
                    Grab(collidedObj.parentObj);
                    availableObjects.Add(collidedObj.parentObj);
                }

                //otherwise, just grab the object
                else
                {
                    Grab(collidedObj);
                    //also add object to list of available objects to be grabbed, in case the caught object is dropped
                    availableObjects.Add(collidedObj);
                }
            }

            //if the manipulator isn't currently grabbing, add collided object to the list of available objects to be grabbed
            if (!grabbingStatus)
            {
                //if the object the manipulator has collided with is the child of a larger assembly, add teh assembly to available objects
                if (collidedObj.orphanStatus)
                {
                    availableObjects.Add(collidedObj.parentObj);
                }

                //otherwise, just add the object to available objects
                else
                {
                    availableObjects.Add(collidedObj);
                }
            }
        }
    }
    private InteractiveObjectController FindRoot(InteractiveObjectController otherObject)
    {
        InteractiveObjectController newRoot = null;

        if (otherObject.rootObject)
        {
            newRoot = parentObject.rootObject;
        }
        else if (otherObject.grabbable)
        {
            newRoot = parentObject;
        }
        else
        {
            newRoot = this;
        }

        return(newRoot);
    }
Beispiel #28
0
    public void Activate(AttachmentTriggerController trigger)
    {
        //Debug.Log("Activating!");

        attachingTrigger    = trigger;
        attachingObject     = GetAttachingObject(attachingTrigger);
        attachingController = GetAttachingController(attachingTrigger);

        if (attachingController && attachingObject && attachingController)
        {
            attachingObject.GetComponent <BoxCollider>().isTrigger = true;
            owningObject.IgnoreCollision(attachingObject.GetComponent <Collider>(), true);
            attachingObject.SetMoveMode(0);

            SetInitialTrackingPositions();
            attachingObject.transform.SetParent(objectGuide);

            attachingObject.busy = true;
            owningObject.busy    = true;
            activated            = true;
        }
    }
    private void Beam()
    {
        RaycastHit hit;

        if (Physics.Raycast(localOrb.transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
        {
            if (!distantOn)
            {
                DistantOn();
            }
            distantEffects.transform.position = hit.point;
            hitObject = hit.collider.GetComponentInParent <InteractiveObjectController>();
        }
        else
        {
            if (distantOn)
            {
                DistantOff();
            }
            hitObject = null;
        }
    }
    public void Detach()
    {
        SetAttached();
        //Reroot(FindRoot(parentObject));

        this.transform.SetParent(parentAttachmentPoint.GetGuide()); // reparent to attachment point guide
        this.gameObject.AddComponent <Rigidbody>();
        rigidBody      = GetComponent <Rigidbody>();                // reset the local variable for the object's rigid body
        rigidBody.mass = mass;                                      // set the rigid body's mass to the stored value
        //parentObject.RemoveObjects(this); // remove this object from the parent object's attached objects group
        //parentObject.SubtractMass(mass);
        ClearParents();
        rootObject   = null;                                    // we're detaching here, there is no more root object (this object is root)
        parentObject = null;                                    // we're detaching here, there is no more parent object (this object is its own parent)
        Reroot(this);                                           // reroot all of this object's attached objects to this object
        attached = false;                                       // this object is no longer attached

        AttachmentPointController temp = parentAttachmentPoint; // temp reference for the attachment point that will be deleted once out of scope

        parentAttachmentPoint = null;                           // get rid of the attachment point global
        temp.Activate(temp.GetAttachingTrigger());              // reactivate the attachment point
    }