Example #1
0
        public bool Decode(bool merge = false)
        {
            if (IsDecoded)
            {
                return(false);
            }

            Debug.Assert(ColorBitmap == null);
            Debug.Assert(AlphaBitmap == null);

            if (!ColorData.IsNullOrEmpty())
            {
                ColorBitmap = FileReader.Decode <Bitmap>("?" + nameof(ColorData), ColorData);
            }
            if (!AlphaData.IsNullOrEmpty())
            {
                AlphaBitmap = FileReader.Decode <Bitmap>("?" + nameof(AlphaData), AlphaData);
            }

            if (merge)
            {
                MergeChannels();
            }

            ColorData = null;
            AlphaData = null;

            var bitmap = ColorBitmap ?? AlphaBitmap;

            _width  = bitmap?.Width ?? 0;
            _height = bitmap?.Height ?? 0;

            return(true);
        }
Example #2
0
    public static AlphaData CreateAlphaData(AlphaRef colorRef, MonoBehaviour mb)
    {
        AlphaData ad = new AlphaData();

        ad.alphaRef    = colorRef;
        ad.originAlpha = ad.alphaRef.get();
        ad.targetAlpha = ad.originAlpha;
        ad.mb          = mb;
        ad.cor         = mb.StartCoroutine(ctrlAlpha(ad));
        return(ad);
    }
Example #3
0
 public static void AppearAlpha(AlphaData ad, float time)
 {
     ad.targetAlpha = ad.originAlpha;
     if (time == 0)
     {
         ad.alphaRef.set(ad.originAlpha);
     }
     else
     {
         ad.convertSpeed = ad.originAlpha / time;
     }
 }
Example #4
0
 private static IEnumerator ctrlAlpha(AlphaData ad)
 {
     while (true)
     {
         try {
             var nowAlpha = ad.alphaRef.get();
             if (nowAlpha != ad.targetAlpha)
             {
                 var deltaAlpha       = ad.convertSpeed * Time.unscaledDeltaTime;
                 var normedDeltaAlpha = Mathf.Clamp01(deltaAlpha / Mathf.Abs(nowAlpha - ad.targetAlpha));
                 ad.alphaRef.set(Mathf.Lerp(nowAlpha, ad.targetAlpha, normedDeltaAlpha));
             }
         }catch {
             yield break;
         }
         yield return(null);
     }
 }
Example #5
0
    private static Coroutine controllAlpha(AlphaData ad, float time, float targetAlpha)
    {
        var   alphaRef = ad.alphaRef;
        float nowAlpha = ad.alphaRef.get();
        var   realTime = time * Mathf.Abs(targetAlpha - nowAlpha) / ad.originAlpha;

        if (ad.cor != null)
        {
            ad.mb.StopCoroutine(ad.cor);
        }
        Timer timer = null;

        timer = Timer.CreateAUnscaledTimer(time, () => { if (ad.cor == timer.Coroutine)
                                                         {
                                                             ad.cor = null;
                                                         }
                                           }, ad.mb);
        timer.timerUpdateAction += () => {
            alphaRef.set(Mathf.Lerp(nowAlpha, targetAlpha, timer.Value));
        };
        ad.cor = timer.Coroutine;
        return(timer.Coroutine);
    }
Example #6
0
 public extern static void GetMatteData([MarshalAs(UnmanagedType.LPStr)] string sInput,
                                        [MarshalAs(UnmanagedType.LPStr)] string sOutput, [MarshalAs(UnmanagedType.LPStruct)] ref AlphaData alphaDatas);
Example #7
0
 public static void SetAlphaImmediately(AlphaData ad, float a)
 {
     ad.targetAlpha  = a * ad.originAlpha;
     ad.convertSpeed = 0;
     ad.alphaRef.set(ad.targetAlpha);
 }