367 lines
11 KiB
C#
367 lines
11 KiB
C#
using Assets.Scripts;
|
||
using Assets.Scripts.UI.Control;
|
||
using DG.Tweening;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.UI;
|
||
|
||
public class NewMainNav : MonoBehaviour
|
||
{
|
||
public class CustomButton
|
||
{
|
||
public Sprite image;
|
||
public UnityAction action;
|
||
public bool isAlways;
|
||
public CustomButton(Sprite image, UnityAction action)
|
||
{
|
||
this.image = image;
|
||
this.action = action;
|
||
isAlways = true;
|
||
}
|
||
|
||
public CustomButton(Sprite image, UnityAction action,bool isAlways)
|
||
{
|
||
this.image = image;
|
||
this.action = action;
|
||
isAlways = false;
|
||
}
|
||
}
|
||
private GameObject exit;
|
||
private GameObject home;
|
||
private GameObject back;
|
||
float delayTime = 0;
|
||
private List<string> typeArray = new List<string>()
|
||
{
|
||
"Back","Exit","Home","Device","Delay","Setting","Support","Avatar","Custom","Custom2","Mail","Custom3"
|
||
};
|
||
private List<int> indexs = new List<int>();
|
||
private int? shrinkIndex = null;
|
||
private CustomButton custom = null,custom2 = null, custom3 = null;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="indexs">仅展开显示的按钮:1:"Exit",3:"Device",4:"Delay",5:"Setting",6:"Support",7:"Avatar"</param>
|
||
/// <param name="shrinkIndex">合上后仍显示的按钮:0:"Back",2:"Home",null:仅PF</param>
|
||
/// <param name="custom">自定义按钮 8:c1 9:c2 11:c3</param>
|
||
public void SetButtonActive(List<int> indexs,int? shrinkIndex = null, CustomButton custom = null, CustomButton custom2 = null,CustomButton custom3 = null,bool ShowMail = true)
|
||
{
|
||
this.indexs = indexs;
|
||
|
||
if (ShowMail)
|
||
{
|
||
//邮箱常驻(除划船机)
|
||
this.indexs.Add(10);
|
||
}
|
||
this.shrinkIndex = shrinkIndex;
|
||
this.custom = custom;
|
||
this.custom2 = custom2;
|
||
this.custom3 = custom3;
|
||
if (custom != null)
|
||
{
|
||
transform.Find("Custom").GetComponent<Button>().onClick.RemoveAllListeners();
|
||
transform.Find("Custom").GetComponent<Button>().onClick.AddListener(custom.action);
|
||
transform.Find("Custom").GetComponent<Image>().sprite = custom.image;
|
||
indexs.Add(8);
|
||
}
|
||
if (custom2 != null)
|
||
{
|
||
transform.Find("Custom2").GetComponent<Button>().onClick.RemoveAllListeners();
|
||
transform.Find("Custom2").GetComponent<Button>().onClick.AddListener(custom2.action);
|
||
transform.Find("Custom2").GetComponent<Image>().sprite = custom2.image;
|
||
indexs.Add(9);
|
||
}
|
||
if (custom3 != null)
|
||
{
|
||
transform.Find("Custom3").GetComponent<Button>().onClick.RemoveAllListeners();
|
||
transform.Find("Custom3").GetComponent<Button>().onClick.AddListener(custom3.action);
|
||
transform.Find("Custom3").GetComponent<Image>().sprite = custom3.image;
|
||
indexs.Add(11);
|
||
}
|
||
SetExpand(false);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// true:展开 false:关闭
|
||
/// </summary>
|
||
/// <param name="flag"></param>
|
||
public void SetExpand(bool flag)
|
||
{
|
||
if (flag)
|
||
{
|
||
autoClose = true;
|
||
}
|
||
else
|
||
{
|
||
autoClose = false;
|
||
}
|
||
closeTime = 5f;
|
||
List<string> types = new List<string>();
|
||
if (indexs != null)
|
||
{
|
||
types = typeArray.Where((x, i) => indexs.Contains(i)).ToList();
|
||
}
|
||
string shrinkName = null;
|
||
if (shrinkIndex.HasValue && isShrinkIndex(shrinkIndex.Value))
|
||
{
|
||
shrinkName = typeArray[shrinkIndex.Value];
|
||
}
|
||
foreach (Transform item in transform)
|
||
{
|
||
if (flag)
|
||
{
|
||
if (item.name == "Down")
|
||
{
|
||
item.gameObject.SetActive(true);
|
||
}
|
||
else if (item.name == "PF")
|
||
{
|
||
item.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
item.gameObject.SetActive(types.Contains(item.name));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
item.gameObject.SetActive(item.name == "PF" || item.name == shrinkName);
|
||
}
|
||
if (item.name == "Custom" || item.name == "Custom2" || item.name == "Custom3")
|
||
{
|
||
//自定义按钮出来
|
||
CustomButton c = null;
|
||
if (item.name == "Custom")
|
||
{
|
||
c = custom;
|
||
}
|
||
else if (item.name == "Custom2")
|
||
{
|
||
c = custom2;
|
||
}
|
||
else if (item.name == "Custom3")
|
||
{
|
||
c = custom3;
|
||
}
|
||
item.gameObject.SetActive(c != null && types.Contains(item.name) && (flag || !flag && c.isAlways));
|
||
}
|
||
}
|
||
}
|
||
|
||
public void ShowButton(string v)
|
||
{
|
||
var i = typeArray.FindIndex((x)=>x == v);
|
||
if (i == -1 || isShrinkIndex(i))
|
||
{
|
||
return;
|
||
}
|
||
indexs.Add(i);
|
||
SetExpand(false);
|
||
}
|
||
public void HideButton(string v)
|
||
{
|
||
var i = typeArray.FindIndex((x) => x == v);
|
||
if (i == -1 || isShrinkIndex(i))
|
||
{
|
||
return;
|
||
}
|
||
Debug.Log(i);
|
||
indexs.RemoveAll(x => x == i);
|
||
SetExpand(false);
|
||
}
|
||
|
||
|
||
private void Awake()
|
||
{
|
||
Utils.DisplayHead(transform.Find("Avatar").GetComponent<Image>(), App.CurrentUser.WxHeadImg);
|
||
UIManager.AddEvent(transform.Find("Avatar").gameObject, EventTriggerType.PointerClick, b =>
|
||
{
|
||
if (App.IsRowerMode == true)
|
||
{
|
||
if (UIManager.Instance.RowerHomeScript.checkRowing()) return;
|
||
UIManager.ShowEditUserPanel();
|
||
}
|
||
else
|
||
{
|
||
UIManager.ShowUserInfoPanel();
|
||
}
|
||
});
|
||
UIManager.AddEvent(transform.Find("PF").gameObject, EventTriggerType.PointerClick, b =>
|
||
{
|
||
SetExpand(true);
|
||
});
|
||
UIManager.AddEvent(transform.Find("Down").gameObject, EventTriggerType.PointerClick, b =>
|
||
{
|
||
SetExpand(false);
|
||
});
|
||
//var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||
|
||
//var rect = ((RectTransform)this.transform).rect;
|
||
//material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||
//this.GetComponent<Image>().material = material;
|
||
|
||
var device = this.transform.Find("Device");
|
||
UIManager.AddEvent(device.gameObject, EventTriggerType.PointerClick, x =>
|
||
{
|
||
//Debug.Log("click device");
|
||
if (App.IsRowerMode.HasValue && App.IsRowerMode.Value)
|
||
{
|
||
if (UIManager.Instance.RowerHomeScript.checkRowing()) return;
|
||
UIManager.ShowRowerDevicePanel();
|
||
}
|
||
else
|
||
{
|
||
UIManager.ShowDevicePanel();
|
||
}
|
||
});
|
||
|
||
home = this.transform.Find("Home").gameObject;
|
||
UIManager.AddEvent(home, EventTriggerType.PointerClick, x =>
|
||
{
|
||
UIManager.ShowHomePanel();
|
||
});
|
||
|
||
exit = this.transform.Find("Exit").gameObject;
|
||
exit.SetActive(false);
|
||
back = transform.Find("Back").gameObject;
|
||
back.SetActive(false);
|
||
#if UNITY_ANDROID || UNITY_IOS
|
||
UIManager.AddEvent(transform.Find("Delay").gameObject, EventTriggerType.PointerClick, b =>
|
||
{
|
||
if (delayTime <= 0)
|
||
{
|
||
delayTime = 3;
|
||
transform.Find("Delay/Tooltips").gameObject.SetActive(true);
|
||
transform.Find("Delay/Tooltips").GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
||
}
|
||
else
|
||
{
|
||
delayTime = 0;
|
||
transform.Find("Delay/Tooltips").GetComponent<CanvasGroup>().DOFade(0, 0.5f).onComplete = () =>
|
||
{
|
||
transform.Find("Delay/Tooltips").gameObject.SetActive(false);
|
||
};
|
||
}
|
||
});
|
||
#endif
|
||
//transform.Find("Delay").GetComponent<PfUIButton>().showTooltip = true;
|
||
UIManager.AddEvent(exit, EventTriggerType.PointerClick, (e) =>
|
||
{
|
||
UIManager.ShowConfirm("Quit", "Do you want to quit PowerFun?", ()=> {
|
||
Application.Quit();
|
||
},2);
|
||
});
|
||
UIManager.AddEvent(back, EventTriggerType.PointerClick, (e) =>
|
||
{
|
||
UIManager.ShowPrePanel();
|
||
});
|
||
|
||
UIManager.AddEvent(transform.Find("Setting").gameObject, EventTriggerType.PointerClick, x =>
|
||
{
|
||
UIManager.ShowSettingModal();
|
||
});
|
||
UIManager.AddEvent(transform.Find("Support").gameObject, EventTriggerType.PointerClick, x =>
|
||
{
|
||
UIManager.ShowFeedBackModal();
|
||
});
|
||
UIManager.AddEvent(transform.Find("Mail").gameObject, EventTriggerType.PointerClick, x =>
|
||
{
|
||
UIManager.ShowMailListPanel();
|
||
});
|
||
App.HasNotReadChanged -= ShowMailDot;
|
||
App.HasNotReadChanged += ShowMailDot;
|
||
}
|
||
private void ShowMailDot(object sender, EventArgs e)
|
||
{
|
||
if (transform)
|
||
{
|
||
transform.Find("Mail/Dot").gameObject.SetActive((bool)sender);
|
||
}
|
||
}
|
||
|
||
|
||
public void ShowRowerTab()
|
||
{
|
||
if (transform.Find("Device"))
|
||
{
|
||
transform.Find("Device").gameObject.SetActive(false);
|
||
}
|
||
if (transform.Find("Exit"))
|
||
{
|
||
transform.Find("Exit").gameObject.SetActive(true);
|
||
}
|
||
if (transform.Find("Home"))
|
||
{
|
||
transform.Find("Home").gameObject.SetActive(false);
|
||
}
|
||
}
|
||
private bool isShrinkIndex(int ind)
|
||
{
|
||
return ind == 0 || ind == 2;
|
||
}
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
|
||
}
|
||
bool isTouch = false;
|
||
float hideTime = 5;
|
||
|
||
bool autoClose = false;
|
||
float closeTime = 5;
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
if (Input.touchCount > 0)
|
||
{
|
||
isTouch = true;
|
||
if (autoClose)
|
||
{
|
||
closeTime = 5f;
|
||
}
|
||
GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
||
}
|
||
hideTime -= Time.deltaTime;
|
||
if (hideTime < 0)
|
||
{
|
||
if (!isTouch)
|
||
{
|
||
GetComponent<CanvasGroup>().DOFade(0.4f, 0.5f);
|
||
}
|
||
isTouch = false;
|
||
hideTime += 5;
|
||
}
|
||
//Debug.Log(Input.touchCount);
|
||
if (delayTime < 0)
|
||
{
|
||
Debug.Log("小时");
|
||
delayTime = 0;
|
||
transform.Find("Delay/Tooltips").GetComponent<CanvasGroup>().DOFade(0, 0.5f).onComplete = () =>
|
||
{
|
||
transform.Find("Delay/Tooltips").gameObject.SetActive(false);
|
||
};
|
||
}
|
||
else if (delayTime > 0)
|
||
{
|
||
Debug.Log(delayTime);
|
||
delayTime -= Time.deltaTime;
|
||
}
|
||
|
||
closeTime -= Time.deltaTime;
|
||
if (closeTime < 0)
|
||
{
|
||
if (autoClose)
|
||
{
|
||
Debug.Log("关一次");
|
||
SetExpand(false);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|