/// <summary> /// Creates and positions a new inspector control for the passed property. /// </summary> /// <param name="inspectorProperty">Property to create an inspector control for.</param> /// <param name="currentValue">Current value of the observed property.</param> /// <param name="valueInherited">Indicates if the current value was inherited.</param> public IInspectorControl CreateInspectorControlFor( InspectorPropertyAttribute inspectorProperty, object currentValue, bool valueInherited) { // Create inspector control. IInspectorControl inspectorControl; if (inspectorProperty.IsList) { inspectorControl = new ListInspector(); } else if (inspectorProperty is InspectorBoolAttribute) { inspectorControl = new CheckBoxInspector(); } else if (inspectorProperty is InspectorStringAttribute) { inspectorControl = new TextBoxInspector(); } else if (inspectorProperty is InspectorFloatAttribute) { inspectorControl = new SingleUpDownInspector(); } else if (inspectorProperty is InspectorIntAttribute) { inspectorControl = new IntegerUpDownInspector(); } else if (inspectorProperty is InspectorEnumAttribute) { inspectorControl = new ComboBoxInspector(); } else if (inspectorProperty is InspectorBlueprintAttribute) { inspectorControl = null; } else if (inspectorProperty is InspectorDataAttribute) { inspectorControl = new DataInspector(); } else if (inspectorProperty is InspectorEntityAttribute) { inspectorControl = new EntityInspector(); } else { inspectorControl = null; } // Setup control. if (inspectorControl != null) { inspectorControl.Init(inspectorProperty, this.editorContext, this.localizationContext, currentValue, valueInherited); } return(inspectorControl); }
public override void PreviewInDataInspector() { #if UNITY_EDITOR Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in Objects) { if (!data.ContainsKey(obj.Prefab)) { data[obj.Prefab] = new PositionList(); } (data[obj.Prefab] as PositionList).Add(obj.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); #endif }
public static bool inspect(ref object data, Type type, string name, string path = "") { if (type == null) { type = data != null?data.GetType() : null; } DataInspector inspector = getInspector(type); bool changed = false; if (inspector != null) { path = path + "." + name; if (inspector.canFoldout()) { EditorGUILayout.BeginHorizontal(); Color color; bool changedColor = beginColor(path, out color); foldoutPath[path] = EditorGUILayout.Foldout(foldoutPath.ContainsKey(path) && foldoutPath[path], name); changed |= inspector.printHead(ref data, type); endColor(changedColor, color); EditorGUILayout.EndHorizontal(); if (foldoutPath[path]) { EditorGUI.indentLevel++; changed |= inspector.inspect(ref data, type, name, path); EditorGUI.indentLevel--; } } else { Color color; bool changedColor = beginColor(path, out color); changed |= inspector.inspect(ref data, type, name, path); endColor(changedColor, color); } if (changed) { changedPath.Add(path); } } return(changed); }
public override void PreviewInDataInspector() { #if UNITY_EDITOR Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in VSData) { if (IgnoredPrototypes.Contains(obj.VSID)) { continue; } if (!data.ContainsKey(obj.VSID)) { data[obj.VSID] = new PositionList(); } (data[obj.VSID] as PositionList).Add(obj.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); #endif }
public override void PreviewInDataInspector() { DataInspector.SetData(Heights); }
public override void PreviewInDataInspector() { DataInspector.SetData(SplatData.Select(x => (IDataInspectorProvider)x.Data).ToList(), SplatData.Select(x => (object)x.Wrapper).ToList()); }
public static MMTerrainLayer DrawExpandedGUI(TerrainWrapper wrapper, MMTerrainLayer layer) { bool isInScene = layer != null && string.IsNullOrEmpty(AssetDatabase.GetAssetPath(layer)); EditorGUILayout.BeginHorizontal(); layer = (MMTerrainLayer)EditorGUILayout.ObjectField(isInScene ? "Asset (In-Scene)" : "Asset", layer, typeof(MMTerrainLayer), true); if (layer != null && isInScene && GUILayout.Button(_saveContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { var path = EditorUtility.SaveFilePanel("Save Terrain Layer", "Assets", layer.name, "asset"); if (!string.IsNullOrEmpty(path)) { path = path.Substring(path.LastIndexOf("Assets/", StringComparison.Ordinal)); AssetDatabase.CreateAsset(layer, path); } } EditorGUILayout.EndHorizontal(); if (layer == null) { EditorGUILayout.HelpBox("Snapshot is Null!", MessageType.Error); if (GUILayout.Button("Create Snapshot", EditorStyles.toolbarButton)) { layer = ScriptableObject.CreateInstance <MMTerrainLayer>(); GUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndVertical(); return(layer); } EditorGUILayout.BeginHorizontal(); var previewContent = new GUIContent(GUIResources.EyeOpenIcon, "Preview"); EditorGUILayout.LabelField("Height:", layer.Heights != null ? string.Format("{0}x{1}", layer.Heights.Width, layer.Heights.Height) : "null"); if (layer.Heights != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { DataInspector.SetData(layer.Heights); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.Heights.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Splats", layer.SplatData != null ? string.Format("{0}", layer.SplatData.Count) : "null"); if (layer.SplatData != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { List <IDataInspectorProvider> data = new List <IDataInspectorProvider>(); List <object> context = new List <object>(); foreach (var keyValuePair in layer.SplatData) { data.Add(keyValuePair.Value); context.Add(keyValuePair.Key); } DataInspector.SetData(data, context); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.SplatData.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Details", layer.DetailData != null ? string.Format("{0}", layer.DetailData.Count) : "null"); if (layer.DetailData != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { List <IDataInspectorProvider> data = new List <IDataInspectorProvider>(); List <object> context = new List <object>(); foreach (var keyValuePair in layer.DetailData) { data.Add(keyValuePair.Value); context.Add(keyValuePair.Key); } DataInspector.SetData(data, context, true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.DetailData.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Trees", layer.Trees != null ? string.Format("{0}", layer.Trees.Count) : "null"); if (layer.Trees != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var tree in layer.Trees) { if (!data.ContainsKey(tree.Prototype)) { data[tree.Prototype] = new PositionList(); } (data[tree.Prototype] as PositionList).Add(tree.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.Trees.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("➥Removals", layer.TreeRemovals != null ? string.Format("{0}", layer.TreeRemovals.Count) : "null"); if (layer.TreeRemovals != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); var compoundTrees = wrapper.GetCompoundTrees(layer, false); compoundTrees.AddRange(layer.Trees); foreach (var guid in layer.TreeRemovals) { MadMapsTreeInstance tree = null; foreach (var t in compoundTrees) { if (t.Guid == guid) { tree = t; break; } } if (tree == null) { Debug.LogError("Couldn't find tree removal " + guid, layer); continue; } if (!data.ContainsKey(tree.Prototype)) { data[tree.Prototype] = new PositionList(); } (data[tree.Prototype] as PositionList).Add(tree.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.TreeRemovals.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); #if VEGETATION_STUDIO EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Vegetation Studio", layer.VSInstances != null ? string.Format("{0}", layer.VSInstances.Count) : "null"); if (layer.VSInstances != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var tree in layer.VSInstances) { if (!data.ContainsKey(tree.VSID)) { data[tree.VSID] = new PositionList(); } (data[tree.VSID] as PositionList).Add(tree.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.VSInstances.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("➥Removals", layer.VSRemovals != null ? string.Format("{0}", layer.VSRemovals.Count) : "null"); if (layer.VSRemovals != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); var compoundVS = wrapper.GetCompoundVegetationStudioData(layer, false); compoundVS.AddRange(layer.VSInstances); foreach (var guid in layer.VSRemovals) { VegetationStudioInstance vsInstance = null; foreach (var t in compoundVS) { if (t.Guid == guid) { vsInstance = t; break; } } if (vsInstance == null) { Debug.LogError("Couldn't find VS removal " + guid, layer); continue; } if (!data.ContainsKey(vsInstance.VSID)) { data[vsInstance.VSID] = new PositionList(); } (data[vsInstance.VSID] as PositionList).Add(vsInstance.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.VSRemovals.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); #endif EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Objects", layer.Objects != null ? string.Format("{0}", layer.Objects.Count) : "null"); if (layer.Objects != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in layer.Objects) { if (!data.ContainsKey(obj.Prefab)) { data[obj.Prefab] = new PositionList(); } (data[obj.Prefab] as PositionList).Add(obj.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.Objects.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("➥Removals", layer.ObjectRemovals != null ? string.Format("{0}", layer.ObjectRemovals.Count) : "null"); if (layer.ObjectRemovals != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); var compoundObjs = wrapper.GetCompoundObjects(layer, false); compoundObjs.AddRange(layer.Objects); foreach (var guid in layer.ObjectRemovals) { WorldStamps.PrefabObjectData?obj = null; foreach (var t in compoundObjs) { if (t.Guid == guid) { obj = t; break; } } if (obj == null) { Debug.LogError("Couldn't find object removal " + guid, layer); continue; } if (!data.ContainsKey(obj.Value.Prefab)) { data[obj.Value.Prefab] = new PositionList(); } (data[obj.Value.Prefab] as PositionList).Add(obj.Value.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.ObjectRemovals.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); bool hasStencil = layer.Stencil != null && layer.Stencil.Width > 0 && layer.Stencil.Height > 0;; EditorGUILayout.LabelField("Stencil" + (hasStencil ? "" : " (null)"), layer.Stencil != null ? string.Format("{0}", string.Format("{0}x{1}", layer.Stencil.Width, layer.Stencil.Height)) : "null"); GUI.enabled = hasStencil; if (GUILayout.Button(EditorGUIUtility.IconContent("Terrain Icon"), EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { TerrainWrapperGUI.StencilLayerDisplay = layer; } if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { DataInspector.SetData(layer.Stencil); } GUI.enabled = true; if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)) && EditorUtility.DisplayDialog("Really Clear?", "", "Yes", "No")) { layer.Stencil.Clear(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.LabelField("Layer Commands", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Capture From Terrain")) { if (EditorUtility.DisplayDialog(string.Format("Capture Layer {0} from current Terrain?", layer.name), "This will clear any existing data!", "Yes", "No")) { layer.SnapshotTerrain(wrapper.Terrain); EditorUtility.SetDirty(layer); EditorUtility.SetDirty(wrapper.Terrain); EditorSceneManager.MarkAllScenesDirty(); AssetDatabase.SaveAssets(); EditorUtility.SetDirty(layer); EditorGUIUtility.ExitGUI(); return(layer); } } EditorGUILayout.Space(); if (GUILayout.Button("Apply To Terrain")) { if (wrapper.PrepareApply()) { layer.WriteToTerrain(wrapper); wrapper.FinaliseApply(); EditorUtility.SetDirty(layer); EditorSceneManager.MarkAllScenesDirty(); EditorGUIUtility.ExitGUI(); return(layer); } } EditorGUILayout.Space(); if (GUILayout.Button("Clear Layer")) { if (EditorUtility.DisplayDialog(string.Format("Clear Layer {0}?", layer.name), "This will clear any existing data!", "Yes", "No")) { layer.Clear(wrapper); EditorUtility.SetDirty(wrapper.Terrain); EditorUtility.SetDirty(layer); EditorSceneManager.MarkAllScenesDirty(); EditorGUIUtility.ExitGUI(); return(layer); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); return(layer); }
public override void OnInspectorGUI() { if (IsPopout) { Wrapper = (TerrainWrapper)EditorGUILayout.ObjectField("Terrain Wrapper", Wrapper, typeof(TerrainWrapper), true); } if (Wrapper == null) { if (IsPopout) { return; } Wrapper = target as TerrainWrapper; return; } for (int i = Wrapper.Layers.Count - 1; i >= 0; i--) { if (!Wrapper.Layers[i]) { Wrapper.Layers.RemoveAt(i); } } _layerDrawer = _layerDrawer ?? new MMTerrainLayerDrawer(Wrapper); _splatsDrawer = _splatsDrawer ?? new TerrainSplatsDrawer(Wrapper); _detailsDrawer = _detailsDrawer ?? new TerrainDetailsDrawer(Wrapper); /*_layerDrawer = _layerDrawer ?? new MMTerrainLayerDrawer(Wrapper); * _splatsDrawer = _splatsDrawer ?? new TerrainSplatsDrawer(Wrapper); * _detailsDrawer = _detailsDrawer ?? new TerrainDetailsDrawer(Wrapper); * if(_tabs == null) * { * _tabs = new[] * { * new GUIContent("Layers") {image = EditorGUIUtility.FindTexture("Terrain Icon")}, * new GUIContent("Splats") {image = EditorGUIUtility.FindTexture("TerrainInspector.TerrainToolSplat")}, * new GUIContent("Details") {image = EditorGUIUtility.FindTexture("TerrainInspector.TerrainToolPlants")}, * new GUIContent("Info") {image = EditorGUIUtility.FindTexture("_Help")}, * }; * }*/ EditorGUILayout.BeginHorizontal(); CurrentTab = GUILayout.Toolbar(CurrentTab, _tabs, GUILayout.Height(20), GUILayout.Width(EditorGUIUtility.currentViewWidth - (IsPopout ? 12 : 40) - 26)); if (GUILayout.Button(new GUIContent(Wrapper.Locked ? GUIResources.LockedIcon : GUIResources.UnlockedIcon, "Lock Wrapper"), EditorStyles.label, GUILayout.Width(24), GUILayout.Height(24))) { Wrapper.Locked = !Wrapper.Locked; } if (!IsPopout && GUILayout.Button(new GUIContent(GUIResources.PopoutIcon, "Popout Inspector"), EditorStyles.label, GUILayout.Width(18), GUILayout.Height(18))) { var w = EditorWindow.GetWindow <TerrainWrapperEditorWindow>(); w.Wrapper = Wrapper; Selection.objects = new Object[0]; return; } EditorGUILayout.EndHorizontal(); GUILayout.Space(4); var currentTabTitle = _tabs[CurrentTab].text; if (currentTabTitle == "Layers") { if (Wrapper.Dirty) { EditorGUILayout.HelpBox("This Wrapper has unnaplied changes. Click \"Reapply All\" to apply them.", MessageType.Info); } _layerDrawer.List.DoLayoutList(); if (_layerDrawer.List.index >= 0 && Wrapper.Layers.Count > 0 && _layerDrawer.List.index < Wrapper.Layers.Count) { var selected = Wrapper.Layers[_layerDrawer.List.index]; Wrapper.Layers[_layerDrawer.List.index] = MMTerrainLayerDrawer.DrawExpandedGUI(Wrapper, selected); } else { EditorGUILayout.HelpBox("Select a Layer to see information about it here.", MessageType.Info); } EditorGUILayout.Space(); } else if (currentTabTitle == "Splats") { _splatsDrawer.List.DoLayoutList(); var splatProtos = new List <SplatPrototype>(Wrapper.Terrain.terrainData.splatPrototypes); foreach (var wrapper in Wrapper.SplatPrototypes) { if (wrapper == null) { continue; } var firstProto = wrapper.GetPrototype(); for (var i = splatProtos.Count - 1; i >= 0; --i) { var secondProto = splatProtos[i]; if (SplatPrototypeWrapper.SplatPrototypeComparer.StaticEquals(firstProto, secondProto)) { splatProtos.RemoveAt(i); continue; } } } if (splatProtos.Count > 0) { EditorGUILayout.BeginHorizontal("Box"); GUILayout.Label(string.Format("You have {0} splat{1} on your terrain that {2} not currently handled with Wrappers!", splatProtos.Count, splatProtos.Count > 1 ? "s" : string.Empty, splatProtos.Count > 1 ? "are" : "is"), GUILayout.MaxWidth(Screen.width - 100)); if (GUILayout.Button("Fix Now")) { var newSplats = MMTerrainLayerUtilities.ResolvePrototypes(Wrapper.Terrain.terrainData.splatPrototypes); Wrapper.SplatPrototypes = newSplats.Values.ToList(); GUIUtility.ExitGUI(); return; } EditorGUILayout.EndHorizontal(); } } else if (currentTabTitle == "Details") { _detailsDrawer.List.DoLayoutList(); var detailProtos = new List <DetailPrototype>(Wrapper.Terrain.terrainData.detailPrototypes); foreach (var wrapper in Wrapper.DetailPrototypes) { if (wrapper == null) { continue; } var firstProto = wrapper.GetPrototype(); for (var i = detailProtos.Count - 1; i >= 0; --i) { var secondProto = detailProtos[i]; if (DetailPrototypeWrapper.DetailPrototypeComparer.StaticEquals(firstProto, secondProto)) { detailProtos.RemoveAt(i); continue; } } } if (detailProtos.Count > 0) { EditorGUILayout.BeginHorizontal("Box"); GUILayout.Label(string.Format("You have {0} detail{1} on your terrain that {2} not currently handled with Wrappers!", detailProtos.Count, detailProtos.Count > 1 ? "s" : string.Empty, detailProtos.Count > 1 ? "are" : "is"), GUILayout.MaxWidth(Screen.width - 100)); if (GUILayout.Button("Fix Now")) { var newDetails = MMTerrainLayerUtilities.ResolvePrototypes(Wrapper.Terrain.terrainData.detailPrototypes); Wrapper.DetailPrototypes = newDetails.Values.ToList(); GUIUtility.ExitGUI(); return; } EditorGUILayout.EndHorizontal(); } } else if (currentTabTitle == "Info") { TerrainWrapper.ComputeShaders = EditorGUILayout.Toggle("Compute Shaders", TerrainWrapper.ComputeShaders); Wrapper.WriteHeights = EditorGUILayout.Toggle("Write Heights", Wrapper.WriteHeights); Wrapper.WriteSplats = EditorGUILayout.Toggle("Write Splats", Wrapper.WriteSplats); Wrapper.WriteTrees = EditorGUILayout.Toggle("Write Trees", Wrapper.WriteTrees); Wrapper.WriteDetails = EditorGUILayout.Toggle("Write Details", Wrapper.WriteDetails); Wrapper.WriteObjects = EditorGUILayout.Toggle("Write Objects", Wrapper.WriteObjects); #if VEGETATION_STUDIO Wrapper.WriteVegetationStudio = EditorGUILayout.Toggle("Write Vegetation Studio", Wrapper.WriteVegetationStudio); #endif EditorExtensions.Seperator(); var previewContent = new GUIContent(GUIResources.EyeOpenIcon, "Preview"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Compound Heights", Wrapper.CompoundTerrainData.Heights != null ? string.Format("{0}", string.Format("{0}x{1}", Wrapper.CompoundTerrainData.Heights.Width, Wrapper.CompoundTerrainData.Heights.Height)) : "null"); if (Wrapper.CompoundTerrainData.SplatData != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { DataInspector.SetData(Wrapper.CompoundTerrainData.Heights); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Compound Splats", Wrapper.CompoundTerrainData.SplatData != null ? string.Format("{0}", Wrapper.CompoundTerrainData.SplatData.Count) : "null"); if (Wrapper.CompoundTerrainData.SplatData != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { List <IDataInspectorProvider> data = new List <IDataInspectorProvider>(); List <object> context = new List <object>(); foreach (var keyValuePair in Wrapper.CompoundTerrainData.SplatData) { data.Add(keyValuePair.Value); context.Add(keyValuePair.Key); } DataInspector.SetData(data, context); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Compound Details", Wrapper.CompoundTerrainData.DetailData != null ? string.Format("{0}", Wrapper.CompoundTerrainData.DetailData.Count) : "null"); if (Wrapper.CompoundTerrainData.DetailData != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { List <IDataInspectorProvider> data = new List <IDataInspectorProvider>(); List <object> context = new List <object>(); foreach (var keyValuePair in Wrapper.CompoundTerrainData.DetailData) { data.Add(keyValuePair.Value); context.Add(keyValuePair.Key); } DataInspector.SetData(data, context, true); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Compound Objects: ", Wrapper.CompoundTerrainData.Objects.Count.ToString()); if (Wrapper.CompoundTerrainData.DetailData != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in Wrapper.CompoundTerrainData.Objects) { if (!data.ContainsKey(obj.Value.Data.Prefab)) { data[obj.Value.Data.Prefab] = new PositionList(); } (data[obj.Value.Data.Prefab] as PositionList).Add(obj.Value.Data.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Compound Trees: ", Wrapper.CompoundTerrainData.Trees.Count.ToString()); if (Wrapper.CompoundTerrainData.Trees != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in Wrapper.CompoundTerrainData.Trees) { if (!data.ContainsKey(obj.Value.Prototype)) { data[obj.Value.Prototype] = new PositionList(); } (data[obj.Value.Prototype] as PositionList).Add(obj.Value.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); #if VEGETATION_STUDIO EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Compound Vegetation Studio Data: ", Wrapper.CompoundTerrainData.VegetationStudio.Count.ToString()); if (Wrapper.CompoundTerrainData.VegetationStudio != null && GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in Wrapper.CompoundTerrainData.VegetationStudio) { if (!data.ContainsKey(obj.Value.VSID)) { data[obj.Value.VSID] = new PositionList(); } (data[obj.Value.VSID] as PositionList).Add(obj.Value.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } EditorGUILayout.EndHorizontal(); EditorExtensions.Seperator(); #endif } }
private void DoSingleInstanceInfo() { var stamp = target as WorldStamp; EditorGUILayout.BeginVertical("Box"); //FIX ISSUES if (stamp.Data.Objects.Exists(data => data.Prefab == null)) { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); EditorGUILayout.LabelField("Stamp contains objects with null prefabs"); if (GUILayout.Button("Fix")) { var prevCount = stamp.Data.Objects.Count; stamp.Data.Objects.RemoveAll(data => data.Prefab == null); Debug.Log(string.Format("Removed {0} missing prefabs from stamp {1}", (prevCount - stamp.Data.Objects.Count), stamp.name), stamp); EditorUtility.SetDirty(stamp); var prefab = GetPrefab(stamp); if (prefab != null) { EditorUtility.SetDirty(prefab); } } EditorGUILayout.EndHorizontal(); } if (stamp.Data.Objects.Exists(data => data.Scale.x < 0 || data.Scale.y < 0 || data.Scale.z < 0)) { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); EditorGUILayout.LabelField("Stamp contains objects with negative scales"); if (GUILayout.Button("Fix")) { for (int i = 0; i < stamp.Data.Objects.Count; i++) { var obj = stamp.Data.Objects[i]; obj.Scale = new Vector3(Mathf.Abs(stamp.Data.Objects[i].Scale.x), Mathf.Abs(stamp.Data.Objects[i].Scale.y), Mathf.Abs(stamp.Data.Objects[i].Scale.z)); stamp.Data.Objects[i] = obj; EditorUtility.SetDirty(stamp); var prefab = GetPrefab(stamp); if (prefab != null) { EditorUtility.SetDirty(prefab); } } } EditorGUILayout.EndHorizontal(); } if (stamp.Data.Objects.Exists(data => PrefabUtility.FindPrefabRoot(data.Prefab) != data.Prefab)) { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); EditorGUILayout.LabelField("Stamp contains references to prefab subobjects"); if (GUILayout.Button("Fix")) { for (int i = 0; i < stamp.Data.Objects.Count; i++) { var obj = stamp.Data.Objects[i]; obj.Prefab = PrefabUtility.FindPrefabRoot(obj.Prefab); stamp.Data.Objects[i] = obj; EditorUtility.SetDirty(stamp); var prefab = GetPrefab(stamp); if (prefab != null) { EditorUtility.SetDirty(prefab); } } } EditorGUILayout.EndHorizontal(); } #if VEGETATION_STUDIO if (stamp.Data.VSData.Exists(data => data.Package == null)) { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); EditorGUILayout.LabelField("Stamp contains Vegetation Studio with no package!"); if (GUILayout.Button("Remove")) { var prevCount = stamp.Data.VSData.Count; stamp.Data.VSData.RemoveAll(data => data.Package == null); Debug.Log(string.Format("Removed {0} invalid instances from stamp {1}", (prevCount - stamp.Data.VSData.Count), stamp.name), stamp); EditorUtility.SetDirty(stamp); var prefab = PrefabUtility.GetPrefabParent(stamp); if (prefab != null) { EditorUtility.SetDirty(prefab); } } EditorGUILayout.EndHorizontal(); } #endif // END FIX ISSUES var previewContent = new GUIContent(GUIResources.EyeOpenIcon, "Preview"); if (stamp == null) { return; } bool isPrefab = PrefabUtility.GetPrefabType(target) == PrefabType.Prefab; bool hasPrefab = PrefabUtility.GetPrefabObject(target); //var dc = stamp.GetComponentInChildren<WorldStampDataContainer>(); //bool isProxy = !isPrefab && dc.Redirect != null; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Heights", stamp.Data.Heights != null ? string.Format("{0}x{1}", stamp.Data.Heights.Width, stamp.Data.Heights.Height) : "null"); if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { DataInspector.SetData(stamp.Data.Heights, null, true); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Splats", stamp.Data.SplatData.Count.ToString()); if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { List <IDataInspectorProvider> data = new List <IDataInspectorProvider>(); List <object> context = new List <object>(); foreach (var splatData in stamp.Data.SplatData) { data.Add(splatData.Data); context.Add(splatData.Wrapper); } DataInspector.SetData(data, context); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Details", stamp.Data.DetailData.Count.ToString()); if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { List <IDataInspectorProvider> data = new List <IDataInspectorProvider>(); List <object> context = new List <object>(); foreach (var detailData in stamp.Data.DetailData) { data.Add(detailData.Data); context.Add(detailData.Wrapper); } DataInspector.SetData(data, context, true); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Trees", stamp.Data.Trees.Count.ToString()); if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var tree in stamp.Data.Trees) { if (!data.ContainsKey(tree.Prototype)) { data[tree.Prototype] = new PositionList(); } (data[tree.Prototype] as PositionList).Add(tree.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } EditorGUILayout.EndHorizontal(); #if VEGETATION_STUDIO EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Vegetation Studio Instances", stamp.Data.VSData.Count.ToString()); if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var tree in stamp.Data.VSData) { if (!data.ContainsKey(tree.VSID)) { data[tree.VSID] = new PositionList(); } (data[tree.VSID] as PositionList).Add(tree.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } EditorGUILayout.EndHorizontal(); #endif EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Objects", stamp.Data.Objects.Count.ToString()); if (GUILayout.Button(previewContent, EditorStyles.label, GUILayout.Width(20), GUILayout.Height(16))) { Dictionary <object, IDataInspectorProvider> data = new Dictionary <object, IDataInspectorProvider>(); foreach (var obj in stamp.Data.Objects) { if (!data.ContainsKey(obj.Prefab)) { data[obj.Prefab] = new PositionList(); } (data[obj.Prefab] as PositionList).Add(obj.Position); } DataInspector.SetData(data.Values.ToList(), data.Keys.ToList(), true); } EditorGUILayout.EndHorizontal(); GUI.enabled = !isPrefab; bool alreadyHasMaskInstance = !hasPrefab || (stamp.Mask != null && stamp.Mask.Count > 0); if (GUILayout.Button(_editingMask ? "Finish Editing" : alreadyHasMaskInstance ? "Edit Mask" : "Edit Mask (Create Instance)")) { if (_editingMask) { EditorUtility.SetDirty(stamp); if (_painter != null) { _painter.Destroy(); _painter = null; } } else if (stamp.Mask == null || stamp.Mask.Count == 0) { stamp.Data.Mask.OnBeforeSerialize(); stamp.Mask = JsonUtility.FromJson <WorldStampMask>(JsonUtility.ToJson(stamp.Data.Mask)); } _editingMask = !_editingMask; GUIUtility.ExitGUI(); return; } GUI.enabled = !_editingMask && hasPrefab && alreadyHasMaskInstance; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Revert Mask")) { if (EditorUtility.DisplayDialog("Really Revert Mask?", "You will lose all mask data you changed on this instance!", "Yes", "No")) { stamp.Mask = null; _editingMask = false; if (_painter != null) { _painter.Destroy(); _painter = null; } } GUIUtility.ExitGUI(); return; } if (GUILayout.Button("Write Mask To Prefab") && stamp.Mask != null) { stamp.Mask.OnBeforeSerialize(); stamp.Data.Mask = JsonUtility.FromJson <WorldStampMask>(JsonUtility.ToJson(stamp.Mask)); var prefab = GetPrefab(stamp); if (prefab != null) { Debug.Log("Wrote mask back to prefab"); EditorUtility.SetDirty(prefab); } stamp.Mask = null; _editingMask = false; if (_painter != null) { _painter.Destroy(); _painter = null; } GUIUtility.ExitGUI(); return; } EditorGUILayout.EndHorizontal(); GUI.enabled = true; EditorGUILayout.EndVertical(); }
public override void PreviewInDataInspector() { DataInspector.SetData(DetailData.Select(x => (IDataInspectorProvider)x.Data).ToList(), DetailData.Select(x => (object)x.Wrapper).ToList(), true); }