Пример #1
0
    protected override void OnUpdate()
    {
        var output    = World.GetOrCreateSystem <ConstraintGatherSystem>().GetOneWayOneDOFConstraintsInput();
        var masses    = GetComponentDataFromEntity <Mass>();
        var positions = GetComponentDataFromEntity <Position>();

        float dt = Time.DeltaTime;

        Entities
        .WithReadOnly(masses)
        .WithReadOnly(positions)
        .ForEach((Entity e, in LightTrackingJoint joint, in Position lightPos) => {
            float targetAngle = Ang.SignedAngleOf(positions[joint.toTrack].pos - lightPos.pos);

            float targetOffset = Ang.SignedDistance(angleFrom: lightPos.rot, angleTo: targetAngle);

            var manifold = new TargetAngularVelocityManifold {
                e            = e,
                id           = e.GetHashCode() ^ 291019149,
                softness     = joint.trackSoftness,
                targetAngVel = TargetAngularVelocityManifold.AngVelForTargetOffset(
                    offset: targetOffset,
                    maxSpeed: joint.trackSpeed,
                    dt: dt
                    )
            };

            output.Add(new OneWayOneDOFConstraint(manifold, masses, dt));
        }).Schedule();
 void Update()
 {
     if (IsPlaying || isPlaying)
     {
         if (IsDown)
         {
             mp = MP;
         }
         if (IsClick)
         {
             dis = V3.Dis(MP, mp);
             if (dis > radius)
             {
                 mp = V3.Move(MP, mp, radius);
             }
             horseTf.rotation = Q.Euler(0, Ang.LookForward(mp, MP), 0);
         }
         if (IsUp)
         {
             rb.V0();
         }
     }
     else
     {
         rb.V0();
     }
 }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        dstManager.AddComponentData(entity, GetLightSource());
        dstManager.AddComponentData(entity, GetLightPosition());

        dstManager.AddComponentData(entity,
                                    new Velocity {
            vel    = 0,
            angVel = angularVelocity * Mathf.Deg2Rad,
        }
                                    );
        dstManager.AddComponentData(entity,
                                    new Mass {
            mass    = math.INFINITY,
            inertia = inertia
        }
                                    );

        dstManager.AddComponentData(entity,
                                    new GravityScale {
            gravityScale = 0
        }
                                    );

        dstManager.AddComponentData(entity, new IgnoreHierarchyTag());

        if (toTrack != null)
        {
            dstManager.AddComponentData(entity,
                                        new LightTrackingJoint {
                toTrack       = conversionSystem.GetPrimaryEntity(toTrack),
                trackSpeed    = math.radians(trackSpeed),
                trackSoftness = trackSoftness
            }
                                        );
        }

        foreach (var snapInfo in snapInfos)
        {
            var joint = conversionSystem.CreateAdditionalEntity(gameObject);
            dstManager.SetName(joint, "Light mount joint");
            dstManager.AddComponentData(joint,
                                        new LightMountJoint {
                lightEntity = entity,
                mount       = conversionSystem.GetPrimaryEntity(snapInfo.mount),
                rangeStart  = Ang.SignedAngleOf(snapInfo.ccw),
                rangeEnd    = Ang.SignedAngleOf(snapInfo.cw),
                id          = Random.Range(0, int.MaxValue)
            }
                                        );
        }
    }