zoukankan      html  css  js  c++  java
  • unity编辑器扩展_07(创建对话框,检测按钮的点击,点击按钮后提示信息,保存设置的数据,显示点击按钮后的处理的进度条信息)

    代码:

    using UnityEditor;
    using UnityEngine;

    public class ChangeValue : ScriptableWizard {
                              
        public int health = 10;
        public int speed = 23;
       
        [MenuItem("Tools/CreateWizard")]
        static void CreateWizard()
        {
            ScriptableWizard.DisplayWizard<ChangeValue>("这是自己创建的标题", "按钮1的名字","按钮2的名字");
        }
        void OnWizardCreate()
        {
            ShowNotification(new GUIContent(Selection.gameObjects.Length + "多个游戏物体被改变"));//显示提示信息
            GameObject[] gameObject = Selection.gameObjects;
            EditorUtility.DisplayProgressBar("这是进度条的标题", "进度信息", 0);
            int count = 0;
            foreach (GameObject go in gameObject)
            {
                count++;
                CompleteProject.PlayerHealth ph = go.GetComponent<CompleteProject.PlayerHealth>();
                Undo.RecordObject(ph,"ph");//对点击事件的撤销功能
                ph.startingHealth += health;
                ph.flashSpeed += speed;
                EditorUtility.DisplayProgressBar("这是进度条标题", "进度信息", count / Selection.gameObjects.Length);
            }
            EditorUtility.ClearProgressBar();
        }
        void OnWizardOtherButton()
        {
            OnWizardCreate();
        }
        const string healtKey = "health";
        const string speedKey = "speed";
        void OnEnable()
        {
            health = EditorPrefs.GetInt(healtKey, health);
            speed = EditorPrefs.GetInt(speedKey, speed);   
        }
        void OnWizardUpdate()
        {
            string helpString = null;
            string errorString = null;
            if (Selection.gameObjects.Length > 0)
            {
                helpString = "您当前选择了" + Selection.gameObjects.Length + "个游戏物体";

            }
            else
            {
                errorString = "请选择至少一个游戏物体";
            }
            EditorPrefs.SetInt(healtKey, health);
            EditorPrefs.SetInt(speedKey, speed);           
        }
        void OnSelectionChange()
        {
            OnWizardUpdate();
        }
    }

    说明:使用ScriptableWizard.DisplayWizard创建对话框<类名>(“对话框名标题”,“按钮1”,“按钮2”),当参数不设置按钮1是,则默认按钮名字为Create。按钮2根据实际情况决定是否需要。

         使用Undo.RecordObject对点击事件的撤销功能,第一个参数为需要保存的值,第二为该值保存后的名字。

       使用ShowNotification显示提示信息

       使用EditorPrefs保存数据

       使用EditorUtility.DisplayProgressBar显示进度

  • 相关阅读:
    使用golang访问kubebernetes
    使用 Rancher 管理现有 Kubernetes 集群
    Running powershell scripts during nuget package installation and removal
    How to Create, Use, and Debug .NET application Crash Dumps in 2019
    寻找写代码感觉(一)之使用 Spring Boot 快速搭建项目
    Selenium+Java之解决org.openqa.selenium.InvalidArgumentException: invalid argument报错问题
    Selenium环境搭建
    关于Xpath定位方法知道这些基本够用
    Web自动化之浏览器启动
    【翻译】编写代码注释的最佳实践
  • 原文地址:https://www.cnblogs.com/shirln/p/7843394.html
Copyright © 2011-2022 走看看