unity 特效制作快捷辅助工具

8 篇文章 0 订阅
3 篇文章 0 订阅

unity 特效制作快捷辅助工具
通过选中节点,鼠标中间点击,弹出配置好的快捷粒子,快速创建模块化粒子
在这里插入图片描述
上码
(注意effectFastList 集合里面的数据需要自己填充)

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using UnityEditor;
using UnityEngine;

public class EffectHelpQuick
{
	[InitializeOnLoadMethod]//这个特性作用:C#编译完成后首先执行该方法
    static void Install()
    {
        EditorApplication.hierarchyWindowItemOnGUI += onhier;
    }
    static PopupExample popupExample;
    static void ShowHierSelectMenu(Rect pos)
    {
        if (popupExample == null)
        {
            popupExample = new PopupExample(effectFastList.Count);
        }
        PopupWindow.Show(pos, popupExample);
        return;
    }
    static void onhier(int guid, Rect selectionRect)
    {
        if (Selection.activeInstanceID == guid)
        {
            var evt = Event.current;
            //if (evt.type == EventType.ContextClick)//用这个触发可以替换掉右键菜单
            if (evt.type == EventType.MouseDown && evt.button == 2)//鼠标中键触发
            {
                var mousePos = evt.mousePosition;
                if (selectionRect.Contains(mousePos))
                {
                    ShowHierSelectMenu(selectionRect);
                    evt.Use();
                }
            }
        }
    }
    //弹出PopupWindow
    public class PopupExample : PopupWindowContent
    {
        int width = 200;
        int height = 300;
        public PopupExample(int _height)
        {
            height = _height;
        }
        public override Vector2 GetWindowSize()
        {
            return new Vector2(width, height);
        }
        public override void OnGUI(Rect rect)
        {
            if (effectFastList != null)
            {
                int heightArea = 0;
                for (int i = 0; i < effectFastList.Count; i++)
                {
                    GUILayout.BeginArea(new Rect(0, heightArea, width, height), effectFastList[i].name, GUI.skin.window);
                    heightArea += effectFastList[i].list.Count * 17+26;
                    foreach (dataInfo infolist in effectFastList[i].list)
                    {
                        if (GUILayout.Button(infolist.name, EditorStyles.toolbarButton))
                        {
                            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(infolist.path, typeof(UnityEngine.Object));
                            if (obj != null && obj is GameObject)
                            {
                                GameObject instGo = GameObject.Instantiate((obj as GameObject));
                                instGo.name = instGo.name.Replace("(Clone)", "");
                                GameObject cutGo = Selection.activeGameObject;
                                if (cutGo != null)
                                {
                                    instGo.transform.parent = cutGo.transform;
                                }
                                Selection.activeGameObject = instGo;
                            }
                            if (popupExample != null)
                            {
                                popupExample.editorWindow.Close();
                            }
                        }
                    }
                    //width += 100;
                    GUILayout.EndArea();
                }        
            }

        }
        public override void OnOpen()
        {
            //Debug.Log("Popup opened: " + this);
        }
        public override void OnClose()
        {
            //Debug.Log("Popup closed: " + this);
        }
    }
    public class dataInfo
    {
        public string name { get; set; }  //名字
        public string path { get; set; }  //prefab 路径
        public bool show { get; set; }
        public List<dataInfo> list { get; set; }
    }
    static List<dataInfo> effectFastList = new List<dataInfo>(); //这里的数据自己填
}

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值