Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        /// <summary>This method applies the preset components to the specified paintable.
        /// NOTE: This is editor-only.</summary>
        public void AddTo(P3dPaintable paintable, Shader shader, int index, int stateLimit)
        {
#if UNITY_EDITOR
            if (addMaterialCloner == true && HasMaterialCloner(paintable, index) == false)
            {
                var newMaterialCloner = paintable.gameObject.AddComponent <P3dMaterialCloner>();

                newMaterialCloner.Index = index;
            }

            foreach (var paintableTexture in GetComponents <P3dPaintableTexture>())
            {
                if (UnityEditorInternal.ComponentUtility.CopyComponent(paintableTexture) == true)
                {
                    var newPaintableTexture = paintable.gameObject.AddComponent <P3dPaintableTexture>();

                    UnityEditorInternal.ComponentUtility.PasteComponentValues(newPaintableTexture);

                    var groupData = P3dGroupData_Editor.GetGroupData(paintableTexture.Group);
                    var slotName  = newPaintableTexture.Slot.Name;

                    if (groupData != null && shader != null)
                    {
                        groupData.TryGetShaderSlotName(shader.name, ref slotName);
                    }

                    newPaintableTexture.Slot = new P3dSlot(index, slotName);

                    if (stateLimit >= 0)
                    {
                        if (newPaintableTexture.UndoRedo != P3dPaintableTexture.UndoRedoType.LocalCommandCopy)
                        {
                            newPaintableTexture.UndoRedo   = P3dPaintableTexture.UndoRedoType.FullTextureCopy;
                            newPaintableTexture.StateLimit = stateLimit;

                            UnityEditor.EditorUtility.SetDirty(newPaintableTexture);
                        }
                    }
                }
            }
#endif
        }
Esempio n. 3
0
        /// <summary>This method returns true if this preset is designed for the specified shader.</summary>
        public bool Targets(Shader target)
        {
            if (target != null)
            {
                var candidates = GetComponents <P3dPaintableTexture>();

                foreach (var candidate in candidates)
                {
                    var groupData = P3dGroupData_Editor.GetGroupData(candidate.Group);

                    if (groupData != null)
                    {
                        if (groupData.Supports(target) == false)
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }