예제 #1
0
    /// <summary>
    /// Adds an arbitrary entry at the given position.
    /// </summary>
    /// <returns>
    /// The entry that was added.
    /// </returns>
    /// <param name='position'>
    /// Position at which the entry should be added.
    /// </param>
    /// <typeparam name='T'>
    /// The type of the entry to be added.
    /// </typeparam>
    public T AddEntry <T> (Vector2 position) where T : UTAutomationPlanEntry
    {
        CUUndoUtility.RegisterUndo(new UObject[] { data, graphData }, "Add Node");
        var entry = UTils.AddAssetOfType <T> (PlanPath, true);

        entry.automationPlanEntryId = Guid.NewGuid().ToString();
        if (data.firstEntry == null)
        {
            data.firstEntry = entry;
        }

        UTNode node = new UTNode();

        node.Data   = entry;
        node.Bounds = new Rect(position.x, position.y, 200, 200);
        graphData.AddNode(node);

        // add offset for next node
        position.x += 50;
        position.y += 50;
        EditorUtility.SetDirty(entry);
        EditorUtility.SetDirty(graphData);
        SelectNode(node, SelectionMode.Replace);
        return(entry);
    }
예제 #2
0
    /// <summary>
    /// Loads a plan into this model.
    /// </summary>
    /// <param name='plan'>
    /// The plan to load.
    /// </param>
    public void LoadPlan(UTAutomationPlan plan)
    {
        if (plan != null)
        {
            data = plan;
            string path = PlanPath;
            graphData = null;
            selectedNodes.Clear();

            // objects with hide fagl are not returned by LoadAssetAtPath
            UnityEngine.Object[] assets = AssetDatabase.LoadAllAssetsAtPath(path);
            foreach (UnityEngine.Object asset in assets)
            {
                if (asset is UTGraph)
                {
                    graphData = (UTGraph)asset;
                    break;
                }
            }
            if (graphData == null)
            {
                graphData      = UTils.AddAssetOfType <UTGraph> (path, true);
                graphData.name = "Graph";
                EditorUtility.SetDirty(graphData);
            }
            if (plan.firstEntry != null)
            {
                SelectNode(graphData.GetNodeFor(plan.firstEntry), SelectionMode.Add);
            }
        }
        else
        {
            data      = null;
            graphData = null;
            selectedNodes.Clear();
            highlightedNode = null;
        }
    }