123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- #region Namespaces
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- #endregion // Namespaces
- public class GE_FantasySkyboxFREE_Demo : MonoBehaviour
- {
- #region Variables
-
- [System.Serializable]
- public class LightAndSky
- {
- // Name
- public string m_Name;
-
- // Light
- public Light m_Light;
-
- // Skybox
- public Material m_Skybox;
-
- // Fog
- public Color m_FogColor;
-
- // Ambient
- public Color m_AmbientLight;
- }
-
- // List of LightAndSky class
- public LightAndSky[] m_LightAndSkyList;
- // Index to current Skybox
- int m_CurrentSkyBox = 2;
-
- #endregion // Variables
-
- #region MonoBehaviour
-
- void Start ()
- {
- // Display first skybox in m_LightAndSkyList
- SetSkyBox(m_CurrentSkyBox);
- // Update UI Text elements
- //UpdateDetailsText();
- //UpdateHowToText();
- }
-
-
- void Update ()
- {
- // User press Left key
- //if(Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.A))
- //{
- // // Show previous skybox
- // OnPreviousSkybox();
- //}
- //// User press Right key
- //if(Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.D))
- //{
- // // Show next skybox
- // OnNextSkybox();
- //}
- }
-
-
- void OnTriggerExit(Collider other)
- {
- Debug.Log("OnTriggerExit="+other.name);
-
- // Reset player position when user move it away from terrain
- this.transform.localPosition = new Vector3(0,1,0);
- }
- #endregion // MonoBehaviour
- // ########################################
- // Switch skybox functions
- // ########################################
- #region Switch skybox functions
- // Switch to previous skybox
- public void OnPreviousSkybox()
- {
- SwitchSkyBox(-1);
- //UpdateDetailsText();
- }
-
- // Switch to next skybox
- public void OnNextSkybox()
- {
- SwitchSkyBox(+1);
- //UpdateDetailsText();
- }
- #endregion // MonoBehaviour
- // ########################################
- // Show skybox functions
- // ########################################
- #region Show skybox functions
- // Switch to a skybox by direction
- // DiffNum less than 0 means previous skybox
- // DiffNum larger than 0 means next skybox
- void SwitchSkyBox(int DiffNum)
- {
- // Update add m_CurrentSkyBox with DiffNum
- m_CurrentSkyBox += DiffNum;
-
- // Clamp m_CurrentSkyBox between 0 and m_LightAndSkyList.Length
- if(m_CurrentSkyBox<0)
- {
- m_CurrentSkyBox = m_LightAndSkyList.Length-1;
- }
- if(m_CurrentSkyBox>=m_LightAndSkyList.Length)
- {
- m_CurrentSkyBox = 0;
- }
-
- // Switch skybox in RenderSettings
- RenderSettings.skybox = m_LightAndSkyList[m_CurrentSkyBox].m_Skybox;
-
- // Switch light
- for(int i=0;i<m_LightAndSkyList.Length;i++)
- {
- m_LightAndSkyList[i].m_Light.gameObject.SetActive(false);
- }
- m_LightAndSkyList[m_CurrentSkyBox].m_Light.gameObject.SetActive(true);
-
- // Enable fog
- RenderSettings.fog = true;
-
- // Set the fog color
- if(m_CurrentSkyBox>=0 && m_CurrentSkyBox<m_LightAndSkyList.Length)
- {
- RenderSettings.fogColor = m_LightAndSkyList[m_CurrentSkyBox].m_FogColor;
- }
- else
- {
- RenderSettings.fogColor = Color.white;
- }
-
- // Set the ambient lighting
- if(m_CurrentSkyBox>=0 && m_CurrentSkyBox<m_LightAndSkyList.Length)
- {
- RenderSettings.ambientLight = m_LightAndSkyList[m_CurrentSkyBox].m_AmbientLight;
- }
- else
- {
- RenderSettings.ambientLight = Color.white;
- }
- }
- void SetSkyBox(int DiffNum)
- {
- // Update add m_CurrentSkyBox with DiffNum
- m_CurrentSkyBox = DiffNum;
- // Clamp m_CurrentSkyBox between 0 and m_LightAndSkyList.Length
- if (m_CurrentSkyBox < 0)
- {
- m_CurrentSkyBox = m_LightAndSkyList.Length - 1;
- }
- if (m_CurrentSkyBox >= m_LightAndSkyList.Length)
- {
- m_CurrentSkyBox = 0;
- }
- // Switch skybox in RenderSettings
- RenderSettings.skybox = m_LightAndSkyList[m_CurrentSkyBox].m_Skybox;
- // Switch light
- for (int i = 0; i < m_LightAndSkyList.Length; i++)
- {
- m_LightAndSkyList[i].m_Light.gameObject.SetActive(false);
- }
- m_LightAndSkyList[m_CurrentSkyBox].m_Light.gameObject.SetActive(true);
- // Enable fog
- RenderSettings.fog = true;
- // Set the fog color
- if (m_CurrentSkyBox >= 0 && m_CurrentSkyBox < m_LightAndSkyList.Length)
- {
- RenderSettings.fogColor = m_LightAndSkyList[m_CurrentSkyBox].m_FogColor;
- }
- else
- {
- RenderSettings.fogColor = Color.white;
- }
- // Set the ambient lighting
- if (m_CurrentSkyBox >= 0 && m_CurrentSkyBox < m_LightAndSkyList.Length)
- {
- RenderSettings.ambientLight = m_LightAndSkyList[m_CurrentSkyBox].m_AmbientLight;
- }
- else
- {
- RenderSettings.ambientLight = Color.white;
- }
- }
- #endregion // Show skybox functions
- // ########################################
- // Update UI text functions
- // ########################################
- //#region Update UI text functions
- //// Update details UI Text
- //void UpdateDetailsText()
- //{
- // // Update ItemNum text
- // GameObject Text_ItemNum = GameObject.Find("Text_ItemNum");
- // if(Text_ItemNum!=null)
- // {
- // Text pText = Text_ItemNum.GetComponent<Text>();
- // pText.text = string.Format("{0:00} of {1:00}",m_CurrentSkyBox+1, m_LightAndSkyList.Length);
- // }
- // // Update Details text
- // GameObject Text_Details = GameObject.Find("Text_Details");
- // if(Text_Details!=null)
- // {
- // Text pText = Text_Details.GetComponent<Text>();
- // pText.text = string.Format(m_LightAndSkyList[m_CurrentSkyBox].m_Name);
- // }
- //}
- //// Update how to UI Text
- //void UpdateHowToText()
- //{
- // // Find Text_HowTo in the scene
- // GameObject Text_HowTo = GameObject.Find("Text_HowTo");
- // if(Text_HowTo!=null)
- // {
- // // Update text according to target platform
- // if(Application.platform == RuntimePlatform.IPhonePlayer ||
- // Application.platform == RuntimePlatform.Android)// ||
- // //Application.platform == RuntimePlatform.BlackBerryPlayer ||
- // //Application.platform == RuntimePlatform.WSAPlayer)
- // {
- // Text pText = Text_HowTo.GetComponent<Text>();
- // pText.text = "Move: Joystick on left | Look: Joystick on right | Change Skybox: Tap";
- // }
- // else
- // {
- // Text pText = Text_HowTo.GetComponent<Text>();
- // pText.text = "Switch Skybox: Left/Right Arrow | Turn: Mouse Drag | Release Mouse: ESC Button";
- // }
- // }
- //}
- //#endregion // Update UI text functions
- }
|