Esempio n. 1
0
        private async void GetInput(object selectedInput)
        {
            PuckInput input = (PuckInput)selectedInput;

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

                ConnectionManagerArcoro.Instance.DestroyConnectionToMouse();
            } catch (RequestFailedException ex) {
                Debug.LogError(ex);
                Notifications.Instance.SaveLogs("Failed to add connection");
            }
        }
Esempio n. 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;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public virtual void ActionUpdate(IO.Swagger.Model.Action action, bool updateConnections = false)
        {
            // Updates (or creates new) parameters of current action
            foreach (IO.Swagger.Model.ActionParameter projectActionParameter in action.Parameters)
            {
                try {
                    // If action parameter exist in action dictionary, then just update that parameter value (it's metadata will always be unchanged)
                    if (Parameters.TryGetValue(projectActionParameter.Id, out ActionParameter actionParameter))
                    {
                        actionParameter.UpdateActionParameter(projectActionParameter);
                    }
                    // Otherwise create a new action parameter, load metadata for it and add it to the dictionary of action
                    else
                    {
                        // Loads metadata of specified action parameter - projectActionParameter. Action.Metadata is created when creating Action.
                        IO.Swagger.Model.ActionParameterMeta actionParameterMetadata = Metadata.GetParamMetadata(projectActionParameter.Id);

                        actionParameter = new ActionParameter(actionParameterMetadata, this, projectActionParameter.Value);
                        Parameters.Add(actionParameter.Id, actionParameter);
                    }
                } catch (ItemNotFoundException ex) {
                    Debug.LogError(ex);
                }
            }
            if (updateConnections)
            {
                string actionOutput = "end";
                if (action.Outputs.Count > 0)
                {
                    actionOutput = action.Outputs[0].Default;
                }

                if (actionOutput != Output.Data.Default)
                {
                    //at the moment, each action has exactly one input and one output
                    Action refAction = null;
                    if (actionOutput != "start" && actionOutput != "end")
                    {
                        refAction = Scene.Instance.GetAction(actionOutput);
                    }

                    if (Output.Connection != null)
                    {
                        ConnectionManagerArcoro.Instance.Connections.Remove(Output.Connection);
                        Destroy(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 = refAction.Input;

                        GameObject c = Instantiate(Scene.Instance.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;
                        input.Data.Default  = Data.Id;
                        Output.Data.Default = refAction.Data.Id;
                        ConnectionManagerArcoro.Instance.Connections.Add(newConnection);
                    }
                    else
                    {
                        refAction = Scene.Instance.GetAction(Output.Data.Default);
                        refAction.Input.InitData();
                        Output.InitData();
                    }
                }
            }
        }