void StateInspector.IEventsVisitor.Visit(StateInspector.PropertyChange propertyChange) { if (inspectedObjectsFilter(propertyChange)) { InspectedObject inspectedObject = EnsureInspectedObjectExists(propertyChange); if (propertyChange.ObjectType.PrimaryPropertyName != null && propertyChange.ObjectType.PrimaryPropertyName == propertyChange.PropertyName) { inspectedObject.Milestones.Add(new Timeline.ObjectLifetimeEvent( propertyChange.Trigger, string.Format("{0}.{1}->{2}", propertyChange.ObjectId, propertyChange.PropertyName, propertyChange.Value), propertyChange.ObjectId, ActivityEventType.Milestone )); } inspectedObject.Tags.UnionWith(propertyChange.Tags); if (propertyChange.ObjectType.DisplayIdPropertyName != null && inspectedObject.DisplayId == null && propertyChange.ObjectType.DisplayIdPropertyName == propertyChange.PropertyName) { if (propertyChange.ValueType == SI.ValueType.UserHash) { inspectedObject.DisplayId = string.Format("<uh>{0}</uh>", propertyChange.Value); } else { inspectedObject.DisplayId = propertyChange.Value; } inspectedObject.YieldPendingEvents(resultEvents); } } }
/// <inheritdoc/> protected internal override void Initialize() { if (InspectedObject == null) { LoadResource(); } if (InspectedObject != null) { int currentIndex = 0; SerializableObject serializableObject = new SerializableObject(InspectedObject.GetType(), InspectedObject); foreach (var field in serializableObject.Fields) { if (!field.Inspectable) { continue; } string path = field.Name; InspectableField inspectableField = InspectableField.CreateInspectable(this, field.Name, path, currentIndex, 0, new InspectableFieldLayout(Layout), field.GetProperty(), InspectableFieldStyle.Create(field)); inspectableFields.Add(inspectableField); isEmpty = false; currentIndex += inspectableField.GetNumLayoutElements(); } base.SetVisible(!isEmpty); } }
InspectedObject EnsureInspectedObjectExists(StateInspector.Event evt, bool forceOverwrite = false) { InspectedObject obj; if (forceOverwrite || !inspectedObjects.TryGetValue(evt.ObjectId, out obj)) { inspectedObjects[evt.ObjectId] = obj = new InspectedObject() { Id = evt.ObjectId, Tags = new HashSet <string>(evt.Tags) }; } return(obj); }
void StateInspector.IEventsVisitor.Visit(StateInspector.ObjectDeletion objectDeletion) { if (inspectedObjectsFilter(objectDeletion)) { InspectedObject inspectedObject = EnsureInspectedObjectExists(objectDeletion); inspectedObjects.Remove(objectDeletion.ObjectId); inspectedObject.YieldPendingEvents(resultEvents); resultEvents.Enqueue(inspectedObject.AddTags(new Timeline.ObjectLifetimeEvent( objectDeletion.Trigger, inspectedObject.MakeActivityDisplayName(), inspectedObject.Id, ActivityEventType.End))); } }
/// <inheritdoc/> protected internal override void Initialize() { if (InspectedObject == null) { LoadResource(); } if (InspectedObject != null) { SerializableObject serializableObject = new SerializableObject(InspectedObject.GetType(), InspectedObject); inspectableFields = InspectableField.CreateFields(serializableObject, this, "", 0, Layout); isEmpty = inspectableFields.Count > 0; base.SetVisible(!isEmpty); } }
//protected List<FieldInfo> Fields { get; set; } protected virtual void OnEnable() { InspectedObject = serializedObject.targetObject; InspectedType = InspectedObject.GetType(); Properties = InspectedType .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(property => property.DeclaringType == InspectedType) .Where(property => (property.SetMethod?.IsPublic).GetValueOrDefault()) .ToList(); //Fields = InspectedType // .GetFields(BindingFlags.Public | BindingFlags.Instance) // .Concat(InspectedType // .GetFields(BindingFlags.NonPublic | BindingFlags.Instance) // .Where(field => field.GetCustomAttribute<SerializeField>() != null) // ) // .Where(field => field.IsInitOnly == false) // .ToList(); }
void AddObject(UnityEngine.Object obj, Mesh mesh, GameObject gameObject) { if (inspectedObjects.Count >= 10) { return; } // https://docs.unity3d.com/ScriptReference/ModelImporter-isReadable.html // In the Unity editor access is always permitted when not in play mode. InspectedObject inspectedObj = new InspectedObject(); inspectedObj.obj = obj; inspectedObj.gameObject = gameObject; inspectedObj.mesh = mesh; inspectedObj.triangles = mesh.triangles; inspectedObj.vertices = mesh.vertices; if (inspectedObj.triangles != null) { inspectedObj.triangleCount = inspectedObj.triangles.Length / 3; } inspectedObj.vertexCount = inspectedObj.mesh.vertexCount; inspectedObj.subMeshCount = Mathf.Min(mesh.subMeshCount, 32); Vector2[] uvs; inspectedObj.hasUV[0] = (uvs = inspectedObj.mesh.uv) != null && uvs.Length > 0; inspectedObj.hasUV[1] = (uvs = inspectedObj.mesh.uv2) != null && uvs.Length > 0; inspectedObj.hasUV[2] = (uvs = inspectedObj.mesh.uv3) != null && uvs.Length > 0; inspectedObj.hasUV[3] = (uvs = inspectedObj.mesh.uv4) != null && uvs.Length > 0; Color32[] colors; inspectedObj.hasColors = (colors = inspectedObj.mesh.colors32) != null && colors.Length > 0; inspectedObjects.Add(inspectedObj); }
void OnGUI() { if (uvPreviewMaterial == null || simpleMaterial == null) { if (!LoadMaterials()) { return; } } for (int i = 0; i < inspectedObjects.Count; i++) { if (inspectedObjects[i].obj == null) { inspectedObjects.RemoveAt(i); i = 0; } } scroolPosition = EditorGUILayout.BeginScrollView(scroolPosition); EditorGUILayout.BeginVertical(); Rect logoRect = EditorGUILayout.GetControlRect(GUILayout.Height(56)); if (Event.current.type == EventType.Repaint) { Styles.logoFont.Draw(logoRect, "nTools|UVInspector", false, false, false, false); } // info box if (inspectedObjects.Count == 0) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Select object with mesh."); EditorGUILayout.EndVertical(); } else if (inspectedObjects.Count == 1) { StringBuilder sb = new StringBuilder(); InspectedObject obj = inspectedObjects[0]; EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Object: " + obj.obj.name + ", Mesh: " + obj.mesh.name); sb.AppendFormat("Submeshes: {0}", obj.subMeshCount); sb.AppendFormat(", Triangles: {0}", obj.triangleCount); sb.AppendFormat(", Vertices: {0}", obj.vertexCount); if (obj.hasColors) { sb.Append(", Colors"); } if (obj.hasUV[0]) { sb.Append(", UV1"); } if (obj.hasUV[1]) { sb.Append(", UV2"); } if (obj.hasUV[2]) { sb.Append(", UV3"); } if (obj.hasUV[3]) { sb.Append(", UV4"); } EditorGUILayout.LabelField(sb.ToString()); EditorGUILayout.EndVertical(); } else { StringBuilder sb = new StringBuilder(); for (int i = 0; i < inspectedObjects.Count; i++) { sb.Append(inspectedObjects[i].obj.name + "(" + inspectedObjects[i].mesh.name + "), "); } EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Multiple objects:"); EditorGUILayout.LabelField(sb.ToString(), EditorStyles.wordWrappedMiniLabel); EditorGUILayout.EndVertical(); } // UI Window float previewWindowHeight = Mathf.Min(EditorGUIUtility.currentViewWidth, this.position.height * 0.75f); Rect previewWindowRect = EditorGUILayout.GetControlRect(GUILayout.Height(previewWindowHeight)); UVPreviewWindow(previewWindowRect); if (inspectedObjects.Count == 1 && !inspectedObjects[0].hasUV[(int)previewUVSet]) { EditorGUI.LabelField(previewWindowRect, "Unassigned UV Channel", Styles.hudFont); } // Toolbar buttons EditorGUILayout.BeginHorizontal(); showGrid = GUILayout.Toggle(showGrid, "Grid", EditorStyles.toolbarButton); showVertexColors = GUILayout.Toggle(showVertexColors, "Vertex Colors", EditorStyles.toolbarButton); tilePreviewTexture = GUILayout.Toggle(tilePreviewTexture, "Texture Tiles", EditorStyles.toolbarButton); GUI.enabled = IsCanFrameSelected(); if (GUILayout.Toggle(false, "Frame View", EditorStyles.toolbarButton, GUILayout.MaxWidth(80))) { FrameSelected(); } GUI.enabled = true; if (GUILayout.Toggle(false, "Reset View", EditorStyles.toolbarButton, GUILayout.MaxWidth(80))) { previewWindowPosition = new Vector2(-0.5f, -0.5f); float aspect = Mathf.Min(viewportSize.x, viewportSize.y) / Mathf.Max(viewportSize.x, viewportSize.y, 1); previewWindowScale = 1.8f * aspect; } EditorGUILayout.EndHorizontal(); if (previewFoldout = nGUI.Foldout(previewFoldout, "Preview")) { ++EditorGUI.indentLevel; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("UV Channel"); previewUVSet = (UVSet)GUILayout.Toolbar((int)previewUVSet, Styles.uvSetNames, GUILayout.MaxWidth(160), GUILayout.Height(20)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Sub Mesh"); if (inspectedObjects.Count == 1) { SubMeshToolbar(inspectedObjects[0].mesh.subMeshCount); } else { GUI.enabled = false; GUI.Button(EditorGUILayout.GetControlRect(GUILayout.MaxWidth(160), GUILayout.Height(20)), inspectedObjects.Count > 1 ? "<Multyply Objects>" : "---"); GUI.enabled = true; } EditorGUILayout.EndHorizontal(); previewTextureSource = (PreviewTextureSource)EditorGUILayout.EnumPopup("Preview Texture", previewTextureSource); ++EditorGUI.indentLevel; if (previewTextureSource == PreviewTextureSource.Custom) { previewTextureTintColor = EditorGUILayout.ColorField("Image Tint", previewTextureTintColor); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Color Channel"); previewTextureChannels = (ColorChannels)GUILayout.Toolbar((int)previewTextureChannels, Styles.colorChannelsNames, GUILayout.MaxWidth(160), GUILayout.Height(20)); EditorGUILayout.EndHorizontal(); customPreviewTexture = (Texture2D)EditorGUILayout.ObjectField("Image", customPreviewTexture, typeof(Texture2D), false); } else if (previewTextureSource == PreviewTextureSource.FromMaterial) { PreviewTextureGUI(); previewTextureTintColor = EditorGUILayout.ColorField("Image Tint", previewTextureTintColor); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Color Channel"); previewTextureChannels = (ColorChannels)GUILayout.Toolbar((int)previewTextureChannels, Styles.colorChannelsNames, GUILayout.MaxWidth(160), GUILayout.Height(20)); EditorGUILayout.EndHorizontal(); } --EditorGUI.indentLevel; --EditorGUI.indentLevel; } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); }