Ejemplo n.º 1
0
        private void UpdateTemplateDescriptionUI(SceneTemplateInfo newSceneTemplateInfo)
        {
            // Text info
            var sceneTemplateTitleLabel = rootVisualElement.Q <Label>(k_SceneTemplateTitleLabelName);

            if (sceneTemplateTitleLabel != null && newSceneTemplateInfo != null)
            {
                sceneTemplateTitleLabel.text = newSceneTemplateInfo.name;
            }

            var sceneTemplatePathLabel   = rootVisualElement.Q <Label>(k_SceneTemplatePathName);
            var sceneTemplatePathSection = rootVisualElement.Q(k_SceneTemplatePathSection);

            if (sceneTemplatePathLabel != null && newSceneTemplateInfo != null && sceneTemplatePathSection != null)
            {
                sceneTemplatePathLabel.text      = newSceneTemplateInfo.assetPath;
                sceneTemplatePathSection.visible = !string.IsNullOrEmpty(newSceneTemplateInfo.assetPath);
            }

            var sceneTemplateDescriptionLabel   = rootVisualElement.Q <Label>(k_SceneTemplateDescriptionName);
            var sceneTemplateDescriptionSection = rootVisualElement.Q(k_SceneTemplateDescriptionSection);

            if (sceneTemplateDescriptionLabel != null && newSceneTemplateInfo != null && sceneTemplateDescriptionSection != null)
            {
                sceneTemplateDescriptionLabel.text      = newSceneTemplateInfo.description;
                sceneTemplateDescriptionSection.visible = !string.IsNullOrEmpty(newSceneTemplateInfo.description);
            }

            // Thumbnail
            m_PreviewArea?.UpdatePreview(newSceneTemplateInfo?.thumbnail, newSceneTemplateInfo?.badge);
            m_PreviewArea?.UpdatePreviewAreaSize();
        }
Ejemplo n.º 2
0
        private void LoadSessionPreferences()
        {
            var lastTemplateAssetPath = EditorPrefs.GetString(GetKeyName(nameof(m_LastSelectedTemplate)), null);

            if (!string.IsNullOrEmpty(lastTemplateAssetPath))
            {
                m_LastSelectedTemplate = m_SceneTemplateInfos.Find(info => info.Equals(lastTemplateAssetPath));
            }

            if (m_LastSelectedTemplate == null)
            {
                m_LastSelectedTemplate = GetDefaultSceneTemplateInfo();
            }
        }
Ejemplo n.º 3
0
        internal void OnEditTemplate(SceneTemplateInfo sceneTemplateInfo)
        {
            if (sceneTemplateInfo == null)
            {
                return;
            }
            if (sceneTemplateInfo.IsInMemoryScene)
            {
                return;
            }

            // Select the asset
            var templateAsset = AssetDatabase.LoadMainAssetAtPath(sceneTemplateInfo.assetPath);

            Selection.SetActiveObjectWithContext(templateAsset, null);

            // Close the dialog
            Close();
        }
Ejemplo n.º 4
0
        private void UpdatePreviewAreaSize(SceneTemplateInfo info = null)
        {
            info = info ?? m_LastSelectedTemplate;
            if (m_PreviewArea == null)
            {
                return;
            }

            if (info == null || info.thumbnail == null || info.thumbnail.height > info.thumbnail.width)
            {
                m_PreviewArea.Element.style.height = Length.Percent(50);
                return;
            }

            var thumbnail   = info.thumbnail;
            var aspectRatio = (float)thumbnail.height / (float)thumbnail.width;
            var width       = m_PreviewArea.Element.worldBound.width;
            var newHeight   = m_PreviewArea.Element.worldBound.width * aspectRatio;

            // Debug.Log($"Preview size: {info.name} width: {info.thumbnail.width} height:{info.thumbnail.height} ratio: {aspectRatio} AreaW: {width} NewHeigth: {newHeight}");
            m_PreviewArea.Element.style.height = newHeight;
        }
Ejemplo n.º 5
0
        private void OnCreateNewScene(SceneTemplateInfo sceneTemplateInfo)
        {
            if (sceneTemplateInfo == null)
            {
                return;
            }

            var loadAdditive = rootVisualElement.Q(k_SceneTemplateCreateAdditiveButtonName) as Toggle;

            SceneTemplateService.newSceneTemplateInstantiating += TemplateInstantiating;
            try
            {
                sceneTemplateInfo.onCreateCallback(loadAdditive.value);
                if (sceneTemplateInfo.IsInMemoryScene)
                {
                    Close();
                }
            }
            finally
            {
                SceneTemplateService.newSceneTemplateInstantiating -= TemplateInstantiating;
            }
        }
Ejemplo n.º 6
0
 private void SetLastSelectedTemplate(SceneTemplateInfo info)
 {
     m_LastSelectedTemplate = info;
     EditorPrefs.SetString(GetKeyName(nameof(m_LastSelectedTemplate)), info.ValidPath);
 }