private void Update() { if (actionsQueue.Count == 0) { AbstractAction action = PickAction(); actionsQueue.Add(action); } currentAction.Execute(); currentAction.Update(); if (currentAction.IsDone()) { currentAction = actionsQueue[0]; actionsQueue.RemoveAt(0); } if (eggTimer >= Random.Range(minEggFrequency, maxEggFrequency)) { EggBehaviour newEgg = Instantiate(egg, new Vector3(transform.position.x, transform.position.y, transform.position.z - transform.forward.z * -1), Quaternion.identity); newEgg.transform.GetChild(0).GetComponent <MeshRenderer>().material.color = transform.GetChild(0).GetComponent <MeshRenderer>().material.color; eggTimer = 0; } eggTimer += Time.deltaTime; }
private void OnCollisionEnter(Collision collision) { if (!isServer) { return; } EggBehaviour eggScript = collision.gameObject.GetComponent <EggBehaviour>(); if (eggScript != null) { StartCoroutine(ControllDizzyState(eggScript.IsBig)); CmdDizzy(eggScript.IsBig); } }
private void ValidateCollider(Collider other) { EggBehaviour eggBehaviour = other.gameObject.GetComponent <EggBehaviour>(); if (eggBehaviour != null && eggBehaviour.Owner != transform.gameObject) { int dizzyTime = 3; if (eggBehaviour.IsBig) { dizzyTime = 6; } BeDizzy(dizzyTime); CmdBeDizzy(dizzyTime); return; } MagicEggBehaviour mEggBehaviour = other.gameObject.GetComponent <MagicEggBehaviour>(); if (mEggBehaviour != null) { isWithMagicEgg = true; UpdateEggText(); StartCoroutine(RemoveMagicEgg()); CmdDestroyMagicEgg(mEggBehaviour.netId); Destroy(mEggBehaviour.gameObject); return; } if (other.GetType().ToString() == "UnityEngine.CapsuleCollider") { EnemyNavNetworkController enemy = other.gameObject.GetComponent <EnemyNavNetworkController>(); if (enemy != null && !enemy.IsDizzy) { if (enemy.isBowser) { BeDizzy(5); CmdBeDizzy(5); } else { BeDizzy(3); CmdBeDizzy(3); } } } }
public float _startTime; // 本状态开始的时间 public EggStateMachine(EggBehaviour behaviour) { _behaviour = behaviour; var goodState = new EggGoodState(this, behaviour); var brokenState = new EggBrokenState(this, behaviour); var emptyState = new EggEmptyState(this, behaviour); var vanishState = new EggVanishState(this, behaviour); var stateList = new Dictionary <EggStateEnum, IFsmState> { { EggStateEnum.GOOD, goodState }, { EggStateEnum.BROKEN, brokenState }, { EggStateEnum.EMPTY, emptyState }, { EggStateEnum.VANISH, vanishState }, }; SetStates(stateList); var allowedTransitions = new Dictionary <EggStateEnum, IList <EggStateEnum> >(); allowedTransitions.Add(EggStateEnum.GOOD, new List <EggStateEnum> { EggStateEnum.NONE, EggStateEnum.VANISH, EggStateEnum.BROKEN, EggStateEnum.EMPTY, }); allowedTransitions.Add(EggStateEnum.BROKEN, new List <EggStateEnum> { EggStateEnum.VANISH, }); allowedTransitions.Add(EggStateEnum.EMPTY, new List <EggStateEnum> { EggStateEnum.VANISH, }); allowedTransitions.Add(EggStateEnum.VANISH, new List <EggStateEnum> { EggStateEnum.NONE, }); SetTransitions(allowedTransitions); }
public EggGoodState(EggStateMachine owner, EggBehaviour behaviour) : base(owner) { parentBehaviour = behaviour; }
private void OnEnable() { _parentScript = GetComponentInParent <EggBehaviour>(); }
private void Start() { _camera = Camera.main; _parentEggMove = transform.parent.GetComponent <EggBehaviour>(); }