Skip to content

Commit

Permalink
update third party
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Aug 5, 2018
1 parent e1b55f4 commit 72d7d9c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 25 deletions.
43 changes: 28 additions & 15 deletions Assets/ThirdParty/UnityCommon/Editor/PackageExporter.cs
@@ -1,6 +1,4 @@
// Copyright 2012-2018 Elringus (Artyom Sovetnikov). All Rights Reserved.

using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -22,6 +20,8 @@ public interface IProcessor

private static string PackageName { get { return PlayerPrefs.GetString(prefsPrefix + "PackageName"); } set { PlayerPrefs.SetString(prefsPrefix + "PackageName", value); } }
private static string Copyright { get { return PlayerPrefs.GetString(prefsPrefix + "Copyright"); } set { PlayerPrefs.SetString(prefsPrefix + "Copyright", value); } }
private static string LicenseFilePath { get { return PlayerPrefs.GetString(prefsPrefix + "LicenseFilePath"); } set { PlayerPrefs.SetString(prefsPrefix + "LicenseFilePath", value); } }
private static string LicenseAssetPath { get { return AssetsPath + "/" + defaultLicenseFileName + ".txt"; } }
private static string AssetsPath { get { return "Assets/" + PackageName; } }
private static string OutputPath { get { return PlayerPrefs.GetString(prefsPrefix + "OutputPath"); } set { PlayerPrefs.SetString(prefsPrefix + "OutputPath", value); } }
private static string OutputFileName { get { return PackageName; } }
Expand All @@ -31,6 +31,7 @@ public interface IProcessor

private const string prefsPrefix = "PackageExporter.";
private const string autoRefreshKey = "kAutoRefresh";
private const string defaultLicenseFileName = "LICENSE";

private static Dictionary<string, string> modifiedScripts = new Dictionary<string, string>();
private static List<UnityEngine.Object> ignoredAssets = new List<UnityEngine.Object>();
Expand All @@ -52,6 +53,8 @@ private void Awake ()
{
if (string.IsNullOrEmpty(PackageName))
PackageName = Application.productName;
if (string.IsNullOrEmpty(LicenseFilePath))
LicenseFilePath = Application.dataPath.Replace("Assets", "") + defaultLicenseFileName;
}

private void OnEnable ()
Expand Down Expand Up @@ -80,6 +83,7 @@ private void OnGUI ()
EditorGUILayout.Space();
PackageName = EditorGUILayout.TextField("Package Name", PackageName);
Copyright = EditorGUILayout.TextField("Copyright Notice", Copyright);
LicenseFilePath = EditorGUILayout.TextField("License File Path", LicenseFilePath);
using (new EditorGUILayout.HorizontalScope())
{
OutputPath = EditorGUILayout.TextField("Output Path", OutputPath);
Expand Down Expand Up @@ -130,10 +134,17 @@ private static bool IsAssetIgnored (string assetPath)

private static void ExportPackageImpl ()
{
DisplayProgressBar("Preparing for export...", 0f);

// Disable auto recompile.
var wasAutoRefreshEnabled = EditorPrefs.GetBool(autoRefreshKey);
EditorPrefs.SetBool(autoRefreshKey, false);

// Load a temp scene and unload assets to prevent reference errors.
sceneSetup = EditorSceneManager.GetSceneManagerSetup();
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
EditorUtility.UnloadUnusedAssetsImmediate(true);

DisplayProgressBar("Pre-processing assets...", 0f);
var processors = GetProcessors();
foreach (var proc in processors)
Expand All @@ -147,15 +158,17 @@ private static void ExportPackageImpl ()
DisplayProgressBar("Hiding ignored assets...", .1f);
if (IsAnyPathsIgnored)
{
// Load a temp scene to prevent errors when hiding source assets.
sceneSetup = EditorSceneManager.GetSceneManagerSetup();
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
foreach (var path in ignoredPaths)
{
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
File.SetAttributes(path + ".meta", File.GetAttributes(path) | FileAttributes.Hidden);
}
AssetDatabase.Refresh();
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
}

// Add license file.
var needToAddLicense = File.Exists(LicenseFilePath);
if (needToAddLicense)
{
File.Copy(LicenseFilePath, LicenseAssetPath);
AssetDatabase.ImportAsset(LicenseAssetPath, ImportAssetOptions.ForceSynchronousImport);
}

// Modify scripts (namespace and copyright).
Expand Down Expand Up @@ -198,24 +211,24 @@ private static void ExportPackageImpl ()
File.WriteAllText(modifiedScript.Key, modifiedScript.Value, Encoding.UTF8);
}

// Remove previously added license asset.
if (needToAddLicense) AssetDatabase.DeleteAsset(LicenseAssetPath);

// Un-hide ignored assets.
DisplayProgressBar("Un-hiding ignored assets...", .95f);
if (IsAnyPathsIgnored)
{
foreach (var path in ignoredPaths)
{
File.SetAttributes(path, File.GetAttributes(path) & ~FileAttributes.Hidden);
File.SetAttributes(path + ".meta", File.GetAttributes(path) & ~FileAttributes.Hidden);
}
AssetDatabase.Refresh();
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
}

DisplayProgressBar("Post-processing assets...", 1f);
foreach (var proc in processors)
proc.OnPackagePostProcess();

EditorPrefs.SetBool(autoRefreshKey, wasAutoRefreshEnabled);
if (IsAnyPathsIgnored) EditorSceneManager.RestoreSceneManagerSetup(sceneSetup);
EditorSceneManager.RestoreSceneManagerSetup(sceneSetup);

EditorUtility.ClearProgressBar();
}
Expand Down
21 changes: 21 additions & 0 deletions Assets/ThirdParty/UnityCommon/LICENSE.txt
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2012-2018 Artyom Sovetnikov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions Assets/ThirdParty/UnityCommon/LICENSE.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Assets/ThirdParty/UnityCommon/Runtime/FpsDisplay.cs
@@ -1,6 +1,4 @@
// Copyright 2012-2018 Elringus (Artyom Sovetnikov). All Rights Reserved.

using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

Expand Down
4 changes: 1 addition & 3 deletions Assets/ThirdParty/UnityCommon/Runtime/SceneSwitcher.cs
@@ -1,6 +1,4 @@
// Copyright 2012-2018 Elringus (Artyom Sovetnikov). All Rights Reserved.

using UnityEngine;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace UnityCommon
Expand Down
4 changes: 1 addition & 3 deletions Assets/ThirdParty/UnityCommon/Runtime/Utils/StringUtils.cs
@@ -1,6 +1,4 @@
// Copyright 2012-2018 Elringus (Artyom Sovetnikov). All Rights Reserved.

using System;
using System;
using UnityEngine;

namespace UnityCommon
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
@@ -1 +1 @@
m_EditorVersion: 2018.2.1f1
m_EditorVersion: 2018.2.2f1

0 comments on commit 72d7d9c

Please sign in to comment.