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);

                if (m_GameObjects != null)
                {
                    var     authoringComponent = graphHolder.GetComponent <ScriptingGraphAuthoring>();
                    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);
        }
Beispiel #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));
        }
Beispiel #5
0
        public IEnumerable <TracingStep> GetDebuggingSteps(IGraphModel context)
        {
            DotsStencil dotsStencil = (DotsStencil)context.Stencil;

            if (!FrameTrace.IsValid)
            {
                yield break;
            }
            var reader = FrameTrace.AsReader();

            reader.BeginForEachIndex(0);
            var debugger = (DotsDebugger)dotsStencil.Debugger;

            while (reader.RemainingItemCount != 0)
            {
                if (debugger.ReadDebuggingDataModel(ref reader, this, out TracingStep step))
                {
                    yield return(step);
                }
            }

            reader.EndForEachIndex();
        }
Beispiel #6
0
 public DotsBlackboardProvider(DotsStencil stencil)
 {
     m_Stencil = stencil;
 }