/// <summary>
        /// Loads the graph asset model and the persisted state associated with the asset.
        /// </summary>
        /// <param name="assetModel">The graph asset model to load.</param>
        /// <param name="boundObject">The GameObject to which the graph is bound, if any.</param>
        public void LoadGraphAsset(IGraphAssetModel assetModel, GameObject boundObject)
        {
            ResetStateCaches();

            if (assetModel != null)
            {
                if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(assetModel as Object, out var guid, out long fileId))
                {
                    guid   = (assetModel as Object)?.GetInstanceID().ToString() ?? "0";
                    fileId = 0;
                }
                PersistedState.SetAssetKey(guid + "/" + fileId);
            }
            else
            {
                PersistedState.SetAssetKey("");
            }

            using (var windowStateUpdater = WindowState.UpdateScope)
            {
                windowStateUpdater.LoadGraphAsset(assetModel, boundObject);
            }

            using (var graphViewStateUpdater = GraphViewState.UpdateScope)
            {
                graphViewStateUpdater.LoadGraphAsset(assetModel);
            }
        }
Ejemplo n.º 2
0
        public void TestWithGraphAssets(IGraphAssetModel graphAssetModel, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithMacros();
            var data   = new GraphAssetSearcherItemData(graphAssetModel);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 3
0
 public static void SetAssetDirty(this IGraphAssetModel graphAssetModel)
 {
     if (graphAssetModel as Object)
     {
         EditorUtility.SetDirty((Object)graphAssetModel);
     }
 }
        /// <summary>
        /// Loads a graph asset from file.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <param name="localFileId">The id of the asset in the file. If 0, the first asset of type <see cref="GraphAssetModel"/> will be loaded.</param>
        /// <returns>The loaded asset, or null if it was not found or if the asset found is not an <see cref="IGraphAssetModel"/>.</returns>
        public static IGraphAssetModel Load(string path, long localFileId)
        {
            IGraphAssetModel assetModel = null;

            if (localFileId != 0L)
            {
                var assets = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (var a in assets)
                {
                    if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(a, out _, out long localId))
                    {
                        continue;
                    }

                    if (localId == localFileId)
                    {
                        return(a as IGraphAssetModel);
                    }
                }
            }
            else
            {
                assetModel = (IGraphAssetModel)AssetDatabase.LoadAssetAtPath(path, typeof(GraphAssetModel));
            }

            return(assetModel);
        }
Ejemplo n.º 5
0
        public override void SetUp()
        {
            base.SetUp();

            m_Asset1 = GraphAssetCreationHelpers <TestGraphAssetModel> .CreateGraphAsset(CreatedGraphType, "Test1", "Assets/test1.asset");

            Window.CommandDispatcher.State.LoadGraphAsset(m_Asset1, null);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadGraphAssetCommand"/> class.
 /// </summary>
 /// <param name="assetModel">The asset model to load.</param>
 /// <param name="boundObject">The game object to which the graph should be bound.</param>
 /// <param name="loadStrategy">The type of loading and how it should affect the stack of loaded assets.</param>
 public LoadGraphAssetCommand(IGraphAssetModel assetModel, GameObject boundObject = null,
                              LoadStrategies loadStrategy = LoadStrategies.Replace)
 {
     AssetPath            = null;
     Asset                = assetModel;
     BoundObject          = boundObject;
     LoadStrategy         = loadStrategy;
     TruncateHistoryIndex = -1;
 }
Ejemplo n.º 7
0
        public static TypeHandle GenerateTypeHandle(this IGraphAssetModel asset, ITypeHandleSerializer serializer)
        {
            if (asset is VSGraphAssetModel vsGraphAssetModel)
            {
                return(serializer.GenerateTypeHandle(vsGraphAssetModel.GraphModel as VSGraphModel));
            }

            return(TypeHandle.Unknown);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Loads a graph asset in the window.
 /// </summary>
 /// <param name="assetModel">The graph asset to load.</param>
 /// <param name="boundObject">The GameObject to which the asset is bound, if any.</param>
 public void LoadGraphAsset(IGraphAssetModel assetModel, GameObject boundObject)
 {
     if (!string.IsNullOrEmpty(m_State.m_CurrentGraph.GetGraphAssetModelPath()))
     {
         m_State.m_LastOpenedGraph = m_State.m_CurrentGraph;
     }
     m_State.m_CurrentGraph         = new OpenedGraph(assetModel, boundObject);
     m_State.m_BlackboardGraphModel = null;
     m_State.SetUpdateType(UpdateType.Complete);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoadGraphAssetCommand"/> class.
 /// </summary>
 /// <param name="assetPath">The path of the asset to load.</param>
 /// <param name="assetLocalId">The subasset file id. If 0, the first GraphAssetModel found in the file will be loaded.</param>
 /// <param name="pluginRepository">The plugin repository.</param>
 /// <param name="boundObject">The game object to which the graph should be bound.</param>
 /// <param name="loadStrategy">The type of loading and how it should affect the stack of loaded assets.</param>
 /// <param name="truncateHistoryIndex">Truncate the stack of loaded assets at this index.</param>
 public LoadGraphAssetCommand(string assetPath, long assetLocalId, PluginRepository pluginRepository, GameObject boundObject = null,
                              LoadStrategies loadStrategy = LoadStrategies.Replace, int truncateHistoryIndex = -1)
 {
     Asset                = null;
     AssetPath            = assetPath;
     BoundObject          = boundObject;
     LoadStrategy         = loadStrategy;
     FileId               = assetLocalId;
     PluginRepository     = pluginRepository;
     TruncateHistoryIndex = truncateHistoryIndex;
 }
Ejemplo n.º 10
0
        public void SetCurrentSelection(IGraphAssetModel graphAssetModel, OpenMode mode, GameObject boundObject = null)
        {
            var windows = (GraphViewEditorWindow[])Resources.FindObjectsOfTypeAll(typeof(GraphViewEditorWindow));

            // Only the last focused editor should try to answer a change to the current selection.
            if (s_LastFocusedEditor != GetInstanceID() && windows.Length > 1)
            {
                return;
            }

            var currentOpenedGraph = CommandDispatcher?.State?.WindowState.CurrentGraph ?? default;

            // don't load if same graph and same bound object
            if (CommandDispatcher?.State?.WindowState.AssetModel != null &&
                graphAssetModel == currentOpenedGraph.GetGraphAssetModel() &&
                currentOpenedGraph.BoundObject == boundObject)
            {
                return;
            }

            var graphAssetFilePath = graphAssetModel.GetPath();
            var fileId             = graphAssetModel.GetFileId();

            // If there is not graph asset, unload the current one.
            if (string.IsNullOrWhiteSpace(graphAssetFilePath) || fileId == 0)
            {
                return;
            }

            // Load this graph asset.
            CommandDispatcher?.Dispatch(new LoadGraphAssetCommand(graphAssetFilePath, fileId, PluginRepository, boundObject));

            if (GraphView?.GraphModel?.AssetModel != null)
            {
                UpdateDirtyState(GraphView.GraphModel.AssetModel.Dirty);
            }

            if (mode != OpenMode.OpenAndFocus)
            {
                return;
            }

            // Check if an existing window already has this asset, if yes give it the focus.
            foreach (var window in windows)
            {
                if (window.CommandDispatcher.State.WindowState.AssetModel == graphAssetModel)
                {
                    window.Focus();
                    return;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenedGraph" /> class.
        /// </summary>
        /// <param name="graphAssetModel">The graph asset model.</param>
        /// <param name="boundObject">The GameObject bound to the graph.</param>
        public OpenedGraph(IGraphAssetModel graphAssetModel, GameObject boundObject)
        {
            if (graphAssetModel == null ||
                !AssetDatabase.TryGetGUIDAndLocalFileIdentifier(graphAssetModel as Object, out m_AssetGUID, out m_AssetLocalId))
            {
                m_AssetGUID    = "";
                m_AssetLocalId = 0L;
            }

            m_GraphAssetModel            = graphAssetModel;
            m_GraphAssetObjectInstanceID = (graphAssetModel as Object)?.GetInstanceID() ?? 0;
            m_BoundObject = boundObject;
        }
        static void AddScriptingGraphToObject(IGraphAssetModel graphAssetModel, GameObject target)
        {
            if (target.GetComponent <ConvertToEntity>() == null)
            {
                target.AddComponent <ConvertToEntity>();
            }

            ScriptingGraphAuthoring authoring = target.GetComponent <ScriptingGraphAuthoring>();

            if (authoring == null)
            {
                authoring = target.AddComponent <ScriptingGraphAuthoring>();
            }

            authoring.ScriptingGraph =
                ((DotsStencil)(graphAssetModel as GraphAssetModel)?.GraphModel.Stencil)?.CompiledScriptingGraphAsset;
        }
        void EnsureGraphAssetModelIsLoaded()
        {
            // GUIDToAssetPath cannot be done in ISerializationCallbackReceiver.OnAfterDeserialize so we do it here.

            var doReload = false;

            if (m_GraphAssetModel == null)
            {
                doReload = true;
            }
            else if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(m_GraphAssetModel as Object, out var assetGuid, out long localId))
            {
                doReload = assetGuid != m_AssetGUID || localId != m_AssetLocalId;
            }

            if (doReload)
            {
                // Try to load object from its GUID. Will fail if it is a memory based asset or if the asset was deleted.
                if (!string.IsNullOrEmpty(m_AssetGUID))
                {
                    var graphAssetModelPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID);
                    m_GraphAssetModel = Load(graphAssetModelPath, m_AssetLocalId);
                }

                // If it failed, try to retrieve object from its instance id (memory based asset).
                if (m_GraphAssetModel == null && m_GraphAssetObjectInstanceID != 0)
                {
                    m_GraphAssetModel = EditorUtility.InstanceIDToObject(m_GraphAssetObjectInstanceID) as IGraphAssetModel;
                }

                if (m_GraphAssetModel == null)
                {
                    m_AssetGUID    = null;
                    m_AssetLocalId = 0;
                    m_GraphAssetObjectInstanceID = 0;
                }
                else
                {
                    AssetDatabase.TryGetGUIDAndLocalFileIdentifier(m_GraphAssetModel as Object, out m_AssetGUID, out m_AssetLocalId);
                    m_GraphAssetObjectInstanceID = (m_GraphAssetModel as Object)?.GetInstanceID() ?? 0;
                }
            }
        }
Ejemplo n.º 14
0
        public override void SetUp()
        {
            base.SetUp();

            GraphViewSettings.UserSettings.EnableSnapToBorders = false;
            GraphViewSettings.UserSettings.EnableSnapToPort    = false;


            m_AssetModel = GraphAssetCreationHelpers <TestAssetModel> .CreateGraphAsset(typeof(TestStencil), "TestFile", k_FilePath);

            CommandDispatcher.Dispatch(new LoadGraphAssetCommand(m_AssetModel));

            m_NodeModel = CreateNode("Movable element", k_NodePos, 0, 1);

            // Add the minimap.
            var miniMap = new MiniMap();

            miniMap.style.left   = k_MinimapRect.x;
            miniMap.style.top    = k_MinimapRect.y;
            miniMap.style.width  = k_MinimapRect.width;
            miniMap.style.height = k_MinimapRect.height;
            graphView.Add(miniMap);
        }
Ejemplo n.º 15
0
 public void SetUp(CommandDispatcher commandDispatcher, IGraphAssetModel assetModel, IGraphTemplate template)
 {
     m_CommandDispatcher = commandDispatcher;
     m_Template          = template;
     m_AssetModel        = assetModel;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets the file id of af the graph asset model.
        /// </summary>
        /// <param name="self">The graph asset model.</param>
        /// <returns>The path of the graph asset model.</returns>
        public static long GetFileId(this IGraphAssetModel self)
        {
            var obj = self as Object;

            return(AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var _, out long fileId) ? fileId : 0);
        }
 protected override bool CanHandleAssetType(IGraphAssetModel asset)
 {
     return(asset is ContextSampleAsset);
 }
 public void SetUp()
 {
     m_Asset1 = GraphAssetCreationHelpers <TestGraphAssetModel> .CreateInMemoryGraphAsset(typeof(ClassStencil), "Test1");
 }
Ejemplo n.º 19
0
 public SearcherFilter WithGraphAsset(IGraphAssetModel assetModel)
 {
     this.RegisterGraphAsset(data => data.GraphAssetModel == assetModel);
     return(this);
 }
Ejemplo n.º 20
0
 public static ITypeMetadata GetMetadata(this IGraphAssetModel asset, Stencil stencil)
 {
     return(asset.GenerateTypeHandle(stencil).GetMetadata(stencil));
 }
Ejemplo n.º 21
0
 public GraphAssetSearcherItemData(IGraphAssetModel graphAssetModel)
 {
     GraphAssetModel = graphAssetModel;
 }
Ejemplo n.º 22
0
 public static TypeHandle GenerateTypeHandle(this IGraphAssetModel asset, Stencil stencil)
 {
     return(asset.GenerateTypeHandle(stencil.GraphContext.TypeHandleSerializer));
 }
 /// <inheritdoc />
 public RecipeBlackboardGraphModel(IGraphAssetModel graphAssetModel)
     : base(graphAssetModel) { }
Ejemplo n.º 24
0
 /// <inheritdoc />
 public VerticalBlackboardGraphModel(IGraphAssetModel graphAssetModel)
     : base(graphAssetModel)
 {
 }
Ejemplo n.º 25
0
 /// <inheritdoc />
 public override IBlackboardGraphModel CreateBlackboardGraphModel(IGraphAssetModel graphAssetModel)
 {
     return(new BlackboardGraphModel(graphAssetModel));
 }
Ejemplo n.º 26
0
        public virtual bool GetGraphAndObjectFromSelection(CommandDispatcher dispatcher, Object selectedObject, out IGraphAssetModel graphAssetModel, out GameObject boundObject)
        {
            graphAssetModel = null;
            boundObject     = null;

            if (selectedObject is IGraphAssetModel selectedObjectAsGraph)
            {
                // don't change the current object if it's the same graph
                if (selectedObjectAsGraph == dispatcher.State?.WindowState.GraphModel?.AssetModel)
                {
                    var currentOpenedGraph = dispatcher.State.WindowState.CurrentGraph;
                    graphAssetModel = currentOpenedGraph.GetGraphAssetModel();
                    boundObject     = currentOpenedGraph.BoundObject;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 27
0
 public bool IsSameAsset(IGraphAssetModel otherGraphAssetModel)
 {
     return(GetHashCode() == otherGraphAssetModel?.GetHashCode());
 }
Ejemplo n.º 28
0
 /// <inheritdoc />
 protected override bool CanHandleAssetType(IGraphAssetModel asset)
 {
     return(asset is VerticalGraphAssetModel);
 }
Ejemplo n.º 29
0
 protected override bool CanHandleAssetType(IGraphAssetModel asset)
 {
     return(true);
 }
        public void SetUp()
        {
            m_GraphAsset = GraphAssetCreationHelpers <TestGraphAssetModel> .CreateInMemoryGraphAsset(typeof(ClassStencil), "Test");

            m_GraphAsset.CreateGraph("Graph");
        }