Skip to content

[Unity-Native] A proposal to support UserData type "Rectangle" and "Position" #92

Description

@JustusPan

Could you please add a feature to support "Rectangle" and "Position" type of UserData?

UserDataScript.cs

using UnityEngine;

[System.Serializable]
public class UserDataRectangle
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;

    public static UserDataRectangle CreateFromJSON(string jsonString)
    {
        return JsonUtility.FromJson<UserDataRectangle>(jsonString);
    }
}

[System.Serializable]
public class UserDataPosition
{
    public int X;
    public int Y;

    public static UserDataPosition CreateFromJSON(string jsonString)
    {
        return JsonUtility.FromJson<UserDataPosition>(jsonString);
    }
}

public class UserDataScript : MonoBehaviour
{
	void FunctionEventText(string value)
	{
	}

	void FunctionEventInt(int value)
	{
	}

    void FunctionEventRectangle(string jsonString)
    {
        UserDataRectangle rect = UserDataRectangle.CreateFromJSON(jsonString);
        Debug.Log("rect.Left: " + rect.Left);
        Debug.Log("rect.Top: " + rect.Top);
        Debug.Log("rect.Right: " + rect.Right);
        Debug.Log("rect.Bottom: " + rect.Bottom);
    }

    void FunctionEventPosition(string jsonString)
    {
        UserDataPosition pos = UserDataPosition.CreateFromJSON(jsonString);
        Debug.Log("pos.X: " + pos.X);
        Debug.Log("pos.Y: " + pos.Y);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions