Esempio n. 1
0
        private void InstantiatePerUnitTypeData(UnitType type)
        {
            var gameObject               = type == UnitType.Melee? UnitViewSettings.Instance.MeleePrefab: UnitViewSettings.Instance.SkeletonPrefab;
            var renderingData            = gameObject.GetComponentInChildren <RenderingDataWrapper>().Value;
            SkinnedMeshRenderer renderer = renderingData.SkinnedMeshRenderer;
            Material            material = renderingData.Material;
            LodData             lodData  = renderingData.LodData;

            var animationComponent = gameObject.GetComponent <Animation>();

            var dataPerUnitType = new Data.DataPerUnitType
            {
                BakedData = KeyframeTextureBaker.BakeClips(renderer, animationComponent, lodData),
                Material  = material,
            };

            dataPerUnitType.Drawer     = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.NewMesh);
            dataPerUnitType.Lod1Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.Lods.Lod1Mesh);
            dataPerUnitType.Lod2Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.Lods.Lod2Mesh);
            dataPerUnitType.Lod3Drawer = new InstancedSkinningDrawer(dataPerUnitType, dataPerUnitType.BakedData.Lods.Lod3Mesh);


            _perUnitTypeDataHolder.Add(type, dataPerUnitType);
            // TransferAnimationData(type);
        }
Esempio n. 2
0
        public InstancedSkinningDrawer(DataPerUnitType data, Mesh meshToDraw)
        {
            _data     = data;
            _mesh     = meshToDraw;
            _material = new Material(data.Material);

            _argsBuffer      = new ComputeBuffer(1, _indirectArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
            _indirectArgs[0] = _mesh.GetIndexCount(0);
            _indirectArgs[1] = (uint)0;
            _argsBuffer.SetData(_indirectArgs);

            _objectRotationsBuffer    = new ComputeBuffer(PreallocatedBufferSize, 16);
            _objectPositionsBuffer    = new ComputeBuffer(PreallocatedBufferSize, 16);
            _textureCoordinatesBuffer = new ComputeBuffer(PreallocatedBufferSize, 12);


            TextureCoordinates = new NativeList <float3>(PreallocatedBufferSize, Allocator.Persistent);
            ObjectPositions    = new NativeList <float4>(PreallocatedBufferSize, Allocator.Persistent);
            ObjectRotations    = new NativeList <quaternion>(PreallocatedBufferSize, Allocator.Persistent);


            _material.SetBuffer("textureCoordinatesBuffer", _textureCoordinatesBuffer);
            _material.SetBuffer("objectPositionsBuffer", _objectPositionsBuffer);
            _material.SetBuffer("objectRotationsBuffer", _objectRotationsBuffer);
            _material.SetTexture("_AnimationTexture0", data.BakedData.Texture0);
            _material.SetTexture("_AnimationTexture1", data.BakedData.Texture1);
            _material.SetTexture("_AnimationTexture2", data.BakedData.Texture2);
        }