public override void Initialize(EffectNode node) { base.Initialize(node); SetUVCoord(Node.LowerLeftUV, Node.UVDimensions); SetColor(Node.Color); SetRotation(Node.OriRotateAngle); }
public JetAffector(float mag, MAGTYPE type, AnimationCurve curve,EffectNode node) : base(node, AFFECTORTYPE.JetAffector) { Mag = mag; MType = type; MagCurve = curve; }
void OnPlaneCollision(Xft.CollisionParam param) { //GameObject g = param.CollideObject; //Vector3 pos = param.CollidePos; Xft.EffectNode ef = param.effectNode; ef.SetBounce(); //Debug.Log("collision is "+g+" "+pos); }
public TurbulenceFieldAffector(Transform obj,float atten, bool useMax, float maxDist, EffectNode node) : base(node, AFFECTORTYPE.TurbulenceAffector) { TurbulenceObj = obj;; UseMaxDistance = useMax; MaxDistance = maxDist; MaxDistanceSqr = MaxDistance * MaxDistance; }
public GravityAffector(GAFTTYPE gtype, bool isacc, Vector3 dir, EffectNode node) : base(node, AFFECTORTYPE.GravityAffector) { GType = gtype; Dir = dir; Dir.Normalize(); IsAccelerate = isacc; }
public Cone AddCone(Vector2 size, int numSegment, float angle, Vector3 dir, int uvStretch, float maxFps, bool usedelta, AnimationCurve deltaAngle, EffectNode owner) { VertexSegment segment = GetVertices((numSegment + 1) * 2, numSegment * 6); Cone f = new Cone(segment, size, numSegment, angle, dir, uvStretch, maxFps); f.UseDeltaAngle = usedelta; f.CurveAngle = deltaAngle; f.Owner = owner; return f; }
public DragAffector(Transform dragObj, bool useDir, Vector3 dir,float mag, bool useMaxDist, float maxDist, float atten, EffectNode node) : base(node, AFFECTORTYPE.DragAffector) { DragObj = dragObj; UseDirection = useDir; Direction = dir; Magnitude = mag; UseMaxDistance = useMaxDist; MaxDistance = maxDist; Attenuation = atten; }
public ColorAffector(Color[] colorArr, float gradualLen, COLOR_GRADUAL_TYPE type, EffectNode node) : base(node, AFFECTORTYPE.ColorAffector) { ColorArr = colorArr; OriColorArr = new Color[ColorArr.Length]; ColorArr.CopyTo(OriColorArr, 0); CType = type; GradualLen = gradualLen; if (GradualLen < 0) IsNodeLife = true; }
public TurbulenceFieldAffector(Transform obj, MAGTYPE mtype, float mag, AnimationCurve curve, float atten, bool useMax, float maxDist, EffectNode node) : base(node, AFFECTORTYPE.TurbulenceAffector) { TurbulenceObj = obj; MType = mtype; Magnitude = mag; MagCurve = curve; UseMaxDistance = useMax; MaxDistance = maxDist; MaxDistanceSqr = MaxDistance * MaxDistance; }
public GravityAffector(Transform obj, GAFTTYPE gtype, MAGTYPE mtype,bool isacc, Vector3 dir, float mag,AnimationCurve curve,EffectNode node) : base(node, AFFECTORTYPE.GravityAffector) { GType = gtype; MType = mtype; Magnitude = mag; MagCurve = curve; Dir = dir; Dir.Normalize(); GravityObj = obj; IsAccelerate = isacc; }
public ColorAffector(EffectLayer owner, EffectNode node) : base(node, AFFECTORTYPE.ColorAffector) { mOwner = owner; if (owner.ColorGradualTimeLength < 0) IsNodeLife = true; if (mOwner.ColorChangeType == COLOR_CHANGE_TYPE.Random) { mRandomKey = Random.Range(0f,1f); } }
public Vector3 GetEmitRotation(EffectNode node) { Vector3 ret = Vector3.zero; //Set Direction: if (Layer.DirType == DIRECTION_TYPE.Sphere) { ret = node.GetOriginalPos() - Layer.DirCenter.position; if (ret == Vector3.zero) { //use random rotation. Vector3 r = Vector3.up; Quaternion rot = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); ret = rot * r; } } else if (Layer.DirType == DIRECTION_TYPE.Planar) { ret = Layer.OriVelocityAxis; } else if (Layer.DirType == DIRECTION_TYPE.Cone) { //if emit uniform circle, the rotation should be spread from the center. if (Layer.EmitType == (int)EMITTYPE.CIRCLE && Layer.EmitUniform) { Vector3 dir; if (!Layer.SyncClient) dir = node.Position - (node.GetRealClientPos() + Layer.EmitPoint); else dir = node.Position - Layer.EmitPoint; Vector3 target = Vector3.RotateTowards(dir, Layer.CircleDir, (90 - Layer.AngleAroundAxis) * Mathf.Deg2Rad, 1); Quaternion rot = Quaternion.FromToRotation(dir, target); ret = rot * dir; } else { //first, rotate y around z 30 degrees Quaternion rotY = Quaternion.Euler(0, 0, Layer.AngleAroundAxis); //second, rotate around y 360 random dir; Quaternion rotAround = Quaternion.Euler(0, Random.Range(0, 360), 0); //last, rotate the dir to OriVelocityAxis Quaternion rotTo = Quaternion.FromToRotation(Vector3.up, Layer.OriVelocityAxis); ret = rotTo * rotAround * rotY * Vector3.up; } } else if (Layer.DirType == DIRECTION_TYPE.Cylindrical) { Vector3 dir = node.GetOriginalPos() - Layer.DirCenter.position; float dist = Vector3.Dot(Layer.OriVelocityAxis, dir); ret = dir - dist * Layer.OriVelocityAxis.normalized; } return ret; }
public override void Initialize(EffectNode node) { base.Initialize(node); SetColor(Node.Color); SetRotation(Node.OriRotateAngle); SetScale(Node.OriScaleX, Node.OriScaleY); SetUVCoord(Node.LowerLeftUV, Node.UVDimensions); //if (Node.Owner.DirType != DIRECTION_TYPE.Sphere) // SetDirection(Node.Owner.ClientTransform.rotation * Node.OriDirection); //else SetDirection(Node.OriDirection); }
public EffectNode dummyNode;//will not be added to the activenode list. so will not be rendered, just to calc uv anim. public void Init(EffectLayer owner) { Owner = owner; Vertexsegment = owner.GetVertexPool().GetRopeVertexSeg(owner.MaxENodes); dummyNode = new EffectNode(0, owner.ClientTransform, false, owner); List<Affector> afts = owner.InitAffectors(dummyNode); dummyNode.SetAffectorList(afts); dummyNode.SetRenderType(4); //use infinite life. dummyNode.Init(Vector3.zero, 0f, -1f, 0, 1f, 1f, Color.clear, Vector2.zero, Vector2.one); }
public BombAffector(Transform obj, BOMBTYPE gtype, MAGTYPE mtype,BOMBDECAYTYPE dtype, float mag, AnimationCurve curve, float decay, Vector3 axis, EffectNode node) : base(node, AFFECTORTYPE.BombAffector) { BombType = gtype; MType = mtype; DecayType = dtype; Magnitude = mag; MagCurve = curve; Decay = decay; BombAxis = axis; BombAxis.Normalize(); BombObj = obj; }
protected void ClearNodeVert(EffectNode node) { int baseIdx = Vertexsegment.VertStart + node.Index * 2; VertexPool pool = Vertexsegment.Pool; pool.Vertices[baseIdx] = Owner.ClientTransform.position; pool.Colors[baseIdx] = Color.clear; pool.Vertices[baseIdx + 1] = Owner.ClientTransform.position; pool.Colors[baseIdx + 1] = Color.clear; pool.VertChanged = true; pool.ColorChanged = true; }
public AirFieldAffector(Transform airObj, Vector3 dir, float atten, bool useMaxdist, float maxDist,bool enableSpread, float spread, float inhV, bool inhRot, EffectNode node) : base(node, AFFECTORTYPE.AirFieldAffector) { AirObj = airObj; Direction = dir.normalized; Attenuation = atten; UseMaxDistance = useMaxdist; MaxDistance = maxDist; MaxDistanceSqr = MaxDistance * MaxDistance; EnableSpread = enableSpread; Spread = spread; InheritVelocity = inhV; InheritRotation = inhRot; LastFieldPos = AirObj.position; }
public CustomMesh(VertexPool.VertexSegment segment, Mesh mesh,Vector3 dir, float maxFps,EffectNode owner) { MyMesh = mesh; m_owner = owner; MeshVerts = new Vector3[mesh.vertices.Length]; mesh.vertices.CopyTo(MeshVerts,0); Vertexsegment = segment; MyDirection = dir; Fps = 1f / maxFps; SetPosition(Vector3.zero); InitVerts(); }
public VortexAffector(Transform obj, MAGTYPE mtype, float mag, AnimationCurve vortexCurve, Vector3 dir, bool inhRot, EffectNode node) : base(node, AFFECTORTYPE.VortexAffector) { VortexCurve = vortexCurve; Direction = dir; InheritRotation = inhRot; VortexObj = obj; MType = mtype; Magnitude = mag; //ver 1.2.1 if (node.Owner.IsRandomVortexDir) { Direction.x = Random.Range (-1f, 1f); Direction.y = Random.Range (-1f, 1f); Direction.z = Random.Range (-1f, 1f); } Direction.Normalize (); }
public VortexAffector (Transform obj, Vector3 dir, bool inhRot, EffectNode node) : base(node, AFFECTORTYPE.VortexAffector) { Direction = dir; InheritRotation = inhRot; VortexObj = obj; //ver 1.2.1 if (node.Owner.IsRandomVortexDir) { Direction.x = Random.Range (-1f, 1f); Direction.y = Random.Range (-1f, 1f); Direction.z = Random.Range (-1f, 1f); } Direction.Normalize (); IsFirst = true; }
public void SetEmitPosition(EffectNode node) { Vector3 retPos = Vector3.zero; 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 = Layer.ClientTransform.position + retPos; else retPos = Layer.ClientTransform.rotation * retPos + Layer.ClientTransform.position; } else { if (Layer.BoxInheritRotation) retPos = Layer.ClientTransform.rotation * retPos; } } else if (Layer.EmitType == (int)EMITTYPE.POINT) { retPos = Layer.EmitPoint; if (!Layer.SyncClient) { retPos = Layer.ClientTransform.position + Layer.EmitPoint; } } else if (Layer.EmitType == (int)EMITTYPE.SPHERE) { retPos = Layer.EmitPoint; if (!Layer.SyncClient) {//同步的话在NodeUpdate里会更新位置 retPos = Layer.ClientTransform.position + 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.EmitPoint + Layer.ClientTransform.forward * Layer.LineLengthLeft; Vector3 right = Layer.EmitPoint + Layer.ClientTransform.forward * Layer.LineLengthRight; 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; if (!Layer.SyncClient) retPos = Layer.ClientTransform.position + retPos; } else if (Layer.EmitType == (int)EMITTYPE.CIRCLE) { float rangle; if (Layer.EmitUniform) { float p = (float)(node.Index + 1) / Layer.MaxENodes; rangle = 360 * p; } else { rangle = Random.Range(0, 360); } Quaternion rotY = Quaternion.Euler(0, rangle, 0); Vector3 v = rotY * (Vector3.right * Layer.Radius); Quaternion rotTo = Quaternion.FromToRotation(Vector3.up, Layer.ClientTransform.rotation * Layer.CircleDir); retPos = rotTo * v; if (!Layer.SyncClient) retPos = Layer.ClientTransform.position + 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 = Layer.ClientTransform.position + 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 = Layer.ClientTransform.position + retPos + Layer.EmitPoint; else retPos = retPos + Layer.EmitPoint; } } node.SetLocalPosition(retPos); }
public List<Affector> InitAffectors(EffectNode node) { List<Affector> AffectorList = new List<Affector>(); if (UVAffectorEnable) { UVAnimation uvAnim = new UVAnimation(); if (UVType == 1) { float perWidth = OriUVDimensions.x / Cols; float perHeight = Mathf.Abs(OriUVDimensions.y / Rows); Vector2 cellSize = new Vector2(perWidth, perHeight); uvAnim.BuildUVAnim(OriTopLeftUV, cellSize, Cols, Rows, Cols * Rows); } UVDimension = uvAnim.UVDimensions[0]; UVTopLeft = uvAnim.frames[0]; if (uvAnim.frames.Length != 1) { uvAnim.loopCycles = LoopCircles; Affector aft = new UVAffector(uvAnim, UVTime, node, RandomStartFrame); AffectorList.Add(aft); } } else { UVDimension = OriUVDimensions; UVTopLeft = OriTopLeftUV; } if (RotAffectorEnable && RotateType != RSTYPE.NONE) { Affector aft; if (RotateType == RSTYPE.NONE) aft = new RotateAffector(DeltaRot, node); else aft = new RotateAffector(RotateType, node); AffectorList.Add(aft); } if (ScaleAffectorEnable && ScaleType != RSTYPE.NONE) { Affector aft; if (ScaleType == RSTYPE.NONE) aft = new ScaleAffector(DeltaScaleX, DeltaScaleY, node); else aft = new ScaleAffector(ScaleType, node); AffectorList.Add(aft); } if (ColorAffectorEnable /*&& ColorAffectType != 0*/) { ColorAffector aft = new ColorAffector(this, node); AffectorList.Add(aft); } if (JetAffectorEnable) { Affector aft = new JetAffector(JetMag, JetMagType, JetCurve, node); AffectorList.Add(aft); } if (VortexAffectorEnable) { Affector aft; aft = new VortexAffector(VortexObj, VortexDirection, VortexInheritRotation, node); AffectorList.Add(aft); } if (UVRotAffectorEnable) { Affector aft; float xscroll = UVRotXSpeed; float yscroll = UVRotYSpeed; if (RandomUVRotateSpeed) { xscroll = Random.Range(UVRotXSpeed, UVRotXSpeedMax); yscroll = Random.Range(UVRotYSpeed, UVRotYSpeedMax); } aft = new UVRotAffector(xscroll, yscroll, node); AffectorList.Add(aft); } if (UVScaleAffectorEnable) { Affector aft = new UVScaleAffector(node); AffectorList.Add(aft); } if (GravityAffectorEnable) { Affector aft; aft = new GravityAffector(GravityObject, GravityAftType, IsGravityAccelerate, GravityDirection, node); AffectorList.Add(aft); if (GravityAftType == GAFTTYPE.Spherical && GravityObject == null) { Debug.LogWarning("Gravity Object is missing, automatically set to effect layer self:" + gameObject.name); GravityObject = transform; } } if (AirAffectorEnable) { Affector aft = new AirFieldAffector(AirObject, AirDirection, AirAttenuation, AirUseMaxDistance, AirMaxDistance, AirEnableSpread, AirSpread, AirInheritVelocity, AirInheritRotation, node); AffectorList.Add(aft); } if (BombAffectorEnable) { Affector aft = new BombAffector(BombObject, BombType, BombDecayType, BombMagnitude, BombDecay, BombAxis, node); AffectorList.Add(aft); } if (TurbulenceAffectorEnable) { Affector aft = new TurbulenceFieldAffector(TurbulenceObject, TurbulenceAttenuation, TurbulenceUseMaxDistance, TurbulenceMaxDistance, node); AffectorList.Add(aft); } if (DragAffectorEnable) { Affector aft = new DragAffector(DragObj, DragUseDir, DragDir, DragMag, DragUseMaxDist, DragMaxDist, DragAtten, node); AffectorList.Add(aft); } if (SineAffectorEnable) { Affector aft = new SineAffector(node); AffectorList.Add(aft); } return AffectorList; }
public virtual void Initialize(EffectNode node) { Node = node; }
public void RemoveActiveNode(EffectNode node) { if (AvailableNodeCount == MaxENodes) { Debug.LogError("something wrong with removing node!"); return; } if (ActiveENodes[node.Index] == null) //already removed return; ActiveENodes[node.Index] = null; AvailableENodes[node.Index] = node; AvailableNodeCount++; }
public GravityAffector(Transform obj, GAFTTYPE gtype, MAGTYPE mtype, bool isacc, Vector3 dir, float mag, AnimationCurve curve, EffectNode node) : base(node, AFFECTORTYPE.GravityAffector) { GType = gtype; MType = mtype; Magnitude = mag; MagCurve = curve; Dir = obj.rotation * dir; Dir.Normalize(); GravityObj = obj; IsAccelerate = isacc; }
public RotateAffector(float delta, EffectNode node) : base(node, AFFECTORTYPE.RotateAffector) { RType = RSTYPE.SIMPLE; Delta = delta; }
public override void Initialize(EffectNode node) { base.Initialize(node); SetUVCoord(node.LowerLeftUV, node.UVDimensions); SetColor(node.Color); SetHeadPosition(node.GetRealClientPos() + node.Position /*+ node.OriDirection.normalized * node.Owner.TailDistance*/); ResetElementsPos(); mLastClientPos = node.Owner.ClientTransform.position; }
//consider node life if TimeLen < 0; public float Evaluate(float time, EffectNode node) { float len = TimeLen; if (len < 0f) len = node.GetLifeTime(); float t = time / len; if (t > 1f) { if (WrapType == WRAP_TYPE.CLAMP) { t = 1f; } else if (WrapType == WRAP_TYPE.LOOP) { int d = Mathf.FloorToInt(t); t = t - (float)d; } else { int n = Mathf.CeilToInt(t); int d = Mathf.FloorToInt(t); if (n % 2 == 0) { t = (float)n - t; } else { t = t - (float)d; } } } return Curve01.Evaluate(t) * MaxValue; }
public Affector(EffectNode node, AFFECTORTYPE type) { Node = node; Type = type; }
protected void Init() { //added 2012.6.24 InitCollision(); Owner = transform.parent.gameObject.GetComponent<XffectComponent>(); if (Owner == null) Debug.LogError("you must set EffectLayer to be XffectComponent's child."); //fixed 2012.6.2. ignoring the red errors. if (ClientTransform == null) { Debug.LogWarning("effect layer: " + gameObject.name + " haven't assign a client transform, automaticly set to itself."); ClientTransform = transform; } AvailableENodes = new EffectNode[MaxENodes]; ActiveENodes = new EffectNode[MaxENodes]; for (int i = 0; i < MaxENodes; i++) { EffectNode n = new EffectNode(i, ClientTransform, SyncClient, this); List<Affector> afts = InitAffectors(n); n.SetAffectorList(afts); n.SetRenderType(RenderType); AvailableENodes[i] = n; } if (RenderType == 4) { RopeDatas.Init(this); } AvailableNodeCount = MaxENodes; emitter = new Emitter(this); mStopped = false; }
public RotateAffector(RSTYPE type, EffectNode node) : base(node,AFFECTORTYPE.RotateAffector) { RType = type; }
public void AddActiveNode(EffectNode node) { if (AvailableNodeCount == 0) Debug.LogError("out index!"); if (AvailableENodes[node.Index] == null) //already added return; ActiveENodes[node.Index] = node; AvailableENodes[node.Index] = null; AvailableNodeCount--; node.TotalIndex = TotalAddedCount++; }
public SineAffector(Vector3 force, bool modifyPos, float maxFreq, float minFreq, EffectNode node) : base(node, AFFECTORTYPE.SineAffector) { SineForce = force; ModifyPos = modifyPos; SineMaxFreq = maxFreq; SineMinFreq = minFreq; SineFreq = SineMinFreq; }