Beispiel #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);
    }
    private void LoadDefaults()
    {
        var action = (UTBakeOcclusionCullingAction)target;

        CUUndoUtility.RegisterUndo(action, "Load default occlusion culling settings");
        UTBakeOcclusionCullingAction.LoadDefaults(action);
        EditorUtility.SetDirty(action);
    }
Beispiel #3
0
    private void LoadSettings()
    {
        var action = (UTBakeNavMeshAction)target;

        CUUndoUtility.RegisterUndo(action, "Load default nav mesh settings");
        UTBakeNavMeshAction.LoadFromSettings(action);
        GUIUtility.keyboardControl = 0;         // unfocus anything
        EditorUtility.SetDirty(action);
    }
Beispiel #4
0
    /// <summary>
    /// Relayouts the plan.
    /// </summary>
    /// <seealso cref="UTGraphLayouter"/>
    public void RelayoutPlan()
    {
        CUUndoUtility.RegisterUndo(new UObject[] { data, graphData }, "Layout automation plan");
        UTGraphLayouter layouter = new UTGraphLayouter();
        var             node     = graphData.GetNodeFor(data.firstEntry);

        layouter.Relayout(graphData, node);
        EditorUtility.SetDirty(data);
        EditorUtility.SetDirty(graphData);
    }
Beispiel #5
0
    /// <summary>
    /// Loads the current settings into the currently selected action if this action implements <see cref="UTICanLoadSettingsFromEditor"/>
    /// </summary>
    public virtual void LoadCurrentSettings()
    {
        if (target is UTICanLoadSettingsFromEditor)
        {
            var action = (UTICanLoadSettingsFromEditor)target;

            CUUndoUtility.RegisterUndo(target, action.LoadSettingsUndoText);
            action.LoadSettings();
            GUIUtility.keyboardControl = 0;             // make sure every textfield is updated.
            EditorUtility.SetDirty(target);
        }
    }
Beispiel #6
0
    /// <summary>
    /// Deletes the connection between a node's connector and the target node.
    /// </summary>
    /// <param name='connector'>
    /// Connector for which the connection should be deleted.
    /// </param>
    public void DeleteConnection(UTNode.Connector connector)
    {
        var sourceEntry = connector.owner.Data;
        var sourceNode  = connector.owner;

        CUUndoUtility.RegisterUndo(new UObject[] { sourceEntry, graphData }, "Remove connector");

        var reference = graphData.GetReference(connector.owner.Data, connector.property);

        SetProperty(sourceEntry, connector.property, null);
        sourceNode.Recalc();
        graphData.DeleteReference(reference);
        EditorUtility.SetDirty(sourceEntry);
        EditorUtility.SetDirty(graphData);
    }
    /// <summary>
    /// Ensures that the given configuration is activated. If it is already the active configuration this method
    /// will do nothing. Otherwise it will activate the given configuration and deactivate any other active
    /// configuration.
    /// </summary>
    /// <param name="configurationToBeActivated">
    /// A <see cref="SMSceneConfigurationBase"/> that is to be activated.
    /// </param>
    public static void EnsureActiveConfiguration(SMSceneConfigurationBase configurationToBeActivated, bool registerUndo)
    {
        List <SMSceneConfigurationBase> allConfigurations = FindConfigurations();

        if (registerUndo)
        {
            CUUndoUtility.RegisterUndo(allConfigurations.ToArray(), "Activate scene configuration");
        }

        foreach (SMSceneConfigurationBase configuration in allConfigurations)
        {
            configuration.activeConfiguration = configuration == configurationToBeActivated;
            EditorUtility.SetDirty(configuration);
        }
    }
Beispiel #8
0
    /// <summary>
    /// Deletes a set of nodes. Also removes the related automation plan entries from the automation plan.
    /// </summary>
    /// <param name='nodes'>
    /// Nodes to be deleted.
    /// </param>
    public void DeleteNodes(IList <UTNode> nodes)
    {
        List <UTNode>  copy   = new List <UTNode> (nodes);
        List <UObject> toUndo = new List <UObject> ();

        toUndo.Add(data);
        toUndo.Add(graphData);

        foreach (var node in copy)
        {
            var targetRefs = graphData.GetTargetReferences(node.Data);
            foreach (var targetRef in targetRefs)
            {
                if (!toUndo.Contains(targetRef.Source))
                {
                    toUndo.Add(targetRef.Source);
                }
            }
        }
        CUUndoUtility.RegisterUndo(toUndo.ToArray(), "Delete nodes");

        foreach (var node in copy)
        {
            var targetRefs = graphData.GetTargetReferences(node.Data);

            foreach (var reference in targetRefs)
            {
                // kill reference in node
                SetProperty(reference.Source, reference.SourceProperty, null);
                var modifiedNode = graphData.GetNodeFor(reference.Source);
                modifiedNode.Recalc();
            }

            graphData.DeleteNode(node);

            if (data.firstEntry == node.Data)
            {
                data.firstEntry = null;
                EditorUtility.SetDirty(data);
            }

            selectedNodes.Remove(node);
            // UObject.DestroyImmediate(node.Data, true);
        }
        EditorUtility.SetDirty(graphData);
    }
Beispiel #9
0
    /// <summary>
    /// Fixes configuration issues such as multiple active configurations or removed scenes
    /// </summary>
    protected void FixConfiguration()
    {
        List <UnityEngine.Object> objects = new List <UnityEngine.Object>(SMSceneConfigurationUtil.FindConfigurations().ToArray());

        CUUndoUtility.RegisterUndo(objects.ToArray(), "Fixing configuration");
        UpdateGuid();

        FixInvalidScenes();

        if (fixActiveState)
        {
            SMSceneConfigurationUtil.EnsureActiveConfiguration(Target, false);
        }

        invalidScreens = null;
        invalidLevels  = null;
        fixActiveState = false;
        EditorUtility.SetDirty(Target);
    }
    /// <summary>
    /// Does the actual rendering. Call from the OnInspectorGUI event in your Unity editor.
    /// </summary>
    public void OnInspectorGUI()
    {
        EditorGUILayout.BeginVertical();
        EditorGUI.BeginChangeCheck();
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
        Undo.SetSnapshotTarget(target, "inspector change");
        Undo.CreateSnapshot();
#else
        CUUndoUtility.RegisterUndo(target, "inspector change");
#endif
        DrawAll();
        if (EditorGUI.EndChangeCheck())
        {
#if UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
            Undo.RegisterSnapshot();
#endif
            // no replacement for 4.3+
            EditorUtility.SetDirty(target);
        }
        EditorGUILayout.EndVertical();
    }
Beispiel #11
0
    /// <summary>
    /// Adds a connection between a node's connector and another node.
    /// </summary>
    /// <param name='sourceConnector'>
    /// Source connector.
    /// </param>
    /// <param name='targetNode'>
    /// Target node.
    /// </param>
    public void AddConnection(UTNode.Connector sourceConnector, UTNode targetNode)
    {
        var sourceEntry = sourceConnector.owner.Data;
        var property    = sourceConnector.property;
        var targetEntry = targetNode.Data;
        var sourceNode  = sourceConnector.owner;

        CUUndoUtility.RegisterUndo(new UObject[] { sourceEntry, graphData }, "Add connector");
        var reference = graphData.GetReference(sourceEntry, property);

        if (reference == null)
        {
            reference                = new UTReference();
            reference.Source         = sourceEntry;
            reference.SourceProperty = property;
            graphData.AddReference(reference);
        }
        reference.Target = targetEntry;
        SetProperty(sourceEntry, property, targetEntry);
        sourceNode.Recalc();
        EditorUtility.SetDirty(sourceEntry);
        EditorUtility.SetDirty(graphData);
    }
Beispiel #12
0
 /// <summary>
 ///  Called before anything is changed on the scene configuration. This will register an undo state
 ///  for the scene configuration.
 /// </summary>
 /// <param name="operation">the performed operation. this is placed in the undo menu.</param>
 protected void BeforeChange(string operation)
 {
     CUUndoUtility.RegisterUndo(Target, operation);
 }
Beispiel #13
0
 /// <summary>
 /// Called by the node editor before moving nodes. Creates an undo stack frame, so the movement can be undone later.
 /// </summary>
 public void StartMovingNodes()
 {
     CUUndoUtility.RegisterUndo(new UObject[] { data, graphData }, "Move nodes");
     EditorUtility.SetDirty(data);
     EditorUtility.SetDirty(graphData);
 }
Beispiel #14
0
    private PropertyEditorState DrawPropertyEditor(IEnumerable <UTConfigurableProperty> properties, PropertyEditorState state,
                                                   DoAdd doAdd, PropertyExists propertyExists, DoDelete doDelete, UObject undoTarget)
    {
        EditorGUILayout.BeginVertical();

        EditorGUILayout.BeginHorizontal();

        state.newPropertyName = EditorGUILayout.TextField("Name", state.newPropertyName);
        GUI.enabled           = !string.IsNullOrEmpty(state.newPropertyName) && UTContext.IsValidPropertyName(state.newPropertyName) && !propertyExists(state.newPropertyName);
        if (GUILayout.Button("Add", UTEditorResources.ExpressionButtonStyle))
        {
            if (undoTarget != null)
            {
                CUUndoUtility.RegisterUndo(undoTarget, "Add Property");
            }
            doAdd(state.newPropertyName);
            state.newPropertyName = "";
        }

        GUI.enabled = true;
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
        var index = 0;

        foreach (var property in properties)
        {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            if (!property.UseExpression)
            {
                if (property.IsPrivate)
                {
                    property.Value = EditorGUILayout.PasswordField(property.Name, property.Value);
                }
                else
                {
                    property.Value = EditorGUILayout.TextField(property.Name, property.Value);
                }
                if (property.SupportsPrivate)
                {
                    if (GUILayout.Button(property.IsPrivate ? UTEditorResources.PrivateIcon : UTEditorResources.PublicIcon, UTEditorResources.DeleteButtonStyle))
                    {
                        property.IsPrivate         = !property.IsPrivate;
                        GUIUtility.keyboardControl = 0;                         // make textfield update.
                    }
                }
            }
            else
            {
                property.Expression = EditorGUILayout.TextField(property.Name, property.Expression);
            }

            if (GUILayout.Button(UTEditorResources.DeleteIcon, UTEditorResources.DeleteButtonStyle))
            {
                if (undoTarget != null)
                {
                    CUUndoUtility.RegisterUndo(undoTarget, "Remove property");
                }
                doDelete(property);
                GUIUtility.ExitGUI();
            }

            var oldExpression = property.UseExpression;
            property.UseExpression = GUILayout.Toggle(oldExpression, UTEditorResources.ExpressionButton, UTEditorResources.ExpressionButtonStyle);

            if (oldExpression != property.UseExpression)
            {
                GUIUtility.keyboardControl = 0;                 // make textfield update.
            }

            EditorGUILayout.EndHorizontal();

            if (!property.UseExpression && property.Value.Contains("$"))
            {
                EditorGUILayout.HelpBox(UTEditorResources.VariableWarningText, MessageType.Warning);
            }
            EditorGUILayout.EndVertical();
            index++;
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
        return(state);
    }