protected void UpdateAnimations() { //Update particle frame progress for (int i = 0; i < _instanceData.Length; i++) { if (_instanceData[i]._active) { //Progress current animation GPUAnimations.GPUAnimations.Animation animation = GetAnimation(_instanceData[i]._animationIndex); //Update current frame float prevFrame = _instanceData[i]._currentFrame; _instanceData[i]._currentFrame += Time.deltaTime * animation._fps * _instanceData[i]._animationSpeed; //Check for events GPUAnimations.GPUAnimations.CheckForEvents(_instanceData[i]._gameObject, animation, prevFrame, _instanceData[i]._currentFrame); //Is animation finished? if (Mathf.FloorToInt(_instanceData[i]._currentFrame - animation._startFrameOffset) >= animation._totalFrames - 1) { AnimationData newAnimationData = PickRandomAnimation(); animation = GetAnimation(newAnimationData._animationIndex); _instanceData[i]._animationIndex = newAnimationData._animationIndex; _instanceData[i]._currentFrame = animation._startFrameOffset; _instanceData[i]._animationSpeed = newAnimationData._speedRange.GetRandomValue();; } } } }
private Vector4 StartNewAnimation(Vector4 oldData, bool randomOffset) { Vector4 data; ParticleAnimation anim = PickRandomAnimation(); GPUAnimations.GPUAnimations.Animation animation = GetAnimation(anim._animationIndex); data.x = anim._animationIndex; data.y = randomOffset ? Random.Range(0, animation._totalFrames - 2) : 0; data.z = anim._speedRange.GetRandomValue(); data.w = 1.0f; return(data); }
protected override void UpdateProperties() { #if UNITY_EDITOR for (int i = 0; i < _materials.Length; i++) { _animationTexture.SetMaterialProperties(_materials[i]); } #endif //Update property block for (int i = 0; i < GetNumRenderedParticles(); i++) { int index = GetRenderedParticlesIndex(i); GPUAnimations.GPUAnimations.Animation animation = GetAnimation(Mathf.RoundToInt(_particleCustomData[index].x)); _particleCurrentFrame[i] = animation._startFrameOffset + _particleCustomData[index].y; } //Update property block _propertyBlock.SetFloatArray("frameIndex", _particleCurrentFrame); }
public GameObject SpawnObject(Vector3 position, Quaternion rotation, Vector3 scale) { for (int i = 0; i < _instanceData.Length; i++) { if (!_instanceData[i]._active) { if (_instanceData[i]._gameObject == null) { _instanceData[i]._gameObject = Instantiate(_clone, this.transform); _instanceData[i]._gameObject.transform.position = position; _instanceData[i]._gameObject.transform.rotation = rotation; _instanceData[i]._gameObject.transform.localScale = scale; _instanceData[i]._gameObject.SetActive(true); _instanceData[i]._skinnedMeshes = _instanceData[i]._gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); for (int j = 0; j < _instanceData[i]._skinnedMeshes.Length; j++) { _instanceData[i]._skinnedMeshes[j].enabled = false; } _instanceData[i]._transform = _instanceData[i]._skinnedMeshes[0].transform; } _instanceData[i]._active = true; AnimationData animation = PickRandomAnimation(); GPUAnimations.GPUAnimations.Animation textureAnim = GetAnimation(animation._animationIndex); _instanceData[i]._animationIndex = animation._animationIndex; _instanceData[i]._currentFrame = Random.Range(0, textureAnim._totalFrames - 2); _instanceData[i]._animationSpeed = animation._speedRange.GetRandomValue(); OnSpawnObject(ref _instanceData[i]); return(_instanceData[i]._gameObject); } } return(null); }
private void UpdateAnimations() { int numParticles = _particleSystem.GetCustomParticleData(_particleCustomData, _customDataChannel); //Update particle frame progress for (int i = 0; i < numParticles; i++) { Vector4 customData = _particleCustomData[i]; float prevFrame = customData.y; //New particle if (customData.w == 0.0f) { _particleCustomData[i] = StartNewAnimation(customData, true); } //Progress current animation else { GPUAnimations.GPUAnimations.Animation animation = GetAnimation(Mathf.RoundToInt(customData.x)); //Update current frame customData.y += Time.deltaTime * animation._fps * customData.z; //Is animation finished? if (Mathf.FloorToInt(customData.y) < animation._totalFrames - 2) { _particleCustomData[i] = customData; } else { _particleCustomData[i] = StartNewAnimation(customData, false); } } } //Update custom data _particleSystem.SetCustomParticleData(_particleCustomData, _customDataChannel); }
private GPUAnimations.GPUAnimations.Animation GetAnimation(int index) { GPUAnimations.GPUAnimations.Animation[] animations = _animationTexture.GetAnimations(); GPUAnimations.GPUAnimations.Animation animation = animations[Mathf.Clamp(index, 0, animations.Length)]; return(animation); }