示例#1
0
        private void Activate()
        {
            foreach (var targetName in ActivationTargets)
            {
                GameObject go = _goqs.FindByName(targetName);
                if (go == null)
                {
                    throw new InvalidOperationException("No GameObject with name " + targetName);
                }

                foreach (var target in go.GetComponentsByInterface <ActivationTarget>())
                {
                    target.Activate();
                }
            }
        }
        private void OnLevelLoadTriggered(GameObject go)
        {
            if (EnabledInHierarchy)
            {
                PointCollector      pointCollector = go.GetComponent <PointCollector>();
                TimeDisplay         timer          = _goqs.FindByName("TimeDisplay").GetComponent <TimeDisplay>();
                PlayerStageProgress psp            = PlayerStageProgress.Instance;

                psp.StageCompleted(_sls.LoadedScene.Name, pointCollector.CollectedPoints, timer.Elapsed, _levelLoadTrigger.LoadedScene.ID);
            }
        }
        protected override void OnTriggerEntered(Collider other)
        {
            if (other.GameObject.GetComponent <CharacterMarker>() != null)
            {
                string     goName        = string.IsNullOrEmpty(GameObjectName) ? GameObject.Name : GameObjectName;
                GameObject go            = _goqs.FindByName(goName);
                Type       componentType = Type.GetType(ComponentTypeName);
                Component  c             = go.GetComponent(componentType);
                MethodInfo mi            = componentType.GetRuntimeMethod(MethodName, Array.Empty <Type>());

                mi.Invoke(c, null);
            }
        }
示例#4
0
        protected override void Start(SystemRegistry registry)
        {
            _input   = registry.GetSystem <InputSystem>();
            _goqs    = registry.GetSystem <GameObjectQuerySystem>();
            _gs      = registry.GetSystem <GraphicsSystem>();
            _physics = registry.GetSystem <PhysicsSystem>();
            _ball    = _goqs.FindByName(BallName);
            if (_ball == null)
            {
                throw new InvalidOperationException("No Ball found in scene with name " + BallName);
            }

            _ballCollider = _ball.GetComponent <Collider>();
            _ballState    = _ball.GetComponent <BallState>();
        }
示例#5
0
 protected override void OnEnabled()
 {
     if (!string.IsNullOrEmpty(JointTargetName))
     {
         Collider collider = _goqs.FindByName(JointTargetName)?.GetComponent <Collider>();
         if (collider != null)
         {
             Entity entity = new Sphere(Transform.Position, 0.1f, float.MaxValue)
             {
                 IsAffectedByGravity = false
             };
             MaximumLinearSpeedConstraint constraint = new MaximumLinearSpeedConstraint(entity, 0f);
             _physics.AddObject(entity);
             _physics.AddObject(constraint);
             RevoluteAngularJoint joint = new RevoluteAngularJoint(entity, collider.Entity, Transform.Up);
             _physics.AddObject(joint);
         }
         else
         {
             Console.WriteLine("Autojoint failed because no child Collider was found.");
         }
     }
 }
示例#6
0
        protected override void Start(SystemRegistry registry)
        {
            if (SkipCinematicCamera)
            {
                SkipCinematicCamera = false;
                Enabled             = false;
                GameObject.RemoveComponent(this);
                return;
            }

            _input = registry.GetSystem <InputSystem>();
            GameObjectQuerySystem goqs = registry.GetSystem <GameObjectQuerySystem>();

            if (ExtraDisabledGameObjectNames != null)
            {
                _extraDisabledGameObjects = ExtraDisabledGameObjectNames.Select(name => goqs.FindByName(name)).ToArray();
            }
            else
            {
                _extraDisabledGameObjects = Array.Empty <GameObject>();
            }
            foreach (var go in _extraDisabledGameObjects)
            {
                go.Enabled = false;
            }

            GameObject ball = goqs.FindByName(BallName);

            _cameraGO = goqs.FindByName(PlayerCameraName);
            BallController bc = _cameraGO.GetComponent <BallController>();

            bc.Enabled = false;
            bc.GetEffectiveCameraTransform(
                ball.Transform.Position,
                registry.GetSystem <PhysicsSystem>().Space.ForceUpdater.Gravity,
                out _finalPosition,
                out _finalRotation);

            GameObject waypointParentGo = goqs.FindByName(WaypointParentName);
            var        wps = waypointParentGo.Transform.Children.Select(t => t.GameObject.GetComponent <CinematicCameraWaypoint>())
                             .OrderBy(ccw => ccw.Time).Select(ccw => ccw.GetWaypointInfo());

            _initialPosition = Transform.Position;
            _initialRotation = Transform.Rotation;
            float lastWaypointTime = wps.Last().Time;

            if (RestAtCameraPositionTime != -1f && lastWaypointTime > RestAtCameraPositionTime)
            {
                throw new InvalidOperationException(
                          "Cannot rest at camera at time " + RestAtCameraPositionTime + ". The last waypoint has time " + lastWaypointTime);
            }
            else if (RestAtCameraPositionTime == -1f)
            {
                _endTime = lastWaypointTime;
            }
            else
            {
                _endTime = RestAtCameraPositionTime;
            }

            WaypointInfo cameraRestWP = new WaypointInfo(RestAtCameraPositionTime, _finalPosition, _finalRotation);

            _waypoints = wps.Append(cameraRestWP).ToArray();

            while (_waypoints[_currentWaypointIndex].Time == 0)
            {
                _initialPosition       = _waypoints[_currentWaypointIndex].Position;
                _initialRotation       = _waypoints[_currentWaypointIndex].Rotation;
                _currentWaypointIndex += 1;
            }

            _positionCurve          = new CardinalSpline3D();
            _positionCurve.Tension  = 0.1f;
            _positionCurve.PreLoop  = CurveEndpointBehavior.Clamp;
            _positionCurve.PostLoop = CurveEndpointBehavior.Clamp;

            _lookDirCurve          = new QuaternionSlerpCurve();
            _lookDirCurve.PreLoop  = CurveEndpointBehavior.Clamp;
            _lookDirCurve.PostLoop = CurveEndpointBehavior.Clamp;

            if (_waypoints.Any())
            {
                WaypointInfo firstWP = _waypoints.First();
                _positionCurve.ControlPoints.Add(firstWP.Time, firstWP.Position);
                _lookDirCurve.ControlPoints.Add(firstWP.Time, firstWP.Rotation);
            }
            foreach (var waypoint in _waypoints)
            {
                _positionCurve.ControlPoints.Add(waypoint.Time, waypoint.Position);
                _lookDirCurve.ControlPoints.Add(waypoint.Time, waypoint.Rotation);
            }

            if (_waypoints.Any())
            {
                WaypointInfo lastWP = _waypoints.Last();
                _positionCurve.ControlPoints.Add(lastWP.Time, lastWP.Position);
                _lookDirCurve.ControlPoints.Add(lastWP.Time, lastWP.Rotation);
            }
        }