Open EloiStree opened 5 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
//Step 1: Change the class name
//Step 2: Insert your code
//How to use ?
// Just drag the script in your project. The code is going to execute and the grenade script store in a used folder
public class PatternGrenadeScript : MonoBehaviour
{
public static void WhatToDoWhenDrop() {
//INSERT YOUR CODE HERE
}
#region GRENADE SCRIPT
public static bool m_deleteAfterUse = false;
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
Debug.Log("> BOOM : "+ GetFileName());
if (IsFileAtProjectRoot())
{
WhatToDoWhenDrop();
if (m_deleteAfterUse)
File.Delete(GetFilePath());
}
}
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
}
Objective
Done