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); }
private void InstantiatePerUnitTypeData(UnitType type) { var minionPrefab = Spawner.GetMinionPrefab(type); var renderingData = minionPrefab.GetComponentInChildren <RenderingDataWrapper>().Value; GameObject bakingObject = GameObject.Instantiate(renderingData.BakingPrefab); SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>(); Material material = renderingData.Material; LodData lodData = renderingData.LodData; var dataPerUnitType = new DataPerUnitType { UnitType = type, BakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), 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); GameObject.Destroy(bakingObject); }
private void initilize() { if (init) { return; } init = true; PreSetting setting = Resources.Load <PreSetting>("PreSetting"); var bakingObject = GameObject.Instantiate(setting.go) as GameObject; SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>(); LodData lodData = new LodData(); lodData.Lod1Mesh = setting.mesh0; lodData.Lod2Mesh = setting.mesh1; lodData.Lod3Mesh = setting.mesh2; lodData.Lod1Distance = 10; lodData.Lod2Distance = 20; lodData.Lod3Distance = 30; Material material = setting.material; //SkinnedMeshRenderer r = Combine.CombineIt(bakingObject.transform); bakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData); //bakedData = KeyframeTextureBaker.BakeClips(r, GetAllAnimationClips(r.GetComponentInParent<Animation>()), lodData); TransferAnimationData(); //UnityEngine.Object fGo = Resources.Load("Formation"); for (int i = 0; i < formationCount; i++) { Vector3 formationPosition = new Vector3(i % 5 * (width + 30), 1, i / 5 * (height + 20)); //GameObject instance = Object.Instantiate(fGo) as GameObject; //instance.name = "Formation_" + i; //Formation form = instance.GetComponent<Formation>(); //form.Init(width, height); //instance.transform.position = formationPosition; FormationData data = new FormationData(); data.width = width; data.height = height; data.formationPosition = formationPosition; formationList.Add(data); } lodDrawer0 = new LodedDrawerECS(bakedData.NewMesh, material, bakedData); lodDrawer1 = new LodedDrawerECS(bakedData.lods.Lod1Mesh, material, bakedData); lodDrawer2 = new LodedDrawerECS(bakedData.lods.Lod2Mesh, material, bakedData); lodDrawer3 = new LodedDrawerECS(bakedData.lods.Lod3Mesh, material, bakedData); }
void Start() { var bakingObject = GameObject.Instantiate(go); SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>(); lodData = new LodData(); lodData.Lod1Mesh = mesh0; lodData.Lod2Mesh = mesh1; lodData.Lod3Mesh = mesh2; lodData.Lod1Distance = 10; lodData.Lod2Distance = 20; lodData.Lod3Distance = 30; bakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), lodData); TransferAnimationData(); UnityEngine.Object fGo = Resources.Load("Formation"); for (int i = 0; i < formationCount; i++) { int width = 12; int height = 6; Vector3 formationPosition = new Vector3(i % 5 * (width + 5), 1, i / 5 * (height + 4)); GameObject instance = Instantiate(fGo) as GameObject; instance.name = "Formation_" + i; Formation form = instance.GetComponent <Formation>(); form.Init(width, height); instance.transform.position = formationPosition; formationList.Add(form); } //SaveTextureToFile(bakedData.Texture0, "tp1.png"); //SaveTextureToFile(bakedData.Texture1, "tp2.png"); //SaveTextureToFile(bakedData.Texture2, "tp3.png"); lodDrawer0 = new LodedDrawer(bakedData.NewMesh, material, bakedData, animationClipData, formationList); lodDrawer1 = new LodedDrawer(bakedData.lods.Lod1Mesh, material, bakedData, animationClipData, formationList); lodDrawer2 = new LodedDrawer(bakedData.lods.Lod2Mesh, material, bakedData, animationClipData, formationList); lodDrawer3 = new LodedDrawer(bakedData.lods.Lod3Mesh, material, bakedData, animationClipData, formationList); }
private void InstantiatePerUnitTypeData(UnitType type) { var minionPrefab = Spawner.GetMinionPrefab(type); var renderingData = minionPrefab.GetComponentInChildren <RenderingDataWrapper>().Value; var bakingObject = GameObject.Instantiate(renderingData.BakingPrefab); SkinnedMeshRenderer renderer = bakingObject.GetComponentInChildren <SkinnedMeshRenderer>(); Material material = renderingData.Material; LodData lodData = renderingData.LodData; var dataPerUnitType = new DataPerUnitType { UnitType = type, BakedData = KeyframeTextureBaker.BakeClips(renderer, GetAllAnimationClips(renderer.GetComponentInParent <Animation>()), 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); #if !USE_SAFE_JOBS dataPerUnitType.BufferPointers = new NativeArray <IntPtr>(12, Allocator.Persistent); dataPerUnitType.BufferPointers[0] = dataPerUnitType.Drawer.BufferPointers[0]; dataPerUnitType.BufferPointers[1] = dataPerUnitType.Drawer.BufferPointers[1]; dataPerUnitType.BufferPointers[2] = dataPerUnitType.Drawer.BufferPointers[2]; dataPerUnitType.BufferPointers[3] = dataPerUnitType.Lod1Drawer.BufferPointers[0]; dataPerUnitType.BufferPointers[4] = dataPerUnitType.Lod1Drawer.BufferPointers[1]; dataPerUnitType.BufferPointers[5] = dataPerUnitType.Lod1Drawer.BufferPointers[2]; dataPerUnitType.BufferPointers[6] = dataPerUnitType.Lod2Drawer.BufferPointers[0]; dataPerUnitType.BufferPointers[7] = dataPerUnitType.Lod2Drawer.BufferPointers[1]; dataPerUnitType.BufferPointers[8] = dataPerUnitType.Lod2Drawer.BufferPointers[2]; dataPerUnitType.BufferPointers[9] = dataPerUnitType.Lod3Drawer.BufferPointers[0]; dataPerUnitType.BufferPointers[10] = dataPerUnitType.Lod3Drawer.BufferPointers[1]; dataPerUnitType.BufferPointers[11] = dataPerUnitType.Lod3Drawer.BufferPointers[2]; #endif perUnitTypeDataHolder.Add(type, dataPerUnitType); TransferAnimationData(type); GameObject.Destroy(bakingObject); }