示例#1
0
	public static GradientWrapper GradientField(GradientWrapper gradient, params GUILayoutOption[] options) {
		if (gradient == null)
			gradient = new GradientWrapper();
		
		gradient.GradientData = s_miGradientField1.Invoke(null, new object[] { gradient.GradientData, options });
		
		return gradient;
	}
示例#2
0
	private void OnGUI(){
		Grad = GUIGradientField.GradientField("Gradient", Grad);

		// Gradient Options
		_invertGradient = EditorGUILayout.Toggle("Invert Gradient", _invertGradient);
		gradType = (GradType)EditorGUILayout.EnumPopup ("Gradient Type", gradType);
		
		// Gradient Falloff
		if(gradType == GradType.Radial){
				EditorGUILayout.BeginHorizontal();
				string falloff = EditorGUILayout.TextField("Falloff", _radialGradientFalloff.ToString());
				float.TryParse(falloff, out _radialGradientFalloff);
			GUILayout.EndHorizontal();
			_radialGradientFalloff = GUILayout.HorizontalSlider(_radialGradientFalloff, 0f, 100f);
		}
		
		// Output filename
		_fileName = EditorGUILayout.TextField("Output Filename",_fileName);

		// Gradient output size/aspect
		EditorGUILayout.BeginHorizontal();
			if(_fixedAspect){
				EditorGUILayout.PrefixLabel("Gradient Size");
			} else {
				EditorGUILayout.PrefixLabel("Gradient Width");
			}
			string gradSizeX = EditorGUILayout.TextField(_gradientSizeX.ToString());
			int.TryParse(gradSizeX, out _gradientSizeX);
			EditorGUILayout.PrefixLabel("px");
		EditorGUILayout.EndHorizontal();

		if(_fixedAspect){
			_gradientSizeY = _gradientSizeX;
		} else {
			string gradSizeY = EditorGUILayout.TextField("Gradient Height",_gradientSizeY.ToString());
			int.TryParse(gradSizeY, out _gradientSizeY);
		}

		// Set parammeters of gradient preview area
		GUILayoutOption[] guioptions = new GUILayoutOption[2];
		guioptions[0] = GUILayout.Height(Mathf.Clamp(_gradientSizeX,4,256));
		guioptions[1] = GUILayout.Width(Mathf.Clamp(_gradientSizeY,4,256));
		
		GUIStyle previewStyle = new GUIStyle();
		
		previewStyle.alignment = TextAnchor.MiddleCenter;
		
		// Load checker pattern for preview area
	
		string path = null;
		
		if(checker == null || checker.width != _gradientSizeX || checker.height != _gradientSizeY){
			
			if(Application.platform == RuntimePlatform.OSXEditor){
				path = Application.dataPath + "/GradientMaker/";
			} else if (Application.platform == RuntimePlatform.WindowsEditor){
				path = Application.dataPath + "\\GradientMaker\\";		
			} 
			
			byte[] rawChecker = File.ReadAllBytes(path + "Checker.png");
			checker = new Texture2D(_gradientSizeX, _gradientSizeY);
			checker.LoadImage(rawChecker);
		}
		
		// Draw prewiew area
		GUILayout.BeginHorizontal(checker, previewStyle, guioptions);
            GUILayout.Label(outTexture, guioptions);
		GUILayout.EndHorizontal();
		
		_overWriteExisting = EditorGUILayout.ToggleLeft("Overwrite existing", _overWriteExisting);
		
		GUILayout.BeginHorizontal();
			if(GUILayout.Button("Save Gradient")){
				InitProcessGradient(false);
			}
		GUILayout.EndHorizontal();
		
		// Update preview if nessisary
		if(GUI.changed){
			Undo.RecordObject(this, "Gradient Changed");
			InitProcessGradient(true);
			EditorUtility.SetDirty (this);
		}
	}
示例#3
0
	private static GradientWrapper CreateGradTexture(){
		// Create gradient object and assign generic starting colours	
		GradientWrapper.ColorKey[] gck = new GradientWrapper.ColorKey[2];
		gck[0] = new GradientWrapper.ColorKey(Color.black, 0f);
		gck[1] = new GradientWrapper.ColorKey(Color.white, 1f);
		GradientWrapper.AlphaKey[] gak = new GradientWrapper.AlphaKey[2];
		gak[0] = new GradientWrapper.AlphaKey(1f, 0f);
		gak[1] = new GradientWrapper.AlphaKey(1f, 1f);
		GradientWrapper gw = new GradientWrapper();
		gw = GUIGradientField.GradientField("Gradient", gw);
		gw.SetKeys(gck, gak);
		return gw;
	}