Skip to content

Commit 56f73f6

Browse files
Merge pull request #1201 from JetBrains/192-vk-unity-templates
Add more file templates for Unity + live templates
2 parents 08bdd82 + 153da30 commit 56f73f6

23 files changed

+512
-4
lines changed

resharper/resharper-unity/src/CSharp/Feature/Services/LiveTemplates/Scope/InUnityCSharpProject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Feature.Services.LiveTemplate
1010
// other scope points. A template can declare that it requires this scope point, and
1111
// the template will only be made available if a ScopeProvider "publishes" this scope
1212
// point based on the current context (e.g. the project is a Unity project)
13-
public class InUnityCSharpProject : InLanguageSpecificProject
13+
public class InUnityCSharpProject : InLanguageSpecificProject, IMandatoryScopePoint
1414
{
1515
private static readonly Guid DefaultUID = new Guid("B37325A3-4F0A-405B-8A5C-00ECA4ED3B30");
1616
private static readonly Guid QuickUID = new Guid("D32F297F-E422-4612-839A-FE76D9914B34");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using JetBrains.ReSharper.LiveTemplates.CSharp.Context;
3+
4+
namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Feature.Services.LiveTemplates.Scope
5+
{
6+
public class IsAvailableForClassAttribute : InCSharpFile
7+
{
8+
private static readonly Guid ourDefaultGuid = new Guid("AE22FA37-D337-48D7-B570-1ADE437DE6E3");
9+
10+
public override Guid GetDefaultUID() => ourDefaultGuid;
11+
public override string PresentableShortName => "Where attribute for class is allowed";
12+
public override string ToString() => "Where attribute for class is allowed";
13+
}
14+
}

resharper/resharper-unity/src/CSharp/Feature/Services/LiveTemplates/Scope/UnityTypeScopeProvider.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Context;
55
using JetBrains.ReSharper.Feature.Services.LiveTemplates.LiveTemplates;
66
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Scope;
7+
using JetBrains.ReSharper.Psi.CSharp.Tree;
78
using JetBrains.ReSharper.Psi.Files;
89
using JetBrains.ReSharper.Psi.Tree;
910

@@ -15,6 +16,7 @@ public class UnityTypeScopeProvider : ScopeProvider
1516
public UnityTypeScopeProvider()
1617
{
1718
Creators.Add(TryToCreate<MustBeInUnityType>);
19+
Creators.Add(TryToCreate<IsAvailableForClassAttribute>);
1820
}
1921

2022
public override IEnumerable<ITemplateScopePoint> ProvideScopePoints(TemplateAcceptanceContext context)
@@ -36,7 +38,16 @@ public override IEnumerable<ITemplateScopePoint> ProvideScopePoints(TemplateAcce
3638
var element = psiFile?.FindTokenAt(caretOffset - prefix.Length);
3739
var typeDeclaration = element?.GetContainingNode<ITypeDeclaration>();
3840
if (typeDeclaration == null)
41+
{
42+
var siblingNode = element?.GetNextMeaningfulSibling();
43+
while (siblingNode is IAttributeList)
44+
{
45+
siblingNode = element.GetNextMeaningfulSibling();
46+
}
47+
if (siblingNode is IClassDeclaration)
48+
yield return new IsAvailableForClassAttribute();
3949
yield break;
50+
}
4051

4152
var unityApi = context.Solution.GetComponent<UnityApi>();
4253
if (unityApi.IsUnityType(typeDeclaration.DeclaredElement))

resharper/resharper-unity/src/CSharp/Feature/Services/LiveTemplates/UnityQuickListDefaultSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ public override void InitDefaultSettings(ISettingsStorageMountPoint mountPoint)
3838
// TODO: Not sure if this would be better handled in a .dotSettings file
3939
var pos = 0;
4040
AddToQuickList(mountPoint, myProjectMainPoint, "MonoBehaviour", ++pos, "5ff5ac38-7207-4256-91ae-b5436552db13");
41+
AddToQuickList(mountPoint, myProjectMainPoint, "ScriptableObject", ++pos, "1404A333-DA7C-47AC-8CB5-7C944DD1422D");
42+
AddToQuickList(mountPoint, myProjectMainPoint, "StateMachineBehaviour", ++pos, "AFA01340-773E-488A-93D6-E19540AE2F1B");
4143
AddToQuickList(mountPoint, myProjectMainPoint, "PlayModeTest", ++pos, "0bcdbc13-d26e-4512-9750-fb930f532e88");
44+
AddToQuickList(mountPoint, myProjectMainPoint, "CustomEditor", ++pos, "2E5D288C-A209-41EE-93B2-7CACDCAE18C6");
45+
AddToQuickList(mountPoint, myProjectMainPoint, "EditorWindow", ++pos, "CA9DFEEA-D5B5-4DDC-933F-8D618D71538E");
46+
AddToQuickList(mountPoint, myProjectMainPoint, "PropertyDrawer", ++pos, "7901AA8B-4060-4763-8FD5-B7B5384FABAA");
47+
AddToQuickList(mountPoint, myProjectMainPoint, "ScriptableWizard", ++pos, "E1BD73A0-0145-4A1A-B4AA-7744144744AF");
48+
AddToQuickList(mountPoint, myProjectMainPoint, "AssetPostprocessor", ++pos, "B669492E-B3A6-4F98-9998-9AF480374340");
4249
AddToQuickList(mountPoint, myProjectMainPoint, "EditModeTest", ++pos, "7b7fa2c7-0ee5-4d4f-bb1f-ddbeacdbfc94");
4350
AddToQuickList(mountPoint, myProjectMainPoint, "StandardSurfaceShader", ++pos, "4b8178a2-8110-4068-a788-43b8227564e5");
4451
AddToQuickList(mountPoint, myProjectMainPoint, "UnlitShader", ++pos, "fdbd3ad2-8db2-466a-a934-4ce25cb40564");

resharper/resharper-unity/src/CSharp/Feature/Services/LiveTemplates/UnityScopeCategoryUIProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public UnityScopeCategoryUIProvider()
2020

2121
public override IEnumerable<ITemplateScopePoint> BuildAllPoints()
2222
{
23+
yield return new IsAvailableForClassAttribute();
24+
yield return new InUnityCSharpProject();
2325
yield return new MustBeInUnityType();
2426
yield return new InUnityShaderLabFile();
2527
}
@@ -28,11 +30,16 @@ public override IEnumerable<ITemplateScopePoint> BuildAllPoints()
2830

2931
public override string Present(ITemplateScopePoint point)
3032
{
33+
if (point is IsAvailableForClassAttribute)
34+
return "In C# file where class attribute is available";
35+
if (point is InUnityCSharpProject)
36+
return "In Unity project";
3137
if (point is MustBeInUnityType)
3238
return "In Unity type where type members are allowed";
3339
if (point is InUnityShaderLabFile)
34-
return "Anywhere in Unity ShaderLab file";
40+
return "In Unity ShaderLab file";
3541
return base.Present(point);
42+
3643
}
3744
}
3845
}

resharper/resharper-unity/src/CSharp/Feature/Services/LiveTemplates/UnityScopeProvider.cs renamed to resharper/resharper-unity/src/CSharp/Feature/Services/LiveTemplates/UnityShaderLabScopeProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Feature.Services.LiveTemplates
1212
{
1313
[ShellComponent]
14-
public class UnityScopeProvider : ScopeProvider
14+
public class UnityShaderLabScopeProvider : ScopeProvider
1515
{
16-
public UnityScopeProvider()
16+
public UnityShaderLabScopeProvider()
1717
{
1818
// Used when creating scope point from settings
1919
Creators.Add(TryToCreate<InUnityShaderLabFile>);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
guid: B669492E-B3A6-4F98-9998-9AF480374340
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=AssetPostprocessor, ValidateFileName=True
9+
scopes: InUnityCSharpEditorFolder
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE)
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
---
15+
16+
# Asset Postprocessor
17+
18+
```
19+
$HEADER$using UnityEngine;
20+
using UnityEditor;
21+
22+
namespace $NAMESPACE$ {
23+
public class $CLASS$ : AssetPostprocessor
24+
{
25+
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
26+
{
27+
$END$
28+
}
29+
}
30+
}
31+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
guid: 2E5D288C-A209-41EE-93B2-7CACDCAE18C6
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=CustomEditor, ValidateFileName=True
9+
scopes: InUnityCSharpEditorFolder
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE), TYPE
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
TYPE-expression: complete()
15+
---
16+
17+
# Custom Editor
18+
19+
```
20+
$HEADER$using UnityEditor;
21+
22+
namespace $NAMESPACE$ {
23+
[CustomEditor(typeof($TYPE$))]
24+
public class $CLASS$ : Editor
25+
{
26+
public override void OnInspectorGUI()
27+
{
28+
$END$
29+
base.OnInspectorGUI();
30+
}
31+
}
32+
}
33+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
guid: CA9DFEEA-D5B5-4DDC-933F-8D618D71538E
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=EditorWindow, ValidateFileName=True
9+
scopes: InUnityCSharpEditorFolder
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE), MENUITEM, TITLE
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
---
15+
16+
# Editor Window
17+
18+
```
19+
$HEADER$using UnityEngine;
20+
using UnityEditor;
21+
22+
namespace $NAMESPACE$ {
23+
public class $CLASS$ : EditorWindow
24+
{
25+
[MenuItem("$MENUITEM$")]
26+
private static void ShowWindow()
27+
{
28+
var window = GetWindow<$CLASS$>();
29+
window.titleContent = new GUIContent("$TITLE$");
30+
window.Show();
31+
}
32+
33+
private void OnGUI()
34+
{
35+
$END$
36+
}
37+
}
38+
}
39+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
guid: 7901AA8B-4060-4763-8FD5-B7B5384FABAA
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=PropertyDrawer, ValidateFileName=True
9+
scopes: InUnityCSharpEditorFolder
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE), TYPE
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
TYPE-expression: complete()
15+
---
16+
17+
# Property Drawer
18+
19+
```
20+
$HEADER$using UnityEngine;
21+
using UnityEditor;
22+
23+
namespace $NAMESPACE$ {
24+
[CustomPropertyDrawer(typeof($TYPE$))]
25+
public class $CLASS$ : PropertyDrawer
26+
{
27+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
28+
{
29+
$END$
30+
}
31+
}
32+
}
33+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
guid: 1404A333-DA7C-47AC-8CB5-7C944DD1422D
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=ScriptableObject, ValidateFileName=True
9+
scopes: InUnityCSharpProject
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE), FILENAME, MENUNAME
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
FILENAME-expression: complete()
15+
MENUNAME-expression: complete()
16+
---
17+
18+
# Scriptable Object
19+
20+
```
21+
$HEADER$using UnityEngine;
22+
23+
namespace $NAMESPACE$ {
24+
[CreateAssetMenu(fileName = "$FILENAME$", menuName = "$MENUNAME$", order = 0)]
25+
public class $CLASS$ : ScriptableObject
26+
{
27+
$END$
28+
}
29+
}
30+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
guid: E1BD73A0-0145-4A1A-B4AA-7744144744AF
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=ScriptableWizard, ValidateFileName=True
9+
scopes: InUnityCSharpEditorFolder
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE), MENUNAME, TITLE, CREATE, OTHER
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
MENUNAME-expression: complete()
15+
TITLE-expression: complete()
16+
CREATE-expression: complete()
17+
OTHER-expression: complete()
18+
---
19+
20+
# Scriptable Wizard
21+
22+
```
23+
$HEADER$using UnityEngine;
24+
using UnityEditor;
25+
26+
namespace $NAMESPACE$ {
27+
public class $CLASS$ : ScriptableWizard
28+
{
29+
[MenuItem("$MENUNAME$")]
30+
public static void CreateWizard()
31+
{
32+
DisplayWizard<$CLASS$>("$TITLE$", "$CREATE$", "$OTHER$");
33+
}
34+
35+
public void OnWizardCreate()
36+
{
37+
$END$
38+
}
39+
40+
public void OnWizardUpdate()
41+
{
42+
43+
}
44+
}
45+
}
46+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
guid: AFA01340-773E-488A-93D6-E19540AE2F1B
3+
image: UnityCSharp
4+
type: File
5+
reformat: True
6+
shortenReferences: True
7+
categories: unity
8+
customProperties: Extension=cs, FileName=StateMachineBehaviour, ValidateFileName=True
9+
scopes: InUnityCSharpProject
10+
parameterOrder: HEADER, (CLASS), (NAMESPACE)
11+
HEADER-expression: fileheader()
12+
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
13+
NAMESPACE-expression: fileDefaultNamespace()
14+
---
15+
16+
# State Machine Behaviour
17+
18+
```
19+
$HEADER$using UnityEngine;
20+
21+
namespace $NAMESPACE$ {
22+
public class $CLASS$ : StateMachineBehaviour
23+
{
24+
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
25+
{
26+
$END$
27+
}
28+
29+
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
30+
{
31+
}
32+
33+
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
34+
{
35+
}
36+
37+
public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
38+
{
39+
}
40+
41+
public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
42+
{
43+
}
44+
}
45+
}
46+
```

0 commit comments

Comments
 (0)