| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using DG.Tweening;
- using UnityEngine.SceneManagement;
- public class GameAssistUI : MonoBehaviour
- {
- [SerializeField] Material outlight;
- [SerializeField] Text text1;
- [SerializeField] Text text2;
- public static GameAssistUI ins;
- void Awake() {
- ins = this;
- }
- void Start()
- {
- this.transform.Find("Button0").GetComponent<Button>().onClick.AddListener(delegate(){
- AudioMgr.ins.PlayBtn();
- SceneManager.LoadScene("Home", LoadSceneMode.Single);
- });
- this.transform.Find("Button1").GetComponent<Button>().onClick.AddListener(delegate(){
- AudioMgr.ins.PlayBtn();
- GameRuleView.Create();
- });
- Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
- btnScaleAim.onClick.AddListener(delegate(){
- AudioMgr.ins.PlayBtn();
- if (btnScaleAim.GetComponentInChildren<Image>().material == outlight) {
- btnScaleAim.GetComponentInChildren<Image>().material = null;
- closeScaleAim();
- } else {
- if (openScaleAim()) {
- btnScaleAim.GetComponentInChildren<Image>().material = outlight;
- }
- }
- });
- Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
- btnScaleShoot.onClick.AddListener(delegate(){
- AudioMgr.ins.PlayBtn();
- if (btnScaleShoot.GetComponentInChildren<Image>().material == outlight) {
- btnScaleShoot.GetComponentInChildren<Image>().material = null;
- closeScaleShoot();
- } else {
- if (openScaleShoot()) {
- btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
- }
- }
- });
- Button btnIdentity = this.transform.Find("Button4").GetComponent<Button>();
- btnIdentity.onClick.AddListener(delegate(){
- AudioMgr.ins.PlayBtn();
- AimHandler.ins.DoIdentity();
- });
- // ------ 查看靶子 ------
- Transform targetView = this.transform.Find("TargetView");
- Button btnViewTarget = this.transform.Find("Button10").GetComponent<Button>();
- btnViewTarget.onClick.AddListener(delegate(){
- AudioMgr.ins.PlayBtn();
- TargetView.ins.ReverseActive();
- });
- if (GameMgr.gameType == 2) {
- targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
- btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
- }
- //看看是不是双人游戏的再次对战
- applyPlayerRecordsWhenGameTryAgain();
- }
- // ------ 开镜瞄准功能 ------
- Transform scope = null;
- float[] scaleAimFieldOfViews = {30, 20, 12, 6, 3};
- float[] scaleAimScopeScales = {150, 98, 58, 29, 14.5f};
- Sequence seq1 = null;
- bool scaleAimOn = false; //该功能是否处于打开状态
- bool openScaleAim()
- {
- int scaleValue = GetPropScaleAimValue();
- if (scaleValue > 0)
- {
- BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
- bowCamera.banCameraFieldOfView = true;
- CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 500);
- bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
- Vector3 localPosition = ArmBow.ins.transform.localPosition;
- localPosition.z = -2;
- ArmBow.ins.transform.localPosition = localPosition;
- scope = bowCamera.transform.Find("Scope");
- float scopeScale = scaleAimScopeScales[scaleValue - 1];
- scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
- scaleAimOn = true;
- onOpenScaleAimSuccess();
- return true;
- }
- if (seq1 != null && !seq1.IsComplete()) {
- seq1.Complete();
- }
- seq1 = DOTween.Sequence();
- seq1.Append(text1.DOFade(1, 0.5f));
- seq1.AppendInterval(2);
- seq1.Append(text1.DOFade(0, 0.5f));
- return false;
- }
- void closeScaleAim()
- {
- BowCamera bowCamera = GameObject.FindObjectOfType<BowCamera>();
- bowCamera.banCameraFieldOfView = false;
- CrossHair.ins.gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(260, 260);
- Vector3 localPosition = ArmBow.ins.transform.localPosition;
- localPosition.z = -0.1f;
- ArmBow.ins.transform.localPosition = localPosition;
- scope.localScale = new Vector3(0, 0, 0);
- scope = null;
- scaleAimOn = false;
- onCloseScaleAimSuccess();
- }
- int GetPropScaleAimValue()
- {
- List<PropInfo> props = PropMgr.ins.ListForEquipped();
- foreach (var prop in props)
- {
- if (prop.config.type == 1) {
- PropScaleAim config = prop.config as PropScaleAim;
- return config.scaleValue;
- }
- }
- return 0;
- }
- // ------ 发射加速功能 ------
- public int shootScaleValue = 1;
- Sequence seq2 = null;
- bool scaleShootOn = false; //该功能是否处于打开状态
- bool openScaleShoot()
- {
- List<PropInfo> props = PropMgr.ins.ListForEquipped();
- foreach (var prop in props)
- {
- if (prop.config.type == 2) {
- PropScaleShoot config = prop.config as PropScaleShoot;
- shootScaleValue = config.scaleValue;
- if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
- scaleShootOn = true;
- onOpenScaleShootSuccess();
- return true;
- }
- }
- if (seq2 != null && !seq2.IsComplete()) {
- seq2.Complete();
- }
- seq2 = DOTween.Sequence();
- seq2.Append(text2.DOFade(1, 0.5f));
- seq2.AppendInterval(2);
- seq2.Append(text2.DOFade(0, 0.5f));
- return false;
- }
- void closeScaleShoot()
- {
- shootScaleValue = 1;
- if (GameDebug.ins) GameDebug.ins.caluculateAbsoluteAngle();
- scaleShootOn = false;
- onCloseScaleShootSuccess();
- }
- //------ 以下给双人模式分别记录提供的接口 ------
- //两位玩家的开镜情况
- bool[] playerScaleAimRecords = {false, false};
- //两位玩家的加速情况
- bool[] playerScaleShootRecords = {false, false};
- private void onOpenScaleAimSuccess() {
- if (GameMgr.gameType == 2) {
- playerScaleAimRecords[getPlayerIndex()] = true;
- }
- }
- private void onCloseScaleAimSuccess() {
- if (GameMgr.gameType == 2) {
- playerScaleAimRecords[getPlayerIndex()] = false;
- }
- }
- private void onOpenScaleShootSuccess() {
- if (GameMgr.gameType == 2) {
- playerScaleShootRecords[getPlayerIndex()] = true;
- }
- }
- private void onCloseScaleShootSuccess() {
- if (GameMgr.gameType == 2) {
- playerScaleShootRecords[getPlayerIndex()] = false;
- }
- }
- private int getPlayerIndex() {
- return ((PKGameMode) GameMgr.ins.gameMode).currentPlayerIndex;
- }
- private void updateFunctionByPlayerRecords() {
- if (GameMgr.gameType != 2) return;
- int playerIndex = getPlayerIndex();
- if (scaleAimOn != playerScaleAimRecords[playerIndex]) {
- Button btnScaleAim = this.transform.Find("Button2").GetComponent<Button>();
- if (playerScaleAimRecords[playerIndex]) {
- if (openScaleAim()) {
- btnScaleAim.GetComponentInChildren<Image>().material = outlight;
- }
- } else {
- btnScaleAim.GetComponentInChildren<Image>().material = null;
- closeScaleAim();
- }
- }
- if (scaleShootOn != playerScaleShootRecords[playerIndex]) {
- Button btnScaleShoot = this.transform.Find("Button3").GetComponent<Button>();
- if (playerScaleShootRecords[playerIndex]) {
- if (openScaleShoot()) {
- btnScaleShoot.GetComponentInChildren<Image>().material = outlight;
- }
- } else {
- btnScaleShoot.GetComponentInChildren<Image>().material = null;
- closeScaleShoot();
- }
- }
- }
- private static bool[] playerRecords = null;
- public void recordPlayerRecordsWhenGameTryAgain() {
- if (GameMgr.gameType != 2) return;
- playerRecords = new bool[] {
- playerScaleAimRecords[0], playerScaleAimRecords[1],
- playerScaleShootRecords[0], playerScaleShootRecords[1]
- };
- }
- private void applyPlayerRecordsWhenGameTryAgain() {
- if (playerRecords != null) {
- playerScaleAimRecords[0] = playerRecords[0];
- playerScaleAimRecords[1] = playerRecords[1];
- playerScaleShootRecords[0] = playerRecords[2];
- playerScaleShootRecords[1] = playerRecords[3];
- playerRecords = null;
- }
- }
- void Update() {
- updateFunctionByPlayerRecords();
- }
- }
|