Ejemplo n.º 1
0
        public void Initialize(VolumetricLightBeam master)
        {
            Debug.Assert(master != null);

            var customHideFlags = Consts.ProceduralObjectsHideFlags;

            m_Master = master;

            transform.SetParent(master.transform, false);

            meshRenderer                      = gameObject.GetOrAddComponent <MeshRenderer>();
            meshRenderer.hideFlags            = customHideFlags;
            meshRenderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows       = false;
            meshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; // different reflection probes could break batching with GPU Instancing
#if UNITY_5_4_OR_NEWER
            meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
#else
            meshRenderer.useLightProbes = false;
#endif

            if (!shouldUseGPUInstancedMaterial)
            {
                m_CustomMaterial = MaterialManager.NewMaterial(gpuInstanced: false);
                ApplyMaterial();
            }

            if (SortingLayer.IsValid(m_Master.sortingLayerID))
            {
                sortingLayerID = m_Master.sortingLayerID;
            }
            else
            {
                Debug.LogError(string.Format("Beam '{0}' has an invalid sortingLayerID ({1}). Please fix it by setting a valid layer.", Utils.GetPath(m_Master.transform), m_Master.sortingLayerID));
            }

            sortingOrder = m_Master.sortingOrder;

            meshFilter           = gameObject.GetOrAddComponent <MeshFilter>();
            meshFilter.hideFlags = customHideFlags;

            gameObject.hideFlags = customHideFlags;

#if UNITY_EDITOR
            UnityEditor.GameObjectUtility.SetStaticEditorFlags(gameObject, master.GetStaticEditorFlagsForSubObjects());
            gameObject.SetSameSceneVisibilityStatesThan(master.gameObject);
#endif

            RestartFadeOutCoroutine();
        }
        void InstantiateParticleSystem()
        {
            // If we duplicate (from Editor and Playmode) the VLB, the children are also duplicated (like the dust particles)
            // we have to make sure to properly destroy them before creating our proper procedural particle instance.
            var slaves = GetComponentsInChildren <ParticleSystem>(true);

            for (int i = slaves.Length - 1; i >= 0; --i)
            {
                DestroyImmediate(slaves[i].gameObject);
            }

            m_Particles = Config.Instance.NewVolumetricDustParticles();

            if (m_Particles)
            {
#if UNITY_EDITOR
                if (m_Master)
                {
                    UnityEditor.GameObjectUtility.SetStaticEditorFlags(m_Particles.gameObject, m_Master.GetStaticEditorFlagsForSubObjects());
                    m_Particles.gameObject.SetSameSceneVisibilityStatesThan(m_Master.gameObject);
                }
#endif
                m_Particles.transform.SetParent(transform, false);
                m_Renderer = m_Particles.GetComponent <ParticleSystemRenderer>();
            }
        }