Nukadelic
Nukadelic
CC#
Created by Nukadelic on 4/20/2023 in #help
❔ Help needed converting anon object to JSON
My attempt :
var data = new { roomLink = roomLink, roomName = roomName, secret = secret };
Debug.Log( data );
// output : { roomLink = localhost:8338, roomName = new room name, secret = password35 }

var json = JsonUtility.ToJson( data );
Debug.Log("JSON = " + json.ToString() );
// output : JSON = {}

Debug.Log("JSON = " + UnityEditor.EditorJsonUtility.ToJson( json ).ToString() );
// output : JSON = {}
var data = new { roomLink = roomLink, roomName = roomName, secret = secret };
Debug.Log( data );
// output : { roomLink = localhost:8338, roomName = new room name, secret = password35 }

var json = JsonUtility.ToJson( data );
Debug.Log("JSON = " + json.ToString() );
// output : JSON = {}

Debug.Log("JSON = " + UnityEditor.EditorJsonUtility.ToJson( json ).ToString() );
// output : JSON = {}
2 replies
CC#
Created by Nukadelic on 2/13/2023 in #help
❔ 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,
};
5 replies