Exemplo n.º 1
0
    IEnumerator AnimatePlanet(IcoPlanet icoplanet, float targetShadowAmount, float targetLuminosity)
    {
        List <Material> materials     = new List <Material>();
        Material        waterMaterial = icoplanet.transform.GetChild(0).GetComponent <MeshRenderer>().material;

        foreach (Transform tr in icoplanet.transform)
        {
            materials.Add(tr.GetComponent <MeshRenderer>().material);
        }

        materials.RemoveAt(0);

        float baseShadowAmount = materials[0].GetFloat("_PlanetColorShadowAmount"),
              baseLuminosity   = waterMaterial.GetFloat("_Luminosity");

        float currentLuminosity;

        for (float t = 0; t < 1; t += Time.deltaTime)
        {
            currentLuminosity = Mathf.LerpUnclamped(baseShadowAmount, targetShadowAmount, m_planetShineAnimCurve.Evaluate(t));

            foreach (Material mat in materials)
            {
                mat.SetFloat("_PlanetColorShadowAmount", currentLuminosity);
            }

            waterMaterial.SetFloat("_Luminosity", Mathf.Lerp(baseLuminosity, targetLuminosity, m_planetShineAnimCurve.Evaluate(t)));

            yield return(new WaitForEndOfFrame());
        }
    }
Exemplo n.º 2
0
    public void Colonize(IcoPlanet planet)
    {
        m_icoPlanet = planet;
        if (!m_icoPlanet)
        {
            print("Failed to colonize space");
            return;
        }

        FindObjectOfType <LightingManager>().DeActivateControl();

        AkSoundEngine.PostEvent("Play_Amb_TP", gameObject);

        m_colonized = true;

        m_room.SetActive(false);

        CleanupPlanet(m_icoPlanet);

        m_icoPlanet.heightDelta      /= 4;
        m_icoPlanet.nbLevels         *= 4;
        m_icoPlanet.m_segmentMaterial = m_newSegmentMaterial;
        m_icoPlanet.SetTesselationLevel(3, 4);
        m_icoPlanet.transform.localScale = new Vector3(m_planetScale, m_planetScale, m_planetScale);

        m_manager.transform.position = Vector3.zero;
        m_manager.transform.rotation = Quaternion.identity;
        m_setup.transform.position   = Vector3.zero;
        m_setup.transform.rotation   = Quaternion.identity;

        m_newRoom.SetActive(true);
    }
Exemplo n.º 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);
            }
        }
    }
Exemplo n.º 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);
        }
    }
Exemplo n.º 5
0
    public void CollectData()
    {
        //increase starting i if adding to existing system?
        int rockyAdded = 0;
        int gasyAdded  = 0;
        int count      = 0;

        for (int i = 0; i < CelestialObject.Objects.Count; i++)
        {
            CelestialObject co = CelestialObject.Objects[i];
            if (!co.staticBody)
            {
                physicsData[count] = new _celestialObject(co, count);
                IcoPlanet ip = co.GetComponentInChildren <IcoPlanet>();
                if (ip != null)
                {
                    planetList[rockyAdded] = new _planet(ip, count);
                    rockyAdded            += 1;
                }
                GasPlanetShaderMAterialPropertyBlock gp = co.GetComponentInChildren <GasPlanetShaderMAterialPropertyBlock>();
                if (gp != null)
                {
                    gasPlanetList[gasyAdded] = new _gasPlanet(gp, count);
                    gasyAdded += 1;
                }
                count += 1;
            }
        }
    }
    protected void Awake()
    {
        rigidbody     = transform.parent.GetComponent <Rigidbody>();
        m_icoPlanet   = transform.parent.GetComponent <IcoPlanet>();
        m_icoSegment  = GetComponent <IcoSegment>();
        m_parentJoint = GetComponentInParent <MTK_JointType_Fixed>();

        m_oldHeight = m_icoSegment.heightLevel;
    }
Exemplo n.º 7
0
    // 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);
        }
    }
Exemplo n.º 8
0
 public void SizeUpdate(float value)
 {
     value = Mathf.Log(value * 100) / 5;
     if (Gas && Planet)
     {
         value *= scaler /* * 0.5f*/;
         Planet.transform.localScale = new Vector3(value, value, value); //localscale adjusts diameter, to keep consistency with rocky icospheres we halve it to get a radius
     }
     else if (!Gas && Planet)
     {
         IcoPlanet ico = Planet.GetComponent <IcoPlanet>();
         ico.shapeSettings.radius = value / 2 * scaler;
         ico.UpdateMesh();
     }
 }
Exemplo n.º 9
0
    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;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
    void CleanupPlanet(IcoPlanet planet)
    {
        foreach (Transform child in planet.transform)
        {
            if (!child.GetComponent <IcoSegment>())
            {
                Destroy(child.gameObject);
            }
        }

        // Set transforms
        planet.GetComponent <Rigidbody>().isKinematic = true;

        planet.transform.parent   = transform;
        planet.transform.rotation = Quaternion.identity;
        planet.transform.position = Vector3.zero;

        foreach (IcoSegment segment in planet.Segments)
        {
            segment.transform.localScale = Vector3.one;
        }
        planet.transform.localScale = Vector3.one;


        // Destroy useless components
        Destroy(planet.GetComponent <MTK_Interactable>());
        Destroy(planet.GetComponent <MeshCollider>());
        Destroy(planet.GetComponent <Outline>());
        foreach (MTK_JointType joint in planet.GetComponents <MTK_JointType>())
        {
            Destroy(joint);
        }

        foreach (IcoSegment segment in planet.Segments)
        {
            segment.GetComponent <MeshCollider>().enabled = true;
            Destroy(segment.GetComponent <Outline>());
            Destroy(segment.GetComponent <MTK_Interactable>());
            foreach (MTK_JointType joint in segment.GetComponents <MTK_JointType>())
            {
                Destroy(joint);
            }
        }
    }
Exemplo n.º 11
0
    void UpdateTPZone(IcoPlanet planet, bool enter)
    {
        if (m_canTPPlanet)
        {
            if (planet)
            {
                if (enter)
                {
                    if (!m_planetList.Contains(planet))
                    {
                        m_planetList.Add(planet);
                    }
                }
                else
                {
                    m_planetList.Remove(planet);
                }
            }

            m_planetTPZone.Planet = lastPlanet;
        }
    }
Exemplo n.º 12
0
    void OnCollisionEnter(Collision collision)
    {
        float otherRadius = collision.gameObject.GetComponent <SphereCollider>().radius;
        float otherX      = collision.gameObject.transform.localScale.x;
        float thisX       = this.gameObject.transform.localScale.x;
        float thisRadius  = this.GetComponent <SphereCollider>().radius;

        if (otherRadius * otherX <= thisRadius * thisX / 2)
        {
            Vector3 testvar = collision.contacts[0].point - this.transform.localPosition;
            if (this.gameObject.tag != "GasPlanet")
            {
                IcoPlanet planet = this.GetComponent <IcoPlanet>();
                planet.MakeCrater(collision, otherRadius * otherX);
            }
        }
        else
        {
            if (!staticBody)
            {
                if (!hasExploded)
                {
                    if (this.transform.localScale.x >= 1)
                    {
                        explosionEffect = Resources.Load <GameObject>("Explosions/BigExplosionEffect");
                        ExplodeBig();
                    }
                    else
                    {
                        explosionEffect = Resources.Load <GameObject>("Explosions/SmallExplosionEffect");
                        ExplodeSmall();
                    }
                    hasExploded = true;
                }
            }
        }
    }