Skip to content

Instantly share code, notes, and snippets.

@RyotaMurohoshi
Last active Sep 3, 2019
Embed
What would you like to do?
Code Inspection and Quick Fix demo code for Rider & Unity
/*
* This is Demo for `Code Inspection` and `Quick Fix` in Rider & Unity.
* Please put this file in Unity project as `Demo.cs` and open with Rider.
* In this code, there are some problem to fix.
* `Code Inspection` tells you them and you can fix it with `Quick Fix` so easily.
*
* これは、Unity & Riderの`Code Inspection`と`Quick Fix`でも用コードです。
* このファイルを`Demo.cs`という名前で、Unityプロジェクトに起き、Riderで開いてください。
* このコードにはいくつか修正しないといけない点があります。
* `Code Inspection`はその点を教えてくれ、そして`Quick Fix`を使えばとても簡単にそれを修正できます。
*
* プレゼン資料はこちら
* Plesentation Contents
* https://speakerdeck.com/ryotamurohoshi/riderfalsesusume-an-hariderkokogahao-ki
*/
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Demo
{
public static class Example
{
public static void Step0()
{
var monsters = LoadMonsters();
// Step0
// QuickFixMe
var isEmpty = monsters.Count() == 0;
}
public static void Step1()
{
var monsters = LoadMonsters();
// Step1
// QuickFixMe
var deadCount = monsters.Where(it => it.Hp > 0).Count();
}
public static void Step2()
{
var myName = "RyotaMurohoshi";
var level = 31;
// Step2
// QuickFixMe
var message = string.Format("{0} : {1}", myName, level);
}
private static IEnumerable<Monster> LoadMonsters()
=> new Monster[0];
}
class Rect
{
public Rect(int height, int width)
{
Height = height;
Width = width;
}
private int Height { get; }
private int Width { get; }
public int Area
{
// Step3
// QuickFixMe
get { return Height * Width; }
}
}
public class Monster
{
public int Hp { get; }
}
public class Demo : MonoBehaviour
{
[SerializeField] private GameObject target;
// Step4
// QuickFixMe
private void Awake()
{
}
private void Start()
{
// Step5
// QuickFixMe
var mover = new Mover();
}
// Step6
// QuickFixMe
private void OnCollisionEnter(Collider other)
{
}
void Update()
{
Move();
}
void Move()
{
// Step7
// QuickFixMe
var mover = GetComponent<Mover>();
mover.Move();
}
void CalcPositions()
{
var forwardPosition = transform.position + Vector3.forward;
// Step8
// QuickFixMe
var backPosition = transform.position + Vector3.back;
}
void NullPropagation()
{
// Step9
// QuickFixMe
Debug.Log(target?.name);
// 等価じゃない
Debug.Log(target == null ? null : target.name);
}
}
}
using UnityEngine;
namespace Demo
{
public class Mover : MonoBehaviour
{
[SerializeField] private float speed;
public void Move()
{
}
public void StartMove()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment