Exemplo n.º 1
0
    void Update()
    {
        lodDrawer0.listPositionData.Clear();
        lodDrawer1.listPositionData.Clear();
        lodDrawer2.listPositionData.Clear();
        lodDrawer3.listPositionData.Clear();

        lodDrawer0.listRotationData.Clear();
        lodDrawer1.listRotationData.Clear();
        lodDrawer2.listRotationData.Clear();
        lodDrawer3.listRotationData.Clear();

        lodDrawer0.listTexturePositionData.Clear();
        lodDrawer1.listTexturePositionData.Clear();
        lodDrawer2.listTexturePositionData.Clear();
        lodDrawer3.listTexturePositionData.Clear();

        Vector3 CameraPosition = Camera.main.transform.position;;

        deltaTime += Time.deltaTime;
        for (int i = 0; i < formationList.Count; ++i)
        {
            Formation formation = formationList[i];
            float     distance  = math.length(CameraPosition - formation.transform.position);
            Debug.Log("Dis: " + distance);
            for (int j = 0; j < formation.Count(); j++)
            {
                Vector3 center = formation.transform.position;
                Vector3 v3     = new Vector3(center.x + j % formation.width, 1, center.z + j / formation.width);
                V4      v4     = new V4(v3.x, v3.y, v3.z, 1);

                AnimationClipDataBaked clip = animationClipData[(int)0 * 25 + AnimationName.Attack1];
                normalizedTime = normalizedTimeStart + deltaTime / clip.AnimationLength;
                normalizedTime = normalizedTime % 1.0f;

                float texturePosition = normalizedTime * clip.TextureRange + clip.TextureOffset;
                int   lowerPixelInt   = (int)math.floor(texturePosition * clip.TextureWidth);

                float   lowerPixelCenter    = (lowerPixelInt * 1.0f) / clip.TextureWidth;
                float   upperPixelCenter    = lowerPixelCenter + clip.OnePixelOffset;
                float   lerpFactor          = (texturePosition - lowerPixelCenter) / clip.OnePixelOffset;
                Vector3 texturePositionData = new Vector3(lowerPixelCenter, upperPixelCenter, lerpFactor);

                if (distance < bakedData.lods.Lod1Distance)
                {
                    lodDrawer0.listPositionData.Add(v4);
                    lodDrawer0.listRotationData.Add(Quaternion.LookRotation(new Vector3(0, UnityEngine.Random.Range(1, 50), 0), new Vector3(0.0f, 1, 0.0f)));
                    lodDrawer0.listTexturePositionData.Add(texturePositionData);
                }
                else if (distance < bakedData.lods.Lod2Distance)
                {
                    lodDrawer1.listPositionData.Add(v4);
                    lodDrawer1.listRotationData.Add(Quaternion.LookRotation(new Vector3(0, UnityEngine.Random.Range(1, 50), 0), new Vector3(0.0f, 1, 0.0f)));
                    lodDrawer1.listTexturePositionData.Add(texturePositionData);
                }
                else if (distance < bakedData.lods.Lod3Distance)
                {
                    lodDrawer2.listPositionData.Add(v4);
                    lodDrawer2.listRotationData.Add(Quaternion.LookRotation(new Vector3(0, UnityEngine.Random.Range(1, 50), 0), new Vector3(0.0f, 1, 0.0f)));
                    lodDrawer2.listTexturePositionData.Add(texturePositionData);
                }
                else
                {
                    lodDrawer3.listPositionData.Add(v4);
                    lodDrawer3.listRotationData.Add(Quaternion.LookRotation(new Vector3(0, UnityEngine.Random.Range(1, 50), 0), new Vector3(0.0f, 1, 0.0f)));
                    lodDrawer3.listTexturePositionData.Add(texturePositionData);
                }
            }
        }


        //for (int i = 0; i < formationList.Count * formationList[0].Count(); i++)
        //{

        //    lodDrawer0.listTexturePositionData.Add(texturePositionData);
        //    lodDrawer1.listTexturePositionData.Add(texturePositionData);
        //    lodDrawer2.listTexturePositionData.Add(texturePositionData);
        //    lodDrawer3.listTexturePositionData.Add(texturePositionData);
        //}

        lodDrawer0.Draw();
        lodDrawer1.Draw();
        lodDrawer2.Draw();
        lodDrawer3.Draw();
    }