Example #1
0
        /// <summary>
        /// SplashObject构建完成后,自动显示闪屏
        /// </summary>
        /// <param name="splashInfo"></param>
        public SplashObject(SplashInfo splashInfo)
        {
            this.splashFormInfo = splashInfo;
            Thread splashThread = new Thread(new ParameterizedThreadStart(StartThread));

            splashThread.Start(this);
        }
    float lastSplashTime  = -1; //Init to -1 to make sure splash works on first frame.
    void OnTriggerEnter2D(Collider2D other)
    {
        if (Time.time - lastSplashTime < timeBetweenSplashes)
        {
            return;
        }
        lastSplashTime = Time.time;
        //Make sure it is a rigidbody
        if (!other.GetComponentInChildren <Rigidbody2D>())
        {
            return;
        }
        //Calculate local position of the hit
        Vector3 localSpace = other.transform.position - waterPlane.transform.position;
        float   xAxis      = localSpace.x / waterPlane.transform.localScale.x;
        //Calculate hit effect strength based on the rigidbody's speed
        float speed            = other.GetComponentInChildren <Rigidbody2D>().velocity.magnitude;
        float speedInterpValue = Mathf.InverseLerp(objSpeedMinHit, objSpeedMaxHit, speed);
        //Calculate the period of the effect based on the effect strength
        float resultantHitTime = Mathf.Lerp(hitMaximumTime, hitMinimumTime, speedInterpValue);

        //If next index of the array is used
        if (currentEmptyIndex >= splashes.Length || (currentEmptyIndex < splashes.Length && splashes[currentEmptyIndex].started))
        {
            currentEmptyIndex = FindSuitableArrayPosition();
        }
        //If all indexes are used (Look at the function FindSuitableArrayPosition down)
        if (currentEmptyIndex == -1)
        {
            currentEmptyIndex = 0;
            return;
        }

        //Set splash info values: start time, start and target value, period
        SplashInfo splashInfo = splashes[currentEmptyIndex];

        splashInfo.startValue  = 0;
        splashInfo.targetValue = speedInterpValue;
        splashInfo.startTime   = Time.time;
        splashInfo.started     = true;
        splashInfo.period      = resultantHitTime * hitEffectTimePercentage;
        //Set the position of the splash hit
        splashesVector[currentEmptyIndex].x = xAxis;
        //For the new model:
        //The z value will be used for shifting the wave. 0 is no shift and 1 is maximum shift
        splashesVector[currentEmptyIndex].z = 0;
        //Custom timer. Starts from 0 to make sure the wave always starts in the upward direction
        splashesVector[currentEmptyIndex].w = 0;
        // Update the array in the material
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        materialPropertyBlock.SetVectorArray(splashesVectorArrayName, splashesVector);
        waterPlane.SetPropertyBlock(materialPropertyBlock);
        currentEmptyIndex++;
    }
Example #3
0
        /// <summary>
        /// 取得正在加载窗体
        /// </summary>
        /// <returns>SplashObject</returns>
        public static SplashObject GetLoading()
        {
            SplashInfo si = new SplashInfo();

            si.BackImage   = SplashResource.Loading;
            si.ShowCaption = false;
            si.TopMost     = true;
            si.GradualMode = true;
            si.FormSize    = new Size(220, 120);
            return(new SplashObject(si));
        }
Example #4
0
        /// <summary>
        /// 取得程序启动闪屏
        /// </summary>
        /// <returns>SplashObject</returns>
        public static SplashObject GetSplash()
        {
            SplashInfo si = new SplashInfo();

            si.BackImage   = SplashResource.Splash;
            si.ShowCaption = false;
            si.TopMost     = true;
            si.GradualMode = true;
            si.FormSize    = new Size(989, 198);
            return(new SplashObject(si));
        }
    float lastSplashTime  = -1; // نعينه ب 1- لنتأكد أن الموجة تعمل من المرة الأولى
    void OnTriggerEnter2D(Collider2D other)
    {
        if (Time.time - lastSplashTime < timeBetweenSplashes)
        {
            return;
        }
        lastSplashTime = Time.time;
        //نتاكد أن الجسم الواقع في الماء يتحرك فيزيائيًا
        if (!other.GetComponentInChildren <Rigidbody2D>())
        {
            return;
        }
        //نحسب الموقع للاصطدام بالنسبة لمركز كائن الماء
        Vector3 localSpace = other.transform.position - waterPlane.transform.position;
        float   xAxis      = localSpace.x / waterPlane.transform.localScale.x;
        //نحسب قيمة التأثير بناءً على سرعة الجسم
        float speed            = other.GetComponentInChildren <Rigidbody2D>().velocity.magnitude;
        float speedInterpValue = Mathf.InverseLerp(objSpeedMinHit, objSpeedMaxHit, speed);
        //نحسب الزمن المطلوب بناءً على قوة التأثير
        float resultantHitTime = Mathf.Lerp(hitMaximumTime, hitMinimumTime, speedInterpValue);

        //إذا كانت الخانة التالية مستخدمة
        if (currentEmptyIndex >= splashes.Length || (currentEmptyIndex < splashes.Length && splashes[currentEmptyIndex].started))
        {
            currentEmptyIndex = FindSuitableArrayPosition();
        }
        //إذا لم يكن هناك أي خانة فارغة
        if (currentEmptyIndex == -1)
        {
            currentEmptyIndex = 0;
            return;
        }
        //تحديد قيم تأثير التموج من زمن وقوة ومدة
        SplashInfo splashInfo = splashes[currentEmptyIndex];

        splashInfo.startValue  = 0;
        splashInfo.targetValue = speedInterpValue;
        splashInfo.startTime   = Time.time;
        splashInfo.started     = true;
        splashInfo.period      = resultantHitTime * hitEffectTimePercentage;
        //تعيين موقع تأثير التموج الأصلي
        splashesVector[currentEmptyIndex].x = xAxis;
        //للنموذج الجديد:
        //مدى تمدد الموجة الحالي (أو إزاحتها عن الموقع الأصلي للاصطدام)
        splashesVector[currentEmptyIndex].z = 0;
        //الزمن الحالي. نبدأ بالصفر دائما ليبدأ شكل الموجة في ارتفاع
        splashesVector[currentEmptyIndex].w = 0;
        // Materialتحديث المصفوفة الموجودة في الـ
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        materialPropertyBlock.SetVectorArray(splashesVectorArrayName, splashesVector);
        waterPlane.SetPropertyBlock(materialPropertyBlock);
        currentEmptyIndex++;
    }
Example #6
0
 /// <summary>
 /// 取得正在加载窗体
 /// </summary>
 /// <returns>SplashObject</returns>
 public static SplashObject GetLoading()
 {
     SplashInfo si = new SplashInfo();
     si.BackImage = Utility.SplashResource.Loading;
     si.ShowCaption = true;
     si.TopMost = true;
     si.GradualMode = true;
     si.FormSize = new Size(220, 120);
     si.Text = "处理中";
     return new SplashObject(si);
 }
Example #7
0
        public void ShowInfo(SplashInfo tipo, params object[] args)
        {
            if (splashForm == null)
            {
                throw new ApplicationException("SplashScreen não está sendo exibida.");
            }

            if (!splashForm.InvokeRequired)
            {
                ((ISplash)SplashForm).ShowInfo(tipo, args);
            }
            else
            {
                splashForm.Invoke(new Action(() => ((ISplash)splashForm).ShowInfo(tipo, args)));
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        //Initialize default values
        splashes       = new SplashInfo[maxHits];
        splashesVector = new Vector4[maxHits];
        for (int i = 0; i < maxHits; i++)
        {
            splashes[i]       = new SplashInfo();
            splashesVector[i] = new Vector4();
        }
        //Set the array for the material
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        materialPropertyBlock.SetVectorArray(splashesVectorArrayName, splashesVector);
        waterPlane.SetPropertyBlock(materialPropertyBlock);
    }
    // Start is called before the first frame update
    void Start()
    {
        //نهيئ جميع المصفوفات بالقيم الافتراضية
        splashes       = new SplashInfo[maxHits];
        splashesVector = new Vector4[maxHits];
        for (int i = 0; i < maxHits; i++)
        {
            splashes[i]       = new SplashInfo();
            splashesVector[i] = new Vector4();
        }
        //Material نعين المصفوفة للـ
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        materialPropertyBlock.SetVectorArray(splashesVectorArrayName, splashesVector);
        waterPlane.SetPropertyBlock(materialPropertyBlock);
    }
Example #10
0
        public void ShowInfo(SplashInfo tipo, params object[] args)
        {
            switch (tipo)
            {
            case SplashInfo.Message:
                lblMessage.Text = args[0].ToString();
                break;

            case SplashInfo.Error:
                break;

            case SplashInfo.Progress:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tipo), tipo, null);
            }
        }
Example #11
0
 /// <summary>
 /// 取得程序启动闪屏
 /// </summary>
 /// <returns>SplashObject</returns>
 public static SplashObject GetSplash()
 {
     SplashInfo si = new SplashInfo();
     //try
     //{
     //    //提前读取好图片
     //    WebClient wc = new WebClient();
     //    Image image = Image.FromStream(wc.OpenRead(GlobalVal.PictureLoadingUrl));
     //    si.BackImage = image;
     //}
     //catch (Exception ex)
     //{
     //    si.BackImage = Utility.SplashResource.Splash;
     //    //GlobalVal.gloWebSerices.AddLog("加载图片[" + GlobalVal.gloPictureLoginUrl + "]失败." + ex.Message, "3", Dns.GetHostAddresses(Dns.GetHostName())[0].ToString());
     //}
     si.BackImage = Utility.SplashResource.Splash;
     si.ShowCaption = false;
     si.TopMost = true;
     si.GradualMode = false;
     si.FormSize = new Size(429, 319);
     return new SplashObject(si);
 }
 // Update is called once per frame
 void Update()
 {
     //For each splash
     for (int s = 0; s < splashes.Length; s++)
     {
         //If there is a splah happening through this item
         if (splashes[s].started)
         {
             SplashInfo splashInfo = splashes[s];
             ///Calculate interpolation value
             float t = (Time.time - splashInfo.startTime) / splashInfo.period;
             ///Current effect strength based on time
             float currVal = Mathf.Lerp(splashInfo.startValue, splashInfo.targetValue, t);
             ///Set the effect strength
             splashesVector[s].y = currVal;
             //For the new model:
             //We increment our custom timer.
             splashesVector[s].w = splashesVector[s].w + Time.deltaTime;
             //In this model we shift the wave manually in both directions
             //If we have started shifting
             if (splashInfo.shift)
             {
                 //If we aren't stopping the wave yet (i.e. we just started the shift)
                 if (!splashInfo.doReverse)
                 {
                     splashesVector[s].z = Mathf.Lerp(0, .5f, t);//We gradually shift the wave across half the distance (specified in the shader)
                 }
                 else//If we are stopping the wave
                 {
                     splashesVector[s].z = Mathf.Lerp(.5f, 1f, t);//Shift to the full distance
                 }
             }
             //Update the array in the material
             MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
             materialPropertyBlock.SetVectorArray(splashesVectorArrayName, splashesVector);
             waterPlane.SetPropertyBlock(materialPropertyBlock);
             if (t >= 1)
             {
                 //Settle the wave
                 if (!splashInfo.doReverse)
                 {
                     //We start shifting the wave in both directions, while keeping the wave strong
                     if (!splashInfo.shift)
                     {
                         splashInfo.shift = true;
                         //Use current time
                         splashInfo.startTime = Time.time;
                         //Use half the period
                         //(Note: this formula calculates the remaining period after the first stage, but it could be precalculated and stored)
                         splashInfo.period = 0.5f * splashInfo.period * (1 - hitEffectTimePercentage) / hitEffectTimePercentage;
                         //Keep the wave strong (same value)
                         splashInfo.startValue = splashInfo.targetValue;
                     }
                     //Here we stop the wave
                     else
                     {
                         //Set the time and reverse the startValue
                         splashInfo.startTime  = Time.time;
                         splashInfo.startValue = splashInfo.targetValue;
                         //Stop the wave by making the effect 0
                         splashInfo.targetValue = 0;
                         //We don't need to recalculate the period in this new model
                         //splashInfo.period = splashInfo.period / hitEffectTimePercentage * (1 - hitEffectTimePercentage);
                         splashInfo.doReverse = true;
                     }
                 }
                 else
                 {
                     //Wave finished. Reset the values.
                     splashInfo.started   = false;
                     splashInfo.doReverse = false;
                     splashInfo.shift     = false;
                 }
             }
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     //لكل تموج
     for (int s = 0; s < splashes.Length; s++)
     {
         //إذا كان التموج في هذه الخانة قد بدأ
         if (splashes[s].started)
         {
             SplashInfo splashInfo = splashes[s];
             //نحسب زمن الاستقراء الحالي
             float t = (Time.time - splashInfo.startTime) / splashInfo.period;
             //قيمة التأثير الحالية بناءً على الزمن
             float currVal = Mathf.Lerp(splashInfo.startValue, splashInfo.targetValue, t);
             //نعين قيمة التأثير
             splashesVector[s].y = currVal;
             //نزيد عداد الزمن الخاص
             splashesVector[s].w = splashesVector[s].w + Time.deltaTime;
             //في هذا النموذج نقوم بإزاحة الموجة إلى الجهتين يدويا
             //إذا بدأنا بالتحريك أو الإزاحة:
             if (splashInfo.move)
             {
                 //إذا لم نبدأ بتهدئة الموجة بعد (انظر الكود الأسفل)
                 if (!splashInfo.doReverse)
                 {
                     splashesVector[s].z = Mathf.Lerp(0, .5f, t);//نزيح الموجة تدريجيًا إلى منتصف المسافة (تحدد داخل الشيدر)
                 }
                 else//في حال بدأنا بتهدئة أو إيقاف الموجة
                 {
                     splashesVector[s].z = Mathf.Lerp(.5f, 1f, t);//نزيحها إلى آخر المسافة
                 }
             }
             // Materialتحديث المصفوفة الموجودة في الـ
             MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
             materialPropertyBlock.SetVectorArray(splashesVectorArrayName, splashesVector);
             waterPlane.SetPropertyBlock(materialPropertyBlock);
             if (t >= 1)
             {
                 //انتهاء المرحلة الأولى
                 if (!splashInfo.doReverse)
                 {
                     //نبدأ مرحلة تحريك الموجة في الاتجاهين
                     //نبقي على استقرار الموجة
                     if (!splashInfo.move)
                     {
                         splashInfo.move = true;
                         //نستخدم الزمن الحالي
                         splashInfo.startTime = Time.time;
                         //نستخدم نصف المدة المحددة
                         //(ملاحظة: المعادلة هذه تحسب الزمن المتبقي بعد انتهاء المرحلة الأولى . يمكن حساب و حفظ قيمته مسبقا بدلا من حسابه هنا)
                         splashInfo.period = 0.5f * splashInfo.period * (1 - hitEffectTimePercentage) / hitEffectTimePercentage;
                         //لا نريد أي تغيير في قوة الموجة في هذه المرحلة
                         splashInfo.startValue = splashInfo.targetValue;
                     }
                     //هنا نوقف الموجة.
                     else
                     {
                         //تحديد المتغيرات الحالية من الزمن وقيمة التأثير الحالية والمدة
                         splashInfo.startTime  = Time.time;
                         splashInfo.startValue = splashInfo.targetValue;
                         //نوقف الموجة عبر جعل قوة تأثيرها 0
                         splashInfo.targetValue = 0;
                         //لا حاجة لإعادة حساب الزمن المتبقي في النموذج الجديد
                         //splashInfo.period = splashInfo.period / hitEffectTimePercentage * (1 - hitEffectTimePercentage);
                         splashInfo.doReverse = true;
                     }
                 }
                 else
                 {
                     //نعيد تعيين المتغيرات بعد انتهاء الموجة
                     splashInfo.started   = false;
                     splashInfo.doReverse = false;
                     splashInfo.move      = false;
                 }
             }
         }
     }
 }
Example #14
0
 /// <summary>
 /// SplashObject构建完成后,自动显示闪屏
 /// </summary>
 /// <param name="splashInfo"></param>
 public SplashObject(SplashInfo splashInfo)
 {
     this.splashFormInfo = splashInfo;
     Thread splashThread = new Thread(new ParameterizedThreadStart(StartThread));
     splashThread.Start(this);
 }