Snippets

HBPNeurorobotics SetPositionServer.cs

Created by erdisayar
using System.Threading.Tasks;
using UnityEngine;
using Grpc.Core;
using Proto.Services;
using Proto.Messages;

public class SetPositionServer : MonoBehaviour
{
    public PositionTestServerService my_class_variable = new PositionTestServerService();
    private void Start()
    {

        var server = new Server()
        {
            Services = { SetPositionService.BindService(my_class_variable) },
            Ports = { new ServerPort("localhost", 50052, ServerCredentials.Insecure) }
        };
        server.Start();
    }
    private void Update()
    {
        //transform.position = transform.position + new Vector3(0 * Time.deltaTime, 2 * Time.deltaTime, 0 * Time.deltaTime);
        //Debug.Log(Time.time);
        if (Time.time > 5) 
        {
            gameObject.SetActive(false);
            Debug.Log(my_class_variable.posx);
            gameObject.transform.position = new Vector3(my_class_variable.posx, my_class_variable.posy, my_class_variable.posz);
            gameObject.transform.rotation = Quaternion.Euler(my_class_variable.rotx, my_class_variable.roty, my_class_variable.rotz);
            gameObject.SetActive(true);
        }
    }
}

public class PositionTestServerService : SetPositionService.SetPositionServiceBase
{
    public float posx = 0;
    public float posy = 0;
    public float posz = 0;
    public float rotx = 0;
    public float roty = 0;
    public float rotz = 0;
    public override Task<Response> SetPosition(Request request, ServerCallContext context)
    {
        // ???????????????
        var hello = $"SetPosition X = {request.X}, Y = {request.Y}, Z = {request.Z}" ;
        var response = new Response {ResponseMessage = hello };
        posx = request.X;
        posy = request.Y;
        posz = request.Z;
        return Task.FromResult(response);
    }

    public override Task<Response> SetRotation(Request request, ServerCallContext context)
    {
        // ???????????????
        var hello = $"SetRotation X = {request.X}, Y = {request.Y}, Z = {request.Z}";
        var response = new Response { ResponseMessage = hello };
        rotx = request.X;
        roty = request.Y;
        rotz = request.Z;
        return Task.FromResult(response);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.