Error message

  • Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /users/fisherde/public_html/fishpitt.com/includes/common.inc).
  • Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in menu_set_active_trail() (line 2394 of /users/fisherde/public_html/fishpitt.com/includes/menu.inc).

Unity3D - Custom Inspector

  • Posted on: 6 November 2014
  • By: Ashley

Right now this isn't fully functional, what I mean is that it doesn't actually 'do' anything, it produces a custom inspector for me in Unity3D, and will serve as a learning piece for me, with the overall goal to create a Fishpitt inspector framework addon, allowing me to turnaround new addons, with fully customised inspectors very quickly.

If you're looking for something to copy/paste into your own inspector/project, this is not it, not in its current form. I've got a bunch of things referenced in this that I've defined elsewhere that obviously will not exist in your project. You will be able to chop away at it and get it to work however.

public override void OnInspectorGUI(){
	#region Defines
	FishpittTerrain FPTerrArr = (FishpittTerrain)target;
	FPStyle = new GUIStyle(EditorStyles.foldout);
 	FPTerrArr.Mod = EditorGUILayout.FloatField("Blending:", FPTerrArr.Mod);
	#endregion
 
	#region Initialisation
	InitFPStyle();
	#endregion
 
	#region Settings
	FPTerrArr.Terr = (Terrain)EditorGUILayout.ObjectField(FPTerrArr.Terr,typeof(Terrain));
	EditorGUILayout.BeginHorizontal();
	EditorGUILayout.LabelField("Texture Array Length");
	EditorGUILayout.IntField(FPTerrArr.TexDets.Length, GUILayout.MinWidth(40),GUILayout.MaxWidth(50));
	EditorGUILayout.EndHorizontal();
	#endregion
 
	#region Terrain Textures and Heights
	EditorGUILayout.BeginVertical();
	AllowEdits = EditorGUILayout.Foldout(AllowEdits,"Texture Names + Heights",FPStyle);
 
	#region Headings
	EditorGUILayout.BeginHorizontal();
	EditorGUILayout.LabelField("Texture Name",GUILayout.MinWidth(100));
	EditorGUILayout.LabelField("Height",GUILayout.MinWidth(40),GUILayout.MaxWidth(50));
	EditorGUILayout.LabelField("Texture",GUILayout.MinWidth(80));
	EditorGUILayout.EndHorizontal();
	#endregion
 
	if(AllowEdits){
		for(int i=0;i<FPTerrArr.TexDets.Length; i++){
			string fieldName = "Texture Name";
			if(FPTerrArr.TexDets[i].Name != "") {fieldName = "("+i+")"+FPTerrArr.TexDets[i].Name;}
			EditorGUILayout.BeginHorizontal();
 
			FPTerrArr.TexDets[i].Name = EditorGUILayout.TextField("",FPTerrArr.TexDets[i].Name,GUILayout.MinWidth(100));
			FPTerrArr.TexDets[i].Height = EditorGUILayout.FloatField(FPTerrArr.TexDets[i].Height,GUILayout.MinWidth(40),GUILayout.MaxWidth(50));
			FPTerrArr.TexDets[i].SecTexture = (Texture)EditorGUILayout.ObjectField(FPTerrArr.TexDets[i].SecTexture, typeof(Texture),GUILayout.MinWidth(80));
			EditorGUILayout.EndHorizontal();
 
		}
	}
	EditorGUILayout.EndVertical();
	if(GUILayout.Button ("Run Retex")){
		// This section is not working.
		Debug.Log("There are this many textures: " + FPTerrArr.Terr.terrainData.splatPrototypes.Length);
		for(int i=0; i<2; i++){
			FPTerrArr.Terr.Flush();
			Debug.Log ("Texture " + i + " " + FPTerrArr.TexDets[i].Name);
			FPSplat[i] = new SplatPrototype();
			FPSplat[i].texture = (Texture2D)FPTerrArr.TexDets[i].SecTexture;
			Debug.Log(FPSplat[i].texture.name);
			FPTerrArr.Terr.terrainData.splatPrototypes[i] = FPSplat[i];
		}
	}
	#endregion
}
Gallery: