C
C#2y ago
Nukadelic

❔ Is it possible to define a struct inline ?

instead of doing this
[System.Serializable]
public struct Properties
{
public float clipDistance;
public float clipHeight;
public float scale;
public float3 rotation;
public float rotationSpeed;
public float floatDistance;
public float floatSpeed;
}

public Properties properties = new Properties
{
clipDistance = 100,
clipHeight = 10,
scale = 0.4f,
rotation = new float3(90, 0, 0),
rotationSpeed = 1,
floatDistance = 0.2f,
floatSpeed = 0.2f,
};
[System.Serializable]
public struct Properties
{
public float clipDistance;
public float clipHeight;
public float scale;
public float3 rotation;
public float rotationSpeed;
public float floatDistance;
public float floatSpeed;
}

public Properties properties = new Properties
{
clipDistance = 100,
clipHeight = 10,
scale = 0.4f,
rotation = new float3(90, 0, 0),
rotationSpeed = 1,
floatDistance = 0.2f,
floatSpeed = 0.2f,
};
i want something like this :
public properties = new [System.Serializable] public struct Properties
{
public float clipDistance = 100,
public float clipHeight = 10,
public float scale = 0.4f,
public float3 rotation = new float3(90, 0, 0),
public float rotationSpeed = 1,
public float floatDistance = 0.2f,
public float floatSpeed = 0.2f,
};
public properties = new [System.Serializable] public struct Properties
{
public float clipDistance = 100,
public float clipHeight = 10,
public float scale = 0.4f,
public float3 rotation = new float3(90, 0, 0),
public float rotationSpeed = 1,
public float floatDistance = 0.2f,
public float floatSpeed = 0.2f,
};
3 Replies
Angius
Angius2y ago
No You can try using a record struct to shorten the declaration of it, though, get a constructor for free and all that
Akseli
Akseli2y ago
^ record struct or use something like ValueTuple
public (float clipDistance, float clipHeight, ...and friends) properties = (100, 10, ...);
public (float clipDistance, float clipHeight, ...and friends) properties = (100, 10, ...);
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server