Example #1
0
        private void TryDrawProjectReferenceButton()
        {
            if (!_projectAsset)
            {
                DrawBreakingError();
                return;
            }

            GUIContent buttonContent = new GUIContent()
            {
                text  = "LDtk Project",
                image = LDtkIconUtility.LoadProjectFileIcon()
            };


            using (new EditorGUILayout.HorizontalScope())
            {
                using (new EditorGUI.DisabledScope(true))
                {
                    using (new LDtkIconSizeScope(16))
                    {
                        EditorGUILayout.ObjectField(buttonContent, _projectAsset, typeof(GameObject), false);
                    }
                }

                if (GUILayout.Button(ReimportProjectButton, GUILayout.Width(105)))
                {
                    string assetPath = AssetDatabase.GetAssetPath(_projectAsset);
                    AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                }
            }
        }
        public void Import(LdtkJson json)
        {
            //set the data class's levels correctly, regardless if they are external levels or not
            json.Levels = GetLevelData(json);


            LDtkProjectBuilder builder = new LDtkProjectBuilder(_importer, json);

            builder.BuildProject();
            GameObject projectGameObject = builder.RootObject;

            if (projectGameObject == null)
            {
                _importer.ImportContext.LogImportError("LDtk: Project GameObject null, not building correctly");
                return;
            }

            _importer.ImportContext.AddObjectToAsset("rootGameObject", projectGameObject, LDtkIconUtility.LoadProjectFileIcon());
            _importer.ImportContext.SetMainObject(projectGameObject);
        }