mcpiroman / UnityNativeTool

Allows to unload native plugins in Unity3d editor
MIT License
183 stars 18 forks source link

Skipping copy of attribute [OptionalAttribute] in function GotoPos as it is not supported. However, if it is desirable to include it, adding such support should be easy. See the method that throws this exception. #35

Closed pinguin999 closed 2 years ago

pinguin999 commented 2 years ago

Is this feature planed? Or can someone implement it?

Thanks

Skipping copy of attribute [OptionalAttribute] in function GotoPos as it is not supported. However, if it is desirable to include it, adding such support should be easy. See the method that throws this exception.
UnityEngine.Debug:LogWarning (object)
UnityNativeTool.Internal.DllManipulator:CreateAttributeBuilderFromAttributeInstance (System.Attribute,string) (at Assets/UnityNativeTool/DllManipulator.cs:492)
UnityNativeTool.Internal.DllManipulator:CreateDelegateTypeForNativeFunctionSignature (UnityNativeTool.Internal.NativeFunctionSignature,string) (at Assets/UnityNativeTool/DllManipulator.cs:453)
UnityNativeTool.Internal.DllManipulator:GetNativeFunctionMockMethod (System.Reflection.MethodInfo) (at Assets/UnityNativeTool/DllManipulator.cs:300)
UnityNativeTool.Internal.DllManipulator:MockNativeFunction (System.Reflection.MethodInfo) (at Assets/UnityNativeTool/DllManipulator.cs:260)
UnityNativeTool.Internal.DllManipulator:Initialize (UnityNativeTool.Internal.DllManipulatorOptions,int,string) (at Assets/UnityNativeTool/DllManipulator.cs:99)
UnityNativeTool.DllManipulatorScript:Initialize () (at Assets/UnityNativeTool/DllManipulatorScript.cs:92)
UnityNativeTool.DllManipulatorScript:OnEnable () (at Assets/UnityNativeTool/DllManipulatorScript.cs:64)
mcpiroman commented 2 years ago

Yes, you can implement it :)

Inside: https://github.com/mcpiroman/UnityNativeTool/blob/bcf66ae9c6d6d873a7ae720fe2d5f02edc0fa820/scripts/DllManipulator.cs#L463 needs to be another case for this type of attribute, analogous to the other ones (MarshalAs, In, Out). This function has to copy attributes - more specifically return CustomAttributeBuilder that has the same type and ctor arguments and fields as the original one.

If you do this, then a PR will be also welcome. If you have difficulties I may find some time somewhen and do it myself.

pinguin999 commented 2 years ago

Hi @mcpiroman

thanks for your help. I found out that it's the case OptionalAttribute but I have no Idea what to do in the case.

Is it a quick fix for you or should I think about just removing the optional parameters.

Thanks K

mcpiroman commented 2 years ago

I looked it up and OptionalAttribute does not have any arguments or properties, so you should just add the case after In and Out attributes, like

                case InAttribute _:
                case OutAttribute _:
                case OptionalAttribute _: 
                {
                    var ctor = attrType.GetConstructor(Type.EmptyTypes);
                    ...

I did not want to do it myself because I would have to setup and run my environment, make some test case... So if you can confirm it indeed works I can just commit it as such.

pinguin999 commented 2 years ago

It works. Thanks!

mcpiroman commented 2 years ago

Added in 004b328