0

0

Unity 注释小技巧

php中文网

php中文网

发布时间:2016-06-07 14:59:38

|

2325人浏览过

|

来源于php中文网

原创

你只需要在字段上添加特效即可 [Header( " 注释 " )][Space( 20 )] public Vector3 test1; ===================================================================================== 自己抽时间写了一个中文显示小脚本.下次问问老大能不能加到项目中去 usin

Unity 注释小技巧

你只需要在字段上添加特效即可


[Header("注释")]
[Space(20)]
public Vector3 test1;

 

=====================================================================================

Unity 注释小技巧自己抽时间写了一个中文显示小脚本.下次问问老大能不能加到项目中去

Unity 注释小技巧

高级Bash脚本编程指南 chm版
高级Bash脚本编程指南 chm版

这本书假定你没有任何关于脚本或一般程序的编程知识, 但是如果你具备相关的知识, 那么你将很容易就能够达到中高级的水平. . . 所有这些只是UNIX®浩瀚知识的一小部分. 你可以把本书作为教材, 自学手册, 或者是关于shell脚本技术的文档. 书中的练习和样例脚本中的注释将会与读者进行更好的互动, 但是最关键的前提是: 想真正学习脚本编程的唯一途径就是亲自动手编写脚本. 这本书也可作为教材来讲解一般的编程概念. 向伟大的中华民族的Linux用户致意! 我希望这本书能够帮助你们学习和理解L

下载

 

using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Reflection;
using System.Collections.Generic;

[CustomEditor(typeof(MyCompoment))]
public class MyCompomentEditor : Editor{
    public MyCompomentEditor():base()
    {
        //Debug.Log("我初始化了");
    }


    private static bool isDevelop = true;

    public override void OnInspectorGUI()
    {
        if (isDevelop)
        {
            MyCompoment edit = (MyCompoment)target;
            Type t = edit.GetType();
            string label = string.Empty;
            FieldInfo[] fieldInfs = t.GetFields();
            System.Object[] atrrs = null;
            for (int i = 0; i < fieldInfs.Length; i++)
            {
                atrrs = fieldInfs[i].GetCustomAttributes(false);
                for (int k = 0; k < fieldInfs[i].GetCustomAttributes(false).Length; k++)
                {
                    if (atrrs[k] is LabelAttribute)
                    {

                        label = ((LabelAttribute)atrrs[k]).Label;
                        switch (fieldInfs[i].FieldType.Name)
                        {
                            case "String":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.TextField(label, fieldInfs[i].GetValue(edit).ToString()));
                                break;
                            case "Float":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.FloatField(label, (float)fieldInfs[i].GetValue(edit)));
                                break;
                            //case "Double":
                            //    fieldInfs[i].SetValue(edit, EditorGUILayout.Doube(label, (double)fieldInfs[i].GetValue(edit)));
                            //    break;
                            case "Int":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.IntField(label, (int)fieldInfs[i].GetValue(edit)));
                                break;
                            case "Int32":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.IntField(label, (int)fieldInfs[i].GetValue(edit)));
                                break;
                            case "Color":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.ColorField(label, (UnityEngine.Color)fieldInfs[i].GetValue(edit)));
                                break;
                            case "GameObject":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.ObjectField(label, (UnityEngine.Object)fieldInfs[i].GetValue(edit), typeof(GameObject)));
                                break;
                            case "Component":
                                Debug.Log("运行过Component");
                                fieldInfs[i].SetValue(edit, EditorGUILayout.ObjectField(label, (UnityEngine.Object)fieldInfs[i].GetValue(edit), typeof(Component)));
                                break;
                            case "Vector2":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.Vector2Field(label, (Vector2)fieldInfs[i].GetValue(edit)));
                                break;
                            case "Vector3":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.Vector3Field(label, (Vector3)fieldInfs[i].GetValue(edit)));
                                break;
                            case "Vector4":
                                fieldInfs[i].SetValue(edit, EditorGUILayout.Vector4Field(label, (Vector4)fieldInfs[i].GetValue(edit)));
                                break;
                            //case "Test":
                            //    Debug.Log("运行过Component");
                            //    fieldInfs[i].SetValue(edit, EditorGUILayout.ObjectField(label, (UnityEngine.Object)fieldInfs[i].GetValue(edit), typeof(Component)));
                            //    break;
                            default:

                                //Debug.Log("fieldInfs[i].Name   " + fieldInfs[i].FieldType.BaseType.Name);
                                if (fieldInfs[i].FieldType.BaseType.Name == "MonoBehaviour")
                                {
                                    fieldInfs[i].SetValue(edit, EditorGUILayout.ObjectField(label, (UnityEngine.Object)fieldInfs[i].GetValue(edit), fieldInfs[i].FieldType));

                                }
                                
                                break;
                        }
                    }
                }
            }

        }
        else
        {
            base.OnInspectorGUI();
        } 
    }


    #region 暂时没有用到的代码


    /*
    /// 
    /// 缓存实例的属性,下次就不需要使用循环了
    /// 
    public Dictionary dir;

    public void GetProrptes() 
    {
        if (isDevelop)
        {
            MyCompoment edit = (MyCompoment)target;
            Type t = edit.GetType();
            string label = string.Empty;

            FieldInfo[] fieldInfos = t.GetFields();
            System.Object[] atrrs = null;
            GUIContent contextUI = null;

            for (int i = 0; i < fieldInfos.Length; i++)
            {
                atrrs = fieldInfos[i].GetCustomAttributes(false);
                for (int k = 0; k < atrrs.Length; k++)
                {
                    if (atrrs[k] is LabelAttribute)
                    {
                        label = ((LabelAttribute)atrrs[k]).Label;
                        contextUI = new GUIContent();
                        contextUI.text = label;
                        EditorGUILayout.PropertyField(serializedObject.FindProperty(fieldInfos[i].Name), contextUI);
                    }
                }
            }
        }
        else
        {
            base.OnInspectorGUI();
        }
    }
    */
    #endregion
}

MyCompoment:

using UnityEngine;
using System.Collections;

[SerializeField]
public class MyCompoment : MonoBehaviour {

    [LabelAttribute(Label = "名字")]
    public string MyName = "123";

    [LabelAttribute(Label = "float数字")]
    public float float1 = 100;

    [LabelAttribute(Label = "double数字")]
    public double double1 = 100;

    [LabelAttribute(Label = "int数字")]
    public int int1 = 100;

    [LabelAttribute(Label = "颜色")]
    public Color color1 = Color.red;

    [LabelAttribute(Label = "游戏物体")]
    public GameObject GameObject1;

    [LabelAttribute(Label = "组件")]
    public StartPanel Component1;

    [LabelAttribute(Label = "2D")]
    public Vector2 Vector2;

    [LabelAttribute(Label = "3D")]
    public Vector3 Vector3;

    [LabelAttribute(Label = "4D")]
    public Vector4 Vector4;

}

LabelAttribute特性:

using UnityEngine;
using System.Collections;
using System;

public class LabelAttribute : Attribute {
    public string Label;

}

 

源代码:  http://yunpan.cn/cJhp4tThyGauJ  访问密码 5789

相关专题

更多
nginx部署php项目教程汇总
nginx部署php项目教程汇总

本专题整合了nginx部署php项目教程汇总,阅读专题下面的文章了解更多详细内容。

0

2026.01.13

PHP 表单处理与文件上传安全实战
PHP 表单处理与文件上传安全实战

本专题聚焦 PHP 在表单处理与文件上传场景中的实战与安全问题,系统讲解表单数据获取与校验、XSS 与 CSRF 防护、文件类型与大小限制、上传目录安全配置、恶意文件识别以及常见安全漏洞的防范策略。通过贴近真实业务的案例,帮助学习者掌握 安全、规范地处理用户输入与文件上传的完整开发流程。

5

2026.01.13

PPT交互图表教程大全
PPT交互图表教程大全

本专题整合了PPT交互图表相关教程汇总,阅读专题下面的文章了解更多详细内容。

53

2026.01.12

Java 项目构建与依赖管理(Maven / Gradle)
Java 项目构建与依赖管理(Maven / Gradle)

本专题系统讲解 Java 项目构建与依赖管理的完整体系,重点覆盖 Maven 与 Gradle 的核心概念、项目生命周期、依赖冲突解决、多模块项目管理、构建加速与版本发布规范。通过真实项目结构示例,帮助学习者掌握 从零搭建、维护到发布 Java 工程的标准化流程,提升在实际团队开发中的工程能力与协作效率。

21

2026.01.12

c++主流开发框架汇总
c++主流开发框架汇总

本专题整合了c++开发框架推荐,阅读专题下面的文章了解更多详细内容。

135

2026.01.09

c++框架学习教程汇总
c++框架学习教程汇总

本专题整合了c++框架学习教程汇总,阅读专题下面的文章了解更多详细内容。

66

2026.01.09

学python好用的网站推荐
学python好用的网站推荐

本专题整合了python学习教程汇总,阅读专题下面的文章了解更多详细内容。

140

2026.01.09

学python网站汇总
学python网站汇总

本专题整合了学python网站汇总,阅读专题下面的文章了解更多详细内容。

13

2026.01.09

python学习网站
python学习网站

本专题整合了python学习相关推荐汇总,阅读专题下面的文章了解更多详细内容。

19

2026.01.09

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
vscode其实很简单
vscode其实很简单

共72课时 | 28.9万人学习

Django 教程
Django 教程

共28课时 | 3万人学习

Go 教程
Go 教程

共32课时 | 3.6万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号