コード例 #1
0
ファイル: Action.cs プロジェクト: xBambusekD/arcor2_editor
        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();
                    }
                }
            }
        }