Ejemplo n.º 1
0
        protected override void OnGUI(Rect position, GUIContent label)
        {
            var attribute = metadata.GetAttribute <HEU_UnitButtonAttribute>(true);

            if (attribute != null)
            {
                string functionName = attribute.functionName;
                string btnLabel     = attribute.buttonLabel;
                int    btnWidth     = attribute.buttonWidth;

                var buttonPosition = new Rect(
                    position.x,
                    position.y,
                    position.width + btnWidth,
                    16
                    );

                if (GUI.Button(buttonPosition, btnLabel, new GUIStyle(UnityEditor.EditorStyles.miniButton)))
                {
                    if (attribute != null)
                    {
                        object         typeObject = metadata.parent.value;
                        GraphReference reference  = GraphWindow.activeReference;
                        typeObject.GetType().GetMethod(functionName).Invoke(typeObject, new object[1] {
                            reference
                        });
                    }
                }
            }
        }
        public static bool IsHierarchyListening(GraphReference reference)
        {
            using (var stack = reference.ToStackPooled())
            {
                // Check if any parent of the graph is not listening
                while (stack.isChild)
                {
                    var parent = stack.parent;

                    // Exit the parent first, as the IsListening method expects to be at the level of the parent
                    stack.ExitParentElement();

                    if (parent is IGraphEventListener listener && !listener.IsListening(stack))
                    {
                        return(false);
                    }
                }

                // Check if the root graph is not listening
                if (stack.graph is IGraphEventListener graphListener && !graphListener.IsListening(stack))
                {
                    return(false);
                }

                return(true);
            }
        }
Ejemplo n.º 3
0
        public static bool CanPredict(IUnitValuePort port, GraphReference reference)
        {
            Ensure.That(nameof(port)).IsNotNull(port);

            var flow = New(reference);

            flow.isPrediction = true;

            bool canPredict;

            if (port is ValueInput)
            {
                canPredict = flow.CanPredict((ValueInput)port);
            }
            else if (port is ValueOutput)
            {
                canPredict = flow.CanPredict((ValueOutput)port);
            }
            else
            {
                throw new NotSupportedException();
            }

            flow.Dispose();

            return(canPredict);
        }
Ejemplo n.º 4
0
 private void TriggerUpdate(GraphReference reference)
 {
     using (var flow = Flow.New(reference))
     {
         Update(flow);
     }
 }
Ejemplo n.º 5
0
        public override string GenerateValueOutput(ValueOutput output, int indent)
        {
            var outputString = string.Empty;

            if (output == liveUnit.result)
            {
                var a           = liveUnit.a;
                var b           = liveUnit.b;
                var entry       = (unit.graph.units.ToListPooled().Where((x) => { return((x as EntryUnit) != null); }).ToListPooled()[0] as EntryUnit);
                var methodInput = entry as MethodInputUnit;

                GraphReference reference = null;

                if (methodInput != null)
                {
                    reference = GraphReference.New(methodInput.macro, BoltX.UnitGuids(methodInput.graph as FlowGraph), false);
                }

                var aConnection = a.connection;
                var bConnection = b.connection;
                var aSource     = aConnection.source;
                var bSource     = bConnection.source;

                outputString += aConnection != null?aSource.unit.CodeGenerator().GenerateValueOutput(aSource, 0) : Patcher.ActualValue(a.type, Flow.FetchValue(a, a.type, reference));

                outputString += CodeBuilder.Operator(BinaryOperator.Or);

                outputString += bConnection != null?bSource.unit.CodeGenerator().GenerateValueOutput(bSource, 0) : Patcher.ActualValue(b.type, Flow.FetchValue(b, b.type, reference));
            }

            return(outputString);
        }
Ejemplo n.º 6
0
 private void EditButton(Rect position)
 {
     if (GUI.Button(position, "Edit"))
     {
         GraphWindow.OpenActive(GraphReference.New((Method)macro.objectReferenceValue, true));
     }
 }
        protected override void OnGUI(Rect position, GUIContent label)
        {
            BeginBlock(metadata, position, GUIContent.none);

            var buttonPosition = new Rect(
                position.x,
                position.y,
                position.width + 8,
                16
                );

            if (GUI.Button(buttonPosition, "Trigger", new GUIStyle(UnityEditor.EditorStyles.miniButton)))
            {
                var attribute = metadata.GetAttribute <UnitButtonAttribute>(true);

                if (attribute != null)
                {
                    var method = attribute.action;

                    object         typeObject = metadata.parent.value;
                    GraphReference reference  = GraphWindow.activeReference;
                    typeObject.GetType().GetMethod(method).Invoke(typeObject, new object[1] {
                        reference
                    });
                }
            }

            if (EndBlock(metadata))
            {
                metadata.RecordUndo();
            }
        }
Ejemplo n.º 8
0
        public static void TriggerEventHandler <TArgs>(this GraphStack stack, Func <EventHook, bool> predicate, TArgs args, Func <IGraphParentElement, bool> recurse, bool force)
        {
            Ensure.That(nameof(stack)).IsNotNull(stack);

            GraphReference reference = null;

            foreach (var element in stack.graph.elements)
            {
                if (element is IGraphEventHandler <TArgs> handler)
                {
                    if (reference == null)
                    {
                        reference = stack.ToReference();
                    }

                    if (predicate == null || predicate.Invoke(handler.GetHook(reference)))
                    {
                        if (force || handler.IsListening(reference))
                        {
                            handler.Trigger(reference, args);
                        }
                    }
                }

                if (element is IGraphParentElement parentElement && recurse(parentElement))
                {
                    if (stack.TryEnterParentElementUnsafe(parentElement))
                    {
                        stack.TriggerEventHandler(predicate, args, recurse, force);
                        stack.ExitParentElement();
                    }
                }
            }
        }
        private bool CanProcess(out GraphReference reference)
        {
            reference = GraphWindow.activeReference;
            var active = GraphWindow.active;

            return(reference != null && active != null && active.hasFocus);
        }
Ejemplo n.º 10
0
    public IEnumerator Enter(Flow flow)
    {
        currentFlow = flow;

        GameObject self = flow.GetValue <GameObject>(selfIn);

        float time = flow.GetValue <float>(timeIn);

        graphReference = flow.stack.AsReference();

        enemy    = self.GetComponent <Enemy>();
        animator = self.GetComponent <Animator>();

        if (!enemy.IsAlive)
        {
            currentFlow.StopCoroutine(true);
        }
        enemy.ReponseToAttack += TryCounter;


        //Attack start
        animator.SetBool("Attacking", true);
        enemy.enemyState = Enemy.EnemyState.Vulnerable;
        vulnerable       = true;
        Player.Instance.Warn(new AttackWarning(self, AttackWarning.WarningType.StartAttack));

        yield return(new WaitForSeconds(time));

        animator.SetBool("Attacking", false);
        enemy.enemyState       = Enemy.EnemyState.Normal;
        vulnerable             = false;
        enemy.ReponseToAttack -= TryCounter;
        yield return(finished);
    }
Ejemplo n.º 11
0
        public static object Predict(IUnitValuePort port, GraphReference reference)
        {
            Ensure.That(nameof(port)).IsNotNull(port);

            var flow = New(reference);

            flow.isPrediction = true;

            object value;

            if (port is ValueInput)
            {
                value = flow.GetValue((ValueInput)port);
            }
            else if (port is ValueOutput)
            {
                value = flow.GetValue((ValueOutput)port);
            }
            else
            {
                throw new NotSupportedException();
            }

            flow.Dispose();

            return(value);
        }
    void OnEnable()
    {
        string val            = DialogueLua.GetVariable("UserChoice").asString;
        var    graphReference = GraphReference.New(_TargetFlowMachine, true);

        Variables.Graph(graphReference).Set(_TargetGraphVariableName, val);
    }
Ejemplo n.º 13
0
    public IEnumerator Enter(Flow flow)
    {
        currentFlow = flow;

        GameObject self = flow.GetValue <GameObject>(selfIn);

        float time = flow.GetValue <float>(timeIn);

        breakThresholdValue = flow.GetValue <Attack>(breakThreshold);

        graphReference = flow.stack.AsReference();

        enemy    = self.GetComponent <Enemy>();
        animator = self.GetComponent <Animator>();

        if (!enemy.IsAlive)
        {
            currentFlow.StopCoroutine(true);
        }

        animator.SetBool("Blocking", true);

        enemy.Attacked        += TryBreak;
        enemy.ReponseToAttack += TryAttack;

        enemy.enemyState = Enemy.EnemyState.Guard;

        yield return(new WaitForSeconds(time));

        animator.SetBool("Blocking", false);
        enemy.enemyState       = Enemy.EnemyState.Normal;
        enemy.Attacked        -= TryBreak;
        enemy.ReponseToAttack -= TryAttack;
        yield return(finished);
    }
Ejemplo n.º 14
0
        /// <summary>
        /// Draws a button to click and edit the graph of this method.
        /// </summary>
        /// <param name="previous"></param>
        private Rect EditGraph(Rect previous)
        {
            var padding       = 4f;
            var doublePadding = padding * 2;

            var returnLabelSize = GUI.skin.label.CalcSize(new GUIContent("Returns"));

            var buttonRect = previous;

            buttonRect.y     += 24;
            buttonRect.x     += padding;
            buttonRect.width -= doublePadding;
            buttonRect.height = 18;

            if (GUI.Button(buttonRect, "Edit Graph"))
            {
                declaration.owner.activeGraph = declaration.graph;
                var reference = GraphReference.New(declaration, true);
                GraphWindow.OpenActive(reference);
            }

            y += 20;

            return(buttonRect);
        }
 public static void StopListening(this IGraphEventListener listener, GraphReference reference)
 {
     using (var stack = reference.ToStackPooled())
     {
         listener.StopListening(stack);
     }
 }
Ejemplo n.º 16
0
 public void TriggerButton(GraphReference reference)
 {
     if (Application.isEditor && Application.isPlaying)
     {
         T vEvent = Flow.FetchValue <T>(_event, reference);
         vEvent?.Raise(vEvent.InspectorRaiseValue);
     }
 }
Ejemplo n.º 17
0
 public override void Instantiate(GraphReference instance)
 {
     base.Instantiate(instance);
     if (_delegate != null)
     {
         _delegate.initialized = false;
     }
 }
Ejemplo n.º 18
0
        public override void Instantiate(GraphReference instance)
        {
            base.Instantiate(instance);

            if (this is IGraphEventListener listener && instance.GetElementData <State.Data>(source).isActive)
            {
                listener.StartListening(instance);
            }
        }
Ejemplo n.º 19
0
 public IEnumerable <string> GetDynamicVariableNames(VariableKind kind, GraphReference reference)
 {
     return(units.OfType <IUnifiedVariableUnit>()
            .Where(v => v.kind == kind && Flow.CanPredict(v.name, reference))
            .Select(v => Flow.Predict <string>(v.name, reference))
            .Where(name => !StringUtility.IsNullOrWhiteSpace(name))
            .Distinct()
            .OrderBy(name => name));
 }
Ejemplo n.º 20
0
        public override void Instantiate(GraphReference instance)
        {
            base.Instantiate(instance);

            if (this is IGraphEventListener listener && XGraphEventListener.IsHierarchyListening(instance))
            {
                listener.StartListening(instance);
            }
        }
Ejemplo n.º 21
0
        public override void Uninstantiate(GraphReference instance)
        {
            if (this is IGraphEventListener listener)
            {
                listener.StopListening(instance);
            }

            base.Uninstantiate(instance);
        }
Ejemplo n.º 22
0
        public override void StartListening(GraphStack stack)
        {
            //m_machine = stack.machine;
            m_graphReference = stack.ToReference();

            if (startOn && AttemptRegister(Flow.New(graphReference)))
            {
                base.StartListening(stack);
            }
        }
Ejemplo n.º 23
0
        public static Flow New(GraphReference reference)
        {
            Ensure.That(nameof(reference)).IsNotNull(reference);

            var flow = GenericPool <Flow> .New(() => new Flow());;

            flow.stack = reference.ToStackPooled();

            return(flow);
        }
Ejemplo n.º 24
0
        public static object FetchValue(ValueInput input, GraphReference reference)
        {
            var flow = New(reference);

            var result = flow.GetValue(input);

            flow.Dispose();

            return(result);
        }
Ejemplo n.º 25
0
        public override void Instantiate(GraphReference instance)
        {
            base.Instantiate(instance);

            var data = instance.GetElementData <Data>(this);

            if (this is IGraphEventListener listener && data.isActive)
            {
                listener.StartListening(instance);
            }
Ejemplo n.º 26
0
        public override EventHook GetHook(GraphReference reference)
        {
            if (!reference.hasData)
            {
                return(hookName);
            }

            var data = reference.GetElementData <Data>(this);

            return(new EventHook(hookName, data.target));
        }
Ejemplo n.º 27
0
 void EditGraph()
 {
     if (graphReference.IsUnityNull())
     {
         graphReference = GraphReference.New(flowMacro, ensureValid: true);
     }
     if (!graphReference.IsUnityNull() && graphReference.isValid)
     {
         GraphWindow.OpenActive(graphReference);
     }
 }
        static GraphReference CreateGraphReferenceFromGrapohAndEntity(GraphBuilder b, GraphDefinition nestedDef, GraphBuilder.VariableHandle entityVariableDataIndex)
        {
            var graphReference = new GraphReference();

            graphReference.Inputs.SetCount(nestedDef.InputTriggers.Count);
            graphReference.Outputs.SetCount(nestedDef.OutputTriggers.Count);
            graphReference.DataInputs.SetCount(nestedDef.InputDatas.Count);
            graphReference.DataOutputs.SetCount(nestedDef.OutputDatas.Count);
            graphReference = b.AddNode(graphReference);
            b.BindVariableToInput(entityVariableDataIndex, graphReference.Target);
            return(graphReference);
        }
Ejemplo n.º 29
0
        protected Analyser(GraphReference reference, TTarget target) : base(target, new TAnalysis())
        {
            Ensure.That(nameof(reference)).IsNotNull(reference);

            this.reference = reference;

            // HACK: It makes more sense to think of analysis as reference-bound,
            // however in practice they are context-bound and therefore it is safe
            // (and more importantly faster) to cache the context once for recursive
            // analyses.
            this.context = reference.Context();
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Invokes a method of a Live Type.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="liveType"></param>
        /// <param name="parameters"></param>
        public static void InvokeVoid(MethodInstance instance)
        {
            var reference = GraphReference.New(instance.method, true);
            var flow      = Flow.New(reference, instance.isCoroutine);

            flow.AssignLocal <ILiveObject>("This", instance.target);

            SetParameters(instance, ((MethodInputUnit)instance.method.entry));

            TriggerFlow(flow, instance.method.entry.trigger);

            RemoveInstance(instance);
        }