コード例 #1
0
	public override void OnInspectorGUI ()
	{
		this.DrawDefaultInspector();
		
		EditorGUI.indentLevel = 0;
		foldout = EditorGUILayout.Foldout(foldout, "MeshRenderer AABB"); 
		if (foldout) {
			EditorGUI.indentLevel = 2;
			bool newIsAABBenabled = EditorGUILayout.Toggle(STR_ENABLE_MESH_AABB,isAABBenabled);
			if (newIsAABBenabled != isAABBenabled) {
				isAABBenabled = newIsAABBenabled;
				EditorUtility.SetDirty(this.target);
			}
			
			// Update status of the "Keep AABB visible" checkbox (optimize this by doing the search in storedSelections dictionary only when the current selection changes)
			if (currentSelection != this.target) {
				currentSelection = this.target as MeshRenderer;
				
				// check if this MeshRenderer is already in the stored selections
				isKeepAABBVisible = storedSelections.ContainsKey(currentSelection.GetInstanceID());
				//Debug.Log("isKeepAABBVisible current status: " + isKeepAABBVisible);
			}
			
			bool newIsKeepAABBVisible = EditorGUILayout.Toggle(STR_KEEP_VISIBLE, isKeepAABBVisible);
			if (newIsKeepAABBVisible != isKeepAABBVisible) {
				if (newIsKeepAABBVisible) {
					Transform[] multiSelection = Selection.transforms;
					
					// check for multi selection
					if (multiSelection.Length > 1) {
						for(int i = 0; i < multiSelection.Length; i++) {
							if ( multiSelection[i].renderer && !storedSelections.ContainsKey((multiSelection[i].renderer as MeshRenderer).GetInstanceID()) ) {
								storedSelections.Add( (multiSelection[i].renderer as MeshRenderer).GetInstanceID(), multiSelection[i].renderer as MeshRenderer);
							}
						}
					} else {
						// add current mesh renderer to the stored selection dictionary to have the AABB always highlighted
						storedSelections.Add(currentSelection.GetInstanceID(), currentSelection);
					}
				} else {
					Transform[] multiSelection = Selection.transforms;
					
					// check for multi-selection
					if (multiSelection.Length > 1) {
						for(int i = 0; i < multiSelection.Length; i++) {
							if ( multiSelection[i].renderer && storedSelections.ContainsKey((multiSelection[i].renderer as MeshRenderer).GetInstanceID()) ) {
								storedSelections.Remove( (multiSelection[i].renderer as MeshRenderer).GetInstanceID() );
							}
						}
					} else {
						// remove current MeshRenderer from the storeSelections dictionary
						storedSelections.Remove(currentSelection.GetInstanceID());
					}
				}
				EditorUtility.SetDirty(this.target);
				// force refresh of the "Keep AABB visible" checkbox status
				currentSelection = null;
			}
			
			// Display current AABB bounds size
			if (currentSelection != null) {
				EditorGUILayout.SelectableLabel("Bounds Size:" + currentSelection.bounds.size.ToString());
			}
							
			EditorGUILayout.Separator();
			GUILayout.BeginVertical();
				if ( GUILayout.Button(STR_CLEAR_ALL_VISIBLE, GUILayout.MaxWidth(200)) ) {
					storedSelections.Clear();
					cleanupList.Clear();
					EditorUtility.SetDirty(this.target);
				}
			GUILayout.EndVertical();
		}
	}