Example #1
0
    private EffectObj createEffectObj(int effectId)
    {
        EffectObj obj = null;

        for (int idx = 0; idx < _effects.Count; ++idx)
        {
            EffectObj effect = _effects[idx];
            if (effect.resid == effectId && !effect.isUsing)
            {
                obj = effect;
                break;
            }
        }
        if (obj == null)
        {
            obj = new EffectObj();
            _effects.Add(obj);
            obj.resid = effectId;
        }
        if (obj.effect == null)
        {
            obj.effect     = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(effectId) as GameObject).transform;
            obj.animations = obj.effect.GetComponentsInChildren <Animation>(true);
            obj.animators  = obj.effect.GetComponentsInChildren <Animator>(true);
            obj.particles  = obj.effect.GetComponentsInChildren <ParticleSystem>(true);
        }
        return(obj);
    }
Example #2
0
 public void SetScaling(float scl)
 {
     ParticleSystem[] ps = EffectObj.GetComponentsInChildren <ParticleSystem>();
     for (int i = 0; i < ps.Length; ++i)
     {
         ps[i].startSize *= scl;
     }
 }
Example #3
0
 private void disableEffect(EffectObj obj)
 {
     if (obj.effect != null)
     {
         obj.effect.parent = null;
         obj.effect.gameObject.SetActive(false);
         obj.isUsing = false;
     }
 }
Example #4
0
 public void Clear()
 {
     for (int idx = 0; idx < _effects.Count; ++idx)
     {
         EffectObj obj = _effects[idx];
         if (obj.effect != null)
         {
             GameObject.Destroy(obj.effect.gameObject);
         }
     }
     _effects.Clear();
 }
        public GameObject BindLineEffectEx(string sEffect, string sDummy, float nPosX, float nPosY, float nPosZ, float fDecTime)
        {
            Transform oSelfDummy = GetDummyFromCache(sDummy);

            if (!oSelfDummy)
            {
                DebugMsg("BindLineEffectEx wrong sDummySelf:" + m_sName + "," + sDummy);
                return(null);
            }

            GameObject oLineObj = ResourceMgr.LoadAssetEx(sEffect, true);

            if (!oLineObj)
            {
                DebugMsg("BindLineEffectEx wrong sEffect:" + sEffect);
                return(null);
            }

            oLineObj.SetActive(false);
            Transform trTempDy = transform.Find("Temp_Dummy");

            if (!trTempDy)
            {
                GameObject goTempDy = new GameObject("Temp_Dummy");
                trTempDy = goTempDy.transform;
                trTempDy.SetParent(transform);
            }
            trTempDy.transform.position = oSelfDummy.position;

            float     fGraphPosZ = SceneMgr.Instance.GetGraphicsPosZ(nPosY);
            Vector3   v3TarPos   = new Vector3(nPosX, nPosY, fGraphPosZ);
            Transform oLineTrans = oLineObj.transform;
            float     fOffsetY   = transform.InverseTransformPoint(oSelfDummy.position).y;
            Vector3   v3Offset   = fOffsetY * transform.up.normalized;

            oLineTrans.position = v3TarPos + v3Offset;
            oLineTrans.LookAt(trTempDy.transform.position);
            oLineTrans.SetParent(trTempDy.transform);

            float nLineLen = Vector3.Distance(oSelfDummy.position, v3TarPos);

            UIMgr.Instance.SetAllLineRenderer(oLineObj, nLineLen / 10);
            oLineObj.SetActive(true);

            EffectObj oEffObj = new EffectObj(oLineTrans, transform, trTempDy, v3Offset, nLineLen);

            m_tEffectObj.Add(oLineObj.GetInstanceID(), oEffObj);

            return(oLineObj);
        }
Example #6
0
 public void RemoveEffect(FightUnit owner, int effectId)
 {
     for (int idx = 0; idx < _effects.Count; ++idx)
     {
         EffectObj obj = _effects[idx];
         if (!obj.isUsing)
         {
             continue;
         }
         if (obj.owner == owner && obj.resid == effectId)
         {
             disableEffect(obj);
         }
     }
 }
Example #7
0
    /// <summary>
    /// 创建一个特效,并且放在指定位置
    /// </summary>
    /// <param name="effectId">特效id</param>
    /// <param name="pos">位置,localpos</param>
    /// <param name="parent">父物体</param>
    public GameObject CreateEffect(FightUnit owner, int effectId, Vector3 pos, Quaternion rot, bool loop, Transform parent = null, float speed = 1)
    {
        EffectObj obj = createEffectObj(effectId);

        obj.SetSpeed(speed);
        obj.effect.parent        = parent;
        obj.effect.localPosition = pos;
        obj.effect.localRotation = rot;
        obj.effect.localScale    = Vector3.one;
        obj.effect.gameObject.SetActive(true);
        obj.accTime = 0;
        obj.isUsing = true;
        obj.loop    = loop;
        obj.owner   = owner;
        return(obj.effect.gameObject);
    }
Example #8
0
    public GameObject CreateFlyEffect(FightUnit owner, int effectId, Quaternion rot, Vector3 des, float time, float playSpeed = 1)
    {
        EffectObj obj = createEffectObj(effectId);

        obj.SetSpeed(playSpeed);
        obj.Destination = des;
        Vector3 original = new Vector3(owner.CurPos.x, 0, owner.CurPos.y);

        obj.effect.localPosition = original;
        obj.effect.localRotation = rot;
        obj.FlySpeed             = (des - original).magnitude / (time != 0 ? time : 1);
        obj.effect.localScale    = Vector3.one;
        obj.effect.gameObject.SetActive(true);
        obj.accTime = 0;
        obj.isUsing = true;
        obj.loop    = false;
        obj.owner   = owner;
        return(obj.effect.gameObject);
    }
Example #9
0
    // Cast the skill with the given index
    public void Cast(int index)
    {
        if (index < character.skills.Count && index >= 0)
        {
            Debug.Log("Casting skill #" + index);
            eventManager.AddEventHandler("OnCastEnd", OnCastEnd);

            castObj.SetActive(true);
            Debug.Log(character.skills[index].castOffset + "");
            castObj.transform.localPosition = character.skills[index].castOffset;

            EffectObj eo = castObj.GetComponent <EffectObj>();
            eo.eventName    = "OnCastEnd";
            eo.characterObj = this;

            string   castEffect = character.skills[index].castEffect;
            Animator anim       = castObj.GetComponent <Animator>();
            anim.Play(castEffect);
        }
    }
Example #10
0
 private void checkEffect(float delta)
 {
     for (int idx = 0; idx < _effects.Count; ++idx)
     {
         EffectObj obj = _effects[idx];
         if (obj.owner != null)
         {
             obj.Pause = FightLogic.Instance.UnitPause && !obj.owner.IsUsingActiveSkill;
         }
         if (!obj.isUsing || obj.loop || obj.Pause)
         {
             continue;
         }
         obj.accTime += delta;
         if (obj.accTime >= obj.LifeTime)
         {
             disableEffect(obj);
         }
     }
 }
Example #11
0
 private void flyEffect(float delta)
 {
     for (int idx = 0; idx < _effects.Count; ++idx)
     {
         EffectObj obj = _effects[idx];
         if (!obj.isUsing || obj.Pause || obj.Destination == Vector3.zero)
         {
             continue;
         }
         float deltaDis = obj.FlySpeed * delta;
         if ((obj.Destination - obj.effect.position).magnitude <= deltaDis)
         {
             obj.effect.position = obj.Destination;
             return;
         }
         else
         {
             Vector3 dir = (obj.Destination - obj.effect.transform.localPosition).normalized;
             obj.effect.transform.localPosition += dir * deltaDis;
         }
     }
 }
Example #12
0
        public GameObject BindLineEffect(string sEffect, GameObject oTarget, string sSelfDummy, string sTarDummy, float nEffTime)
        {
            RenderObj oTarRenObj = oTarget.GetComponent <RenderObj>();

            if (!oTarRenObj)
            {
                DebugMsg("Target is NOT a Character:" + oTarget.name);
                return(null);
            }

            Transform oTarDummy = oTarRenObj.GetDummyFromCache(sTarDummy);

            if (!oTarDummy)
            {
                DebugMsg("BindLineEffect wrong sDummyTarget:" + m_sName + "," + sTarDummy);
                return(null);
            }

            Transform oSelfDummy = GetDummyFromCache(sSelfDummy);

            if (!oSelfDummy)
            {
                DebugMsg("BindLineEffect wrong sDummySelf:" + m_sName + "," + sSelfDummy);
                return(null);
            }

            GameObject oLineObj = ResourceMgr.LoadAssetEx(sEffect, true);

            if (!oLineObj)
            {
                DebugMsg("BindLineEffect wrong sEffect:" + sEffect);
                return(null);
            }

            oLineObj.SetActive(false);
            Transform trTempDy = transform.Find("Temp_Dummy");

            if (!trTempDy)
            {
                GameObject goTempDy = new GameObject("Temp_Dummy");
                trTempDy = goTempDy.transform;
                trTempDy.SetParent(transform);
            }
            trTempDy.transform.position = oSelfDummy.position;

            Transform oLineTrans = oLineObj.transform;

            oLineTrans.position = oTarDummy.position;
            float   fOffsetY = transform.InverseTransformPoint(oSelfDummy.position).y;
            Vector3 v3Offset = fOffsetY * transform.up.normalized;

            UIMgr.Instance.SetAllLineRenderer(oLineObj, 1 / 10);
            oLineTrans.LookAt(trTempDy.transform.position);
            oLineTrans.SetParent(trTempDy.transform);
            oLineObj.SetActive(true);

            EffectObj oEffObj = new EffectObj(oLineTrans, transform, trTempDy, oTarDummy, v3Offset, nEffTime / 1000);

            m_tEffectObj.Add(oLineObj.GetInstanceID(), oEffObj);
            return(oLineObj);
        }