當前位置: 首頁>>代碼示例>>C#>>正文


C# UnityEngine.Gradient類代碼示例

本文整理匯總了C#中UnityEngine.Gradient的典型用法代碼示例。如果您正苦於以下問題:C# Gradient類的具體用法?C# Gradient怎麽用?C# Gradient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Gradient類屬於UnityEngine命名空間,在下文中一共展示了Gradient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DrawGradientRect

        /// <summary>
        /// Draws gradient rectangle on texture
        /// </summary>t
        public static void DrawGradientRect(this Texture2D texture, int x, int y, int blockWidth, int blockHeight,
            Gradient gradient, Directions progressionDirection)
        {
            Func<int, int, Color> getColor;
            switch (progressionDirection)
            {
                case Directions.Left:
                    getColor = (_x, _y) => gradient.Evaluate(1 - (float) _x/(float) blockWidth);
                    break;
                case Directions.Right:
                    getColor = (_x, _y) => gradient.Evaluate((float) _x/(float) blockWidth);
                    break;
                case Directions.Down:
                    getColor = (_x, _y) => gradient.Evaluate(1 - (float) _y/(float) blockHeight);
                    break;
                case Directions.Up:
                    getColor = (_x, _y) => gradient.Evaluate((float) _y/(float) blockHeight);
                    break;
                default:
                    Debug.LogError("Not supported direction: " + progressionDirection);
                    return;
            }

            var colors = new Color[blockWidth*blockHeight];
            for (int _y = 0; _y < blockHeight; _y++)
            {
                for (int _x = 0; _x < blockWidth; _x++)
                {
                    colors[_x + _y*blockWidth] = getColor(_x, _y);
                }
            }
            texture.SetPixels(x, y, blockWidth, blockHeight, colors);
        }
開發者ID:rickoskam,項目名稱:ShepherdGame,代碼行數:36,代碼來源:TextureE.cs

示例2: DebugCreateTonsOfPresets

 public void DebugCreateTonsOfPresets()
 {
     int num = 150;
     string str = "Preset_";
     for (int i = 0; i < num; i++)
     {
         List<GradientColorKey> list = new List<GradientColorKey>();
         int num3 = Random.Range(3, 8);
         for (int j = 0; j < num3; j++)
         {
             list.Add(new GradientColorKey(new Color(Random.value, Random.value, Random.value), Random.value));
         }
         List<GradientAlphaKey> list2 = new List<GradientAlphaKey>();
         int num5 = Random.Range(3, 8);
         for (int k = 0; k < num5; k++)
         {
             list2.Add(new GradientAlphaKey(Random.value, Random.value));
         }
         Gradient presetObject = new Gradient {
             colorKeys = list.ToArray(),
             alphaKeys = list2.ToArray()
         };
         this.Add(presetObject, str + (i + 1));
     }
 }
開發者ID:CarlosHBC,項目名稱:UnityDecompiled,代碼行數:25,代碼來源:GradientPresetLibrary.cs

示例3: OnGUI

		internal static void OnGUI()
		{
			if(!initialized)
				GetPreferences();

			GUILayout.Label("Settings", z_GUI.headerTextStyle);

			rebuildNormals = EditorGUILayout.Toggle(gc_rebuildNormals, rebuildNormals);
			hideWireframe = EditorGUILayout.Toggle(gc_hideWireframe, hideWireframe);
			lockBrushSettings = EditorGUILayout.Toggle(gc_lockBrushSettings, lockBrushSettings);
			fullStrengthColor = EditorGUILayout.ColorField(gc_fullStrengthColor, fullStrengthColor);

			try
			{
				EditorGUI.BeginChangeCheck();
				
				object out_gradient = z_ReflectionUtil.Invoke(	null,
																typeof(EditorGUILayout),
																"GradientField",
																new System.Type[] { typeof(GUIContent), typeof(Gradient), typeof(GUILayoutOption[]) },
																BindingFlags.NonPublic | BindingFlags.Static,
																new object[] { gc_BrushGradient, gradient, null });
				gradient = (Gradient) out_gradient;

				if(EditorGUI.EndChangeCheck())
					SetPreferences();
			}
			catch
			{
				// internal editor gripe about something unimportant
			}
		}
開發者ID:alex-carlson,項目名稱:PixelitisGGJ,代碼行數:32,代碼來源:z_GlobalSettingsEditor.cs

示例4: DrawInternal

 private void DrawInternal(Rect rect, Gradient gradient)
 {
     if (gradient != null)
     {
         GradientEditor.DrawGradientWithBackground(rect, GradientPreviewCache.GetGradientPreview(gradient));
     }
 }
開發者ID:CarlosHBC,項目名稱:UnityDecompiled,代碼行數:7,代碼來源:GradientPresetLibrary.cs

示例5: Gradient

 /// <summary>
 /// Creates a gradient between two colors
 /// </summary>
 public static Gradient Gradient(Color from, Color to)
 {
     var g = new Gradient();
     g.SetKeys(new[] {new GradientColorKey(from, 0), new GradientColorKey(to, 1)},
         new[] {new GradientAlphaKey(from.a, 0), new GradientAlphaKey(to.a, 1)});
     return g;
 }
開發者ID:liamzebedee,項目名稱:hackagong2015,代碼行數:10,代碼來源:ColorE.cs

示例6: GenerateColorsEvenGradient

        /// <summary>
        /// Generate colors evely spaced out on a given gradient.
        /// </summary>
        /// <param name="colorCount"></param>
        /// <param name="gradient"></param>
        /// <param name="jitter"></param>
        /// <returns></returns>
        public static List<Color> GenerateColorsEvenGradient(
			int colorCount, 
			Gradient gradient, 
			float jitter)
        {
            return gradient.SampleEvenly(colorCount, jitter).ToList();
        }
開發者ID:MRGS,項目名稱:ArcadeRoyale,代碼行數:14,代碼來源:ProceduralPalette.cs

示例7: Deserialize

		public static bool Deserialize(string str, out Gradient gradient)
		{
			gradient = null;

			string[] arrays = str.Split('\n');

			if(arrays.Length < 2)
				return false;

			string[] colors_str = arrays[0].Split('|');
			string[] alphas_str = arrays[1].Split('|');

			if(colors_str.Length < 2 || alphas_str.Length < 2)
				return false;

			List<GradientColorKey> colors = new List<GradientColorKey>();
			List<GradientAlphaKey> alphas = new List<GradientAlphaKey>();

			foreach(string s in colors_str)
			{
				string[] key = s.Split('&');

				if(key.Length < 2)
					continue;

				Color value;
				float time;

				if(!TryParseColor(key[0], out value))
					continue;

				if(!float.TryParse(key[1], out time))
					continue;

				colors.Add( new GradientColorKey(value, time) );
			}

			foreach(string s in alphas_str)
			{
				string[] key = s.Split('&');

				if(key.Length < 2)
					continue;

				float alpha, time;

				if(!float.TryParse(key[0], out alpha))
					continue;
				if(!float.TryParse(key[1], out time))
					continue;

				alphas.Add( new GradientAlphaKey(alpha, time) );
			}

			gradient = new Gradient();
			gradient.SetKeys(colors.ToArray(), alphas.ToArray());

			return true;
		}
開發者ID:alex-carlson,項目名稱:PixelitisGGJ,代碼行數:59,代碼來源:z_GradientSerializer.cs

示例8: CreateGradientTexture

 public static Texture2D CreateGradientTexture(Gradient gradient)
 {
   Texture2D preview = new Texture2D(256, 2, TextureFormat.ARGB32, false);
   preview.wrapMode = TextureWrapMode.Clamp;
   preview.hideFlags = HideFlags.HideAndDontSave;
   GradientEditor.RefreshPreview(gradient, preview);
   return preview;
 }
開發者ID:BlakeTriana,項目名稱:unity-decompiled,代碼行數:8,代碼來源:GradientEditor.cs

示例9: RefreshPreview

 public static void RefreshPreview(Gradient gradient, Texture2D preview)
 {
   Color[] colors = new Color[512];
   for (int index = 0; index < 256; ++index)
     colors[index] = colors[index + 256] = gradient.Evaluate((float) index / 256f);
   preview.SetPixels(colors);
   preview.Apply();
 }
開發者ID:BlakeTriana,項目名稱:unity-decompiled,代碼行數:8,代碼來源:GradientEditor.cs

示例10: Init

 private void Init(Gradient newGradient)
 {
     this.m_Gradient = newGradient;
     if (this.m_GradientEditor != null)
     {
         this.m_GradientEditor.Init(newGradient, 0);
     }
     base.Repaint();
 }
開發者ID:randomize,項目名稱:VimConfig,代碼行數:9,代碼來源:GradientPicker.cs

示例11: Init

 public void Init(Gradient gradient, int numSteps)
 {
   this.m_Gradient = gradient;
   this.m_TextureDirty = true;
   this.m_NumSteps = numSteps;
   this.BuildArrays();
   if (this.m_RGBSwatches.Count <= 0)
     return;
   this.m_SelectedSwatch = this.m_RGBSwatches[0];
 }
開發者ID:BlakeTriana,項目名稱:unity-decompiled,代碼行數:10,代碼來源:GradientEditor.cs

示例12: constructor

	static public int constructor(IntPtr l) {
		try {
			UnityEngine.Gradient o;
			o=new UnityEngine.Gradient();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
開發者ID:xclouder,項目名稱:godbattle,代碼行數:12,代碼來源:Lua_UnityEngine_Gradient.cs

示例13: constructor

 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.Gradient o;
         o=new UnityEngine.Gradient();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
開發者ID:BobLChen,項目名稱:hugula,代碼行數:13,代碼來源:Lua_UnityEngine_Gradient.cs

示例14: Add

		public override void Add(object presetObject, string presetName)
		{
			Gradient gradient = presetObject as Gradient;
			if (gradient == null)
			{
				Debug.LogError("Wrong type used in GradientPresetLibrary");
				return;
			}
			Gradient gradient2 = new Gradient();
			gradient2.alphaKeys = gradient.alphaKeys;
			gradient2.colorKeys = gradient.colorKeys;
			this.m_Presets.Add(new GradientPresetLibrary.GradientPreset(gradient2, presetName));
		}
開發者ID:guozanhua,項目名稱:UnityDecompiled,代碼行數:13,代碼來源:GradientPresetLibrary.cs

示例15: Replace

		public override void Replace(int index, object newPresetObject)
		{
			Gradient gradient = newPresetObject as Gradient;
			if (gradient == null)
			{
				Debug.LogError("Wrong type used in GradientPresetLibrary");
				return;
			}
			Gradient gradient2 = new Gradient();
			gradient2.alphaKeys = gradient.alphaKeys;
			gradient2.colorKeys = gradient.colorKeys;
			this.m_Presets[index].gradient = gradient2;
		}
開發者ID:guozanhua,項目名稱:UnityDecompiled,代碼行數:13,代碼來源:GradientPresetLibrary.cs


注:本文中的UnityEngine.Gradient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。