Beispiel #1
0
        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();
        }
Beispiel #2
0
        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));
                }
            }
        }
Beispiel #3
0
        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);
                        }
                    }
                }
            }
        }