예제 #1
0
    public void Pickup()
    {
        // Get nearest
        m_CurrentInteracteble = GetNearestInteractable();

        // Null check
        if (!m_CurrentInteracteble)
        {
            return;
        }

        // Already held, check
        if (m_CurrentInteracteble.m_ActiveHand)
        {
            m_CurrentInteracteble.m_ActiveHand.Drop();
        }

        // Position
        m_CurrentInteracteble.transform.position = transform.position;

        // Attach
        Rigidbody targetBody = m_CurrentInteracteble.GetComponent <Rigidbody>();

        m_Joint.connectedBody = targetBody;

        // Set active hand
        m_CurrentInteracteble.m_ActiveHand = this;
    }
예제 #2
0
    public void FollowTarge(Interacteble newTarget)
    {
        agent.stoppingDistance = newTarget.radius * .8f;
        agent.updateRotation   = false;

        target = newTarget.interactionTransform;
    }
예제 #3
0
 void RemoveFocus()
 {
     if (focus != null)
     {
         focus.OnDefocused();
     }
     focus = null;
     motor.StopFollowingTarget();
 }
예제 #4
0
    private void OnTriggerStay(Collider other)
    {
        Interacteble interacteble = other.GetComponent <Interacteble>();

        if (interacteble != null && !inRangeGo.Contains(other.gameObject))
        {
            inRangeGo.Add(other.gameObject);
        }
    }
예제 #5
0
 public InteractionButton(Node node, int nodeIndex, Interacteble target, int targetIndex, EditorController controllerReference)
 {
     parentNode  = node;
     parentIndex = nodeIndex;
     interaction = target;
     index       = targetIndex;
     type        = ButtonEditorType.INTERACTABLE;
     controller  = controllerReference;
 }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                //  FindObjectOfType<AudioManager>().Play("On_My_Way");

                motor.MoveToPoint(hit.point);

                RemoveFocus();
                mNavMeshAgent.destination = hit.point;
            }
        }

        if (mNavMeshAgent.remainingDistance <= mNavMeshAgent.stoppingDistance)
        {
            mRunning = false;
            FindObjectOfType <AudioManager>().Play("test");
        }
        else
        {
            mRunning = true;
        }

        mAnimator.SetBool("running", mRunning);

        if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                Interacteble interacteble = hit.collider.GetComponent <Interacteble>();

                FindObjectOfType <AudioManager>().Play("gun");
                if (interacteble != null)
                {
                    SetFocus(interacteble);
                }

                if (mNavMeshAgent.remainingDistance <= mNavMeshAgent.stoppingDistance)
                {
                    mRunning = true;
                }
            }
        }
    }
예제 #7
0
 void SetFocus(Interacteble newFocus)
 {
     if (newFocus != focus)
     {
         if (focus != null)
         {
             focus.OnDefocused();
         }
         focus = newFocus;
         motor.FollowTarget(newFocus);
     }
     newFocus.OnFocused(transform);
 }
예제 #8
0
    private void SelectJob()
    {
        RaycastHit hit;
        Ray        ray     = Camera.main.ScreenPointToRay(Input.mousePosition);
        LayerMask  newMask = ~(_invertMask ? ~_jobLayer.value : _jobLayer.value);

        if (Physics.Raycast(ray, out hit, 10000, newMask))
        {
            Interacteble interacteble = hit.collider.GetComponent <Interacteble>();
            if (interacteble != null && Input.GetButtonDown("LeftMouseButtom"))
            {
                _npc.SelectJob(interacteble);
                ResetManager();
            }
        }
    }
예제 #9
0
    private Interacteble GetNearestInteractable()
    {
        Interacteble nearest     = null;
        float        minDistance = float.MaxValue;
        float        distance    = 0.0f;

        foreach (Interacteble interactable in m_ContactInteractebles)
        {
            distance = (interactable.transform.position - transform.position).sqrMagnitude;

            if (distance < minDistance)
            {
                minDistance = distance;
                nearest     = interactable;
            }
        }

        return(nearest);
    }
예제 #10
0
    public void Drop()
    {
        // Null check
        if (!m_CurrentInteracteble)
        {
            return;
        }

        // Aply velocity
        Rigidbody targetBody = m_CurrentInteracteble.GetComponent <Rigidbody>();

        targetBody.velocity        = m_Pose.GetVelocity();
        targetBody.angularVelocity = m_Pose.GetAngularVelocity();

        // Detach
        m_Joint.connectedBody = null;

        // Clear
        m_CurrentInteracteble.m_ActiveHand = null;
        m_CurrentInteracteble = null;
    }
예제 #11
0
    public void Command(Ray ray)
    {
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100))
        {
            //Set focus
            Interacteble interactable = hit.collider.GetComponent <Interacteble>();
            if (interactable != null)
            {
                SetFocus(interactable);
            }
            else
            {
                RemoveFocus();
                //Move entity to pos
                if (Physics.Raycast(ray, out hit, 100, movmentMask))
                {
                    motor.MoveToPoint(hit.point);
                }
            }
        }
    }
예제 #12
0
    void Update()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }
        if (Input.GetMouseButton(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100, movementMask))
            {
                // Debug.Log("We Hit " + hit.collider.name + " " + hit.point);
                //Move our player to what we hit
                motor.MoveToPoint(hit.point);
                //Stop focusing any objects
                RemoveFocus();
            }
        }
        if (Input.GetMouseButton(1))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                //Debug.Log("We Hit " + hit.collider.name + " " + hit.point);
                //Check if we hit an interactble
                Interacteble interacteble = hit.collider.GetComponent <Interacteble>();
                //If we did, set it as our focus
                if (interacteble != null)
                {
                    SetFocus(interacteble);
                }
            }
        }
    }
예제 #13
0
 private void Update()
 {
     ray = _cam.ScreenPointToRay(Input.mousePosition);
     if (Physics.Raycast(ray, out hit, _getItemDistance))
     {
         if (_lastInterateble = hit.transform.GetComponent <Interacteble>())
         {
             _lastInterateble.Interact(this);
             HelpingText.enabled = true;
         }
     }
     else
     {
         if (_lastRetentionBlock)
         {
             _lastRetentionBlock.useGravity = true;
             _lastRetentionBlock            = null;
         }
         _holdSlider.parent.parent.gameObject.SetActive(false);
         HelpingText.enabled = false;
         CanHolding          = true;
         IsStartHold         = true;
     }
 }
예제 #14
0
 void RemoveFocus()
 {
     focus = null;
 }
예제 #15
0
 public void SetInteraction(Interacteble newInteractable)
 {
     interaction = newInteractable;
 }
예제 #16
0
 public void AddInteraction(Interacteble newInteraction)
 {
     possibleInteractions.Add(newInteraction);
 }
예제 #17
0
 public void CreateInteraction(Interacteble interaction)
 {
     currentNode.AddInteraction(interaction);
 }
예제 #18
0
    public void FollowTarget(Interacteble newTarget)
    {
        agent.stoppingDistance = newTarget.radius * 0.8f;

        target = newTarget.interactionTransform;
    }
예제 #19
0
 private void Awake()
 {
     entity = true;
     motor  = GetComponent <UnitMotor>();
     focus  = null;
 }
예제 #20
0
    void FixedUpdate()
    {
        // calculating the closest interaction GameObject
        Closest = colsestGo(inRangeGo, InteractingArea);

        durationEPressed();

        //interacting with objects
        if (Input.GetKeyDown(KeyCode.E) && Closest != null)
        {
            //calculating if "Closest" is within interaction radius
            Vector3 diff        = Closest.transform.position - InteractingArea.position;
            float   curDistance = diff.sqrMagnitude;

            Interacteble interacteble = Closest.GetComponent <Interacteble>();

            //continue dialouge if dialouge is showing
            if (diualougeDisplayed == true)
            {
                DialogueManager.DisplayNextSentence();
            }
            //else check to interact with object in radius
            else if (curDistance < interactingRadius && interacteble != null || holdingObject == true)
            {
                interacteble.Interact();

                //if object is a text interaction
                if (interacteble.InteractionType == Interacteble.typeOfInteraction.TextInteraction)
                {
                    Dialogue dialogue = interacteble.text.dialogue;
                    if (dialogue != null)
                    {
                        diualougeDisplayed = true;
                        DialogueManager.StartDialogue(dialogue);
                    }
                    else
                    {
                        Debug.LogWarning("missing Dialouge from " + interacteble.name);
                    }
                }
                //check what type of interaction it is
                //if object can be picked up
                else if (interacteble.InteractionType == Interacteble.typeOfInteraction.pickUp)
                {
                    if (!holdingObject)
                    {
                        currentlyHolding = Closest;
                        holdingObject    = true;
                        //pick up object
                    }
                    ePressedAmount++;
                }
                else if (interacteble.InteractionType == Interacteble.typeOfInteraction.Activate)
                {
                }
            }
        }

        if (Input.GetKeyUp(KeyCode.E) && Closest != null)
        {
            if (timer > minimumThrowlimit)
            {
                TrowObject();
            }
            else if (ePressedAmount > 1)
            {
                TrowObject();
            }

            timer = 0;
        }

        //this is whats picking up the objces/dropping it
        if (holdingObject)
        {
            PickUp();
        }
    }
예제 #21
0
 public void SelectJob(Interacteble interacteble)
 {
     _defending    = false;
     _interacteble = interacteble;
     _target       = interacteble.gameObject.transform.position;
 }
예제 #22
0
 void SetFocus(Interacteble newFocus)
 {
     focus = newFocus;
 }
예제 #23
0
    // Update is called once per frame
    void Update()
    {
        keyDownCheck();
        keyUpCheck();

        #region Camera Movment
        //X
        if (forwards && zSpeed < moveSpeedMax)
        {
            zSpeed += moveSpeed;
        }
        if (backwards && zSpeed > -moveSpeedMax)
        {
            zSpeed -= moveSpeed;
        }
        if (!backwards && !forwards)
        {
            if (zSpeed > 0.009f)
            {
                zSpeed -= friction;
            }
            else if (zSpeed < -0.009f)
            {
                zSpeed += friction;
            }
            else
            {
                zSpeed = 0;
            }
        }
        //Y
        if (leftwards && xSpeed > -moveSpeedMax)
        {
            xSpeed -= moveSpeed;
        }
        if (rightwards && xSpeed < moveSpeedMax)
        {
            xSpeed += moveSpeed;
        }
        if (!leftwards && !rightwards)
        {
            if (xSpeed > 0.009f)
            {
                xSpeed -= friction;
            }
            else if (xSpeed < -0.009f)
            {
                xSpeed += friction;
            }
            else
            {
                xSpeed = 0;
            }
        }
        #endregion

        #region Zoom
        float scroll   = Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
        float distance = Vector3.Distance(Camera.main.transform.position, this.transform.position);
        if (distance - scroll < minZoom)
        {
            scroll = distance - minZoom;
        }
        if (distance - scroll > maxZoom)
        {
            scroll = distance - maxZoom;
        }

        if (distance > minZoom && scroll > 0)
        {
            Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, this.transform.position, scroll);
        }
        if (distance < maxZoom && scroll < 0)
        {
            Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, this.transform.position, scroll);
        }
        #endregion

        #region Rotation

        //Q & E rotation
        if (leftRotation && rotation < maxRotationSpeed)
        {
            rotation += rotationSpeed;
        }
        if (rightRotation && rotation > -maxRotationSpeed)
        {
            rotation -= rotationSpeed;
        }
        if (!leftRotation && !rightRotation)
        {
            if (rotation > 0.009f)
            {
                rotation -= rotationFriction;
            }
            else if (rotation < -0.009f)
            {
                rotation += rotationFriction;
            }
            else
            {
                rotation = 0;
            }
        }
        else if (!leftMB)
        {
            Camera.main.transform.RotateAround(this.gameObject.transform.position, Vector3.up, rotation);
            this.gameObject.transform.Rotate(Vector3.up, rotation);
        }


        if (leftMB && mEnabled)
        {
            rotation = Input.GetAxis("Mouse X") * rotationSpeedMouse;
            Camera.main.transform.RotateAround(this.gameObject.transform.position, Vector3.up, rotation);
            this.gameObject.transform.Rotate(Vector3.up, rotation);
        }


        #endregion

        #region Pitch
        float pitch = Input.GetAxis("Mouse Y") * pitchSpeed;
        if (rightMB && leftMB && mEnabled)
        {
            float zAngle = Camera.main.transform.rotation.eulerAngles.x;

            if (zAngle > minPitch && pitch > 0)
            {
                Camera.main.transform.Rotate(-pitch, 0, 0);
            }
            if (zAngle < maxPitch && pitch < 0)
            {
                Camera.main.transform.Rotate(-pitch, 0, 0);
            }
        }
        #endregion


        if (!mEnabled)
        {
            #region Select
            if (Input.GetMouseButtonDown(0))
            {
                //Creating Ray
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                //Check what it his
                if (Physics.Raycast(ray, out hit, 10000))
                {
                    Interacteble interactable = hit.collider.GetComponent <Interacteble>();

                    if (interactable != null)
                    {
                        SetFocus(interactable);
                    }
                    else
                    {
                        RemoveFocus();
                    }
                }
            }
            #endregion

            if (Input.GetMouseButtonDown(1) && focus != null)
            {
                if (focus.entity)
                {
                    Ray  ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
                    Unit unit = (Unit)focus;
                    unit.Command(ray);
                }
            }
        }


        speed = new Vector3(xSpeed, ySpeed, zSpeed);
        speed = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y / 2, 0) * speed;

        if (Camera.main.transform.rotation.y < 0)
        {
            speed *= -1;
        }
        this.gameObject.transform.Translate(speed);
    }