private void DrawLayerGroups() { var paintable = false; if (currentPaintMaterial != null) { foreach (var slot in currentPaintMaterial.Slots) { var layerGroup = slot.Group; EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField(P3dGroupData.GetGroupName(layerGroup, false)); var used = !excludedGroups.Contains(layerGroup); var isolate = isolatedGroups.Contains(layerGroup); EditorGUI.BeginDisabledGroup(isolate == false && isolatedGroups.Count > 0); used = EditorGUILayout.Toggle("Paint", used); EditorGUI.EndDisabledGroup(); isolate = EditorGUILayout.Toggle("Isolate", isolate); if (used == true) { excludedGroups.Remove(layerGroup); paintable = true; } else { excludedGroups.Add(layerGroup); } if (isolate == true) { isolatedGroups.Clear(); isolatedGroups.Add(layerGroup); paintable = true; } else { isolatedGroups.Remove(layerGroup); } EditorGUILayout.EndVertical(); } } if (layerGroups.Count == 0) { EditorGUILayout.HelpBox("You haven't added any paintable objects and/or materials in the Scene tab.", MessageType.Warning); } else if (paintable == false) { EditorGUILayout.HelpBox("You must enable painting for at least one texture.", MessageType.Warning); } }
public static void Draw(Rect position, SerializedProperty property) { var sPro = property.FindPropertyRelative("index"); var groupData = P3dGroupData.GetGroupData(sPro.intValue); P3dHelper.BeginColor(groupData == null); if (GUI.Button(position, groupData != null ? groupData.name : "", EditorStyles.popup) == true) { var menu = new GenericMenu(); var groupDatas = P3dGroupData.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 WriteThumbnailTex(RenderTexture texture, P3dPaintMaterial.Slot paintSlot, P3dShaderTemplate.Write write) { if (paintSlot != null) { P3dPaintReplace.Blit(texture, paintSlot.Texture, paintSlot.Color); } else { var group = P3dGroupData.GetGroupData(write.SourceGroup); if (group != null) { P3dPaintReplace.Blit(texture, group.DefaultTexture, group.DefaultColor); } else { P3dPaintReplace.Blit(texture, default(Texture), default(Color)); } } }
private static void AddMenuItem(GenericMenu menu, P3dGroupData groupData, SerializedProperty sPro, int index) { var content = new GUIContent(groupData.GetName(true)); menu.AddItem(content, sPro.intValue == index, () => { sPro.intValue = index; sPro.serializedObject.ApplyModifiedProperties(); }); }
public void UpdateMergedLayers(Layer currentLayer) { foreach (var mat in Mats) { foreach (var mergedLayer in mat.MergedLayers.Values) { mergedLayer.Dirty = true; if (mergedLayer.Layer != currentLayer) { mergedLayer.Clear(); mergedLayer.Layer = currentLayer; } } if (mat.Template != null) { foreach (var slot in mat.Template.Slots) { mat.UpdateMergedLayers(slot.WriteR.SourceGroup); mat.UpdateMergedLayers(slot.WriteG.SourceGroup); mat.UpdateMergedLayers(slot.WriteB.SourceGroup); mat.UpdateMergedLayers(slot.WriteA.SourceGroup); } } foreach (var pair in mat.MergedLayers) { var group = pair.Key; var mergedLayer = pair.Value; if (mergedLayer.Dirty == true) { mergedLayer.Clear(); } else { var currentLayerIndex = Layers.IndexOf(currentLayer); if (mergedLayer.Under == null) { mergedLayer.Under = P3dHelper.GetRenderTexture(mat.Desc); var groupData = P3dGroupData.GetGroupData(group); if (groupData != null) { P3dPaintReplace.Blit(mergedLayer.Under, groupData.DefaultTexture, groupData.DefaultColor); } else { P3dPaintReplace.Blit(mergedLayer.Under, default(Texture), default(Color)); } for (var i = 0; i < currentLayerIndex; i++) { TryBlendInto(ref mergedLayer.Under, Layers[i], mat.Id, group); } } // Last layer? if (currentLayerIndex == Layers.Count - 1) { if (mergedLayer.Above != null) { mergedLayer.Above = P3dHelper.ReleaseRenderTexture(mergedLayer.Above); } } else { if (mergedLayer.Above == null) { mergedLayer.Above = P3dHelper.GetRenderTexture(mat.Desc); P3dPaintReplace.Blit(mergedLayer.Above, default(Texture), default(Color)); for (var i = currentLayerIndex + 1; i < Layers.Count; i++) { TryBlendInto(ref mergedLayer.Above, Layers[i], mat.Id, group); } } } if (mergedLayer.Final == null) { mergedLayer.Final = P3dHelper.GetRenderTexture(mat.Desc); } P3dPaintReplace.Blit(mergedLayer.Final, mergedLayer.Under, Color.white); TryBlendInto(ref mergedLayer.Final, currentLayer, mat.Id, group); if (mergedLayer.Above != null) { mergedLayer.Final = P3dPaintFill.Blit(mergedLayer.Final, P3dBlendMode.AlphaBlend, mergedLayer.Above, Color.white, 1.0f, 0.0f); } } } } }