What would be the C# equivalent of the following struct defined in C++
I have the following structs defined in C++ used in one of my project which are to be re-used for another project in C# script of Unity engine. I wish to use these struct types as argument types between the C# script and C functions in a dll but I do not know how to convert them into C# declaration.
Here are the struct definitions:
struct SMove
{
std::string m_MotionID;
std::string m_AnimSrc;
float m_StartFrame;
float m_EndFrame;
// features
enum XFEATURE
{
XFEATURE_NONE = 0,
// Insert new features
XFEATURE_ENERGY,
XFEATURE_POWERLEVEL,
};
float m_Intensity;
};
struct SElement
{
float m_Start;
float m_End;
};
typedef std::vector<SElement> TElements;
struct SGroup
{
float m_Start;
float m_End;
long m_Level;
TElements m_Elements;
};
typedef std::vector<SGroup> TGroups;
struct SDivision
{
std::string m_PlayerID;
std::string m_DivisionID;
float m_Start;
float m_End;
TGroups m_Groups;
// features
float m_Intensity;
};
typedef std::vector<SDivision> TDivisions;
typedef std::vector<long*> TScript;
struct SScriptList
{
TScript* m_Seg[9][4][2];
};
I have just started learning C# and I know it can only interop with C so all std::string and std::vector has to be somehow replace with something recognised in both C and C#. I开发者_如何转开发 know std::string can be replaced with const char* but how do I go about converting the rest? I have googled many sites but couldn't find any examples similar to mine. How do I declare arrays of struct inside another struct in C# and its C equivalent like in SDivision and SGroup?
Update:
I have converted some of the structs to C as follows:
struct SElement
{
float m_Start;
float m_End;
};
struct SGroup
{
float m_Start;
float m_End;
long m_Level;
//Array of Elements
SElement* m_pElements;
int m_numElements;
};
struct SDivision {
const char* m_PlayerID;
const char* m_DivisionID;
float m_Start;
float m_End;
//Array of Groups
SGroup* m_pGroups;
int m_numGroups;
float m_Intensity;
};
What would the C# equivalent be?
Best course of action here is to have C++/CLI bridge DLL. C++/CLI bridge should be built with the same version of Visual Studio in which original DLL is built. The build result is regular .NET library.
精彩评论