Ejemplo n.º 1
0
 void InitHitBox()
 {
     for (int i = 0; i < weaponDamage.Count; i++)
     {
         FightBox fb = weaponDamage[i].gameObject.AddComponent <FightBox>();
         fb.Init(owner, null);
         //角色有刚体,可以由角色驱动.
     }
 }
Ejemplo n.º 2
0
 //是否开启武器触发器,用于打碎瓶子罐子,等场景物件,与部分只响应攻击的
 public void ChangeAttack(bool open)
 {
     for (int i = 0; i < weaponDamage.Count; i++)
     {
         if (weaponDamage[i] == null)
         {
             continue;
         }
         if (weaponDamage[i].enabled != open)
         {
             weaponDamage[i].enabled = open;
             FightBox fb = weaponDamage[i].GetComponent <FightBox>();
             if (fb != null)
             {
                 fb.ChangeAttack(open);
             }
         }
     }
 }
Ejemplo n.º 3
0
    //public void SaveParticle(string file)
    //{
    //    if (source != null && source.particle != null)
    //    {
    //        System.IO.FileStream fs = System.IO.File.OpenWrite(file);
    //        System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
    //        w.Write(source.particle);
    //        w.Flush();
    //        w.Close();
    //        fs.Close();
    //    }
    //}

    //原粒子系统是右手坐标系的,转移到左手坐标系后非常多问题,特别是父子关系以及,跟随和子物体旋转叠加
    public void Init(SfxEffect effect, SFXEffectPlay parent, int index, float timePlayed, bool preLoad = false)
    {
        playedTime         = timePlayed;
        PlayDone           = false;
        transform.rotation = Quaternion.identity;
        effectIndex        = index;
        parentSfx          = parent;//当找不到跟随者的时候,向父询问其他特效是否包含此名称.
        name       = effect.EffectName;
        EffectType = effect.EffectType;
        //一个是跟随移动,一个是跟随旋转
        mOwner = parent.GetComponent <MeteorUnit>();
        source = effect;
        if (effect.EffectType.Equals("PARTICLE"))
        {
            particle = Instantiate(Resources.Load <GameObject>("SFXParticles"), Vector3.zero, Quaternion.identity, transform).GetComponent <ParticleSystem>();
            ParticleSystem.MainModule              mainModule     = particle.main;
            ParticleSystem.EmissionModule          emissionModule = particle.emission;
            ParticleSystem.ShapeModule             shapeModule    = particle.shape;
            ParticleSystem.ForceOverLifetimeModule force          = particle.forceOverLifetime;

            emissionModule.rateOverTime          = new ParticleSystem.MinMaxCurve(effect.MaxParticles, effect.MaxParticles);
            mainModule.startLifetime             = new ParticleSystem.MinMaxCurve(effect.StartLifetime, effect.StartLifetime2);
            mainModule.maxParticles              = effect.MaxParticles;
            mainModule.startSize3D               = false;
            mainModule.startSize                 = new ParticleSystem.MinMaxCurve(effect.startSizeMin, effect.startSizeMax);
            mainModule.startSpeed                = new ParticleSystem.MinMaxCurve(effect.Speed, effect.Speed);
            mainModule.loop                      = effect.particleNotLoop == 0;
            mainModule.duration                  = effect.frames[effect.FrameCnt - 1].startTime;
            mainModule.gravityModifierMultiplier = effect.gravity;



            //96字节
            if (effect.ParticleBytes == 96)
            {
            }
            //124字节的,烟雾特效,旋转角度 0-360,shape使用box, render使用billboard
            else if (effect.ParticleBytes == 124)
            {
                mainModule.startRotation3D = effect.EnableParticleRotate == 1;
                if (mainModule.startRotation3D)
                {
                    mainModule.startRotationX = effect.RotateAxis.x;
                    mainModule.startRotationY = effect.RotateAxis.y;
                    mainModule.startRotationZ = effect.RotateAxis.z;
                }
                mainModule.startRotation = new ParticleSystem.MinMaxCurve(effect.HRotateSpeed, effect.VRotateSpeed);

                shapeModule.shapeType = ParticleSystemShapeType.Box;
                shapeModule.scale     = new Vector3(effect.startSizeMin, 0, effect.startSizeMax);
                //shapeModule.box = new Vector3(effect.emitWidth, 0, effect.emitLong);
                ParticleSystemRenderer r = particle.GetComponent <ParticleSystemRenderer>();
                r.renderMode      = ParticleSystemRenderMode.Billboard;
                r.minParticleSize = 0.1f;
                r.maxParticleSize = 0.1f;
            }
            //112字节的,
            else if (effect.ParticleBytes == 112)
            {
            }
        }

        if (string.IsNullOrEmpty(effect.Bone0))
        {
            PositionFollow = mOwner == null ? parentSfx.transform : mOwner.transform;
        }
        else
        if (effect.Bone0.Equals("ROOT"))
        {
            PositionFollow = mOwner == null ? parent.transform : mOwner.ROOTNull;
        }
        else if (effect.Bone0.Equals("Character"))//根骨骼上一级,角色,就是不随着b骨骼走,但是随着d_base走
        {
            PositionFollow = mOwner == null ? parent.transform: mOwner.RootdBase;
        }
        else
        {
            PositionFollow = FindFollowed(effect.Bone0);
        }

        if (string.IsNullOrEmpty(effect.Bone1))
        {
            RotateFollow = mOwner == null ? parent.transform : mOwner.transform;
        }
        else
        if (effect.Bone1.Equals("ROOT"))
        {
            RotateFollow = mOwner == null ? parent.transform : mOwner.ROOTNull;
        }
        else if (effect.Bone1.Equals("Character"))
        {
            RotateFollow = mOwner == null ? parent.transform : mOwner.RootdBase;
        }
        else
        {
            RotateFollow = FindFollowed(effect.Bone1);
        }

        if (PositionFollow != null)
        {
            transform.position = PositionFollow.transform.position;
        }

        mRender = gameObject.GetComponent <MeshRenderer>();
        mFilter = gameObject.GetComponent <MeshFilter>();
        int meshIndex = -1;

        //部分模型是要绕X旋转270的,这样他的缩放,和移动,都只能靠自己
        if (effect.EffectType.Equals("PLANE"))
        {
            meshIndex = 0;
        }
        else if (effect.EffectType.Equals("BOX"))
        {
            meshIndex = 1;
        }
        else if (effect.EffectType.Equals("DONUT"))
        {
            transform.localScale = effect.frames[0].scale;
            meshIndex            = 2;
        }
        else if (effect.EffectType.Equals("MODEL"))//自行加载模型
        {
            transform.localScale = effect.frames[0].scale;
            transform.rotation   = RotateFollow.rotation * effect.frames[0].quat;
            transform.position   = PositionFollow.position + effect.frames[0].pos;
            if (!string.IsNullOrEmpty(effect.Tails[0]))
            {
                string[] des = effect.Tails[0].Split(new char[] { '\\' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (des.Length != 0)
                {
                    Utility.ShowMeteorObject(des[des.Length - 1], transform);
                }
            }
            //这个时候,不要用自带的meshfilter了,让他自己处理显示问题,只要告诉他在哪个地方显示
            meshIndex = 100;
        }
        else if (effect.EffectType.Equals("SPHERE"))
        {
            meshIndex = 3;
        }
        else if (effect.EffectType.Equals("PARTICLE"))
        {
            if (!string.IsNullOrEmpty(effect.Tails[0]))
            {
                PositionFollow = FindFollowed(effect.Tails[0]);
            }
            if (!string.IsNullOrEmpty(effect.Tails[1]))
            {
                RotateFollow = FindFollowed(effect.Tails[1]);
            }
            if (PositionFollow != null)
            {
                transform.position = PositionFollow.transform.position;
            }
            meshIndex = 101;
        }
        else if (effect.EffectType.Equals("CYLINDER"))
        {
            meshIndex = 4;
        }
        else if (effect.EffectType.Equals("BILLBOARD"))
        {
            LookAtC   = true;
            meshIndex = 5;
        }
        else if (effect.EffectType.Equals("DRAG"))
        {
            meshIndex = 6;
        }
        //决定模型
        if (meshIndex != -1 && meshIndex < GamePool.Instance.MeshMng.Meshes.Length)
        {
            if (meshIndex == 4)
            {
                mFilter.mesh = SfxMeshGenerator.Ins.CreateCylinder(source.origAtt.y, source.origAtt.x, source.origScale.x);
            }
            else if (meshIndex == 3)
            {
                mFilter.mesh = SfxMeshGenerator.Ins.CreateSphere(source.SphereRadius);
            }
            else if (meshIndex == 0)
            {
                mFilter.mesh = SfxMeshGenerator.Ins.CreatePlane(source.origScale.x, source.origScale.y);
            }
            //else if (meshIndex == 1)
            //    mFilter.mesh = SfxMeshGenerator.Ins.CreateBox(source.origScale.x, source.origScale.y, source.origScale.z);
            else
            {
                mFilter.mesh = GamePool.Instance.MeshMng.Meshes[meshIndex];
            }
        }
        if (effect.Texture.ToLower().EndsWith(".bmp") || effect.Texture.ToLower().EndsWith(".jpg") || effect.Texture.ToLower().EndsWith(".tga"))
        {
            texture = effect.Texture.Substring(0, effect.Texture.Length - 4);
            tex     = Resources.Load <Texture>(texture);
        }
        else if (effect.Texture.ToLower().EndsWith(".ifl"))
        {
            iflTexture         = gameObject.AddComponent <IFLLoader>();
            iflTexture.IFLFile = Resources.Load <TextAsset>(effect.Texture);
            if (effect.EffectType.Equals("PARTICLE"))
            {
                iflTexture.SetTargetMeshRenderer(particle.GetComponent <ParticleSystemRenderer>());
            }
            iflTexture.LoadIFL();//传递false表示由特效控制每一帧的切换时间.
            tex = iflTexture.GetTexture(0);
        }
        //else
        //    print("effect contains other prefix:" + effect.Texture == null ? " texture is null" : effect.Texture);
        if (tex != null)
        {
            if (effect.EffectType.Equals("PARTICLE"))
            {
                ParticleSystemRenderer render = particle.GetComponent <ParticleSystemRenderer>();
                if (effect.BlendType == 0)
                {
                    render.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照
                }
                else
                if (effect.BlendType == 1)
                {
                    render.material.shader = Shader.Find("UnlitAdditive");//滤色 加亮 不透明
                }
                else
                if (effect.BlendType == 2)
                {
                    render.material.shader = Shader.Find("UnlitAdditive");//反色+透明度
                }
                else if (effect.BlendType == 3)
                {
                    render.material.shader = Shader.Find("Mobile/Particles/Alpha Blended");//不滤色,支持透明
                }
                else if (effect.BlendType == 4)
                {
                    render.material.shader = Shader.Find("Custom/MeteorBlend4");//滤色,透明
                }
                else
                {
                    render.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照
                }
                if (texture.Equals("AItem09"))
                {
                    render.enabled = false;
                    particle.Stop();

                    /* 应该是有一个地裂的粒子特效,但是这个特效参数没分析出来.
                     *  tex = Resources.Load<Texture>("AItemParticle");
                     *  render.material.SetTexture("_MainTex", tex);
                     */
                }
                else
                {
                    render.material.SetTexture("_MainTex", tex);
                }
                render.material.SetColor("_Color", effect.frames[0].colorRGB);
                render.material.SetColor("_TintColor", effect.frames[0].colorRGB);
                render.material.SetFloat("_Intensity", effect.frames[0].TailFlags[9]);
                if (GameStateMgr.Ins.gameStatus != null && !GameStateMgr.Ins.gameStatus.DisableParticle)
                {
                    particle.Play();
                }
            }
            else
            {
                if (effect.BlendType == 0)
                {
                    mRender.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照
                }
                else
                if (effect.BlendType == 1)
                {
                    mRender.material.shader = Shader.Find("UnlitAdditive");//滤色 加亮 不透明
                }
                else
                if (effect.BlendType == 2)
                {
                    mRender.material.shader = Shader.Find("UnlitAdditive");//反色+透明度
                }
                else if (effect.BlendType == 3)
                {
                    mRender.material.shader = Shader.Find("Mobile/Particles/Alpha Blended");//不滤色,支持透明
                }
                else if (effect.BlendType == 4)
                {
                    mRender.material.shader = Shader.Find("Custom/MeteorBlend4");//滤色,透明
                }
                else
                {
                    mRender.material.shader = Shader.Find("Unlit/Texture");//普通不透明无光照
                }
                if (effect.BlendType == 2)
                {
                    mRender.material.SetColor("_InvColor", effect.frames[0].colorRGB);
                }
                else
                {
                    mRender.material.SetColor("_Color", effect.frames[0].colorRGB);
                    mRender.material.SetColor("_TintColor", effect.frames[0].colorRGB);
                }
                mRender.material.SetFloat("_Intensity", effect.frames[0].TailFlags[9]);
                mRender.material.SetTexture("_MainTex", tex);
                if (effect.uSpeed != 0.0f || effect.vSpeed != 0.0f)
                {
                    tex.wrapMode = TextureWrapMode.Repeat;
                }
                else
                {
                    tex.wrapMode = TextureWrapMode.Clamp;
                }
                mRender.material.SetFloat("_u", effect.uSpeed);
                mRender.material.SetFloat("_v", effect.vSpeed);
            }
        }
        else
        {
            mRender.enabled = false;
        }
        //drag不知道有什么作用,可能只是定位用的挂载点
        if (effect.Hidden == 1 || meshIndex == 6)
        {
            if (particle != null)
            {
                ParticleSystemRenderer render = particle.GetComponent <ParticleSystemRenderer>();
                if (render != null)
                {
                    render.enabled = false;
                }
            }
            mRender.enabled = false;
        }
        if (effect.EffectName.StartsWith("Attack"))
        {
            if (effect.EffectType.ToUpper() == "BOX")
            {
                BoxCollider bo = gameObject.AddComponent <BoxCollider>();
                //bo.center = Vector3.zero;
                //bo.size = Vector3.one;
                damageBox           = bo;
                damageBox.isTrigger = true;
            }
            //} else if (effect.EffectType.ToUpper() == "PLANE") {
            //    BoxCollider bo = gameObject.AddComponent<BoxCollider>();
            //    //bo.center = Vector3.zero;
            //    //bo.size = source.origScale;
            //    damageBox = bo;
            //}
            else
            {
                //SphereCollider sph = gameObject.AddComponent<SphereCollider>();
                //damageBox = sph;
                //sph.radius = 1.0f;
                //sph.center = Vector3.zero;
                //Debug.LogError("Attack Effect Create MeshCollider");
                MeshCollider co = gameObject.AddComponent <MeshCollider>();
                co.convex    = true;
                co.isTrigger = true;
                damageBox    = co;
                //Debug.LogError("attackBox not Box:" + name);
            }
            hitBox = gameObject.AddComponent <FightBox>();
            //多个子特效是可以打到多次的,由子特效存储攻击到的目标,决定后续是否能再击中
            hitBox.Init(mOwner, null);
            damageBox.enabled = false;
            if (U3D.showBox)
            {
                BoundsGizmos.Instance.AddCollider(damageBox);
                BoundsGizmos.Instance.AddTransform(transform);
            }
        }

        if (preLoad)
        {
            PlayDone = true;
            if (parentSfx != null)
            {
                parentSfx.OnPlayDone(this);
            }
            else
            {
                Destroy(gameObject);
            }
            return;
        }
    }