예제 #1
0
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(GameObject);

            if (entity != Entity.Null)
            {
                quaternion currentRotation;
                // Make sure that the entity has a Rotation
                if (!ctx.EntityManager.HasComponent <Rotation>(entity))
                {
                    ctx.EntityManager.AddComponent <Rotation>(entity);
                    currentRotation = quaternion.identity;
                }
                else
                {
                    currentRotation = ctx.EntityManager.GetComponentData <Rotation>(entity).Value;
                }

                currentRotation *= Quaternion.Euler(ctx.ReadFloat3(Value));
                ctx.EntityManager.SetComponentData(entity, new Rotation {
                    Value = currentRotation
                });
            }

            ctx.Trigger(Output);
        }
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            PhysicsCollider physicsCollider = ctx.EntityManager.GetComponentData <PhysicsCollider>(entity);
            Collider *      colliderPtr     = (Collider *)physicsCollider.Value.GetUnsafePtr();

            CollisionFilter newFilter = new CollisionFilter();

            newFilter.BelongsTo    = (uint)ctx.ReadInt(this.BelongsTo);
            newFilter.CollidesWith = (uint)ctx.ReadInt(this.CollidesWith);
            newFilter.GroupIndex   = ctx.ReadInt(this.GroupIndex);

            colliderPtr->Filter = newFilter;

            ctx.Trigger(Output);
        }
예제 #3
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsMass>(entity) || !ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                return;
            }

            PhysicsMass     physicsMass     = ctx.EntityManager.GetComponentData <PhysicsMass>(entity);
            PhysicsVelocity physicsVelocity = ctx.EntityManager.GetComponentData <PhysicsVelocity>(entity);

            if (LinearOnly)
            {
                physicsVelocity.ApplyLinearImpulse(physicsMass, ctx.ReadFloat3(Value));
            }
            else
            {
                Translation t = ctx.EntityManager.GetComponentData <Translation>(entity);
                Rotation    r = ctx.EntityManager.GetComponentData <Rotation>(entity);

                ComponentExtensions.ApplyImpulse(ref physicsVelocity, physicsMass, t, r, ctx.ReadFloat3(Value), ctx.ReadFloat3(Point));
            }

            ctx.EntityManager.SetComponentData(entity, physicsVelocity);
        }
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsGravityFactor>(entity))
            {
                ctx.EntityManager.AddComponent <PhysicsGravityFactor>(entity);
            }

            float gravityFactor = ctx.ReadFloat(Value);

            ctx.EntityManager.SetComponentData(entity, new PhysicsGravityFactor()
            {
                Value = gravityFactor
            });

            ctx.Trigger(Output);
        }
예제 #5
0
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var readValue = ctx.ReadValueOfType(Value, VariableType);

            ctx.Write(OutValue, readValue);
            ctx.Trigger(Output);
        }
예제 #6
0
        public Execution Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            Entity target = ctx.ReadEntity(Target);

            Assert.AreNotEqual(Entity.Null, target, "Referenced graph must have an entity");
            int index = ctx.GetTriggeredIndex(Inputs, port);

            return(ctx.RunNestedGraph(this, target, index));
        }
예제 #7
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            PhysicsCollider physicsCollider = ctx.EntityManager.GetComponentData <PhysicsCollider>(entity);
            Collider *      colliderPtr     = (Collider *)physicsCollider.Value.GetUnsafePtr();

            if (!ctx.EntityManager.HasComponent <PhysicsGravityFactor>(entity))
            {
                ctx.EntityManager.AddComponent <PhysicsGravityFactor>(entity);
            }
            float gravityFactor = ctx.ReadFloat(GravityFactor);

            ctx.EntityManager.SetComponentData(entity, new PhysicsGravityFactor()
            {
                Value = gravityFactor
            });

            if (!ctx.EntityManager.HasComponent <PhysicsMass>(entity))
            {
                ctx.EntityManager.AddComponent <PhysicsMass>(entity);
            }
            float mass = ctx.ReadFloat(Mass);

            ctx.EntityManager.SetComponentData(entity, PhysicsMass.CreateDynamic(colliderPtr->MassProperties, mass));

            if (!ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                ctx.EntityManager.AddComponent <PhysicsVelocity>(entity);
            }
            ctx.EntityManager.SetComponentData(entity, new PhysicsVelocity {
                Linear = float3.zero, Angular = float3.zero
            });

            float drag        = ctx.ReadFloat(Drag);
            float angularDrag = ctx.ReadFloat(AngularDrag);

            if (!ctx.EntityManager.HasComponent <PhysicsDamping>(entity))
            {
                ctx.EntityManager.AddComponent <PhysicsDamping>(entity);
            }
            ctx.EntityManager.SetComponentData(entity, new PhysicsDamping {
                Linear = drag, Angular = angularDrag
            });

            ctx.Trigger(Output);
        }
예제 #8
0
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            // MBRIAU: NOTES:
            // If the scale is only modified in the editor, the info is only stored in the CompositeScale
            // If the scale is modified by Scale, it's stored in Scale and CompositeScale is updated with that value
            // If the scale is modified by NonUniformScale, it's stored in NonUniformScale and CompositeScale is updated with that value

            // WEIRD CASES
            // if both are set, the CompositeScale is not properly updated with what is rendered! We need to make sure to avoid setting both NonUniformScale and UniformScale
            // TODO: Would be interesting to try to add a Scale/NonUniformScale and then remove the component to see how the CompositeScale behaves

            var entity = ctx.ReadEntity(GameObject);

            if (entity != Entity.Null)
            {
                // Important to read right now and get the right value before messing around with the scaling components of that entity
                Value  v = ctx.ReadValue(Value);
                float3 newScale;
                if (v.Type == ValueType.Float)
                {
                    newScale = new float3(v.Float, v.Float, v.Float);
                }
                else if (v.Type == ValueType.Int)
                {
                    newScale = new float3(v.Int, v.Int, v.Int);
                }
                else if (v.Type == ValueType.Float3)
                {
                    newScale = v.Float3;
                }
                else
                {
                    // Simply return without triggering
                    // TODO: Should display a warning or only allow float and float3 to be connected
                    return;
                }

                NonUniformScale nus = new NonUniformScale {
                    Value = newScale
                };

                if (ctx.EntityManager.HasComponent <Scale>(entity))
                {
                    ctx.EntityManager.RemoveComponent <Scale>(entity);
                }

                if (!ctx.EntityManager.HasComponent <NonUniformScale>(entity))
                {
                    ctx.EntityManager.AddComponent <NonUniformScale>(entity);
                }

                ctx.EntityManager.SetComponentData(entity, nus);
            }

            ctx.Trigger(Output);
        }
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity != Unity.Entities.Entity.Null)
            {
                ctx.EntityManager.SetEnabled(entity, false);
            }
            ctx.Trigger(Output);
        }
예제 #10
0
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Prefab);

            if (entity != Entity.Null)
            {
                var instantiated = ctx.EntityManager.Instantiate(entity);
                ctx.Write(Instantiated, instantiated);
            }

            ctx.Trigger(Output);
        }
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(GameObject);

            if (entity != Entity.Null)
            {
                var t = ctx.EntityManager.GetComponentData <Translation>(entity);
                t.Value = ctx.ReadFloat3(Value);
                ctx.EntityManager.SetComponentData(entity, t);
            }

            ctx.Trigger(Output);
        }
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var prefab = ctx.ReadEntity(Prefab);

            if (prefab == Entity.Null)
            {
                ctx.Trigger(Output);
                return;
            }

            var entity = ctx.EntityManager.Instantiate(prefab);

            var activated = ctx.ReadBool(Activate);

            ctx.EntityManager.SetEnabled(entity, activated);

            AddComponent(ctx, entity, new Translation {
                Value = ctx.ReadFloat3(Position)
            });
            AddComponent(ctx, entity, new Rotation {
                Value = ctx.ReadQuaternion(Rotation)
            });

            var scale          = ctx.ReadFloat3(Scale);
            var isUniformScale = scale.x.Equals(scale.y) && scale.x.Equals(scale.z);

            if (isUniformScale)
            {
                if (ctx.EntityManager.HasComponent <NonUniformScale>(entity))
                {
                    ctx.EntityManager.RemoveComponent <NonUniformScale>(entity);
                }
                AddComponent(ctx, entity, new Scale {
                    Value = scale.x
                });
            }
            else
            {
                if (ctx.EntityManager.HasComponent <Scale>(entity))
                {
                    ctx.EntityManager.RemoveComponent <Scale>(entity);
                }
                AddComponent(ctx, entity, new NonUniformScale {
                    Value = scale
                });
            }

            ctx.Write(Instantiated, entity);
            ctx.Trigger(Output);
        }
        public unsafe Execution Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return(Execution.Done);
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return(Execution.Done);
            }

            ref State state = ref ctx.GetState(this);
예제 #14
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            // No mass (infinite)
            if (ctx.EntityManager.HasComponent <PhysicsMass>(entity))
            {
                ctx.EntityManager.RemoveComponent <PhysicsMass>(entity);
            }

            // No damping (animated)
            if (ctx.EntityManager.HasComponent <PhysicsDamping>(entity))
            {
                ctx.EntityManager.RemoveComponent <PhysicsDamping>(entity);
            }

            // No gravity (actually need a component to "remove" the gravity)
            if (!ctx.EntityManager.HasComponent <PhysicsGravityFactor>(entity))
            {
                ctx.EntityManager.AddComponent <PhysicsGravityFactor>(entity);
            }
            ctx.EntityManager.SetComponentData(entity, new PhysicsGravityFactor()
            {
                Value = 0
            });

            // Let's set the Velocity to zero only if it hasn't been set yet (MBriau: not sure if it should always be set to zero or maybe add an option)
            if (!ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                ctx.EntityManager.AddComponentData(entity, new PhysicsVelocity()
                {
                    Linear = float3.zero, Angular = float3.zero
                });
            }

            ctx.Trigger(Output);
        }
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            Assert.AreEqual(Input.Port.Index, port.Port.Index);
            string message = null;

            for (uint i = 0; i < Messages.DataCount; i++)
            {
                ConcatToMessage(ctx, ctx.ReadValue(Messages.SelectPort(i)), ref message);
            }

            if (message != null)
            {
                Debug.Log(message);
            }

            ctx.Trigger(Output);
        }
예제 #16
0
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            bool anyMatched = false;
            var  val        = ctx.ReadInt(Selector);

            for (uint i = 0; i < SwitchValues.DataCount; i++)
            {
                if (ctx.ReadInt(SwitchValues.SelectPort(i)) == val)
                {
                    ctx.Trigger(SwitchTriggers.SelectPort(i));
                    anyMatched = true;
                }
            }
            if (!anyMatched)
            {
                ctx.Trigger(Default);
            }
        }
        public Execution Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var go = ctx.ReadEntity(GameObject);

            if (go == Entity.Null)
            {
                go = ctx.CurrentEntity;
            }

            if (!ctx.EntityManager.HasComponent <Child>(go))
            {
                ctx.Write(Child, Entity.Null);
                ctx.Write(ChildIndex, -1);
                ctx.Trigger(Done);
                return(Execution.Done);
            }

            ref State state = ref ctx.GetState(this);
예제 #18
0
        public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(GameObject);

            if (entity != Entity.Null)
            {
                // Make sure that the entity has a Rotation
                if (!ctx.EntityManager.HasComponent <Rotation>(entity))
                {
                    ctx.EntityManager.AddComponent <Rotation>(entity);
                }

                Rotation r = new Rotation {
                    Value = ctx.ReadQuaternion(Value)
                };
                ctx.EntityManager.SetComponentData(entity, r);
            }

            ctx.Trigger(Output);
        }
예제 #19
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsVelocity>(entity) || !ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                return;
            }

            PhysicsVelocity physicsVelocity = ctx.EntityManager.GetComponentData <PhysicsVelocity>(entity);
            PhysicsMass     physicsMass     = ctx.EntityManager.GetComponentData <PhysicsMass>(entity);

            physicsVelocity.ApplyLinearImpulse(physicsMass, ctx.ReadFloat3(Value));

            ctx.EntityManager.SetComponentData(entity, physicsVelocity);
        }
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            PhysicsCollider physicsCollider = ctx.EntityManager.GetComponentData <PhysicsCollider>(entity);
            Collider *      colliderPtr     = (Collider *)physicsCollider.Value.GetUnsafePtr();

            colliderPtr->Filter = CollisionFilter.Default;

            ctx.Trigger(Output);
        }
예제 #21
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsMass>(entity) || !ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            PhysicsCollider physicsCollider = ctx.EntityManager.GetComponentData <PhysicsCollider>(entity);

            float newMass = ctx.ReadFloat(Mass);

            Collider *colliderPtr = (Collider *)physicsCollider.Value.GetUnsafePtr();

            ctx.EntityManager.SetComponentData(entity, PhysicsMass.CreateDynamic(colliderPtr->MassProperties, newMass));
        }
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                return;
            }

            PhysicsCollider physicsCollider = ctx.EntityManager.GetComponentData <PhysicsCollider>(entity);

            Collider *colliderPtr = (Collider *)physicsCollider.Value.GetUnsafePtr();

            float3 linearVelocity  = ctx.ReadFloat3(Linear);
            float3 angularVelocity = ctx.ReadFloat3(Angular);

            // TODO: MBRIAU: Make sure to understand exactly what's going on here
            // Calculate the angular velocity in local space from rotation and world angular velocity
            float3 angularVelocityLocal = math.mul(math.inverse(colliderPtr->MassProperties.MassDistribution.Transform.rot), angularVelocity);

            ctx.EntityManager.SetComponentData(entity, new PhysicsVelocity()
            {
                Linear  = linearVelocity,
                Angular = angularVelocityLocal
            });

            ctx.Trigger(Output);
        }
예제 #23
0
        public unsafe void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
        {
            var entity = ctx.ReadEntity(Entity);

            if (entity == Unity.Entities.Entity.Null)
            {
                return;
            }

            if (!ctx.EntityManager.HasComponent <PhysicsCollider>(entity))
            {
                return;
            }

            if (ctx.EntityManager.HasComponent <PhysicsGravityFactor>(entity))
            {
                ctx.EntityManager.RemoveComponent <PhysicsGravityFactor>(entity);
            }

            if (ctx.EntityManager.HasComponent <PhysicsMass>(entity))
            {
                ctx.EntityManager.RemoveComponent <PhysicsMass>(entity);
            }

            if (ctx.EntityManager.HasComponent <PhysicsVelocity>(entity))
            {
                ctx.EntityManager.RemoveComponent <PhysicsVelocity>(entity);
            }

            if (ctx.EntityManager.HasComponent <PhysicsDamping>(entity))
            {
                ctx.EntityManager.RemoveComponent <PhysicsDamping>(entity);
            }

            ctx.Trigger(Output);
        }
 public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
 {
     ctx.Trigger(ctx.ReadBool(Condition) ? IfTrue : IfFalse);
 }
예제 #25
0
 public void Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
 {
     ctx.Write(State, port.GetPort().Index == SetTrue.GetPort().Index);
     ctx.Trigger(Done);
 }
 public Execution Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
 {
     Execution     Result = ctx.IsNodeCurrentlyScheduledForUpdate() ? Execution.Running : Execution.Done;
     ref WaitState state  = ref ctx.GetState(this);
예제 #27
0
 Execution IStateFlowNode.Execute <TCtx>(TCtx ctx, InputTriggerPort port)
 {
     return(ctx.TriggerGraphOutput(OutputIndex));
 }
예제 #28
0
 public Execution Execute <TCtx>(TCtx ctx, InputTriggerPort port) where TCtx : IGraphInstance
 {
     ref State state = ref ctx.GetState(this);
 public Edge(OutputTriggerPort output, InputTriggerPort input)
 {
     Output = output.Port;
     Input  = input.Port;
 }