コード例 #1
0
        private bool ValidateInputs(string brushName, Brush targetBrush)
        {
            if (!this.ValidateUniqueAssetName(brushName))
            {
                return(false);
            }

            if (targetBrush == null)
            {
                EditorUtility.DisplayDialog(
                    TileLang.Text("Target brush was not specified"),
                    TileLang.Text("Select the brush that you would like to create an alias of."),
                    TileLang.ParticularText("Action", "Close")
                    );
                return(false);
            }

            var targetBrushDescriptor = BrushUtility.GetDescriptor(targetBrush.GetType());

            if (targetBrushDescriptor == null || !targetBrushDescriptor.SupportsAliases)
            {
                EditorUtility.DisplayDialog(
                    TileLang.Text("Unable to create alias brush"),
                    string.Format(
                        /* 0: class of target brush */
                        TileLang.Text("No alias designer was registered for '{0}'"),
                        targetBrush.GetType().FullName
                        ),
                    TileLang.ParticularText("Action", "Close")
                    );
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private void RefreshTargetDesigner()
        {
            // Clear previous designer.
            if (this.targetDesigner != null)
            {
                this.targetDesigner.OnDisable();
                this.targetDesigner = null;
            }

            // Attach to new target.
            this.targetBrush = this.aliasBrush.target;

            BrushDescriptor brushDescriptor = null;

            this.targetSupportsAliases = true;

            if (this.targetBrush != null)
            {
                brushDescriptor = BrushUtility.GetDescriptor(this.targetBrush.GetType());
                if (brushDescriptor == null || !brushDescriptor.SupportsAliases)
                {
                    this.targetSupportsAliases = false;
                }
            }
            else
            {
                // Basic alias brush implementation.
                brushDescriptor = BrushUtility.GetDescriptor <Brush>();
            }

            this.targetDesigner        = brushDescriptor.CreateAliasDesigner(this.aliasBrush);
            this.targetDesigner.Window = this.Window;
            this.targetDesigner.OnEnable();
        }
コード例 #3
0
        /// <summary>
        /// Creates new alias brush asset.
        /// </summary>
        /// <remarks>
        /// <para>Brush asset should be marked as dirty once you have finished making
        /// modifications using <see cref="M:UnityEditor.EditorUtility.SetDirty">UnityEditor.EditorUtility.SetDirty</see>.</para>
        /// </remarks>
        /// <param name="name">Name of brush.</param>
        /// <param name="target">Target for alias brush. Specify <c>null</c> for none.</param>
        /// <returns>
        /// The brush; or <c>null</c> if an error has occurred.
        /// </returns>
        public static AliasBrush CreateAliasBrush(string name, Brush target = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                Debug.LogError("No name specified.");
                return(null);
            }

            string assetPath = AssetDatabase.GenerateUniqueAssetPath(GetBrushAssetPath() + name + ".asset");

            // Create new brush.
            var aliasBrush = ScriptableObject.CreateInstance <AliasBrush>();

            aliasBrush.target = target;

            aliasBrush.forceLegacySideways = false;

            if (target != null)
            {
                BrushDescriptor descriptor = BrushUtility.GetDescriptor(target.GetType());
                if (descriptor == null || !descriptor.SupportsAliases)
                {
                    Debug.LogError("No alias designer was registered for '" + target.GetType().FullName + "'");
                    return(null);
                }

                aliasBrush.RevertToTarget();
            }

            SaveBrushAsset(aliasBrush, assetPath);
            return(aliasBrush);
        }
コード例 #4
0
        public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            /*
             * var brush = target as Brush;
             *
             * var brushDescriptor = BrushUtility.GetDescriptor(brush.GetType());
             * if (brushDescriptor != null && brushDescriptor.CanHavePreviewCache(brush)) {
             *  return BrushUtility.CreateBrushPreview(target as Brush, width, height);
             * }
             * else {
             *  return null;
             * }
             *
             * return null;
             */

            try
            {
                var brush = target as Brush;
                //BrushUtility.CreateBrushPreview
                var brushDescriptor = BrushUtility.GetDescriptor(brush.GetType());
                if (brushDescriptor != null && brushDescriptor.CanHavePreviewCache(brush))
                {
                    var orientatedBrush = target as OrientedBrush;
                    if (orientatedBrush != null)
                    {
                        var ori = orientatedBrush.DefaultOrientation;
                        if (ori != null)
                        {
                            if (ori.VariationCount > 0)
                            {
                                var obj = ori.GetVariation(0);
                                if (obj != null)
                                {
                                    return(GetPreviewTexture(obj as GameObject, width, height));

                                    //if (!AssetPreview.IsLoadingAssetPreviews())
                                    //{
                                    //    GameObject go = obj as GameObject;
                                    //    Texture2D texture2D  = AssetPreview.GetAssetPreview(go);

                                    //    if (texture2D != null)
                                    //    {
                                    //        var duplicatedTexture = Instantiate(texture2D);
                                    //        if (duplicatedTexture != null)
                                    //            return duplicatedTexture;
                                    //    }
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
            }
            return(null);
        }
コード例 #5
0
        public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            var brush = target as Brush;

            var brushDescriptor = BrushUtility.GetDescriptor(brush.GetType());

            if (brushDescriptor != null && brushDescriptor.CanHavePreviewCache(brush))
            {
                return(BrushUtility.CreateBrushPreview(target as Brush, width, height));
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
        private void LoadBrushDesignerView()
        {
            // Ensure that GUI is updated correctly.
            this._clearFocusControl = true;

            var selectedBrush = this.SelectedObject as Brush;

            // Create editor for brush!
            Type brushType       = selectedBrush.GetType();
            var  brushDescriptor = BrushUtility.GetDescriptor(brushType);

            if (brushDescriptor == null)
            {
                return;
            }

            this.designerView = brushDescriptor.CreateDesigner(selectedBrush);
            if (this.designerView != null)
            {
                this.designerView.Window = this;
                this.designerView.OnEnable();
            }
        }
コード例 #7
0
        private void _brushList_BrushContextMenu(Brush brush)
        {
            // Do not attempt to display context menu for "(Erase)" item.
            if (brush == null)
            {
                return;
            }

            var brushRecord = BrushDatabase.Instance.FindRecord(brush);

            var brushContextMenu = new EditorMenu();

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Show in Designer")))
            .Enabled(!brushRecord.IsMaster)     // Cannot edit a master brush :)
            .Action(() => {
                ToolUtility.ShowBrushInDesigner(brush);
            });

            var selectedTilesetBrush = brush as TilesetBrush;

            if (selectedTilesetBrush != null)
            {
                brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Goto Tileset"))
                .Action(() => {
                    this.brushList.Model.View            = BrushListView.Tileset;
                    this.brushList.Model.SelectedTileset = selectedTilesetBrush.Tileset;

                    var designerWindow = RotorzWindow.GetInstance <DesignerWindow>();
                    if (designerWindow != null && !designerWindow.IsLocked)
                    {
                        designerWindow.SelectedObject = selectedTilesetBrush.Tileset;
                    }

                    this.Repaint();
                });
            }

            brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Reveal Asset"))
            .Action(() => {
                EditorGUIUtility.PingObject(brush);
            });

            brushContextMenu.AddSeparator();

            brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Refresh Preview"))
            .Action(() => {
                BrushUtility.RefreshPreviewIncludingDependencies(brush);
            });

            brushContextMenu.AddSeparator();

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Create Duplicate")))
            .Action(() => {
                var window = CreateBrushWindow.ShowWindow <DuplicateBrushCreator>();
                window.SharedProperties["targetBrush"] = brush;
            });

            var brushDescriptor = BrushUtility.GetDescriptor(brush.GetType());

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Create Alias")))
            .Enabled(brushDescriptor.SupportsAliases)
            .Action(() => {
                var window = CreateBrushWindow.ShowWindow <AliasBrushCreator>();
                window.SharedProperties["targetBrush"] = brush;
            });

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Delete Brush")))
            .Action(() => {
                TileSystemCommands.DeleteBrush(brush, ToolUtility.SharedBrushListModel.View == BrushListView.Tileset);
            });

            brushContextMenu.ShowAsContext();
        }
コード例 #8
0
        /// <summary>
        /// Specify brush that the edited brush is an alias of.
        /// </summary>
        /// <param name="brush">Target brush.</param>
        public void SetAliasTarget(Brush brush)
        {
            // Do not proceed if no changes have been made.
            if (brush == this.AliasBrush.target)
            {
                return;
            }

            Undo.RecordObject(this.Brush, TileLang.ParticularText("Action", "Set Target"));

            var brushDescriptor = (brush != null)
                ? BrushUtility.GetDescriptor(brush.GetType())
                : null;

            if (brush == this.AliasBrush || brush is AliasBrush)
            {
                // Brush cannot be an alias of itself or another alias.
                if (this.Window != null)
                {
                    this.Window.ShowNotification(new GUIContent(TileLang.Text("Cannot create alias of another alias brush.")));
                }
                this.AliasBrush.target = null;
            }
            else if (brush == null)
            {
                // No brush was specified, clear target.
                this.AliasBrush.target = null;
            }
            else if (brushDescriptor == null)
            {
                // Unknown target brush.
                if (this.Window != null)
                {
                    string targetBrushNicifiedName = ObjectNames.NicifyVariableName(brush.GetType().Name);
                    this.Window.ShowNotification(new GUIContent(string.Format(
                                                                    /* 0: nicified name of the target brush class (i.e. 'Uber Oriented Brush') */
                                                                    TileLang.Text("Cannot create alias of the unregistered brush '{0}'."),
                                                                    targetBrushNicifiedName
                                                                    )));
                }
                this.AliasBrush.target = null;
            }
            else if (!brushDescriptor.SupportsAliases)
            {
                // Brush does not support aliases.
                if (this.Window != null)
                {
                    this.Window.ShowNotification(new GUIContent(string.Format(
                                                                    /* 0: name of the target brush (i.e. 'Grass Platform') */
                                                                    TileLang.Text("Cannot create alias of '{0}'."),
                                                                    brushDescriptor.DisplayName
                                                                    )));
                }
                this.AliasBrush.target = null;
            }
            else
            {
                if (this.Window != null)
                {
                    this.Window.RemoveNotification();
                }

                // Update alias reference.
                this.AliasBrush.target = brush;
            }

            // Find out if target brush is a master brush.
            var targetBrushRecord = BrushDatabase.Instance.FindRecord(this.AliasBrush.target);

            if (targetBrushRecord != null)
            {
                this.isTargetMasterBrush = targetBrushRecord.IsMaster;
            }

            this.SetDirty();

            BrushUtility.RefreshPreview(this.Brush);
        }