Tweety-666
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # FairyGUI+遊戲腳本設計 - GameManager腳本(下) GameManager腳本長又複雜,所以分篇寫。 接續上篇: ```C# using System.Collections; using System.Collections.Generic; using UnityEngine; using FairyGUI; //用FGUI的API才需要 using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { //有掛載在某遊戲物件上才需要: MonoBehaviour //UI相關 [HideInInspector] //在inspector編輯區內隱藏 public bool isInGame;//如果是在遊戲內,則是UIManager來管理版面;如果是還沒進入遊戲,則是GameManager來管理。 private UIManager currentManager; //一般開發會想到建立兩個class,需要就去引用。這邊讓UIM在GM內,GM一定可以調用到它。 //單例建立 private static GameManager _instance; public static GameManager Instance //在VS內,把上面那句選起來,ctrl+r+e快捷建立下方的get、set,不用自己寫。 { get { return _instance; } set { _instance = value; } } //聲音相關 [HideInInspector] public AudioSourceManager audioSourceManager; //聲音管理 //下方這兩項,建立在這卻不建立在ASM裡,因為GM實例化在場景上,會有inspector,可以拖動音檔跟AS進去,請見下圖 public AudioSource audioSource; public AudioClip[] audioClip; //多個音樂片段從unity拖曳進audioClip陣列 //信息處理 [HideInInspector] public MessageManager messageManager; private void Awake() //用Awake,會比Start先執行。 { DontDestroyOnLoad(this.gameObject); //加載場景不銷毀 Instance = this; //前方有寫Instance是GM單例,讓Instance等於「這個」 //加載資源包,因為GM負責遊戲運作,所以資源包給GM //這邊的Package都是FGUI先做好的。加載場景GUI之前,先放入遊戲頁面、主頁面、組件資源。 UIPackage.AddPackage("UI/Res_XXX"); //字體 //字體資源加載路徑為預設在Assets下的Resources的Font資料夾。 UIConfig.defaultFont = "某某字體"; //UIConfig.buttonSound = buttonSound; //全域設定按鈕聲音 //設定自適應,利用FGUI的方法 GRoot.inst.SetContentScaleFactor(寬, 高, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight); //最後一個參數是讓自動它去選載具的高度還是寬度的配適度比較好 //實例化,讓這些實例化在GM內,GM就一定能引用他們。 //因為manager也不是真的遊戲物件或prefabs,所以也不是用instantiate生成 //new是新產生一個東西,這邊的範例是函式,new一定是全新的 //下方這些Manager,被內含在GM內,這樣GM可以操控他們 if (currentManager == null) { currentManager = new UIManager(); } if (audioSourceManager == null) { audioSourceManager = new AudioSourceManager(this); //這邊參數有this,為何呢?可以去看ASM腳本得知。 } if (messageManager == null) { messageManager = new MessageManager(); } } //下篇重點內容為以下: //語言切換 //set頁面在這加載不同語言的資源 public void ChangeLanguage(FairyGUI.Utils.XML xML) { UIPackage.SetStringsSource(xML); //字符串資源,也就是語言xml文件 UIPackage.RemoveAllPackages(); //因為加載了舊包,再去FGUI改語言,加載過的包的內容不變。所以要清除原本包,加載新的進來 UIPackage.AddPackage("UI/Res_Main"); UIPackage.AddPackage("UI/Res_Game"); UIPackage.AddPackage("UI/Res_Component"); //這邊各司其職,UIM加載頁面、ASM處理聲音 currentUIManager.MainUIManager(); //包銷毀了,UIM重新加載介面到UIPanelDict字典內,並顯示MainPanel。 audioSourceManager.ChangeBGM(0); //介面加載完,聲音也要請ASM處理,從第0個音頻開始。可以回到ASM去看函式。 SceneManager.LoadSceneAsync(0); //記得加上UnityEngine.SceneManagement的命名空間,重新加載包後,要重新加載遊戲介面。 //有兩種方法loadScene直接加載,LoadSceneAsync是異步加載,0是代表第0個場景。 //小問題:為何已經UIM加載了,還得用SceneManager去加載畫面呢? //UIM是基於FGUI,在同個場景(Scene)內加載畫面,還有加載字典 //SceneManager基於unity,加載不同Scene //所以兩個都要加載唷 } //這邊的函式先定義好,給MainPanel用,從MP內進去遊戲 //這個函式內容為0.4秒後進去遊戲 public void ToGame() { //使用SceneManager.LoadSence的話,電腦效能太慢,加載會卡住 //可使用沿時調用方法,0.4秒後執行ToTheGame函式 Invoke("ToTheGame", 0.4f); } //在主頁面是由UIManager的MainUIManager管理 //進入遊戲後叫GameUIManager來管理 //叫ASM來處理聲音 public void ToTheGame() { currentUIManager.GameUIManager(); audioSourceManager.ChangeBGM(2); SceneManager.LoadSceneAsync(2); } //這函式跟上方很像 //0.4秒後執行進入主頁面函式 public void ToMain() { Invoke("ToTheMain", 0.4f); } //邏輯一樣,從遊戲頁面切換到主頁面時,GameUIManager叫MainUIManager來管理 //叫ASM處理聲音 public void ToTheMain() { currentUIManager.MainUIManager(); audioSourceManager.ChangeBGM(0); SceneManager.LoadSceneAsync(1); //異步加載第1個場景,可以到build setting去放場景順序,目前場景0是Main,1是Game } ``` --- 同場加映,什麼是**異步加載**? 通常都是使用SceneManager.LoadScene(),來加載場景。 SceneManager.LoadSceneAsync(),是指應用程序在當前場景運行時,將場景加載到後台。 官方說法為: ```C# using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; public class Example : MonoBehaviour { void Update() { // Press the space key to start coroutine if (Input.GetKeyDown(KeyCode.Space)) { // Use a coroutine to load the Scene in the background StartCoroutine(LoadYourAsyncScene()); } } IEnumerator LoadYourAsyncScene() { // The Application loads the Scene in the background as the current Scene runs. // This is particularly good for creating loading screens. // You could also load the Scene by using sceneBuildIndex. In this case Scene2 has // a sceneBuildIndex of 1 as shown in Build Settings. AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2"); // Wait until the asynchronous scene fully loads while (!asyncLoad.isDone) { yield return null; } } } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully