Skip to content

Initialize Project Script

mika edited this page Jul 27, 2022 · 5 revisions

(27.07.2022) Available currently for DEV branch only)
You can use custom project initialization scripts (these are copied into New Project and executed at first launch).

GUIDE

  • Take example script below or more recent versions from https://github.com/unitycoder/UnityInitializeProject/tree/main/Assets/Editor
  • Copy "InitializeProject.cs" file into UnityLauncherPro/Scripts/ folder
    image
  • Enable init script from Settings tab (and check that filename matches):
    image
  • Now Create New Project and when launched, it should execute this script (using editor argument: -executeMethod UnityLauncherProTools.InitializeProject.Init)
  • NOTE: if you use your own scripts, make sure the NameSpace is "UnityLauncherProTools", Class is "InitializeProject", and Method is "Init"

EXAMPLE SCRIPT (creates initial folders for new project)

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace UnityLauncherProTools
{
    public class InitializeProject
    {
        // settings
        static string[] folders = new string[] { "Fonts", "Materials", "Models", "Prefabs", "Scenes", "Scripts", "Shaders", "Sounds", "Textures" };

        static string assetsFolder;

        [MenuItem("Tools/Initialize Project")]
        public static void Init()
        {
            assetsFolder = Application.dataPath;

            CreateFolders();
            // TODO adjust project settings, linear, company name
            // TODO remove extra packages
            // TODO setup light settings
            // TODO adjust mainscene: camera pos, skybox off?
            // TODO save mainscene
            // TODO add mainscene to build scenes list
            // TODO adjust quality settings (but only in mobile?)

            // TODO self destruct this editor script file?

            // refresh folder
            AssetDatabase.Refresh();
        }

        static void CreateFolders()
        {
            // create each folder if it doesnt exists
            foreach (string folder in folders)
            {
                if (!Directory.Exists(assetsFolder + "/" + folder))
                {
                    Directory.CreateDirectory(assetsFolder + "/" + folder);
                }
            }
        }
    }
}
Clone this wiki locally