public ParameterAdjustor(string paramPath, ParamDataType type, ParamDeltaType delta, List <string> paramList, List <MusicState> stateList) { ParamPath = paramPath; ParamType = type; ParamDelta = delta; ParamList = paramList; StateList = stateList; activeStates = new HashSet <MusicState>(); foreach (MusicState state in StateList) { activeStates.Add(state); } paramFieldInfo = null; Validate(); }
public void Apply(ParticleSystem ps, MusicState state, int measureCount) { if (!hasConflict) { if (activeStates.Contains(state)) { if (paramFieldInfo == null) { paramFieldInfo = GetTargetProperty(ps, ParamPath, typeof(ParticleSystem)); } switch (ParamDelta) { case ParamDeltaType.Constant: { switch (ParamType) { case ParamDataType.Bool: bool bValue = ParamList[0].ToLower() == "true"; paramFieldInfo.SetValueForParent(bValue); break; case ParamDataType.Float: float fValue = float.Parse(ParamList[0]); paramFieldInfo.SetValueForParent(fValue); break; case ParamDataType.Integer: float iValue = int.Parse(ParamList[0]); paramFieldInfo.SetValueForParent(iValue); break; } break; } case ParamDeltaType.Linear: { switch (ParamType) { case ParamDataType.Float: float fStartValue = float.Parse(ParamList[0]); float fRate = float.Parse(ParamList[1]); float fValue = fStartValue + measureCount * fRate; paramFieldInfo.SetValueForParent(fValue); break; case ParamDataType.Integer: int iStartValue = int.Parse(ParamList[0]); float iRate = float.Parse(ParamList[1]); int iValue = (int)(iStartValue + measureCount * iRate); paramFieldInfo.SetValueForParent(iValue); break; } break; } case ParamDeltaType.LinearCapped: { switch (ParamType) { case ParamDataType.Float: float fStartValue = float.Parse(ParamList[0]); float fRate = float.Parse(ParamList[1]); float fEndValue = float.Parse(ParamList[2]); float fPotentialValue = fStartValue + measureCount * fRate; //Debug.Log(fPotentialValue); float fValue = fRate >= 0 ? Mathf.Min(fEndValue, fPotentialValue) : Mathf.Max(fEndValue, fPotentialValue); paramFieldInfo.SetValueForParent(fValue); break; case ParamDataType.Integer: int iStartValue = int.Parse(ParamList[0]); float iRate = float.Parse(ParamList[1]); int iEndValue = int.Parse(ParamList[2]); int iPotentialValue = iStartValue + (int)(measureCount * iRate); int iValue = iRate >= 0 ? System.Math.Min(iEndValue, iPotentialValue) : System.Math.Max(iEndValue, iPotentialValue); paramFieldInfo.SetValueForParent(iValue); break; } break; } case ParamDeltaType.Threshold: { int threshold = int.Parse(ParamList[0]); switch (ParamType) { case ParamDataType.Bool: bool bValue = ParamList[1].ToLower() == "true"; if (measureCount >= threshold) { paramFieldInfo.SetValueForParent(bValue); } break; case ParamDataType.Float: float fValue = float.Parse(ParamList[1]); if (measureCount >= threshold) { paramFieldInfo.SetValueForParent(fValue); } break; case ParamDataType.Integer: int iValue = int.Parse(ParamList[1]); if (measureCount >= threshold) { paramFieldInfo.SetValueForParent(iValue); } break; } break; } case ParamDeltaType.InheritLinear: { switch (ParamType) { case ParamDataType.Float: float fRate = float.Parse(ParamList[0]); float fOldValue = (float)paramFieldInfo.GetValueFromParent(); float fValue = fOldValue + fRate; paramFieldInfo.SetValueForParent(fValue); break; case ParamDataType.Integer: float iRate = float.Parse(ParamList[0]); int iOldValue = (int)paramFieldInfo.GetValueFromParent(); int iValue = (int)(iOldValue + iRate); paramFieldInfo.SetValueForParent(iValue); break; } break; } case ParamDeltaType.InheritLinearCapped: { switch (ParamType) { case ParamDataType.Float: float fRate = float.Parse(ParamList[0]); float fEndValue = float.Parse(ParamList[1]); float fOldValue = (float)paramFieldInfo.GetValueFromParent(); float fPotentialValue = fOldValue + fRate; //Debug.Log(fPotentialValue); float fValue = fRate >= 0 ? Mathf.Min(fEndValue, fPotentialValue) : Mathf.Max(fEndValue, fPotentialValue); paramFieldInfo.SetValueForParent(fValue); break; case ParamDataType.Integer: float iRate = float.Parse(ParamList[0]); int iEndValue = int.Parse(ParamList[1]); int iOldValue = (int)paramFieldInfo.GetValueFromParent(); int iPotentialValue = (int)(iOldValue + iRate); int iValue = iRate >= 0 ? System.Math.Min(iEndValue, iPotentialValue) : System.Math.Max(iEndValue, iPotentialValue); paramFieldInfo.SetValueForParent(iValue); break; } break; } } } } }