internal float CalcGroupWeight(int startIdx, int length, float totalWeight, bool weightPassNext, int layer) { if (totalWeight <= 0f) { for (int gi = startIdx; gi < startIdx + length; gi++) { attachStateComponent[gi].weight = 0f; } return(0f); } float layerTotalWeight = 0f; for (int gi = startIdx; gi < startIdx + length; gi++) { SpriteTransform.StateComponentPair pair = attachStateComponent[gi]; if (pair.state.blendMode == AnimationBlendMode.Blend) { float w = pair.state.weight * pair.state.componentEnable[1 + pair.component.index]; layerTotalWeight += w; } else { pair.weight = pair.state.weight; } } float layerWeight = layerTotalWeight >= 1f ? totalWeight : (weightPassNext ? layerTotalWeight : totalWeight); if (layerTotalWeight > 0f) { float iw = 1f / layerTotalWeight; for (int gi = startIdx; gi < startIdx + length; gi++) { SpriteTransform.StateComponentPair pair = attachStateComponent[gi]; pair.weight = pair.state.weight * iw * layerWeight * pair.state.componentEnable[1 + pair.component.index]; } } else { for (int gi = startIdx; gi < startIdx + length; gi++) { SpriteTransform.StateComponentPair pair = attachStateComponent[gi]; if (pair.state.blendMode == AnimationBlendMode.Blend) { pair.weight = 0f; } } } return(totalWeight - layerWeight); }
internal void AttachState(SpriteAnimationState state, SpriteAnimationComponent component) { SpriteTransform.StateComponentPair pair = new SpriteTransform.StateComponentPair(); pair.state = state; pair.component = component; pair.applyTo = this; attachStateComponent.Add(pair); state.referenceList.Add(pair); Refresh(); }
internal void EvaluateTransform(SpriteTransform sprTransform) { sprTransform.ZeroTransform(); for (int idx = 0; idx < sprTransform.attachStateComponent.Count; idx++) { SpriteTransform.StateComponentPair pair = sprTransform.attachStateComponent[idx]; SpriteAnimationKeyFrame kf = null; if (pair.state.blendMode == AnimationBlendMode.Additive) { //reset buffer transformPropertys[1] = transformPropertys[2] = transformPropertys[3] = 0f; transformPropertys[4] = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 0f; transformPropertys[10] = transformPropertys[11] = 0f; kf = pair.component.EvaluateAddtive(pair.state.lastEvaluateTime, sprTransform, transformPropertys); } else { //reset buffer transformPropertys[1] = transformPropertys[2] = transformPropertys[3] = 0f; transformPropertys[4] = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 1f; transformPropertys[10] = transformPropertys[11] = 0f; kf = pair.component.EvaluateBlending(pair.state.lastEvaluateTime, sprTransform, transformPropertys); } if (pair.lastRefClip != kf.refClip) { if (pair.lastRefClip != null) { string name = pair.state.name + "_" + pair.component.fullPath + "_" + pair.lastRefClip.name; SpriteAnimationState state = this[name]; if (state != null) { Stop(state); } pair.lastRefClip = null; } if (kf.refClip != null) { string name = pair.state.name + "_" + pair.component.fullPath + "_" + kf.refClip.name; if (!animationStates.ContainsKey(name)) { AddClip(kf.refClip, name); SpriteAnimationState state = this[name]; state.parentState = pair.state; state.parentTransform = pair.applyTo; state.parentComponentLayer = (int)pair.component.layer; state.removeAfterStop = true; state.layer = pair.state.layer; state.weight = pair.state.weight; state.lastTime = 0f; state.lastFrameIndex = -1; state.lastEvaluateTime = 0; pair.lastRefClip = kf.refClip; state.parentState.subClipState.Add(state); state.enabled = true; } } } float weight = pair.weight; { sprTransform.position.x += transformPropertys[1] * weight; sprTransform.position.y += transformPropertys[2] * weight; sprTransform.rotation += transformPropertys[3] * weight; sprTransform.scale.x += transformPropertys[4] * weight; sprTransform.scale.y += transformPropertys[5] * weight; sprTransform.color.r += transformPropertys[6] * weight; sprTransform.color.g += transformPropertys[7] * weight; sprTransform.color.b += transformPropertys[8] * weight; sprTransform.color.a += transformPropertys[9] * weight; sprTransform.shear.x += transformPropertys[10] * weight; sprTransform.shear.y += transformPropertys[11] * weight; } } }