278 lines
8.7 KiB
C#
Raw Normal View History

2021-12-28 11:25:09 +08:00
using Assets.Scripts;
using Assets.Scripts.UI.Control;
2021-12-27 09:39:07 +08:00
using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
2021-12-27 09:39:07 +08:00
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class NewMainNav : MonoBehaviour
{
public class CustomButton
{
public Sprite image;
public UnityAction action;
public CustomButton(Sprite image, UnityAction action)
{
this.image = image;
this.action = action;
}
}
2021-12-27 09:39:07 +08:00
private GameObject exit;
private GameObject home;
private GameObject back;
float delayTime = 0;
private List<string> typeArray = new List<string>()
{
2021-12-29 14:23:37 +08:00
"Back","Exit","Home","Device","Delay","Setting","Support","Avatar","Custom","Custom2"
2021-12-27 09:39:07 +08:00
};
private List<int> indexs = new List<int>();
2021-12-28 11:25:09 +08:00
private int? shrinkIndex = null;
2021-12-29 14:23:37 +08:00
private CustomButton custom = null,custom2 = null;
2021-12-27 09:39:07 +08:00
/// <summary>
2021-12-28 11:25:09 +08:00
///
2021-12-27 09:39:07 +08:00
/// </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>
2021-12-29 14:23:37 +08:00
/// <param name="custom">自定义按钮 8:c1 9:c2</param>
public void SetButtonActive(List<int> indexs,int? shrinkIndex = null, CustomButton custom = null, CustomButton custom2 = null)
2021-12-27 09:39:07 +08:00
{
this.indexs = indexs;
2021-12-28 11:25:09 +08:00
this.shrinkIndex = shrinkIndex;
this.custom = custom;
2021-12-29 14:23:37 +08:00
this.custom2 = custom2;
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;
2021-12-29 14:23:37 +08:00
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);
}
2021-12-27 09:39:07 +08:00
SetExpand(false);
}
2021-12-29 14:23:37 +08:00
2021-12-27 09:39:07 +08:00
/// <summary>
/// true:展开 false:关闭
/// </summary>
/// <param name="flag"></param>
2021-12-29 14:23:37 +08:00
public void SetExpand(bool flag)
2021-12-27 09:39:07 +08:00
{
List<string> types = new List<string>();
if (indexs != null)
{
types = typeArray.Where((x, i) => indexs.Contains(i)).ToList();
}
2021-12-28 11:25:09 +08:00
string shrinkName = null;
if (shrinkIndex.HasValue && (shrinkIndex == 0 || shrinkIndex == 2))
{
shrinkName = typeArray[shrinkIndex.Value];
}
2021-12-27 09:39:07 +08:00
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
{
2021-12-28 11:25:09 +08:00
item.gameObject.SetActive(item.name == "PF"|| item.name == shrinkName);
2021-12-27 09:39:07 +08:00
}
2022-01-05 17:40:12 +08:00
//自定义按钮出来
if (item.name == "Custom")
{
item.gameObject.SetActive(custom != null && types.Contains(item.name));
}
else if (item.name == "Custom2")
{
item.gameObject.SetActive(custom2 != null && types.Contains(item.name));
}
2021-12-27 09:39:07 +08:00
}
}
2021-12-29 14:23:37 +08:00
public void ShowButton(string v)
{
var i = typeArray.FindIndex((x)=>x == v);
if (i == -1 || i == 0 || i == 2)
{
return;
}
indexs.Add(i);
SetExpand(false);
}
public void HideButton(string v)
{
var i = typeArray.FindIndex((x) => x == v);
if (i == -1 || i == 0 || i == 2)
{
return;
}
Debug.Log(i);
indexs.RemoveAll(x => x == i);
SetExpand(false);
}
2021-12-27 09:39:07 +08:00
private void Awake()
{
2021-12-28 11:25:09 +08:00
Utils.DisplayHead(transform.Find("Avatar").GetComponent<Image>(), App.CurrentUser.WxHeadImg);
UIManager.AddEvent(transform.Find("Avatar").gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowUserInfoPanel();
});
2021-12-27 09:39:07 +08:00
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");
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 =>
{
2021-12-30 16:51:04 +08:00
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);
};
}
2021-12-27 09:39:07 +08:00
});
#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();
});
}
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);
}
}
// Start is called before the first frame update
void Start()
{
}
2021-12-29 17:05:58 +08:00
bool isTouch = false;
float hideTime = 5;
2021-12-27 09:39:07 +08:00
// Update is called once per frame
void Update()
{
2021-12-29 17:05:58 +08:00
if (Input.touchCount > 0)
{
Debug.Log(235);
isTouch = true;
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;
}
2021-12-30 16:51:04 +08:00
//Debug.Log(Input.touchCount);
2021-12-27 09:39:07 +08:00
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;
}
}
}