//-------------------------------扩展部分-------------------------------- /** * 组件的公共部分,Vector2 */ public static void SetVector2(this Dictionary <string, IJsonNode> jsonNode, string desc, Vector2 data, int?digits = null) { MyJson_Array cItemArr = new MyJson_Array(); cItemArr.AddNumber(data.x, digits); cItemArr.AddNumber(data.y, digits); jsonNode[desc] = cItemArr; }
public static void SetColor3(this Dictionary <string, IJsonNode> jsonNode, string desc, Color data, int?digits = null) { MyJson_Array cItemArr = new MyJson_Array(); cItemArr.AddNumber(data.r, digits); cItemArr.AddNumber(data.g, digits); cItemArr.AddNumber(data.b, digits); jsonNode[desc] = cItemArr; }
public static void SetUVTransform(this Dictionary <string, IJsonNode> jsonNode, string desc, Vector4 data, int?digits = null) { var tx = data.z; var ty = data.w; var sx = data.x; var sy = data.y; var cx = 0.0f; var cy = 0.0f; var rotation = 0.0f; var c = Math.Cos(rotation); var s = Math.Sin(rotation); MyJson_Array cItemArr = new MyJson_Array(); cItemArr.AddNumber(sx * c); cItemArr.AddNumber(sx * s); cItemArr.AddNumber(-sx * (c * cx + s * cy) + cx + tx); cItemArr.AddNumber(-sy * s); cItemArr.AddNumber(sy * c); cItemArr.AddNumber(-sy * (-s * cx + c * cy) + cy + ty); cItemArr.AddNumber(0.0); cItemArr.AddNumber(0.0); cItemArr.AddNumber(1.0); jsonNode[desc] = cItemArr; }
/** * 组件的公共部分 Rect */ public static void SetRect(this Dictionary <string, IJsonNode> jsonNode, string desc, Rect data, int?digits = null) { MyJson_Array cItemArr = new MyJson_Array(); cItemArr.AddNumber(data.x, digits); cItemArr.AddNumber(data.y, digits); cItemArr.AddNumber(data.width, digits); cItemArr.AddNumber(data.height, digits); jsonNode[desc] = cItemArr; }
protected void AddCurve(MyJson_Tree curveItem, string key, Keyframe[] keys) { MyJson_Array frmes = new MyJson_Array(); foreach (Keyframe k in keys) { MyJson_Array keyItem = new MyJson_Array(); keyItem.AddNumber(k.time); keyItem.AddNumber(k.value); frmes.Add(keyItem); } curveItem[key] = frmes; }
public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson) { SphereCollider comp = component as SphereCollider; var sphereItem = new MyJson_Array(); sphereItem.AddNumber(comp.center.x); sphereItem.AddNumber(comp.center.y); sphereItem.AddNumber(comp.center.z); sphereItem.AddNumber(comp.radius); compJson.Add("sphere", sphereItem); return(true); }
public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson) { BoxCollider comp = component as BoxCollider; var halfSize = comp.size * 0.5f; var minimum = comp.center - halfSize; var maximum = comp.center + halfSize; MyJson_Array aabbItem = new MyJson_Array(); aabbItem.AddNumber(minimum.x); aabbItem.AddNumber(minimum.y); aabbItem.AddNumber(minimum.z); aabbItem.AddNumber(maximum.x); aabbItem.AddNumber(maximum.y); aabbItem.AddNumber(maximum.z); compJson.Add("aabb", aabbItem); return(true); }
public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson) { ParticleSystem comp = component as ParticleSystem; if (!comp.emission.enabled || obj.GetComponent <ParticleSystemRenderer>() == null) { MyLog.LogWarning("无效的粒子组件:" + obj.name); return(false); } //main { var main = comp.main; var mainItem = new MyJson_Tree(false); compJson["main"] = mainItem; mainItem.SetNumber("duration", main.duration); mainItem.SetBool("loop", main.loop); this.AddMinMaxCurve(mainItem, "startDelay", main.startDelay); this.AddMinMaxCurve(mainItem, "startLifetime", main.startLifetime); this.AddMinMaxCurve(mainItem, "startSpeed", main.startSpeed); mainItem.SetBool("startSize3D", main.startSize3D); if (main.startSize3D) { this.AddMinMaxCurve(mainItem, "startSizeX", main.startSizeX); this.AddMinMaxCurve(mainItem, "startSizeY", main.startSizeY); this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSizeZ); } else { this.AddMinMaxCurve(mainItem, "startSizeX", main.startSize); this.AddMinMaxCurve(mainItem, "startSizeY", main.startSize); this.AddMinMaxCurve(mainItem, "startSizeZ", main.startSize); } mainItem.SetBool("_startRotation3D", main.startRotation3D); if (main.startRotation3D) { this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotationX); this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotationY); this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotationZ); } else { this.AddMinMaxCurve(mainItem, "startRotationX", main.startRotation); this.AddMinMaxCurve(mainItem, "startRotationY", main.startRotation); this.AddMinMaxCurve(mainItem, "startRotationZ", main.startRotation); } this.AddMinMaxGradient(mainItem, "startColor", main.startColor); this.AddMinMaxCurve(mainItem, "gravityModifier", main.gravityModifier); mainItem.SetEnum("_simulationSpace", main.simulationSpace); mainItem.SetEnum("scaleMode", main.scalingMode); mainItem.SetBool("playOnAwake", main.playOnAwake); if (ExportToolsSetting.instance.estimateMaxParticles) { var value = this.EstimateMaxParticles(comp); mainItem.SetInt("_maxParticles", value); MyLog.Log(comp.gameObject.name + " 粒子估算:" + value); } else { mainItem.SetInt("_maxParticles", main.maxParticles); } } //emission { var emissionItem = new MyJson_Tree(false); compJson["emission"] = emissionItem; this.AddMinMaxCurve(emissionItem, "rateOverTime", comp.emission.rateOverTime); emissionItem["bursts"] = new MyJson_Array(); var bursts = new ParticleSystem.Burst[comp.emission.burstCount]; comp.emission.GetBursts(bursts); foreach (var burst in bursts) { MyJson_Array burstItem = new MyJson_Array(); burstItem.AddNumber(burst.time); burstItem.AddInt(burst.minCount); burstItem.AddInt(burst.maxCount); burstItem.AddInt(burst.cycleCount); burstItem.AddNumber(burst.repeatInterval); (emissionItem["bursts"] as MyJson_Array).Add(burstItem); } } //shape if (comp.shape.enabled) { var shapItem = new MyJson_Tree(false); compJson["shape"] = shapItem; shapItem.SetEnum("shapeType", comp.shape.shapeType); shapItem.SetNumber("angle", comp.shape.angle); shapItem.SetNumber("length", comp.shape.length); shapItem.SetEnum("arcMode", comp.shape.arcMode); shapItem.SetNumber("arc", comp.shape.arc); shapItem.SetNumber("arcSpread", comp.shape.arcSpread); shapItem.SetEnum("radiusMode", comp.shape.radiusMode); shapItem.SetNumber("radius", comp.shape.radius); shapItem.SetNumber("radiusSpread", comp.shape.radiusSpread); shapItem.SetVector3("box", comp.shape.box); shapItem.SetBool("randomDirection", comp.shape.randomDirectionAmount > 0); shapItem.SetBool("spherizeDirection", comp.shape.sphericalDirectionAmount > 0); this.AddMinMaxCurve(shapItem, "arcSpeed", comp.shape.arcSpeed); } //velocityOverLifetiem if (comp.velocityOverLifetime.enabled) { var velocityOverItem = new MyJson_Tree(false); compJson["velocityOverLifetime"] = velocityOverItem; velocityOverItem.SetEnum("_mode", comp.velocityOverLifetime.x.mode); velocityOverItem.SetEnum("_space", comp.velocityOverLifetime.space); this.AddMinMaxCurve(velocityOverItem, "_x", comp.velocityOverLifetime.x); this.AddMinMaxCurve(velocityOverItem, "_y", comp.velocityOverLifetime.y); this.AddMinMaxCurve(velocityOverItem, "_z", comp.velocityOverLifetime.z); } //colorOverLifetime if (comp.colorOverLifetime.enabled) { var colorOverItem = new MyJson_Tree(false); compJson["colorOverLifetime"] = colorOverItem; this.AddMinMaxGradient(colorOverItem, "_color", comp.colorOverLifetime.color); } //sizeOverLifetime if (comp.sizeOverLifetime.enabled) { var sizeOverItem = new MyJson_Tree(false); compJson["sizeOverLifetime"] = sizeOverItem; sizeOverItem.SetBool("_separateAxes", comp.sizeOverLifetime.separateAxes); this.AddMinMaxCurve(sizeOverItem, "_size", comp.sizeOverLifetime.size); this.AddMinMaxCurve(sizeOverItem, "_x", comp.sizeOverLifetime.x); this.AddMinMaxCurve(sizeOverItem, "_y", comp.sizeOverLifetime.y); this.AddMinMaxCurve(sizeOverItem, "_z", comp.sizeOverLifetime.z); } //rotationOverLifetime if (comp.rotationOverLifetime.enabled) { var rotationOverItem = new MyJson_Tree(false); compJson["rotationOverLifetime"] = rotationOverItem; rotationOverItem.SetBool("_separateAxes", comp.rotationOverLifetime.separateAxes); this.AddMinMaxCurve(rotationOverItem, "_x", comp.rotationOverLifetime.x); this.AddMinMaxCurve(rotationOverItem, "_y", comp.rotationOverLifetime.y); this.AddMinMaxCurve(rotationOverItem, "_z", comp.rotationOverLifetime.z); } //textureSheetAnimationModule if (comp.textureSheetAnimation.enabled) { var textureSheetAnimation = new MyJson_Tree(false); compJson["textureSheetAnimation"] = textureSheetAnimation; textureSheetAnimation.SetInt("_numTilesX", comp.textureSheetAnimation.numTilesX); textureSheetAnimation.SetInt("_numTilesY", comp.textureSheetAnimation.numTilesY); textureSheetAnimation.SetEnum("_animation", comp.textureSheetAnimation.animation); textureSheetAnimation.SetBool("_useRandomRow", comp.textureSheetAnimation.useRandomRow); textureSheetAnimation.SetInt("_cycleCount", comp.textureSheetAnimation.cycleCount); textureSheetAnimation.SetInt("_rowIndex", comp.textureSheetAnimation.rowIndex); this.AddMinMaxCurve(textureSheetAnimation, "_frameOverTime", comp.textureSheetAnimation.frameOverTime, comp.textureSheetAnimation.numTilesX * comp.textureSheetAnimation.numTilesY); this.AddMinMaxCurve(textureSheetAnimation, "_startFrame", comp.textureSheetAnimation.startFrame); } return(true); }