Inheritance: MonoBehaviour
Beispiel #1
0
    public override void Start()
    {
        base.Start();

        behaviorFunc[(int)BossBehaviorKind.Run]         = Run;
        behaviorFunc[(int)BossBehaviorKind.MeleeAttack] = MeleeAttack;
        behaviorFunc[(int)BossBehaviorKind.Laser]       = ShootLaser;
        behaviorFunc[(int)BossBehaviorKind.Ball]        = FireBalls;
        behaviorFunc[(int)BossBehaviorKind.Spawn]       = SpawnMobs;
        behaviorFunc[(int)BossBehaviorKind.Curse]       = CursePlayer;

        sqrAttRad = attRad * attRad;

        wand = GetComponentInChildren <MeleeWeapon>();
        wand.SetDamage(damage);
        trail = GetComponentInChildren <WeaponTrail>();
        trail.SetColor(Color.blue);

        colliderRad = GetComponent <CapsuleCollider>().radius;

        mobSpawnPts = FindObjectsOfType <MobSpawnPt>();
        movePts     = FindObjectsOfType <BossMovePt>();

        selector = new Selector();
        selector.Add(BossBehaviorKind.Run, 9);
        selector.Add(BossBehaviorKind.MeleeAttack, 10);
        selector.Add(BossBehaviorKind.Laser, 5);
        selector.Add(BossBehaviorKind.Ball, 9);
        selector.Add(BossBehaviorKind.Spawn, 4);
        selector.Add(BossBehaviorKind.Curse, 6);

        InitPostProcessing();

        rIndicator.Init(laserLength, Color.blue, 15);
    }
Beispiel #2
0
 public void AddTrail(WeaponTrail trail)
 {
     if (!weaponTrails.Contains(trail))
     {
         weaponTrails.Add(trail);
     }
 }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        ani = GetComponent <AnimationController> ();

        trail = Instantiate(Resources.Load <GameObject>("particles/newWeaponTrail")) as GameObject;
        var rightHand = ChuMeng.Util.FindChildRecursive(transform, "Point001");

        if (rightHand != null)
        {
            trail.transform.parent        = rightHand;
            trail.transform.localPosition = Vector3.zero;
            trail.transform.localScale    = Vector3.one;
            //X Rotate 90 For New Game Model
            //模型的挂点的z轴向上 因此需要调整 weaponTrail 的Y轴和模型z轴一致
            trail.transform.localRotation = Quaternion.Euler(90, 0, 0);
        }
        //GetComponent<AnimationController>().AddTrail(trail.GetComponent<WeaponTrail>());

        wt = trail.GetComponent <WeaponTrail>();
        wt.SetTime(0, 0, 1);
        trail.SetActive(true);
        ani.AddTrail(wt);

        StartCoroutine(PlayNow());
    }
Beispiel #4
0
    public override void Start()
    {
        base.Start();

        sqrAttRad = attRad * attRad;

        fsm    = GetComponent <FSM>();
        trail  = GetComponentInChildren <WeaponTrail>();
        weapon = GetComponentInChildren <MeleeWeapon>();
        weapon.SetDamage(swordDamage);
    }
Beispiel #5
0
    protected override void OnInit(object userData)
    {
        base.OnInit(userData);

        msgText = this.gameObject.GetComponentInChildren <TextMesh> ();;
        GameObject  weaponTrailObj = GameObject.FindGameObjectWithTag("WeaponTrail");
        WeaponTrail weaponTrail    = weaponTrailObj.GetOrAddComponent <WeaponTrail> ();

        weaponTrail.height = 0.6f;
        weaponTrail.time   = 0.3f;

        weaponTrailController = new WeaponTrialController(weaponTrail);
    }
Beispiel #6
0
    private void initWeaponTrail()
    {
        if (weaponTrailGo != null)
        {
            weaponTrail                     = weaponTrailGo.AddComponent <WeaponTrail>();
            weaponTrail.height              = 0.2f;
            weaponTrail.time                = 0.6f;
            weaponTrail.minDistance         = 0.1f;
            weaponTrail.timeTransitionSpeed = 1f;
            weaponTrail.desiredTime         = 0.5f;

            loadWeaponTrailMat();
        }
    }
Beispiel #7
0
 public void Awake()
 {
     isReleased         = false;
     onGround           = true;
     sr                 = GetComponent <SpriteRenderer>();
     trail              = GetComponent <Trails>().trail;
     sj2d               = GetComponent <SpringJoint2D>();
     r2d                = GetComponent <Rigidbody2D>();
     sj2d.connectedBody = GameObject.Find("Right").GetComponent <Rigidbody2D>();
     lrRight            = GameObject.Find("Right").GetComponent <LineRenderer>();
     lrLeft             = GameObject.Find("Left").GetComponent <LineRenderer>();
     rightPos           = GameObject.Find("RightPos").transform;
     leftPos            = GameObject.Find("LeftPos").transform;
 }
Beispiel #8
0
    private void initWeaponTrail()
    {
        if(weaponTrailGo != null)
        {
            weaponTrail = weaponTrailGo.AddComponent<WeaponTrail>();
            weaponTrail.height = 0.2f;
            weaponTrail.time = 0.6f;
            weaponTrail.minDistance = 0.1f;
            weaponTrail.timeTransitionSpeed = 1f;
            weaponTrail.desiredTime = 0.5f;

            loadWeaponTrailMat();
        }
    }
    //LineRenderer line;
    public void LoadAttack(InventoryItem weapon, MeteorUnit target, AttackDes attackdef, MeteorUnit Owner)
    {
        //line = gameObject.AddComponent<LineRenderer>();
        //line.startWidth = 1f;
        //line.endWidth = 1f;
        //line.numPositions = 200;
        owner       = Owner;
        _attack     = attackdef;
        auto_target = target;
        WeaponRoot  = new GameObject().transform;
        WeaponRoot.SetParent(transform);
        WeaponRoot.localPosition    = Vector3.zero;
        WeaponRoot.localScale       = Vector3.one;
        WeaponRoot.localRotation    = Quaternion.Euler(0, 0, 0);
        WeaponRoot.name             = "WeaponRoot";
        WeaponRoot.gameObject.layer = gameObject.layer;
        Weapon = weapon;
        //计算控制点
        spline.SetControlPoint(0, transform.position);
        InitSpline();
        //List<Vector3> veclst = spline.GetEquiDistantPointsOnCurve(200);
        //line.SetPositions(veclst.ToArray());
        tTotal = spline.GetLength() / speed;
        //Debug.LogError("tTotal Init:" + tTotal + " length:" + spline.GetLength() + " speed:" + speed);
        LoadWeapon();
        //增加拖尾
        GameObject trailS = NodeHelper.Find("d_wpnRS", this.gameObject);
        GameObject trailE = NodeHelper.Find("d_wpnRE", this.gameObject);

        Trail = gameObject.AddComponent <WeaponTrail>();
        if (trailS != null)
        {
            Trail.AddTransform(trailS.transform);
        }
        if (trailE != null)
        {
            Trail.AddTransform(trailE.transform);
        }
        Trail.Init(Owner);
        Trail.Open();
        MeshRenderer mr = gameObject.GetComponentInChildren <MeshRenderer>();

        if (mr != null)
        {
            BoxCollider bc = mr.gameObject.AddComponent <BoxCollider>();
            bc.isTrigger = true;
            bc.size      = new Vector3(10, 5, 10);
        }
    }
    void LateUpdate()
    {
        if (characterAnim.doBaseSkill1)
        {
            currentWeaponTrail = baseSkill_Trail1;
        }
        else if (characterAnim.doBaseSkill2)
        {
            currentWeaponTrail = baseSkill_Trail2;
        }
        else if (characterAnim.doSkill1)
        {
            currentWeaponTrail = Skill_Trail1;
        }
        else if (characterAnim.doSkill2)
        {
            currentWeaponTrail = Skill_Trail2;
        }
        else if (characterAnim.doSkill3)
        {
            currentWeaponTrail = Skill_Trail3;
        }

        t = Mathf.Clamp(Time.deltaTime, 0, 0.066f);

        if (t > 0)
        {
            while (tempT < t)
            {
                tempT += animationIncrement;

                if (currentWeaponTrail.time > 0)
                {
                    currentWeaponTrail.Itterate(Time.time - t + tempT);
                }
                else
                {
                    currentWeaponTrail.ClearTrail();
                }
            }

            tempT -= t;

            if (currentWeaponTrail.time > 0)
            {
                currentWeaponTrail.UpdateTrail(Time.time, t);
            }
        }
    }
Beispiel #11
0
 public WeaponTrail GetAttackTail()
 {
     if (pAttackTrail == null)
     {
         for (int i = 0; i < trails.Count; i++)
         {
             if (trails[i].name == "attack")
             {
                 pAttackTrail = trails[i];
                 break;
             }
         }
     }
     return(pAttackTrail);
 }
Beispiel #12
0
        private void PlayTrails(ParticleSystem particle)
        {
            TrailRenderer component = particle.gameObject.GetComponent <TrailRenderer>();

            if (component != null)
            {
                component.enabled = true;
                component.time    = -component.time;
                this.trailToClear = component;
            }
            WeaponTrail component2 = particle.gameObject.GetComponent <WeaponTrail>();

            if (component2 != null)
            {
                component2.Restart();
            }
        }
        private void SetupAbilityViewEffects(DeployedTroop deployedTroop, TroopAbilityVO abilityVO)
        {
            GameObjectViewComponent gameObjectViewComp = deployedTroop.Entity.GameObjectViewComp;

            if (gameObjectViewComp == null)
            {
                return;
            }
            WeaponTrail componentInChildren = gameObjectViewComp.MainGameObject.GetComponentInChildren <WeaponTrail>();

            if (componentInChildren != null)
            {
                deployedTroop.WeaponTrail = componentInChildren;
                float[] weaponTrailFxParams = abilityVO.WeaponTrailFxParams;
                if (weaponTrailFxParams != null && weaponTrailFxParams.Length >= 2)
                {
                    deployedTroop.WeaponTrailActivateLifetime   = weaponTrailFxParams[0];
                    deployedTroop.WeaponTrailDeactivateLifetime = weaponTrailFxParams[1];
                }
            }
        }
Beispiel #14
0
    private void SetupModels()
    {
        if (PlayerPrefs.HasKey("Hair"))
        {
            for (int i = 0; i < modelHairs.Length; ++i)
            {
                if (PlayerPrefs.GetInt("Hair") == i)
                {
                    modelHairs[i].SetActive(true);
                }
                else
                {
                    Destroy(modelHairs[i]);
                }
                modelHairs[i] = null;
            }
        }
        else
        {
            modelHairs[0].SetActive(true);
        }
        if (PlayerPrefs.HasKey("Cloth"))
        {
            for (int i = 0; i < modelCloths.Length; ++i)
            {
                if (PlayerPrefs.GetInt("Cloth") == i)
                {
                    modelCloths[i].SetActive(true);
                }
                else
                {
                    Destroy(modelCloths[i]);
                }
                modelCloths[i] = null;
            }
        }
        else
        {
            modelCloths[0].SetActive(true);
        }
        if (PlayerPrefs.HasKey("Sword"))
        {
            int swordIdx = PlayerPrefs.GetInt("Sword");
            for (int i = 0; i < modelSwords.Length; ++i)
            {
                if (swordIdx == i)
                {
                    modelSwords[i].obj.SetActive(true);
                }
                else
                {
                    Destroy(modelSwords[i].obj);
                    modelSwords[i].obj     = null;
                    modelSwords[i].skillPt = null;
                }
            }

            trail  = modelSwords[swordIdx].obj.GetComponentInChildren <WeaponTrail>();
            weapon = modelSwords[swordIdx].obj.GetComponent <MeleeWeapon>();


            fireBallPt = modelSwords[swordIdx].skillPt;
        }
        else
        {
            trail  = modelSwords[0].obj.GetComponentInChildren <WeaponTrail>();
            weapon = modelSwords[0].obj.GetComponent <MeleeWeapon>();

            fireBallPt = modelSwords[0].skillPt;
            modelSwords[0].obj.SetActive(true);
        }
        if (PlayerPrefs.HasKey("ShoulderPad"))
        {
            for (int i = 0; i < modelShoulderPads.Length; ++i)
            {
                if (PlayerPrefs.GetInt("ShoulderPad") == i)
                {
                    modelShoulderPads[i].SetActive(true);
                }
                else
                {
                    Destroy(modelShoulderPads[i]);
                }
                modelShoulderPads[i] = null;
            }
        }
        else
        {
            modelShoulderPads[0].SetActive(true);
        }
    }
Beispiel #15
0
 public void RemoveTrail(WeaponTrail trail)
 {
     weaponTrails.Remove(trail);
 }
Beispiel #16
0
    //力量感很差,仅仅运行轨迹是一条曲线还是不行的。要有冲击感,要做变速/匀加速按固定轨迹运动,才行
    //因为贝塞尔通过时间计算曲线的某一位置,可以把时间参数模拟加快,做为变量
    //但是怎么去控制
    //LineRenderer line;
    public void LoadAttack(InventoryItem weapon, MeteorUnit target, AttackDes attackdef, MeteorUnit Owner)
    {
        //line = gameObject.AddComponent<LineRenderer>();
        //line.startWidth = 1f;
        //line.endWidth = 1f;
        //line.numPositions = 200;
        if (attackdef != null)
        {
            if (attackdef.PoseIdx == 218)
            {
                //轻力度
                speed = (normal_speed + max_speed) / 2;
            }
            else if (attackdef.PoseIdx == 220)
            {
                //中等力度
                speed = (middle_speed + max_speed) / 2;
            }
            else if (attackdef.PoseIdx == 222)
            {
                //超级力度
                speed = (super_speed + max_speed) / 2;
            }
        }
        owner       = Owner;
        _attack     = attackdef;
        auto_target = target;
        WeaponRoot  = new GameObject().transform;
        WeaponRoot.SetParent(transform);
        WeaponRoot.localPosition    = Vector3.zero;
        WeaponRoot.localScale       = Vector3.one;
        WeaponRoot.localRotation    = Quaternion.Euler(0, 0, 0);
        WeaponRoot.name             = "WeaponRoot";
        WeaponRoot.gameObject.layer = gameObject.layer;
        Weapon = weapon;
        //计算控制点
        spline.SetControlPoint(0, transform.position);
        InitSpline();
        //List<Vector3> veclst = spline.GetEquiDistantPointsOnCurve(200);
        //line.SetPositions(veclst.ToArray());
        totalTime = spline.GetLength() / speed;
        //float a = (max_speed - speed) / totalTime;
        //Debug.LogError("tTotal Init:" + tTotal + " length:" + spline.GetLength() + " speed:" + speed);
        LoadWeapon();
        //增加拖尾
        GameObject trailS = NodeHelper.Find("d_wpnRS", this.gameObject);
        GameObject trailE = NodeHelper.Find("d_wpnRE", this.gameObject);

        Trail = gameObject.AddComponent <WeaponTrail>();
        if (trailS != null)
        {
            Trail.AddTransform(trailS.transform);
        }
        if (trailE != null)
        {
            Trail.AddTransform(trailE.transform);
        }
        Trail.Init(Owner);
        Trail.Open();
        MeshRenderer mr = gameObject.GetComponentInChildren <MeshRenderer>();

        if (mr != null)
        {
            BoxCollider hitBox = mr.gameObject.AddComponent <BoxCollider>();
            hitBox.isTrigger = true;
            hitBox.size      = new Vector3(10, 5, 10);
            if (U3D.showBox)
            {
                BoundsGizmos.Instance.AddCollider(hitBox);
            }
        }
    }
Beispiel #17
0
 public void AddTrail(WeaponTrail trail)
 {
     trails.Add(trail);
 }
 //
 public void AddTrail(WeaponTrail trail)
 {
     trails.Add (trail);
 }
    //GMB文件合并了网格,应该是不用设置位置和旋转了
    public void GenerateWeaponModel(string DesFile, GMBFile fModel, DesFile fIns, bool rightHand = true, float scale = 1.0f, string textureOverrite = "", bool ModelLayer = false)
    {
        if (string.IsNullOrEmpty(DesFile) || fModel == null || fIns == null)
        {
            return;
        }
        string    matIden = DesFile;
        Transform WR      = null;

        if (rightHand)
        {
            if (R != null)
            {
                DestroyImmediate(R);
            }
            R = new GameObject().transform;
            R.gameObject.layer = ModelLayer ? LayerMask.NameToLayer("RenderModel") : LayerMask.NameToLayer("Weapon");
            R.SetParent(RP);
            R.localRotation = Quaternion.identity;
            R.localPosition = Vector3.zero;
            R.localScale    = Vector3.one;
            R.name          = matIden;
            WR = R;
        }
        else
        {
            if (L != null)
            {
                DestroyImmediate(L);
            }
            L = new GameObject().transform;
            L.gameObject.layer = ModelLayer ? LayerMask.NameToLayer("RenderModel") : LayerMask.NameToLayer("Weapon");
            L.SetParent(LP);
            L.localRotation = Quaternion.identity;
            L.localPosition = Vector3.zero;
            L.name          = matIden;
            L.localScale    = Vector3.one;
            WR = L;
        }
        //武器挂点必须在缩放正确后才能到指定的位置
        WR.localScale = Vector3.one;
        Material[] mat = new Material[fModel.TexturesCount];
        Dictionary <int, string> iflMaterials = new Dictionary <int, string>();

        for (int x = 0; x < fModel.TexturesCount; x++)
        {
            mat[x] = null;
            string tex = "";
            if (!string.IsNullOrEmpty(textureOverrite))
            {
                tex = textureOverrite;
            }
            else
            {
                tex = fModel.TexturesNames[x];
            }
            //若不是以ifl结尾的材质,那么要分割文件后缀,若是ifl类型的,则直接是xx.ifl.bytes类型的数据,是OK的
            bool iflMaterial = true;
            if (!tex.ToLower().EndsWith(".ifl"))
            {
                iflMaterial = false;
                int del = tex.LastIndexOf('.');
                if (del != -1)
                {
                    tex = tex.Substring(0, del);
                }
            }

            if (iflMaterial)
            {
                if (!iflMaterials.ContainsKey(x))
                {
                    iflMaterials.Add(x, tex);//记录x号材质是ifl类型的材质,以后会用到,这个序号的材质并且动态更换这个材质的贴图的
                }
            }
            else
            {
                string weaponIden = string.Format("{0}_{1:D2}{2}", matIden, x, textureOverrite);//还要考虑重载贴图也要生成对应的新材质
                mat[x] = Resources.Load <Material>(weaponIden);
                if (mat[x] == null)
                {
                    Texture texture = Resources.Load <Texture>(tex);
                    if (texture == null)
                    {
                        Debug.LogError("texture miss on load gmb:" + tex + " texture name:" + tex);
                    }
                    mat[x] = new Material(ShaderMng.Find("AlphaTexture"));
                    mat[x].SetTexture("_MainTex", texture);
                    mat[x].name = weaponIden;
                    //if (!System.IO.Directory.Exists("Assets/Materials/" + "Weapons" + "/resources/"))
                    //    System.IO.Directory.CreateDirectory("Assets/Materials/" + "Weapons" + "/resources/");
                    //AssetDatabase.CreateAsset(mat[x], "Assets/Materials/" + "Weapons" + "/resources/" + mat[x].name + ".mat");
                    //AssetDatabase.Refresh();
                }
            }
        }

        for (int i = 0; i < fIns.SceneItems.Count; i++)
        {
            GameObject objMesh         = new GameObject();
            bool       addIflComponent = false;
            int        iflParam        = -1;
            int        iflMatIndex     = 0;
            objMesh.name = fIns.SceneItems[i].name;
            objMesh.transform.localRotation = Quaternion.identity;
            objMesh.transform.localPosition = Vector3.zero;
            objMesh.transform.localScale    = Vector3.one;
            bool realObject = false;//是不是正常物体,虚拟体无需设置材质球之类
            if (i < fModel.SceneObjectsCount)
            {
                //for (int j = 0; j < fModel.SceneObjectsCount; j++)
                //{
                //if (fModel.mesh[j].name == objMesh.name)
                {
                    realObject = true;
                    Mesh w = new Mesh();
                    //前者子网格编号,后者 索引缓冲区
                    Dictionary <int, List <int> > tr = new Dictionary <int, List <int> >();
                    List <Vector3> ve  = new List <Vector3>();
                    List <Vector2> uv  = new List <Vector2>();
                    List <Vector3> nor = new List <Vector3>();
                    List <Color>   col = new List <Color>();
                    for (int k = 0; k < fModel.mesh[i].faces.Count; k++)
                    {
                        int key = fModel.mesh[i].faces[k].material;
                        if (tr.ContainsKey(key))
                        {
                            tr[key].Add(fModel.mesh[i].faces[k].triangle[0]);
                            tr[key].Add(fModel.mesh[i].faces[k].triangle[1]);
                            tr[key].Add(fModel.mesh[i].faces[k].triangle[2]);
                        }
                        else
                        {
                            tr.Add(key, new List <int>());
                            tr[key].Add(fModel.mesh[i].faces[k].triangle[0]);
                            tr[key].Add(fModel.mesh[i].faces[k].triangle[1]);
                            tr[key].Add(fModel.mesh[i].faces[k].triangle[2]);
                        }
                    }
                    for (int k = 0; k < fModel.mesh[i].vertices.Count; k++)
                    {
                        ve.Add(fModel.mesh[i].vertices[k].pos);
                        uv.Add(fModel.mesh[i].vertices[k].uv);
                        col.Add(fModel.mesh[i].vertices[k].color);
                        nor.Add(fModel.mesh[i].vertices[k].normal);
                    }
                    w.SetVertices(ve);
                    w.uv           = uv.ToArray();
                    w.subMeshCount = tr.Count;
                    int             ss        = 0;
                    List <Material> targetMat = new List <Material>();
                    foreach (var each in tr)
                    {
                        w.SetIndices(each.Value.ToArray(), MeshTopology.Triangles, ss++);
                        if (each.Key >= 0 && each.Key < fModel.shader.Length)
                        {
                            int materialIndex = fModel.shader[each.Key].TextureArg0;
                            if (materialIndex >= 0 && materialIndex < mat.Length)
                            {
                                if (mat[materialIndex] == null)
                                {
                                    targetMat.Add(new Material(Shader.Find("Unlit/Transparent")));
                                    addIflComponent = true;
                                    iflParam        = materialIndex;
                                    iflMatIndex     = targetMat.Count - 1;
                                }
                                else
                                {
                                    targetMat.Add(mat[materialIndex]);
                                }
                            }
                            else
                            {
                                //占位材质,代表原文件里用到了序号<0的材质(即空材质),这里使用默认材质代替,一般武器加载不会触发这里,但是有极个别情况
                                Material defaults = new Material(Shader.Find("Unlit/Texture"));
                                defaults.name = string.Format("{0}_{1:D2}", objMesh.name, materialIndex);
                                targetMat.Add(defaults);
                            }
                        }
                    }
                    MeshRenderer mr = objMesh.AddComponent <MeshRenderer>();
                    MeshFilter   mf = objMesh.AddComponent <MeshFilter>();
                    mf.mesh         = w;
                    mf.mesh.colors  = col.ToArray();
                    mf.mesh.normals = nor.ToArray();
                    mf.mesh.RecalculateBounds();
                    mf.mesh.RecalculateNormals();

                    mr.materials = targetMat.ToArray();
                    string vis = "";
                    if (fIns.SceneItems[i].ContainsKey("visible", out vis))
                    {
                        if (vis == "0")
                        {
                            mr.enabled = false;
                            BoxCollider box = mr.gameObject.AddComponent <BoxCollider>();
                            objMesh.tag = "weapon";
                            box.enabled = false;
                            weaponDamage.Add(box);
                        }
                    }
                    else
                    if (fIns.SceneItems[i].name.EndsWith("Box"))
                    {
                        BoxCollider box = mr.gameObject.AddComponent <BoxCollider>();
                        box.enabled = false;
                        weaponDamage.Add(box);
                    }
                }
            }

            objMesh.transform.SetParent(WR);
            objMesh.layer = WR.gameObject.layer;
            if (addIflComponent && iflMaterials.ContainsKey(iflParam))
            {
                IFLLoader iflL = objMesh.AddComponent <IFLLoader>();
                iflL.fileNameReadOnly = iflMaterials[iflParam];
                iflL.IFLFile          = Resources.Load <TextAsset>(iflMaterials[iflParam]);
                iflL.matIndex         = iflMatIndex;
                iflL.LoadIFL();
            }

            if (!realObject)
            {
                objMesh.transform.localRotation = fIns.SceneItems[i].quat;
                objMesh.transform.localPosition = fIns.SceneItems[i].pos;
            }
            else
            {
                objMesh.transform.localRotation = Quaternion.identity;
                objMesh.transform.localScale    = Vector3.one;
                objMesh.transform.localPosition = Vector3.zero;
            }
        }

        WR.localScale = Vector3.one * scale;
        //WR.localRotation = new Quaternion(0.7071f, 0, 0, -0.7071f);//挂右手试试不旋转会怎样
        WeaponTrail wt = WR.gameObject.AddComponent <WeaponTrail>();

        if (rightHand)
        {
            //右手
            GameObject ctrlRs = NodeHelper.Find("d_wpnRS", WR.gameObject);
            if (ctrlRs != null)
            {
                wt.AddTransform(ctrlRs.transform);
            }
            GameObject ctrlRe = NodeHelper.Find("d_wpnRE", WR.gameObject);
            if (ctrlRe != null)
            {
                wt.AddTransform(ctrlRe.transform);
            }
        }
        else
        {
            //左手
            GameObject ctrlLs = NodeHelper.Find("d_wpnLS", WR.gameObject);
            if (ctrlLs != null)
            {
                wt.AddTransform(ctrlLs.transform);
            }
            GameObject ctrlLe = NodeHelper.Find("d_wpnLE", WR.gameObject);
            if (ctrlLe != null)
            {
                wt.AddTransform(ctrlLe.transform);
            }
        }
        if (owner != null)
        {
            wt.Init(owner);
            trail.Add(wt);
        }
        else
        {
            GameObject.Destroy(wt);
        }
    }
Beispiel #20
0
 private void Awake()
 {
     myTrail = GetComponent <WeaponTrail>();
     myTrail.SetTime(0, 0, 1);//初始的时候不要拖尾
 }
Beispiel #21
0
 public WeaponTrialController(WeaponTrail weaponTrail)
 {
     this.weaponTrail = weaponTrail;
 }
Beispiel #22
0
 void Start()
 {
     wt = this.GetComponent <WeaponTrail>();
     wt.ClearTrail();
     wt.StartTrail(.2f, .2f);
 }
    //把背包里的物品,装备到身上.
    public void EquipWeapon(InventoryItem item, bool ModelLayer = false)
    {
        if (Weapon == null && item != null)
        {
            if (item.Info().MainType == (int)EquipType.Weapon)
            {
                float scale = 1.0f;
                if (item.Info().Size != 0)//size为0的时候
                {
                    scale = (item.extra == null ? item.Info().Size : item.Info().Size *(1 + item.extra.SizePercent / 100.0f));
                }
                else
                {
                    scale = (item.extra == null ? 1 : (1 + item.extra.SizePercent / 100.0f));
                }
                WeaponDatas.WeaponDatas weaponProperty = U3D.GetWeaponProperty(item.Info().UnitId);


                string weaponL = "";
                string weaponR = "";
                PoseType = item.WeaponPos;
                if (item.WeaponPos == 0)
                {
                    weaponL = weaponProperty.WeaponL;
                    weaponR = weaponProperty.WeaponR;
                }
                else if (item.WeaponPos == 1)
                {
                    weaponL = weaponProperty.PosAWL;
                    weaponR = weaponProperty.PosAWR;
                }
                else if (item.WeaponPos == 2)
                {
                    weaponL = weaponProperty.PosBWL;
                    weaponR = weaponProperty.PosBWR;
                }

                //Debug.Log("加载武器:" + " 左手:" + weaponL + "右手:" + weaponR);
                if (!string.IsNullOrEmpty(weaponL))
                {
                    GameObject weaponPrefab = Resources.Load <GameObject>(weaponL);
                    if (weaponPrefab == null)
                    {
                        GMCFile fGmcL = Main.Ins.GMCLoader.Load(weaponL);
                        DesFile fDesL = Main.Ins.DesLoader.Load(weaponL);

                        if (fGmcL != null && fDesL != null)
                        {
                            GenerateWeaponModel(weaponL, fGmcL, fDesL, false, scale, weaponProperty.TextureL, ModelLayer);
                        }
                        else if (fGmcL == null && fDesL != null)
                        {
                            GMBFile fGmbL = Main.Ins.GMBLoader.Load(weaponL);
                            GenerateWeaponModel(weaponL, fGmbL, fDesL, false, scale, weaponProperty.TextureL, ModelLayer);
                        }
                    }
                    else
                    {
                        if (L != null)
                        {
                            DestroyImmediate(L);
                        }
                        GameObject objWeapon = GameObject.Instantiate(weaponPrefab);
                        objWeapon.layer = ModelLayer ? LayerMask.NameToLayer("RenderModel") : LayerMask.NameToLayer("Weapon");
                        L = objWeapon.transform;
                        //L = new GameObject().transform;
                        L.SetParent(LP);
                        L.localPosition = Vector3.zero;
                        //这种导入来的模型,需要Y轴旋转180,与原系统的物件坐标系存在一些问题
                        L.localRotation = new Quaternion(0, 1, 0, 0);
                        L.name          = weaponL;
                        L.localScale    = Vector3.one;
                        //WE = L;
                        //武器挂点必须在缩放正确后才能到指定的位置
                        WeaponTrail wt = L.gameObject.AddComponent <WeaponTrail>();
                        //右手
                        //GameObject ctrlRs = Global.ldaControlX("d_wpnRS", L.gameObject);
                        //if (ctrlRs != null)
                        //    wt.AddTransform(ctrlRs.transform);
                        //GameObject ctrlRe = Global.ldaControlX("d_wpnRE", L.gameObject);
                        //if (ctrlRe != null)
                        //    wt.AddTransform(ctrlRe.transform);
                        //左手
                        GameObject ctrlLs = NodeHelper.Find("d_wpnLS", L.gameObject);
                        if (ctrlLs != null)
                        {
                            wt.AddTransform(ctrlLs.transform);
                        }
                        GameObject ctrlLe = NodeHelper.Find("d_wpnLE", L.gameObject);
                        if (ctrlLe != null)
                        {
                            wt.AddTransform(ctrlLe.transform);
                        }

                        //每个武器只能有一个碰撞盒
                        BoxCollider box = L.GetComponentInChildren <BoxCollider>();
                        if (box != null)
                        {
                            box.enabled          = false;
                            box.gameObject.layer = ModelLayer ? LayerMask.NameToLayer("RenderModel") : LayerMask.NameToLayer("Weapon");
                            weaponDamage.Add(box);
                        }
                        else
                        {
                            Debug.LogError("新增武器上找不到碰撞盒[除了暗器火枪飞轮外都应该有碰撞盒]");
                        }
                        if (owner != null)
                        {
                            wt.Init(owner);
                            trail.Add(wt);
                        }
                        else
                        {
                            GameObject.Destroy(wt);
                            wt = null;
                        }
                    }
                }
                if (!string.IsNullOrEmpty(weaponR))
                {
                    GameObject weaponPrefab = Resources.Load <GameObject>(weaponR);
                    if (weaponPrefab == null)
                    {
                        GMCFile fGmcR = Main.Ins.GMCLoader.Load(weaponR);
                        DesFile fDesR = Main.Ins.DesLoader.Load(weaponR);
                        if (fGmcR != null && fDesR != null)
                        {
                            GenerateWeaponModel(weaponR, fGmcR, fDesR, true, scale, weaponProperty.TextureR, ModelLayer);
                        }
                        else if (fGmcR == null && fDesR != null)
                        {
                            GMBFile fGmbR = Main.Ins.GMBLoader.Load(weaponProperty.WeaponR);
                            GenerateWeaponModel(weaponR, fGmbR, fDesR, true, scale, weaponProperty.TextureR, ModelLayer);
                        }
                    }
                    else
                    {
                        if (R != null)
                        {
                            DestroyImmediate(R);
                        }
                        GameObject objWeapon = GameObject.Instantiate(weaponPrefab);
                        objWeapon.layer = ModelLayer ? LayerMask.NameToLayer("RenderModel") : LayerMask.NameToLayer("Weapon");
                        R = objWeapon.transform;
                        R.SetParent(RP);
                        R.localPosition = Vector3.zero;
                        R.localRotation = new Quaternion(0, 1, 0, 0);
                        R.name          = weaponR;
                        R.localScale    = Vector3.one;

                        //武器挂点必须在缩放正确后才能到指定的位置
                        WeaponTrail wt = R.gameObject.AddComponent <WeaponTrail>();
                        //右手
                        GameObject ctrlRs = NodeHelper.Find("d_wpnRS", R.gameObject);
                        if (ctrlRs != null)
                        {
                            wt.AddTransform(ctrlRs.transform);
                        }
                        GameObject ctrlRe = NodeHelper.Find("d_wpnRE", R.gameObject);
                        if (ctrlRe != null)
                        {
                            wt.AddTransform(ctrlRe.transform);
                        }
                        BoxCollider box = R.GetComponentInChildren <BoxCollider>();
                        if (box != null)
                        {
                            box.enabled          = false;
                            box.gameObject.layer = ModelLayer ? LayerMask.NameToLayer("RenderModel") : LayerMask.NameToLayer("Weapon");
                            weaponDamage.Add(box);
                        }
                        else
                        {
                            Debug.LogError("新增武器上找不到碰撞盒[除了暗器火枪飞轮外都应该有碰撞盒]");
                        }

                        if (owner != null)
                        {
                            wt.Init(owner);
                            trail.Add(wt);
                        }
                        else
                        {
                            GameObject.Destroy(wt);
                        }
                    }
                }
            }
            Weapon = item;
        }
        else
        {
            Debug.LogError("if you want equip you must call unequip first if the weapon exist");
        }

        if (owner != null && owner.Stealth)
        {
            MeshRenderer[] mrl = LP.gameObject.GetComponentsInChildren <MeshRenderer>();
            for (int i = 0; i < mrl.Length; i++)
            {
                if (!mrl[i].enabled)
                {
                    continue;
                }
                for (int j = 0; j < mrl[i].materials.Length; j++)
                {
                    mrl[i].materials[j].SetFloat("_Alpha", 0.2f);
                }
            }

            MeshRenderer[] mrr = RP.gameObject.GetComponentsInChildren <MeshRenderer>();
            for (int i = 0; i < mrr.Length; i++)
            {
                if (!mrr[i].enabled)
                {
                    continue;
                }
                for (int j = 0; j < mrr[i].materials.Length; j++)
                {
                    mrr[i].materials[j].SetFloat("_Alpha", 0.2f);
                }
            }
        }
    }
 void Awake()
 {
     currentWeaponTrail = baseSkill_Trail1;
     characterAnim      = GetComponent <CharacterAnim>();
 }