예제 #1
0
        /// <summary>
        /// 创建关卡
        /// </summary>
        private void CreateScene()
        {
            if (!Directory.Exists(Utils.GetSceneDirectory(m_sceneName)))
            {
                Directory.CreateDirectory(Utils.GetSceneDirectory(m_sceneName));
            }

            // 创建空场景
            EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

            // 创建网格
            GameObject templateGo = GameObject.Find(typeof(TemplateGrid).Name);

            if (templateGo != null)
            {
                DestroyImmediate(templateGo);
            }
            templateGo       = new GameObject();
            templateGo.layer = LayerMask.NameToLayer(typeof(TemplateGrid).Name);
            templateGo.name  = typeof(TemplateGrid).Name;
            TemplateGrid templateGrid = templateGo.AddComponent <TemplateGrid>();

            templateGrid.width  = 20;
            templateGrid.lenght = 20;
            templateGrid.height = 0;

            // environment
            GameObject environmentGo = GameObject.Find(typeof(Environment).Name);

            if (environmentGo != null)
            {
                DestroyImmediate(environmentGo);
            }
            environmentGo      = new GameObject();
            environmentGo.name = typeof(Environment).Name;
            var environment = environmentGo.AddComponent <Environment>();

            environment.sceneName = Utils.ToUpperFirstChar(m_sceneName);

            // navmesh
            GameObject navmeshGo = new GameObject();

            navmeshGo.transform.position = Vector3.zero;
            navmeshGo.name = "Navmesh";

            var navmesh = navmeshGo.AddComponent <NavMeshSurface>();

            navmesh.collectObjects = CollectObjects.All;
            //navmesh.layerMask = 1 << LayerMask.NameToLayer(LevelFunctionType.Ground.ToString());

            EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), Utils.GetScenePath(m_sceneName));

            Initialize();
        }
예제 #2
0
        protected override void OnInitialize()
        {
            // 创建工具
            if (m_selectorTools == null)
            {
                m_selectorTools = new SelectorTools();
            }
            if (m_brushTools == null)
            {
                m_brushTools = new BrushTools();
            }
            if (m_suckerTools == null)
            {
                m_suckerTools = new SuckerTools();
            }
            if (m_eraseTools == null)
            {
                m_eraseTools = new EraseTools();
            }

            // 工具事件注册
            m_selectorTools.toolsEventHandler -= OnSelectorToolsEventHandler;
            m_selectorTools.toolsEventHandler += OnSelectorToolsEventHandler;

            m_brushTools.toolsEventHandler -= OnBrushToolsEventHandler;
            m_brushTools.toolsEventHandler += OnBrushToolsEventHandler;

            m_suckerTools.toolsEventHandler -= OnSuckerToolsEventHandler;
            m_suckerTools.toolsEventHandler += OnSuckerToolsEventHandler;

            m_eraseTools.toolsEventHandler -= OnEraseToolsEventHandler;
            m_eraseTools.toolsEventHandler += OnEraseToolsEventHandler;

            // 创建窗口
            if (m_brushWindow == null)
            {
                m_brushWindow = new BrushWindow();
            }
            if (m_selecterWindow == null)
            {
                m_selecterWindow = new SelectorWindow();
            }

            // 模版格子
            if (m_templateGrid == null)
            {
                m_templateGrid = GameObject.Find(typeof(TemplateGrid).Name).gameObject.GetComponent <TemplateGrid>();
            }
            // 注册场景事件
            m_templateGrid.SceneRenderHandler -= OnSceneRender;
            m_templateGrid.SceneRenderHandler += OnSceneRender;

            // window id
            m_toolsWindowId     = EUI.GetWindowId();
            m_operationWindowId = EUI.GetWindowId();

            // GUILayoutOption
            m_layoutWidth  = GUILayout.Width(SettingManager.Inst.Setting.sceneToolsIconSize);
            m_layoutHeight = GUILayout.Height(SettingManager.Inst.Setting.sceneToolsIconSize);

            // 场景视角设置
            m_sceneViewQuaIndex = 0;
        }