//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); } }
//力量感很差,仅仅运行轨迹是一条曲线还是不行的。要有冲击感,要做变速/匀加速按固定轨迹运动,才行 //因为贝塞尔通过时间计算曲线的某一位置,可以把时间参数模拟加快,做为变量 //但是怎么去控制 //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); } } }