示例#1
0
        private Vector3 GetPosition(GameObject scannerObj, Terrain terrain, bool terrainMode = false)
        {
            Vector3 position = Vector3.zero;

            if (terrainMode)
            {
                if (terrain != null)
                {
                    position.y = terrain.terrainData.size.x / 2f;
                }
            }
            else
            {
                GaiaSceneInfo sceneInfo = null;
                if (Terrain.activeTerrains.Length > 0)
                {
                    sceneInfo = GaiaSceneInfo.GetSceneInfo();
                }
                if (sceneInfo != null)
                {
                    position.y = sceneInfo.m_seaLevel;
                    scannerObj.transform.position = position;
                }
                else
                {
                    scannerObj.transform.position = new Vector3(0f, 50f, 0f);
                }
            }


            return(position);
        }
        void OnEnable()
        {
            //Grab the active terrain height map
            if (Gaia.TerrainHelper.GetActiveTerrainCount() == 1 && Gaia.TerrainHelper.GetActiveTerrain() != null)
            {
                //Get sea level
                GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo();
                m_seaLevel = sceneInfo.m_seaLevel;

                //Get our manager
                m_visualiser = (ResourceVisualiser)target;
                m_visualiser.Initialise();
                m_visualiser.Visualise();

                //Update resource sea level
                m_visualiser.m_resources.ChangeSeaLevel(m_seaLevel);
            }
        }
示例#3
0
        /// <summary>
        /// Select or create a scanner
        /// </summary>
        public static GameObject CreateScanner()
        {
            GameObject gaiaObj    = GaiaUtils.GetGaiaGameObject();
            GameObject scannerObj = GameObject.Find("Scanner");

            if (scannerObj == null)
            {
                scannerObj = new GameObject("Scanner");
                scannerObj.transform.parent = gaiaObj.transform;
                GaiaSceneInfo sceneInfo = null;
                if (Terrain.activeTerrains.Length > 0)
                {
                    sceneInfo = GaiaSceneInfo.GetSceneInfo();
                }
                if (sceneInfo != null)
                {
                    Vector3 position = scannerObj.transform.position;
                    position.y = sceneInfo.m_seaLevel;
                    scannerObj.transform.position = position;
                }
                else
                {
                    scannerObj.transform.position = new Vector3(0f, 50f, 0f);
                }
                Scanner scanner = scannerObj.AddComponent <Scanner>();

                #if UNITY_EDITOR
                //Load the material to draw it
                string matPath = GaiaUtils.GetAssetPath("GaiaScannerMaterial.mat");
                if (!string.IsNullOrEmpty(matPath))
                {
                    scanner.m_previewMaterial = AssetDatabase.LoadAssetAtPath <Material>(matPath);
                }
                #endif
            }
            return(scannerObj);
        }
        void Start()
        {
            mainlight         = gameObject.GetComponent <Light>();
            mainlight.cookie  = null;
            causticsObject    = gameObject.transform;
            storedFogColor    = UnityEngine.RenderSettings.fogColor;
            storedFogDistance = UnityEngine.RenderSettings.fogEndDistance;
            partentObject     = GetOrCreateEnvironmentParent().transform;

            ambientAudio = null;
            if (ambientAudio == null)
            {
                ambientAudio = GameObject.Find("Ambient Audio");
            }

            underwaterAudio = null;
            if (underwaterAudio == null)
            {
                underwaterAudio = GameObject.Find("Underwater SoundFX");
            }
            #if UNITY_EDITOR
            if (player == null)
            {
                player = GetThePlayer();
            }
            #endif
            GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo();
            if (sceneInfo != null)
            {
                m_sealevel = sceneInfo.m_seaLevel;
            }

            if (m_useHorizonFix)
            {
                horizonObject = GameObject.Find("Ambient Underwater Horizon");
                if (horizonObjectStored != null)
                {
                    horizonObject      = Instantiate(horizonObjectStored);
                    horizonObject.name = "Ambient Underwater Horizon";
                    if (partentObject != null)
                    {
                        horizonObject.transform.parent = partentObject;
                    }

                    MeshRenderer[] theRenders = horizonObject.GetComponentsInChildren <MeshRenderer>();
                    foreach (MeshRenderer rends in theRenders)
                    {
                        rends.enabled = false;
                    }
                }
            }

            if (m_useUnderwaterparticles)
            {
                underwaterParticles = GameObject.Find("Underwater Particles Effects");
                if (underwaterParticlesStored != null)
                {
                    underwaterParticles      = Instantiate(underwaterParticlesStored);
                    underwaterParticles.name = "Underwater Particles Effects";
                    underwaterParticles.SetActive(false);
                    if (partentObject != null)
                    {
                        underwaterParticles.transform.parent = partentObject;
                    }
                }
            }

            if (gameObject.GetComponent <AudioSource>() == null)
            {
                gameObject.AddComponent <AudioSource>();
                objectAudioSource        = gameObject.GetComponent <AudioSource>();
                objectAudioSource.volume = m_waterSubmergeSounfFXVolume;
            }
            else
            {
                objectAudioSource        = gameObject.GetComponent <AudioSource>();
                objectAudioSource.volume = m_waterSubmergeSounfFXVolume;
            }

            if (mainlight.type == LightType.Directional)
            {
                mainlight.cookieSize = m_causticsSize;
            }
        }
示例#5
0
        /// <summary>
        /// On Enable
        /// </summary>
        private void OnEnable()
        {
#if UNITY_EDITOR
            m_gaiaSettings = GaiaUtils.GetGaiaSettings();

            m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo();

            if (m_gaiaSettings != null)
            {
                m_currentRenderer = m_gaiaSettings.m_currentRenderer;
            }
#if UNITY_POST_PROCESSING_STACK_V2
            transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();

            underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();

            if (Application.isPlaying)
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = true;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = true;
                }
            }
            else
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = false;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = false;
                }
            }
#endif

#if UNITY_2019_1_OR_NEWER && HDPipeline
            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                if (m_aboveWaterProfile == null)
                {
                    m_aboveWaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Post Processing Profile"));
                }

                if (m_underwaterProfile == null)
                {
                    m_underwaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Underwater Post Processing Profile"));
                }
            }
#endif
#endif
        }
示例#6
0
        /// <summary>
        /// Start function
        /// </summary>
        void Start()
        {
#if UNITY_POST_PROCESSING_STACK_V2
            transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();

            underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();

            if (Application.isPlaying)
            {
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = true;
                }
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = true;
                }
            }
            else
            {
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = false;
                }
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = false;
                }
            }
#endif

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

            if (m_gaiaSceneInfo == null)
            {
                m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo();
            }

            if (m_gaiaSettings != null)
            {
                m_currentRenderer = m_gaiaSettings.m_currentRenderer;
            }

#if HDPipeline
            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                GameObject underwaterProbe = GameObject.Find("Underwater Reflection Probe");
                if (underwaterProbe != null)
                {
                    m_underwaterProbe = GameObject.Find("Underwater Reflection Probe").GetComponent <ReflectionProbe>();
                }
            }
#endif
            GameObject waterPlanar = GameObject.Find("Water Planar Reflections");
            if (waterPlanar != null)
            {
                ReflectionProbe reflection = GameObject.Find("Water Planar Reflections").GetComponent <ReflectionProbe>();
                {
                    if (reflection != null)
                    {
                        reflection.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom;
                    }
#if HDPipeline
                    HDAdditionalReflectionData reflectionData = GameObject.Find("Water Planar Reflections").GetComponent <HDAdditionalReflectionData>();
                    if (reflectionData != null)
                    {
#if !UNITY_2019_1_OR_NEWER
                        reflectionData.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom;
#else
                        reflectionData.mode = ProbeSettings.Mode.Realtime;
#endif
                    }
#endif
                }
            }

#if HDPipeline
            if (m_underwaterProbe != null)
            {
                m_underwaterProbe.enabled = false;
            }
#endif

            mainlight        = gameObject.GetComponent <Light>();
            mainlight.cookie = null;
            causticsObject   = gameObject.transform;
            partentObject    = GetOrCreateEnvironmentParent().transform;
            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
#if UNITY_2019_1_OR_NEWER && HDPipeline
                postVolume = GameObject.Find("Gaia HDRP Post Processing").GetComponent <Volume>();

                volume = GameObject.Find("High Definition Environment Volume").GetComponent <Volume>();
                if (volume != null)
                {
                    VolumeProfile profile = volume.sharedProfile;
                    if (profile != null)
                    {
                        VolumetricFog fog;
                        if (profile.TryGet(out fog))
                        {
                            storedFogColor    = fog.albedo.value;
                            storedFogDistance = fog.meanFreePath.value;
                        }
                    }
                }
#endif
            }
            else
            {
                storedFogColor    = RenderSettings.fogColor;
                storedFogDistance = RenderSettings.fogEndDistance;
            }

            ambientAudio = null;
            if (ambientAudio == null)
            {
                ambientAudio = GameObject.Find("Ambient Audio");
            }

            underwaterAudio = null;
            if (underwaterAudio == null)
            {
                underwaterAudio = GameObject.Find("Underwater SoundFX");
            }
#if UNITY_EDITOR
            if (player == null)
            {
                player = GetThePlayer();
            }
#endif
            if (m_gaiaSceneInfo != null)
            {
                m_sealevel = m_gaiaSceneInfo.m_seaLevel;
            }

            if (m_useHorizonFix)
            {
                horizonObject = GameObject.Find("Ambient Underwater Horizon");
                if (horizonObjectStored != null)
                {
                    horizonObject      = Instantiate(horizonObjectStored);
                    horizonObject.name = "Ambient Underwater Horizon";
                    if (partentObject != null)
                    {
                        horizonObject.transform.parent = partentObject;
                    }

                    MeshRenderer[] theRenders = horizonObject.GetComponentsInChildren <MeshRenderer>();
                    foreach (MeshRenderer rends in theRenders)
                    {
                        rends.enabled = false;
                    }
                }
            }

            if (m_useUnderwaterparticles)
            {
                underwaterParticles = GameObject.Find("Underwater Particles Effects");
                if (underwaterParticlesStored != null)
                {
                    underwaterParticles      = Instantiate(underwaterParticlesStored);
                    underwaterParticles.name = "Underwater Particles Effects";
                    underwaterParticles.SetActive(false);
                    if (partentObject != null)
                    {
                        underwaterParticles.transform.parent = partentObject;
                    }
                }
            }

            if (gameObject.GetComponent <AudioSource>() == null)
            {
                gameObject.AddComponent <AudioSource>();
                objectAudioSource        = gameObject.GetComponent <AudioSource>();
                objectAudioSource.volume = m_waterSubmergeSounfFXVolume;
            }
            else
            {
                objectAudioSource        = gameObject.GetComponent <AudioSource>();
                objectAudioSource.volume = m_waterSubmergeSounfFXVolume;
            }

            if (mainlight.type == LightType.Directional)
            {
                mainlight.cookieSize = m_causticsSize;
            }

            StopAllCoroutines();
        }
示例#7
0
        /// <summary>
        /// On Enable
        /// </summary>
        private void OnEnable()
        {
#if UNITY_EDITOR
            m_gaiaSettings = GaiaUtils.GetGaiaSettings();

            m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo();

            if (m_gaiaSettings != null)
            {
                m_currentRenderer = m_gaiaSettings.m_currentRenderer;
            }
#if UNITY_POST_PROCESSING_STACK_V2
            transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();

            underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();

            if (Application.isPlaying)
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = true;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = true;
                }
            }
            else
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = false;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = false;
                }
            }
#endif

#if UNITY_2019_1_OR_NEWER && HDPipeline
            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                if (m_aboveWaterProfile == null)
                {
                    m_aboveWaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Post Processing Profile"));
                }

                if (m_underwaterProfile == null)
                {
                    m_underwaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Underwater Post Processing Profile"));
                }
            }
#endif
#endif

            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                GameObject volumeObject = GameObject.Find("High Definition Environment Volume");
                if (volumeObject != null)
                {
#if !UNITY_2019_1_OR_NEWER && HDPipeline
                    if (volume == null)
                    {
                        volume = GameObject.Find("High Definition Environment Volume").GetComponent <Volume>();
                        if (volume != null)
                        {
                            VolumeProfile profile = volume.sharedProfile;
                            if (profile != null)
                            {
                                VolumetricFog fog;
                                if (profile.TryGet(out fog))
                                {
                                    storedFogColor    = fog.albedo.value;
                                    storedFogDistance = fog.meanFreePath.value;
                                }
                            }
                        }
                    }
#endif
                }
                else
                {
                    Debug.LogWarning("Unabled to find a HDRP environment volume in the scene. Please insure one is set in this scene.");
                }
            }

#if UNITY_2019_1_OR_NEWER && HDPipeline
            postVolume = GameObject.Find("Gaia HDRP Post Processing").GetComponent <Volume>();
#endif
        }