| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using DG.Tweening;
- using UnityEngine.SceneManagement;
- /* 游戏帮助界面(右侧方的辅助功能) */
- public class GameAssistUIDoublePlayer : MonoBehaviour
- {
- [SerializeField] Material outlight;
- Button btnScaleAim;
- Button btnScaleShoot;
- public Action action_OnClickBtnIdentity;
- public static GameAssistUIDoublePlayer ins;
- [Header("公共相关参数")]
- [SerializeField]
- Button btnBack;
- //当前操作的用户
- PlayerType currentPlayerType = PlayerType.FirstPlayer;
- [Header("1P相关参数")]
- [SerializeField]
- Button btnScaleAim1P;
- [SerializeField]
- Button btnScaleShoot1P;
- [SerializeField]
- Button btnCrosshair1P;
- [SerializeField]
- Button btnDoIdentity1P;
- [Header("2P相关参数")]
- [SerializeField]
- Button btnScaleAim2P;
- [SerializeField]
- Button btnScaleShoot2P;
- [SerializeField]
- Button btnCrosshair2P;
- [SerializeField]
- Button btnDoIdentity2P;
- void Awake()
- {
- ins = this;
- }
- public void onBtnBack()
- {
- AudioMgr.ins.PlayBtn();
- SceneManager.LoadScene("Home", LoadSceneMode.Single);
- //GameMgr.ins.userGameAnalyse.showResultView(() => {
- // SceneManager.LoadScene("Home", LoadSceneMode.Single);
- //});
- }
- void Start()
- {
- //返回主页
- btnBack.onClick.AddListener(onBtnBack);
- //控制瞄准镜
- btnScaleAim1P.onClick.AddListener(delegate ()
- {
- AudioMgr.ins.PlayBtn();
- currentPlayerType = PlayerType.FirstPlayer;
- if (btnScaleAim1P.GetComponentInChildren<Image>().material == outlight)
- {
- closeScaleAim();
- }
- else
- {
- openScaleAim();
- }
- });
- btnScaleAim2P.onClick.AddListener(delegate ()
- {
- AudioMgr.ins.PlayBtn();
- currentPlayerType = PlayerType.SecondPlayer;
- if (btnScaleAim2P.GetComponentInChildren<Image>().material == outlight)
- {
- closeScaleAim();
- }
- else
- {
- openScaleAim();
- }
- });
- //控制加速
- btnScaleShoot1P.onClick.AddListener(delegate ()
- {
- AudioMgr.ins.PlayBtn();
- currentPlayerType = PlayerType.FirstPlayer;
- if (btnScaleShoot1P.GetComponentInChildren<Image>().material == outlight)
- {
- closeScaleShoot();
- }
- else
- {
- openScaleShoot();
- }
- });
- btnScaleShoot2P.onClick.AddListener(delegate ()
- {
- AudioMgr.ins.PlayBtn();
- currentPlayerType = PlayerType.SecondPlayer;
- if (btnScaleShoot2P.GetComponentInChildren<Image>().material == outlight)
- {
- closeScaleShoot();
- }
- else
- {
- openScaleShoot();
- }
- });
- defaultOpenScaleShoot();
- //重置中心点
- btnDoIdentity1P.onClick.AddListener(delegate ()
- {
- if (btnDoIdentity1P.GetComponent<LongPressMonitor>().isLongPress) return;
- AudioMgr.ins.PlayBtn();
- if (GameObject.Find("AutoResetViewNewLeft")) return;
- GameObject resetView = Instantiate(Resources.Load<GameObject>("AutoResetViewNew"));
- resetView.name = "AutoResetViewNewLeft";
- AutoResetViewNew autoResetViewNewScript = resetView.GetComponent<AutoResetViewNew>();
- autoResetViewNewScript.setPosLeft();
- autoResetViewNewScript.action_OnDestroy += () =>
- {
- if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
- {
- InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.FirstPlayer);
- }
- else
- {
- //使用旧模式重置1p
- AimHandler.ins?.DoIdentity();
- }
- };
- //action_OnClickBtnIdentity?.Invoke();
- });
- btnDoIdentity1P.gameObject.AddComponent<LongPressMonitor>().onLongPress += () =>
- {
- AudioMgr.ins.PlayBtn();
- if (SB_EventSystem.ins) SB_EventSystem.ins.AwakenSimulateMouse();
- };
- //重置中心点
- btnDoIdentity2P.onClick.AddListener(delegate ()
- {
- if (btnDoIdentity2P.GetComponent<LongPressMonitor>().isLongPress) return;
- AudioMgr.ins.PlayBtn();
- if (GameObject.Find("AutoResetViewNewRight")) return;
- GameObject resetView = Instantiate(Resources.Load<GameObject>("AutoResetViewNew"));
- resetView.name = "AutoResetViewNewRight";
- AutoResetViewNew autoResetViewNewScript = resetView.GetComponent<AutoResetViewNew>();
- autoResetViewNewScript.setPosRight();
- autoResetViewNewScript.action_OnDestroy += () =>
- {
- if (SceneManager.GetActiveScene().name == "InfraredGameDouble")
- {
- InfraredDemo._ins?.SetAdjustPointsOffset(PlayerType.SecondPlayer);
- }
- else {
- //使用新模式重置2p
- if (BluetoothAim.ins.getSmartBowHelper2P() != null)
- {
- BluetoothAim.ins.getSmartBowHelper2P().ResetAim();
- }
- }
- };
- //action_OnClickBtnIdentity?.Invoke();
- });
- btnDoIdentity2P.gameObject.AddComponent<LongPressMonitor>().onLongPress += () =>
- {
- AudioMgr.ins.PlayBtn();
- if (SB_EventSystem.ins) SB_EventSystem.ins.AwakenSimulateMouse();
- };
- if(btnCrosshair1P != null) InitCrosshair(PlayerType.FirstPlayer, btnCrosshair1P);
- if(btnCrosshair2P != null) InitCrosshair(PlayerType.SecondPlayer, btnCrosshair2P);
- // ------ 查看靶子 ------
- //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 || GameMgr.gameType == 9) {
- // targetView.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 30);
- // btnViewTarget.transform.GetComponent<RectTransform>().anchoredPosition = new Vector2(45, 195);
- //}
- LoadMyRecord();
- applyPlayerRecordsWhenGameTryAgain();
- }
- /// <summary>
- /// 准心显示
- /// </summary>
- /// <param name="playerType"></param>
- public void InitCrosshair(PlayerType playerType, Button btnCrosshair)
- {
- if (InfraredDemo._ins == null) return;
- AimCrossHair aimCrossHair = GameController.ins.GetAimCrossHair(playerType);
- //设置准心是否显示
- aimCrossHair.SetOnlyShow(InfraredDemo._ins.getDoubleCrosshairValue(playerType) == 1);
- aimCrossHair.SyncVisiable();
- bool onInitOpen = aimCrossHair.GetOnlyShow();
- Image crossHairImage = btnCrosshair.GetComponentInChildren<Image>();
- crossHairImage.material = onInitOpen ? outlight : null;
- btnCrosshair.onClick.AddListener(delegate () {
- AudioMgr.ins.PlayBtn();
- bool onlyShow = !aimCrossHair.GetOnlyShow();
- aimCrossHair.SetOnlyShow(onlyShow);
- //保存准心状态
- if (InfraredDemo._ins) InfraredDemo._ins.setDoubleCrosshairValue(playerType, onlyShow);
- if (onlyShow)
- {
- crossHairImage.material = outlight;
- }
- else
- {
- crossHairImage.material = null;
- }
- });
- }
- void OnDestroy()
- {
- if (ins == null) ins = null;
- SaveMyRecord();
- }
- void Update()
- {
- }
- [System.NonSerialized] public int playerScaleAimValue_OnlinePK = 0;
- bool[] playerScaleAimRecords = { false, false };
- bool[] playerScaleShootRecords = { false, false };
- int GetMyPlayerIndex()
- {
- if (GlobalData.pkMatchType == PKMatchType.OnlinePK)
- {
- // return GlobalData.playerIndexInRoom;
- return 0;
- }
- return 0;
- }
- int GetCurPlayerIndex()
- {
- if (GlobalData.pkMatchType == PKMatchType.OnlinePK)
- {
- // GameMode gm = GameMgr.ins.gameMode;
- // if (GameMgr.gameType == 9) return ((PKGameMode_OnlinePK) gm).gameLogic.currentPlayerIndex;
- return 0;
- }
- else if (GlobalData.pkMatchType == PKMatchType.LocalPK)
- {
- GameMode gm = GameMgr.ins.gameMode;
- if (GameMgr.gameType == 2) return ((PKGameMode)gm).currentPlayerIndex;
- if (GameMgr.gameType == 6) return ((RabbitHuntGameMode_LocalPK)gm).currentPlayerIndex;
- if (GameMgr.gameType == 7) return ((YejiHuntGameMode_LocalPK)gm).currentPlayerIndex;
- if (GameMgr.gameType == 8) return ((WolfHuntGameMode_LocalPK)gm).currentPlayerIndex;
- }
- return 0;
- }
- void SaveMyRecord()
- {
- int gameType = 0; //多种模式共用记录
- int myPlayerIndex = GetMyPlayerIndex();
- bool isScaleAimOpen = playerScaleAimRecords[myPlayerIndex];
- bool isScaleShootOpen = playerScaleShootRecords[myPlayerIndex];
- PlayerPrefs.SetInt("ScaleAim," + gameType + "," + LoginMgr.myUserInfo.id, isScaleAimOpen ? 1 : 0);
- PlayerPrefs.SetInt("ScaleShoot," + gameType + "," + LoginMgr.myUserInfo.id, isScaleShootOpen ? 1 : 0);
- }
- void LoadMyRecord()
- {
- int gameType = 0; //多种模式共用记录
- if (CommonConfig.SpecialVersion1)
- {
- if (PlayerPrefs.GetInt("sv1_ScaleAimShoot," + LoginMgr.myUserInfo.id, 0) == 0)
- {
- PlayerPrefs.SetInt("sv1_ScaleAimShoot," + LoginMgr.myUserInfo.id, 1);
- PlayerPrefs.SetInt("ScaleAim," + gameType + "," + LoginMgr.myUserInfo.id, 0);
- PlayerPrefs.SetInt("ScaleShoot," + gameType + "," + LoginMgr.myUserInfo.id, 1);
- }
- }
- bool isScaleAimOpen = PlayerPrefs.GetInt("ScaleAim," + gameType + "," + LoginMgr.myUserInfo.id, 0) == 1 ? true : false;
- bool isScaleShootOpen = PlayerPrefs.GetInt("ScaleShoot," + gameType + "," + LoginMgr.myUserInfo.id, 0) == 1 ? true : false;
- if (isScaleAimOpen && GetPropScaleAimValue() == 0)
- {
- isScaleAimOpen = false;
- }
- if (isScaleShootOpen && getScaleShootProp() == null)
- {
- isScaleShootOpen = false;
- }
- int myPlayerIndex = GetMyPlayerIndex();
- playerScaleAimRecords[myPlayerIndex] = isScaleAimOpen;
- playerScaleShootRecords[myPlayerIndex] = isScaleShootOpen;
- if (isLocalPK())
- {
- playerScaleAimRecords[(myPlayerIndex + 1) % 2] = isScaleAimOpen;
- playerScaleShootRecords[(myPlayerIndex + 1) % 2] = isScaleShootOpen;
- }
- }
- #region 本地双人PK,再来时保存记录
- private static bool[] playerRecords = null;
- private bool isLocalPK()
- {
- int[] gameTypes = { 2, 6, 7, 8 };
- if (System.Array.IndexOf(gameTypes, GameMgr.gameType) > -1)
- {
- return true;
- }
- return false;
- }
- public void recordPlayerRecordsWhenGameTryAgain()
- {
- if (!isLocalPK()) 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;
- }
- }
- #endregion
- #region 道具开关监听
- private void onOpenScaleAimSuccess()
- {
- playerScaleAimRecords[GetCurPlayerIndex()] = true;
- }
- private void onCloseScaleAimSuccess()
- {
- playerScaleAimRecords[GetCurPlayerIndex()] = false;
- }
- private void onOpenScaleShootSuccess()
- {
- playerScaleShootRecords[GetCurPlayerIndex()] = true;
- }
- private void onCloseScaleShootSuccess()
- {
- playerScaleShootRecords[GetCurPlayerIndex()] = false;
- }
- #endregion
- // ------ 开镜瞄准功能 ------
- [System.NonSerialized] public int aimScaleValue = 1;
- float[] scaleAimFieldOfViews = { 30, 20, 12, 6, 3 };
- float[] scaleAimScopeScales = { 150, 98, 58, 29, 14.5f };
- Sequence seq1 = null;
- [System.NonSerialized] public bool scaleAimOn = false; //该功能是否处于打开状态
- bool openScaleAim()
- {
- int scaleValue = GetPropScaleAimValue();
- if (scaleValue > 0)
- {
- if (currentPlayerType == PlayerType.FirstPlayer)
- {
- btnScaleAim1P.GetComponentInChildren<Image>().material = outlight;
- }
- else
- {
- btnScaleAim2P.GetComponentInChildren<Image>().material = outlight;
- }
- aimScaleValue = scaleValue;
- DisplayScaleAim(true, aimScaleValue);
- //scaleAimOn = true;
- // onOpenScaleAimSuccess();
- return true;
- }
- return false;
- }
- int aimScaleDisplayValue = -1;
- void DisplayScaleAim(bool open, int scaleValue)
- { //渲染
- aimScaleDisplayValue = scaleValue;
- Debug.Log("DisplayScaleAim:" + currentPlayerType);
- BowCameraDoublePlayer bowCamera = GameController.ins.GetBowCameraDoublePlayer(currentPlayerType);
- Transform scope = bowCamera.transform.Find("Scope");
- GameController.ins.GetAimCrossHair(currentPlayerType).gameObject.GetComponent<RectTransform>().sizeDelta =
- open ? new Vector2(500, 500) : new Vector2(260, 260);
- if (open) GameController.ins.GetAimCrossHair(currentPlayerType).openDisplayToCenter();// //Vector3.zero;
- bowCamera.banCameraFieldOfView = open;
- bowCamera.SetScaleAimDisplaying(open);
- if (open)
- {
- bowCamera.SetCameraFieldOfView(scaleAimFieldOfViews[scaleValue - 1]);
- }
- ArmBowDoublePlayer armbowDoublePlayer = GameController.ins.GetArmBowDoublePlayer(currentPlayerType);
- Vector3 localPosition = armbowDoublePlayer.transform.localPosition;
- localPosition.z = open ? -2 : ArmBowDoublePlayer.localPosZ;
- armbowDoublePlayer.transform.localPosition = localPosition;
- if (open)
- {
- float scopeScale = scaleAimScopeScales[scaleValue - 1];
- scope.localScale = new Vector3(scopeScale, scopeScale, scopeScale);
- }
- else
- {
- scope.localScale = new Vector3(0, 0, 0);
- }
- }
- void closeScaleAim()
- {
- if (currentPlayerType == PlayerType.FirstPlayer)
- {
- btnScaleAim1P.GetComponentInChildren<Image>().material = null;
- }
- else
- {
- btnScaleAim2P.GetComponentInChildren<Image>().material = null;
- }
- DisplayScaleAim(false, aimScaleValue);
- //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;
- }
- // ------ 发射加速功能 ------
- [System.NonSerialized] public int shootScaleValue = 1;
- [System.NonSerialized] public int shootScaleValue2P = 1;
- Sequence seq2 = null;
- bool scaleShootOn = false; //该功能是否处于打开状态
- //默认开启两个加速
- void defaultOpenScaleShoot() {
- PropInfo prop = getScaleShootProp();
- if (prop != null)
- {
- PropScaleShoot config = prop.config as PropScaleShoot;
- btnScaleShoot1P.GetComponentInChildren<Image>().material = outlight;
- shootScaleValue = config.scaleValue;
- btnScaleShoot2P.GetComponentInChildren<Image>().material = outlight;
- shootScaleValue2P = config.scaleValue;
- }
- }
- bool openScaleShoot()
- {
- PropInfo prop = getScaleShootProp();
- if (prop != null)
- {
- PropScaleShoot config = prop.config as PropScaleShoot;
- if (currentPlayerType == PlayerType.FirstPlayer)
- {
- btnScaleShoot1P.GetComponentInChildren<Image>().material = outlight;
- shootScaleValue = config.scaleValue;
- }
- else
- {
- btnScaleShoot2P.GetComponentInChildren<Image>().material = outlight;
- shootScaleValue2P = config.scaleValue;
- }
- //scaleShootOn = true;
- //onOpenScaleShootSuccess();
- return true;
- }
- return false;
- }
- void closeScaleShoot()
- {
- if (currentPlayerType == PlayerType.FirstPlayer)
- {
- btnScaleShoot1P.GetComponentInChildren<Image>().material = null;
- shootScaleValue = 1;
- }
- else
- {
- btnScaleShoot2P.GetComponentInChildren<Image>().material = null;
- shootScaleValue2P = 1;
- }
- // scaleShootOn = false;
- // onCloseScaleShootSuccess();
- }
- PropInfo getScaleShootProp()
- {
- List<PropInfo> props = PropMgr.ins.ListForEquipped();
- foreach (var prop in props)
- {
- if (prop.config.type == 2)
- {
- return prop;
- }
- }
- return null;
- }
- }
|