Exemplo n.º 1
0
        /// <summary>
        /// Creates a New PrefabPalette
        /// </summary>
        /// <returns>The Newly created PrefabPalette</returns>
        internal static PrefabPalette AddNew()
        {
            string path = PolyEditorUtility.UserAssetDirectory + "Prefab Palette";

            if (string.IsNullOrEmpty(path))
            {
                path = "Assets";
            }

            path = AssetDatabase.GenerateUniqueAssetPath(path + "/New Prefab Palette.asset");

            if (!string.IsNullOrEmpty(path))
            {
                PrefabPalette palette = ScriptableObject.CreateInstance <PrefabPalette>();
                palette.SetDefaultValues();

                AssetDatabase.CreateAsset(palette, path);
                AssetDatabase.Refresh();

                EditorGUIUtility.PingObject(palette);

                return(palette);
            }

            return(null);
        }
Exemplo n.º 2
0
        public PrefabLoadoutEditor(List <PrefabPalette> palettes, PrefabPalette startingPalette)
        {
            currentPalette = startingPalette;

            prefabPaletteEditors = new Dictionary <PrefabPalette, PrefabPaletteEditor>();
            m_CurrentLoadouts    = s_UserLoadout.value.infos;

            RefreshPalettesList(palettes);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Switch to a new Palette Edition, which means switching paletteEditor too
 /// </summary>
 /// <param name="palette">the target palette</param>
 internal void ChangePalette(PrefabPalette palette)
 {
     if (!prefabPaletteEditors.ContainsKey(palette))
     {
         var editor = (PrefabPaletteEditor)Editor.CreateEditor(palette);
         editor.loadoutEditor = this;
         prefabPaletteEditors.Add(palette, editor);
     }
     currentPalette = palette;
 }
Exemplo n.º 4
0
        internal override bool SetDefaultSettings()
        {
            RefreshAvailablePalettes();
            PrefabPalette defaultPalette = m_AvailablePalettes.FirstOrDefault(x => x.name.Contains("Default"));

            if (defaultPalette == null)
            {
                return(false);
            }

            SetPrefabPalette(defaultPalette);

            return(true);
        }
Exemplo n.º 5
0
 void SetPrefabPalette(PrefabPalette palette)
 {
     prefabPalette = palette;
     prefabLoadoutEditor.ChangePalette(palette);
     RefreshAvailablePalettes();
 }
Exemplo n.º 6
0
        /// <summary>
        /// Draw everything concerning a single Prefab Palette in the Polybrush Window
        /// </summary>
        /// <param name="thumbSize">size of the preview textures</param>
        internal void OnInspectorGUI_Internal(int thumbSize)
        {
            PolyGUILayout.Label(m_GCCurrentPaletteLabel);

            serializedObject.Update();
            int  count        = prefabs != null ? prefabs.arraySize : 0;
            Rect dropDownZone = EditorGUILayout.BeginVertical(paletteStyle);

            dropDownZone.width = EditorGUIUtility.currentViewWidth;
            Rect backGroundRect = new Rect(dropDownZone);

            if (count != 0)
            {
                const int pad  = 4;
                int       size = thumbSize + pad;
                backGroundRect.x += 8;
                backGroundRect.y += 4;
                // The backgroundRect is currently as wide as the current view.
                // Adjust it to take the size of the vertical scrollbar and padding into account.
                backGroundRect.width -= (20 + (int)GUI.skin.verticalScrollbar.fixedWidth);
                // size variable will not take into account the padding to the right of all the thumbnails,
                // therefore it needs to be substracted from the width.
                int container_width = ((int)Mathf.Floor(backGroundRect.width) - (pad + 1));
                int columns         = (int)Mathf.Floor(container_width / size);
                int rows            = count / columns + (count % columns == 0 ? 0 : 1);
                if (rows < 1)
                {
                    rows = 1;
                }

                backGroundRect.height = 8 + rows * thumbSize + (rows - 1) * pad;
                EditorGUI.DrawRect(backGroundRect, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);

                int currentIndex = 0;
                for (int i = 0; i < rows; i++)
                {
                    var horizontalRect = EditorGUILayout.BeginHorizontal();
                    for (int j = 0; j < columns; j++)
                    {
                        GUILayout.Space(pad);
                        var prefab          = prefabs.GetArrayElementAtIndex(currentIndex);
                        var previewRectXPos = pad + j * size + horizontalRect.x;
                        DrawPrefabPreview(prefab, currentIndex, thumbSize, previewRectXPos, horizontalRect.y);
                        currentIndex++;
                        if (currentIndex >= count)
                        {
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(pad);
                }

                EditorGUILayout.EndVertical();

                if (selected.Count > 0)
                {
                    EditorGUILayout.LabelField(m_GCPlacementSettingsLabel);
                    GUILayout.Space(pad);
                }

                EditorGUILayout.BeginVertical();

                foreach (var i in selected)
                {
                    DrawSinglePrefabPlacementSettings(prefabs.GetArrayElementAtIndex(i), i);
                }

                /// Little Hack to get the Rect for dropping new prefabs
                Rect endDropDownZone = EditorGUILayout.BeginVertical();
                dropDownZone.height = endDropDownZone.y - dropDownZone.y;
                EditorGUILayout.EndVertical();
            }
            else
            {
                dropDownZone.height = thumbSize;
                var r = EditorGUILayout.BeginVertical(GUILayout.Height(thumbSize + 4));
                EditorGUI.DrawRect(r, EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);
                GUILayout.FlexibleSpace();
                GUILayout.Label("Drag Prefabs Here!", EditorStyles.centeredGreyMiniLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();

            Event e = Event.current;

            if (dropDownZone.Contains(e.mousePosition) &&
                (e.type == EventType.DragUpdated || e.type == EventType.DragPerform) && DragAndDrop.objectReferences.Length > 0)
            {
                if (PolyEditorUtility.ContainsPrefabAssets(DragAndDrop.objectReferences))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }

                if (e.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    IEnumerable <GameObject> dragAndDropReferences = DragAndDrop.objectReferences
                                                                     .Where(x => x is GameObject && PolyEditorUtility.IsPrefabAsset(x)).Cast <GameObject>();

                    foreach (GameObject go in dragAndDropReferences)
                    {
                        prefabs.InsertArrayElementAtIndex(prefabs.arraySize);
                        SerializedProperty last       = prefabs.GetArrayElementAtIndex(prefabs.arraySize - 1);
                        SerializedProperty gameObject = last.FindPropertyRelative("gameObject");
                        gameObject.objectReferenceValue = go;
                        PlacementSettings.PopulateSerializedProperty(last.FindPropertyRelative("settings"));
                        last.FindPropertyRelative("name").stringValue = go.name;
                    }
                }
            }

            if (e.type == EventType.KeyUp)
            {
                if (IsDeleteKey(e) && !GUI.GetNameOfFocusedControl().Contains("cancelbackspace"))
                {
                    PrefabPalette t = target as PrefabPalette;
                    t.RemoveRange(selected.ToArray());

                    selected.Clear();

                    if (onSelectionChanged != null)
                    {
                        onSelectionChanged(null);
                    }

                    PolybrushEditor.DoRepaint();
                }
            }

            serializedObject.ApplyModifiedProperties();
            redrawCounter += 1;
        }
Exemplo n.º 7
0
 public LoadoutInfo(PrefabPalette p, int index)
 {
     palette = p;
     prefab  = p.prefabs[index].gameObject;
 }