示例#1
0
        internal static GraphStack New(IGraphRoot root, List <IGraphParentElement> parentElements)
        {
            var stack = GenericPool <GraphStack> .New(() => new GraphStack());

            stack.InitializeNoAlloc(root, parentElements, true);
            return(stack);
        }
        private static IGraphDebugData FetchRootDebugData(IGraphRoot root)
        {
            if (!rootDatas.TryGetValue(root, out var rootData))
            {
                rootData = new GraphDebugData(root.childGraph);
                rootDatas.Add(root, rootData);
            }

            return(rootData);
        }
示例#3
0
        public static GraphReference New(IGraphRoot root, IEnumerable <IGraphParentElement> parentElements, bool ensureValid)
        {
            if (!ensureValid && !IsValidRoot(root))
            {
                return(null);
            }

            var reference = new GraphReference();

            reference.Initialize(root, parentElements, ensureValid);
            reference.Hash();
            return(reference);
        }
示例#4
0
        public static GraphReference New(IGraphRoot root, bool ensureValid)
        {
            if (!ensureValid && !IsValidRoot(root))
            {
                return(null);
            }

            var reference = new GraphReference();

            reference.Initialize(root);
            reference.Hash();
            return(reference);
        }
        protected void Initialize(IGraphRoot root)
        {
            if (!IsValidRoot(root))
            {
                throw new ArgumentException("Graph pointer root must be a valid Unity object with a non-null child graph.", nameof(root));
            }

            if (!(root is IMachine && root is MonoBehaviour || root is IMacro && root is ScriptableObject))
            {
                throw new ArgumentException("Graph pointer root must be either a machine or a macro.", nameof(root));
            }

            this.root = root;

            parentStack.Add(root);

            graphStack.Add(root.childGraph);

            dataStack.Add(machine?.graphData);

            debugDataStack.Add(fetchRootDebugDataBinding?.Invoke(root));

            if (machine != null)
            {
                // Annoyingly, getting the gameObject property is an API call
                // First, we'll try using our IMachine safe reference that is assigned in play mode on Awake
                // If that fails, we'll try fetching it dynamically

                if (machine.threadSafeGameObject != null)
                {
                    gameObject = machine.threadSafeGameObject;
                }
                else if (UnityThread.allowsAPI)
                {
                    gameObject = component.gameObject;
                }
                else
                {
                    throw new GraphPointerException("Could not fetch graph pointer root game object.", this);
                }
            }
            else
            {
                gameObject = null;
            }
        }
        protected void Initialize(IGraphRoot root, IEnumerable <IGraphParentElement> parentElements, bool ensureValid)
        {
            Initialize(root);

            Ensure.That(nameof(parentElements)).IsNotNull(parentElements);

            foreach (var parentElement in parentElements)
            {
                if (!TryEnterParentElement(parentElement, out var error))
                {
                    if (ensureValid)
                    {
                        throw new GraphPointerException(error, this);
                    }

                    break;
                }
            }
        }
示例#7
0
        private void InitializeNoAlloc(IGraphRoot root, List <IGraphParentElement> parentElements, bool ensureValid)
        {
            Initialize(root);

            Ensure.That(nameof(parentElements)).IsNotNull(parentElements);

            foreach (var parentElement in parentElements)
            {
                if (!TryEnterParentElement(parentElement, out var error))
                {
                    if (ensureValid)
                    {
                        throw new GraphPointerException(error, this);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
 protected static bool IsValidRoot(IGraphRoot root)
 {
     return(root?.childGraph != null && root as UnityObject != null);
 }