Ejemplo n.º 1
0
        protected override bool OnStartPluginFrame(ref FluvioTimeStep timeStep)
        {
#if UNITY_5_5
            if (_disableInEditMode && !Application.isPlaying)
            {
                return(false);
            }
#endif

            // Always process the full fluid group - this plugin requires sub-fluids to work properly.
            includeFluidGroup = true;

            // Skip the first frame
            if (m_FirstFrame)
            {
                m_FirstFrame = false;
                return(false);
            }

            if (!fluidB || !fluidB.enabled)
            {
                return(false);
            }

            // Create arrays
            var oldCount = m_Count;
            m_Count = fluid.GetTotalParticleCount();
            Array.Resize(ref m_MixerData, m_Count);

            for (var i = oldCount; i < m_Count; ++i)
            {
                m_MixerData[i].emitVelocity.w = 0;
            }

            // Get timestep
            m_TimeStep = timeStep;
            // Get gravity
            m_Gravity = fluid.gravity;
            // Get simulation scale
            m_SimulationScale = fluid.simulationScale;
            // Set flag indicating whether or not the mixing fluids are the same
            m_MixingFluidsAreTheSame = fluid == fluidB;
            // Get squared mixing distance
            m_MixingDistanceSq = fluid.smoothingDistance * fluid.smoothingDistance * distanceMultiplier * distanceMultiplier;
            // Get fluid IDs
            m_FluidAID = fluid.GetFluidID();
            m_FluidBID = fluidB.GetFluidID();
            m_FluidCID = fluidC ? 1 : 0;
            m_FluidDID = fluidD ? 2 : 0;

            // Fluid B and (C or D) at least must be enabled
            return(fluidC || fluidD);
        }
Ejemplo n.º 2
0
        protected override bool OnStartPluginFrame(ref FluvioTimeStep timeStep)
        {
            // Clear all touch points
            m_TouchPointsCount = 0;

            // This plugin only runs in Play mode
            if (!Application.isPlaying)
                return false;

            // Get camera and near clip
            var cam = Camera.main;

            if (!cam)
                return false;

            // Get plane passing through fluid position facing the camera
            var plane = new Plane(-cam.transform.forward, fluid.transform.position);

            if (Input.touchCount == 0 || !useMultiTouch)
            {
                // Check for mouse button
                var mouseIsPressed = Input.GetMouseButton(mouseButton);

                if (alwaysOn || mouseIsPressed)
                {
                    var touchPosition = Input.mousePosition;
                    AddTouchPoint(touchPosition, cam, plane);
                }
            }
            else
            {
                // Check all touches
                for (int i = 0, l = Input.touchCount; i < l; ++i)
                {
                    var touch = Input.GetTouch(i);
                    AddTouchPoint(touch.position, cam, plane);
                }
            }

            // Make sure we have an acceleration curve, and that it is signed (-1 to 1)
            if (acceleration == null)
                acceleration = new FluvioMinMaxCurve {scalar = 1000.0f, minConstant = 0.0f, maxConstant = 1000.0f};

            SetCurveAsSigned(acceleration, true);

            // Return false if we didn't add any touch points
            return m_TouchPointsCount > 0;
        }
Ejemplo n.º 3
0
        void OnPreSolve(FluvioTimeStep timeStep)
        {
            if (m_Rigidbodies == null)
            {
                return;
            }

            int l = Mathf.Min(m_Rigidbodies.Length, fluid.particleCount);

            for (int i = 0; i < l; ++i)
            {
                // Get objects
                Rigidbody2D      body     = m_Rigidbodies[i];
                CircleCollider2D collider = m_Colliders[i];
                FluidParticle    particle = fluid.GetParticle(i);

                // Assign properties
                body.gameObject.SetActive(particle.enabled);

                if (body.isKinematic)
                {
                    body.isKinematic = false;
                }

                body.mass          = fluid.particleMass * m_MassModifier;
                body.interpolation = m_RigidbodyInterpolation;

                collider.radius         = fluid.smoothingDistance * m_ColliderSizeModifier;
                collider.sharedMaterial = m_PhysicMaterial;

                if (particle.lifetime < 1.0f)
                {
                    // Send physics information to particles (collisions)
                    particle.position = body.transform.position;
                    particle.velocity = body.velocity * timeStep.dt;

                    // Assign particle
                    fluid.SetParticle(ref particle, i);
                }
            }
        }
Ejemplo n.º 4
0
        void OnPostSolve(FluvioTimeStep timeStep)
        {
            if (m_Rigidbodies == null)
            {
                return;
            }

            int l = Mathf.Min(m_Rigidbodies.Length, fluid.particleCount);

            for (int i = 0; i < l; ++i)
            {
                // Get objects
                Rigidbody2D   body     = m_Rigidbodies[i];
                FluidParticle particle = fluid.GetParticle(i);

                if (body.isKinematic)
                {
                    body.isKinematic = false;
                }
                body.transform.position = particle.position;
                body.velocity           = particle.velocity * timeStep.inv_dt;
            }
        }
Ejemplo n.º 5
0
        protected override bool OnStartPluginFrame(ref FluvioTimeStep timeStep)
        {
            // Clear all touch points
            m_TouchPointsCount = 0;

            // This plugin only runs in Play mode
            if (!Application.isPlaying)
            {
                return(false);
            }

            // Get camera and near clip
            var cam = Camera.main;

            if (!cam)
            {
                return(false);
            }

            // Get plane passing through fluid position facing the camera
            var plane = new Plane(-cam.transform.forward, fluid.transform.position);

            if (Input.touchCount == 0 || !useMultiTouch)
            {
                // Check for mouse button
                var mouseIsPressed = Input.GetMouseButton(mouseButton);

                if (alwaysOn || mouseIsPressed)
                {
                    var touchPosition = Input.mousePosition;
                    AddTouchPoint(touchPosition, cam, plane);
                }
            }
            else
            {
                // Check all touches
                for (int i = 0, l = Input.touchCount; i < l; ++i)
                {
                    var touch = Input.GetTouch(i);
                    AddTouchPoint(touch.position, cam, plane);
                }
            }

            // Make sure we have an acceleration curve, and that it is signed (-1 to 1)
            if (acceleration == null)
            {
                acceleration = new FluvioMinMaxCurve {
                    scalar = 1000.0f, minConstant = 0.0f, maxConstant = 1000.0f
                }
            }
            ;

            SetCurveAsSigned(acceleration, true);

            // Return false if we didn't add any touch points
            return(m_TouchPointsCount > 0);
        }

        void AddTouchPoint(Vector3 touchPosition, Camera cam, Plane plane)
        {
            if (m_TouchPointsCount == m_TouchPoints.Length)
            {
                return;
            }

            // Get orthographic world point
            var ortho = cam.orthographic;

            cam.orthographic = true;
            var worldPoint = cam.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, cam.nearClipPlane));

            cam.orthographic = ortho;

            // Create ray
            var ray = new Ray(worldPoint, -plane.normal);

            m_TouchPoints[m_TouchPointsCount] = ray.GetPoint(plane.GetDistanceToPoint(ray.origin));

            ++m_TouchPointsCount;
        }
Ejemplo n.º 6
0
        protected override bool OnStartPluginFrame(ref FluvioTimeStep timeStep)
        {
            // Always process the full fluid group - this plugin requires sub-fluids to work properly.
            includeFluidGroup = true;

            // Skip the first frame
            if (m_FirstFrame)
            {
                m_FirstFrame = false;
                return false;
            }

            if (!fluidB || !fluidB.enabled)
                return false;

            // Create arrays
            var oldCount = m_Count;
            m_Count = fluid.GetTotalParticleCount();
            Array.Resize(ref m_ParticleSystems, m_Count);
            Array.Resize(ref m_EmitPositions, m_Count);
            Array.Resize(ref m_EmitVelocities, m_Count);

            for (var i = oldCount; i < m_Count; ++i)
            {
                m_ParticleSystems[i] = 0;
            }

            // Get timestep
            m_TimeStep = timeStep;
            // Get gravity
            m_Gravity = fluid.gravity;
            // Get simulation scale
            m_SimulationScale = fluid.simulationScale;
            // Set flag indicating whether or not the mixing fluids are the same
            m_MixingFluidsAreTheSame = fluid == fluidB;
            // Get squared mixing distance
            m_MixingDistanceSq = fluid.smoothingDistance*fluid.smoothingDistance*distanceMultiplier*distanceMultiplier;
            // Get fluid IDs
            m_FluidAID = fluid.GetFluidID();
            m_FluidBID = fluidB.GetFluidID();
            m_FluidCID = fluidC ? 1 : 0;
            m_FluidDID = fluidD ? 2 : 0;

            // Fluid B and (C or D) at least must be enabled
            return fluidC || fluidD;
        }
Ejemplo n.º 7
0
    void OnPostSolve(FluvioTimeStep timeStep)
    {
        if (sleep)
        {
            sleep = false;
            return;
        }

        fluid.GetParticles(ref particles);

#if !(UNITY_IPHONE || UNITY_ANDROID) || UNITY_EDITOR
        bool doTouch = !requireClick ? true : (Input.GetMouseButton(0) || Input.GetMouseButton(1));
        if (doTouch)
        {
            if (Input.GetMouseButton(0) || !requireClick)
            {
                touchMode = invert ? TouchMode.Push : TouchMode.Pull;
            }
            else
            {
                touchMode = invert ? TouchMode.Pull : TouchMode.Push;
            }
            Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, z));
            float   f     = (int)touchMode * force;
            for (int i = 0; i < particles.Length; i++)
            {
                FluidParticle p = particles[i];

                if (!p.enabled)
                {
                    continue;
                }

                float dist = (p.position - point).sqrMagnitude;
                if (dist <= maxDistance * maxDistance)
                {
                    p.AddForce((point - p.position).normalized * f);
                }

                particles[i] = p;
            }
        }
#else
        foreach (Touch t in Input.touches)
        {
            Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(t.position.x, t.position.y, z));
            float   f     = force * (int)touchMode / (Input.touchCount * .5f);
            for (int i = 0; i < particles.Length; i++)
            {
                FluidParticle p = particles[i];

                if (!p.enabled)
                {
                    continue;
                }

                float dist = (p.position - point).sqrMagnitude;
                if (dist <= maxDistance * maxDistance)
                {
                    p.AddForce((point - p.position).normalized * f);
                }

                particles[i] = p;
            }
        }
#endif
        fluid.SetParticles(particles, particles.Length);
    }
Ejemplo n.º 8
0
 void OnPostSolve(FluvioTimeStep timeStep)
 {
     fluid.GetParticles(ref particles);
 }
        void OnPreSolve(FluvioTimeStep timeStep)
        {
            if (m_Rigidbodies == null)
                return;

            int l = Mathf.Min(m_Rigidbodies.Length, fluid.particleCount);

            for(int i = 0; i < l; ++i)
            {
                // Get objects
                Rigidbody2D body = m_Rigidbodies[i];
                CircleCollider2D collider = m_Colliders[i];
                FluidParticle particle = fluid.GetParticle(i);

                // Assign properties
                body.gameObject.SetActive(particle.enabled);

                if (body.isKinematic) body.isKinematic = false;

                body.mass = fluid.particleMass * m_MassModifier;
                body.interpolation = m_RigidbodyInterpolation;

                collider.radius = fluid.smoothingDistance * m_ColliderSizeModifier;
                collider.sharedMaterial = m_PhysicMaterial;

                if (particle.lifetime < 1.0f)
                {
                    // Send physics information to particles (collisions)
                    particle.position = body.transform.position;
                    particle.velocity = body.velocity * timeStep.dt;

                    // Assign particle
                    fluid.SetParticle(ref particle, i);
                }
            }
        }
        void OnPostSolve(FluvioTimeStep timeStep)
        {
            if (m_Rigidbodies == null)
                return;

            int l = Mathf.Min(m_Rigidbodies.Length, fluid.particleCount);

            for(int i = 0; i < l; ++i)
            {
                // Get objects
                Rigidbody2D body = m_Rigidbodies[i];
                FluidParticle particle = fluid.GetParticle(i);

                if (body.isKinematic) body.isKinematic = false;
                body.transform.position = particle.position;
                body.velocity = particle.velocity * timeStep.inv_dt;
            }
        }
Ejemplo n.º 11
0
    void OnPostSolve(FluvioTimeStep timeStep)
    {
        if (sleep)
        {
            sleep = false;
            return;
        }

        fluid.GetParticles(ref particles);

        #if !(UNITY_IPHONE || UNITY_ANDROID) || UNITY_EDITOR
        bool doTouch = !requireClick ? true : (Input.GetMouseButton(0) || Input.GetMouseButton(1));
        if (doTouch)
        {
            if (Input.GetMouseButton(0) || !requireClick)
            {
                touchMode = invert ? TouchMode.Push : TouchMode.Pull;
            }
            else
            {
                touchMode = invert ? TouchMode.Pull : TouchMode.Push;
            }
            Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, z));
            float f = (int)touchMode * force;
            for(int i = 0; i < particles.Length; i++)
            {
                FluidParticle p = particles[i];

                if (!p.enabled)
                    continue;

                float dist = (p.position - point).sqrMagnitude;
                if (dist <= maxDistance *  maxDistance)
                {
                    p.AddForce((point - p.position).normalized * f);
                }

                particles[i] = p;
            }
        }
        #else
        foreach(Touch t in Input.touches)
        {
            Vector3 point = Camera.main.ScreenToWorldPoint(new Vector3(t.position.x, t.position.y, z));
            float f = force * (int)touchMode / (Input.touchCount * .5f);
            for(int i = 0; i < particles.Length; i++)
            {
                FluidParticle p = particles[i];

                if (!p.enabled)
                    continue;

                float dist = (p.position - point).sqrMagnitude;
                if (dist <=  maxDistance * maxDistance)
                {
                    p.AddForce((point - p.position).normalized * f);
                }

                particles[i] = p;
            }
        }
        #endif
        fluid.SetParticles(particles, particles.Length);
    }