查看: 593|回复: 0
打印 上一主题 下一主题

[其他] 生成cubemap的代码

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53480
精华
316

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-11-21 07:17:14 |只看该作者 |倒序浏览

using UnityEngine;  
using UnityEditor;  
using System.Collections;  

public class GenerateCubeMapTool : EditorWindow {  
       
        private Cubemap cubemap;  
       
        private GameObject obj;  
       
        //  // Use this for initialization  
        //  void Start () {  
        //  }  
       
        // Update is called once per frame  
        void Update () {  
               
        }  
       
        [MenuItem("Tools/GenerateCubeMapTool")]  
        static void Init () {  
                //      GenerateCubeMapTool window = (GenerateCubeMapTool) EditorWindow.GetWindow(typeof(GenerateCubeMapTool));  
                EditorWindow.GetWindow (typeof(GenerateCubeMapTool));  
        }  
       
        void OnGUI () {  
               
                EditorGUILayout.Space ();  
               
                this.cubemap = (Cubemap) EditorGUILayout.ObjectField (this.cubemap, typeof(Cubemap), false);  
               
                EditorGUILayout.Space ();  
               
                if ( GUILayout.Button ("Select Camera Object in Scene")) {  
                       
                        if (Selection.activeGameObject) {  
                                this.obj = Selection.activeGameObject;  
                        }  
                       
                }  
               
                if (this.obj != null) {  
                        EditorGUILayout.HelpBox ("obj name : " + this.obj.name, MessageType.None);  
                }  
               
                EditorGUILayout.Space ();  
               
                if (this.obj != null) {  
                        if (GUILayout.Button ("Render to Cubemap")) {  
                               
                                this.renderToCubeMap();  
                        }  
                }  
        }  
       
       
        void renderToCubeMap() {  
               
                if (this.cubemap != null && this.obj.camera != null) {  
                       
                        this.obj.camera.RenderToCubemap(this.cubemap);  
                }  
                else if (this.obj.camera == null) {  
                        Debug.Log("Please make sure the gameObject has the camera component");  
                }  
                else if (this.cubemap == null) {  
                        Debug.Log("Please select the cubemap, and try again.");  
                }  
        }  
}

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-9-22 18:17 , Processed in 0.175365 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部