Exemplo n.º 1
0
        public void Initialize(XffectComponent owner)
        {
            Owner = owner;
            switch (Type)
            {
            case XEventType.CameraShake:
                m_eventHandler = new CameraShakeEvent(this);
                break;

            case XEventType.Light:
                m_eventHandler = new LightEvent(this);
                break;

            case XEventType.Sound:
                m_eventHandler = new SoundEvent(this);
                break;

            case XEventType.CameraEffect:
                if (CameraEffectType == CameraEffectEvent.EType.ColorInverse)
                {
                    m_eventHandler = new ColorInverseEvent(this);
                }
                else if (CameraEffectType == CameraEffectEvent.EType.Glow)
                {
                    m_eventHandler = new GlowEvent(this);
                }
                else if (CameraEffectType == CameraEffectEvent.EType.GlowPerObj)
                {
                    m_eventHandler = new GlowPerObjEvent(this);
                }
                else if (CameraEffectType == CameraEffectEvent.EType.RadialBlur)
                {
                    m_eventHandler = new RadialBlurEvent(this);
                }
                else if (CameraEffectType == CameraEffectEvent.EType.RadialBlurMask)
                {
                    m_eventHandler = new RadialBlurTexAddEvent(this);
                }
                else if (CameraEffectType == CameraEffectEvent.EType.Glitch)
                {
                    m_eventHandler = new GlitchEvent(this);
                }
                break;

            case XEventType.TimeScale:
                m_eventHandler = new TimeScaleEvent(this);
                break;

            default:
                Debug.LogWarning("invalid event type!");
                break;
            }
            m_eventHandler.Initialize();
            m_elapsedTime = 0f;
            m_finished    = false;
        }
Exemplo n.º 2
0
 public override void Initialize()
 {
     if (m_owner.LightComp == null)
     {
         Debug.LogWarning("you should assign a light source to Light Event to use it!");
         return;
     }
     m_elapsedTime = 0f;
     XffectComponent.SetActive(m_owner.LightComp.gameObject, false);
 }
Exemplo n.º 3
0
 public override void Reset()
 {
     if (m_owner.LightComp == null)
     {
         return;
     }
     XffectComponent.SetActive(m_owner.LightComp.gameObject, false);
     m_elapsedTime = 0f;
     m_editorFlag  = false;
 }
Exemplo n.º 4
0
        public void Reset()
        {
            //activate on death subemitter.
            if (Owner.UseSubEmitters && !string.IsNullOrEmpty(Owner.DeathSubEmitter))
            {
                XffectComponent sub = Owner.SpawnCache.GetEffect(Owner.DeathSubEmitter);
                if (sub == null)
                {
                    return;
                }

                sub.transform.position = CurWorldPos;
                sub.Active();
            }

            //Position = Vector3.up * -9999;
            Position    = Owner.ClientTransform.position;
            Velocity    = Vector3.zero;
            ElapsedTime = 0f;


            CurWorldPos = Owner.transform.position;

            LastWorldPos = CurWorldPos;

            IsCollisionEventSended = false;

            if (Owner.IsRandomStartColor)
            {
                //StartColor = Owner.RandomColorParam.GetGradientColor(UnityEngine.Random.Range(0f, 1f));
                StartColor = Owner.RandomColorGradient.Evaluate(UnityEngine.Random.Range(0f, 1f));
            }

            //do not use foreach in script!
            for (int i = 0; i < AffectorList.Count; i++)
            {
                Affector aft = AffectorList[i];
                aft.Reset();
            }

            Scale = Vector3.one;


            mIsFade = false;


            RenderObj.Reset();

            if (Owner.UseSubEmitters &&
                SubEmitter != null && XffectComponent.IsActive(SubEmitter.gameObject) &&
                Owner.SubEmitterAutoStop)
            {
                SubEmitter.StopEmit();
            }
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        public XffectComponent ReleaseEffect(string name)
        {
            XffectComponent xft = GetEffect(name);

            if (xft == null)
            {
                //Debug.LogWarning("can't find available effect in cache!:" + name);
                return(null);
            }
            xft.Active();
            return(xft);
        }
 public void Initialize()
 {
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft == null)
         {
             continue;
         }
         xft.Initialize();
         XffectList.Add(xft);
     }
 }
Exemplo n.º 8
0
        //release effect by world position. in this case, the client transform's position should be zero.
        //notice: if the xffect is not auto-deactive, you should remember to manually deactive it.
        //** automaticaly set client to EffectCache, so you should make sure EffectCache's position is always zero.
        public XffectComponent ReleaseEffect(string name, Vector3 pos)
        {
            XffectComponent xft = GetEffect(name);

            if (xft == null)
            {
                Debug.LogWarning("can't find available effect in cache!:" + name);
                return(null);
            }
            xft.Active();
            xft.SetClient(transform);
            xft.SetEmitPosition(pos);
            return(xft);
        }
Exemplo n.º 9
0
 public void Reset()
 {
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft != null && xft.gameObject.activeSelf)
         {
             xft.DeActive();
         }
         CompositeXffect cxft = child.GetComponent <CompositeXffect>();
         if (cxft != null && cxft.gameObject.activeSelf)
         {
             cxft.DeActive();
         }
     }
 }
Exemplo n.º 10
0
        //for only-one effect
        public bool IsEffectActive(string eftName)
        {
            List <XffectComponent> cache = EffectDic[eftName];

            if (cache == null)
            {
                Debug.LogError(name + ": cache doesnt exist!");
                return(true);
            }
            if (cache.Count > 1)
            {
                Debug.LogWarning("DeActive() only support one Xffect cache!");
            }
            XffectComponent xft = cache[0];

            return(XffectComponent.IsActive(xft.gameObject));
        }
Exemplo n.º 11
0
        //not support auto extend.
        public CompositeXffect GetCompositeXffect(string name)
        {
            List <CompositeXffect> cache = CompEffectDic[name];

            if (cache == null)
            {
                return(null);
            }
            foreach (CompositeXffect xftc in cache)
            {
                if (!XffectComponent.IsActive(xftc.gameObject))
                {
                    return(xftc);
                }
            }
            return(null);
        }
Exemplo n.º 12
0
        public override void Update(float deltaTime)
        {
            if (m_editorFlag)
            {
                return;
            }
            if (m_owner.LightComp == null)
            {
                return;
            }

            m_elapsedTime += deltaTime;

            if (m_elapsedTime > m_owner.EndTime)
            {
                XffectComponent.SetActive(m_owner.LightComp.gameObject, false);
                return;
            }

            if (m_elapsedTime > m_owner.StartTime)
            {
                XffectComponent.SetActive(m_owner.LightComp.gameObject, true);
                float intensity = 0f;
                if (m_owner.LightIntensityType == MAGTYPE.Curve && m_owner.LightIntensityCurve != null)
                {
                    intensity = m_owner.LightIntensityCurve.Evaluate(m_elapsedTime - m_owner.StartTime);
                }
                else
                {
                    intensity = m_owner.LightIntensity;
                }
                m_owner.LightComp.intensity = intensity;

                float range = 0f;
                if (m_owner.LightRangeType == MAGTYPE.Curve && m_owner.LightRangeCurve != null)
                {
                    range = m_owner.LightRangeCurve.Evaluate(m_elapsedTime - m_owner.StartTime);
                }
                else
                {
                    range = m_owner.LightRange;
                }
                m_owner.LightComp.range = range;
            }
        }
Exemplo n.º 13
0
        public void StopEffect(string eftName, float fadeTime)
        {
            List <XffectComponent> cache = EffectDic[eftName];

            if (cache == null)
            {
                Debug.LogError(name + ": cache doesnt exist!");
                return;
            }

            for (int i = 0; i < cache.Count; i++)
            {
                XffectComponent xft = cache[i];
                if (!XffectComponent.IsActive(xft.gameObject))
                {
                    continue;
                }
                xft.StopSmoothly(fadeTime);
            }
        }
Exemplo n.º 14
0
        public void Initialize()
        {
            XffectList.Clear();
            foreach (Transform child in transform)
            {
                XffectComponent xft = child.GetComponent <XffectComponent>();
                if (xft == null)
                {
                    XffectCache xc = child.GetComponent <XffectCache>();
                    if (xc != null)
                    {
                        xc.Init();
                    }
                    continue;
                }

                xft.Initialize();
                XffectList.Add(xft);
            }
        }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
        //deactive the effect smoothly.
        public void StopEffect(string eftName)
        {
            List <XffectComponent> cache = EffectDic[eftName];

            if (cache == null)
            {
                Debug.LogError(name + ": cache doesnt exist!");
                return;
            }
            if (cache.Count > 1)
            {
                Debug.LogWarning("DeActive() only support one Xffect cache!");
            }
            XffectComponent xft = cache[0];

            if (!XffectComponent.IsActive(xft.gameObject))
            {
                return;
            }
            xft.StopEmit();
        }
Exemplo n.º 17
0
        public void Init(XffectComponent parent)
        {
            Owner = parent;
            if (Owner == null)
            {
                Debug.Log("you must set EffectLayer to be XffectComponent's child.");
            }


            if (ClientTransform == null)
            {
                Debug.Log("effect layer: " + gameObject.name + " haven't assign a client transform, automaticly set to itself.");
                ClientTransform = transform;
            }

            if (RenderType < 0 || RenderType > (int)ERenderType.Max)
            {
                Debug.Log("unspported RenderType.");
            }

            _RenderType = (ERenderType)RenderType;

            AvailableENodes = new EffectNode[MaxENodes];
            for (int i = 0; i < MaxENodes; i++)
            {
                EffectNode n    = new EffectNode(i, ClientTransform, SyncClient, this);
                var        afts = InitAffectors(n);
                n.SetAffectorList(afts);

                n.SetRenderType(_RenderType);
                AvailableENodes[i] = n;
            }

            ActiveENodes       = new EffectNode[MaxENodes];
            AvailableNodeCount = MaxENodes;
            emitter            = new Emitter(this);
            mStopped           = false;
            mElapsedTime       = 0f;
            LastClientPos      = ClientTransform.position;
        }
Exemplo n.º 18
0
        //note this function also modified MeshList.
        MeshFilter CreateMeshObj(Material mat)
        {
            GameObject obj = new GameObject("xftmesh " + mat.name);

            obj.layer = gameObject.layer;
            MeshList.Add(obj);
            obj.AddComponent <MeshFilter>();
            obj.AddComponent <MeshRenderer>();
            SetActive(obj, true);



#if UNITY_EDITOR
            if (!EditorApplication.isPlaying)
            {
                XffectComponent.SetActive(obj, true);
                //obj.hideFlags = HideFlags.HideAndDontSave;
                EditorUtility.SetSelectedWireframeHidden(obj.GetComponent <Renderer>(), true);
            }
#endif

            MeshFilter   Meshfilter;
            MeshRenderer Meshrenderer;
            Meshfilter                  = (MeshFilter)obj.GetComponent(typeof(MeshFilter));
            Meshrenderer                = (MeshRenderer)obj.GetComponent(typeof(MeshRenderer));
            Meshrenderer.castShadows    = false;
            Meshrenderer.receiveShadows = false;
            Meshrenderer.GetComponent <Renderer>().sharedMaterial = mat;

            if (UseWith2DSprite)
            {
                Meshrenderer.sortingLayerName = SortingLayerName;
                Meshrenderer.sortingOrder     = SortingOrder;
            }

            Meshfilter.sharedMesh = new Mesh();
            return(Meshfilter);
        }
Exemplo n.º 19
0
        public void Init()
        {
            if (mInited)
            {
                return;
            }

            EffectDic     = new Dictionary <string, List <XffectComponent> >();
            CompEffectDic = new Dictionary <string, List <CompositeXffect> >();

            foreach (Transform child in transform)
            {
                XffectComponent xft = child.GetComponent <XffectComponent>();
                if (xft != null)
                {
                    //make sure all children are inited.
                    xft.Initialize();
                    if (!EffectDic.ContainsKey(child.name))
                    {
                        EffectDic[child.name] = new List <XffectComponent>();
                    }
                    EffectDic[child.name].Add(xft);
                }
                CompositeXffect cxft = child.GetComponent <CompositeXffect>();
                if (cxft != null)
                {
                    cxft.Initialize();
                    if (!CompEffectDic.ContainsKey(child.name))
                    {
                        CompEffectDic[child.name] = new List <CompositeXffect>();
                    }
                    CompEffectDic[child.name].Add(cxft);
                }
            }

            mInited = true;
        }
Exemplo n.º 20
0
        public XffectComponent GetEffect(string name)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                //Init();
                RefreshDic();
            }
#endif

            if (!EffectDic.ContainsKey(name))
            {
                Debug.LogError("there is no effect:" + name + " in effect cache!");
                return(null);
            }
            List <XffectComponent> cache = EffectDic[name];
            if (cache == null)
            {
                return(null);
            }

            foreach (XffectComponent xft in cache)
            {
                //IMPORTANT: xft might be destroyed if you used it in other parent. always check it.
                if (xft == null)
                {
                    continue;
                }

                if (!XffectComponent.IsActive(xft.gameObject))
                {
                    return(xft);
                }
            }
            return(AddXffect(name));
        }
Exemplo n.º 21
0
        public void DeActiveEffect(string eftName)
        {
            List <XffectComponent> cache = EffectDic[eftName];

            if (cache == null)
            {
                Debug.LogError(name + ": cache doesnt exist!");
                return;
            }
            //if (cache.Count > 1)
            //{
            //Debug.LogWarning("DeActive() only support one Xffect cache!");
            //}

            for (int i = 0; i < cache.Count; i++)
            {
                XffectComponent xft = cache[i];
                if (!XffectComponent.IsActive(xft.gameObject))
                {
                    continue;
                }
                xft.DeActive();
            }
        }
Exemplo n.º 22
0
        public void CollisionDetection()
        {
            if (!Owner.UseCollisionDetection || IsCollisionEventSended)
            {
                return;
            }

            bool collided = false;

            GameObject collideObject = null;

            if (Owner.CollisionType == COLLITION_TYPE.Sphere && Owner.CollisionGoal != null)
            {
                Vector3 diff  = CurWorldPos - Owner.CollisionGoal.position;
                float   range = Owner.ColliisionPosRange + Owner.ParticleRadius;
                if (diff.sqrMagnitude <= range * range /*|| //fixed, don't check get through.
                                                        * Vector3.Dot(diff, LastCollisionDetectDir) < 0*/)
                {
                    collided      = true;
                    collideObject = Owner.CollisionGoal.gameObject;
                }
                LastCollisionDetectDir = diff;
            }
            else if (Owner.CollisionType == COLLITION_TYPE.CollisionLayer)
            {
                int layer = 1 << Owner.CollisionLayer;

                RaycastHit hit;
                Vector3    p1 = GetOriginalPos();
                if (Physics.SphereCast(p1, Owner.ParticleRadius, Velocity.normalized, out hit, Owner.ParticleRadius, layer))
                {
                    collided      = true;
                    collideObject = hit.collider.gameObject;
                }

                //if (Physics.CheckSphere(GetOriginalPos(), Owner.ParticleRadius, layer))
                //{
                //collided = true;
                //}
            }
            else if (Owner.CollisionType == COLLITION_TYPE.Plane)
            {
                if (!Owner.CollisionPlane.GetSide(CurWorldPos - Owner.PlaneDir.normalized * Owner.ParticleRadius))
                {
                    collided      = true;
                    collideObject = Owner.gameObject;
                }
            }
            else
            {
                //Debug.LogError("invalid collision target!");
            }

            if (collided)
            {
                if (Owner.EventHandleFunctionName != "" && Owner.EventReceiver != null)
                {
                    //Owner.EventReceiver.SendMessage(Owner.EventHandleFunctionName, Owner.CollisionGoal);
                    Owner.EventReceiver.SendMessage(Owner.EventHandleFunctionName, new CollisionParam(collideObject, GetOriginalPos(), Velocity.normalized));
                }

                IsCollisionEventSended = true;
                if (Owner.CollisionAutoDestroy)
                {
                    //distroy.
                    ElapsedTime = Mathf.Infinity;
                }


                //activate on collision subemitter.
                if (Owner.UseSubEmitters && !string.IsNullOrEmpty(Owner.CollisionSubEmitter))
                {
                    XffectComponent sub = Owner.SpawnCache.GetEffect(Owner.CollisionSubEmitter);
                    if (sub == null)
                    {
                        return;
                    }

                    sub.transform.position = CurWorldPos;
                    sub.Active();
                }
            }
        }
Exemplo n.º 23
0
        public void Update(float deltaTime)
        {
            ElapsedTime += deltaTime;
            for (int i = 0; i < AffectorList.Count; i++)
            {
                Affector aft = AffectorList[i];
                aft.Update(deltaTime);
            }


            if (Owner.EmitType == (int)EMITTYPE.Spline && Owner.DirType == DIRECTION_TYPE.Spline)
            {
                XSpline spline = Owner.EmitSpline.Spline;

                if (Owner.SplineEaseType == XEase.Easing.Linear)
                {
                    mSplineIterator.Iterate(mOriSpeed * deltaTime);
                }
                else
                {
                    mSplineOffset += mOriSpeed * deltaTime;
                    float t = mSplineOffset / spline.Length;
                    t = Mathf.Clamp(t, 0, 1);
                    mSplineIterator.SetOffset(XEase.EaseByType(Owner.SplineEaseType, 0, spline.Length, t));
                }

                Position = mSplineIterator.GetPosition();
            }
            else
            {
                Position += Velocity * deltaTime;
            }



            //if (Mathf.Abs(Acceleration) > 1e-04)
            //{
            //Velocity += Velocity.normalized * Acceleration * deltaTime;
            //}

            if (SyncClient)
            {
                //NOTICE: only sync position.
                CurWorldPos = Position + GetRealClientPos();
            }
            else
            {
                CurWorldPos = Position;
            }


            CollisionDetection();

            //sync subemitters position.
            if (Owner.UseSubEmitters && SubEmitter != null && XffectComponent.IsActive(SubEmitter.gameObject))
            {
                SubEmitter.transform.position = CurWorldPos;
            }


            RenderObj.Update(deltaTime);

            if (Owner.UseShaderCurve2 || Owner.UseShaderCurve1)
            {
                float x = Owner.UseShaderCurve1 ? Owner.ShaderCurveX1.Evaluate(GetElapsedTime(), this) : 1f;

                float y = Owner.UseShaderCurve2 ? Owner.ShaderCurveX2.Evaluate(GetElapsedTime(), this) : 0f;

                RenderObj.ApplyShaderParam(x, y);
            }
            else if (Owner.UseFlowControl)
            {
                float x = Owner.FlowSpeed * GetElapsedTime();
                float y = Owner.FlowStretchLength;

                //float d = x % y;

                //float p = x / y;

                //float px = x;

                //if (Mathf.FloorToInt(p) % 2 == 0)
                //{
                //    //first circle.
                //    px = d;
                //}
                //else
                //{
                //    px = y - d;
                //}


                RenderObj.ApplyShaderParam(x, y);
            }


            LastWorldPos = CurWorldPos;

            if (ElapsedTime > LifeTime && LifeTime > 0)
            {
                Reset();
                Remove();
            }
        }
Exemplo n.º 24
0
        protected void AddNodes(int num)
        {
            int added = 0;

            for (int i = 0; i < MaxENodes; i++)
            {
                if (added == num)
                {
                    break;
                }
                EffectNode node = AvailableENodes[i];
                if (node != null)
                {
                    AddActiveNode(node);
                    added++;

                    //activate on birth subemitter.
                    if (UseSubEmitters && !string.IsNullOrEmpty(BirthSubEmitter))
                    {
                        XffectComponent sub = SpawnCache.GetEffect(BirthSubEmitter);
                        if (sub == null)
                        {
                            return;
                        }

                        node.SubEmitter = sub;
                        sub.Active();
                    }


                    emitter.SetEmitPosition(node);
                    float nodeLife = 0;
                    if (IsNodeLifeLoop)
                    {
                        nodeLife = -1;
                    }
                    else
                    {
                        nodeLife = Random.Range(NodeLifeMin, NodeLifeMax);
                    }
                    Vector3 oriDir = emitter.GetEmitRotation(node);
                    float   speed  = OriSpeed;
                    if (IsRandomSpeed)
                    {
                        speed = Random.Range(SpeedMin, SpeedMax);
                    }

                    Color c = Color1;

                    if (IsRandomStartColor)
                    {
                        //c = RandomColorParam.GetGradientColor(Random.Range(0f, 1f));
                        c = RandomColorGradient.Evaluate(Random.Range(0f, 1f));
                    }

                    float oriScalex = Random.Range(OriScaleXMin, OriScaleXMax);
                    float oriScaley = Random.Range(OriScaleYMin, OriScaleYMax);

                    if (UniformRandomScale)
                    {
                        oriScaley = oriScalex;
                    }

                    node.Init(oriDir.normalized, speed, nodeLife, Random.Range(OriRotationMin, OriRotationMax),
                              oriScalex, oriScaley, c, UVTopLeft, UVDimension);
                }
                else
                {
                    continue;
                }
            }
        }
Exemplo n.º 25
0
        public void Update(float deltaTime)
        {
            ElapsedTime += deltaTime;

            if (isCollision && isBounce)
            {
                //Update color only not velocity and position
                for (int i = 0; i < AffectorList.Count; i++)
                {
                    Affector aft = AffectorList[i];
                    aft.Update(deltaTime);
                }
                UpdateBounce(deltaTime);
                //Position += Velocity * deltaTime;
                if (SyncClient)
                {
                    //NOTICE: only sync position.
                    CurWorldPos = Position + GetRealClientPos();
                }
                else
                {
                    CurWorldPos = Position;
                }
            }
            else
            {
                for (int i = 0; i < AffectorList.Count; i++)
                {
                    Affector aft = AffectorList[i];
                    aft.Update(deltaTime);
                }

                Position += Velocity * deltaTime;

                if (SyncClient)
                {
                    //NOTICE: only sync position.
                    CurWorldPos = Position + GetRealClientPos();
                }
                else
                {
                    CurWorldPos = Position;
                }

                CollisionDetection();
            }

            //sync subemitters position.
            if (Owner.UseSubEmitters && SubEmitter != null && XffectComponent.IsActive(SubEmitter.gameObject))
            {
                SubEmitter.transform.position = CurWorldPos;
            }


            if (Type == 1)
            {
                UpdateSprite(deltaTime);
            }
            else if (Type == 2)
            {
                UpdateRibbonTrail(deltaTime);
            }
            else if (Type == 3)
            {
                UpdateCone(deltaTime);
            }
            else if (Type == 4)
            {
                UpdateCustomMesh(deltaTime);
            }

            LastWorldPos = CurWorldPos;

            if (ElapsedTime > LifeTime && LifeTime > 0)
            {
                Reset();
                Remove();
            }
        }
Exemplo n.º 26
0
        public void Reset()
        {
            isCollision = false;
            isBounce    = false;

            //activate on death subemitter.
            if (Owner.UseSubEmitters && !string.IsNullOrEmpty(Owner.DeathSubEmitter))
            {
                XffectComponent sub = Owner.SpawnCache.GetEffect(Owner.DeathSubEmitter);
                if (sub == null)
                {
                    return;
                }
                sub.Active();
                sub.transform.position = CurWorldPos;
            }

            //Position = Vector3.up * -9999;
            //if (Owner.SpriteType == (int)STYPE.BILLBOARD_UP) {
            //	Position = Quaternion.Euler (new Vector3 (0, Owner.transform.rotation.eulerAngles.y, 0)) * Owner.EmitPoint + Owner.transform.position;
            //} else {
            Position = Owner.EmitPoint + Owner.transform.position;
            //}

            Velocity    = Vector3.zero;
            ElapsedTime = 0f;


            CurWorldPos = Owner.transform.position;

            LastWorldPos = CurWorldPos;

            IsCollisionEventSended = false;

            //foreach (Affector aft in AffectorList)
            //{
            //    aft.Reset();
            //}V

            //do not use foreach in your script!
            for (int i = 0; i < AffectorList.Count; i++)
            {
                Affector aft = AffectorList[i];
                aft.Reset();
            }

            Scale = Vector3.one;

            if (Type == 1)
            {
                Sprite.SetRotation(OriRotateAngle);
                Sprite.SetPosition(Position);
                Sprite.SetColor(Color.clear);
                Sprite.Update(true, 0f);
                //TODO:should reset in ScaleAffector.
                Scale = Vector3.one;
            }
            else if (Type == 2)
            {
                Vector3 headpos;
                if (Owner.AlwaysSyncRotation)
                {
                    headpos = ClientTrans.rotation * (GetRealClientPos() + Owner.EmitPoint);
                }
                else
                {
                    headpos = GetRealClientPos() + Owner.EmitPoint;
                }
                Ribbon.SetHeadPosition(headpos /*+ OriDirection.normalized * Owner.TailDistance*/);
                Ribbon.Reset();
                Ribbon.SetColor(Color.clear);
                Ribbon.UpdateVertices(Vector3.zero);
            }
            else if (Type == 3)
            {
                Cone.SetRotation(OriRotateAngle);
                Cone.SetColor(Color.clear);
                Cone.SetPosition(Position);
                Scale = Vector3.one;
                Cone.ResetAngle();
                Cone.Update(true, 0f);
            }
            else if (Type == 4)
            {
                CusMesh.SetColor(Color.clear);
                CusMesh.SetRotation(OriRotateAngle);
                CusMesh.Update(true, 0f);
            }


            if (Owner.UseSubEmitters && SubEmitter != null && XffectComponent.IsActive(SubEmitter.gameObject))
            {
                SubEmitter.StopEmit();
            }
        }
Exemplo n.º 27
0
        public void Update(float deltaTime)
        {
            ElapsedTime += deltaTime;


            //foreach (Affector aft in AffectorList)
            //{
            //    aft.Update(deltaTime);
            //}

            for (int i = 0; i < AffectorList.Count; i++)
            {
                Affector aft = AffectorList[i];
                aft.Update(deltaTime);
            }

            Position += Velocity * deltaTime;

            CollisionDetection();

            //if (Mathf.Abs(Acceleration) > 1e-04)
            //{
            //Velocity += Velocity.normalized * Acceleration * deltaTime;
            //}

            if (SyncClient)
            {
                //NOTICE: only sync position.
                CurWorldPos = Position + GetRealClientPos();
            }
            else
            {
                CurWorldPos = Position;
            }

            //sync subemitters position.
            if (Owner.UseSubEmitters && SubEmitter != null && XffectComponent.IsActive(SubEmitter.gameObject))
            {
                SubEmitter.transform.position = CurWorldPos;
            }


            if (Type == 1)
            {
                UpdateSprite(deltaTime);
            }
            else if (Type == 2)
            {
                UpdateRibbonTrail(deltaTime);
            }
            else if (Type == 3)
            {
                UpdateCone(deltaTime);
            }
            else if (Type == 4)
            {
                UpdateCustomMesh(deltaTime);
            }

            LastWorldPos = CurWorldPos;

            if (ElapsedTime > LifeTime && LifeTime > 0 && Owner.NotExpired == false)
            {
                Reset();
                Remove();
            }
        }
Exemplo n.º 28
0
        public void Update(float deltaTime)
        {
            ElapsedTime += deltaTime;
            for (int i = 0; i < AffectorList.Count; i++)
            {
                Affector aft = AffectorList[i];
                aft.Update(deltaTime);
            }

            Position += Velocity * deltaTime;



            //if (Mathf.Abs(Acceleration) > 1e-04)
            //{
            //Velocity += Velocity.normalized * Acceleration * deltaTime;
            //}

            if (SyncClient)
            {
                //NOTICE: only sync position.
                CurWorldPos = Position + GetRealClientPos();
            }
            else
            {
                CurWorldPos = Position;
            }


            CollisionDetection();

            //sync subemitters position.
            if (Owner.UseSubEmitters && SubEmitter != null && XffectComponent.IsActive(SubEmitter.gameObject))
            {
                SubEmitter.transform.position = CurWorldPos;
            }


            RenderObj.Update(deltaTime);

            if (Owner.UseShaderCurve2 || Owner.UseShaderCurve1)
            {
                float x = Owner.UseShaderCurve1 ? Owner.ShaderCurveX1.Evaluate(GetElapsedTime(), this) : 1f;

                float y = Owner.UseShaderCurve2 ? Owner.ShaderCurveX2.Evaluate(GetElapsedTime(), this) : 0f;

                RenderObj.ApplyShaderParam(x, y);
            }
            else if (Owner.UseFlowControl)
            {
                float x = Owner.FlowSpeed * GetElapsedTime();
                float y = Owner.FlowStretchLength;

                //float d = x % y;

                //float p = x / y;

                //float px = x;

                //if (Mathf.FloorToInt(p) % 2 == 0)
                //{
                //    //first circle.
                //    px = d;
                //}
                //else
                //{
                //    px = y - d;
                //}


                RenderObj.ApplyShaderParam(x, y);
            }


            LastWorldPos = CurWorldPos;

            if (ElapsedTime > LifeTime && LifeTime > 0)
            {
                Reset();
                Remove();
            }
        }
Exemplo n.º 29
0
        public void CollisionDetection()
        {
            if (!Owner.UseCollisionDetection || IsCollisionEventSended)
            {
                return;
            }

            bool collided = false;

            GameObject collideObject = null;

            if (Owner.CollisionType == COLLITION_TYPE.Sphere && Owner.CollisionGoal != null)
            {
                Vector3 diff  = CurWorldPos + Velocity.normalized * Owner.CollisionOffset - Owner.CollisionGoal.position;
                float   range = Owner.ColliisionPosRange + Owner.ParticleRadius;
                if (diff.sqrMagnitude <= range * range /*|| //fixed, don't check get through.
                                                        * Vector3.Dot(diff, LastCollisionDetectDir) < 0*/)
                {
                    collided      = true;
                    collideObject = Owner.CollisionGoal.gameObject;
                }
                LastCollisionDetectDir = diff;
            }
            else if (Owner.CollisionType == COLLITION_TYPE.CollisionLayer)
            {
                int layer = 1 << Owner.CollisionLayer;

                RaycastHit hit;
                Vector3    p1 = GetOriginalPos() + Velocity.normalized * Owner.CollisionOffset;
                if (Physics.SphereCast(p1, Owner.ParticleRadius, Velocity.normalized, out hit, Owner.ParticleRadius, layer))
                {
                    collided      = true;
                    collideObject = hit.collider.gameObject;
                }
            }
            else if (Owner.CollisionType == COLLITION_TYPE.Plane)
            {
                //Debug.Log("particle pos "+CurWorldPos+" nor "+Owner.PlaneDir.normalized+" "+Owner.ParticleRadius);
                //Debug.Log("plane "+Owner.CollisionPlane.distance+" "+Owner.CollisionPlane.normal+" pos ");
                //var realPos = CurWorldPos + Owner.transform.position;
                //var realPos = CurWorldPos;
                var realPos = this.Position;
                var np      = realPos - Owner.PlaneDir.normalized * Owner.ParticleRadius;

                /*
                 * if(realPos.y <= 0) {
                 *  Debug.Log("Collide: "+Owner.CollisionPlane.distance+" w "+CurWorldPos+" pos "+Owner.transform.position
                 +" np "+np+" emitPoint "+Owner.EmitPoint);
                 *  collided = true;
                 *  collideObject = Owner.gameObject;
                 * }
                 */

                if (!Owner.CollisionPlane.GetSide(np))
                {
                    Debug.Log("Collide: " + Owner.CollisionPlane.distance + " w " + CurWorldPos + " pos " + Owner.transform.position
                              + " np " + np + " emitPoint " + Owner.EmitPoint);
                    //var testP = new Plane(Vector3.up, Owner.transform.position);
                    //var side = testP.GetSide(np);
                    //Debug.Log("TestP: "+testP.distance+" n "+testP.normal+" np "+np+" si "+side);

                    collided      = true;
                    collideObject = Owner.gameObject;
                }
            }
            else
            {
                Debug.LogError("invalid collision type!");
            }

            if (collided)
            {
                if (Owner.EventHandleFunctionName != "" && Owner.EventReceiver != null)
                {
                    //Owner.EventReceiver.SendMessage(Owner.EventHandleFunctionName, Owner.CollisionGoal);
                    Owner.EventReceiver.SendMessage(Owner.EventHandleFunctionName, new CollisionParam(collideObject, GetOriginalPos(), this));
                    isCollision = true;
                }

                IsCollisionEventSended = true;
                if (Owner.CollisionAutoDestroy)
                {
                    //distroy.
                    ElapsedTime = Mathf.Infinity;
                }


                //activate on collision subemitter.
                if (Owner.UseSubEmitters && !string.IsNullOrEmpty(Owner.CollisionSubEmitter))
                {
                    XffectComponent sub = Owner.SpawnCache.GetEffect(Owner.CollisionSubEmitter);
                    if (sub == null)
                    {
                        return;
                    }
                    sub.Active();
                    sub.transform.position = CurWorldPos;
                }
            }
        }
Exemplo n.º 30
0
        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;
        }
Exemplo n.º 31
0
 public void Initialize( XffectComponent owner)
 {
     Owner = owner;
     switch (Type)
     {
         case XEventType.CameraShake:
             m_eventHandler = new CameraShakeEvent(this);
             break;
         case XEventType.Light:
             m_eventHandler = new LightEvent(this);
             break;
         case XEventType.Sound:
             m_eventHandler = new SoundEvent(this);
             break;
         case XEventType.CameraEffect:
             if (CameraEffectType == CameraEffectEvent.EType.ColorInverse)
             {
                 m_eventHandler = new ColorInverseEvent(this);
             }
             else if (CameraEffectType == CameraEffectEvent.EType.Glow)
             {
                 m_eventHandler = new GlowEvent(this);
             }
             else if (CameraEffectType == CameraEffectEvent.EType.GlowPerObj)
             {
                 m_eventHandler = new GlowPerObjEvent(this);
             }
             else if (CameraEffectType == CameraEffectEvent.EType.RadialBlur)
             {
                 m_eventHandler = new RadialBlurEvent(this);
             }
             else if (CameraEffectType == CameraEffectEvent.EType.RadialBlurMask)
             {
                 m_eventHandler = new RadialBlurTexAddEvent(this);
             }
             else if (CameraEffectType == CameraEffectEvent.EType.Glitch)
             {
                 m_eventHandler = new GlitchEvent(this);
             }
             break;
         case XEventType.TimeScale:
             m_eventHandler = new TimeScaleEvent(this);
             break;
         default:
             Debug.LogWarning("invalid event type!");
             break;
     }
     m_eventHandler.Initialize();
     m_elapsedTime = 0f;
     m_finished = false;
 }