public void Update() { if (State == ForceState.Initializing) { Amount = Math.Min(_targetAmount, Amount + _targetAmount * _type.IncreasingRatio); if (_targetAmount == Amount) { State = ForceState.Living; if (_duration == -1) { return; } Task.Factory.StartNew(() => { Task.Delay(_duration); State = ForceState.Dying; }); } } else if (State == ForceState.Dying) { Amount = Math.Max(0, Amount - _targetAmount * _type.IncreasingRatio); if (Amount == 0) { State = ForceState.Dead; _logger.Log($"{_name} - DEAD !!!"); } } }
protected override void OnUpdate() { var playerPos = new float3(); Entities.ForEach((ref PlayerAvatarComponent playerComp, ref Translation posComp) => playerPos = posComp.Value); var screenPosX = 0.0f; Entities.ForEach((CameraObjectComponent cameraComp) => screenPosX = cameraComp.camera.WorldToScreenPoint(playerPos).x); Entities.ForEach((GUIPresetComponent guiPresetComp, ref ForceStateComponent forceStateComp) => { GUIPreset guiPreset = guiPresetComp.preset; if (ForceState.None == _oldState && ForceState.None != (ForceState)forceStateComp.state) { guiPreset.forceStateBalloon.SetActive(true); } else if (ForceState.None != _oldState && ForceState.None == (ForceState)forceStateComp.state) { guiPreset.forceStateBalloon.SetActive(false); } _oldState = (ForceState)forceStateComp.state; if (guiPreset.forceStateBalloon.activeSelf) { var rectTransform = guiPreset.forceStateBalloon.GetComponent <RectTransform>(); Debug.Assert(null != rectTransform); rectTransform.anchoredPosition = new Vector2(screenPosX / guiPreset.canvas.scaleFactor, rectTransform.anchoredPosition.y); } }); }
void TouchMoved(UITouch touch) { if (touch == null) { return; } if (touchExited) { return; } var cancelDistance = minWidth / 2 + 20; if (touch.LocationInView(this).Distance(new CGPoint(Bounds.GetMidX(), Bounds.GetMidY())) < cancelDistance) { // the touch has moved outside of the bounds of the button touchExited = true; forceState = ForceState.Reset; AnimateToRest(); return; } var force = touch.Force / touch.MaximumPossibleForce; var scale = 1 + (maxWidth / minWidth - 1) * force; // update the button's size and color Transform = CGAffineTransform.MakeScale(scale, scale); if (!isOn) { BackgroundColor = UIColor.FromWhiteAlpha(0.2f - force * 0.2f, 1); } switch (forceState) { case ForceState.Reset: if (force > activationForce) { forceState = ForceState.Activated; activationFeedbackGenerator.ImpactOccurred(); } break; case ForceState.Activated: if (force <= confirmationForce) { forceState = ForceState.Confirmed; Activate(); } break; case ForceState.Confirmed: if (force <= resetForce) { forceState = ForceState.Reset; } break; } }
public Force(double amount, double angle, ForceType type, int duration = 0, string name = "force lambda") { _name = name; _logger = GameServiceLocator.Instance.Get <Logger>(); _duration = duration; _type = type; _targetAmount = amount; Angle = angle; State = ForceState.Initializing; }
public void SetForceState(string newState) { ForceState value; if (!stringStateMap.TryGetValue(newState, out value)) { Debug.Log("Warning: SetForceState Function's parameter is wrong string."); return; } state = value; }
void TouchEnded(UITouch touch) { if (touch == null) { return; } if (touchExited) { return; } forceState = ForceState.Reset; AnimateToRest(); }
private void Start() { anim = GetComponent <Animator>(); cc = GetComponent <CharacterController>(); AttackDecision = GetComponent <AttackDetectionTwo>(); gamePanel = GameObject.Find("Canvas").transform.GetChild(0).GetComponent <GamePanel>(); IdleState idle = new IdleState(1, this); RunState Runing = new RunState(2, this); RollState Rolling = new RollState(3, this); AttackState attack = new AttackState(4, this); SwitchWeaponsState switchWeapons = new SwitchWeaponsState(5, this); GetHitAndDeath getHitAndDeath = new GetHitAndDeath(6, this); ForceState force = new ForceState(7, this); machine = new StateMachine(idle); machine.AddState(Runing); machine.AddState(Rolling); machine.AddState(attack); machine.AddState(switchWeapons); machine.AddState(getHitAndDeath); machine.AddState(force); }
void Update() { if (forceCount >= SUPER_FORCE_COUNT) { AddForceItem(-SUPER_FORCE_COUNT); state = ForceState.SUPER; playerControl.OnStartSuperForce(); } if (SuperForceTimer < 0) { state = ForceState.ATTRACT; SuperForceTimer = MAX_SUPER_TIME; playerControl.OnFinishSuperForce(); forceEffect.Stop(); } int sign = 1; switch (state) { case ForceState.ATTRACT: { sign = 1; } break; case ForceState.PUSHOUT: { sign = -1; } break; case ForceState.SUPER: { sign = 1; SuperForceTimer -= Time.deltaTime; gameRoot.ResetTime(); if (!forceEffect.isPlaying) { forceEffect.Play(); } } break; default: { sign = 0; } break; } foreach (var obj in forceObjects) { if (state == ForceState.SUPER) { if (obj.tag != null) { bool value = false; if (tagSignMap.TryGetValue(obj.tag, out value)) { if (value) { sign = 1; } else { sign = -1; } } } } Vector3 dir = (gameObject.transform.position - obj.transform.position).normalized * sign; obj.Move(dir); } }