Beispiel #1
0
    protected override void OnWorkshopUpdateState(bool state, MTK_Interactable current)
    {
        if (state)
        {
            m_scaleEffect = current.GetComponent <ScaleEffect>();

            if (!m_scaleEffect)
            {
                m_scaleEffect = current.gameObject.AddComponent <ScaleEffect>();
                m_scaleEffect.ApplyEffect();
            }

            AkSoundEngine.PostEvent("LFO_Scale_Play", gameObject);
        }
        else
        {
            if (m_scaleEffect)
            {
                m_scaleEffect.RemoveEffect();
            }

            m_scaleEffect = null;

            AkSoundEngine.PostEvent("LFO_Scale_Stop", gameObject);
        }
    }
    void Release()
    {
        if (m_grabbed)
        {
            m_grabbed.Grab(false);

            grabbedJoint.onJointBreak.RemoveListener(Release);
            grabbedJoint.RemoveJoint();

            if (grabbedJoint.rigidbody)
            {
                grabbedJoint.rigidbody.velocity        = m_inputManager.GetVelocity();
                grabbedJoint.rigidbody.angularVelocity = m_inputManager.GetAngularVelocity();
            }

            grabbedJoint.onJointBreak.RemoveListener(Release);
            m_telekinesis.Active = true;

            m_handAnimator.SetBool("Visible", true);
            m_handAnimator.SetBool("Attract", false);

            m_onReleaseInteractable.Invoke(m_grabbed);

            m_setup.NotifyRelease(m_grabbed);
            m_grabbed = null;

            // ObjectInTrigger = null;
        }
    }
Beispiel #3
0
    void Catch(MTK_Interactable interactable)
    {
        if (Time.time > m_lastActivationTime + m_activationCooldown)
        {
            if (!interactable.jointType.Used() && !catchedObject && !interactable.isDistanceGrabbed)
            {
                m_lastActivationTime = Time.time;
                if (m_snapToCenter)
                {
                    interactable.transform.position = transform.position;
                }

                interactable.jointType.JoinWith(gameObject);
                GetComponent <Joint>().breakForce = float.MaxValue;
                AkSoundEngine.PostEvent("Socle_Activated_Play", gameObject);
                catchedObject = interactable;
                interactable.jointType.onJointBreak.AddListener(Release);
                interactable.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePosition;
                interactable.isDistanceGrabbable = false;

                IcoPlanet icoplanet = interactable.GetComponent <IcoPlanet>();

                if (icoplanet)
                {
                    StartCoroutine(AnimatePlanet(icoplanet, 0.12f, 15));
                    onPlanetCatched.Invoke(true);
                }

                m_visual.SetActive(false);
                m_nbObjectsInTrigger = 0;

                onObjectCatched.Invoke(true);
            }
        }
    }
Beispiel #4
0
    public void Release()
    {
        if (catchedObject)
        {
            catchedObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;

            m_lastActivationTime = Time.time;
            onObjectCatched.Invoke(false);
            catchedObject.jointType.onJointBreak.RemoveListener(Release);
            catchedObject.isDistanceGrabbable = true;

            MTK_Interactable tmp = catchedObject;
            catchedObject = null;

            IcoPlanet icoplanet = tmp.GetComponent <IcoPlanet>();

            if (icoplanet)
            {
                StartCoroutine(AnimatePlanet(icoplanet, 0.04f, 4.2f));
                onPlanetCatched.Invoke(false);
            }

            tmp.jointType.RemoveJoint();
            tmp.GetComponent <Rigidbody>().AddForce(m_ejectForce * Vector3.up, ForceMode.Impulse);

            m_nbObjectsInTrigger = 0;
            objInTrigger         = null;

            m_button.SetActive(false);
        }
    }
Beispiel #5
0
    protected void EnableWorkshop(bool state)
    {
        MTK_Interactable current = m_dropzone.catchedObject;

        OnWorkshopUpdateState(state, current);

        if (state)
        {
            m_sound.Post(gameObject);
            current.isDistanceGrabbable = false;
            current.IndexJointUsed      = 1;

            current.jointType.onJointBreak.AddListener(() => Destroy(m_confJoint));
            current.isGrabbable = false;

            m_catchedObjectJoint = current.jointType;

            StartCoroutine(AnimateWorkshop(2, () =>
            {
                current.isGrabbable = true;
                m_dropzone.EnableButton();
            }));
        }
        else
        {
            current.IndexJointUsed      = 0;
            current.isDistanceGrabbable = true;

            m_catchedObjectJoint = null;
        }
    }
    void AnchorHologram(Hologram holo)
    {
        Outline outline = holo.referenceObject.GetComponent <Outline>();

        if (outline)
        {
            outline.enabled = false;
        }

        GameObject copy = Instantiate(holo.referenceObject);

        copy.transform.position = holo.transform.position;
        copy.transform.rotation = holo.transform.rotation;
        copy.transform.parent   = holo.projectedSegment.transform;
        copy.layer = LayerMask.NameToLayer("Planet");

        MTK_Interactable interact = copy.GetComponent <MTK_Interactable>();

        interact.isDroppable         = false;
        interact.isDistanceGrabbable = false;

        copy.AddComponent <ObjectOnPlanet>().referenceObject = holo.referenceObject;

        Destroy(copy.GetComponent <Rigidbody>());

        holo.referenceObject.transform.position = -1000f * Vector3.up;
        holo.referenceObject.GetComponent <Rigidbody>().isKinematic = true;
    }
Beispiel #7
0
    // Use this for initialization
    void Initialize()
    {
        m_vertices = Icosphere.GenerateIcosphere(1f, m_nbSubdivisions);

        m_segments = new List <IcoSegment>();

        for (int i = 0; i < m_vertices.Count / 3; ++i)
        {
            Vector3 v0 = m_vertices[3 * i + 0];
            Vector3 v1 = m_vertices[3 * i + 1];
            Vector3 v2 = m_vertices[3 * i + 2];

            GameObject segment = new GameObject();
            segment.transform.position = transform.position;
            segment.name             = "segment" + i;
            segment.transform.parent = transform;
            segment.AddComponent <MeshRenderer>();
            segment.GetComponent <MeshRenderer>().material = m_segmentMaterial;
            segment.layer = LayerMask.NameToLayer("Planet");

            IcoSegment icoSeg = segment.AddComponent <IcoSegment>();
            m_segments.Add(icoSeg);
            icoSeg.heightLevel = m_defaultHeightLevel;
            icoSeg.icoPlanet   = this;
            icoSeg.SetBaseVertices(v0, v1, v2);

            m_segmentJoints.Add(segment.AddComponent <MTK_PlanetSegmentJoint>());
            MTK_Interactable interactable = segment.AddComponent <MTK_Interactable>();
            interactable.isDistanceGrabbable = false;
            interactable.isGrabbable         = false;
            interactable.isDroppable         = false;
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        MTK_Interactable candidate = GetCandidate(other);

        if (candidate && candidate.isGrabbable)
        {
            ObjectInTrigger = candidate;
        }
    }
    private void OnTriggerExit(Collider other)
    {
        MTK_Interactable candidate = GetCandidate(other);

        if (candidate && candidate == ObjectInTrigger)
        {
            ObjectInTrigger = null;
        }
    }
Beispiel #10
0
    public void NotifyRelease(MTK_Interactable released)
    {
        m_grabbedList.Remove(released);

        if (m_grabbedList.Count == 0)
        {
            m_scalerDrop.enabled = false;
            m_tileDrop.enabled   = m_placerDrop.enabled = false;
        }
    }
Beispiel #11
0
    bool IsLevitating(MTK_Interactable interactable)
    {
        Rigidbody rb = interactable.GetComponent <Rigidbody>();

        if (rb)
        {
            return(!rb.useGravity);
        }
        return(false);
    }
Beispiel #12
0
    public void NotifyGrab(MTK_Interactable grabbed)
    {
        m_grabbedList.Add(grabbed);

        m_scalerDrop.enabled = true;

        if (grabbed.GetComponent <IcoPlanet>())
        {
            m_tileDrop.enabled = m_placerDrop.enabled = true;
        }
    }
Beispiel #13
0
 private void OnTriggerStay(Collider other)
 {
     if (enabled && other.attachedRigidbody)
     {
         MTK_Interactable interact = other.attachedRigidbody.GetComponent <MTK_Interactable>();
         if (interact && interact.isDroppable)
         {
             Catch(interact);
         }
     }
 }
Beispiel #14
0
 private void OnTriggerExit(Collider other)
 {
     if (enabled && other.attachedRigidbody)
     {
         MTK_Interactable interact = other.attachedRigidbody.GetComponent <MTK_Interactable>();
         if (interact && interact.isDroppable)
         {
             objInTrigger = null;
             m_nbObjectsInTrigger--;
         }
     }
 }
    // Update is called once per frame
    void EnableTerraformation(bool state)
    {
        if (state)
        {
            m_icoPlanet = m_dropzone.catchedObject.GetComponent <IcoPlanet>();

            if (m_icoPlanet)
            {
                AkSoundEngine.PostEvent("Play_Anim_Extrud", gameObject);
                m_icoPlanet.Animate();

                Invoke("EnableButton", 2);

                m_icoPlanet.GetComponent <Collider>().enabled = false;

                MTK_Interactable interactable = m_icoPlanet.GetComponent <MTK_Interactable>();
                interactable.isDistanceGrabbable = false;
                interactable.isGrabbable         = false;

                foreach (IcoSegment segment in m_icoPlanet.Segments)
                {
                    segment.GetComponent <MTK_Interactable>().isGrabbable = true;
                    segment.GetComponent <Collider>().enabled             = true;
                }

                AkSoundEngine.PostEvent("Soundseed_Play", gameObject);
                AkSoundEngine.PostEvent("Mute_Planet", gameObject);
            }
            else
            {
                m_dropzone.Release();
            }
        }
        else if (m_icoPlanet)
        {
            MTK_Interactable interactable = m_icoPlanet.GetComponent <MTK_Interactable>();
            interactable.isDistanceGrabbable = true;
            interactable.isGrabbable         = true;

            m_icoPlanet.GetComponent <Collider>().enabled = true;
            foreach (IcoSegment segment in m_icoPlanet.Segments)
            {
                segment.GetComponent <MTK_Interactable>().isGrabbable = false;
                segment.GetComponent <Collider>().enabled             = false;
            }
            m_icoPlanet.GenerateMeshCollider();

            m_icoPlanet = null;

            AkSoundEngine.PostEvent("Soundseed_Stop", gameObject);
            AkSoundEngine.PostEvent("UnMute_Planet", gameObject);
        }
    }
    protected override void OnWorkshopUpdateState(bool state, MTK_Interactable current)
    {
        IcoPlanet ico = m_dropzone.catchedObject.GetComponent <IcoPlanet>();

        if (state)
        {
            if (ico)
            {
                ico.GetComponent <MeshCollider>().enabled = false;

                foreach (IcoSegment segment in ico.Segments)
                {
                    segment.GetComponent <MeshCollider>().enabled = true;
                    if (segment.GetComponent <IcoSegment>())
                    {
                        foreach (Transform decoration in segment.transform)
                        {
                            decoration.GetComponent <MTK_Interactable>().isGrabbable = true;
                        }
                    }
                }
            }
            else
            {
                m_dropzone.Release();
            }
        }
        else
        {
            m_placingEnabled = false;

            if (ico)
            {
                ico.GetComponent <MeshCollider>().enabled = true;
                foreach (Transform segment in m_dropzone.catchedObject.transform)
                {
                    if (segment.GetComponent <IcoSegment>())
                    {
                        segment.GetComponent <MeshCollider>().enabled = false;
                        foreach (Transform decoration in segment)
                        {
                            decoration.GetComponent <MTK_Interactable>().isGrabbable = false;
                        }
                    }
                }
            }
        }
    }
Beispiel #17
0
    void UnAttract()
    {
        //m_handAnimator.SetBool("Attract", false);
        m_handAnimator.SetBool("Attract", true);

        m_wObjectStop.Post(Target.gameObject);

        if (m_connectedBody)
        {
            m_connectedBody.useGravity = true;
            m_connectedBody            = null;
        }

        Target.isDistanceGrabbed = false;
        Target = null;
    }
    MTK_Interactable GetCandidate(Collider other)
    {
        IcoSegment seg = other.gameObject.GetComponent <IcoSegment>();

        if (seg && fingerCollider && seg.IsInside(fingerCollider.position, other))
        {
            return(null);
        }

        MTK_Interactable candidate = other.GetComponent <MTK_Interactable>();

        if (!(candidate && candidate.isGrabbable) && other.attachedRigidbody)
        {
            candidate = other.attachedRigidbody.GetComponent <MTK_Interactable>();
        }

        return(candidate);
    }
Beispiel #19
0
    void GrabIfTarget(MTK_Interactable input)
    {
        if (m_attract && Target && input)
        {
            if (Target.gameObject == input.gameObject)
            {
                m_inputManager.Haptic(1);

                m_wObjectGrabbed.Post(Target.gameObject);
                m_wObjectStop.Post(Target.gameObject);
                m_wHandStop.Post(gameObject);

                input.transform.position = transform.position;
                m_hand.Grab(Target);

                SetLevitation(input, false);
                UnAttract();
            }
        }
    }
Beispiel #20
0
    void SetLevitation(MTK_Interactable interactable, bool value)
    {
        Rigidbody rb = interactable.GetComponent <Rigidbody>();

        if (rb)
        {
            if (value)
            {
                interactable.GetComponent <Rigidbody>().isKinematic = false;
                interactable.GetComponent <Rigidbody>().drag        = 0;

                interactable.UseEffects = false;
                rb.velocity             = Vector3.up;
                rb.angularVelocity      = Random.onUnitSphere;

                m_lastForceApplied = Vector3.zero;
            }
            rb.useGravity = !value; // !gravity = levitate
        }
    }
Beispiel #21
0
    public MTK_Interactable GetClosestToView(Vector3 position, Vector3 direction, float maxAngle)
    {
        float            minAngle = maxAngle;
        MTK_Interactable closest  = null;
        float            angle;

        foreach (MTK_Interactable item in m_grabbableesList)
        {
            if (item.isDistanceGrabbable)
            {
                angle = Vector3.Angle(item.transform.position - position, direction);

                if (angle < minAngle)
                {
                    closest  = item;
                    minAngle = angle;
                }
            }
        }

        return(closest);
    }
Beispiel #22
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.attachedRigidbody)
        {
            MTK_Interactable interactable = other.attachedRigidbody.GetComponent <MTK_Interactable>();
            if (interactable && interactable.isGrabbable && !interactable.isDistanceGrabbed)
            {
                UpdateTPZone(interactable.GetComponent <IcoPlanet>(), true);

                if (!other.attachedRigidbody.gameObject.GetComponent <PlanetEffect>())
                {
                    if (!other.GetComponentInParent <IcoSegment>())
                    {
                        PlanetEffect eff = other.attachedRigidbody.gameObject.AddComponent <PlanetEffect>();
                        if (eff)
                        {
                            eff.maxSpeed          = m_maxSpeed;
                            eff.accelerationForce = m_accelerationForce;
                            eff.impactForce       = impactForce;
                            eff.sunRigidbody      = m_rb;
                            m_planetEffectsList.Add(eff);

                            eff.explosionEffect = m_explosionEffect;

                            UpdateState(m_planetEffectsList.Count);

                            if (m_exclusionPlatform.m_objectsInTrigger.Contains(eff.gameObject))
                            {
                                eff.effectActive = false;
                                eff.GetComponent <Rigidbody>().useGravity = true;
                            }
                        }
                    }
                }
            }
        }
    }
    public void Grab(MTK_Interactable obj)
    {
        if (obj)
        {
            // if(!obj.GetComponent<ScaleEffect>() && !obj.GetComponent<IcoSegment>())
            //     obj.transform.position = transform.position;

            if (obj.jointType.Used())
            {
                obj.jointType.RemoveJoint();
            }

            obj.jointType.onJointBreak.AddListener(Release);

            if (!obj.jointType.JoinWith(gameObject))
            {
                obj.jointType.onJointBreak.RemoveListener(Release);
                return;
            }

            obj.Grab(true);

            m_grabbed    = obj;
            grabbedJoint = obj.jointType;

            inputManager.Haptic(1);
            m_telekinesis.Active = false;

            m_handAnimator.SetBool("Visible", false);
            m_handAnimator.SetBool("Attract", true);

            m_setup.NotifyGrab(m_grabbed);

            // ObjectInTrigger = null;
        }
    }
Beispiel #24
0
    void Update()
    {
        if (Active)
        {
            if (!m_attract)
            {
                if (m_interactHand.ObjectInTrigger)
                {
                    Target = null;
                }
                else if (!m_connectedBody)
                {
                    Target = m_interactiblesManager.GetClosestToView(transform.position, m_repere.position - transform.position, 15);
                }
            }

            if (Target)
            {
                float distanceScale = Mathf.Min(GetDistanceToTarget() / m_initDistanceToTarget, 1);                 // 1 -> 0

                // Detect movement to trigger attraction
                if (m_attract)
                {
                    Vector3 force = (m_repere.position - m_lastPos) * 10;

                    if (force.sqrMagnitude > m_maxForce)
                    {
                        force = force.normalized * m_maxForce;
                    }

                    if (force.sqrMagnitude > Mathf.Max(m_minMagnitudeToAttract, m_lastForceApplied.sqrMagnitude))
                    {
                        Attract(force);
                    }

                    // Levitation
                    if (!m_connectedBody && IsLevitating(Target))
                    {
                        Rigidbody rgbd = Target.GetComponent <Rigidbody>();
                        rgbd.velocity = Vector3.ClampMagnitude(rgbd.velocity, .1f);
                    }
                }

                // Apply various forces
                if (m_connectedBody)
                {
                    Vector3 targetVel = (transform.position - Target.transform.position).normalized * m_forceScale;
                    targetVel += distanceScale * m_lastForceApplied * GetDistanceToTarget();

                    m_connectedBody.rotation = Quaternion.RotateTowards(m_connectedBody.rotation, transform.rotation * Quaternion.Euler(Target.m_upwardRotation), Time.deltaTime * (1 - distanceScale) * 500);
                    m_connectedBody.velocity = Vector3.MoveTowards(m_connectedBody.velocity, targetVel * (Mathf.Sqrt(GetDistanceToTarget()) * m_distanceSpeedScale), Time.deltaTime * (20 + (1 - distanceScale) * 10));

                    m_inputManager.Haptic((1 - distanceScale) / 10);

                    AkSoundEngine.SetRTPCValue("Grab_Distance", GetDistanceToTarget());
                }
            }

            // Update force
            m_lastPos = m_repere.position;
        }
    }
Beispiel #25
0
 protected abstract void OnWorkshopUpdateState(bool state, MTK_Interactable current);
Beispiel #26
0
 public void UnSubscribe(MTK_Interactable input)
 {
     m_grabbableesList.Remove(input);
 }
Beispiel #27
0
 public void Subscribe(MTK_Interactable input)
 {
     m_grabbableesList.Add(input);
 }