(一)基礎設置ide
拖入資源庫中的「銀河」材質球,設置放大參數,使相機包裹其中;this
設置Canvas分辨率爲1920*1080,RenderMode選爲世界空間;調整位置,視圖以下所示。編碼
(二)場景選擇設置須要設置一個面片,position(0,0,-2000),設置一個空物體(0,0,0),將面片做爲空物體的子物體。將GameItem做爲預製體,使用代碼自動生成。spa
在遊戲運行時,在GameItemSpan下生成GameItem,定義一個Material[],每次選擇旋轉的角度private float m_Angle;code
using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class GameItemSelect : MonoBehaviour { public static GameItemSelect _Instance;
public Material[] m_gameItemMatArr; public GameObject go_GameItem; private float m_Angle; public int Index = 0; private void Awake() { _Instance = this; m_Angle = 360.0f / m_gameItemMatArr.Length; for (int i = 0; i < m_gameItemMatArr.Length; i++) { GameObject go = Instantiate(go_GameItem, transform); go.transform.localEulerAngles = new Vector3(0, i * m_Angle, 0); go.GetComponentInChildren<MeshRenderer>().material = m_gameItemMatArr[i]; go.GetComponentInChildren<GameItem>().SetVideoName(m_gameItemMatArr[i].name); go.GetComponentInChildren<GameItem>().Index = i; } } public void RotateForWord() { Index++; if (Index >= m_gameItemMatArr.Length) { Index = 0; } transform.DORotate(new Vector3(0, -Index * m_Angle, 0), 0.3f); } public void RotateBack() { Index--; if (Index < 0) { Index = m_gameItemMatArr.Length - 1; } transform.DORotate(new Vector3(0, -Index * m_Angle, 0), 0.3f); } }
(三)使用DOTwing實現遊樂項目切換orm
transform.DORotate(new Vector3(0, -Index * m_Angle, 0), 0.3f);
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameItemPanel : MonoBehaviour { private Button btn_Forword; private Button btn_Back; private Button btn_Select; private Text txt_Title; private string[] m_GameItemNameArr; private void Awake() { ReadGameItemNameText(); Init(); } private void Update() { txt_Title.text = m_GameItemNameArr[GameItemSelect._Instance.Index]; } private void ReadGameItemNameText() { TextAsset textAsset= Resources.Load < TextAsset >( "遊樂項目名字"); m_GameItemNameArr = textAsset.text.Split('\n'); } private void Init() { txt_Title = transform.Find("txt_Title").GetComponent<Text>(); btn_Forword = transform.Find("btn_forward").GetComponent<Button>(); btn_Forword.onClick.AddListener(() => { GameItemSelect._Instance.RotateForWord(); }); btn_Back = transform.Find("btn_back").GetComponent<Button>(); btn_Back.onClick.AddListener(() => { GameItemSelect._Instance.RotateBack(); }); btn_Select = transform.Find("btn_select").GetComponent<Button>(); btn_Select.onClick.AddListener(() => { LoadingPanel._instance.LoadScene(); }); } }
(4)項目名稱的展現blog
新建」遊樂項目」文檔,順序與材質球的順序一致。文檔的編碼爲「UTF_8」,文件放在Resous文件夾中
private void ReadGameItemNameText()
{
TextAsset textAsset= Resources.Load < TextAsset >( "遊樂項目名字"); m_GameItemNameArr = textAsset.text.Split('\n'); }
TextAsset爲文本資源,Split()方法爲切割;