Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NamPhuThuy/cbc9fbdc918b197cb46b4411db664602 to your computer and use it in GitHub Desktop.

Select an option

Save NamPhuThuy/cbc9fbdc918b197cb46b4411db664602 to your computer and use it in GitHub Desktop.
Add this file into Assest/ScriptTemplates of any Unity project to custom the Default Script Template (the script that is generated when create a new script in Unity))
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class #SCRIPTNAME# : MonoBehaviour
{
#region MonoBehaviour Methods
void Start()
{
}
void Update()
{
}
#endregion
#region Private Methods
#endregion
#region Public Methods
#endregion
#region Editor Methods
public void ResetValues()
{
// Add default reset values logic here
}
#endregion
}
#if UNITY_EDITOR
[CustomEditor(typeof(#SCRIPTNAME#))]
[CanEditMultipleObjects]
public class #SCRIPTNAME#Editor : Editor
{
public override void OnInspectorGUI()
{
// Draw the default inspector
DrawDefaultInspector();
// Get a reference to the script
#SCRIPTNAME# script = (#SCRIPTNAME#)target;
// Add a button to call ResetValues()
if (GUILayout.Button("Reset Values"))
{
script.ResetValues();
EditorUtility.SetDirty(script); // Mark the object as dirty
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment