예제 #1
0
        protected bool Initialize()
        {
            // initialize members
            if (_transform == null)
            {
                _transform = transform;
            }
            if (pSystem == null)
            {
                pSystem = gameObject.GC <ParticleSystem>();

                if (pSystem == null)
                {
                    return(false);
                }

                #if UNITY_5_5_OR_NEWER
                mainModule = pSystem.main;
                if (pSystem.main.maxParticles > 14000)
                {
                    mainModule.maxParticles = 14000;
                }
                #else
                if (pSystem.maxParticles > 14000)
                {
                    pSystem.maxParticles = 14000;
                }
                #endif

                pRenderer = pSystem.GC <ParticleSystemRenderer>();
                if (pRenderer.NotNull())
                {
                    pRenderer.enabled = false;
                }

                Shader   foundShader = Shader.Find("UI/Default");
                Material pMaterial   = new Material(foundShader);

                if (material == null)
                {
                    material = pMaterial;
                }

                currentMaterial = material;
                if (currentMaterial && currentMaterial.HasProperty("_MainTex"))
                {
                    currentTexture = currentMaterial.mainTexture;
                    if (currentTexture == null)
                    {
                        currentTexture = Texture2D.whiteTexture;
                    }
                }
                material = currentMaterial;
                // automatically set scaling
                #if UNITY_5_5_OR_NEWER
                mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy;
                #else
                pSystem.scalingMode = ParticleSystemScalingMode.Hierarchy;
                #endif

                particles = null;
            }
            #if UNITY_5_5_OR_NEWER
            if (particles == null)
            {
                particles = new ParticleSystem.Particle[pSystem.main.maxParticles];
            }
            #else
            if (particles == null)
            {
                particles = new ParticleSystem.Particle[pSystem.maxParticles];
            }
            #endif

            imageUV = new Vector4(0, 0, 1, 1);

            // prepare texture sheet animation
            textureSheetAnimation          = pSystem.textureSheetAnimation;
            textureSheetAnimationFrames    = 0;
            textureSheetAnimationFrameSize = Vector2.zero;
            if (textureSheetAnimation.enabled)
            {
                textureSheetAnimationFrames    = textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY;
                textureSheetAnimationFrameSize = new Vector2(1f / textureSheetAnimation.numTilesX, 1f / textureSheetAnimation.numTilesY);
            }

            return(true);
        }