123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using UnityEngine;
- namespace wf
- {
- public struct HSVColor
- {
- public HSVColor(Color color)
- {
- int num = (int)Mathf.Floor(255f * color.r);
- int num2 = (int)Mathf.Floor(255f * color.g);
- int num3 = (int)Mathf.Floor(255f * color.b);
- int num4 = Math.Max(Math.Max(num, num2), num3);
- int num5 = Math.Min(Math.Min(num, num2), num3);
- this.h = 0f;
- if (num4 == num5)
- {
- this.h = 0f;
- }
- else if (num4 == num)
- {
- this.h = (60f * (float)(num2 - num3) / (float)(num4 - num5) + 360f) % 360f;
- }
- else if (num4 == num2)
- {
- this.h = (float)(60 * (num3 - num) / (num4 - num5) + 120);
- }
- else if (num4 == num3)
- {
- this.h = (float)(60 * (num - num2) / (num4 - num5) + 240);
- }
- this.s = ((num4 != 0) ? ((float)(num4 - num5) / (float)num4) : 0f);
- this.v = (float)num4 / 255f;
- }
- public Color ToColor()
- {
- float num = Mathf.Max(0f, this.h);
- float num2 = Mathf.Clamp(this.s, 0f, 1f);
- float num3 = Mathf.Clamp(this.v, 0f, 1f);
- if (num2 == 0f)
- {
- return new Color(num3, num3, num3);
- }
- float r = 0f;
- float g = 0f;
- float b = 0f;
- float num4 = num % 360f / 60f;
- int num5 = (int)Math.Floor((double)num4);
- float num6 = num4 - (float)num5;
- float num7 = num3 * (1f - num2);
- float num8;
- if (num5 % 2 == 0)
- {
- num8 = num3 * (1f - (1f - num6) * num2);
- }
- else
- {
- num8 = num3 * (1f - num6 * num2);
- }
- switch (num5)
- {
- case 0:
- r = num3;
- g = num8;
- b = num7;
- break;
- case 1:
- r = num8;
- g = num3;
- b = num7;
- break;
- case 2:
- r = num7;
- g = num3;
- b = num8;
- break;
- case 3:
- r = num7;
- g = num8;
- b = num3;
- break;
- case 4:
- r = num8;
- g = num7;
- b = num3;
- break;
- case 5:
- r = num3;
- g = num7;
- b = num8;
- break;
- }
- return new Color(r, g, b);
- }
- public float h;
- public float s;
- public float v;
- }
- }
|