コード例 #1
0
 // Start is called before the first frame update
 void Start()
 {
     source          = gameObject.GetComponentInChildren <NVIDIA.Flex.FlexSourceActor>();
     isPouring       = false;
     source.isActive = false;
     Debug.Log(source.container.maxParticles + " liquid stored");
     rotateX             = transform;
     BottleSpawnPosition = GameObject.FindGameObjectWithTag("Respawn").transform.position;
     liquid_in_glass     = 0;
     bartender_rage      = 0;
 }
        void OnFlexUpdate(FlexContainer.ParticleData _particleData)
        {
            FlexActor actor = GetComponent <FlexActor>();

            if (actor is FlexSourceActor)
            {
                FlexSourceActor sourceActor = actor as FlexSourceActor;
                var             main        = m_particleSystem.main;
                float           time        = Time.time - Time.fixedTime;
                int[]           indices     = sourceActor.indices;
                int             indexCount  = sourceActor.indexCount;
                float[]         ages        = sourceActor.ages;
                m_particleSystem.Clear();
                m_particleSystem.Emit(indices.Length);
                if (m_particles.Length != indexCount)
                {
                    m_particles = new ParticleSystem.Particle[indexCount];
                }
                float   startLifetime = main.startLifetime.Evaluate(0);
                Color32 startColor    = main.startColor.Evaluate(0);
                float   startSize     = main.startSize.Evaluate(0);
                for (int i = 0; i < indexCount; ++i)
                {
                    ParticleSystem.Particle p = m_particles[i];
                    p.velocity          = _particleData.GetVelocity(indices[i]);;
                    p.position          = (Vector3)_particleData.GetParticle(indices[i]) + p.velocity * (time - Time.fixedDeltaTime);
                    p.remainingLifetime = ages[i] - time;
                    p.startLifetime     = startLifetime;
                    p.startColor        = startColor;
                    p.startSize         = startSize;
                    m_particles[i]      = p;
                }
                //m_particleSystem.SetParticles(m_particles, m_particles.Length);
            }
            else if (actor)
            {
                var   main       = m_particleSystem.main;
                float time       = Time.time - Time.fixedTime;
                int[] indices    = actor.indices;
                int   indexCount = actor.indexCount;
                //m_particleSystem.Clear();
                //m_particleSystem.Emit(indices.Length);
                if (m_particles.Length != indexCount)
                {
                    m_particles = new ParticleSystem.Particle[indexCount];
                }
                Color32 startColor = main.startColor.Evaluate(0);
                float   startSize  = main.startSize.Evaluate(0);
                for (int i = 0; i < indexCount; ++i)
                {
                    ParticleSystem.Particle p = m_particles[i];
                    p.velocity          = _particleData.GetVelocity(indices[i]);
                    p.position          = (Vector3)_particleData.GetParticle(indices[i]) + p.velocity * (time - Time.fixedDeltaTime);
                    p.remainingLifetime = m_particleSystem.main.startLifetime.Evaluate(0);
                    p.startLifetime     = p.remainingLifetime;
                    p.startColor        = startColor;
                    p.startSize         = startSize;
                    m_particles[i]      = p;
                }
                //m_particleSystem.SetParticles(m_particles, m_particles.Length);
            }
            m_particleSystem.SetParticles(m_particles, m_particles.Length);
        }