public override void Initialize(EffectNode node) { base.Initialize(node); //if (Node.Owner.STGranularity <= 3) //{ // Debug.LogError("spline trail's elemt count should > 3!"); //} mElementList.Clear(); XSplineComponent spcomp = Node.Owner.STBezierSpline; int elemCount = spcomp.CachedElements.Count; for (int i = 0; i < elemCount; i++) { mElementList.Add(new Element(Vector3.zero, Node.Owner.STElementWidth)); } SetUVCoord(node.LowerLeftUV, node.UVDimensions); SetColor(node.Color); RefreshElementsPos(); }
void BuildDynamicSplineFor(XffectComponent xt, Vector3 offset) { //note you may need to check the specific effectlayer's name here. XSplineComponent spline = xt.EffectLayerList[0].EmitSpline; //build the spline dynamically. spline.RemoveAllPointsExceptFirst(); spline.AppendWorldPoint(offset); spline.AppendWorldPoint(Target.transform.position); spline.ReBuild(); }
public void RefreshElementsPos() { XSplineComponent spcomp = Node.Owner.STBezierSpline; mElementList[0].Position = spcomp.CachedElements[0].Pos; for (int i = 0; i < mElementList.Count; i++) { mElementList[i].Position = spcomp.CachedElements[i].Pos; } }
void UpdateScaledLength() { mLastValidElemIndex = 0; XSplineComponent spcomp = Node.Owner.STBezierSpline; //int lastIdx = spcomp.Spline.GetSegmentCount() - 1; float trailLen = spcomp.Spline.Length; float totalLen = 0f; float limitLen = trailLen * Node.Scale.y * Node.OriScaleY; //NODE all the elements are in the child space of spline, not the EffectLayer. Quaternion localRot = Quaternion.identity; if (Node.Owner.RotAffectorEnable || Node.Owner.RandomOriRot) { localRot = Quaternion.AngleAxis(Node.OriRotateAngle + Node.RotateAngle, Node.Owner.RotationAxis); } Vector3 splinePos = spcomp.transform.position; mElementList[0].Position = spcomp.transform.localToWorldMatrix.MultiplyPoint(localRot * spcomp.CachedElements[0].Pos) - splinePos + Node.Position; for (int i = 1; i < mElementList.Count; i++) { mLastValidElemIndex = i; mElementList[i].Position = spcomp.transform.localToWorldMatrix.MultiplyPoint(localRot * spcomp.CachedElements[i].Pos) - splinePos + Node.Position; totalLen += (spcomp.CachedElements[i].Pos - spcomp.CachedElements[i - 1].Pos).magnitude; if (totalLen > limitLen) { Vector3 dir = spcomp.CachedElements[i].Pos - spcomp.CachedElements[i - 1].Pos; totalLen -= dir.magnitude; float diff = limitLen - totalLen; mElementList[i].Position = spcomp.CachedElements[i - 1].Pos + dir.normalized * diff; mElementList[i].Position = spcomp.transform.localToWorldMatrix.MultiplyPoint(localRot * mElementList[i].Position) - splinePos + Node.Position; return; } } }
public void SetEmitPosition(EffectNode node) { Vector3 retPos = Vector3.zero; Vector3 clientPos = node.GetRealClientPos(); if (Layer.EmitType == (int)EMITTYPE.BOX) { Vector3 center = Layer.EmitPoint; float x = Random.Range(center.x - Layer.BoxSize.x / 2, center.x + Layer.BoxSize.x / 2); float y = Random.Range(center.y - Layer.BoxSize.y / 2, center.y + Layer.BoxSize.y / 2); float z = Random.Range(center.z - Layer.BoxSize.z / 2, center.z + Layer.BoxSize.z / 2); retPos.x = x; retPos.y = y; retPos.z = z; if (!Layer.SyncClient) { //if (!Layer.BoxInheritRotation) // retPos = clientPos + retPos; //else retPos = Layer.ClientTransform.rotation * retPos + clientPos; } else { //if (Layer.BoxInheritRotation) retPos = Layer.ClientTransform.rotation * retPos; } } else if (Layer.EmitType == (int)EMITTYPE.POINT) { retPos = Layer.ClientTransform.rotation * Layer.EmitPoint; if (!Layer.SyncClient) { retPos = clientPos + Layer.EmitPoint; } } else if (Layer.EmitType == (int)EMITTYPE.SPHERE) { retPos = Layer.EmitPoint; if (!Layer.SyncClient) {//同步的话在NodeUpdate里会更新位置 retPos = clientPos + Layer.EmitPoint; } Vector3 r = Vector3.up * Layer.Radius; Quaternion rot = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); retPos = rot * r + retPos; } //Line direction is based on client transform's rotation. else if (Layer.EmitType == (int)EMITTYPE.LINE) { Vector3 left = Layer.LineStartObj.position; Vector3 right = Layer.LineEndObj.position; Vector3 dir = right - left; float length; if (Layer.EmitUniform) { float p = (float)(node.Index + 1) / Layer.MaxENodes; length = dir.magnitude * p; } else { length = Random.Range(0, dir.magnitude); } retPos = left + dir.normalized * length - clientPos; if (!Layer.SyncClient) { retPos = clientPos + retPos; } } else if (Layer.EmitType == (int)EMITTYPE.Spline) { XSplineComponent spcomp = Layer.EmitSpline; int splineIndex; if (Layer.EmitSplinePosType == EEmitSplinePos.Uniformly) { int index = node.Index; float p = (float)(index + 1) / Layer.MaxENodes; splineIndex = (int)(spcomp.CachedElements.Count * p) - 1; splineIndex = Mathf.Clamp(splineIndex, 0, spcomp.CachedElements.Count - 1); } else if (Layer.EmitSplinePosType == EEmitSplinePos.Random) { splineIndex = Random.Range(0, spcomp.CachedElements.Count); } else { splineIndex = 0; } retPos = spcomp.transform.localToWorldMatrix.MultiplyPoint(spcomp.CachedElements[splineIndex].Pos); node.SetSplineOffset(spcomp.CachedElements[splineIndex].Offset); } else if (Layer.EmitType == (int)EMITTYPE.CIRCLE) { float rangle; if (Layer.EmitUniform) { int index = node.Index; float p = (float)(index + 1) / (Layer.MaxENodes); rangle = 360 * p; } else { rangle = Random.Range(0, 360); } float radius = Layer.Radius; if (Layer.UseRandomCircle) { radius = Random.Range(Layer.CircleRadiusMin, Layer.CircleRadiusMax); } Quaternion rotY = Quaternion.Euler(0, rangle, 0); Vector3 v = rotY * (Vector3.right * radius); Quaternion rotTo = Quaternion.FromToRotation(Vector3.up, Layer.ClientTransform.rotation * Layer.CircleDir); retPos = rotTo * v; if (!Layer.SyncClient) { retPos = clientPos + retPos + Layer.EmitPoint; } else { retPos = retPos + Layer.EmitPoint; } } else if (Layer.EmitType == (int)EMITTYPE.Mesh) { if (Layer.EmitMesh == null) { Debug.LogWarning("please set a mesh to the emitter."); return; } int index = 0; if (Layer.EmitMeshType == 0) { int vertCount = Layer.EmitMesh.vertexCount; if (Layer.EmitUniform) { index = (node.Index) % (vertCount - 1); } else { index = Random.Range(0, vertCount - 1); } retPos = Layer.EmitMesh.vertices[index]; if (!Layer.SyncClient) { retPos = clientPos + retPos + Layer.EmitPoint; } else { retPos = retPos + Layer.EmitPoint; } } else if (Layer.EmitMeshType == 1) { Vector3[] verts = Layer.EmitMesh.vertices; int triCount = Layer.EmitMesh.triangles.Length / 3; if (Layer.EmitUniform) { index = (node.Index) % (triCount - 1); } else { index = Random.Range(0, triCount - 1); } int vid1 = Layer.EmitMesh.triangles[index * 3 + 0]; int vid2 = Layer.EmitMesh.triangles[index * 3 + 1]; int vid3 = Layer.EmitMesh.triangles[index * 3 + 2]; retPos = (verts[vid1] + verts[vid2] + verts[vid3]) / 3; if (!Layer.SyncClient) { retPos = clientPos + retPos + Layer.EmitPoint; } else { retPos = retPos + Layer.EmitPoint; } } } node.SetLocalPosition(retPos); }
public void SetRenderType(int type) { Type = type; if (type == 0) { RenderObj = Owner.GetVertexPool().AddSprite(Owner.SpriteWidth, Owner.SpriteHeight, (STYPE)Owner.SpriteType, (ORIPOINT)Owner.OriPoint, 60f, IsSimpleSprite()); } else if (type == 1) { float rwidth = Owner.RibbonWidth; float rlen = Owner.RibbonLen; if (Owner.UseRandomRibbon) { rwidth = UnityEngine.Random.Range(Owner.RibbonWidthMin, Owner.RibbonWidthMax); rlen = UnityEngine.Random.Range(Owner.RibbonLenMin, Owner.RibbonLenMax); } RenderObj = Owner.GetVertexPool().AddRibbonTrail(Owner.FaceToObject, Owner.FaceObject, rwidth, Owner.MaxRibbonElements, rlen, Owner.ClientTransform.position + Owner.EmitPoint, 60f); } else if (type == 2) { RenderObj = Owner.GetVertexPool().AddCone(Owner.ConeSize, Owner.ConeSegment, Owner.ConeAngle, Owner.OriVelocityAxis, 0, 60f, Owner.UseConeAngleChange, Owner.ConeDeltaAngle); } else if (type == 3) { if (Owner.CMesh == null) { Debug.LogError("custom mesh layer has no mesh to display!", Owner.gameObject); } Vector3 dir = Vector3.zero; if (Owner.OriVelocityAxis == Vector3.zero) { Owner.OriVelocityAxis = Vector3.up; } dir = Owner.OriVelocityAxis; RenderObj = Owner.GetVertexPool().AddCustomMesh(Owner.CMesh, dir, 60f); } else if (type == 4) { RenderObj = Owner.GetVertexPool().AddRope(); } else if (type == 5) { RenderObj = Owner.GetVertexPool().AddSphericalBillboard(); } else if (type == 6) { XSplineComponent spcomp = Owner.STBezierSpline; int elemCount = spcomp.CachedElements.Count; RenderObj = Owner.GetVertexPool().AddSplineTrail(elemCount); } else { RenderObj = Owner.GetVertexPool().AddDecal(); } RenderObj.Node = this; }