Ejemplo n.º 1
0
 public HarvestResource(Actor self)
 {
     harv = self.Trait<Harvester>();
     harvInfo = self.Info.TraitInfo<HarvesterInfo>();
     facing = self.Trait<IFacing>();
     body = self.Trait<BodyOrientation>();
     territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
     resLayer = self.World.WorldActor.Trait<ResourceLayer>();
 }
Ejemplo n.º 2
0
        public DeliverUnit(Actor self, CPos destination)
        {
            this.self = self;
            this.destination = destination;

            carryallFacing = self.Trait<IFacing>();
            carryall = self.Trait<Carryall>();
            body = self.Trait<BodyOrientation>();

            carryable = carryall.Carryable.Trait<Carryable>();
            positionable = carryall.Carryable.Trait<IPositionable>();
            carryableFacing = carryall.Carryable.Trait<IFacing>();
            state = State.Transport;
        }
Ejemplo n.º 3
0
        public PickupUnit(Actor self, Actor cargo, int delay)
        {
            this.cargo = cargo;
            this.delay = delay;
            carryable = cargo.Trait<Carryable>();
            carryableFacing = cargo.Trait<IFacing>();
            carryableBody = cargo.Trait<BodyOrientation>();

            movement = self.Trait<IMove>();
            carryall = self.Trait<Carryall>();
            carryallFacing = self.Trait<IFacing>();

            state = State.Intercept;
        }
Ejemplo n.º 4
0
        public AppModel()
        {
            KinectManager.SensorConnected
            .Subscribe(sensor =>
            {
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                sensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
                sensor.SkeletonStream.EnableWithDefaultSmoothing();

                try
                {
                    sensor.Start();
                }
                catch (Exception ex)
                {
                    // センサーが他のプロセスに既に使用されている場合に発生します。
                    Debug.WriteLine(ex);
                }
            });
            KinectManager.SensorDisconnected
            .Subscribe(sensor => sensor.Stop());
            KinectManager.Initialize();

            // フレームのデータ。
            var frameData = Observable.Interval(FramesInterval)
                            .Select(_ => new
            {
                Sensor    = KinectManager.Sensor.Value,
                ColorData = KinectManager.Sensor.Value.GetColorData(FramesInterval),
                DepthData = KinectManager.Sensor.Value.GetDepthDataInInt16(FramesInterval),
                BodyData  = KinectManager.Sensor.Value.GetSkeletonData(FramesInterval),
            })
                            .ToReadOnlyReactiveProperty(null, ReactivePropertyMode.DistinctUntilChanged);

            // ターゲットの人物。
            TargetBody = frameData
                         .Where(_ => _.BodyData != null)
                         .Select(_ => GetTargetBody(_.BodyData, TargetBody.Value))
                         .ToReadOnlyReactiveProperty(null, ReactivePropertyMode.DistinctUntilChanged);

            // ターゲットの人物が存在するかどうか。
            HasTargetBody = TargetBody
                            .Select(b => b != null)
                            .ToReadOnlyReactiveProperty();

            // ヒット ゾーン内の手。z 要素は体からの差分。
            HitHand = TargetBody
                      .Select(b => GetHitHand(b, HitHand.Value))
                      .ToReadOnlyReactiveProperty(null, ReactivePropertyMode.DistinctUntilChanged);

            // ヒット ゾーン内かどうか。
            IsHandHit = HitHand
                        .Select(_ => _.HasValue)
                        .ToReadOnlyReactiveProperty();

            AreHandsAbove = TargetBody.Select(GetAreHandsAbove).ToReadOnlyReactiveProperty();
            IsSquat       = TargetBody.Select(GetIsSquat).ToReadOnlyReactiveProperty();
            IsJumping     = TargetBody.Select(GetIsJumping).ToReadOnlyReactiveProperty();

            BodyOrientation = TargetBody.Select(GetBodyOrientation).ToReadOnlyReactiveProperty();
            IsLeftOriented  = BodyOrientation.Select(x => x < -0.35).ToReadOnlyReactiveProperty();
            IsRightOriented = BodyOrientation.Select(x => x > 0.35).ToReadOnlyReactiveProperty();

            JawLower = TargetBody
                       .Select(body =>
            {
                if (body == null)
                {
                    return(0);
                }

                var data = frameData.Value;
                if (data.ColorData == null || data.DepthData == null || data.BodyData == null)
                {
                    return(0);
                }

                if (faceTracker == null)
                {
                    faceTracker = new FaceTracker(data.Sensor);
                }

                var faceFrame = faceTracker.Track(data.Sensor.ColorStream.Format, data.ColorData, data.Sensor.DepthStream.Format, data.DepthData, body);
                if (!faceFrame.TrackSuccessful)
                {
                    return(0);
                }

                var animationUnits = faceFrame.GetAnimationUnitCoefficients();
                return(animationUnits[AnimationUnit.JawLower]);
            })
                       .ToReadOnlyReactiveProperty();
            IsMouthOpen = JawLower.Select(x => x > 0.35).ToReadOnlyReactiveProperty();
        }
Ejemplo n.º 5
0
 public ReleaseUnit(Actor self)
 {
     facing   = self.Trait <IFacing>();
     carryall = self.Trait <Carryall>();
     body     = self.Trait <BodyOrientation>();
 }
Ejemplo n.º 6
0
 public SpawnsShrapnel(Actor self, SpawnsShrapnelInfo info)
     : base(info)
 {
     world = self.World;
     body  = self.TraitOrDefault <BodyOrientation>();
 }
Ejemplo n.º 7
0
 public SpawnsFragment(Actor self, SpawnsFragmentInfo info)
     : base(info)
 {
     world = self.World;
     body  = self.TraitOrDefault <BodyOrientation>();
 }