| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ArmBow : MonoBehaviour
- {
- [SerializeField] AnimationPlayer AP_arm;
- [SerializeField] AnimationPlayer AP_bow;
- [SerializeField] GameObject arrow;
- [SerializeField] BowCamera bowCamera;
- public HashSet<TargetBody> validTargets = new HashSet<TargetBody>();
- private bool canShoot = false;
- private bool pulling = false;
- private bool readying = false;
- public static ArmBow ins;
- void Start()
- {
- ins = this;
- this.readyShoot();
- }
- void OnDestroy()
- {
- ins = null;
- }
- void FixedUpdate()
- {
- if (this.canShoot)
- {
- if (DebugBowPower.ins != null) DebugBowPower.ins.DoUpdate();
- }
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Q))
- {
- this.ADS_fire();
- }
- if (this.pulling) {
- this.bowCamera.updateFollowPullBow();
- }
- else if (!this.canShoot)
- {
- this.bowCamera.updateGiveUpPullBow();
- }
- CrossHair.ins.gameObject.SetActive(this.canShoot);
- }
- void onComplete(AnimationPlayerCompleteResult res) {
- if (res.index == 0) {
- this.readying = true;
- this.idle();
- this.Invoke("idleToADS", 0.1f);
- }
- else if (res.index == 2) {
- this.ADS_idle();
- }
- }
- void ready() {
- this.arrow.SetActive(true);
- AP_arm.play(0, WrapMode.Once);
- AP_bow.play(0, WrapMode.Once);
- AP_arm.completeCallback = onComplete;
- this.pulling = false;
- this.canShoot = false;
- }
- void idle() {
- AP_arm.play(1, WrapMode.Loop);
- AP_bow.play(1, WrapMode.Loop);
- AP_arm.completeCallback = null;
- this.pulling = false;
- this.canShoot = false;
- if (DebugBowPower.ins != null) DebugBowPower.ins.Init();
- }
- public void idleToADS() {
- AP_arm.play(2, WrapMode.Once);
- AP_bow.play(2, WrapMode.Once);
- AP_arm.completeCallback = onComplete;
- this.pulling = true;
- this.canShoot = false;
- }
- void ADS_idle() {
- this.canShoot = true;
- this.pulling = false;
- if (DebugBowPower.ins != null) DebugBowPower.ins.PullFinish();
- }
- public void ADS_fire() {
- this.pulling = false;
- this.canShoot = false;
- this.readying = false;
- AP_arm.play(3, WrapMode.Once);
- AP_bow.play(3, WrapMode.Once);
- AP_arm.completeCallback = null;
- this.arrow.SetActive(false);
- this.Invoke("shoot", 0.1f);
- }
- public void readyShoot() {
- this.bowCamera.setFieldOfView(60, false);
- this.gameObject.SetActive(true);
- this.ready();
- }
- public void shoot() {
- // Vector3 rayHitPoint = CrossHair.ins.getRayHitPoint();
- GameObject arrowCopy = GameObject.Instantiate(this.arrow, this.bowCamera.transform.position, this.bowCamera.transform.rotation);
- Vector3 s1 = arrowCopy.transform.localScale;
- Vector3 s2 = bowCamera.transform.localScale;
- arrowCopy.transform.localScale = new Vector3(s1.x * s2.x, s1.y * s2.y, s1.z * s2.z);
- // arrowCopy.transform.LookAt(rayHitPoint);
- Arrow arrowComp = arrowCopy.AddComponent<Arrow>();
- arrowComp.armBow = this;
- // Arrow.speed = DebugBowPower.ins.getPowerPercent() * 100f;
- // Arrow.speed = BaseSpeedSlider.ins.getValue();
- // Arrow.speed = Mathf.Pow(ShootCheck.ins.shootSpeed, ShootCheck.ins.shootSpeed < 13 ? 2f: (ShootCheck.ins.shootSpeed < 15 ? 2.5f : 3.0f));
- Arrow.speed = ShootCheck.ins.shootSpeed/16*80;
- arrowCopy.SetActive(true);
- arrow.SetActive(false);
- AudioMgr.ins.PlayShoot(AudioMgr.GetAudioSource(arrowCopy));
- this.gameObject.SetActive(false);
- }
- public void OnEnable()
- {
- AudioMgr.GetAudioSource(this.gameObject).clip = null;
- }
- //debug
- public void mouseDown()
- {
- if (!this.readying) return;
- if (this.pulling || this.canShoot) return;
- this.idleToADS();
- }
- public void mouseUp()
- {
- if (!this.readying) return;
- if (this.pulling) {
- this.idle();
- } else if (this.canShoot) {
- this.ADS_fire();
- }
- }
- }
- // public class ArmBow : MonoBehaviour
- // {
- // [SerializeField] AnimationPlayer AP_arm;
- // [SerializeField] Animator AP_bow;
- // [SerializeField] AnimationPlayer AP_bowForArrow;
- // [SerializeField] GameObject arrow;
- // [SerializeField] BowCamera bowCamera;
- // public HashSet<TargetBody> validTargets = new HashSet<TargetBody>();
- // private bool canShoot = false;
- // private bool pulling = false;
- // private bool readying = false;
- // public static ArmBow ins;
- // void Start()
- // {
- // ins = this;
- // this.readyShoot();
- // }
- // void OnDestroy()
- // {
- // ins = null;
- // }
- // void FixedUpdate()
- // {
- // // if (this.canShoot)
- // // {
- // // DebugBowPower.ins.DoUpdate();
- // // }
- // }
- // void Update()
- // {
- // if (Input.GetKeyDown(KeyCode.Q))
- // {
- // this.ADS_fire();
- // }
- // if (this.pulling) {
- // this.bowCamera.updateFollowPullBow();
- // } else if (!this.canShoot)
- // {
- // this.bowCamera.updateGiveUpPullBow();
- // }
- // CrossHair.ins.gameObject.SetActive(this.canShoot);
- // }
- // void onComplete(AnimationPlayerCompleteResult res) {
- // if (res.index == 1) {
- // this.ADS_idle();
- // } else if (res.index == 3) {
- // this.idle();
- // }
- // }
- // void idle() {
- // this.arrow.SetActive(false);
- // AP_arm.play(0, WrapMode.Loop);
- // AP_bowForArrow.play(0, WrapMode.Loop);
- // // AP_bow.SetBool("ads", false);
- // // AP_bow.SetBool("fire", false);
- // AP_bow.Play("gong_daiji");
- // AP_arm.completeCallback = null;
- // this.pulling = false;
- // this.canShoot = false;
- // // DebugBowPower.ins.Init();
- // }
- // public void idleToADS() {
- // this.arrow.SetActive(true);
- // AP_arm.play(1, WrapMode.Once);
- // AP_bowForArrow.play(1, WrapMode.Once);
- // // AP_bow.SetBool("ads", true);
- // // AP_bow.SetBool("idle", false);
- // AP_bow.Play("gong_lagong");
- // AP_arm.completeCallback = onComplete;
- // this.pulling = true;
- // this.canShoot = false;
- // }
- // void ADS_idle() {
- // AP_arm.play(2, WrapMode.Loop);
- // AP_bowForArrow.play(2, WrapMode.Loop);
- // AP_bow.Play("gong_lagongdaiji");
- // AP_arm.completeCallback = null;
- // this.canShoot = true;
- // this.pulling = false;
- // // DebugBowPower.ins.PullFinish();
- // }
- // public void ADS_fire() {
- // if (!this.canShoot)
- // {
- // return;
- // }
- // this.pulling = false;
- // this.canShoot = false;
- // this.readying = false;
- // AP_arm.play(3, WrapMode.Once);
- // AP_bowForArrow.play(3, WrapMode.Once);
- // // AP_bow.SetBool("fire", true);
- // AP_bow.Play("gong_songshou");
- // AP_arm.completeCallback = onComplete;
- // this.Invoke("shoot", 0.1f);
- // }
- // public void readyShoot() {
- // this.readying = true;
- // this.bowCamera.setFieldOfView(60, false);
- // this.idle();
- // this.gameObject.SetActive(true);
- // this.Invoke("idleToADS", 0.5f);
- // }
- // public void shoot() {
- // Vector3 rayHitPoint = CrossHair.ins.getRayHitPoint();
- // GameObject arrowCopy = GameObject.Instantiate(this.arrow, this.bowCamera.transform.position, this.bowCamera.transform.rotation);
- // Vector3 s1 = arrowCopy.transform.localScale;
- // Vector3 s2 = bowCamera.transform.localScale;
- // arrowCopy.transform.localScale = new Vector3(s1.x * s2.x, s1.y * s2.y, s1.z * s2.z);
- // arrowCopy.transform.LookAt(rayHitPoint);
- // Arrow arrowComp = arrowCopy.AddComponent<Arrow>();
- // arrowComp.armBow = this;
- // // arrowComp.calculateSpeed(rayHitPoint);
- // // Arrow.speed = BaseSpeedSlider.ins.getValue() * DebugBowPower.ins.getPowerPercent();
- // // Arrow.speed = BaseSpeedSlider.ins.getValue();
- // Arrow.speed = Mathf.Pow(ShootCheck.ins.shootSpeed, ShootCheck.ins.shootSpeed < 13 ? 2f: (ShootCheck.ins.shootSpeed < 15 ? 2.5f : 3.0f));
- // arrowCopy.SetActive(true);
- // arrow.SetActive(false);
- // AudioMgr.ins.PlayShoot(AudioMgr.GetAudioSource(arrowCopy));
- // this.gameObject.SetActive(false);
- // }
- // public void OnEnable()
- // {
- // AudioMgr.GetAudioSource(this.gameObject).clip = null;
- // }
- // //debug
- // public void mouseDown()
- // {
- // if (!this.readying) return;
- // if (this.pulling || this.canShoot) return;
- // this.idleToADS();
- // }
- // public void mouseUp()
- // {
- // if (!this.readying) return;
- // if (this.pulling) {
- // this.idle();
- // } else if (this.canShoot) {
- // this.ADS_fire();
- // }
- // }
- // }
|