Esempio n. 1
0
        public void Init(Transform parent)
        {
            transform.SetParent(parent);
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;

            m_currentWaterConfig = m_waterConfigs[0];
            //resetting the collision list
            if (colObjList != null)
            {
                colObjList.Clear();
            }
            StopAll();

            //calculate base length
            baseLen = (m_currentWaterConfig.WaterTip.position - m_currentWaterConfig.hinge.position).magnitude;
        }
Esempio n. 2
0
        public void Spray(Vector3 toPosition)
        {
            WaterConfig waterConfig = GetWaterConfig(toPosition.x);
            Vector3     worldPos    = Camera.main.ScreenToWorldPoint(toPosition);
            //scale it according to input position
            float newLen, newScale = 0.0f;

            //get required scale (due to input)
            newLen = (worldPos - waterConfig.hinge.position).magnitude;
            //min and max scale mentioned below are determined by trial and error
            newScale = Mathf.Clamp(newLen / baseLen, 0.13f, 1.3f);
            //apply new scale
            waterConfig.hinge.localScale = Vector3.one * newScale;

            if (!waterConfig.WaterPlayer.IsPlaying)
            {
                waterConfig.WaterPlayer.SetClip(0);
                waterConfig.WaterPlayer.Play();
            }
        }
Esempio n. 3
0
        WaterConfig GetWaterConfig(float xPos)
        {
            Vector2 bounds = m_currentWaterConfig.WaterXAxisBounds * Screen.width;

            if (xPos >= Math.Min(bounds.x, bounds.y) && xPos <= Math.Max(bounds.x, bounds.y))
            {
                return(m_currentWaterConfig);
            }
            else
            {
                for (int i = 0; i < m_waterConfigs.Length; i++)
                {
                    bounds = m_waterConfigs[i].WaterXAxisBounds * Screen.width;
                    if (xPos >= Math.Min(bounds.x, bounds.y) && xPos <= Math.Max(bounds.x, bounds.y))
                    {
                        m_currentWaterConfig.WaterPlayer.Stop();
                        m_currentWaterConfig = m_waterConfigs[i];
                        break;
                    }
                }
            }

            return(m_currentWaterConfig);
        }