public void StartMoveAmmo(Vector3 firePos, PlayerEnum playerIndex, NpcPathCtrl ammoMovePath = null, GameObject hitObjNpc = null) { float disTmp = Vector3.Distance(firePos, AmmoTran.position); Vector3 vecA = firePos - AmmoTran.position; if (disTmp < 10f || disTmp > MaxDisVal || AmmoType == PlayerAmmoType.PaiJiPaoAmmo) { firePos = AmmoTran.position + (vecA.normalized * MaxDisVal); //Debug.Log("StartMoveAmmo::fix firePos -> "+"disTmp "+disTmp+", disMax "+MaxDisVal); } IsChuanJiaDanHitCamColForward = false; ObjAmmo = gameObject; if (!ObjAmmo.activeSelf) { ObjAmmo.SetActive(true); IsDestroyAmmo = false; } AmmoTran = transform; PlayerState = playerIndex; MoveAmmoByItween(firePos, ammoMovePath); IsHandleRpc = true; }
void MoveAmmoByItween(Vector3 firePos, NpcPathCtrl ammoMovePath) { Vector3[] posArray = new Vector3[2]; if (ammoMovePath == null) { posArray[0] = AmmoTran.position; posArray[1] = firePos; AmmoStartPos = AmmoTran.position; iTween.MoveTo(ObjAmmo, iTween.Hash("path", posArray, "speed", MvSpeed, "orienttopath", true, "easeType", iTween.EaseType.linear, "oncomplete", "MoveAmmoOnCompelteITween")); } else { int countMark = ammoMovePath.transform.childCount; Transform[] tranArray = ammoMovePath.transform.GetComponentsInChildren <Transform>(); List <Transform> nodesTran = new List <Transform>(tranArray) { }; nodesTran.Remove(ammoMovePath.transform); transform.position = nodesTran[0].position; transform.rotation = nodesTran[0].rotation; firePos = nodesTran[countMark - 1].position; AmmoStartPos = nodesTran[countMark - 2].position; iTween.MoveTo(ObjAmmo, iTween.Hash("path", nodesTran.ToArray(), "speed", MvSpeed, "orienttopath", true, "easeType", iTween.EaseType.linear, "oncomplete", "MoveAmmoOnCompelteITween")); } AmmoEndPos = firePos; }
//bool IsXiaoFeiJiAmmo = false; //internal void SetIsXiaoFeiJiAmmo(bool isXiaoFeiJiAmmo) //{ // IsXiaoFeiJiAmmo = isXiaoFeiJiAmmo; //} //static int TestChongJiBoCount = 0; public void StartMoveAmmo(Vector3 firePos, PlayerEnum playerIndex, XKPlayerAutoFire autoFireCom = null, NpcPathCtrl ammoMovePath = null, GameObject hitObjNpc = null) { if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //没有激活任何玩家. SetIsAiFireAmmo(true); } else { SetIsAiFireAmmo(false); } float disTmp = Vector3.Distance(firePos, AmmoTran.position); Vector3 vecA = firePos - AmmoTran.position; if (disTmp < 10f || disTmp > MaxDisVal || AmmoType == PlayerAmmoType.PaiJiPaoAmmo) { firePos = AmmoTran.position + (vecA.normalized * MaxDisVal); //Debug.Log("Unity:"+"StartMoveAmmo::fix firePos -> "+"disTmp "+disTmp+", disMax "+MaxDisVal); } IsChuanJiaDanHitCamColForward = false; IsCreatAmmoParticle = false; m_TimeLast = Time.time; ObjAmmo = gameObject; if (IsDestroyAmmo == true) { ObjAmmo.SetActive(true); IsDestroyAmmo = false; IsHitNpcAmmo = false; } AmmoTran = transform; PlayerState = playerIndex; if (AmmoType == PlayerAmmoType.ChongJiBoAmmo) { //冲击波子弹不用运动,只需要检测一次范围伤害. if (m_AmmmoData != null && autoFireCom != null) { m_AmmmoData.SetActiveAmmoCore(autoFireCom.CountAmmoStateZhuPao, autoFireCom.PlayerIndex); } CheckPlayerAmmoForwardHitNpc(); //StartCoroutine(DelayRemoveChongJiBoAmmo()); //TestChongJiBoCount++; //SSDebug.LogWarning("TestChongJiBoCount ============== " + TestChongJiBoCount + ", AmmoActive == " + gameObject.activeInHierarchy); } else { MoveAmmoByItween(firePos, ammoMovePath, autoFireCom); } IsHandleRpc = true; }
// void OnTriggerEnter(Collider other) // { // //Debug.Log("OnTriggerEnter...name "+other.name); // if (Network.peerType == NetworkPeerType.Client) { // return; // } // // XkNpcZaiTiCtrl script = other.GetComponent<XkNpcZaiTiCtrl>(); // if (script == null) { // return; // } // script.SetNpcIsDoFire(this); // } public void DrawPath() { Transform parTran = transform.parent; NpcPathCtrl pathScript = parTran.GetComponent <NpcPathCtrl>(); if (pathScript != null) { pathScript.DrawPath(); } }
public void StartMoveAmmo(Vector3 firePos, PlayerEnum playerSt, NpcPathCtrl ammoMovePath = null, GameObject hitObjNpc = null) { HitNpcObj = hitObjNpc; ObjAmmo = gameObject; if (!ObjAmmo.activeSelf) { ObjAmmo.SetActive(true); IsDestroyAmmo = false; } AmmoTran = transform; PlayerState = playerSt; MoveAmmoByItween(firePos, ammoMovePath); IsHandleRpc = true; }
//**********************************************************************************************// /// <summary> /// 获取npc需要运动的总路程. /// </summary> internal float GetNpcMoveDistance() { float distance = 0f; if (NpcPath != null) { NpcPathCtrl npcPathCom = NpcPath.GetComponent <NpcPathCtrl>(); distance += npcPathCom.m_PathLength; if (NpcPath.childCount > 0) { //计算产生点到第一个路径点的距离. Vector3 startPos = transform.position; Vector3 endPos = NpcPath.GetChild(0).position; distance += Vector3.Distance(startPos, endPos); } } return(distance); }
/// <summary> /// 获取npc的路径数据. /// </summary> public NpcPathCtrl GetNpcPahtData() { NpcPathCtrl[] comGp = m_NpcPathGp; if (comGp == null || comGp.Length <= 0) { Debug.LogWarning("Unity: not find NpcPathData!"); return(null); } NpcPathCtrl com = null; int rv = Random.Range(0, 100) % comGp.Length; com = comGp[rv]; if (com == null) { Debug.LogWarning("Unity: com was null! rv ============ " + rv); } return(com); }
public void SetSpawnNpcInfo(XKSpawnNpcPoint spawnScript) { transform.SetParent(XkGameCtrl.NpcObjArray); NetViewCom = GetComponent <NetworkView>(); SpawnPointScript = spawnScript; // SetAimState(); TestSpawnPoint = spawnScript.gameObject; if (spawnScript.NpcPath != null) { NpcPathScript = spawnScript.NpcPath.GetComponent <NpcPathCtrl>(); } NpcObj = gameObject; NpcTran = transform; NpcPathTran = spawnScript.NpcPath; MvSpeed = spawnScript.MvSpeed; FireDistance = spawnScript.FireDistance; if (IsDeathNPC) { IsDeathNPC = false; IsHiddenNpcObj = false; } //SetNpcFireAnimationIsAimFeiJiPlayer(spawnScript.IsAimFeiJiPlayer); NpcMoveScript = NpcTran.GetComponentsInChildren <XKNpcMoveCtrl>(); for (int i = 0; i < NpcMoveScript.Length; i++) { NpcMoveScript[i].SetIsFangZhenNpc(this, i); NpcMoveScript[i].SetNpcSpawnScriptInfo(spawnScript); NpcMoveScript[i].SetIndexNpc(i); } FangZhenNpcCount = NpcMoveScript.Length; //Debug.Log("Unity:"+"SetSpawnNpcInfo -> FangZhenNpcCount "+FangZhenNpcCount+", fangZhenObj "+NpcObj.name); if (spawnScript.TimeRootAni > 0f) { PlayNpcAnimation(spawnScript.AniRootName); } StartCoroutine(StartMoveNpcByItween(spawnScript.AniRunName, spawnScript.TimeRootAni)); }
void MoveAmmoByItween(Vector3 firePos, NpcPathCtrl ammoMovePath) { if (ammoMovePath == null) { Vector3[] posArray = new Vector3[2]; posArray[0] = AmmoTran.position; float lobTime = Vector3.Distance(firePos, posArray[0]) / MvSpeed; if (AmmoType == PlayerAmmoType.GenZongAmmo || AmmoType == PlayerAmmoType.PaiJiPaoAmmo) { Vector3 posTmp = AmmoType == PlayerAmmoType.GenZongAmmo ? GetGenZongDanFirePos() : firePos; if (posTmp != Vector3.zero) { firePos = posTmp; } if (AmmoType == PlayerAmmoType.PaiJiPaoAmmo) { RaycastHit hit; Vector3 posA = firePos + Vector3.up * 50f; Physics.Raycast(posA, Vector3.down, out hit, 500f, XkGameCtrl.GetInstance().LandLayer); if (hit.collider != null) { firePos = hit.point; } } if (AmmoType == PlayerAmmoType.PaiJiPaoAmmo && PaiJiPaoTiShiPrefab != null) { PaiJiPaoTiShi = (GameObject)Instantiate(PaiJiPaoTiShiPrefab, firePos, Quaternion.identity); if (XkGameCtrl.NpcAmmoArray != null) { PaiJiPaoTiShi.transform.parent = XkGameCtrl.NpcAmmoArray; } } float disMV = Vector3.Distance(firePos, posArray[0]); lobTime = disMV / MvSpeed; float lobHeight = disMV * XKPlayerGlobalDt.GetInstance().KeyPaiJiPaoValPlayer; //lobHeight = lobHeight > 10f ? 10f : lobHeight; AmmoCore.transform.localPosition = Vector3.zero; AmmoCore.transform.localEulerAngles = Vector3.zero; iTween.MoveBy(AmmoCore, iTween.Hash("y", lobHeight, "time", lobTime / 2, "easeType", iTween.EaseType.easeOutQuad)); iTween.MoveBy(AmmoCore, iTween.Hash("y", -lobHeight, "time", lobTime / 2, "delay", lobTime / 2, "easeType", iTween.EaseType.easeInCubic)); //iTween.FadeTo(gameObject, iTween.Hash("delay", 3, "time", .5, "alpha", 0, "onComplete", "CleanUp")); } posArray[1] = firePos; //AmmoStartPos = AmmoTran.position; iTween.MoveTo(gameObject, iTween.Hash("position", firePos, "time", lobTime, "easeType", iTween.EaseType.linear, "oncomplete", "MoveAmmoOnCompelteITween")); } else { int countMark = ammoMovePath.transform.childCount; Transform[] tranArray = ammoMovePath.transform.GetComponentsInChildren <Transform>(); List <Transform> nodesTran = new List <Transform>(tranArray) { }; nodesTran.Remove(ammoMovePath.transform); transform.position = nodesTran[0].position; transform.rotation = nodesTran[0].rotation; firePos = nodesTran[countMark - 1].position; //AmmoStartPos = nodesTran[countMark-2].position; iTween.MoveTo(ObjAmmo, iTween.Hash("path", nodesTran.ToArray(), "speed", MvSpeed, "orienttopath", true, "easeType", iTween.EaseType.linear, "oncomplete", "MoveAmmoOnCompelteITween")); } //AmmoEndPos = firePos; }
void MoveAmmoByItween(Vector3 firePos, NpcPathCtrl ammoMovePath, XKPlayerAutoFire autoFireCom) { //if (autoFireCom != null) //{ // SSDebug.Log("MoveAmmoByItween -> AmmoType ==== " + AmmoType + ", IsQianHouFire ==== " + autoFireCom.IsQianHouFire); // SSDebug.Log("MoveAmmoByItween -> CountAmmoStateZhuPao ==== " + autoFireCom.CountAmmoStateZhuPao // + ", CountAmmoStateJiQiang ==== " + autoFireCom.CountAmmoStateJiQiang); //} if (m_AmmmoData != null && autoFireCom != null) { switch (AmmoType) { case PlayerAmmoType.PaiJiPaoAmmo: case PlayerAmmoType.ChuanTouAmmo: case PlayerAmmoType.SanDanAmmo: case PlayerAmmoType.ChongJiBoAmmo: case PlayerAmmoType.DaoDanAmmo: { if (AmmoType == PlayerAmmoType.DaoDanAmmo) { //普通导弹子弹. m_AmmmoData.SetActiveAmmoCore(0, autoFireCom.PlayerIndex); } else { //其它特殊导弹. m_AmmmoData.SetActiveAmmoCore(autoFireCom.CountAmmoStateZhuPao, autoFireCom.PlayerIndex); } break; } case PlayerAmmoType.PuTongAmmo: { if (autoFireCom.IsQianHouFire == true) { //小飞机发射的子弹. m_AmmmoData.SetActiveAmmoCore(autoFireCom.CountAmmoStateJiQiang, autoFireCom.PlayerIndex); } break; } } } if (ammoMovePath == null) { Vector3[] posArray = new Vector3[2]; posArray[0] = AmmoTran.position; float lobTime = Vector3.Distance(firePos, posArray[0]) / MvSpeed; if (AmmoType == PlayerAmmoType.GenZongAmmo || AmmoType == PlayerAmmoType.PaiJiPaoAmmo) { Vector3 posTmp = AmmoType == PlayerAmmoType.GenZongAmmo ? GetGenZongDanFirePos() : firePos; if (posTmp != Vector3.zero) { firePos = posTmp; } if (AmmoType == PlayerAmmoType.PaiJiPaoAmmo) { RaycastHit hit; Vector3 posA = firePos + Vector3.up * 50f; Physics.Raycast(posA, Vector3.down, out hit, 500f, XkGameCtrl.GetInstance().LandLayer); if (hit.collider != null) { firePos = hit.point; } } if (AmmoType == PlayerAmmoType.PaiJiPaoAmmo && PaiJiPaoTiShiPrefab != null) { PaiJiPaoTiShi = (GameObject)Instantiate(PaiJiPaoTiShiPrefab, firePos, Quaternion.identity); if (XkGameCtrl.NpcAmmoArray != null) { PaiJiPaoTiShi.transform.parent = XkGameCtrl.NpcAmmoArray; } if (PaiJiPaoTiShi != null) { //迫击炮子弹提示. SSPlayerAmmoTiShiData ammoTiShiDt = PaiJiPaoTiShi.GetComponent <SSPlayerAmmoTiShiData>(); if (ammoTiShiDt != null) { ammoTiShiDt.InitPlayerAmmo(PlayerState); } } } float disMV = Vector3.Distance(firePos, posArray[0]); lobTime = disMV / MvSpeed; float lobHeight = disMV * XKPlayerGlobalDt.GetInstance().KeyPaiJiPaoValPlayer; //lobHeight = lobHeight > 10f ? 10f : lobHeight; if (m_AmmmoData != null && autoFireCom != null) { GameObject objCore = m_AmmmoData.GetAmmoCore(autoFireCom.CountAmmoStateZhuPao); if (objCore != null) { AmmoCore = objCore; } } AmmoCore.transform.localPosition = Vector3.zero; AmmoCore.transform.localEulerAngles = Vector3.zero; iTween.MoveBy(AmmoCore, iTween.Hash("y", lobHeight, "time", lobTime / 2, "easeType", iTween.EaseType.easeOutQuad)); iTween.MoveBy(AmmoCore, iTween.Hash("y", -lobHeight, "time", lobTime / 2, "delay", lobTime / 2, "easeType", iTween.EaseType.easeInCubic)); //iTween.FadeTo(gameObject, iTween.Hash("delay", 3, "time", .5, "alpha", 0, "onComplete", "CleanUp")); } posArray[1] = firePos; //AmmoStartPos = AmmoTran.position; iTween.MoveTo(gameObject, iTween.Hash("position", firePos, "time", lobTime, "easeType", iTween.EaseType.linear, "oncomplete", "MoveAmmoOnCompelteITween")); } else { int countMark = ammoMovePath.transform.childCount; Transform[] tranArray = ammoMovePath.transform.GetComponentsInChildren <Transform>(); List <Transform> nodesTran = new List <Transform>(tranArray) { }; nodesTran.Remove(ammoMovePath.transform); transform.position = nodesTran[0].position; transform.rotation = nodesTran[0].rotation; firePos = nodesTran[countMark - 1].position; //AmmoStartPos = nodesTran[countMark-2].position; iTween.MoveTo(ObjAmmo, iTween.Hash("path", nodesTran.ToArray(), "speed", MvSpeed, "orienttopath", true, "easeType", iTween.EaseType.linear, "oncomplete", "MoveAmmoOnCompelteITween")); } //AmmoEndPos = firePos; }