Выбираем в меню сверху "BuildAndUPLOAD/StandaloneServer",
билдит, архивирует папку с билдом в .zip, заливает на фтп.
Скрипт кладем в папку Editor в проекте,
меняем адрес, логин и пароль для фтп.
К посту приаттачен архив, там длл который кладем в папку Editor/Plugins/ в проекте.
Синтаксис:
Используется csharp
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Net;
using System.IO;
using Ionic.Zip;
public class BuildFacility
{
[MenuItem("BuildAndUPLOAD/StandaloneServer")]
public static void MyBuild5()
{
Debug.Log("started build: " + System.DateTime.Now +" Please Wait...");
string[] levels = new string[] { "Assets/scenes/ServerGame.unity" };
string build_name = "ServerBuild";
string build_path = "server_autobuilds/";
//1. билдим
BuildPipeline.BuildPlayer(levels, "server_autobuilds/"+build_name+".exe", BuildTarget.StandaloneWindows, BuildOptions.None);
string zip_name = build_name + ".zip";
//2. архивируем (используем DotNetZip)
Compress(build_path, zip_name);
//3. заливаем на сервак
string fp = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + zip_name;
ftpfile("/"+zip_name, fp);
Debug.Log("finished build: " + System.DateTime.Now);
}
static void Compress(string build_path, string zip_name)
{
using (ZipFile zip = new ZipFile())
{
zip.UseUnicodeAsNecessary = true; // utf-8
string uncompressed_file_path = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + build_path;
string p = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + zip_name;
zip.AddDirectory(uncompressed_file_path);
zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
zip.Save(p);
}
}
public static void ftpfile(string ftpfilepath, string inputfilepath)
{
string ftphost = "ip";
string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential("login", "password");
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(inputfilepath);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
}
using UnityEditor;
using System.Collections;
using System.Net;
using System.IO;
using Ionic.Zip;
public class BuildFacility
{
[MenuItem("BuildAndUPLOAD/StandaloneServer")]
public static void MyBuild5()
{
Debug.Log("started build: " + System.DateTime.Now +" Please Wait...");
string[] levels = new string[] { "Assets/scenes/ServerGame.unity" };
string build_name = "ServerBuild";
string build_path = "server_autobuilds/";
//1. билдим
BuildPipeline.BuildPlayer(levels, "server_autobuilds/"+build_name+".exe", BuildTarget.StandaloneWindows, BuildOptions.None);
string zip_name = build_name + ".zip";
//2. архивируем (используем DotNetZip)
Compress(build_path, zip_name);
//3. заливаем на сервак
string fp = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + zip_name;
ftpfile("/"+zip_name, fp);
Debug.Log("finished build: " + System.DateTime.Now);
}
static void Compress(string build_path, string zip_name)
{
using (ZipFile zip = new ZipFile())
{
zip.UseUnicodeAsNecessary = true; // utf-8
string uncompressed_file_path = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + build_path;
string p = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/" + zip_name;
zip.AddDirectory(uncompressed_file_path);
zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
zip.Save(p);
}
}
public static void ftpfile(string ftpfilepath, string inputfilepath)
{
string ftphost = "ip";
string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential("login", "password");
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(inputfilepath);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
}