protected void AddMinMaxGradient(MyJson_Tree compItem, string key, ParticleSystem.MinMaxGradient gradient) { MyJson_Tree gradientItem = new MyJson_Tree(false); gradientItem.SetEnum("mode", gradient.mode); switch (gradient.mode) { case ParticleSystemGradientMode.Color: gradientItem.SetColor("color", gradient.color); break; case ParticleSystemGradientMode.TwoColors: gradientItem.SetColor("colorMin", gradient.colorMin); gradientItem.SetColor("colorMax", gradient.colorMax); break; case ParticleSystemGradientMode.Gradient: this.AddGradient(gradientItem, "gradient", gradient.gradient); break; case ParticleSystemGradientMode.TwoGradients: this.AddGradient(gradientItem, "gradientMin", gradient.gradientMin); this.AddGradient(gradientItem, "gradientMax", gradient.gradientMax); break; } compItem[key] = gradientItem; }
protected void AddGradient(MyJson_Tree gradientItem, string key, Gradient gradient) { //alpha和color过渡值最大为4,如果不够手动填充,如果超过,中间的截掉 GradientAlphaKey[] alphaKeys = this.FillGradientAlpha(gradient); GradientColorKey[] colorKeys = this.FillGradientColor(gradient); MyJson_Tree gradients = new MyJson_Tree(false); gradients.SetEnum("mode", gradient.mode); var alphaKeysItem = new MyJson_Array(); var colorKeysItem = new MyJson_Array(); gradients["alphaKeys"] = alphaKeysItem; gradients["colorKeys"] = colorKeysItem; //alphaKey foreach (GradientAlphaKey _ak in alphaKeys) { MyJson_Tree akItem = new MyJson_Tree(false); int akHash = akItem.GetHashCode(); akItem.SetNumber("alpha", _ak.alpha); akItem.SetNumber("time", _ak.time); alphaKeysItem.Add(akItem); } //colorKey foreach (GradientColorKey _ck in colorKeys) { MyJson_Tree ckItem = new MyJson_Tree(false); int ckHash = ckItem.GetHashCode(); ckItem.SetColor("color", _ck.color); ckItem.SetNumber("time", _ck.time); colorKeysItem.Add(ckItem); } gradientItem[key] = gradients; }