Skip to content

Instantly share code, notes, and snippets.

@EloiStree
Last active July 20, 2020 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EloiStree/27951f13eec1f45b0130d720d0f1f1bb to your computer and use it in GitHub Desktop.
Save EloiStree/27951f13eec1f45b0130d720d0f1f1bb to your computer and use it in GitHub Desktop.
// Just drag me in your project to install the Unity Package Facilitator and Git Utility.
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
public class
Package : MonoBehaviour
{
public static PackageValue[] m_wantedDependencies = new PackageValue[] {
new PackageValue("be.eloistree.unitypackagefacilitator", "https://github.com/eloistree/2019_07_21_UnityPackageFacilitator.git#InDevelopment"),
new PackageValue("be.eloistree.quickgitutility","https://github.com/eloistree/2019_07_21_QuickGitUtility.git#InDevelopment"),
new PackageValue("be.eloistree.license","https://github.com/EloiStree/GeneralLicense.git")
};
private static void WhatToDoWhenDrop()
{
string manifestPath = Application.dataPath + "/../Packages/manifest.json";
string packageFile = File.ReadAllText(manifestPath);
string packageToAdd = "";
for (int i = 0; i < m_wantedDependencies.Length; i++)
{
string toAdd = string.Format("\"{0}\": \"{1}\"", m_wantedDependencies[i].m_id, m_wantedDependencies[i].m_version);
if (packageFile.IndexOf(toAdd) < 0)
{
packageToAdd = string.Format("\n {0}, ", toAdd);
packageFile = packageFile.Replace("\"dependencies\": {", "\"dependencies\": {" + packageToAdd);
}
}
File.WriteAllText(manifestPath, packageFile);
AssetDatabase.Refresh();
}
public class PackageValue
{
public string m_id = "";
public string m_version = "0.0.1";
public PackageValue(string id, string version)
{
this.m_id = id;
this.m_version = version;
}
}
#region GRENADE SCRIPT
public static bool m_deleteAfterUse = false;
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
if (IsFileAtProjectRoot())
{
Debug.Log("> BOOM : " + GetFileName());
WhatToDoWhenDrop();
if (m_deleteAfterUse)
{
File.Delete(GetFilePath());
}
else
{
string filePath = GetFilePath();
string dir = Application.dataPath + "/GrenadeScripts/Used";
Directory.CreateDirectory(dir);
File.Move(filePath, dir + "/" + GetFileName());
AssetDatabase.Refresh();
}
}
}
private static bool IsFileAtProjectRoot()
{
return File.Exists(Application.dataPath + "/" + GetFileName());
}
private static string GetFileName()
{
return Path.GetFileName(new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName());
}
private static string GetFilePath()
{
return new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
}
#endregion
}
#endif
// Just drag me in your project to install the Unity Package Facilitator and Git Utility.
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
public class
Package : MonoBehaviour
{
public static PackageValue[] m_wantedDependencies = new PackageValue[] {
new PackageValue("be.eloistree.unitypackagefacilitator", "https://github.com/eloistree/2019_07_21_UnityPackageFacilitator.git#1ae98f48237fc4ac9bb5765043f71ddb7d773316"),
new PackageValue("be.eloistree.quickgitutility","https://github.com/eloistree/2019_07_21_QuickGitUtility.git#3dd9d21765d5ff873cab42c1f10b5b6889558ea1"),
new PackageValue("be.eloistree.license","https://github.com/EloiStree/GeneralLicense.git")
};
private static void WhatToDoWhenDrop()
{
string manifestPath = Application.dataPath + "/../Packages/manifest.json";
string packageFile = File.ReadAllText(manifestPath);
string packageToAdd = "";
for (int i = 0; i < m_wantedDependencies.Length; i++)
{
string toAdd = string.Format("\"{0}\": \"{1}\"", m_wantedDependencies[i].m_id, m_wantedDependencies[i].m_version);
if (packageFile.IndexOf(toAdd) < 0)
{
packageToAdd = string.Format("\n {0}, ", toAdd);
packageFile = packageFile.Replace("\"dependencies\": {", "\"dependencies\": {" + packageToAdd);
}
}
File.WriteAllText(manifestPath, packageFile);
AssetDatabase.Refresh();
}
public class PackageValue
{
public string m_id = "";
public string m_version = "0.0.1";
public PackageValue(string id, string version)
{
this.m_id = id;
this.m_version = version;
}
}
#region GRENADE SCRIPT
public static bool m_deleteAfterUse = false;
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
if (IsFileAtProjectRoot())
{
Debug.Log("> BOOM : " + GetFileName());
WhatToDoWhenDrop();
if (m_deleteAfterUse)
{
File.Delete(GetFilePath());
}
else
{
string filePath = GetFilePath();
string dir = Application.dataPath + "/GrenadeScripts/Used";
Directory.CreateDirectory(dir);
File.Move(filePath, dir + "/" + GetFileName());
AssetDatabase.Refresh();
}
}
}
private static bool IsFileAtProjectRoot()
{
return File.Exists(Application.dataPath + "/" + GetFileName());
}
private static string GetFileName()
{
return Path.GetFileName(new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName());
}
private static string GetFilePath()
{
return new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
}
#endregion
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment