Giter VIP home page Giter VIP logo

vscode-unity-code-snippets's Introduction

Unity Code Snippets

Create Unity classes and methods easily.

Visual Studio Marketplace Installs Visual Studio Marketplace Rating (Stars) Visual Studio Marketplace Version

Features

2.0.0: Support to style configuration. Now you can use K&R and Allman (C#/Unity default) styles! More at Configuration section.

All the Unity code snippets you need. This extension intends to be the complete collection of Unity snippets for Visual Studio Code.

It takes advantage of latest Visual Studio Code snippets features to create the code faster for you.

MonoBehaviour

Create game classes like MonoBehaviours, NetworkBehaviours and StateMachineBehaviours easily. Also create common methods like Start(), Update() or OnTriggerEnter2D() and log calls.

MonoBehaviour

Editor

Create Editor classes like Editor, EditorWindow and PropertyDrawer as easy as it can be.

Unity Editor

ScriptableObject

You never remember the property that goes with the ScriptableObject to create it via Unity create menu? Not a problem.

ScriptableObject

Installation

As in any Visual Studio Code Extension you have several options to install:

  • Enter the Visual Studio Code Marketplace, search for Unity Code Snippets (or enter directly on the extension page) and click on Install button.
  • Inside Visual Studio Code, enter in the Extensios panel, search for Unity Code Snippets and click on Install button
  • Run the following command in the Command Palette:
    ext install kleber-swf.unity-code-snippets
    

Configuration

Starting at version 2.0.0 the extension is configurable.

To configure the extension, open VSCode Settings and search for "Unity Code Snippets". Note that after changing any of the settings, you need to restart VSCode to apply them to the snippets.

Style

The indentation style for the snippets. For now you can choose between K&R (the default for 1.x version) and Allman (default to C#/Unity). If you need a different one, please leave an issue or upvote an existing one at the project issues bord. Default: K&R.

K&R style

K&R Indentation style

Allman style

Allman Indentation style

Use Private Keyword

Adds the private accessor keyword to private members. Default: true.

No private keyword

No private keyword

Auto Complete: Classes

Auto complete classes like MonoBehaviour and Editor.

Auto Complete: Methods

Auto complete methods like Start and OnCollisionEnter.

Auto Complete: Calls

Auto complete utility calls like Debug.Log and Debug.DrawLine.

Auto Complete: Attributes

Auto complete attributes like [SerializeField] and [RequireComponent] (just these two for now).

Auto Complete: Experimental Attributes

Auto complete all other attributes like [HideInInspector] and [ContextMenu]. There are a lot o attributes and this can pollute your Intellisense popup.

All the snippets

Start typing the names to create the corresponding snippet. Some of them have a special snippet to not mess up with the default Intellisense behavior.

Snippets are devided in categories, all of them can be enabled/disabled in the options.

  • Classes:

    • Game Classes:
      • MonoBehaviour
      • StateMachineBehaviour
      • NetworkBehaviour
      • ScriptableObject
    • Editor Classes:
      • Editor
      • EditorWithReorderableList
      • EditorWindow
      • PropertyDrawer
      • ScriptableWizard
    • Standard Classes:
      • class
      • interface
  • MonoBehaviour Methods:

    • Awake()
    • FixedUpdate()
    • LateUpdate()
    • OnAnimatorIK()
    • OnAnimatorMove()
    • OnApplicationFocus()
    • OnApplicationPause()
    • OnApplicationQuit()
    • OnAudioFilterRead()
    • OnBecameInvisible()
    • OnBecameVisible()
    • OnCollisionEnter()
    • OnCollisionEnter2D()
    • OnCollisionExit()
    • OnCollisionExit2D()
    • OnCollisionStay()
    • OnCollisionStay2D()
    • OnConnectedToServer()
    • OnControllerColliderHit()
    • OnDestroy()
    • OnDisable()
    • OnDisconnectedFromServer()
    • OnDrawGizmos()
    • OnDrawGizmosSelected()
    • OnEnable()
    • OnFailedToConnect()
    • OnFailedToConnectToMasterServer()
    • OnFocus()
    • OnGUI()
    • OnHierarchyChange()
    • OnInspectorUpdate()
    • OnJointBreak()
    • OnJointBreak2D()
    • OnLostFocus()
    • OnMasterServerEvent()
    • OnMouseDown()
    • OnMouseDrag()
    • OnMouseEnter()
    • OnMouseExit()
    • OnMouseOver()
    • OnMouseUp()
    • OnMouseUpAsButton()
    • OnNetworkInstantiate()
    • OnParticleCollision()
    • OnParticleSystemStopped()
    • OnParticleTrigger()
    • OnPlayerConnected()
    • OnPlayerDisconnected()
    • OnPostRender()
    • OnPreCull()
    • OnPreRender()
    • OnProjectChange()
    • OnRenderImage()
    • OnRenderObject()
    • OnSceneGUI()
    • OnSelectionChange()
    • OnSerializeNetworkView()
    • OnServerInitialized()
    • OnStateEnter()
    • OnStateExit()
    • OnStateIK()
    • OnStateMove()
    • OnStateUpdate()
    • OnTransformChildrenChanged()
    • OnTransformParentChanged()
    • OnTriggerEnter()
    • OnTriggerEnter2D()
    • OnTriggerExit()
    • OnTriggerExit2D()
    • OnTriggerStay()
    • OnTriggerStay2D()
    • OnValidate()
    • OnWillRenderObject()
    • OnWizardCreate()
    • OnWizardOtherButton()
    • OnWizardUpdate()
    • Reset()
    • Start()
    • Update()
  • Calls:

    • Debug.Log() (type log)
    • Debug.LogError() (type logerror)
    • Debug.LogException() (type logexception)
    • Debug.LogWarning() (type logwarning)
    • Debug.LogFormat() (type logformat)
    • Debug.LogErrorFormat() (type logerrorformat)
    • Debug.LogWarningFormat() (type logwarningformat)
    • Debug.DrawLine() (type drawline)
    • Debug.DrawRay() (type drawray)
  • Attributes:

    • [SerializeField] (type sfield)
    • [RequireComponent]
  • Experimental snippets:

    • [AddComponentMenu]
    • [AssemblyIsEditorAssembly]
    • [BeforeRenderOrder]
    • [CanEditMultipleObjects]
    • [ColorUsage]
    • [ContextMenu]
    • [ContextMenuItem]
    • [CreateAssetMenu]
    • [CustomEditor]
    • [CustomEditorForRenderPipeline]
    • [CustomGridBrush]
    • [CustomPreview]
    • [CustomPropertyDrawer]
    • [Delayed]
    • [DisallowMultipleComponent]
    • [DrawGizmo]
    • [EditorWindowTitle]
    • [ExcludeFromObjectFactory]
    • [ExcludeFromPreset]
    • [ExecuteAlways]
    • [ExecuteInEditMode]
    • [FilePath]
    • [GradientUsage]
    • [GUITarget]
    • [Header]
    • [HelpURL]
    • [HideInCallstack]
    • [HideInInspector]
    • [Icon]
    • [ImageEffectAfterScale]
    • [ImageEffectAllowedInSceneView]
    • [ImageEffectOpaque]
    • [ImageEffectTransformsToLDR]
    • [ImageEffectUsesCommandBuffer]
    • [InitializeOnEnterPlayMode]
    • [InitializeOnLoad]
    • [InitializeOnLoadMethod]
    • [InspectorName]
    • [InspectorOrder]
    • [LightingExplorerExtension]
    • [Localization]
    • [MenuItem]
    • [Min]
    • [Multiline]
    • [NonReorderable]
    • [PreferBinarySerialization]
    • [Range]
    • [RuntimeInitializeOnLoadMethod]
    • [SelectionBase]
    • [SerializeReference]
    • [SettingsProvider]
    • [SettingsProviderGroup]
    • [SharedBetweenAnimators]
    • [Space]
    • [TextArea]
    • [Tooltip]

If you have any suggestion, please don't give the extension a bad review. Instead, open an issue in the Github project page and I'll try to add it when/if possible.

If you like the color theme of the previews, you can download it here: Base16 Ocean Dark Extended Theme.

Thank you for downloading this extension.

If you like the extension, please rate it with 5⭐. And, if you are feeling especially kind today, also leave a kind comment: Review this Extension.

vscode-unity-code-snippets's People

Contributors

dmbfm avatar farukaygun avatar ferhattepe avatar isnt-alice avatar kleber-jg avatar kleber-swf avatar zoosewu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vscode-unity-code-snippets's Issues

Singleton shortcut.

Hi, i have started using plugin just now. I wonder is there a short cut to create a singleton?

UnityEngine.UI

The editor told me the namespace "UnityEngine.UI" was missing .
But I can run my code successfully in Unity .

//////Environment////////////////////////////////////////////////////////////////
Unity Version : 2019.3
VSCode : 1.41.3
////////////////////////////////////////////////////////////////////////////////////

Reinstall the extension : the problem is still not solved .
Reinstall VS Code : the problem is still not solved .
Reinstall Unity : the problem is still not solved .

add singleton

i think it would be usefull to add singleton snippet.

Add bracket position option

I'd like my { after method names to be on a new line, instead of the same line as the method declaration, could you consider adding an option for the extension to allow this as a choice?

Suggestion: Add RequireComponent snippet

Example of use

[RequireComponent(typeof(MyComponent))]
public class MyComponent2 : MonoBehaviour {

}

This line declares a dependency of one component to another, and is considered unity best practices. But it's also very annoying to write.

Error -1703

My visual studio code was working perfectly earlier today, but now I am getting an error message when trying to open visual studio code by clicking on the script within Unity. I am capable of opening it directly via the visual studio code shortcut, but not within unity by clicking on the VS Code script. The error message reads "The application “Visual Studio Code” can’t be opened.-1703". Please Help

Check existing text on line

Great tool btw, tons of really useful features!

It just frustrates me when I type "private void Up" then press tab to complete and end up getting this:

private void private void Update() {

}

I know that if I just typed "Up" and pressed tab I'd get what I want, but force of habit for writing I methods gets me often typing the scope and return type before the name.

Spelling mistake in README.md

It is spelt "Extensions" and not "Extensios" so :-
"Inside Visual Studio Code, enter in the Extensios panel, search for Unity Code Snippets and click on Install button"
has to be changed to :-
"Inside Visual Studio Code, enter in the Extensions panel, search for Unity Code Snippets and click on Install button."

Publish extension on Open-VSX, so it can be used in VSCodium, Gitpod

Can you please publish the extension on open-vsx.org, so it can reach more users?
Open-VSX is a vendor-neutral alternative to VS Marketplace, that can legally be used in VS Code forks like VSCodium, GitPod.
Of course, you don't have to change anything in the extension itself.

The process is pretty much the same as publishing to VS Marketplace.
It can even be automated, see this repo:

Though the preferred solution for such a situation is to convince the maintainers to start publishing themselves, you can add the extensions here to have them published by our CI workflow.

You can claim ownership of your namespace kleber-swf, and officially support the extension there.

More details on this blog post.

Remove parenthesis from method name found in prefixes.

It would be nice to remove parenthesis from the names used in the prefixes. Currently, anytime I type in parenthesis, it will pull up the hint window with all the methods that has parenthesis inside it.

For example, if I type the following:

private void TestMethod()

It will pull up a hint window with all the methods such as Awake(), OnGUI(), etc. right after that. I normally would want to hit enter right after TestMethod() for a new line to start { }, but the hints with all the methods with parenthesis pops up every time.

This could all be remedied if parenthesis were just removed from all the prefix names, as I doubt most people pulled up references to them using parenthesis.

View project solution folder structure

@kleber-swf How should I enable the Visual Studio solution folder structure as shown in the GIFs in your README? Currently, I use fernandoescolar.vscode-solution-explorer (vscode-solution-explorer) for this.

Allow curly braces created in new line.

Hello, most of the team members use Visual Studio, and whenever they create a new method curly braces are created in the following line. In your snippets, curly braces are placed next to the name of the method and it makes the project incomprehensible across the team. Is there any way that I can change this behavior?

This is what happens.

public void foo(){

}

This is what I want.

public void foo()
{

}

Thanks.

Not Working

It just suddenly stopped working propperly and it got really hard to code without any clue of how to complete the code.

Unity methods should be public or protected

There can be strange shadowing issues if Unity methods such as Start() and Update() are private, if they are defined in a class then also in a subclass only one of them will get called. For this reason they should probably be made public or at least protected.

Change Bracket Formatting Setting

Is there a setting for the extension that I could change how the snippets put brackets on the same line? I personally prefer having the brackets on their own line so using this extension requires me to go back and fix it every time I put in a snippet. I know others prefer brackets on the same line so just a setting to change that depending on preferences I feel would be helpful.

Default intellisense

Hi I'm having trouble with the plugin, I've used it before and everything was fine but with new latest install it is preventing the default intenseness showing.

Here is an example where I am creating a new GameObject. With your plugin installed I dont get the intellisense, without it, I get the intellisense.

Heres a shot with it installed:
screenshot 2019-02-04 at 18 16 16

And here with it disabled:
screenshot 2019-02-04 at 18 16 57

Thanks

Option to change formatting of snippets.

Hi there - great tool.
I'd love the option of changing the formatting of the snippets from:

private void OnEnable() {
    
}

to:

private void OnEnable()
{
    
}

As this matches our project's style.

Don't hate on me! ;)

Gizmos not been suggested

So I was writing some code and found out that Gizmos by itself wasn't been suggested.

https://imgur.com/ErT6g9f

Do I need to modify something so Gizmos is suggested, or it's just not implemented yet?

I wonder if something "broke" for the auto-completion, after installing it suggested "gameObject" but not that's not the case.

Is there a way to check what could be wrong?

Singleton Snippet

Hi, first of all thank you for your work :) it is very usefull :)

I would like to propose adding snippet for singletong, example code:

using UnityEngine;

public class GameManager : MonoBehaviour
{

    static GameManager instance;

    public static GameManager Instance
    {
        get
        {
            if (instance == null)
            {
                instance = GameObject.FindObjectOfType<GameManager>();
                if (instance == null)
                {
                    instance = new GameObject().AddComponent<GameManager>();
                }
            }
            return instance;
        }
    }

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }
}

Remove/Disable snippets

I'd like to disable snippets that are more annoying than anything,
for instance the "OnParticleCollision(GameObject)" appears every time you tape "private ga" (for private GameObject obviously) and it has priority over intellisense so you can't arrow down to choose "GameObject", forcing you to tape the whole word or escape the suggestion.

So that's why it would be great to be able to disable some snippets. Thanks

SerializeField snippet

Hello, can you please add a separate snippet for SerializeField to avoid conflict with default C# SerializeField snippet? Because right now it is needed to press two times an arrow key to select the right snippet.

image

I would suggest "sfield" like in Rider.

Possibility to reorder these suggestions to the bottom of the list?

This is a great plugin but unfortunately I've had to turn it off.

As seen in the screenshot, native items are not listed first and often intellisense picks items from this library on top of everything else even though its much more rare to need it.

In this example I typed the word "gameobj" and all of the suggestions from this plugin come in at the top. This basically makes intellisence for csharp useless. If i am missing something in the vscode settings that can fix this, please disregard.

image

Add Function Comments Automatically

Would it be great to be able to add comments or comment tags for functions automatically - something like typing 'summary' and it will create the summary comment structure to comment the function.

Something similar for parameters comments.

Maybe this already exists and I do not know how to use it ?

Many thanks.

Just some more suggestions

the library is still pretty small and doesn't cover many methods that Unity users use. I would have gladly help you expand it, but I'm still a big dummy with code

Autocomplete code snippets not working as intended

Hey there first off, thanks for the code snippets!

However, I think there's a minor issue, but I'm not sure even sure if or how it's possible!

For example, if you type in "private void" and start typing OnCollision, or any method etc, the autocomplete will become "private void private void OnCollision" etc.

And whatever you wrote before will stay.

Do you think it's possible that it can parse to see if there's any text before and just parse what's necessary?

Thanks again for the snippets!

Add option to make open brackets in a new line

Just like the title is saying, please add an option for open brackets in a new line. I personally like the open brackets being in a new line more, so it is a bit annoying having to manually put them in a new line. Please add this functionality! Thank you

Add .gitignore snippet

Greetings

The recommended gitignore settings for a Unity project as per described in the Unity docs is:

# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

I have to google for it every time I create a new project or repo. Could we add this to the list of snippets?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.