コード例 #1
0
 void BlockFluid(bool bStatic)
 {
     if (m_collider && m_fluid)
     {
         Vector2[] points = m_collider.points;
         int       size   = points.Length;
         if (size >= 3)
         {
             Ray        ray1 = new Ray(transform.TransformPoint(points[0]), new Vector3(0, 0, 1));
             RaycastHit h1   = new RaycastHit();
             if (m_fluid.GetComponent <Collider>().Raycast(ray1, out h1, 10))
             {
                 Ray        ray2 = new Ray(transform.TransformPoint(points[1]), new Vector3(0, 0, 1));
                 RaycastHit h2   = new RaycastHit();
                 if (m_fluid.GetComponent <Collider>().Raycast(ray2, out h2, 10))
                 {
                     for (int i = 2; i < size; ++i)
                     {
                         Ray        ray3 = new Ray(transform.TransformPoint(points[i]), new Vector3(0, 0, 1));
                         RaycastHit h3   = new RaycastHit();
                         if (m_fluid.GetComponent <Collider>().Raycast(ray3, out h3, 10))
                         {
                             m_fluid.AddObstacleTriangle(h1.textureCoord, h2.textureCoord, h3.textureCoord, bStatic);
                         }
                         h2 = h3;
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
    void LateUpdate()
    {
        // if (Input.GetMouseButton(0) || m_alwaysOn)
        {
            Ray        ray     = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
            RaycastHit hitInfo = new RaycastHit();
            if (m_particlesArea.GetComponent <Collider>().Raycast(ray, out hitInfo, 100))
            {
                float fWidth  = m_particlesArea.GetComponent <Renderer>().bounds.extents.x * 2f;
                float fRadius = (m_particlesRadius * m_particlesArea.GetWidth()) / fWidth;
                m_particlesArea.AddParticles(hitInfo.textureCoord, fRadius, m_particlesStrength * Time.deltaTime);
            }
        }

        //if (Input.GetMouseButtonDown(1))
        {
            m_previousMousePosition = Input.mousePosition;
        }

        //if (Input.GetMouseButton(1) || m_alwaysOn)
        {
            Ray        ray     = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
            RaycastHit hitInfo = new RaycastHit();
            if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 100))
            {
                Vector3 direction = (Input.mousePosition - m_previousMousePosition + Vector3.up * 10f) * m_velocityStrength * Time.deltaTime;
                float   fWidth    = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
                float   fRadius   = (m_velocityRadius * m_fluid.GetWidth()) / fWidth;
                m_fluid.AddVelocity(hitInfo.textureCoord, direction, fRadius);
            }
            m_previousMousePosition = Input.mousePosition;
        }
    }
コード例 #3
0
ファイル: Blocker.cs プロジェクト: lloyar/The-Best-Match
    void LateUpdate()
    {
        Ray        ray     = new Ray(transform.position, new Vector3(0, 0, 1));
        RaycastHit hitInfo = new RaycastHit();

        if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
        {
            float fWidth = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
            //float fHeight = m_fluid.renderer.bounds.extents.z * 2f;
            float fRadius = (GetRadius() * m_fluid.GetWidth()) / fWidth;
            m_fluid.AddObstacleCircle(hitInfo.textureCoord, fRadius, false);
        }
    }
コード例 #4
0
 void LateUpdate()
 {
     if (m_fluid)
     {
         Vector3 currentPosition = transform.position;
         if (m_speed != Vector3.zero)
         {
             Ray        ray     = new Ray(currentPosition, new Vector3(0, 0, 1));
             RaycastHit hitInfo = new RaycastHit();
             if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
             {
                 float fWidth = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
                 //float fHeight = m_fluid.renderer.bounds.extents.z * 2f;
                 float fRadius = (GetRadius() * m_fluid.GetWidth()) / fWidth;
                 m_fluid.AddVelocity(hitInfo.textureCoord, -m_speed, fRadius);
             }
         }
     }
 }
コード例 #5
0
ファイル: DrawMeterial.cs プロジェクト: AtwoodDeng/lady
    Vector2 getFluidVelocity(Vector3 position)
    {
        Ray        ray     = Camera.main.ScreenPointToRay(position);
        RaycastHit hitInfo = new RaycastHit();

        if (fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
        {
            Vector2 simSize       = new Vector2(fluid.GetWidth(), fluid.GetHeight());
            Vector2 posInSimSpace = new Vector2(hitInfo.textureCoord.x * simSize.x, hitInfo.textureCoord.y * simSize.y);
            Vector2 velInSimSpace = fluid.GetVelocity((int)posInSimSpace.x, (int)posInSimSpace.y) * Time.deltaTime;
            return(velInSimSpace);
        }
        return(Vector2.zero);
    }
コード例 #6
0
 void LateUpdate()
 {
     if (m_fluid)
     {
         Ray        ray     = new Ray(gameObject.transform.position, new Vector3(0, 0, 1));
         RaycastHit hitInfo = new RaycastHit();
         if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
         {
             Vector2 simSize         = new Vector2(m_fluid.GetWidth(), m_fluid.GetHeight());
             Vector2 posInSimSpace   = new Vector2(hitInfo.textureCoord.x * simSize.x, hitInfo.textureCoord.y * simSize.y);
             Vector2 velInSimSpace   = m_fluid.GetVelocity((int)posInSimSpace.x, (int)posInSimSpace.y) * Time.deltaTime;
             Vector2 worldSize       = m_particleArea.GetRenderSize();
             Vector2 velInWorldSpace = new Vector2((velInSimSpace.x * worldSize.x) / simSize.x, (velInSimSpace.y * worldSize.y) / simSize.y);
             gameObject.transform.position = gameObject.transform.position + new Vector3(velInWorldSpace.x, velInWorldSpace.y, 0f);
         }
     }
 }
コード例 #7
0
    void LateUpdate()
    {
        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch      touch   = Input.GetTouch(i);
            Ray        ray     = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0f));
            RaycastHit hitInfo = new RaycastHit();
            if (m_particlesArea.GetComponent <Collider>().Raycast(ray, out hitInfo, 100))
            {
                float fWidth  = m_particlesArea.GetComponent <Renderer>().bounds.extents.x * 2f;
                float fRadius = (m_particlesRadius * m_particlesArea.GetWidth()) / fWidth;
                m_particlesArea.AddParticles(hitInfo.textureCoord, fRadius, m_particlesStrength * Time.deltaTime);

                if (touch.phase == TouchPhase.Moved)
                {
                    Vector3 direction = new Vector3(touch.deltaPosition.x, touch.deltaPosition.y) * m_velocityStrength * touch.deltaTime;
                    fWidth  = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
                    fRadius = (m_velocityRadius * m_fluid.GetWidth()) / fWidth;
                    m_fluid.AddVelocity(hitInfo.textureCoord, direction, fRadius);
                }
            }
        }
    }