public void InitBasicGraph(VSGraphModel graphModel)
        {
            var dotsStencil = (DotsStencil)graphModel.Stencil;

            dotsStencil.Type = m_GraphType;
            if (dotsStencil.CompiledScriptingGraphAsset == null)
            {
                CreateDotsCompiledScriptingGraphAsset(graphModel);
            }

            if (m_AttachToGameObject)
            {
                var graphAssetModel = graphModel.AssetModel;
                var graphHolder     = ObjectFactory.CreateGameObject(graphAssetModel.Name);
                Place(graphHolder, m_GraphHolderParent);

                AddScriptingGraphToObject((VSGraphAssetModel)graphModel.AssetModel, graphHolder);

                var authoringComponent = graphHolder.GetComponent <ScriptingGraphAuthoring>();

                if (m_GameObjects != null)
                {
                    Vector2 position = new Vector2(10, 10);
                    DotsStencil.CreateVariablesFromGameObjects(graphModel, authoringComponent, m_GameObjects, position, false);
                }
            }
        }
        internal static void CreateDotsCompiledScriptingGraphAsset(IGraphModel graphModel)
        {
            DotsStencil stencil = (DotsStencil)graphModel.Stencil;

            stencil.CompiledScriptingGraphAsset = ScriptableObject.CreateInstance <ScriptingGraphAsset>();
            AssetDatabase.AddObjectToAsset(stencil.CompiledScriptingGraphAsset, (Object)graphModel.AssetModel);
        }
Пример #3
0
        static State CreateObjectReference(State prevState, CreateObjectReferenceAction action)
        {
            var graph = action.GraphModel as VSGraphModel;

            if (action.Type == CreateObjectReferenceAction.ReferenceType.Subgraph)
            {
                DotsStencil.CreateSubGraphReference(graph, action.Objects.OfType <VSGraphAssetModel>(),
                                                    action.GraphSpacePosition);
            }
            else
            {
                if (prevState.EditorDataModel.BoundObject == null)
                {
                    Debug.LogError(
                        "Cannot create object references when a graph is opened in asset mode. Select a game object referencing this graph to do that.");
                    return(prevState);
                }

                var authoringComponent = (prevState.EditorDataModel.BoundObject as GameObject)
                                         ?.GetComponent <ScriptingGraphAuthoring>();
                Assert.IsNotNull(authoringComponent,
                                 "The currently bound object has no ScriptingGraphAuthoring component. This is impossible.");
                DotsStencil.CreateVariablesFromGameObjects(graph, authoringComponent,
                                                           action.Objects.OfType <GameObject>(), action.GraphSpacePosition,
                                                           action.Type == CreateObjectReferenceAction.ReferenceType.ObjectGraph);
            }

            prevState.MarkForUpdate(UpdateFlags.GraphTopology);
            return(prevState);
        }
        public void HandleDragPerform(DragPerformEvent e, Store store, DragNDropContext ctx, VisualElement element)
        {
            var state = store.GetState();

            if (state?.CurrentGraphModel == null)
            {
                return;
            }
            DotsStencil stencil = (DotsStencil)state.CurrentGraphModel.Stencil;

            if (stencil.Type == DotsStencil.GraphType.Subgraph)
            {
                Debug.LogError("Cannot create object references in a subgraph. Create a Data Input of type Game Object instead and feed it from an object graph in the scene.");
                return;
            }

            if (!(state?.EditorDataModel?.BoundObject as UnityEngine.Object))
            {
                Debug.LogError("Cannot create object references when a graph is opened in asset mode. Select a game object referencing this graph to do that.");
                return;
            }

            Vector2 graphSpacePosition = element.WorldToLocal(e.mousePosition);

            if (DragAndDrop.objectReferences.OfType <VSGraphAssetModel>().Any())
            {
                if (!DragAndDrop.objectReferences.All(x => x is VSGraphAssetModel assetModel && assetModel.GraphModel?.Stencil is DotsStencil dotsStencil && dotsStencil.Type == DotsStencil.GraphType.Subgraph))
                {
                    Debug.LogError("Object graph references must be created from their Game Object in the scene hierarchy. Only subgraphs can be referenced using their asset");
                    return;
                }
                store.Dispatch(new CreateObjectReferenceAction(graphSpacePosition, state?.CurrentGraphModel, DragAndDrop.objectReferences, CreateObjectReferenceAction.ReferenceType.Subgraph));
                return;
            }

            if (!DragAndDrop.objectReferences.Any(x => x is GameObject go && go.GetComponent <ScriptingGraphAuthoring>()))
            {
                store.Dispatch(new CreateObjectReferenceAction(graphSpacePosition, state?.CurrentGraphModel, DragAndDrop.objectReferences, CreateObjectReferenceAction.ReferenceType.Object));
                return;
            }

            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Object Reference"), false, () =>
            {
                store.Dispatch(new CreateObjectReferenceAction(graphSpacePosition, state?.CurrentGraphModel, DragAndDrop.objectReferences, CreateObjectReferenceAction.ReferenceType.Object));
            });
            menu.AddItem(new GUIContent("Smart Object"), false, () =>
            {
                store.Dispatch(new CreateObjectReferenceAction(graphSpacePosition, state?.CurrentGraphModel, DragAndDrop.objectReferences, CreateObjectReferenceAction.ReferenceType.ObjectGraph));
            });
            menu.DropDown(new Rect(e.originalMousePosition, Vector2.zero));
        }
 public DotsBlackboardProvider(DotsStencil stencil)
 {
     m_Stencil = stencil;
 }