public static void Show(string prefabName, float hitPointDist) { if (hitPointDist < 6f) { hitPointDist = Mathf.Clamp(hitPointDist, 1.5f, 6f); // 获得距离的比例 float t = 1f - ((hitPointDist - 1.5f) / 4.5f); float x = Mathf.Lerp(0.5f, 1.5f, t) + Random.Range((float)-0.5f, (float)0.5f); // 计算位置 float num3 = ((float)GameMenu.INSTANCE.GetComponent <CanvasScaler>().referenceResolution.x / ((float)Screen.height)); float num4 = Screen.width * num3; float num5 = Screen.height * num3; float max = (num4 * 0.75f) / 3f; float num7 = (num5 * 0.75f) / 3f; // 实例化 RectTransform rectTF = Instantiate(PrefabResources.Get(prefabName)) as RectTransform; // 放到画布下面 rectTF.parent = GameMenu.INSTANCE.effectPanelTrans; ZombieAttackedBlood attackedBlood = rectTF.GetComponent <ZombieAttackedBlood>(); // 设置位置,旋转的角度 rectTF.localPosition = new Vector3(Random.Range(-max, max), Random.Range(-num7, num7), 0); attackedBlood.sprite1Trans.localEulerAngles = new Vector3(0f, 0f, Random.Range(0f, 360f)); attackedBlood.sprite2Trans.localEulerAngles = new Vector3(0f, 0f, Random.Range(0f, 360f)); rectTF.localScale = new Vector3(0.1f, 0.1f, 0.1f); // 开始动画,透明度、尺寸、位置,尺寸根据距离远近变化 attackedBlood.canvasGroup.DOFade(1f, 0.2f); // 显示 rectTF.DOScale(new Vector3(x, x, 1f), 0.2f); rectTF.DOLocalMoveY((rectTF.localPosition.y - 25f), 1.5f).SetEase(Ease.OutCubic); // 可见 rectTF.gameObject.SetActive(true); } }
// 4.加载预制体 private void LoadAdditiveRoutine() { // 加载预制体 for (int i = 0; i < AlwaysLoadPrefabs.Length; i++) { PrefabResources.Get(AlwaysLoadPrefabs[i]); } //HeroController.isMocked = false; // 实例化英雄 Debug.Log("实例化英雄"); Transform transform = Instantiate(PrefabResources.Get("Main/Hero")) as Transform; transform.gameObject.SetActive(true); // 加载4段 if (this.loadRoutineDelegate != null) { this.loadRoutineDelegate(this, 1f); } // 加载结束 if (this.loadEndDelegate != null) { this.loadEndDelegate(this); } }
public static void Show() { RectTransform rectTF = UnityEngine.Object.Instantiate(PrefabResources.Get("Effect/BloodBoxEffect")).GetComponent <RectTransform>(); rectTF.parent = GameMenu.INSTANCE.effectPanelTrans; rectTF.offsetMin = Vector2.zero; rectTF.offsetMax = Vector2.zero; rectTF.localScale = Vector3.one; rectTF.gameObject.SetActive(true); Debug.Log(rectTF.localPosition); }
public void CreateZombie(StgZombieBornDealer zombieDealer) { Transform trans = UnityEngine.Object.Instantiate(PrefabResources.Get("Zombie/" + zombieName)); trans.position = this.position + new Vector3(UnityEngine.Random.Range(-this.range, this.range), 0.3f, UnityEngine.Random.Range(-this.range, this.range)); trans.eulerAngles = new Vector3(0f, (float)UnityEngine.Random.Range(0, 360), 0f); ZombieAbs zombieAbs = trans.GetComponent <ZombieAbs>(); zombieAbs.Agent.Warp(trans.position); zombieAbs.zombieDieDelegate = (Action <ZombieAbs>)Delegate.Combine(zombieAbs.zombieDieDelegate, new Action <ZombieAbs>(zombieDealer.HandleZombieDie)); trans.gameObject.SetActive(true); StgZombieBornDealer.zombies.Add(zombieAbs); }
public static void Show(string prefabName, Vector3 position, int dir, float angle) { RectTransform rectTF = Instantiate(PrefabResources.Get(prefabName)) as RectTransform; rectTF.parent = GameMenu.INSTANCE.effectPanelTrans; ZombieAttackBlood component = rectTF.GetComponent <ZombieAttackBlood>(); float startScaleX = component.startScaleX; float startScaleY = component.startScaleY; float minScaleX = component.minScaleX; float maxScaleX = component.maxScaleX; float minScaleY = component.minScaleY; float maxScaleY = component.maxScaleY; float scaleMoveMul = component.scaleMoveMul; float x = Random.Range(minScaleX, maxScaleX); float y = Random.Range(minScaleY, maxScaleY); if (dir > 0) { angle += Random.Range(-5, 5); position += new Vector3((Mathf.Cos(angle) * x) * scaleMoveMul, (Mathf.Sin(angle) * y) * scaleMoveMul, 0f); rectTF.localPosition = position; rectTF.localEulerAngles = new Vector3(0f, 0f, angle); rectTF.localScale = new Vector3(startScaleX, startScaleY, 1f); } else if (dir < 0) { angle += UnityEngine.Random.Range(-5, 5); position += new Vector3((-Mathf.Cos(angle) * x) * scaleMoveMul, (Mathf.Sin(angle) * y) * scaleMoveMul, 0f); rectTF.localPosition = position; rectTF.localEulerAngles = new Vector3(0f, 0f, 180f - angle); rectTF.localScale = new Vector3(startScaleX, startScaleY, 1f); } else { angle += UnityEngine.Random.Range(-5, 5); position += new Vector3((-Mathf.Sin(angle) * y) * scaleMoveMul, (Mathf.Cos(angle) * x) * scaleMoveMul, 0f); rectTF.localPosition = position; rectTF.localEulerAngles = new Vector3(0f, 0f, 90f + angle); rectTF.localScale = new Vector3(startScaleX, startScaleY, 1f); } Image img = rectTF.GetComponent <Image>(); Tween imgTween = img.DOFade(1, 0.5f); imgTween.SetUpdate(true); imgTween.Play(); Tween rectTFTween = rectTF.DOScale(new Vector3(x, y, 1f), 0.3f); rectTFTween.SetUpdate(true); rectTFTween.Play(); rectTF.transform.gameObject.SetActive(true); }
public static MenuWeaponLoader GetLoader(string name) { if (loaders.ContainsKey(name)) { return(loaders[name]); } MenuWeaponLoader newLoader = new MenuWeaponLoader(); newLoader.weaponInstance = Instantiate(PrefabResources.Get("Weapon/" + name).gameObject); newLoader.originPos = newLoader.weaponInstance.transform.localPosition; newLoader.weaponInstance.SetActive(false); newLoader.gunSprite = Resources.Load("Textures/" + name, typeof(Sprite)) as Sprite; Debug.Log(newLoader.gunSprite.name); loaders[name] = newLoader; return(newLoader); }
public bool isAvailable; // 是否为可用对象 public static void Show(string prefabName, Vector3 position) { BloodSequence bloodSeq = bloodLibrary.Get(prefabName); // 如果为空,就新实例化一个 if (bloodSeq == null) { Transform trans = Instantiate(PrefabResources.Get(prefabName)) as Transform; bloodSeq = trans.GetComponent <BloodSequence>(); bloodLibrary.Add(prefabName, bloodSeq); } bloodSeq.timer = 0f; // 设置 bloodSeq.isAvailable = false; bloodSeq.transform.position = position; bloodSeq.gameObject.SetActive(true); }
// 初始化 public void Init() { // 实例化第一支枪 Transform gun1Trans = Instantiate(PrefabResources.Get("Gun/" + Profile.Gun1Name)); gun1Trans.parent = GameCameraController.INSTANCE.gunNode; gun1Trans.localPosition = new Vector3(0, 0, 0); gun1Trans.localRotation = Quaternion.identity; gun1Trans.localScale = new Vector3(1f, 1f, 1f); gun1Trans.gameObject.SetActive(false); // 已经挂上了GameWeaponGun并进行了设置,所以直接获取即可 GameWeaponGun gun1 = gun1Trans.gameObject.GetComponent <GameWeaponGun>(); gun1.unequipEndDelegate = (Action)Delegate.Combine(gun1.unequipEndDelegate, new Action(this.WeaponUnequipEnd)); Transform aimPoint1 = Instantiate(PrefabResources.Get("UI/" + Profile.Gun1Name + "_AimPoint")); aimPoint1.parent = GameMenu.INSTANCE.aimPointNode; aimPoint1.localScale = new Vector3(1f, 1f, 1f); gun1.aimPoint = aimPoint1.GetComponent <GameAimPointNormal>(); weapons.Add(gun1); // 实例化第二支枪 Transform gun2Trans = Instantiate(PrefabResources.Get("Gun/" + Profile.Gun2Name)); gun2Trans.parent = GameCameraController.INSTANCE.gunNode; gun2Trans.localPosition = new Vector3(0, 0, 0); gun2Trans.localRotation = Quaternion.identity; gun2Trans.localScale = new Vector3(1f, 1f, 1f); gun2Trans.gameObject.SetActive(false); GameWeaponGun gun2 = gun2Trans.gameObject.GetComponent <GameWeaponGun>(); gun2.unequipEndDelegate = (Action)Delegate.Combine(gun2.unequipEndDelegate, new Action(this.WeaponUnequipEnd)); Transform aimPoint2 = Instantiate(PrefabResources.Get("UI/" + Profile.Gun2Name + "_AimPoint")); aimPoint2.parent = GameMenu.INSTANCE.aimPointNode; aimPoint2.localScale = new Vector3(1f, 1f, 1f); gun2.aimPoint = aimPoint2.GetComponent <GameAimPointNormal>(); weapons.Add(gun2); this.nowIndex = 0; this.nowCount = 2; // 画布上的按钮挂上委托,使可攻击、攻击结束、换子弹、换枪 InstantiateAllEnd(); }
// 击中场景 protected virtual void ProcessHitScene() { string tag = this.target.tag; Transform transform = null; if (tag.EndsWith("Metal")) { transform = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletBoomMetal")) as Transform; AudioManager.INSTANCE.Play("Gun/hit_metal", Vector3.zero, 1f, Random.Range((float)0.9f, (float)1.1f), false, false); } else if (tag.EndsWith("Glass")) { transform = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletBoomMetal")) as Transform; AudioManager.INSTANCE.Play("Gun/hit_metal", Vector3.zero, 1f, Random.Range((float)0.75f, (float)1.25f), false, false); } else if (tag.EndsWith("MetalMove")) { transform = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletBoomMetalNoHole")) as Transform; AudioManager.INSTANCE.Play("Gun/hit_metal", Vector3.zero, 1f, Random.Range((float)0.9f, (float)1.1f), false, false); } else if (tag.EndsWith("NormalMove")) { transform = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletBoomSandNoHole")) as Transform; AudioManager.INSTANCE.Play("Gun/hit_wood", Vector3.zero, 1f, Random.Range((float)0.75f, (float)1.25f), false, false); } else { transform = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletBoomSand")) as Transform; if (Random.Range(0f, 1f) > 0.3f) { AudioManager.INSTANCE.Play("Gun/hit_rock", Vector3.zero, 1f, Random.Range((float)0.75f, (float)1.25f), false, false); } else { AudioManager.INSTANCE.Play("Gun/hit_wood", Vector3.zero, 1f, Random.Range((float)0.75f, (float)1.25f), false, false); } } // 向法线方向移动一点点,避免重合 transform.position = this.targetPos + (this.targetNormal * 0.025f); transform.forward = this.targetNormal; }
private void Fire() { this.lightTimer = 0.15f; // ? base.timer = 0f; if (this.isIgnoreTimeScale) { this.lastFireTime = Time.realtimeSinceStartup; } else { this.lastFireTime = Time.time; } Debug.Log("fire"); base.anim.Stop(); base.anim.Play("SHOOT"); // 初始化方位 Vector3 mainCameraForward = GameCameraController.INSTANCE.MainCameraTrans.forward; Vector3 mainCameraRight = GameCameraController.INSTANCE.MainCameraTrans.right; Vector3 mainCameraUp = GameCameraController.INSTANCE.MainCameraTrans.up; float num = 0.01f; // 测试 //if(base.isAimed) //{ // num = 0f; //} //else if((base.aimPoint != null) && (base.aimPoint is GameAimPointNormal)) //{ //} float num2 = Random.Range(-1f, 1) * num; float num3 = Random.Range(-1f, 1) * num; // 微小的偏移 Vector3 direction = (mainCameraForward + (num2 * mainCameraRight)) + (num3 * mainCameraUp); Ray ray = new Ray(GameCameraController.INSTANCE.MainCameraTrans.position, direction); GunBulletBase gunBulletBaseComp = null; RaycastHit hit; // 射线检测,少了layer参数,待补 if (Physics.Raycast(ray, out hit, 1000)) { Transform trans; // 待补 trans = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletNormal")) as Transform; // 起始位置为枪口火花处 trans.position = base.muzzleFlash.transform.position; // 设置上面挂着的GunBulletBase对象 gunBulletBaseComp = trans.GetComponent <GunBulletBase>(); gunBulletBaseComp.baseDmg = base.baseDmg; gunBulletBaseComp.basePower = base.basePower; gunBulletBaseComp.SetTarget(hit); } else // 如果没有检测到 { Debug.Log("没检测到目标,向前跑500m"); Transform trans2; // 待补 trans2 = Instantiate(PrefabResources.Get("Weapon/Bullet/BulletNormal")) as Transform; trans2.position = base.muzzleFlash.transform.position; gunBulletBaseComp = trans2.GetComponent <GunBulletBase>(); gunBulletBaseComp.SetTarget(base.muzzleFlash.transform.position + (mainCameraForward * 500)); } // 开枪震动效果 GameCameraController.INSTANCE.fireRot.ApplyFire(base.fireForce * 5f); GameCameraController.INSTANCE.fireShake.ApplyFire(base.fireForce * 10, base.fireForce * 0.1f); base.aimPoint.Shoot(base.fireForce); if (base.muzzleFlash != null) { muzzleFlash.SetFire(); } if (Time.timeScale < 0.5f) { // 受时间影响的声音 } else { AudioManager.INSTANCE.Play("Gun/" + base.weaponName + "_Shoot", 0.6f); } }