コード例 #1
0
    // Use this for initialization
    void Start()
    {
        //QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;

        //Make sure that the editor's updater won't run at runtime
        //WaterPlusScriptEditor editorScript = gameObject.GetComponent<WaterPlusScriptEditor>();
        //if (editorScript)
        //	Destroy(editorScript);

        //yAnimationValue = 0.0f;
        //initialTransformY = transform.position.y - tideAmplitude;

        //Debug.Log("Increasing Y-Axis");

        waterCenter = GetComponent <Renderer>().bounds.center;

        if (movementType == WaterMovementType.directional)
        {
            speed = velocity.magnitude;
        }

        //Convert to tiles/second from world_units/second
        float tileWidth = GetComponent <Renderer>().bounds.size.x / gameObject.GetComponent <Renderer>().material.GetTextureScale("_MainTex").x;

        speed = speed / tileWidth;

        waterMaterial = GetComponent <Renderer>().material;

        //Pro only
//		if (Camera.main)
//				Camera.main.depthTextureMode |= DepthTextureMode.Depth;

        /*if (waterQualityLevel == WaterQualityLevel.automatic) {
         *      if (isTargetingMobile)
         *              waterQualityLevel = WaterQualityLevel.simple;
         *      else
         *              waterQualityLevel = WaterQualityLevel.beautiful;
         * }*/


        Shader.DisableKeyword("WATER_EDGEBLEND_OFF");   Shader.EnableKeyword("WATER_EDGEBLEND_ON");

        if (movementType == WaterMovementType.flowmap)
        {
            Shader.DisableKeyword("FLOWMAP_ANIMATION_OFF"); Shader.EnableKeyword("FLOWMAP_ANIMATION_ON");
            //speed *= 10.0f;	//Account for flowmap strength
            FlowmapAnimator fmAnimatior = gameObject.AddComponent <FlowmapAnimator>();
            fmAnimatior.flowSpeed = speed;
        }
        else
        {
            Shader.DisableKeyword("FLOWMAP_ANIMATION_ON");  Shader.EnableKeyword("FLOWMAP_ANIMATION_OFF");
        }

        Light dirLight = FindTheBrightestDirectionalLight();

        /*if (dirLight != null) {
         *      Vector3 anisoLightPos = dirLight.transform.position;
         *
         *      renderer.material.SetVector("anisoLightPos", new Vector4(anisoLightPos.x, anisoLightPos.y, anisoLightPos.z, 0.0f) );
         * }*/

        projectedLightDir = dirLight.transform.forward - transform.up * Vector3.Dot(transform.up, dirLight.transform.forward);
        projectedLightDir.Normalize();

        anisoDirAnimationOffset = Vector2.zero;

        causticsAnimationFrame = 0;

        //Load normalmaps animation?
        if (animatedNormalmaps)
        {
            normalmapAnimation = new Texture2D[60];
            dudvfoamAnimation  = new Texture2D[60];

            for (int i = 0; i < 60; i++)
            {
                //string texName = "water_hm";
                string texName = "";                //"water_normal_";

                if (i < 10)
                {
                    texName = "0";
                }

//				if (i < 100)
//					texName = texName + "0";

                texName = texName + i;

                //normalmapAnimation[i] = Resources.Load("water_normal_" + texName, typeof(Texture2D) ) as Texture2D;
                normalmapAnimation[i] = Resources.Load("water_hm" + texName, typeof(Texture2D)) as Texture2D;
                dudvfoamAnimation[i]  = Resources.Load("dudv_foam" + texName, typeof(Texture2D)) as Texture2D;

                if (null == normalmapAnimation[i])
                {
                    Debug.LogError("unable to find normalmap animation file 'water_normal_" + texName + "'. Aborting.");
                    animatedNormalmaps = false;
                    break;
                }

                if (null == dudvfoamAnimation[i])
                {
                    Debug.LogError("unable to find dudv animation file 'dudv_foam" + texName + "'. Aborting.");
                    animatedNormalmaps = false;
                    break;
                }
            }

            normalmapAnimationFrame = 0;
        }
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        //QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable;

        //Make sure that the editor's updater won't run at runtime
        //WaterPlusScriptEditor editorScript = gameObject.GetComponent<WaterPlusScriptEditor>();
        //if (editorScript)
        //	Destroy(editorScript);

        //yAnimationValue = 0.0f;
        //initialTransformY = transform.position.y - tideAmplitude;

        waterCenter = GetComponent <Renderer>().bounds.center;

        if (movementType == WaterMovementType.directional)
        {
            speed = velocity.magnitude;
        }

        //Convert to tiles/second from world_units/second
        float tileWidth = GetComponent <Renderer>().bounds.size.x / gameObject.GetComponent <Renderer>().material.GetTextureScale("_MainTex").x;

        speed = speed / tileWidth;

        waterMaterial = GetComponent <Renderer>().material;

        //Pro only
//		if (Camera.main)
//				Camera.main.depthTextureMode |= DepthTextureMode.Depth;

        /*if (waterQualityLevel == WaterQualityLevel.automatic) {
         *      if (isTargetingMobile)
         *              waterQualityLevel = WaterQualityLevel.simple;
         *      else
         *              waterQualityLevel = WaterQualityLevel.beautiful;
         * }*/


        Shader.DisableKeyword("WATER_EDGEBLEND_OFF");   Shader.EnableKeyword("WATER_EDGEBLEND_ON");

        if (movementType == WaterMovementType.flowmap)
        {
            Shader.DisableKeyword("FLOWMAP_ANIMATION_OFF"); Shader.EnableKeyword("FLOWMAP_ANIMATION_ON");
            //speed *= 10.0f;	//Account for flowmap strength
            FlowmapAnimator fmAnimatior = gameObject.AddComponent <FlowmapAnimator>();
            fmAnimatior.flowSpeed = speed;
        }
        else
        {
            Shader.DisableKeyword("FLOWMAP_ANIMATION_ON");  Shader.EnableKeyword("FLOWMAP_ANIMATION_OFF");
        }

        Light dirLight = FindTheBrightestDirectionalLight();

        /*if (dirLight != null) {
         *      Vector3 anisoLightPos = dirLight.transform.position;
         *
         *      renderer.material.SetVector("anisoLightPos", new Vector4(anisoLightPos.x, anisoLightPos.y, anisoLightPos.z, 0.0f) );
         * }*/

        projectedLightDir = dirLight.transform.forward - transform.up * Vector3.Dot(transform.up, dirLight.transform.forward);
        projectedLightDir.Normalize();

        anisoDirAnimationOffset = Vector2.zero;
    }