Unity 注释小技巧

php中文网
发布: 2016-06-07 14:59:38
原创
2323人浏览过

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

Unity 注释小技巧

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


[Header(<span>"</span><span>注释</span><span>"</span><span>)]
[Space(</span><span>20</span><span>)]
</span><span>public</span> Vector3 test1;
登录后复制

 

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

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

Unity 注释小技巧

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

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

高级Bash脚本编程指南 chm版 20
查看详情 高级Bash脚本编程指南 chm版

 

<span>using</span><span> UnityEngine;
</span><span>using</span><span> System.Collections;
</span><span>using</span><span> UnityEditor;
</span><span>using</span><span> System;
</span><span>using</span><span> System.Reflection;
</span><span>using</span><span> System.Collections.Generic;

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


    </span><span>private</span> <span>static</span> <span>bool</span> isDevelop = <span>true</span><span>;

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

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

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

                                }
                                
                                </span><span>break</span><span>;
                        }
                    }
                }
            }

        }
        </span><span>else</span><span>
        {
            </span><span>base</span><span>.OnInspectorGUI();
        } 
    }


    </span><span>#region</span> 暂时没有用到的代码


    <span>/*</span><span>
    /// <summary>
    /// 缓存实例的属性,下次就不需要使用循环了
    /// </summary>
    public Dictionary<string, string> 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();
        }
    }
    </span><span>*/</span>
    <span>#endregion</span><span>
}</span>
登录后复制

MyCompoment:

<span>using</span><span> UnityEngine;
</span><span>using</span><span> System.Collections;

[SerializeField]
</span><span>public</span> <span>class</span><span> MyCompoment : MonoBehaviour {

    [LabelAttribute(Label </span>= <span>"</span><span>名字</span><span>"</span><span>)]
    </span><span>public</span> <span>string</span> MyName = <span>"</span><span>123</span><span>"</span><span>;

    [LabelAttribute(Label </span>= <span>"</span><span>float数字</span><span>"</span><span>)]
    </span><span>public</span> <span>float</span> float1 = <span>100</span><span>;

    [LabelAttribute(Label </span>= <span>"</span><span>double数字</span><span>"</span><span>)]
    </span><span>public</span> <span>double</span> double1 = <span>100</span><span>;

    [LabelAttribute(Label </span>= <span>"</span><span>int数字</span><span>"</span><span>)]
    </span><span>public</span> <span>int</span> int1 = <span>100</span><span>;

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

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

    [LabelAttribute(Label </span>= <span>"</span><span>组件</span><span>"</span><span>)]
    </span><span>public</span><span> StartPanel Component1;

    [LabelAttribute(Label </span>= <span>"</span><span>2D</span><span>"</span><span>)]
    </span><span>public</span><span> Vector2 Vector2;

    [LabelAttribute(Label </span>= <span>"</span><span>3D</span><span>"</span><span>)]
    </span><span>public</span><span> Vector3 Vector3;

    [LabelAttribute(Label </span>= <span>"</span><span>4D</span><span>"</span><span>)]
    </span><span>public</span><span> Vector4 Vector4;

}</span>
登录后复制

LabelAttribute特性:

<span>using</span><span> UnityEngine;
</span><span>using</span><span> System.Collections;
</span><span>using</span><span> System;

</span><span>public</span> <span>class</span><span> LabelAttribute : Attribute {
    </span><span>public</span> <span>string</span><span> Label;

}</span>
登录后复制

 

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

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

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