Esempio n. 1
0
 private void Awake()
 {
     if (m_mainCamera == null)
     {
         m_mainCamera = GaiaUtils.GetCamera();
     }
 }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            if (dropdownGUIStyle == null)
            {
                dropdownGUIStyle = new GUIStyle(EditorStyles.popup)
                {
                    fixedHeight = 16f, margin = new RectOffset(0, 0, 4, 0)
                };
            }

            if (m_profile != null)
            {
                Transform transform = m_profile.gameObject.transform;
                transform.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
                if (m_profile.m_mainCamera == null)
                {
                    m_profile.m_mainCamera = GaiaUtils.GetCamera();
                }
            }

            //Initialization
            m_editorUtils.Initialize(); // Do not remove this!
            if (m_gaiaSettings == null)
            {
                m_gaiaSettings = GaiaUtils.GetGaiaSettings();
            }

            m_editorUtils.Panel("GlobalSettings", GlobalSettingsPanel, false, true, true);
        }
Esempio n. 3
0
 /// <summary>
 /// On Start find camera
 /// </summary>
 private void Start()
 {
     if (m_mainCamera == null)
     {
         m_mainCamera = GaiaUtils.GetCamera(true);
     }
 }
Esempio n. 4
0
        public void UpdateCulling(GaiaSettings gaiaSettings)
        {
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }
            if (GaiaGlobal.Instance.m_mainCamera == null)
            {
                GaiaGlobal.Instance.m_mainCamera = GaiaUtils.GetCamera();
            }

            float farClipPlane = 2000f;

            if (GaiaGlobal.Instance.m_mainCamera != null)
            {
                farClipPlane = GaiaGlobal.Instance.m_mainCamera.farClipPlane;
            }

            if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
            {
                GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }

            Terrain terrain = TerrainHelper.GetActiveTerrain();

            //Objects
            m_layerDistances = new float[32];
            for (int i = 0; i < m_layerDistances.Length; i++)
            {
                string layerName = LayerMask.LayerToName(i);
                switch (layerName)
                {
                case "Default":
                case "Water":
                case "PW_VFX":
                    m_layerDistances[i] = 0f;
                    break;

                case "PW_Object_Small":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 5f);
                    break;

                case "PW_Object_Medium":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 3f);
                    break;

                case "PW_Object_Large":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment);
                    break;

                default:
                    m_layerDistances[i] = 0f;
                    break;
                }
            }
        }
Esempio n. 5
0
 private void Start()
 {
     if (m_player == null)
     {
         if (GaiaUtils.GetCamera() != null)
         {
             m_player = GaiaUtils.GetCamera().transform;
         }
     }
 }
Esempio n. 6
0
        private void Start()
        {
            if (m_camera == null)
            {
                m_camera = GaiaUtils.GetCamera();
            }

            if (!VerifyCameraController())
            {
                Debug.LogError("Car Controller could not be setup correctly.");
            }
        }
Esempio n. 7
0
        public void LoadUnderwaterSystemAssets()
        {
#if UNITY_EDITOR
            Camera camera = GaiaUtils.GetCamera();
            if (camera != null)
            {
                m_playerCamera = camera.transform;
            }

            if (m_causticTextures == null || m_causticTextures.Count <= 0)
            {
                m_causticTextures = new List <Texture2D>
                {
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_001.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_002.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_003.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_004.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_005.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_006.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_007.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_008.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_009.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_010.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_011.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_012.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_013.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_014.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_015.tif")),
                    AssetDatabase.LoadAssetAtPath <Texture2D>(GaiaUtils.GetAssetPath("CausticsRender_016.tif"))
                };
            }

            if (m_submergeSoundFXDown == null)
            {
                m_submergeSoundFXDown = AssetDatabase.LoadAssetAtPath <AudioClip>(GaiaUtils.GetAssetPath("Gaia Ambient Submerge Down.mp3"));
            }

            if (m_submergeSoundFXUp == null)
            {
                m_submergeSoundFXUp = AssetDatabase.LoadAssetAtPath <AudioClip>(GaiaUtils.GetAssetPath("Gaia Ambient Submerge Up.mp3"));
            }

            if (m_underwaterSoundFX == null)
            {
                m_underwaterSoundFX = AssetDatabase.LoadAssetAtPath <AudioClip>(GaiaUtils.GetAssetPath("Gaia Ambient Underwater Sound Effect.mp3"));
            }

            if (m_fogColorGradient == null)
            {
                m_fogColorGradient = CreateGradient();
            }
#endif
        }
Esempio n. 8
0
        public void OnEnable()
        {
            m_instance     = this;
            WeatherPresent = CheckWeatherPresent();

            if (!Application.isPlaying)
            {
                if (m_lightingProfile == null)
                {
                    return;
                }

                if (m_waterProfile == null)
                {
                    return;
                }

                if (m_gaiaSettings == null)
                {
                    m_gaiaSettings = GaiaUtils.GetGaiaSettings();
                    if (m_gaiaSettings == null)
                    {
                        return;
                    }
                }
            }

            if (m_mainCamera == null)
            {
                m_mainCamera = GaiaUtils.GetCamera();
            }

            if (m_sunLight == null)
            {
                m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }

            if (m_moonLight == null)
            {
                GameObject moonObject = GameObject.Find("Moon Light");
                if (moonObject != null)
                {
                    m_moonLight = moonObject.GetComponent <Light>();
                }
            }

            UpdateGaiaTimeOfDay(false);
            CheckPostProcessingFog(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Sets up the camera if not already done
        /// </summary>
        private void OnEnable()
        {
            if (m_mainCamera == null)
            {
                m_mainCamera = GaiaUtils.GetCamera(true);
            }

            //Create the target directory
            string path = Path.Combine(Application.dataPath, m_targetDirectory);

            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
                #if UNITY_EDITOR
                AssetDatabase.Refresh();
                #endif
            }
        }
Esempio n. 10
0
        public bool VerifyCameraController()
        {
            if (m_camera == null)
            {
                m_camera = GaiaUtils.GetCamera();
                if (m_camera == null)
                {
                    return(false);
                }
            }

            CameraController controller = m_camera.GetComponent <CameraController>();

            if (controller == null)
            {
                controller = m_camera.gameObject.AddComponent <CameraController>();
            }

            controller.target             = m_carFocusPoint;
            controller.targetHeight       = m_cameraControllerData.targetHeight;
            controller.distance           = m_cameraControllerData.distance;
            controller.offsetFromWall     = m_cameraControllerData.offsetFromWall;
            controller.maxDistance        = m_cameraControllerData.maxDistance;
            controller.minDistance        = m_cameraControllerData.minDistance;
            controller.xSpeed             = m_cameraControllerData.xSpeed;
            controller.ySpeed             = m_cameraControllerData.ySpeed;
            controller.yMinLimit          = m_cameraControllerData.yMinLimit;
            controller.yMaxLimit          = m_cameraControllerData.yMaxLimit;
            controller.zoomRate           = m_cameraControllerData.zoomRate;
            controller.rotationDampening  = m_cameraControllerData.rotationDampening;
            controller.zoomDampening      = m_cameraControllerData.zoomDampening;
            controller.collisionLayers    = m_cameraControllerData.collisionLayers;
            controller.lockToRearOfTarget = m_cameraControllerData.lockToRearOfTarget;
            controller.allowMouseInputX   = m_cameraControllerData.allowMouseInputX;
            controller.allowMouseInputY   = m_cameraControllerData.allowMouseInputY;

            return(true);
        }
Esempio n. 11
0
        private void Setup(bool helpEnabled)
        {
            m_profile.m_locationProfile = (LocationSystemScriptableObject)m_editorUtils.ObjectField("LocationProfile", m_profile.m_locationProfile, typeof(LocationSystemScriptableObject), false, helpEnabled);
            if (m_profile.m_locationProfile == null)
            {
                m_profile.m_locationProfile = AssetDatabase.LoadAssetAtPath <LocationSystemScriptableObject>(GaiaUtils.GetAssetPath("Location Profile.asset"));
            }

            if (m_profile.m_camera == null)
            {
                EditorGUILayout.BeginHorizontal();
                m_profile.m_camera = (Transform)m_editorUtils.ObjectField("Camera", m_profile.m_camera, typeof(Transform), true, helpEnabled);
                if (m_editorUtils.Button("FindCamera", GUILayout.MaxWidth(50f)))
                {
                    Camera locatedCam = GaiaUtils.GetCamera();
                    if (locatedCam != null)
                    {
                        m_profile.m_camera = locatedCam.transform;
                    }
                    else
                    {
                        Debug.LogWarning("No camera could be found in your scene please add one from the GameObject/Camera in the top toolbar.");
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.HelpBox("A camera transform must be provided for Location Manager to work. You can press 'Find' button to quickly locate the camera in the scene.", MessageType.Warning);
            }
            else
            {
                m_profile.m_camera = (Transform)m_editorUtils.ObjectField("Camera", m_profile.m_camera, typeof(Transform), true, helpEnabled);
            }

            m_profile.m_player = (Transform)m_editorUtils.ObjectField("Player", m_profile.m_player, typeof(Transform), true, helpEnabled);

            m_profile.m_trackPlayer = m_editorUtils.Toggle("TrackPlayer", m_profile.m_trackPlayer, helpEnabled);
        }
Esempio n. 12
0
 private void StartReflectionSystem()
 {
     RenderPipelineManager.beginCameraRendering += ExecutePlanarReflections;
     m_gameCamera = GaiaUtils.GetCamera();
 }
Esempio n. 13
0
        /// <summary>
        /// Takes the actual screen shot when the key is pressed or takeshot is true
        /// </summary>
        private void LateUpdate()
        {
            if (Input.GetKeyDown(m_screenShotKey) || m_takeShot)
            {
                if (m_mainCamera == null)
                {
                    m_mainCamera = GaiaUtils.GetCamera(true);
                }

                //Pick up and use the actual screen dimensions
                if (m_useScreenSize)
                {
                    m_targetWidth  = Screen.width;
                    m_targetHeight = Screen.height;
                }

                m_refreshAssetDB = true;
                RenderTexture rt;
                if (m_imageFormat == GaiaConstants.ImageFileType.Exr)
                {
                    rt = new RenderTexture(m_targetWidth, m_targetHeight, 24, DefaultFormat.HDR);
                }
                else
                {
                    rt = new RenderTexture(m_targetWidth, m_targetHeight, 24, DefaultFormat.LDR);
                }
                m_mainCamera.targetTexture = rt;
                Texture2D screenShot;
                if (m_imageFormat == GaiaConstants.ImageFileType.Exr)
                {
                    screenShot = new Texture2D(m_targetWidth, m_targetHeight, TextureFormat.RGBAFloat, false);
                }
                else
                {
                    screenShot = new Texture2D(m_targetWidth, m_targetHeight, TextureFormat.RGB24, false);
                }

                bool allowHDR = m_mainCamera.allowHDR;
                if (m_imageFormat == GaiaConstants.ImageFileType.Exr)
                {
                    m_mainCamera.allowHDR = true;
                }
                m_mainCamera.Render();
                m_mainCamera.allowHDR = allowHDR;
                RenderTexture.active  = rt;
                screenShot.ReadPixels(new Rect(0, 0, m_targetWidth, m_targetHeight), 0, 0);
                m_mainCamera.targetTexture = null;
                RenderTexture.active       = null; // JC: added to avoid errors
                Destroy(rt);

                if (m_watermark != null)
                {
                    Gaia.GaiaUtils.MakeTextureReadable(m_watermark);
                    screenShot = AddWatermark(screenShot, m_watermark);
                }

                byte[] bytes = null;
                switch (m_imageFormat)
                {
                case GaiaConstants.ImageFileType.Exr:
                    bytes = ImageConversion.EncodeToEXR(screenShot, Texture2D.EXRFlags.CompressZIP);
                    break;

                case GaiaConstants.ImageFileType.Png:
                    bytes = ImageConversion.EncodeToPNG(screenShot);
                    break;

                case GaiaConstants.ImageFileType.Tga:
                    bytes = ImageConversion.EncodeToTGA(screenShot);
                    break;

                case GaiaConstants.ImageFileType.Jpg:
                    bytes = ImageConversion.EncodeToJPG(screenShot, 100);
                    break;
                }

                string filename = ScreenShotName(m_targetWidth, m_targetHeight);
                PWCommon4.Utils.WriteAllBytes(filename, bytes);
                m_takeShot = false;
                Debug.Log(string.Format("Took screenshot to: {0}", filename));
            }
        }
Esempio n. 14
0
        private void Update()
        {
            if (Application.isPlaying)
            {
                if (m_underwaterTransitionPostFX != null)
                {
                    if (m_underwaterTransitionPostFX.transform.position.y != m_seaLevel)
                    {
                        SetupTransitionVFX(m_enableTransitionFX);
                    }
                }

                if (m_mainLight == null)
                {
                    m_mainLight = GaiaUtils.GetMainDirectionalLight();
                }

                if (m_playerCamera == null)
                {
                    Debug.LogError("Player Camera is missing from the setup. Will try find it for you");
                    Camera camera = GaiaUtils.GetCamera();
                    if (camera != null)
                    {
                        m_playerCamera = camera.transform;
                    }
                    return;
                }
                else
                {
                    if (EnableUnderwaterEffects)
                    {
                        if (m_playerCamera.position.y > m_seaLevel)
                        {
                            if (!m_surfaceSetup)
                            {
                                IsUnderwater      = SetupWaterSystems(false, m_startingUnderwater);
                                m_underwaterSetup = false;
                                m_surfaceSetup    = true;
                            }
                        }
                        else
                        {
                            if (!m_underwaterSetup)
                            {
                                if (m_underwaterTransitionPostFX != null)
                                {
                                    m_underwaterTransitionPostFX.SetActive(true);
                                }
                                if (m_underwaterPostFX != null)
                                {
                                    m_underwaterPostFX.SetActive(true);
                                }
                                UpdateSurfaceFogSettings();
                                IsUnderwater      = SetupWaterSystems(true, m_startingUnderwater);
                                m_underwaterSetup = true;
                                m_surfaceSetup    = false;
                            }

                            UpdateUnderwaterFog();
                            UpdateUnderwaterPostFX();
                        }
                    }
                    else
                    {
                        if (m_underwaterTransitionPostFX != null)
                        {
                            m_underwaterTransitionPostFX.SetActive(false);
                        }
                        if (m_underwaterPostFX != null)
                        {
                            m_underwaterPostFX.SetActive(false);
                        }
                    }
                }

                if (m_weatherSystemExists)
                {
#if GAIA_PRO_PRESENT
                    if (!ProceduralWorldsGlobalWeather.Instance.IsRainingFinished || !ProceduralWorldsGlobalWeather.Instance.IsSnowingFinished)
                    {
                        ProceduralWorldsGlobalWeather.Instance.CheckUnderwaterParticlesVFX(IsUnderwater);
                    }
#endif
                }

                if (!IsUnderwater)
                {
                    UpdateSurfaceFogSettings();
                }
                else
                {
#if GAIA_PRO_PRESENT
                    if (m_weatherSystemExists)
                    {
                        if (ProceduralWorldsGlobalWeather.Instance.CheckIsNight())
                        {
                            m_mainLight = ProceduralWorldsGlobalWeather.Instance.m_moonLight;
                        }
                        else
                        {
                            m_mainLight = ProceduralWorldsGlobalWeather.Instance.m_sunLight;
                        }
                    }
#endif
                    if (m_underwaterMaterial != null)
                    {
                        UpdateUnderwaterMaterial();
                    }
                }
            }
            else
            {
                if (m_underwaterParticleSystem != null)
                {
                    m_underwaterParticleSystem.Stop();
                }

                if (m_underwaterPostFX != null)
                {
                    m_underwaterPostFX.SetActive(false);
                }

                if (m_underwaterTransitionPostFX != null)
                {
                    m_underwaterTransitionPostFX.SetActive(false);
                }

                if (m_horizonObject != null)
                {
                    m_horizonObject.SetActive(false);
                }
            }
        }