public void TestBullet(IEntityDataStruct entityDStruct) { if (!isShowTestBullet) { return; } SMsgPropCreateEntity_SC_Bullet bulletSC = (SMsgPropCreateEntity_SC_Bullet)entityDStruct; #region 子弹 //Log.Instance.StartLog(); //Log.Instance.AddLog("66666", "0", bulletSC.PosX.ToString(), bulletSC.PosY.ToString(), bulletSC.DirX.ToString(), bulletSC.DirY.ToString()); //Log.Instance.AppendLine(); #endregion //TraceUtil.Log("子弹id=" + bulletSC.BaseValue.OBJECT_FIELD_ENTRY_ID); //TraceUtil.Log("子弹类型=" + bulletSC.BaseValue.OBJECT_FIELD_TYPE); BulletData bData = SkillDataManager.Instance.GetBulletData(bulletSC.BaseValue.OBJECT_FIELD_ENTRY_ID); GameObject bulletGO = CircleGO; bool isCircle = true; if (bData.m_shapeParam1 == 2) { //矩形 bulletGO = SquareGO; isCircle = false; } Vector3 localPos = Vector3.zero.GetFromServer(bulletSC.PosX, bulletSC.PosY); localPos = new Vector3(localPos.x, bulletGO.transform.position.y, localPos.z); Quaternion quaternion = bulletGO.transform.rotation; float rad = Mathf.Atan2(-1 * bulletSC.DirY, bulletSC.DirX); float QuaterionY = 90 - rad * Mathf.Rad2Deg; //\本地图片反了 QuaterionY += 180; //\test if (this.CreateFan(bData, localPos, QuaterionY)) { return; } if (isShowSquareBullet) { GameObject TestGO = (GameObject)UnityEngine.Object.Instantiate(bulletGO, localPos, Quaternion.Euler(quaternion.eulerAngles.x, QuaterionY, quaternion.eulerAngles.z)); if (isCircle) { TestGO.transform.localScale = new Vector3(TestGO.transform.lossyScale.x * bData.m_shapeParam2, TestGO.transform.lossyScale.y * bData.m_shapeParam2, TestGO.transform.lossyScale.z); } else { TestGO.transform.localScale = new Vector3(TestGO.transform.lossyScale.x * bData.m_shapeParam3, TestGO.transform.lossyScale.y * bData.m_shapeParam2, TestGO.transform.lossyScale.z); } } }
/// <summary> /// 网络通知调用创建子弹 /// </summary> /// <param name="entityDStruct"></param> private void CreateBullet(IEntityDataStruct entityDStruct) { SMsgPropCreateEntity_SC_Bullet bulletSC = (SMsgPropCreateEntity_SC_Bullet)entityDStruct; BulletData bData = SkillDataManager.Instance.GetBulletData(bulletSC.BaseValue.OBJECT_FIELD_ENTRY_ID); //TraceUtil.Log("网络通知调用创建子弹"); if (bData == null) { TraceUtil.Log("找不到子弹配置信息"); return; } var bulletPrefabStr = bData.m_bulletResPath; if (bulletPrefabStr == "0") { //TraceUtil.Log("未配置子弹实体"); return; } GameObject bulletPrefab = MapResManager.Instance.GetMapEffectPrefab(bulletPrefabStr); Vector3 localPos = Vector3.zero.GetFromServer(bulletSC.PosX, bulletSC.PosY); localPos = new Vector3(localPos.x, bulletPrefab.transform.position.y, localPos.z); GameObject bulletGO = (GameObject)UnityEngine.Object.Instantiate(bulletPrefab, localPos, bulletPrefab.transform.rotation); //bulletGO.transform.localScale = new Vector3(bulletGO.transform.lossyScale.x * bData.m_shapeParam2, bulletGO.transform.lossyScale.y * bData.m_shapeParam3, bulletGO.transform.lossyScale.z); BulletBehaviour bulletBehaviour = bulletGO.GetComponent <BulletBehaviour>(); if (bulletBehaviour == null) { bulletBehaviour = bulletGO.AddComponent <BulletBehaviour>(); } bulletBehaviour.InitBulletFromServer(bulletSC.BaseValue.OBJECT_FIELD_ENTRY_ID, bulletSC.CasterUID, bData, bulletSC.TargetId); //子弹运动轨迹(根据角度) Vector3 motionVector = Vector3.zero; Vector3 accelerationVector = Vector3.zero; Vector3 motionNormalize = new Vector3(bulletSC.DirX, 0, -1 * bulletSC.DirY); motionNormalize.Normalize(); var speed = bData.m_startSpeed; float parseLifeTime = bData.m_lifeTime / 1000f; if (bData.m_mountType == 2) //必达型子弹,使用服务器速度 { Vector3 targetPos = Vector3.zero.GetFromServer(bulletSC.TargetX, bulletSC.TargetY); speed = Vector3.Distance(localPos, targetPos) / parseLifeTime;// bulletSC.Speed / 10; //厘米转分米 } motionVector = motionNormalize * speed; float rad = Mathf.Atan2(-1 * bulletSC.DirY, bulletSC.DirX); float QuaterionY = 90 - rad * Mathf.Rad2Deg; if (bData.m_acceleration != 0) { accelerationVector = motionVector * (bData.m_acceleration / bData.m_startSpeed); } Quaternion initQuaternion = bulletBehaviour.transform.rotation; bulletBehaviour.transform.rotation = Quaternion.Euler(initQuaternion.eulerAngles.x, QuaterionY, initQuaternion.eulerAngles.z); //Vector3 bulletReferencePos = /*bulletBehaviour.transform.position+*/ .transform.TransformPoint(bData.m_initPos.y, 0, bData.m_initPos.x); bulletBehaviour.Fired(localPos, QuaterionY, motionVector, accelerationVector, parseLifeTime); EntityModel bulletModel = new EntityModel(); bulletModel.GO = bulletGO; bulletModel.Behaviour = bulletBehaviour; bulletModel.EntityDataStruct = entityDStruct; EntityController.Instance.RegisteEntity(bulletSC.GUID, bulletModel); #region 打印测试 //Log.Instance.AddOtherLog( #endregion }