Пример #1
0
        private async void GetOutput(object selectedOutput)
        {
            PuckOutput output = (PuckOutput)selectedOutput;

            if (selectedOutput == null || output == null)
            {
                ConnectionManagerArcoro.Instance.DestroyConnectionToMouse();
                return;
            }
            try {
                await WebsocketManager.Instance.AddLogicItem(output.Action.Data.Id, Action.Data.Id, false);

                ConnectionManagerArcoro.Instance.DestroyConnectionToMouse();
            } catch (RequestFailedException ex) {
                Debug.LogError(ex);
                Notifications.Instance.SaveLogs("Failed to add connection");
            }
        }
Пример #2
0
        /// <summary>
        /// Updates connections between actions in the scene.
        /// </summary>
        /// <param name="projectObjects"></param>
        /// <param name="connections"></param>
        public void UpdateActionConnections(List <IO.Swagger.Model.ProjectActionPoint> actionPoints, Dictionary <string, string> connections)
        {
            Dictionary <string, Action> actionsToActualize = new Dictionary <string, Action>();

            // traverse through all actions (even freshly created)
            foreach (Action action in GetAllActions())
            {
                // get connection from dictionary [actionID,outputAction]
                if (connections.TryGetValue(action.Data.Id, out string actionOutput))
                {
                    // Check if action's output action is NOT the same as actionOutput from newly received data from server,
                    // then connection changed and we have to delete actual connection of current action and create new one
                    Action refAction = null;
                    // Find corresponding action defined by ID
                    if (actionOutput != "start" && actionOutput != "end")
                    {
                        refAction = GetAction(actionOutput);
                        if (refAction != null)
                        {
                            actionOutput = refAction.Data.Id;
                        }
                        else
                        {
                            actionOutput = "";
                        }
                    }
                    if (action.Output.Data.Default != actionOutput)
                    {
                        // Destroy old connection if there was some
                        if (action.Output.Connection != null)
                        {
                            ConnectionManagerArcoro.Instance.Connections.Remove(action.Output.Connection);
                            Destroy(action.Output.Connection.gameObject);
                        }

                        // Create new connection only if connected action exists (it is not start nor end)
                        if (refAction != null)
                        {
                            // Create new one
                            //PuckInput input = GetAction(actionOutput).Input;
                            PuckInput  input  = refAction.Input;
                            PuckOutput output = action.Output;

                            GameObject c = Instantiate(ConnectionPrefab);
                            c.transform.SetParent(ConnectionManager.instance.transform);
                            Connection newConnection = c.GetComponent <Connection>();
                            // We are always connecting output to input.
                            newConnection.target[0] = output.gameObject.GetComponent <RectTransform>();
                            newConnection.target[1] = input.gameObject.GetComponent <RectTransform>();

                            input.Connection  = newConnection;
                            output.Connection = newConnection;
                            ConnectionManagerArcoro.Instance.Connections.Add(newConnection);
                        }
                    }
                    actionsToActualize.Add(action.Data.Id, action);
                }
            }

            // Set action inputs and outputs for updated connections
            foreach (IO.Swagger.Model.ProjectActionPoint projectActionPoint in actionPoints)
            {
                foreach (IO.Swagger.Model.Action projectAction in projectActionPoint.Actions)
                {
                    if (actionsToActualize.TryGetValue(projectAction.Id, out Action action))
                    {
                        // Sets action inputs (currently each action has only 1 input)
                        foreach (IO.Swagger.Model.ActionIO actionIO in projectAction.Inputs)
                        {
                            action.Input.Data = actionIO;
                        }

                        // Sets action outputs (currently each action has only 1 output)
                        foreach (IO.Swagger.Model.ActionIO actionIO in projectAction.Outputs)
                        {
                            action.Output.Data = actionIO;
                        }
                    }
                }
            }
        }