private void DrawTab0() { var selectedGameObjects = Selection.GetFiltered <GameObject>(SelectionMode.ExcludePrefab); var selectedCount = 0; for (var i = 0; i < selectedGameObjects.Length; i++) { DrawSelection(selectedGameObjects[i].transform, ref selectedCount); } if (selectedCount == 0) { EditorGUILayout.HelpBox("Select any GameObjects in your Hierarchy or Scene that have a MeshFilter+MeshRenderer or SkinnedMeshRenderer.", MessageType.Info); } if (paintables.Count > 0) { EditorGUILayout.Separator(); for (var i = 0; i < paintables.Count; i++) { var paintable = paintables[i]; EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(Color.red); if (GUILayout.Button("Unlock", GUILayout.Width(50.0f)) == true) { paintable.Unlock(); paintables.Remove(paintable); } P3dHelper.EndColor(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField("", paintable.Root, typeof(GameObject), true); EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Edit", GUILayout.Width(40.0f)) == true) { tab = 1; paintableIndex = paintables.IndexOf(paintable); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); P3dHelper.BeginColor(Color.red); if (GUILayout.Button("Unlock All") == true) { for (var i = 0; i < paintables.Count; i++) { paintables[i].Unlock(); } paintables.Clear(); } P3dHelper.EndColor(); } }
private void UpdateClonersPanel() { for (var i = 0; i < scene.Cloners.Count; i++) { EditorGUILayout.Space(); var cloner = scene.Cloners[i]; var matRect = EditorGUILayout.BeginVertical(GetSelectableStyle(currentCloners.Contains(cloner), true)); P3dHelper.BeginLabelWidth(60.0f); if (currentCloners.Contains(cloner) == true) { EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(scene.MatNameValid(cloner.Name) == false); cloner.Name = EditorGUILayout.TextField(cloner.Name); P3dHelper.EndColor(); if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current cloner from the paint scene.", "Delete") == true) { scene.Cloners.RemoveAt(i--); P3dHelper.ClearControl(); } EditorGUILayout.EndHorizontal(); cloner.Position = EditorGUILayout.Vector3Field("Position", cloner.Position); cloner.Euler = EditorGUILayout.Vector3Field("Euler", cloner.Euler); cloner.Flip = EditorGUILayout.Toggle("Flip", cloner.Flip); } else { EditorGUILayout.LabelField(cloner.Name); } P3dHelper.EndLabelWidth(); EditorGUILayout.EndVertical(); if (Event.current.type == EventType.MouseDown && matRect.Contains(Event.current.mousePosition) == true) { if (currentCloners.Remove(cloner) == false) { currentCloners.Add(cloner); } P3dHelper.ClearControl(); } } if (GUILayout.Button("Add Cloner") == true) { currentCloners.Add(scene.AddCloner("New Cloner", Vector3.zero, Vector3.zero)); P3dHelper.ClearControl(); } }
public static void Draw(Rect position, SerializedProperty property) { var sPro = property.FindPropertyRelative("index"); var groupData = P3dGroupData_Editor.GetGroupData(sPro.intValue); P3dHelper.BeginColor(groupData == null); if (GUI.Button(position, groupData != null ? groupData.name : "MISSING: " + sPro.intValue, EditorStyles.popup) == true) { var menu = new GenericMenu(); var groupDatas = P3dGroupData_Editor.CachedInstances.OrderBy(d => d.Index); var editorCount = 0; foreach (var cachedGroupData in groupDatas) { if (cachedGroupData != null) { if (cachedGroupData.Index >= 0) { AddMenuItem(menu, cachedGroupData, sPro, cachedGroupData.Index); } else { editorCount++; } } } if (editorCount > 0) { menu.AddDisabledItem(new GUIContent("")); menu.AddDisabledItem(new GUIContent("EDITOR")); menu.AddDisabledItem(new GUIContent("")); foreach (var cachedGroupData in groupDatas) { if (cachedGroupData != null && cachedGroupData.Index < 0) { AddMenuItem(menu, cachedGroupData, sPro, cachedGroupData.Index); } } } menu.DropDown(position); } P3dHelper.EndColor(); }
private void DrawSceneFooter(P3dPaintableTexture[] paintableTextures) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUILayout.Separator(); EditorGUI.BeginDisabledGroup(CanLoadAll(paintableTextures) == false); if (GUILayout.Button("Load All", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true) { if (EditorUtility.DisplayDialog("Are you sure?", "This will replace all paintable textures with their currently exported texture state.", "ok") == true) { foreach (var paintableTexture in paintableTextures) { var outputTexture = paintableTexture.OutputTexture; if (outputTexture != null) { paintableTexture.Replace(outputTexture, Color.white); paintableTexture.Texture = outputTexture; } } } } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanExportAll(paintableTextures) == false); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Export All", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true) { if (EditorUtility.DisplayDialog("Are you sure?", "This will re-export all paintable textures in your scene.", "ok") == true) { foreach (var paintableTexture in paintableTextures) { if (paintableTexture.OutputTexture != null) { System.IO.File.WriteAllBytes(AssetDatabase.GUIDToAssetPath(paintableTexture.Output), paintableTexture.GetPngData()); } } AssetDatabase.Refresh(); } } P3dHelper.EndColor(); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); }
private bool DrawStarButton(Rect rect, bool starred) { var favouriteContent = new GUIContent(starred == true ? "★" : "✰", "Add/Remove this from the favourites list?"); if (buttonS == null) { buttonS = new GUIStyle(EditorStyles.miniButton); buttonS.fontSize = 15; buttonS.clipping = TextClipping.Overflow; } P3dHelper.BeginColor(starred == true ? Color.yellow : Color.white); var clicked = GUI.Button(rect, favouriteContent, buttonS); P3dHelper.EndColor(); return(clicked); }
private bool DrawAddableObject(GameObject go, Material[] materials) { var add = false; GUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(go, typeof(GameObject), true); EditorGUI.EndDisabledGroup(); tempTemplates.Clear(); for (var i = 0; i < materials.Length; i++) { var material = materials[i]; var templates = P3dShaderTemplate.GetTemplates(material != null ? material.shader : null); var slot = GetTempObj(go, i); if (templates.Contains(slot.Template) == false) { slot.Template = templates.Count > 0 ? templates[0] : null; } GUILayout.BeginVertical(EditorStyles.helpBox); P3dHelper.BeginLabelWidth(60.0f); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField("Material", material, typeof(Material), true); EditorGUI.EndDisabledGroup(); P3dHelper.BeginColor(slot.Template == null); P3dShaderTemplate_Editor.DrawDropdown("Template", material, slot); P3dHelper.EndColor(); P3dHelper.EndLabelWidth(); GUILayout.EndVertical(); tempTemplates.Add(slot.Template); } if (GUILayout.Button("Add") == true) { add = true; } GUILayout.EndVertical(); return(add); }
private void DrawSelection(Transform t, ref int selectedCount) { var renderer = t.GetComponent <Renderer>(); if (renderer != null) { var paintable = paintables.Find(p => p.Root == t.gameObject); if (paintable == null) { EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Lock", GUILayout.Width(40.0f)) == true) { paintable = new P3dWindowPaintable(t.gameObject); paintables.Add(paintable); } P3dHelper.EndColor(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField("", t.gameObject, typeof(GameObject), true); EditorGUI.EndDisabledGroup(); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Lock & Edit", GUILayout.Width(80.0f)) == true) { paintable = new P3dWindowPaintable(t.gameObject); paintables.Add(paintable); tab = 1; paintableIndex = paintables.IndexOf(paintable); } P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); selectedCount++; } } for (var i = 0; i < t.childCount; i++) { DrawSelection(t.GetChild(i), ref selectedCount); } }
private void DrawCurrentColor() { var rectT = P3dHelper.Reserve(); var rect = P3dHelper.Reserve(); var rectA = GetRect(rect, rect.xMin + 20, rect.xMax); var rectS = GetRect(rect, rect.xMin, rect.xMin + 18); var starred = P3dWindowData.Instance.FavouriteColors.Contains(P3dWindowData.Instance.CurrentColor); P3dHelper.BeginColor(Color.gray, P3dWindowData.Instance.CurrentBlend != P3dWindowData.ColorBlendType.None); if (GUI.Button(GetRect(rectT, rectT.xMin + rectT.width / 3 * 0, rectT.xMin + rectT.width / 3 * 1), blendContentA, EditorStyles.miniButtonLeft) == true) { P3dWindowData.Instance.CurrentBlend = P3dWindowData.ColorBlendType.None; } P3dHelper.EndColor(); P3dHelper.BeginColor(Color.gray, P3dWindowData.Instance.CurrentBlend != P3dWindowData.ColorBlendType.Replace); if (GUI.Button(GetRect(rectT, rectT.xMin + rectT.width / 3 * 1, rectT.xMin + rectT.width / 3 * 2), blendContentB, EditorStyles.miniButtonMid) == true) { P3dWindowData.Instance.CurrentBlend = P3dWindowData.ColorBlendType.Replace; } P3dHelper.EndColor(); P3dHelper.BeginColor(Color.gray, P3dWindowData.Instance.CurrentBlend != P3dWindowData.ColorBlendType.Multiply); if (GUI.Button(GetRect(rectT, rectT.xMin + rectT.width / 3 * 2, rectT.xMin + rectT.width / 3 * 3), blendContentC, EditorStyles.miniButtonRight) == true) { P3dWindowData.Instance.CurrentBlend = P3dWindowData.ColorBlendType.Multiply; } P3dHelper.EndColor(); P3dWindowData.Instance.CurrentColor = EditorGUI.ColorField(rectA, GUIContent.none, P3dWindowData.Instance.CurrentColor); if (DrawStarButton(rectS, starred) == true) { if (starred == true) { P3dWindowData.Instance.FavouriteColors.Remove(P3dWindowData.Instance.CurrentColor); } else { P3dWindowData.Instance.FavouriteColors.Add(P3dWindowData.Instance.CurrentColor); } } }
private void DrawFavouriteColors() { if (GUILayout.Button("Favourite Colors", expandFavouriteColors == true ? EditorStyles.toolbarDropDown : EditorStyles.toolbarButton) == true) { expandFavouriteColors = !expandFavouriteColors; } if (expandFavouriteColors == true) { var count = 0; for (var i = 0; i < P3dWindowData.Instance.FavouriteColors.Count; i++) { var color = P3dWindowData.Instance.FavouriteColors[i]; count++; var rect = P3dHelper.Reserve(); if (GUI.Button(rect, GUIContent.none) == true) { P3dWindowData.Instance.CurrentColor = color; } rect.xMin += 3; rect.xMax -= 3; rect.yMin += 3; rect.yMax -= 3; P3dHelper.BeginColor(color); GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture); P3dHelper.EndColor(); } if (count == 0) { EditorGUILayout.HelpBox("You have no favourite colors!", MessageType.Info); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var sObj = property.serializedObject; var sIdx = property.FindPropertyRelative("Index"); var sNam = property.FindPropertyRelative("Name"); var rectA = position; rectA.width = EditorGUIUtility.labelWidth; var rectB = position; rectB.xMin += EditorGUIUtility.labelWidth; rectB.width = 20; var rectC = position; rectC.xMin += EditorGUIUtility.labelWidth; rectC.xMin += 22; rectC.width -= 20; var rectD = position; rectD.xMin = rectD.xMax - 18; var component = property.serializedObject.targetObject as Component; var exists = false; // Invalid slot? if (component != null) { var material = P3dHelper.GetMaterial(component.gameObject, sIdx.intValue); if (material != null && P3dHelper.TexEnvNameExists(material.shader, sNam.stringValue) == false) { exists = true; } } P3dHelper.BeginColor(exists); { EditorGUI.LabelField(rectA, label); sIdx.intValue = Mathf.Clamp(EditorGUI.IntField(rectB, sIdx.intValue), 0, 99); sNam.stringValue = EditorGUI.TextField(rectC, sNam.stringValue); sObj.ApplyModifiedProperties(); // Draw menu if (GUI.Button(rectD, "", EditorStyles.popup) == true) { if (component != null) { var menu = new GenericMenu(); var renderer = component.GetComponent <Renderer>(); if (renderer != null) { var materials = renderer.sharedMaterials; if (materials.Length > 0) { for (var i = 0; i < materials.Length; i++) { var material = materials[i]; var materialName = i.ToString(); var matIndex = i; if (material != null) { materialName += " (" + material.name + ")"; var texEnvs = P3dHelper.GetTexEnvs(material.shader); if (texEnvs != null && texEnvs.Count > 0) { for (var j = 0; j < texEnvs.Count; j++) { var texName = texEnvs[j].Name; var texTitle = texName; var tex = material.GetTexture(texName); if (tex != null) { texTitle += " (" + tex.name + ")"; } else { texTitle += " (empty)"; } menu.AddItem(new GUIContent(materialName + "/" + texTitle), sIdx.intValue == matIndex && sNam.stringValue == texName, () => { sIdx.intValue = matIndex; sNam.stringValue = texName; sObj.ApplyModifiedProperties(); }); } } else { menu.AddDisabledItem(new GUIContent(materialName + "/This Material's shader has no textures!")); } } else { menu.AddDisabledItem(new GUIContent(materialName + "/This Material is null!")); } } } else { menu.AddDisabledItem(new GUIContent("This GameObject has no materials!")); } } else { menu.AddDisabledItem(new GUIContent("This GameObject has no renderer!")); } menu.DropDown(rectD); } } } P3dHelper.EndColor(); }
public static void Draw(SerializedProperty sSlots, Shader shader) { var removeIndex = -1; for (var i = 0; i < sSlots.arraySize; i++) { var sSlot = sSlots.GetArrayElementAtIndex(i); var sName = sSlot.FindPropertyRelative("Name"); var sAlias = sSlot.FindPropertyRelative("Alias"); EditorGUILayout.BeginVertical(EditorStyles.helpBox); P3dHelper.BeginColor(P3dHelper.TexEnvNameExists(shader, sName.stringValue) == false); { var rect = P3dHelper.Reserve(); var rectA = rect; rectA.width = EditorGUIUtility.labelWidth; var rectB = rect; rectB.xMin += EditorGUIUtility.labelWidth; rectB.xMax -= 20; var rectC = rect; rectC.xMin = rectC.xMax - 18; EditorGUI.LabelField(rectA, new GUIContent(sName.name, sName.tooltip)); EditorGUI.PropertyField(rectB, sName, GUIContent.none); // Draw menu if (GUI.Button(rectC, "", EditorStyles.popup) == true) { var menu = new GenericMenu(); var texEnvs = P3dHelper.GetTexEnvs(shader); if (texEnvs != null && texEnvs.Count > 0) { for (var j = 0; j < texEnvs.Count; j++) { var texName = texEnvs[j].Name; menu.AddItem(new GUIContent(texName), sName.stringValue == texName, () => { sName.stringValue = texName; sName.serializedObject.ApplyModifiedProperties(); }); } } else { menu.AddDisabledItem(new GUIContent("This shader has no textures!")); } menu.DropDown(rectC); } } P3dHelper.EndColor(); EditorGUILayout.PropertyField(sAlias); DrawElement(sSlot.FindPropertyRelative("WriteR")); DrawElement(sSlot.FindPropertyRelative("WriteG")); DrawElement(sSlot.FindPropertyRelative("WriteB")); DrawElement(sSlot.FindPropertyRelative("WriteA")); P3dHelper.BeginColor(Color.red); if (GUILayout.Button("Remove Slot") == true) { removeIndex = i; } P3dHelper.EndColor(); EditorGUILayout.EndVertical(); } EditorGUILayout.Separator(); if (GUILayout.Button("Add Slot") == true) { sSlots.arraySize += 1; } if (removeIndex >= 0) { sSlots.DeleteArrayElementAtIndex(removeIndex); } }
protected override void OnInspector() { EditorGUILayout.BeginHorizontal(); var newMesh = (Mesh)EditorGUILayout.ObjectField("Mesh", mesh, typeof(Mesh), false); if (GUILayout.Button("Refresh", EditorStyles.miniButton, GUILayout.Width(50)) == true) { ready = false; } EditorGUILayout.EndHorizontal(); if (newMesh != mesh) { ready = false; mesh = newMesh; } if (mesh != null) { if (mesh.subMeshCount != submeshNames.Length) { var submeshNamesList = new List <string>(); for (var i = 0; i < mesh.subMeshCount; i++) { submeshNamesList.Add(i.ToString()); } submeshNames = submeshNamesList.ToArray(); } EditorGUILayout.Separator(); var newSubmesh = EditorGUILayout.Popup("Submesh", submesh, submeshNames); var newCoord = EditorGUILayout.Popup("Coord", coord, new string[] { "UV0", "UV1", "UV2", "UV3" }); var newMode = EditorGUILayout.Popup("Mode", mode, new string[] { "Texcoord", "Triangles" }); if (mode == 1) // Triangles { EditorGUILayout.BeginHorizontal(); var newPitch = EditorGUILayout.FloatField("Pitch", pitch); var newYaw = EditorGUILayout.FloatField("Yaw", yaw); EditorGUILayout.EndHorizontal(); if (newPitch != pitch || newYaw != yaw) { ready = false; pitch = newPitch; yaw = newYaw; } } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Triangles", EditorStyles.boldLabel); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.BeginHorizontal(); EditorGUILayout.IntField("Total", triangleCount); P3dHelper.BeginColor(invalidCount > 0); EditorGUILayout.IntField("With No UV", invalidCount); P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(outsideCount > 0); EditorGUILayout.IntField("Out Of Bounds", outsideCount); P3dHelper.EndColor(); P3dHelper.BeginColor(partiallyCount > 0); EditorGUILayout.IntField("Partially Out Of Bounds", partiallyCount); P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(utilizationPercent < 40.0f); EditorGUILayout.FloatField("Utilization %", utilizationPercent); P3dHelper.EndColor(); P3dHelper.BeginColor(overlapPercent > 0); EditorGUILayout.FloatField("Overlap %", overlapPercent); P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); if (coord != newCoord || newSubmesh != submesh || newMode != mode || ready == false) { ready = true; coord = newCoord; submesh = newSubmesh; mode = newMode; listA.Clear(); listB.Clear(); ratioList.Clear(); mesh.GetTriangles(indices, submesh); mesh.GetVertices(positions); mesh.GetUVs(coord, coords); triangleCount = indices.Count / 3; invalidCount = 0; outsideCount = 0; partiallyCount = 0; overlapTex = P3dHelper.Destroy(overlapTex); utilizationPercent = 0.0f; overlapPercent = 0.0f; if (coords.Count > 0) { if (mode == 0) // Texcoord { BakeOverlap(); } var rot = Quaternion.Euler(pitch, yaw, 0.0f); var off = -mesh.bounds.center; var mul = P3dHelper.Reciprocal(mesh.bounds.size.magnitude); var half = Vector3.one * 0.5f; for (var i = 0; i < indices.Count; i += 3) { var positionA = positions[indices[i + 0]]; var positionB = positions[indices[i + 1]]; var positionC = positions[indices[i + 2]]; var coordA = coords[indices[i + 0]]; var coordB = coords[indices[i + 1]]; var coordC = coords[indices[i + 2]]; var outside = 0; outside += IsOutside(coordA) ? 1 : 0; outside += IsOutside(coordB) ? 1 : 0; outside += IsOutside(coordC) ? 1 : 0; var area = Vector3.Cross(coordA - coordB, coordA - coordC).sqrMagnitude; var invalid = area <= float.Epsilon; if (invalid == true) { invalidCount++; } if (outside == 3) { outsideCount++; } if (outside == 1 || outside == 2) { partiallyCount++; } if (mode == 0) // Texcoord { listA.Add(coordA); listA.Add(coordB); listA.Add(coordB); listA.Add(coordC); listA.Add(coordC); listA.Add(coordA); } if (mode == 1) // Triangles { positionA = half + rot * (off + positionA) * mul; positionB = half + rot * (off + positionB) * mul; positionC = half + rot * (off + positionC) * mul; positionA.z = positionB.z = positionC.z = 0.0f; listA.Add(positionA); listA.Add(positionB); listA.Add(positionB); listA.Add(positionC); listA.Add(positionC); listA.Add(positionA); if (invalid == true) { listB.Add(positionA); listB.Add(positionB); listB.Add(positionB); listB.Add(positionC); listB.Add(positionC); listB.Add(positionA); } } } } else { invalidCount = triangleCount; } arrayA = listA.ToArray(); arrayB = listB.ToArray(); } var rect = EditorGUILayout.BeginVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); var pos = rect.min; var siz = rect.size; GUI.Box(rect, ""); if (mode == 0 && overlapTex != null) // Texcoord { GUI.DrawTexture(rect, overlapTex); } Handles.BeginGUI(); if (listA.Count > 0) { for (var i = listA.Count - 1; i >= 0; i--) { var coord = listA[i]; coord.x = pos.x + siz.x * coord.x; coord.y = pos.y + siz.y * (1.0f - coord.y); arrayA[i] = coord; } Handles.DrawLines(arrayA); for (var i = listB.Count - 1; i >= 0; i--) { var coord = listB[i]; coord.x = pos.x + siz.x * coord.x; coord.y = pos.y + siz.y * (1.0f - coord.y); arrayB[i] = coord; } Handles.color = Color.red; Handles.DrawLines(arrayB); } Handles.EndGUI(); } else { EditorGUILayout.HelpBox("No Mesh Selected.\nTo select a mesh, click Analyze Mesh from the P3dPaintable component, or from the Mesh inspector context menu (gear icon at top right).", MessageType.Info); } }
public void OnGUI() { Technique = (P3dWindowBrushTechnique)EditorGUILayout.EnumPopup("Technique", Technique); EditorGUI.indentLevel++; switch (Technique) { case P3dWindowBrushTechnique.Replace: { P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group")); Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture; Color = EditorGUILayout.ColorField("Color", Color); Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f); } break; case P3dWindowBrushTechnique.Fill: { P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group")); BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode); Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture; Color = EditorGUILayout.ColorField("Color", Color); Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f); } break; case P3dWindowBrushTechnique.Sphere: { P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group")); BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode); Color = EditorGUILayout.ColorField("Color", Color); Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f); Radius = EditorGUILayout.FloatField("Radius", Radius); Hardness = EditorGUILayout.FloatField("Hardness", Hardness); } break; case P3dWindowBrushTechnique.Decal: { P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group")); BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode); P3dHelper.BeginColor(Texture == null); Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture; P3dHelper.EndColor(); if (BlendMode == P3dBlendMode.Replace) { P3dHelper.BeginColor(Shape == null); Shape = EditorGUI.ObjectField(P3dHelper.Reserve(), "Shape", Shape, typeof(Texture), false) as Texture; P3dHelper.EndColor(); } Color = EditorGUILayout.ColorField("Color", Color); Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f); Radius = EditorGUILayout.FloatField("Radius", Radius); Angle = EditorGUILayout.FloatField("Angle", Angle); Depth = EditorGUILayout.FloatField("Depth", Depth); Hardness = EditorGUILayout.FloatField("Hardness", Hardness); NormalFront = EditorGUILayout.Slider("Normal Front", NormalFront, 0.0f, 1.0f); NormalBack = EditorGUILayout.Slider("Normal Back", NormalBack, 0.0f, 1.0f); NormalRange = EditorGUILayout.Slider("Normal Range", NormalRange, 0.001f, 0.25f); } break; case P3dWindowBrushTechnique.SphereTriplanar: { P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group")); BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode); P3dHelper.BeginColor(Texture == null); Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture; P3dHelper.EndColor(); Strength = EditorGUILayout.FloatField("Strength", Strength); Tiling = EditorGUILayout.FloatField("Tiling", Tiling); Color = EditorGUILayout.ColorField("Color", Color); Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f); Radius = EditorGUILayout.FloatField("Radius", Radius); Hardness = EditorGUILayout.FloatField("Hardness", Hardness); } break; case P3dWindowBrushTechnique.SphereBlur: { P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group")); Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f); KernelSize = EditorGUILayout.Slider("Kernel Size", KernelSize, 0.0001f, 0.1f); Radius = EditorGUILayout.FloatField("Radius", Radius); Hardness = EditorGUILayout.FloatField("Hardness", Hardness); } break; } EditorGUI.indentLevel--; }
private void UpdateObjectsPanel() { if (Selection.gameObjects.Length == 0 && scene.Objs.Count == 0) { EditorGUILayout.HelpBox("Select a GameObject with a MesFilter+MeshRenderer or SkinnedMeshRenderer.", MessageType.Info); } // Mark tempObjs.ForEach(t => t.Dirty = true); foreach (var go in Selection.gameObjects) { if (scene.ObjExists(go.transform) == false) { var mf = go.GetComponent <MeshFilter>(); var mr = go.GetComponent <MeshRenderer>(); if (mf != null && mr != null && mf.sharedMesh != null) { GUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(go, typeof(GameObject), true); EditorGUI.EndDisabledGroup(); var materials = mr.sharedMaterials; tempTemplates.Clear(); for (var i = 0; i < materials.Length; i++) { var material = materials[i]; var templates = P3dShaderTemplate.GetTemplates(material != null ? material.shader : null); var slot = GetTempObj(go, i); if (templates.Contains(slot.Template) == false) { slot.Template = templates.Count > 0 ? templates[0] : null; } GUILayout.BeginVertical(EditorStyles.helpBox); P3dHelper.BeginLabelWidth(60.0f); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField("Material", material, typeof(Material), true); EditorGUI.EndDisabledGroup(); P3dHelper.BeginColor(slot.Template == null); P3dShaderTemplate_Editor.DrawDropdown("Template", material, slot); P3dHelper.EndColor(); P3dHelper.EndLabelWidth(); GUILayout.EndVertical(); tempTemplates.Add(slot.Template); } if (GUILayout.Button("Add") == true) { scene.AddObj(go.transform, mf.sharedMesh, go.transform.position, go.transform.rotation, go.transform.lossyScale, materials, tempTemplates.ToArray(), settings.DefaultTextureSize); } GUILayout.EndVertical(); } } } // Sweep tempObjs.RemoveAll(t => t.Dirty == true); EditorGUILayout.Separator(); for (var i = 0; i < scene.Objs.Count; i++) { if (i > 0) { EditorGUILayout.Space(); } var obj = scene.Objs[i]; var objRect = EditorGUILayout.BeginVertical(GetSelectableStyle(obj == currentObj, true)); P3dHelper.BeginLabelWidth(60.0f); if (obj == currentObj) { EditorGUILayout.BeginHorizontal(); obj.Name = EditorGUILayout.TextField(obj.Name); if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current layer from the paint window.", "Delete") == true) { scene.RemoveObj(obj); i--; P3dHelper.ClearControl(); } EditorGUILayout.EndHorizontal(); obj.Mesh = (Mesh)EditorGUILayout.ObjectField("Mesh", obj.Mesh, typeof(Mesh), true); obj.Paintable = EditorGUILayout.Toggle("Paintable", obj.Paintable); obj.Coord = (P3dCoord)EditorGUILayout.EnumPopup("Coord", obj.Coord); obj.Transform = (Transform)EditorGUILayout.ObjectField("Transform", obj.Transform, typeof(Transform), true); if (obj.Transform == null) { obj.Position = EditorGUILayout.Vector3Field("Position", obj.Position); EditorGUI.BeginChangeCheck(); var newRot = EditorGUILayout.Vector3Field("Rotation", obj.Rotation.eulerAngles); if (EditorGUI.EndChangeCheck() == true) { obj.Rotation = Quaternion.Euler(newRot); } obj.Scale = EditorGUILayout.Vector3Field("Scale", obj.Scale); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel); if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20)) == true) { obj.MatIds.Add(-1); } EditorGUILayout.EndHorizontal(); for (var j = 0; j < obj.MatIds.Count; j++) { var matId = obj.MatIds[j]; var rect = P3dHelper.Reserve(); rect.xMin += 10; var mat = scene.GetMat(matId); if (GUI.Button(rect, mat != null ? mat.Name : "", EditorStyles.popup) == true) { var menu = new GenericMenu(); for (var k = 0; k < scene.Mats.Count; k++) { var setObj = obj; var setIdx = j; var setMat = scene.Mats[k]; menu.AddItem(new GUIContent(setMat.Name), setMat == mat, () => setObj.MatIds[setIdx] = setMat.Id); } var remObj = obj; var remIdx = j; menu.AddSeparator(""); menu.AddItem(new GUIContent("Remove"), false, () => remObj.MatIds.RemoveAt(remIdx)); menu.DropDown(rect); } } } else { EditorGUILayout.LabelField(obj.Name); } P3dHelper.EndLabelWidth(); EditorGUILayout.EndVertical(); if (Event.current.type == EventType.MouseDown && objRect.Contains(Event.current.mousePosition) == true) { currentObj = obj; P3dHelper.ClearControl(); } } }
private void UpdateMaterialsPanel() { for (var i = 0; i < scene.Mats.Count; i++) { EditorGUILayout.Space(); var mat = scene.Mats[i]; var matRect = EditorGUILayout.BeginVertical(GetSelectableStyle(mat == currentMat, true)); P3dHelper.BeginLabelWidth(60.0f); if (mat == currentMat) { EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(scene.MatNameValid(mat.Name) == false); mat.Name = EditorGUILayout.TextField(mat.Name); P3dHelper.EndColor(); if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current material from the paint window.", "Delete") == true) { scene.Mats.RemoveAt(i--); P3dHelper.ClearControl(); } EditorGUILayout.EndHorizontal(); P3dHelper.BeginColor(mat.Material == null); mat.Material = (Material)EditorGUILayout.ObjectField("Material", mat.Material, typeof(Material), true); P3dHelper.EndColor(); P3dHelper.BeginColor(mat.Template == null); P3dShaderTemplate_Editor.DrawDropdown("Template", mat.Material, mat); P3dHelper.EndColor(); mat.Width = EditorGUILayout.IntField("Width", mat.Width); mat.Height = EditorGUILayout.IntField("Height", mat.Height); /* * foreach (var slot in mat.Slots) * { * EditorGUILayout.ObjectField(slot.Texture, typeof(Texture), false); * } * * foreach (var layer in mat.MergedLayers.Values) * { * if (layer.Layer != null) * { * EditorGUILayout.LabelField(layer.Layer.Name ); * } * EditorGUILayout.ObjectField(layer.Under, typeof(Texture), false); * EditorGUILayout.ObjectField(layer.Above, typeof(Texture), false); * EditorGUILayout.ObjectField(layer.Final, typeof(Texture), false); * } */ if (mat.SizesMatch == false && GUILayout.Button("Resize") == true) { mat.Resize(); } } else { EditorGUILayout.LabelField(mat.Name); } P3dHelper.EndLabelWidth(); EditorGUILayout.EndVertical(); if (Event.current.type == EventType.MouseDown && matRect.Contains(Event.current.mousePosition) == true) { currentMat = mat; P3dHelper.ClearControl(); } } if (GUILayout.Button("Add Material") == true) { currentMat = scene.AddMat(null, null, settings.DefaultTextureSize); P3dHelper.ClearControl(); } }
private Texture DrawObject(P3dWindowPaintableTexture paintableTexture, Material material, Texture texture) { if (texture != null) { var texture2D = texture as Texture2D; if (texture2D != null) { EditorGUI.BeginDisabledGroup(paintableTexture.Locked == true); if (material.hideFlags != HideFlags.None) { EditorGUILayout.HelpBox("This may be a shared texture, so you should clone it before modification.", MessageType.Warning); } if (GUILayout.Button("Clone") == true) { texture = texture2D = Instantiate(texture2D); } var textureImporter = P3dHelper.GetAssetImporter <TextureImporter>(texture); if (textureImporter != null) { if (textureImporter.isReadable == false) { EditorGUILayout.HelpBox("This texture's import settings does not have Read/Write Enabled.", MessageType.Error); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Enable Read/Write") == true) { textureImporter.isReadable = true; textureImporter.SaveAndReimport(); } P3dHelper.EndColor(); } } else { changeFormat = EditorGUILayout.Foldout(changeFormat, "Change Format"); if (changeFormat == true) { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.EnumPopup("Current Format", texture2D.format, EditorStyles.popup); EditorGUI.EndDisabledGroup(); changeFormatNew = (TextureFormat)EditorGUILayout.EnumPopup("New Format", changeFormatNew, EditorStyles.popup); P3dHelper.BeginColor(Color.green); if (GUI.Button(P3dHelper.Reserve(), "Change Format") == true) { var newTexture2D = new Texture2D(texture2D.width, texture2D.height, changeFormatNew, texture2D.mipmapCount > 0); changeFormatFailed = true; if (CanReadWrite(newTexture2D) == true) { var readableTexture = P3dHelper.GetReadableCopy(texture2D); var pixels = readableTexture.GetPixels32(); P3dHelper.Destroy(readableTexture); newTexture2D.name = texture2D.name; newTexture2D.SetPixels32(pixels); newTexture2D.Apply(); texture = texture2D = newTexture2D; changeFormat = false; changeFormatFailed = false; } } P3dHelper.EndColor(); if (changeFormatFailed == true) { EditorGUILayout.HelpBox("Failed to change format. This means the format you tried to use is not readable.", MessageType.Error); } } changeSize = EditorGUILayout.Foldout(changeSize, "Change Size"); if (changeSize == true) { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.IntField("Current Width", texture2D.width); EditorGUILayout.IntField("Current Height", texture2D.height); EditorGUI.EndDisabledGroup(); changeWidth = EditorGUILayout.IntField("Width", changeWidth); changeHeight = EditorGUILayout.IntField("Height", changeHeight); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Change Size") == true) { var newTexture2D = new Texture2D(changeWidth, changeHeight, texture2D.format, texture2D.mipmapCount > 0); changeSizeFailed = true; if (CanReadWrite(newTexture2D) == true) { var readableTexture = P3dHelper.GetReadableCopy(texture2D, TextureFormat.ARGB32, false, changeWidth, changeHeight); var pixels = readableTexture.GetPixels32(); P3dHelper.Destroy(readableTexture); newTexture2D.name = texture2D.name; newTexture2D.SetPixels32(pixels); newTexture2D.Apply(); texture = texture2D = newTexture2D; changeSize = false; changeSizeFailed = false; } } P3dHelper.EndColor(); if (changeSizeFailed == true) { EditorGUILayout.HelpBox("Failed to change size. Either the texture format is non-readable, or the texture size you chose is invalid.", MessageType.Error); } } } if (P3dHelper.IsAsset(material) == true && P3dHelper.IsAsset(texture) == false) { EditorGUILayout.HelpBox("This texture is stored in the scene, but it's applied to a material that's stored in an asset. You should save the texture as an asset too, otherwise it won't work properly.", MessageType.Warning); } if (P3dHelper.IsAsset(texture) == false) { if (GUILayout.Button("Save As Texture2D Asset") == true) { var path = P3dHelper.SaveDialog("Save Texture As Asset", "Assets", texture.name, "asset"); if (string.IsNullOrEmpty(path) == false) { AssetDatabase.CreateAsset(texture, path); } } if (GUILayout.Button("Save As Png Asset") == true) { var path = P3dHelper.SaveDialog("Export Texture", "Assets", texture.name, "png"); if (string.IsNullOrEmpty(path) == false) { P3dHelper.SaveTextureAsset(texture, path, true); var newTexture2D = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)); if (newTexture2D != null) { //ClearUndo(); var importer = P3dHelper.GetAssetImporter <TextureImporter>(newTexture2D); importer.isReadable = true; importer.textureCompression = TextureImporterCompression.Uncompressed; importer.filterMode = FilterMode.Trilinear; importer.anisoLevel = 8; importer.SaveAndReimport(); texture = texture2D = newTexture2D; P3dHelper.SetDirty(this); } } } } EditorGUI.EndDisabledGroup(); if (paintableTexture.Locked == true) { EditorGUILayout.BeginHorizontal(); P3dHelper.BeginColor(Color.red); if (GUILayout.Button("Unlock", GUILayout.Width(50.0f)) == true) { paintableTexture.Unlock(); } P3dHelper.EndColor(); P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture); paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel); if (GUILayout.Button("Paint", GUILayout.Width(45.0f)) == true) { tab = 2; } EditorGUILayout.EndHorizontal(); } else { var shared = false; if (TextureAlreadyLocked(texture) == true) { EditorGUILayout.HelpBox("This texture has already been locked in another object, so you don't need to lock it again. Paint will automatically be applied as long as you keep this texture expanded.", MessageType.Info); shared = true; } EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(shared); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Lock", GUILayout.Width(45.0f)) == true) { Repaint(); paintableTexture.Lock(this); } P3dHelper.EndColor(); P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture); EditorGUI.EndDisabledGroup(); paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel); P3dHelper.BeginColor(Color.green); EditorGUI.BeginDisabledGroup(shared); if (GUILayout.Button("Lock & Paint", GUILayout.Width(85.0f)) == true) { Repaint(); if (paintableTexture.Lock(this) == true) { tab = 2; } } EditorGUI.EndDisabledGroup(); P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); if (paintableTexture.LockFailed == true) { EditorGUILayout.HelpBox("Failed to lock texture.\nThis may be because the texture is not readable, if so, try cloning it.\nThis may be because the texture format is not readable, if so, try changing the format.", MessageType.Error); } } } else { EditorGUILayout.HelpBox("This texture isn't a Texture2D, so it cannot be painted.", MessageType.Error); } } else { EditorGUILayout.HelpBox("There is no texture in this slot. Either drag and drop one in, or create one below.", MessageType.Warning); createFormat = (TextureFormat)EditorGUILayout.EnumPopup("Format", createFormat); createMipMaps = EditorGUILayout.Toggle("Mip Maps", createMipMaps); createLinear = EditorGUILayout.Toggle("Linear", createLinear); createColor = EditorGUILayout.ColorField("Color", createColor); createWidth = EditorGUILayout.IntField("Width", createWidth); createHeight = EditorGUILayout.IntField("Height", createHeight); P3dHelper.BeginColor(Color.green); if (GUILayout.Button("Create") == true) { var newTexture2D = new Texture2D(createWidth, createHeight, createFormat, createMipMaps, createLinear); createFailed = true; if (CanReadWrite(newTexture2D) == true) { var pixels32 = new Color32[createWidth * createHeight]; var color32 = (Color32)createColor; for (var i = createWidth * createHeight - 1; i >= 0; i--) { pixels32[i] = color32; } newTexture2D.SetPixels32(pixels32); newTexture2D.Apply(); texture = newTexture2D; createFailed = false; } } P3dHelper.EndColor(); if (createFailed == true) { EditorGUILayout.HelpBox("Failed to create texture. This means the format you tried to use is not readable, or the size is invalid.", MessageType.Error); } } return(texture); }
protected override void OnInspector() { DrawNextPaint(); if (scene == null) { scene = CreateInstance <P3dScene>(); scene.name = "Temp"; scene.AddLayer(); scene.AddCloner("Mirror X", Vector3.zero, new Vector3(0.0f, 90.0f, 0.0f)); scene.AddCloner("Mirror Y", Vector3.zero, new Vector3(90.0f, 0.0f, 0.0f)); scene.AddCloner("Mirror Z", Vector3.zero, new Vector3(0.0f, 0.0f, 0.0f)); } if (previewDrawn == true && Event.current.type == EventType.Repaint) { previewDrawn = false; foreach (var layer in scene.Layers) { foreach (var images in layer.Images) { if (images.Preview != null) { images.Preview = P3dHelper.ReleaseRenderTexture(images.Preview); } } } pendingUpdate = true; } if (scene.Layers.Contains(currentLayer) == false) { currentLayer = null; if (scene.Layers.Count > 0) { currentLayer = scene.Layers[scene.Layers.Count - 1]; } } if (scene.Mats.Contains(currentMat) == false) { currentMat = null; if (scene.Mats.Count > 0) { currentMat = scene.Mats[scene.Mats.Count - 1]; } } if (scene.Objs.Contains(currentObj) == false) { currentObj = null; if (scene.Objs.Count > 0) { currentObj = scene.Objs[scene.Objs.Count - 1]; } } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginDisabledGroup(CanUndo == false); if (GUILayout.Button(new GUIContent("◄", "Undo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true) { Undo(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanRedo == false); if (GUILayout.Button(new GUIContent("►", "Redo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true) { Redo(); } EditorGUI.EndDisabledGroup(); if (GUILayout.Toggle(currentState == StateType.Scene, "Scene", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Scene; } if (GUILayout.Toggle(currentState == StateType.Paint, "Paint", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Paint; } if (GUILayout.Toggle(currentState == StateType.Layer, "Layer", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Layer; } if (GUILayout.Toggle(currentState == StateType.Config, "Config", EditorStyles.toolbarButton, GUILayout.Width(50)) == true) { currentState = StateType.Config; } EditorGUILayout.Separator(); EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false); if (GUILayout.Button("Save", EditorStyles.toolbarButton, GUILayout.Width(40)) == true) { HandleSave(); } EditorGUI.EndDisabledGroup(); P3dHelper.BeginColor(Color.green, P3dHelper.IsAsset(scene) == false); if (GUILayout.Button("Save As", EditorStyles.toolbarButton, GUILayout.Width(55)) == true) { HandleSaveAs(); } P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseUp) { dragId = -1; dragHandle = -1; } switch (currentState) { case StateType.Scene: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); objectsScrollPosition = GUILayout.BeginScrollView(objectsScrollPosition, GUILayout.Width(200)); UpdateObjectsPanel(); GUILayout.EndScrollView(); DrawViewport(); materialsScrollPosition = GUILayout.BeginScrollView(materialsScrollPosition, GUILayout.Width(200)); UpdateMaterialsPanel(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; case StateType.Paint: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); GUILayout.BeginVertical(GUILayout.Width(200)); brushesScrollPosition = GUILayout.BeginScrollView(brushesScrollPosition, GUILayout.ExpandWidth(true)); UpdatePaintBrushesPanel(200); GUILayout.EndScrollView(); dynamicsScrollPosition = GUILayout.BeginScrollView(dynamicsScrollPosition, GUILayout.ExpandWidth(true), GUILayout.Height(200)); UpdateDynamicsPanel(); GUILayout.EndScrollView(); GUILayout.EndVertical(); DrawViewport(); paintScrollPosition = GUILayout.BeginScrollView(paintScrollPosition, GUILayout.Width(200)); UpdatePaintMaterialsPanel(200); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; case StateType.Layer: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); repeatersScrollPosition = GUILayout.BeginScrollView(repeatersScrollPosition, GUILayout.Width(200)); UpdateClonersPanel(); GUILayout.EndScrollView(); DrawViewport(); layersScrollPosition = GUILayout.BeginScrollView(layersScrollPosition, GUILayout.Width(200)); UpdateLayersPanel(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; case StateType.Config: { GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true)); sceneScrollPosition = GUILayout.BeginScrollView(sceneScrollPosition, GUILayout.Width(200)); UpdateScenePanel(); GUILayout.EndScrollView(); DrawViewport(); settingsScrollPosition = GUILayout.BeginScrollView(settingsScrollPosition, GUILayout.Width(200)); UpdateSettingsPanel(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); } break; } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUILayout.LabelField("Undo state " + stateIndex + " of " + states.Count, GUILayout.Width(135)); EditorGUILayout.Separator(); scene = (P3dScene)EditorGUILayout.ObjectField(scene, typeof(P3dScene), false, GUILayout.MinWidth(50)); EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false); if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(55)) == true) { HandleExport(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); HandleDraw(); if (pendingUpdate == true && Event.current.type == EventType.Repaint) { pendingUpdate = false; UpdatePaintedMats(); } Repaint(); }
private void DrawTab2() { var brush = P3dWindowData.Instance.Brush; var presetBrushes = P3dWindowData.Instance.PresetBrushes; if (CanPaint() == true) { EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(CanUndo() == false); if (GUILayout.Button("Undo") == true) { Undo(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanWrite() == false); P3dHelper.BeginColor(NeedsWrite() == true ? Color.green : GUI.color); if (GUILayout.Button(new GUIContent("Write", "If you're editing imported textures (e.g. .png), then they must be written to apply changes.")) == true) { Write(); } P3dHelper.EndColor(); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanRedo() == false); if (GUILayout.Button("Redo") == true) { Redo(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("Before you can paint, you need to lock at least one texture.", MessageType.Info); } EditorGUILayout.Separator(); brush.OnGUI(); if (GUILayout.Button("Save As Preset") == true) { var exists = presetBrushes.Exists(p => p.Name == brush.Name); if (exists == false || EditorUtility.DisplayDialog("Overwrite brush?", "You already have a preset brush with this name. Overwrite it?", "Yes", "Cancel") == true) { var newPreset = presetBrushes.Find(p => p.Name == brush.Name); if (newPreset == null) { newPreset = new P3dWindowBrush(); presetBrushes.Add(newPreset); } brush.CopyTo(newPreset); } } EditorGUILayout.Separator(); brush.Tip0.OnGUI(); EditorGUILayout.Separator(); brush.Tip1.OnGUI(); EditorGUILayout.Separator(); brush.Tip2.OnGUI(); EditorGUILayout.Separator(); brush.Tip3.OnGUI(); if (presetBrushes.Count > 0) { EditorGUILayout.Separator(); EditorGUILayout.LabelField("Preset Brushes", EditorStyles.boldLabel); for (var i = 0; i < presetBrushes.Count; i++) { var presetBrush = presetBrushes[i]; EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(i <= 0); if (GUILayout.Button("▲", GUILayout.Width(20)) == true) { presetBrushes[i] = presetBrushes[i - 1]; presetBrushes[i - 1] = presetBrush; } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(i >= presetBrushes.Count - 1); if (GUILayout.Button("▼", GUILayout.Width(20)) == true) { presetBrushes[i] = presetBrushes[i + 1]; presetBrushes[i + 1] = presetBrush; } EditorGUI.EndDisabledGroup(); if (GUILayout.Button(presetBrush.Name) == true) { presetBrush.CopyTo(brush); } P3dHelper.BeginColor(Color.red); if (GUILayout.Button("X", GUILayout.Width(20)) == true) { if (P3dWindowData.Instance.ConfirmDeletePreset == false || EditorUtility.DisplayDialog("Delete preset brush?", "This cannot be undone.\n(You can disable this warning in the Extras tab)", "Delete", "Cancel") == true) { presetBrushes.RemoveAt(i); } } P3dHelper.EndColor(); EditorGUILayout.EndHorizontal(); } } }
protected void BeginError(bool error = true) { P3dHelper.BeginColor(error); }
private void DrawTab2() { if (cachedBrushes == null || GUILayout.Button("Refresh Brushes") == true) { cachedBrushes = AssetDatabase.FindAssets("t:GameObject").Select(guid => AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(guid)).GetComponent <P3dBrush>()).Where(b => b != null).ToList(); } cachedBrushes.RemoveAll(b => b == null); var categories = cachedBrushes.Select(b => b.Category).Where(c => string.IsNullOrEmpty(c) == false).Distinct(); if (CanPaint() == true) { EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(CanUndo() == false); if (GUILayout.Button("Undo") == true) { Undo(); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanWrite() == false); P3dHelper.BeginColor(NeedsWrite() == true ? Color.green : GUI.color); if (GUILayout.Button(new GUIContent("Write", "If you're editing imported textures (e.g. .png), then they must be written to apply changes.")) == true) { Write(); } P3dHelper.EndColor(); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(CanRedo() == false); if (GUILayout.Button("Redo") == true) { Redo(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); if (P3dWindowData.Instance.CurrentBrushesSafe.Count == 0) { EditorGUILayout.HelpBox("Before you can paint, you need to select a brush you want to paint with.", MessageType.Info); } } else { EditorGUILayout.HelpBox("Before you can paint, you need to lock at least one texture.", MessageType.Info); } EditorGUILayout.Separator(); EditorGUILayout.LabelField("Brush Color", EditorStyles.boldLabel); DrawCurrentColor(); EditorGUILayout.Separator(); DrawFavouriteColors(); DrawFavouriteBrushes(); DrawUncategorizedBrushes(cachedBrushes); foreach (var category in categories) { DrawBrushes(cachedBrushes, category); } }
protected override void OnInspector() { Draw("category"); EditorGUILayout.Separator(); foreach (var t in Targets) { if (P3dPaintMaterial.CachedInstances.Contains(t) == false) { P3dPaintMaterial.CachedInstances.Add(t); } } var sObj = serializedObject; var sSlots = sObj.FindProperty("slots"); Draw("style"); if (Any(t => t.Style == P3dPaintMaterial.StyleType.Decal)) { Draw("shape"); } BeginError(Any(t => t.Material == null)); Draw("material"); EndError(); BeginError(Any(t => t.Template == null)); P3dShaderTemplate_Editor.DrawDropdown("Template", Target.Material, Target, sObj.FindProperty("previewTemplate")); EndError(); var removeIndex = -1; for (var i = 0; i < sSlots.arraySize; i++) { var sSlot = sSlots.GetArrayElementAtIndex(i); var sGroup = sSlot.FindPropertyRelative("Group"); var sTexture = sSlot.FindPropertyRelative("Texture"); var sColor = sSlot.FindPropertyRelative("Color"); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.PropertyField(sGroup); EditorGUILayout.PropertyField(sTexture); EditorGUILayout.PropertyField(sColor); P3dHelper.BeginColor(Color.red); if (GUILayout.Button("Remove Slot") == true) { removeIndex = i; } P3dHelper.EndColor(); EditorGUILayout.EndVertical(); } EditorGUILayout.Separator(); if (GUILayout.Button("Add Slot") == true) { sSlots.arraySize += 1; var sSlot = sSlots.GetArrayElementAtIndex(sSlots.arraySize - 1); sSlot.FindPropertyRelative("Group").enumValueIndex = 0; sSlot.FindPropertyRelative("Texture").objectReferenceValue = null; sSlot.FindPropertyRelative("Color").colorValue = Color.white; } if (removeIndex >= 0) { sSlots.DeleteArrayElementAtIndex(removeIndex); } serializedObject.ApplyModifiedProperties(); }
private void DrawBrush(P3dBrush brush) { var rect = P3dHelper.Reserve(); var rectS = GetRect(rect, rect.xMin, rect.xMin + 18); var rectA = GetRect(rect, rect.xMin + 20, rect.xMax - 102); var rectB = GetRect(rect, rect.xMax - 100, rect.xMax - 40); var rectC = GetRect(rect, rect.xMax - 40, rect.xMax); var active = P3dWindowData.Instance.CurrentBrushesSafe.Contains(brush); var locked = Locked.Contains(brush); if (buttonL == null) { buttonL = new GUIStyle(EditorStyles.helpBox); //buttonL.fontSize = 15; buttonL.clipping = TextClipping.Overflow; } EditorGUI.BeginDisabledGroup(locked == true); P3dHelper.BeginColor(active == true ? Color.green : Color.white); if (GUI.Button(rectA, brush.name, buttonL) == true) { if (Event.current.control == true || Event.current.shift == true) { if (active == true) { P3dWindowData.Instance.CurrentBrushesSafe.Remove(brush); } else { P3dWindowData.Instance.CurrentBrushesSafe.Add(brush); } } else { var count = P3dWindowData.Instance.CurrentBrushesSafe.RemoveAll(b => Locked.Contains(b) == false); if (active == false || count > 1) { P3dWindowData.Instance.CurrentBrushesSafe.Add(brush); } } } P3dHelper.EndColor(); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(active == false); P3dHelper.BeginColor(locked == true ? Color.green : Color.white); if (GUI.Button(rectB, locked == true ? "Unlock" : "Lock", EditorStyles.miniButtonLeft) == true) { if (locked == true) { Locked.Remove(brush); } else { Locked.Add(brush); } } P3dHelper.EndColor(); EditorGUI.EndDisabledGroup(); if (GUI.Button(rectC, new GUIContent("Find", "Select the brush in the project?"), EditorStyles.miniButtonRight) == true) { Selection.activeObject = brush; EditorGUIUtility.PingObject(brush); } var starred = P3dWindowData.Instance.FavouriteBrushesSafe.Contains(brush) == true; if (DrawStarButton(rectS, starred) == true) { if (starred == true) { P3dWindowData.Instance.FavouriteBrushesSafe.Remove(brush); } else { P3dWindowData.Instance.FavouriteBrushesSafe.Add(brush); } } }