Esempio n. 1
0
    public async void SaveParameters()
    {
        if (Base.Parameter.CheckIfAllValuesValid(actionParameters))
        {
            List <IO.Swagger.Model.ActionParameter> parameters = new List <IO.Swagger.Model.ActionParameter>();
            foreach (IParameter actionParameter in actionParameters)
            {
                IO.Swagger.Model.ParameterMeta   metadata = CurrentAction.Metadata.GetParamMetadata(actionParameter.GetName());
                IO.Swagger.Model.ActionParameter ap       = new IO.Swagger.Model.ActionParameter(name: actionParameter.GetName(), value: JsonConvert.SerializeObject(actionParameter.GetValue()), type: metadata.Type);
                parameters.Add(ap);
            }
            Debug.Assert(ProjectManager.Instance.AllowEdit);
            try {
                await WebsocketManager.Instance.UpdateAction(CurrentAction.Data.Id, parameters, CurrentAction.GetFlows());

                Base.Notifications.Instance.ShowToastMessage("Parameters saved");
                SaveParametersBtn.SetInteractivity(false, "Parameters unchanged");
                parametersChanged = false;
                if (string.IsNullOrEmpty(GameManager.Instance.ExecutingAction))
                {
                    ExecuteActionBtn.SetInteractivity(true);
                }
            } catch (RequestFailedException e) {
                Notifications.Instance.ShowNotification("Failed to update action ", e.Message);
            }
        }
    }
Esempio n. 2
0
    public async void CreateActionObject()
    {
        string newActionObjectName = (string)nameInput.GetValue();

        if (Base.Parameter.CheckIfAllValuesValid(actionParameters))
        {
            List <IO.Swagger.Model.Parameter> parameters = new List <IO.Swagger.Model.Parameter>();
            foreach (IParameter actionParameter in actionParameters)
            {
                if (!parametersMetadata.TryGetValue(actionParameter.GetName(), out Base.ParameterMetadata actionParameterMetadata))
                {
                    Base.Notifications.Instance.ShowNotification("Failed to create new action object", "Failed to get metadata for action object parameter: " + actionParameter.GetName());
                    return;
                }
                IO.Swagger.Model.ActionParameter ap = new IO.Swagger.Model.ActionParameter(name: actionParameter.GetName(), value: JsonConvert.SerializeObject(actionParameter.GetValue()), type: actionParameterMetadata.Type);
                parameters.Add(DataHelper.ActionParameterToParameter(ap));
            }
            try {
                Ray     ray   = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0f));
                Vector3 point = TransformConvertor.UnityToROS(GameManager.Instance.Scene.transform.InverseTransformPoint(ray.GetPoint(0.5f)));
                IO.Swagger.Model.Pose pose = null;
                if (actionObjectMetadata.HasPose)
                {
                    pose = new IO.Swagger.Model.Pose(position: DataHelper.Vector3ToPosition(point), orientation: DataHelper.QuaternionToOrientation(Quaternion.identity));
                }
                SceneManager.Instance.SelectCreatedActionObject = newActionObjectName;

                await Base.WebsocketManager.Instance.AddObjectToScene(newActionObjectName, actionObjectMetadata.Type, pose, parameters);

                callback?.Invoke();
                Close();
            } catch (Base.RequestFailedException e) {
                Base.Notifications.Instance.ShowNotification("Failed to add action", e.Message);
            }
        }
    }