public void startActionAnimationInAChunk(String id, int duration, int chunk, float remainingDistance = -1.0f) { ChunkAnimation animation = new ChunkAnimation(id, duration); uint row = chunkTilesPos [chunk] [1].First; uint col = chunkTilesPos [chunk] [1].Second; float worldPositionX = getTileWorldPositionX(row, col); float worldPositionY = getTileWorldPositionY(row, col); uint rowEnd = chunkTilesPos [chunk] [7].First; uint colEnd = chunkTilesPos [chunk] [7].Second; float worldPositionXEnd = getTileWorldPositionX(rowEnd, colEnd); float worldPositionYEnd = getTileWorldPositionY(rowEnd, colEnd); Vector3 worldPosition = new Vector3(worldPositionX, worldPositionY, ANIMATION_Z_LAYER); Vector3 worldPositionEnd = new Vector3(worldPositionXEnd, worldPositionYEnd, ANIMATION_Z_LAYER); Vector3 dir = worldPositionEnd - worldPosition; float distance = dir.magnitude; dir.Normalize(); animation.setPosition(worldPosition); animation.setDirection(dir); animation.calculateSpeed(distance); animation.setRemainingDistance((remainingDistance < 0) ? distance : remainingDistance); AnimationManager.GetInstance().addChunkAnimation(chunk, animation); }
public void removeChunkAnimation(int chunk) { if (_currentActionAnimation.ContainsKey(chunk)) { ChunkAnimation animation = _currentActionAnimation [chunk]; GameObject.Destroy(animation.instance); _currentActionAnimation.Remove(chunk); } }
// Use this for initialization void Start() { if (m_ShareAnimation == null) { // m_ShareAnimation = GetComponent<TransformAnimation>(); m_ShareAnimation = GetComponent <ChunkAnimation>(); } m_ShareAnimation.DoBeenHit += Handler_DoBeenHit; }
public void save(ActionManagerData actionManagerData) { foreach (ChunkAction chunkAction in _actionInProgress) { float remainingDistance = 0.0f; if (chunkAction.hasAnimation()) { ChunkAnimation animation = AnimationManager.GetInstance().getCurrentAnimationInAChunk(chunkAction.chunk); remainingDistance = animation.remainingDistance; } actionManagerData.ActionsInProgress.Add(new ActionInProgressData(chunkAction.id, chunkAction.hoursElapsed, chunkAction.chunk, remainingDistance)); } }
private void OnEnable() { // init native containers blocks = new NativeArray <BlockType>(FixedChunkSizeXZ * ChunkSizeY * FixedChunkSizeXZ, Allocator.Persistent); lightingData = new NativeArray <int>(FixedChunkSizeXZ * ChunkSizeY * FixedChunkSizeXZ, Allocator.Persistent); biomeTypes = new NativeArray <BiomeType>(FixedChunkSizeXZ * FixedChunkSizeXZ, Allocator.Persistent); blockParameters = new NativeHashMap <BlockParameter, short>(2048, Allocator.Persistent); blockVerticles = new NativeList <float3>(16384, Allocator.Persistent); blockTriangles = new NativeList <int>(32768, Allocator.Persistent); blockUVs = new NativeList <float2>(16384, Allocator.Persistent); liquidVerticles = new NativeList <float3>(8192, Allocator.Persistent); liquidTriangles = new NativeList <int>(16384, Allocator.Persistent); liquidUVs = new NativeList <float2>(8192, Allocator.Persistent); plantsVerticles = new NativeList <float3>(4096, Allocator.Persistent); plantsTriangles = new NativeList <int>(8192, Allocator.Persistent); plantsUVs = new NativeList <float2>(4096, Allocator.Persistent); chunkDissapearingAnimation = GetComponent <ChunkDissapearingAnimation>(); chunkAnimation = GetComponent <ChunkAnimation>(); World.TimeToBuild += BuildBlocks; StartCoroutine(CheckNeighbours()); if (biomeColorsTexture == null) { biomeColorsTexture = new Texture2D(FixedChunkSizeXZ, FixedChunkSizeXZ, TextureFormat.RGB24, true); biomeColorsTexture.filterMode = FilterMode.Bilinear; biomeColorsTexture.wrapMode = TextureWrapMode.Clamp; biomeColorsTexture.Apply(); } lightingBuffer = new ComputeBuffer(FixedChunkSizeXZ * ChunkSizeY * FixedChunkSizeXZ, sizeof(int), ComputeBufferType.Default); var mr = blockMeshFilter.GetComponent <MeshRenderer>(); mr.material.SetBuffer("lightData", lightingBuffer); }
public void Init() { if (!blocks.IsCreated) { // init native containers blocks = new NativeArray <BlockType>(FixedChunkSizeXZ * ChunkSizeY * FixedChunkSizeXZ, Allocator.Persistent); lightingData = new NativeArray <int>(FixedChunkSizeXZ * ChunkSizeY * FixedChunkSizeXZ, Allocator.Persistent); biomeTypes = new NativeArray <BiomeType>(FixedChunkSizeXZ * FixedChunkSizeXZ, Allocator.Persistent); blockParameters = new NativeHashMap <BlockParameter, short>(2048, Allocator.Persistent); blockVerticles = new NativeList <float3>(16384, Allocator.Persistent); blockTriangles = new NativeList <int>(32768, Allocator.Persistent); blockUVs = new NativeList <float2>(16384, Allocator.Persistent); liquidVerticles = new NativeList <float3>(8192, Allocator.Persistent); liquidTriangles = new NativeList <int>(16384, Allocator.Persistent); liquidUVs = new NativeList <float2>(8192, Allocator.Persistent); plantsVerticles = new NativeList <float3>(4096, Allocator.Persistent); plantsTriangles = new NativeList <int>(8192, Allocator.Persistent); plantsUVs = new NativeList <float2>(4096, Allocator.Persistent); chunkDissapearingAnimation = GetComponent <ChunkDissapearingAnimation>(); chunkAnimation = GetComponent <ChunkAnimation>(); } if (lightingBuffer == null || !lightingBuffer.IsValid()) { lightingBuffer = new ComputeBuffer(FixedChunkSizeXZ * ChunkSizeY * FixedChunkSizeXZ, sizeof(int), ComputeBufferType.Default); var mr = blockMeshFilter.GetComponent <MeshRenderer>(); mr.material.SetBuffer("lightData", lightingBuffer); } World.TimeToBuild += BuildBlocks; StartCoroutine(CheckNeighbours()); }
public void addChunkAnimation(int chunk, ChunkAnimation animation) { _currentActionAnimation.Add(chunk, animation); }
// Use this for initialization void Start() { if (m_ShareAnimation == null) { // m_ShareAnimation = GetComponent<TransformAnimation>(); m_ShareAnimation = GetComponent<ChunkAnimation>(); } m_ShareAnimation.DoBeenHit += Handler_DoBeenHit ; }