# 開始做專案前的舊程式研究文件 ###### tags: `程式` [TOC] :::info 以下排序為程式碼改動的優先順序 by 茹瑄 ::: # 程式研究相關紀錄 * [Google Cloud API 研究](/S13ygrN8RamjKEaRzn2Pvg) * [SteamVR](/XNudw9WlRmWqfDQEnQoqFw) * Yarn spinner(待補) # 開作前的測試 * [Stylized Amusement Park / Roller Coaster](https://assetstore.unity.com/packages/3d/environments/stylized-amusement-park-roller-coaster-197863) * 想要跟老師說的美術組合 * [POLYGON Farm - Low Poly 3D Art by Synty](https://assetstore.unity.com/packages/3d/environments/industrial/polygon-farm-low-poly-3d-art-by-synty-146192) * [Quirky Series - Animals Mega Pack Vol.1](https://assetstore.unity.com/packages/3d/characters/animals/quirky-series-animals-mega-pack-vol-1-137259) * UniStorm * 用起來比較無腦、而且功能不會過多 * 那就用這個吧XDD * Google Cloud * Mini First Person Controller * Yarn spinner * 排隊 * 將上面的功能做個Prototype試試看 * 有需要去思考語音範圍的問題嗎...好像不需要 可以先把這些東西砸起來看看會有甚麼問題,看看效能上有沒有甚麼很大的問題 # Bug處理 - [x] 原專案本身的Bug - [x] 先嘗試分類Hard那個場景的物件吧= = - [x] 如果都要重做的話那其實也不用搞了 - [ ] 重作專案的Bug # 功能增加 ## 一定要有的 - [ ] 語音功能 - [ ] 文字轉語音...OMG - [ ] [Cloud Text-to-Speech API](https://cloud.google.com/text-to-speech/docs/reference/rest) - [ ] [Text To Speech using Google Cloud - Pro](https://assetstore.unity.com/packages/add-ons/machinelearning/text-to-speech-using-google-cloud-pro-115170) - [ ] 劇本系統(防止後來老師想改劇本或流程很麻煩) - [ ] 重複問答 - [ ] 語音撥放 - [ ] 接受答案後改變文本 ## 有會更好的 - [ ] 基本UI介面常駐 - [ ] 糖果數量顯示 - [ ] 設定介面 - [ ] 離開遊戲 - [ ] 音量控制 - [ ] Debugger模式 - [ ] 不需要VR的操作模擬 - [ ] 跳關 - [ ] 更友善的教學 - [ ] 路線提示加強 - [ ] API版本偵測的功能 # 重構 - [ ] 刪除不必要的程式碼 - [ ] 把整體程式弄得比較有系統 - [ ] 名稱重新取名 - [ ] 資料夾 - [ ] 程式碼 - [ ] Scene - [ ] 刪除重複的場景 - [ ] 先確定整體流程實際上使用的場景在做更動 - [ ] 有一堆不明用途的Camera在場上 # 優化 - [x] 場景卡頓 - [x] 其實實際玩下來還好 - [x] 有沒有多餘的資源是可以刪除的? - [x] 已經先用Asset hunter Pro清除500mb的大小 - [ ] 遊戲流程優化 - [ ] if增加那些增加遊樂園真實度的資源,就要想辦法優化整體場景,不然會Lag到瘋掉,但還是先跑跑看會不會真的這樣吧 - [ ] 消除重複的3D模型與UI(ex:那些動物的模型與UI介面) - [ ] 資料傳Google Cloud的Lag時間修復(Task) ![](https://i.imgur.com/KpY578H.png) skyPlay動畫的程式碼 # 其它 - [ ] 遊戲美化?(真的需要給自己找麻煩嗎?但目前的樣子看起來真的不太爽) - [x] 要確認遊樂園的物理設施的運作方式(痾應該是有物理效果的沒錯吧?好吧沒有Orz) - [x] 素材本身能不能動?能,也可以隔專案搬遷 - [ ] 要怎麼管理場景有大量物件的專案分類? - [ ] [Steam VR測試關閉](https://blog.csdn.net/qq_39731130/article/details/125228164?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-125228164-blog-120003650.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-125228164-blog-120003650.pc_relevant_default&utm_relevant_index=8) - [x] 其實也不用真的去做一個資料輸入介面,直接編輯ScriptableObject的ChildInfoData資料就行了... - [ ] 不過可能到時要做一個初始化資料的相關程式就是 - [ ] 要使用UniRx處理連線Google cloud跟語音倒數的技術處理嗎? # 程式碼現況 * 觸發遊玩的場景是跟行動畫面是分開的 * 完全不物件導向 * 一堆沒用到的程式碼沒刪除乾淨 * Candy這個UI介面完全不是共用的,是用一種神奇的方式放在這個地方 * 一大堆的重複物件 * [x] 怎麼辦我真的想打掉重來了= =,先從hard分類目前的狀況吧 ## 程式詳細 遊戲剛進來的程式 game start_elf 儲存玩家資料的地方 playerstat scoreboard 顯示candy資料的地方 candy 顯示money資料 controlMoney 各種只是控制物件顯示消失的程式碼 Balloon MrSong money1 Door 太多的不想一一找出來Orz ## 觸發遊樂園機制的程式碼 * 問題點 * 重複程式碼的部分,可能重構時要重新再做調整 * 碰碰車 * 雲霄飛車 * 旋轉木馬 * 天女散花 * 摩天輪 CameraChange.cs ![](https://i.imgur.com/8qwVN2U.png) ``` using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraChange : MonoBehaviour { [SerializeField] private Transform player1; [SerializeField] private Transform carTransform; [SerializeField] private Transform centerTransform; [SerializeField] private Transform horseTransform; [SerializeField] private Transform skyTransform; [SerializeField] private Transform rollerWaitTransform; [SerializeField] private Transform rollerTransform; [SerializeField] private Transform wheelWaitTransform; [SerializeField] private Transform wheelTransform; [SerializeField] private Transform addTransform; [SerializeField] private Transform hungryTransform; [SerializeField] private Transform seatTransform; [SerializeField] private Transform foodTransform; [SerializeField] private Transform findBobiTransform; [SerializeField] private Transform byeTransform; private GameObject hungryCanva; public void Car() { Debug.Log("0000"); player1.SetParent(carTransform); player1.localPosition = Vector3.zero; player1.rotation = carTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; StartCoroutine(changeScene6()); } IEnumerator changeScene6()//碰碰車 { yield return new WaitForSeconds(12);//10 //player2.SetActive(false); //player1.SetActive(true); player1.SetParent(null); player1.position = centerTransform.position; player1.rotation = centerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; //Debug.Log("hi"); } public void Horse() { player1.SetParent(horseTransform); player1.localPosition = Vector3.zero; player1.rotation = horseTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; StartCoroutine(changeScene1()); } IEnumerator changeScene1()//旋轉木馬 { yield return new WaitForSeconds(16);//16 //player2.SetActive(false); //player1.SetActive(true); player1.SetParent(null); player1.position = centerTransform.position; player1.rotation = centerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; //Debug.Log("hi"); } public void Sky() { player1.SetParent(skyTransform); player1.localPosition = Vector3.zero; player1.rotation = skyTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; StartCoroutine(changeScene2()); } IEnumerator changeScene2()//天女 { yield return new WaitForSeconds(10); //player2.SetActive(false); //player1.SetActive(true); player1.SetParent(null); player1.position = centerTransform.position; player1.rotation = centerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; //Debug.Log("hi"); } public void rollerWait() { player1.SetParent(rollerWaitTransform); player1.localPosition = Vector3.zero; player1.rotation = rollerWaitTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; //StartCoroutine(changeScene2()); } ``` * 雲霄飛車的觸發方式...其實基本上每段觸發遊玩遊樂園的程式碼都長得差不多... ``` public void roller() { player1.SetParent(rollerTransform); player1.localPosition = Vector3.zero; player1.rotation = rollerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; StartCoroutine(changeScene3()); } IEnumerator changeScene3()//雲霄 { yield return new WaitForSeconds(32); //player2.SetActive(false); //player1.SetActive(true); player1.SetParent(null); player1.position = centerTransform.position; player1.rotation = centerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } ``` ``` public void WheelWait() { player1.SetParent(wheelWaitTransform); player1.localPosition = Vector3.zero; player1.rotation = wheelWaitTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void wheel() { player1.SetParent(wheelTransform); player1.localPosition = Vector3.zero; player1.rotation = wheelTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; StartCoroutine(changeScene4()); } IEnumerator changeScene4()//摩天輪 { yield return new WaitForSeconds(32); player1.SetParent(null); player1.position = centerTransform.position; player1.rotation = centerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void countinue() { player1.SetParent(centerTransform); player1.localPosition = Vector3.zero; player1.rotation = centerTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void nnnoCountinue() { player1.SetParent(hungryTransform); player1.localPosition = Vector3.zero; player1.rotation = hungryTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void Seat() { player1.SetParent(seatTransform); player1.localPosition = Vector3.zero; player1.rotation = seatTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void Food() { player1.SetParent(foodTransform); player1.localPosition = Vector3.zero; player1.rotation = foodTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void FindBobi() { player1.SetParent(findBobiTransform); player1.localPosition = Vector3.zero; player1.rotation = findBobiTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } public void ByeByeGame() { player1.SetParent(byeTransform); player1.localPosition = Vector3.zero; player1.rotation = byeTransform.rotation; player1.GetChild(0).localPosition = Vector3.zero; player1.GetChild(0).localRotation = Quaternion.identity; } } ``` SteamVR Unity Plugin 好像沒有用到的GameObject/Scripts noMondyCanvas MOVE.cs 被隱藏的Main Camera 所有的Scene Build的Scene...有包含到所有遊戲內容跑的Scene嗎Orz 要實際跑一次看看到底有哪些Scene才行呢Orz 目前只有兩個Scene有真正被使用到...startGame_hard跟Hard Orz ## 角色名稱 GO_ ElfCam 那些Transition點是用來限制玩家移動範圍的 ## 動畫Camera的製作方式 ![](https://i.imgur.com/mICIes5.png) 不直接把角色的物件扔到transition上,而是另外創一個專門用來處理此事件的Camera,不過Camera的設定要跟Player本身的一模一樣 好吧他們大部分的程式碼都只是純粹的讓他顯示消失,不存在半點更新的架構Orz ## 原本的場景樣子 ![](https://i.imgur.com/EpK0iAL.png) ![](https://i.imgur.com/aomJc0f.png) ![](https://i.imgur.com/2ZBAB9W.png) ## 資料夾樣子 ![](https://i.imgur.com/JNV0SAc.png) ![](https://i.imgur.com/UMU6bPz.png) ## 遊樂園遊玩的製作方式(其實直接把整個Animation搬遷過去也行啦) 1. 雲霄飛車 * Group131 * coasterPlay * 塞了一個Player * 動畫可以留,Player的設定要再調整 ![](https://i.imgur.com/9yyIeqd.png) 2. 旋轉木馬 * carousel_horse 1 3. 碰碰車 * Group_021 * Group_015 * Group_009 * 沒想到這個設施也是用動畫帶過去阿... * player/Go_player2 * 應該是用來設定transform的 * Main Camera * 雖然這個應該是有用到,但它下面掛的程式...? * `game` * `Playside` * `MOVE` ![](https://i.imgur.com/nj4wdkC.png) 4. 摩天輪 * Group_330 * Group311 * wheeltransition 5. 天女散花 * Group601 3 ## TODO ![](https://i.imgur.com/JrfunBX.png) 下次從這裡繼續看 * Yarn Spinner也有Google.Protobuf,如果出問題到時要注意這點...收尾的時候還是嘗試把相關API的版本升一升好了... * 因為語音檔都換成用Google cloud的Text to speech替代了,所以這些檔案可以刪除 * 摩天輪的動畫合併 ## 程式架構稍微紀錄(之後會寫的更程式資料點) * `AduioManager` * GameCore/GameManager? * `AmusementParkSystem` * 基本上是用來替代`CameraChange`的功能 * `Voice System` * 暫時把Google cloud的連結與語音讀取實作都放在這裡,之後要拆 * SettingGUI * GameStartGUI * CandyGUI? * VRAdapter * 可能要有個用來限制小孩移動與移動到指定位置的開關 * WeatherSystemAdapter? * CostCalculator * 排隊...系統?? * `ChildInfoData` * 用來儲存小孩與其他資訊資料 * Yarn Spinner衍生程式 * 主要實作的部分 * * VROptionView * 主要接語音辨識的地方