internal void Initialize(SerializedSceneManager serializedManager,
                                 SerializedSceneModel serializedScene)
        {
            SerializedSceneManager = serializedManager;
            this.serializedScene   = serializedScene;
            selectedTransitionProp = null;

            // Need this to reset transition prop because for some reason Redo isn't
            // resulting in this being called properly when the SceneManagerEditor reinitializes
            Undo.undoRedoPerformed -= OnUndoRedo;
            Undo.undoRedoPerformed += OnUndoRedo;

            transitionListDisplay = new ReorderableList(serializedScene.SerializedObject,
                                                        serializedScene.TransitionsProp, true, true, false, true);

            transitionListDisplay.drawHeaderCallback  = OnDrawHeader;
            transitionListDisplay.drawElementCallback = DrawElement;
            transitionListDisplay.onSelectCallback    = OnSelected;
            transitionListDisplay.onRemoveCallback    = OnRemoved;

            transitionListDisplay.index = -1;

            if (serializedScene.TransitionsProp.arraySize > 0)
            {
                transitionListDisplay.index = 0;
                OnSelected(transitionListDisplay);
            }
        }
Exemple #2
0
        private void SetSelectedNode(SceneNode selectedNode)
        {
            if (selectedNode == null)
            {
                return;
            }

            if (selectedNode.SceneId == SceneManagerController.ANY_SCENE_ID)
            {
                serializedScene = serializedManager.GetAnySceneSerializedModel();
                Repaint();
                return;
            }

            SerializedProperty scenesProp = serializedManager.ScenesProp;

            // Get the serialized property of the scene node from the scene manager
            for (int i = 0; i < scenesProp.arraySize; i++)
            {
                SerializedSceneModel serializedModel = serializedManager.GetSerializedSceneModel(i);

                if (serializedModel.SceneIdProp.intValue == selectedNode.SceneId)
                {
                    serializedScene = serializedModel;
                    Repaint();
                    break;
                }
            }
        }
        internal void DeleteSceneNode(int sceneId, bool addToExclusionFilter)
        {
            SceneModel model = TargetManager.scenes.Find((x) => x.SceneId == sceneId);

            if (sceneId == TargetManager.AnyScene.SceneId)
            {
                return;
            }

            if (model == null)
            {
                return;
            }

            Undo.SetCurrentGroupName("Delete Scene Node");
            int undoGroup = Undo.GetCurrentGroup();

            Undo.RegisterCompleteObjectUndo(SceneNodesObject.targetObject, "Scene Nodes");

            SerializedProperty scenesProperty = ScenesProp;

            for (int i = scenesProperty.arraySize - 1; i >= 0; i--)
            {
                SerializedSceneModel serializedScene = GetSerializedSceneModel(i);

                serializedScene.DeleteTransitionsInvolving(sceneId);

                if (serializedScene.SceneIdProp.intValue == sceneId)
                {
                    scenesProperty.DeleteArrayElementAtIndex(i);
                }
            }

            SerializedManager.ApplyModifiedProperties();

            for (int i = 0; i < SceneNodesProp.arraySize; i++)
            {
                if (GetSceneNodeIdProperty(i).intValue == sceneId)
                {
                    SceneNodesProp.DeleteArrayElementAtIndex(i);
                    break;
                }
            }

            SceneNodesObject.ApplyModifiedProperties();

            if (addToExclusionFilter)
            {
                SerializedProperty exclusion = SerializedSceneFilter.FindProperty("FilesToExclude");
                SerializedProperty newEntry  = exclusion.AddArrayElement();
                newEntry.stringValue = model.SceneAssetPath;
                SerializedSceneFilter.ApplyModifiedProperties();
            }

            Undo.CollapseUndoOperations(undoGroup);
        }
Exemple #4
0
        private void NodeEditor_OnSelectionChanged(object sender, System.EventArgs e)
        {
            lockConditionsEditor = null;
            transitionListEditor = null;
            serializedScene      = null;

            NodeEditor.NodeEditor nodeEditor = sender as NodeEditor.NodeEditor;

            IEnumerable <Node> selectedNodes = nodeEditor.GetSelectedNodes();

            foreach (Node selected in selectedNodes)
            {
                SceneNode sceneNode = selected as SceneNode;

                if (sceneNode == null)
                {
                    continue;
                }

                SetSelectedNode(sceneNode);

                if (transitionListEditor == null)
                {
                    transitionListEditor = CreateInstance <TransitionListEditor>();
                    transitionListEditor.OnRequestRepaint += TransitionListEditor_OnRequestRepaint;
                    transitionListEditor.Initialize(serializedManager, serializedScene);
                }

                return;
            }

            IEnumerable <Connector> selectedConnectors = nodeEditor.GetSelectedConnectors();

            foreach (Connector selected in selectedConnectors)
            {
                SceneNode startNode = selected.GetStartNode() as SceneNode;
                SceneNode endNode   = selected.GetEndNode() as SceneNode;

                SetSelectedNode(startNode);

                if (transitionListEditor == null)
                {
                    transitionListEditor = CreateInstance <TransitionListEditor>();
                    transitionListEditor.Initialize(serializedManager, serializedScene);
                }

                transitionListEditor.SetSelectedTransition(endNode.SceneId);
            }
        }
        private void OnDrawElement(Rect rect, int index, bool isActive, bool isSelected)
        {
            SerializedSceneModel serializedScene = serializedManager.GetSerializedSceneModel(index);
            
            Rect toggleRect = new Rect(rect);
            toggleRect.width = 20f;

            Rect labelRect = new Rect(rect);
            labelRect.xMin = 40f;

            EditorGUI.BeginChangeCheck();

            serializedScene.IncludeInIterProp.boolValue = EditorGUI.Toggle(toggleRect, 
                includeInIterContent, serializedScene.IncludeInIterProp.boolValue);

            EditorGUI.LabelField(labelRect, serializedScene.SceneNameProp.stringValue);

            if(EditorGUI.EndChangeCheck())
                serializedScene.SerializedObject.ApplyModifiedProperties();
        }