Unity3D研究院编辑器之脚本生成Preset Libraries
2015-11-13 11:40
489 查看
Unity3D研究院编辑器之脚本生成Preset Libraries(十四)
雨松MOMO 【Unity3D拓展编辑器】 围观499次 4条评论 编辑日期:2015-10-29 字体:大 中 小<iframe id="cproIframe_u1121907_1" width="300" height="250" src="http://pos.baidu.com/acom?adn=4&at=134&aurl=&cad=1&ccd=24&cec=UTF-8&cfv=18&ch=0&col=zh-CN&conOP=0&cpa=1&dai=1&dis=0&layout_filter=rank%2Ctabcloud<r=http%3A%2F%2Fwww.xuanyusong.com%2Farchives%2Fcategory%2Funity%2Funity3deditor<u=http%3A%2F%2Fwww.xuanyusong.com%2Farchives%2F3711&lunum=6&n=92004029_cpr&pcs=1920x946&pis=10000x10000&ps=369x1329&psr=1920x1080&pss=1920x409&qn=2c588d3b116eaffc&rad=&rsi0=300&rsi1=250&rsi5=4&rss0=%23FFFFFF&rss1=%23FFFFFF&rss2=%230000FF&rss3=%23444444&rss4=%23008000&rss5=&rss6=%23e10900&rss7=&scale=&skin=&td_id=1121907&tn=text_default_300_250&tpr=1447385594307&ts=1&version=2.0&xuanting=0&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u1121907&ti=Unity3D%E7%A0%94%E7%A9%B6%E9%99%A2%E7%BC%96%E8%BE%91%E5%99%A8%E4%B9%8B%E8%84%9A%E6%9C%AC%E7%94%9F%E6%88%90Preset%20Libraries%EF%BC%88%E5%8D%81%E5%9B%9B%EF%BC%89%20%7C%20%E9%9B%A8%E6%9D%BEMOMO%E7%A8%8B%E5%BA%8F%E7%A0%94%E7%A9%B6%E9%99%A2&tt=1447385594265.43.70.73" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="margin: 0px; padding: 0px; font-family: inherit;"></iframe>
Preset Libraries它干的事就是把若干个颜色值保存起来。我们都知道颜色值用rgba来保存的。这样拷贝起来就很麻烦了,如果说我把每个界面的颜色都做成模板,需要设置颜色的时候在模板里选择多好?unity提供了Preset Libraries 就可以达到这个需求。 http://docs.unity3d.com/Manual/PresetLibraries.html。
但是问题来了,这东西不能通过脚本来自动化完成,总不能手动的一个一个设置吧。。。我想做的就是用脚本来创建Preset Libraries,找了半天也没找到官方提供的API。那么没办法只能自己来了。直接上代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | using UnityEngine; using UnityEditor; using System; using System.Collections.Generic; public class Test { public class ColorData { public string name; public Color color; } [MenuItem("Tool/Creat Color")] static void Build () { //复制一份新的模板到newColorPath目录下 string templateColorPath="Assets/Template/color.colors"; string newColorPath="Assets/Editor/界面1.colors"; AssetDatabase.DeleteAsset(newColorPath); AssetDatabase.CopyAsset(templateColorPath,newColorPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //这里我写了两条临时测试数据 List<ColorData>colorList = new List<ColorData>(){ new ColorData(){name ="按钮样式1颜色",color = Color.green}, new ColorData(){name ="按钮样式2颜色", color =new Color(0.1f,0.1f,0.1f,0.1f)} }; UnityEngine.Object newColor = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(newColorPath); SerializedObject serializedObject = new SerializedObject(newColor); SerializedProperty property = serializedObject.FindProperty("m_Presets"); property.ClearArray(); //把我的测试数据写进去 for(int i =0; i< colorList.Count; i++){ property.InsertArrayElementAtIndex(i); SerializedProperty colorsProperty = property.GetArrayElementAtIndex(i); colorsProperty.FindPropertyRelative("m_Name").stringValue = colorList[i].name; colorsProperty.FindPropertyRelative("m_Color").colorValue = colorList[i].color; } //保存 serializedObject.ApplyModifiedProperties(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } |
生成出来之后,在选择颜色的时候就可以设置模板里的颜色啦。
本文固定链接: http://www.xuanyusong.com/archives/3711
转载请注明: 雨松MOMO 2015年10月29日 于 雨松MOMO程序研究院 发表
相关文章推荐
- unity 打开asset自定义处理
- #你好Unity3D#手机上的路径(来自我的长微博)
- #你好Unity3D#避免玩家作弊(来自我的长微博)
- Unity3D研究院之处理摄像机与角色之间被挡时的局部透明效果
- Unity研究院之提前获取粒子特效的播放时长
- Unity3D研究院之监听Project视图结构变化的事件
- Unity人工智能学习—躲避规则障碍一
- VS调试Unity3D脚本
- unity 菜单栏添加新菜单
- Unity3D脚本自动添加tag和Layer
- Unity UGUI-ScrollBar的滑块 设置为不会根据内容 自动拉伸
- Unity UGUI-ScrollRect的Mask 对动态字体无效
- cardboard sdk for unity 系统分析 - 属性行为分析CardBoard类
- cardboard sdk for unity 系统分析 - 对像与类
- [Unity3D] 通过修改PlayMaker源代码实现进化版的FSM
- 搭建CARDBOARD+ANDROID+unity3d的VR开发环境
- Unity3D中隐藏与显示物体的一些操作
- 猫都能学会的Unity3D Shader入门指南(二)
- 猫都能学会的Unity3D Shader入门指南(一)
- Surface Shader Examples 详解