| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- local Toast = {}
- local DESTORY_TIME = 2.5
- local funDestory
- local function StopAllCoroutine()
- if funDestory then require("Base/CoroutineHelper.lua"):Stop(funDestory) end
- end
- local function DestoryToast()
- funDestory = require("Base/CoroutineHelper.lua"):Start(function ()
- require("Base/CoroutineHelper.lua"):Wait(DESTORY_TIME)
- CS.UnityEngine.GameObject.Destroy(Toast.rootPanel)
- Toast.rootPanel = nil
- end)
- end
- local function OpenToast()
- local canvas = CS.UnityEngine.GameObject.Find('Canvas')
- Toast._rootCanvas = canvas
- local prefabTaost = LoadResource('CommonUtils/Prefabs/ZUIToastPanel.prefab')
- local rootPanel = CS.UnityEngine.GameObject.Instantiate(prefabTaost, canvas.transform)
- Toast.rootPanel = rootPanel
- end
- local function RefreshToastImg(szToastPath)
- if nil == szToastPath then
- szToastPath = "CommonUtils/Textures/Toast/prompt.png"
- end
- local rootPanel = Toast.rootPanel
- local img = rootPanel.transform:Find("Image").gameObject
- require("Base/UIHelper.lua"):LoadSprite(img, szToastPath, szToastPath)
- end
- function Toast.ToastInfo(szToastPath)
- if Toast.rootPanel then
- RefreshToastImg(szToastPath)
- StopAllCoroutine()
- DestoryToast()
- return
- end
- OpenToast()
- RefreshToastImg(szToastPath)
- DestoryToast()
- end
- return Toast
|