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); }
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 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(); } }