123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Imagine.WebAR;
- using Nfynt;
- using TMPro;
- using TriLibCore;
- using UnityEngine;
- using UnityEngine.UI;
- using DG.Tweening;
- using static TaskConfig;
- using static TaskConfig.windowItemGameObject;
- using System.Runtime.InteropServices;
- public class TaskManager : MonoBehaviour
- {
- [DllImport("__Internal")] private static extern void WebGLShowWx(string settings);
- public GameObject backgo;
- public GameObject HtmlBG;
- public UserInfo myInfo;
- //public ARCamera ar;
- public List<TestConfigExcelData> tconfigs;
- public TestConfigExcelData ntconfig;
- public RawImage bg;
- public RawImage imgbg;
- public RawImage centerbg;
- public RawImage centerbg2;
- public RawImage topbg;
- public GameObject prebg;
- public GameObject Closebt;
- public GameObject Closebt2;
- //public TextMeshProUGUI dialogueText;
- public Text dialogueText;
- public GameObject Main;
- public GameObject Sence;
- public GameObject daoju;
- public GameObject video;
- public GameObject allimg;
- public GameObject allimg2;
- public GameObject ar_1img;
- public GameObject ar_2img;
- public GameObject ar_1glb;
- public GameObject ar_2glb;
-
- public RawImage bigbg;
- public GameObject GamePIntu;
- public List<GameObject> daojulist;
- public ImageTracker itracker;
- public WorldTracker wtracker;
- public GameObject tuodongbg;
- public GameObject shibie;
- public GameObject Inputgo;
- public GameObject duihuakuang;
- TestConfigExcelItem nowTaskItem;
- public GameObject xiansuo;
- public int nowTaskIndex;
- public int nowTaskCt;
- public GameObject main_click;
- public GameObject inputbt;
- private void Awake()
- {
- // PlayerPrefs.DeleteAll();
- StartCoroutine(InitGame());
- }
- public void saveindex(bool isFinish)
- {
- if (PlayerPrefs.GetInt("isend")!=1)
- {
- PlayerPrefs.SetInt("nowTaskCt", nowTaskCt);
- PlayerPrefs.SetInt("nowTaskIndex", nowTaskIndex);
- if (isFinish)
- {
- PlayerPrefs.SetInt("isend", 1);
- }
- }
- }
- private IEnumerator InitGame()
- {
- Main.SetActive(false);
- Sence.SetActive(false);
- // yield return new WaitForSeconds(1f);
- // ar.PauseCamera();
- // yield return new WaitForSeconds(2f);
-
- yield return StartCoroutine(InitUser());
- if (PlayerPrefs.GetInt("isend") != 1)
- {
- backgo.SetActive(false);
- myInfo.taskIndex = PlayerPrefs.GetInt("nowTaskIndex");
- myInfo.taskCt = PlayerPrefs.GetInt("nowTaskCt");
- nowTaskIndex = myInfo.taskIndex;
- nowTaskCt = myInfo.taskCt;
- ntconfig = tconfigs[nowTaskCt];
- nowTaskItem = ntconfig.items[nowTaskIndex];
- yield return StartCoroutine(checktaskSence(nowTaskItem));
- }
- else
- {
- backgo.SetActive(false);
- Main.SetActive(true);
- Sence.SetActive(false);
- }
- }
- bool isclickxumu;
- public void gotoxumu()
- {
- SetWebGLText.Instance.clearTexture();
- if (PlayerPrefs.GetInt("isend") == 1)
- {
- backgo.SetActive(true);
- isEnd = false;
- isclickxumu = true;
- nowTaskCt = 0;
- nowTaskIndex = -1;
- ntconfig = tconfigs[nowTaskCt];
- nowTaskItem = ntconfig.items[0];
- nextTask();
- Main.SetActive(false);
- Sence.SetActive(true);
- }
- }
- public void gotodadian()
- {
- isEnd = false;
- isclickxumu = false;
- nowTaskCt = 1;
- nowTaskIndex = 8;
- ntconfig = tconfigs[nowTaskCt];
- nowTaskItem = ntconfig.items[nowTaskIndex];
- nextTask();
- Main.SetActive(false);
- Sence.SetActive(true);
- backgo.SetActive(PlayerPrefs.GetInt("isend") == 1);
- }
- GameObject hc;
- public RawImage lihui;
- public List<GameObject> items;
- public GameObject rawjingzi;
- private IEnumerator checktaskSence(TestConfigExcelItem ti)
- {
- backgo.SetActive(PlayerPrefs.GetInt("isend") == 1);
- if(hc)
- {
- Destroy(hc);
- hc = null;
- }
- dialogueText.DOKill();
- dialogueText.text="";
- dialogueText.DOText(ti.info,2f);
- // dialogueText.text = ti.info;
- if(iidex==1&& ti.info2!="")
- dialogueText.DOText(ti.info2,2f);
- //dialogueText.text = ti.info2;
-
- getTexture(ti.bgName, (tex) => {
- if (tex)
- {
- bg.texture = tex;
- bg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 1);
- }
- else
- {
- bg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 0);
- }
- });
- getTexture(ti.lihui, (tex) => {
- if (tex)
- {
- lihui.GetComponent<RectTransform>().sizeDelta = new Vector2(tex.width, tex.height);
- lihui.texture = tex;
- lihui.color = new Color(bg.color.r, bg.color.g, bg.color.b, 1);
- lihui.transform.localScale = new Vector3(ti.lihuisize, ti.lihuisize, ti.lihuisize);
- }
- else
- {
- lihui.color = new Color(bg.color.r, bg.color.g, bg.color.b, 0);
- }
- });
- getTexture(ti.imgName, (tex) => {
- if (tex)
- {
- imgbg.texture = tex;
- imgbg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 1);
- }
- else
- {
- imgbg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 0);
- }
- duihuakuang.SetActive(ti.centerName != "one_end");
- });
- getTexture(ti.centerName, (tex) => {
- if (tex)
- {
- centerbg.GetComponent<RectTransform>().sizeDelta = new Vector2(tex.width, tex.height);
- centerbg.texture = tex;
- centerbg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 1);
- centerbg.gameObject.SetActive(true);
- centerbg.transform.localScale = new Vector3(ti.centersize, ti.centersize, ti.centersize);
- }
- else
- {
- centerbg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 0);
- }
- });
-
- GetBD(ti.perbName, (go) => {
- if(go)
- {
- go.SetActive(true);
- go.transform.parent = prebg.transform;
- go.transform.localPosition = Vector3.zero;
- go.transform.localEulerAngles = Vector3.zero;
- go.transform.localScale = Vector3.one;
- hc = go;
- }
- });
- if(ti.type != TaskType.ARTask)
- {
- bigbg.color = new Color(bigbg.color.r, bigbg.color.g, bigbg.color.b, 1);
- imgbg.color = new Color(imgbg.color.r, imgbg.color.g, imgbg.color.b, 1);
- }
- for (int i = 0; i < items.Count; i++)
- {
- if(ti.daojus.Length>i)
- {
- items[i].SetActive(ti.daojus[i]);
- }else
- {
- items[i].SetActive(false);
- }
- }
- dialogueText.GetComponent<Button>().enabled = ti.isTextNext;
- ar_1glb.SetActive(false);
- ar_2glb.SetActive(false);
- inputbt.SetActive(false);
- HtmlBG.SetActive(ti.type!=TaskType.ARTask);
- shibie.SetActive(false);
- switch (ti.type)
- {
- case TaskType.Dialogue:
-
- ar_2img.SetActive(false);
- ar_1img.SetActive(false);
- Main.SetActive(false);
- Sence.SetActive(true);
- allimg.SetActive(ti.isClose);
- Closebt.SetActive(ti.isClosebtShow);
- allimg.GetComponent<Button>().enabled = !ti.isClosebtShow;
- tuodongbg.SetActive(ti.isTuo);
- rawjingzi.SetActive(ti.isTuo);
- break;
- case TaskType.Xiansuo:
- Main.SetActive(false);
- Sence.SetActive(true);
- xiansuo.SetActive(true);
- break;
- case TaskType.ARTask:
- WebGLShowWx(ti.info);
- nextTask();
- // Main.SetActive(false);
- break;
- case TaskType.SkipSence:
- switch (ti.guochang)
- {
- case "daoju":
- daoju.SetActive(true);
- Invoke("nextTask", 1f);
- break;
- case "main":
- Main.SetActive(true);
- Sence.SetActive(false);
- main_click.SetActive(true);
- break;
- default:
- if(ti.guochang!="")
- {
- GameObject v = video;
- if (ti.isguochangskip)
- v = end2;
- v.SetActive(true);
- v.GetComponent<NVideoPlayer>().enabled = true;
- yield return null;
- v.GetComponent<NVideoPlayer>().Config.PlayOnAwake = false;
- v.GetComponent<NVideoPlayer>().Config.VideoSrcPath = Application.streamingAssetsPath + "/" + ti.guochang + ".mp4";
- v.GetComponent<NVideoPlayer>().Config.LoopPlayer = ti.isguochangskip;
- if (ti.isguochangskip)
- v.GetComponent<NVideoPlayer>().Unmute();
- else
- v.GetComponent<NVideoPlayer>().Mute();
- yield return null;
- if(!v.GetComponent<NVideoPlayer>().enabled)
- {
- v.GetComponent<NVideoPlayer>().enabled = true;
- yield return null;
- if (!v.GetComponent<NVideoPlayer>().IsPlaying)
- v.GetComponent<NVideoPlayer>().Play();
- }
- else{
- if (!v.GetComponent<NVideoPlayer>().IsPlaying)
- v.GetComponent<NVideoPlayer>().Play();
- }
- if (!ti.isguochangskip)
- {
- duihuakuang.SetActive(ti.centerName != "one_end");
- Invoke("videoclose", 3f);
- }
- }
- else
- {
- }
- break;
- }
- break;
- case TaskType.GameTask:
- switch (ti.info)
- {
- case "pintu":
- GamePIntu.SetActive(true);
- break;
- }
- break;
- case TaskType.InputTask:
- inputbt.SetActive(true);
- ar_2img.SetActive(false);
- ar_1img.SetActive(false);
- Main.SetActive(false);
- Sence.SetActive(true);
- allimg.SetActive(ti.isClose);
- Closebt.SetActive(ti.isClosebtShow);
- allimg.GetComponent<Button>().enabled = !ti.isClosebtShow;
- tuodongbg.SetActive(ti.isTuo);
- Inputgo.SetActive(true);
- break;
- case TaskType.ChooseTask:
- ar_2img.SetActive(false);
- ar_1img.SetActive(false);
- Main.SetActive(false);
- Sence.SetActive(true);
- allimg.SetActive(ti.isClose);
- dialogueText.GetComponent<Button>().enabled =false;
- Closebt.SetActive(ti.isClosebtShow);
- allimg.GetComponent<Button>().enabled = !ti.isClosebtShow;
- choosego.SetActive(true);
- tuodongbg.SetActive(ti.isTuo);
- break;
- }
- yield return null;
- if(ti.texiao!=null&& ti.texiao!="")
- {
- nongwu.SetActive(true);
- yield return null;
- string path = nongwu.GetComponent<NVideoPlayer>().Config.VideoSrcPath;
- string[] parr = nongwu.GetComponent<NVideoPlayer>().Config.VideoSrcPath.Split('/');
- string pname = parr[parr.Length - 1];
- if (pname.Split('.')[0] != ti.texiao)
- {
- nongwu.GetComponent<NVideoPlayer>().Config.VideoSrcPath = Application.streamingAssetsPath + "/" + ti.texiao + ".mp4";
- nongwu.GetComponent<NVideoPlayer>().Config.LoopPlayer = true;
- }
- nongwu.GetComponent<NVideoPlayer>().Mute();
- yield return null;
- //
- if (!nongwu.GetComponent<NVideoPlayer>().IsPlaying)
- nongwu.GetComponent<NVideoPlayer>().Play();
- }
- else
- {
- nongwu.SetActive(false);
- }
- //
- }
- int arcount;
- bool isarinit=false;
- public GameObject textgo;
- public void arFound(string name)
- {
- if (arcount == 1 && name == "ar_1")
- {
- wtracker.PlaceOrigin();
- textgo.SetActive(false);
- nextTask();
- }
- if (arcount == 2 && name == "ar_2")
- {
- wtracker.PlaceOrigin();
- textgo.SetActive(false);
- nextTask();
- }
- }
- public GameObject errortext;
- public void checkinput()
- {
- if(Inputgo.GetComponent<InputField>().text == nowTaskItem.taskcheck)
- {
- Inputgo.SetActive(false);
- nextTask();
- }else
- {
- errortext.SetActive(true);
- }
- }
- public void yanchi()
- {
- bigbg.color = new Color(bigbg.color.r, bigbg.color.g, bigbg.color.b, 0);
- imgbg.color = new Color(imgbg.color.r, imgbg.color.g, imgbg.color.b, 0);
- }
- public GameObject showBT;
- public void videoclose()
- {
- showBT.SetActive(true);
- // showBT.GetComponent<>(true);
- //nextTask();
- }
- void jieshu()
- {
- Main.SetActive(true);
- Sence.SetActive(false);
- saveindex(true);
- }
- void isClickfalse()
- {
- isClick=false;
- }
- bool isClick =false;
- bool isEnd;
- public void nextTask()
- {
- if(isClick)
- {
- //return;
- }
- Invoke("isClickfalse",1f);
- isClick=true;
- if(nowTaskItem.type == TaskType.InputTask)
- {
- Inputgo.GetComponent<InputField>().text = "";
- }
- if(!allimg.activeSelf||(allimg.activeSelf&& nowTaskItem.isClose)|| nowTaskItem.type== TaskType.ChooseTask)
- {
- if (nowTaskIndex + 1 >= ntconfig.items.Length)
- {
- if(nowTaskCt+1>=tconfigs.Count)
- {
- if(!isEnd)
- {
- Invoke("jieshu", 2f);
- isEnd = true;
- }
- }
- else
- {
- if(!isclickxumu)
- {
- nowTaskCt++;
- ntconfig = tconfigs[nowTaskCt];
- nowTaskIndex = 0;
- nowTaskItem = ntconfig.items[nowTaskIndex];
- StartCoroutine(checktaskSence(nowTaskItem));
- saveindex(false);
- }
- else
- {
- if (!isEnd)
- {
- Invoke("jieshu", 2f);
- isEnd = true;
- }
- // Main.SetActive(true);
- // Sence.SetActive(false);
- }
- }
- }
- else
- {
- nowTaskIndex++;
- nowTaskItem = ntconfig.items[nowTaskIndex];
- StartCoroutine(checktaskSence(nowTaskItem));
- if(nowTaskItem.type == TaskType.Dialogue)
- saveindex(false);
- }
- }
- }
- public void gotomain()
- {
- backgo.SetActive(false);
- Main.SetActive(true);
- Sence.SetActive(false);
- centerbg.color = new Color(bg.color.r, bg.color.g, bg.color.b, 0);
- }
- public static void getTexture(string m_url, Action<Texture2D> callback)
- {
- if (m_url == "" || m_url == null)
- {
- callback.Invoke(null);
- }
- else
- {
- string filePath = System.IO.Path.Combine(Application.streamingAssetsPath + "/ui", m_url);
- SetWebGLText.Instance.GetTexture(filePath + ".png", (Texture2D t2d) => {
- callback.Invoke(t2d);
- });
- }
- }
- public static void GetBD(string m_url, Action<GameObject> callback)
- {
- if (m_url == "" || m_url == null)
- {
- callback.Invoke(null);
- }
- else
- {
- SetWebGLText.Instance.GetBD(m_url, (GameObject t2d) => {
- callback.Invoke(t2d);
- });
- }
- }
- public void checkisNextTask()
- {
-
- //nextTask();
- }
- public void showdaoju(string urlname)
- {
- allimg2.SetActive(true);
- Closebt2.SetActive(true);
- allimg2.GetComponent<Button>().enabled = false;
- getTexture(urlname, (tex) => {
- if (tex)
- {
- centerbg2.GetComponent<RectTransform>().sizeDelta = new Vector2(tex.width, tex.height);
- centerbg2.texture = tex;
- centerbg2.color = new Color(bg.color.r, bg.color.g, bg.color.b, 1);
- centerbg2.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
- centerbg2.gameObject.SetActive(true);
- }
- else
- {
- centerbg2.color = new Color(bg.color.r, bg.color.g, bg.color.b, 0);
- }
- });
- }
- public static void loadUrl(string ModelURL, Action<AssetLoaderContext> OnLoad, Action<AssetLoaderContext> OnMaterialsLoad, Action<AssetLoaderContext, float> OnProgress, Action<IContextualizedError> OnError, GameObject go = null)
- {
- var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
- var webRequest = AssetDownloader.CreateWebRequest(ModelURL);
- AssetDownloader.LoadModelFromUri(webRequest, OnLoad, OnMaterialsLoad, OnProgress, OnError, go, assetLoaderOptions);
- }
- public static void loadFile(string ModelPath, Action<AssetLoaderContext> OnLoad, Action<AssetLoaderContext> OnMaterialsLoad, Action<AssetLoaderContext, float> OnProgress, Action<IContextualizedError> OnError, GameObject go = null)
- {
- var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
- AssetLoader.LoadModelFromFile(ModelPath, OnLoad, OnMaterialsLoad, OnProgress, OnError, go, assetLoaderOptions);
- }
- private IEnumerator InitUser()
- {
- myInfo = new UserInfo();
- yield return null;
- }
- public int iidex;
- public void chooseitem(int index)
- {
- iidex = index;
- nextTask();
- }
- public GameObject choosego;
- public GameObject end2;
- public GameObject nongwu;
- }
|