Open justinlueders opened 9 years ago
Agreed! For me, trying to call gameObject.GetComponent
i like this since it is consistent with how jetbrains products handle things when you when do something like try to create a instance of a class that does not exist. Problem is how to do so. In the case of it create a class if you type new MyClass()
it creates it in the same file you are in. This would not work for components since unity requires them to be in their own files.
Would this simply be a case of creating a new class that derives from MonoBehaviour
? Why would Unity require this to be in a separate file?
its a new class that Derives from MonoBehaviour, but Unity Requires that all MonoBehaviours be in their own file that has the same filename as the class name.
I feel if you felt it was worth the work, the best approach would be to create the new file, in the same folder as the current file.
I prefer to derive all the components from my custom ScriptBase class rather from MonoBehaviour directly. The feature will be useless for me unless the base class name could be customized.
It would most likely create a new class with a template style "hotspot" for the base class name, defaulted to MonoBehaviour
. Does that sound about right?
Sounds perfect.
Unity attachs components to gameObject by guid in meta files, it has only one per file, thats why mb need to be in separated files.
This actually looks more like an issue with the underlying ReSharper engine. I've raised a couple of issues - RSRP-470158 and RSRP-470159.
When creating a type from usage in creating a generic class, ReSharper will create a new class that includes the inheritance constraint (e.g. public class Foo : IFoo
), but when doing the same from a generic method invocation, it doesn't include the constraint (e.g. it only creates public class Foo
).
But fixing this won't quite fix it - ideally, R# should show a code completion list for the inherited type, so AddComponent<T>() where T : Component
would initially create public class MyComponent : Component
, but the inherited type would be a hotspot that shows code completion when you tab to it, allowing you to select MonoBehaviour
.
if Foo does not exist (or cant be found and used) offer to create a new class that derives from MonoBehaviour and has a start and update method defined, much like when creating a script inside of the Unity3D editor.