English / Japanese
This package provides an analyzer that warns against assigning on C# code to fields that are assigned from within the Unity inspector.
You can install this package using UPM (Unity Package Manager).
- Open Package Manager Window
- Click Add(+) on the status bar
- Select Add package from git URL
- Input
https://github.com/miyaji255/InspectorOnlyFields.git?path=InspectorOnlyFields/Packages/InspectorOnlyFields
- Click Add
You can install using OpenUPM. The page is here. https://openupm.com/packages/com.github.miyaji255.inspector-only-fields/
Add the InspectorOnly
attribute to fields to which you want to assign values from the inspector. Then, The analyzer will warn you when assigning a value to the fields.
using InspectorOnlyFields;
using UnityEngine;
public class SampleObject : MonoBehaviour
{
// InspOnly001: The assignment to 'GameObject' is prohibited by the InspectorOnly attribute
[InspectorOnly]
public GameObject GameObject = new GameObject();
void Start()
{
// InspOnly: The assignment to 'GameObject' is prohibited by the InspectorOnly attribute
GameObject = new GameObject();
}
}
Translated by DeepL.com