IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> Unity技能编辑器(特效,音效) -> 正文阅读

[游戏开发]Unity技能编辑器(特效,音效)

技能编辑器是用于我们在创建角色后对角色进行编辑的编辑器,属于一种常见的编辑器类型,掌握技能编辑器有利于我们更好的对角色进行改造以及优化。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Newtonsoft.Json;
using System;
using System.IO;

public class SkillEditorWindow : EditorWindow
{
    class PlayerEditor
    {
        public int characterIndex = 0;
        public int folderIndex = 0;
        public string characterName = string.Empty;
        public string folderName = string.Empty;
        public string characterFilter = string.Empty;
        public List<string> charactList = new List<string>();
        public Player playerEntity = null;
    }
    PlayerEditor player = new PlayerEditor();
    private List<string> folderList = new List<string>();
    public List<string> characterList = new List<string>();

    Dictionary<string, List<string>> folderprefabs = new Dictionary<string, List<string>>();

    string newSkillName = string.Empty;
    public string PlayerName = "";
    public string EnemyName = "";
    public int SelectIndex = 0;



    public int SelectEnemyIndex = 0;
    public int SelectEnemyPrefabIndex = 0;
    public List<string> SilleEnemys = new List<string>();
    public List<string> EnemyPrefabs = new List<string>();

    public string SkillName = null;
    public string Names = "";
    SkillWindow skillWindow;
   
    [MenuItem("Tools/Skill _%Q")]
    public static void Init() 
    {
        if (Application.isPlaying) 
        {
            var s = GetWindow<SkillEditorWindow>("SkillEditor");
            if (s != null)
            {
                s.Show();
            }
        } 
    }
    public void OnEnable()
    {
        SerachFolder();
        GetFileFlder();
    }

    private void GetFileFlder()
    {
        folderList.Clear();
        folderList.Add("All");
        string[] folders = Directory.GetDirectories(GetPath());
        foreach (var item in folders)
        {
            folderList.Add(Path.GetFileName(item));
        }
    }

    private void SerachFolder()
    {
        string[] FolderbNameas = Directory.GetFiles(GetPath(), "*.prefab", SearchOption.AllDirectories);
        characterList.Clear();
        foreach (var item in FolderbNameas)
        {
            characterList.Add(Path.GetFileNameWithoutExtension(item));
        }
        characterList.Sort();
        characterList.Insert(0, "null");
        player.charactList.AddRange(characterList);
    }

    string GetPath()
    {
        return Application.dataPath + "/GameDate/Model";
    }
 
    private void OnGUI()
    {
        GUILayout.Button("ChangeCameraParam");
        GUILayout.Label("Player");
        GUILayout.BeginHorizontal();
        PlayerName = GUILayout.TextField(PlayerName, GUILayout.Width(100), GUILayout.Height(20));
        int folderIndex = EditorGUILayout.Popup(player.folderIndex, folderList.ToArray());
        if (folderIndex != player.folderIndex)
        {
            player.folderIndex = folderIndex;
            player.characterIndex = -1;
            string folderName = folderList[player.folderIndex];
            List<string> lists;
            if (folderName.Equals("all"))
            {
                lists = characterList;
            }
            else
            {
                if (!folderprefabs.TryGetValue(folderName, out lists))
                {
                    lists = new List<string>();
                    string[] files = Directory.GetFiles(GetPath() + "/" + folderName, "*.prefab", SearchOption.AllDirectories);
                    foreach (var item in files)
                    {
                        lists.Add(Path.GetFileNameWithoutExtension(item));
                    }
                    folderprefabs[folderName] = lists;
                }
            }
            player.charactList.Clear();
            player.charactList.AddRange(lists);
        }

        SelectIndex = EditorGUILayout.Popup(player.characterIndex,player.charactList.ToArray(), GUILayout.Width(120), GUILayout.Height(20));
        if (SelectIndex!=player.characterIndex) 
        {
            player.characterIndex = SelectIndex;
            if (player.characterName!=player.charactList[player.characterIndex])
            {
                player.characterName = player.charactList[player.characterIndex];
                if (!string.IsNullOrEmpty(player.characterName)) 
                {
                    if (player.playerEntity!=null) 
                    {
                        player.playerEntity.Destroy();
                    }
                    player.playerEntity = Player.Init(player.characterName);
                }
            }
        }
     
    
        GUILayout.EndHorizontal();
        GUILayout.Space(5);

        GUILayout.Label("Enemy");
        SilleEnemys.Add("all");
        SilleEnemys.Add("Enemy");
        EnemyPrefabs.Add("null");
        EnemyPrefabs.Add("Teddy");
        GUILayout.BeginHorizontal();
        EnemyName = GUILayout.TextField(EnemyName, GUILayout.Width(100), GUILayout.Height(20));
        SelectEnemyIndex = EditorGUILayout.Popup(SelectEnemyIndex, SilleEnemys.ToArray(), GUILayout.Width(120), GUILayout.Height(20));
        SelectEnemyPrefabIndex = EditorGUILayout.Popup(SelectEnemyPrefabIndex, EnemyPrefabs.ToArray(), GUILayout.Width(120), GUILayout.Height(20));
        GUILayout.EndHorizontal();
        GUILayout.Space(3);

        GUILayout.Label("New");
        GUILayout.BeginHorizontal();
        SkillName= GUILayout.TextField(SkillName, GUILayout.Width(200), GUILayout.Height(20));
        if (GUILayout.Button("New")) 
        {
            if (!string.IsNullOrEmpty(SkillName) &&player.playerEntity!=null) 
            {
                List<SkillBase> skills = player.playerEntity.AddNewSkills(SkillName);
                SkillName = "";
            }

        }
        GUILayout.EndHorizontal();
        GUILayout.Space(3);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Sa ve", GUILayout.Width(110), GUILayout.Height(20)))
        {
            player.playerEntity.SaveSkill();
        }

        if (GUILayout.Button("Save As", GUILayout.Width(110), GUILayout.Height(20)))
        {

        }
        if (GUILayout.Button("Delete", GUILayout.Width(110), GUILayout.Height(20)))
        {

        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("ActFilter");
        Names= GUILayout.TextField(Names, GUILayout.Width(100), GUILayout.Height(20));
        GUILayout.EndHorizontal();
        if (player.playerEntity!=null) 
        {
            Pos = GUILayout.BeginScrollView(Pos, false, true);
            foreach (var item in player.playerEntity.skillList)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(item.Key))
                {
                    Names = item.Key;
                    List<SkillBase> skillComponet = player.playerEntity.GetSkill(item.Key);
                    foreach (var ite in skillComponet)
                    {
                        ite.Init();
                    }
                    OpenSkillWindow(item.Key, skillComponet);
                }
                GUILayoutOption[] options = new GUILayoutOption[]
                {
                     GUILayout.Width(60),
                   GUILayout.Height(20)
                };
                if (GUILayout.Button("删除技能",options))
                {
                    player.playerEntity.RemoveSkill(item.Key);
                    break;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
        }
    }
    Vector2 Pos = new Vector2(0, 0);

    private void OpenSkillWindow(string skillName, List<SkillBase> skillCompoent)
    {
        if (skillCompoent != null)
        {
            if (skillWindow == null)
            {
                skillWindow = GetWindow<SkillWindow>("");
            }
            skillWindow.titleContent = new GUIContent(skillName);
            skillWindow.SetiniySkill(skillCompoent, player.playerEntity);
            skillWindow.Show();
            skillWindow.Repaint();
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;

public class SkillWindow : EditorWindow
{
    string[] skills =new string[] { "低", "中", "高" };
    string[] comos = new string[] { "null","动画", "特效","音效" };
    List<SkillBase> skillComPonents=new List<SkillBase>();
    public List<string> FolderList = new List<string>();
    public int SelectIndex = 0;
    public int Folderindex = 0;
    public float speed = 1;
    public float speed1 = 0;
    public bool isok = true;
    public bool isOpen = true;
    public string str = "AnimationQueue";
    Player _player;
    public AnimationClip anim;

    public Skill_Anim Anim;
    public void SetiniySkill(List<SkillBase> skillCompoent,Player player)
    {
        _player = player;
        speed = 1;
        skillComPonents = skillCompoent;
        _player.currSkillComponts = skillComPonents;
    }
    private void OnGUI()
    {
        FolderList.Add(null);
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("播放", GUILayout.Width(130), GUILayout.Height(20)))
        {
            foreach (var item in skillComPonents)
            {
                item.Play();
            }
        }
        if (GUILayout.Button("停止", GUILayout.Width(130), GUILayout.Height(20)))
        {
            foreach (var item in skillComPonents)
            {
                item.Stop();
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        _player.times = GUILayout.TextField(_player.times);

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();

        _player.quanzhong = GUILayout.TextField(_player.quanzhong);

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        GUILayout.Label("特效等级");
        SelectIndex = EditorGUILayout.Popup(SelectIndex, skills, GUILayout.Width(120), GUILayout.Height(20));
        GUILayout.EndHorizontal();    

        GUILayout.BeginHorizontal();
        GUILayout.Label("播放速度");
        float Speed=EditorGUILayout.Slider(speed, 0, 3);
        if (Speed!= speed)
        {
            speed = Speed;
            Time.timeScale = speed;
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();

        GUILayout.Label("动画时间轴");
        GUILayout.Label(speed1.ToString(), GUILayout.Width(50));
        float value = GUILayout.HorizontalSlider((float)Math.Round(speed1, 2), 0, 3);
        if (Mathf.Abs(value - speed1) > 0.001)
        {
            speed1 = value;
        }
        //speed1 = EditorGUILayout.Slider(speed1, 0, 5);
        //if (Mathf.Abs()) 
        //{

        //}
        GUILayout.EndHorizontal();
        GUILayout.Space(3);
        GUILayout.BeginHorizontal();
        Folderindex = EditorGUILayout.Popup(Folderindex, comos, GUILayout.Width(120), GUILayout.Height(20));
        if (GUILayout.Button("添加", GUILayout.Width(100), GUILayout.Height(20)))
        {
            switch (Folderindex)
            {
                case 1:
                    skillComPonents.Add(new Skill_Anim(_player));
                    break;
                case 2:
                    skillComPonents.Add(new Skill_Effects(_player));
                    break;
                case 3:
                    skillComPonents.Add(new Skill_Audio(_player));
                    break;
                default:
                    break;
            }
        }
        GUILayout.EndHorizontal();

        isok = EditorGUILayout.Toggle("全部展开", isok);
        if (isok) 
        {
            isOpen=EditorGUILayout.Foldout(isOpen, str);
            Pos = GUILayout.BeginScrollView(Pos, false, true);
            foreach (var item in skillComPonents)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(item.name);
                if (GUILayout.Button("删除")) 
                {
                    skillComPonents.Remove(item);
                    break;
                }
                GUILayout.EndHorizontal();
                if (item is Skill_Anim) 
                {
                    ShowSkill_Anim(item as Skill_Anim);
                }
                if (item is Skill_Effects)
                {
                    ShowSkill_Effect(item as Skill_Effects);
                }
                if (item is Skill_Audio)
                {
                    ShowSkill_Audio(item as Skill_Audio);
                }
            }
            GUILayout.EndScrollView();
        }
    }

    Vector2 Pos = new Vector2(0, 0);
    void ShowSkill_Anim(Skill_Anim _Anim) 
    {
        _Anim.trigger = EditorGUILayout.TextField(_Anim.trigger);
        AnimationClip clip = EditorGUILayout.ObjectField(_Anim.clip, typeof(AnimationClip), false) as AnimationClip;
        if (_Anim.clip!=clip) 
        {
            _Anim.SetAnimClip(clip);
        }
    }
    void ShowSkill_Effect(Skill_Effects _Effect)
    {
        _Effect.trigger = EditorGUILayout.TextField(_Effect.trigger);
        GameObject game = EditorGUILayout.ObjectField(_Effect.game, typeof(GameObject), false) as GameObject;
        if (_Effect.game != game)
        {
            _Effect.SetGameClip(game);
        }
    }
    void ShowSkill_Audio(Skill_Audio _Audio)
    {
        _Audio.trigger = EditorGUILayout.TextField(_Audio.trigger);
        AudioClip clip = EditorGUILayout.ObjectField(_Audio.clip, typeof(AudioClip), false) as AudioClip;
        if (_Audio.clip != clip)
        {
            _Audio.SetAudioClip(clip);
        }
    }
}

上面这段代码是用于对技能进行更精确的编辑时所使用的。

下面展示一下具体的效果:

技能编辑器大致效果就是在创建角色时进行编辑操作。

下面附上完整项目,

?Skill_Editor.zip-Unity3D文档类资源-CSDN下载

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2021-12-14 16:17:43  更:2021-12-14 16:19:23 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/27 21:05:56-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码