Ejemplo n.º 1
0
 public LE_CmdCreateTerrain(LE_LogicTerrain p_logicTerrain, int p_terrainBaseTextureIndex, TerrainData p_terrainData)
 {
     m_logicTerrain            = p_logicTerrain;
     m_terrainData             = p_terrainData;
     m_terrainBaseTextureIndex = p_terrainBaseTextureIndex;
 }
Ejemplo n.º 2
0
        // some of the content in this method must be called in the first update and cannot be initialized in the start function
        private void Initialize_InFirstUpdate()
        {
            LE_ConfigLevel LEConfLevel = GetComponentInChildren <LE_ConfigLevel>();

            if (LEConfLevel == null)
            {
                Debug.LogError("LE_LevelEditorMain: a LE_ConfigLevel component must be added to the game object with the LE_LevelEditorMain script!");
                LEConfLevel = gameObject.AddComponent <LE_ConfigLevel>();
            }

            Camera           cam           = Cam;
            LE_ConfigTerrain LEConfTerrain = GetComponentInChildren <LE_ConfigTerrain>();

            // check further parameters that have been set in Start of other scripts
            if (LE_GUIInterface.Instance.delegates.IsCursorOverUI == null)
            {
                Debug.LogError("LE_LevelEditorMain: you have not setup LE_GUIInterface.delegates.IsCursorOverUI. Terrain might be edited behind UI while the user interacts with the UI, same is true for object placement!");
            }

            // initialize terrain logic
            if (IS_TERRAIN_EDITOR)
            {
                // init 3d UI
                m_GUI3dTerrain = gameObject.AddComponent <LE_GUI3dTerrain>();
                m_GUI3d.Add(m_GUI3dTerrain);

                // init default terrain
                InitializeDefaultTerrain(LEConfTerrain);

                // init logic
                m_logicTerrain = new LE_LogicTerrain(LEConfTerrain, m_GUI3dTerrain);
                m_logic.Add(m_logicTerrain);
            }
            else if (LEConfTerrain.CustomDefaultTerrain != null)
            {
                Debug.LogWarning("LE_LevelEditorMain: IS_TERRAIN_EDITOR is set to 'false', but you have provided a value for LE_ConfigTerrain.CustomDefaultTerrain! The value will be ignored!");
            }

            // initialize level logic
            m_logicLevel = new LE_LogicLevel(
                LEConfLevel,
                m_GUI3dTerrain,
                m_GUI3dObject,
                IS_OBLIQUE_FOCUS_CENTERING,
                LEConfTerrain.TerrainTextureConfig.TERRAIN_TEXTURES,
                LEConfTerrain.TerrainTextureConfig.TERRAIN_TEXTURE_SIZES,
                LEConfTerrain.TerrainTextureConfig.TERRAIN_TEXTURE_OFFSETS);
            m_logic.Add(m_logicLevel);

            // initialize object logic
            if (IS_OBJECT_EDITOR)
            {
                m_logic.Add(new LE_LogicObjects(m_GUI3dObject, ROOT_OBJECT_MAP));
            }

            // initialize camera gizmo
            if (cam != null && IS_WITH_CAMERA_PERSPECTIVE_GIZMO)
            {
                if (LE_GUIInterface.Instance.delegates.GetCameraPerspectiveGizmoRightPixelOffset != null)
                {
                    // calculate the screen rect of the camera perspective gizmo (used later for mouse over UI calculation)
                    const float relativeSize = 0.2f;
                    float       rectW        = relativeSize * (float)Screen.width / cam.aspect;
                    float       rectH        = relativeSize * (float)Screen.height;
                    m_perspectiveGizmoRect = new Rect(Screen.width - LE_GUIInterface.Instance.delegates.GetCameraPerspectiveGizmoRightPixelOffset() - rectW, 0f, rectW, rectH);
                    if (string.IsNullOrEmpty(LayerMask.LayerToName(CAMERA_PERSPECTIVE_GIZMO_LAYER)))
                    {
                        Debug.LogWarning("LE_LevelEditorMain: Inspector property 'CAMERA_PERSPECTIVE_GIZMO_LAYER' is set to '" + CAMERA_PERSPECTIVE_GIZMO_LAYER + "', but this layer has no name in 'Tags & Layers' set. Please set the name of this layer to 'CameraPerspectiveGizmo' or change the value of the 'CAMERA_PERSPECTIVE_GIZMO_LAYER' property! To open the 'Tags & Layers' manager select any game object, in the inspector click on the layer drop down at top right then click on 'Add Layer...'.");
                    }
                    else if (LayerMask.LayerToName(CAMERA_PERSPECTIVE_GIZMO_LAYER) != "CameraPerspectiveGizmo")
                    {
                        Debug.LogWarning("LE_LevelEditorMain: Inspector property 'CAMERA_PERSPECTIVE_GIZMO_LAYER' is set to '" + CAMERA_PERSPECTIVE_GIZMO_LAYER + "', but the name of this layer is '" + LayerMask.LayerToName(CAMERA_PERSPECTIVE_GIZMO_LAYER) + "'. Is this intended? If not please set the name of this layer to 'CameraPerspectiveGizmo' or change the value of the 'CAMERA_PERSPECTIVE_GIZMO_LAYER' property! To open the 'Tags & Layers' manager select any game object, in the inspector click on the layer drop down at top right then click on 'Add Layer...'.");
                    }
                    // create and setup the camera perspective gizmo
                    m_cameraPerspectiveGizmo = CPG_CameraPerspectiveGizmo.Create(cam, CAMERA_PERSPECTIVE_GIZMO_LAYER);
                    if (m_cameraPerspectiveGizmo != null)
                    {
                        // move the camera perspective gizmo far away (it will not be rendered anyway, but this is needed to prevent collision)
                        m_cameraPerspectiveGizmo.transform.position = Vector3.down * -10000f;
                        // set ortho offset of the gizmo
                        m_cameraPerspectiveGizmo.OrthoOffset = cam.farClipPlane * 0.2f;
                        // make sure that the main camera will not render the gizmo
                        cam.cullingMask = cam.cullingMask & ~(1 << CAMERA_PERSPECTIVE_GIZMO_LAYER);
                        // set position of the gizmo
                        m_cameraPerspectiveGizmo.RelativeScreenSize = relativeSize;
                        float rightMenuOffset = LE_GUIInterface.Instance.delegates.GetCameraPerspectiveGizmoRightPixelOffset() / (float)Screen.width;
                        m_cameraPerspectiveGizmo.RelativeScreenPos = new Vector2(1f - relativeSize * 0.5f / cam.aspect - rightMenuOffset, 1f - relativeSize * 0.5f);
                        // register for events of the camera perspective gizmo
                        m_cameraPerspectiveGizmo.m_onBeforeSwitchToOrthographic += OnCameraPerspectiveSwitchToOrthographic;
                        m_cameraPerspectiveGizmo.m_onAfterSwitchToPerspective   += OnCameraPerspectiveSwitchToPerspective;
                    }
                }
                else
                {
                    Debug.LogError("LE_LevelEditorMain: LE_GUIInterface.delegates.GetCameraPerspectiveGizmoRightPixelOffset was not set from the UI scripts! The camera perspective gizmo cannot be placed to the right screen position! To set this delegate use 'LE_GUIInterface.Instance.delegates.GetCameraPerspectiveGizmoRightPixelOffset = ...' in one of the Start functions of your scripts!");
                }
            }

            // apply an oblique camera projection to bring focused objects to the middle of the visible screen
            // instead of being in the middle of the rendered screen, which means close to the right menu UI
            if (IS_OBLIQUE_FOCUS_CENTERING && !SetObliqueFocusProjectionMatrix(true))
            {
                Debug.LogError("LE_LevelEditorMain: IS_OBLIQUE_FOCUS_CENTERING is true, but you have not provided the LE_GUIInterface.delegates.GetObliqueCameraPerspectiveRightPixelOffset delegate! Provide it to bring focused objects in the center of the visible (not covered by UI) screen area!");
            }
        }
Ejemplo n.º 3
0
 public LE_CmdAddTerrainTexture(LE_LogicTerrain p_logicTerrain, Texture2D p_texToAdd)
 {
     m_logicTerrain = p_logicTerrain;
     m_texToAdd     = p_texToAdd;
 }