public override void OnModeEnter(Mode mode) { MAnimal animal = mode.Animal; var pos = animal.Center; var AllColliders = Physics.OverlapSphere(pos, FindRadius, animal.HitLayer); Collider MinDistanceCol = null; float Distance = float.MaxValue; foreach (var col in AllColliders) { if (col.transform.root == animal.transform.root) { continue; //Don't Find yourself } var DistCol = Vector3.Distance(animal.Center, col.transform.position); if (Distance > DistCol) { Distance = DistCol; MinDistanceCol = col; } } if (MinDistanceCol) { animal.StartCoroutine(MalbersTools.AlignLookAtTransform(animal.transform, MinDistanceCol.transform, AlignTime)); } }
public override void StateGizmos(MAnimal animal) { if (!IsActiveState && AntiFall) { PaintRays(animal); } }
void OnTriggerEnter(Collider other) { // if (other.isTrigger) return; // if (!MalbersTools.CollidersLayer(other, LayerMask.GetMask("Animal"))) return; //Just accept animal layer only MAnimal newAnimal = other.GetComponentInParent <MAnimal>(); //Get the animal on the entering collider if (!newAnimal) { return; //If there's no animal do nothing } if (animal_Colliders.Find(coll => coll == other) == null) //if the entering collider is not already on the list add it { animal_Colliders.Add(other); } if (newAnimal == CurrentAnimal) { return; //if the animal is the same do nothing (when entering two animals on the same Zone) } else { if (CurrentAnimal) { animal_Colliders = new List <Collider>(); //Clean the colliders } CurrentAnimal = newAnimal; //Set a new Animal OnEnter.Invoke(CurrentAnimal); ActivateZone(); } }
void OnTriggerExit(Collider other) { if (other.isTrigger) { return; } MAnimal existing_animal = other.GetComponentInParent <MAnimal>(); if (!existing_animal) { return; //If there's no animal script found skip all } if (existing_animal != CurrentAnimal) { return; //If is another animal exiting the zone SKIP } if (animal_Colliders.Find(item => item == other)) //Remove the collider from the list that is exiting the zone. { animal_Colliders.Remove(other); } if (animal_Colliders.Count == 0) //When all the collides are removed from the list.. { OnExit.Invoke(CurrentAnimal); //Invoke On Exit when all animal's colliders has exited the Zone ResetStoredAnimal(); } }
void Start() { anim = GetComponent <Animator>(); if (Dragon) { if (!Dragon.activeInHierarchy) { Dragon = Instantiate(Dragon); } animal = Dragon.GetComponent <MAnimal>(); animal.transform.position = transform.position; animal.Anim.Play("Hatch"); //Set the egg State (This set on the animator INT -10 which is the transition for the EggHatching Start Animation animal.LockInput = true; animal.LockMovement = true; //animal.enabled = false; animal.transform.localPosition += preHatchOffset; animal.GetComponentInChildren <SkinnedMeshRenderer>().enabled = false; } if (hatchtype == HatchType.Time) { StartCoroutine(TimeCrackEgg()); } }
private void OnEnable() { animal = this.FindComponent <MAnimal>(); animal.OnModeEnd.AddListener(OnModeEnd); Restart(); }
/// <summary>Finds the Main Animal used as Player on the Active Scene</summary> void FindMainAnimal() { activeAnimal = MAnimal.MainAnimal; if (player != null) { if (player.IsPrefab()) { InstantiateNewPlayer(); } else { activeAnimal = player.GetComponent <MAnimal>(); } if (activeAnimal) { activeAnimal.OnStateChange.AddListener(OnCharacterDead); //Listen to the Animal changes of states activeAnimal.TeleportRot(RespawnPoint.Value); //Move the Animal to is Start Position RespawnState = RespawnState ?? activeAnimal.OverrideStartState; activeAnimal.OverrideStartState = RespawnState; } } else { activeAnimal = MAnimal.MainAnimal; if (activeAnimal != null) { player = activeAnimal.gameObject; FindMainAnimal(); } } }
public override void OnModeEnter(Mode mode) { MAnimal animal = mode.Animal; IAlign SelfAligner = animal.GetComponent <IAlign>(); IAlign EnemyAligner = null; var pos = SelfAligner != null ? SelfAligner.MainPoint.position : animal.transform.position; var AllColliders = Physics.OverlapSphere(pos, FindRadius, animal.HitLayer); Collider MinDistanceCol; float Distance = float.MaxValue; foreach (var col in AllColliders) { if (col.GetComponentInParent <MAnimal>() == animal) { continue; //Don't Find your own colliders } var DistCol = Vector3.Distance(animal.transform.position, col.transform.position); if (Distance > DistCol) { Distance = DistCol; MinDistanceCol = col; EnemyAligner = col.GetComponentInParent <IAlign>(); } } if (EnemyAligner != null) { EnemyAligner.Align(animal.transform); } }
///// <summary>Enable/Disable is AllInputs on the Animal</summary> //public bool Colliders; public void Modify(MAnimal animal) { if ((int)modify == 0) { return; //Means that the animal have no modification } if (Modify(modifier.IgnoreLowerStates)) { animal.ActiveState.IgnoreLowerStates = IgnoreLowerStates; } if (Modify(modifier.AdditivePositionSpeed)) { animal.UseAdditivePos = AdditivePosition; } // if (Modify(modifier.AdditiveRotationSpeed)) animal.UseAdditiveRot = AdditiveRotation; if (Modify(modifier.RootMotion)) { animal.RootMotion = RootMotion; } if (Modify(modifier.Gravity)) { animal.UseGravity = Gravity; } if (Modify(modifier.Sprint)) { animal.UseSprintState = Sprint; } if (Modify(modifier.Grounded)) { animal.Grounded = Grounded; } if (Modify(modifier.OrientToGround)) { animal.UseOrientToGround = OrientToGround; } if (Modify(modifier.CustomRotation)) { animal.UseCustomAlign = CustomRotation; } if (Modify(modifier.Persistent)) { animal.ActiveState.IsPersistent = Persistent; } if (Modify(modifier.LockInput)) { animal.LockInput = LockInput; } if (Modify(modifier.LockMovement)) { animal.LockMovement = LockMovement; } // if (Modify(modifier.Colliders)) animal.EnableColliders(Colliders); if (Modify(modifier.FreeMovement)) { animal.FreeMovement = FreeMovement; } }
/// <summary>Set everyting up when the Animal Script Start</summary> public virtual void AwakeMode(MAnimal animal) { this.Animal = animal; //Cache the Animal ModeTagHash = Animator.StringToHash(AnimationTag); //Convert the Tag on a TagHash OnAbilityIndex.Invoke(AbilityIndex); Current_CoolDown_Time = -CoolDown; //First Time IMPORTANT }
public override void StateGizmos(MAnimal animal) { if (Application.isPlaying && SwimState != null && animal != null) { Gizmos.color = Color.blue; Gizmos.DrawSphere(SwimState.WaterPivotPoint, SwimState.m_Radius * animal.ScaleFactor); } }
void Start() { animal = GetComponent <MAnimal>(); if (item != null) { PickUpItem(); } }
void InstantiateNewPlayer() { activePlayer = Instantiate(playerPrefab, transform.position, transform.rotation) as GameObject; activeAnimal = activePlayer.GetComponent <MAnimal>(); activeAnimal.OverrideStartState = RespawnState; activeAnimal.OnStateChange.AddListener(OnCharacterDead); OnRestartGame.Invoke(); }
void InstantiateNewPlayer() { InstantiatedPlayer = Instantiate(player, RespawnPoint.position, RespawnPoint.rotation); activeAnimal = InstantiatedPlayer.GetComponent <MAnimal>(); activeAnimal.OverrideStartState = RespawnState; activeAnimal.OnStateChange.AddListener(OnCharacterDead); OnRestartGame.Invoke(); Respawning = false; }
/// <summary> Enable Disable the Zone COllider for and X time</summary> IEnumerator ZoneColliderONOFF() //For Automatic only { yield return(null); if (AutomaticDisabled > 0) { ZoneCollider.enabled = false; CurrentAnimal.ActiveMode.ResetAbilityIndex(); //Reset the Ability Index when Set to automatic and the Collider is off yield return(new WaitForSeconds(AutomaticDisabled)); ZoneCollider.enabled = true; } CurrentAnimal = null; //clean animal animal_Colliders = new List <Collider>(); //Reset Colliders yield return(null); }
public virtual void ResetStoredAnimal() { CurrentAnimal.IsOnZone = false; if (zoneType == ZoneType.Mode) { var PreMode = CurrentAnimal.Mode_Get(modeID); if (PreMode != null) { PreMode.ResetAbilityIndex(); PreMode.GlobalProperties.OnEnter.RemoveListener(OnZONEActive); } } CurrentAnimal = null; animal_Colliders = new List <Collider>(); //Clean the colliders }
/// <summary>Finds the Main Animal used as Player on the Active Scene</summary> void FindMainAnimal() { var animal = MAnimal.MainAnimal; if (animal) { activePlayer = animal.gameObject; //Set the Current Player activeAnimal = animal; //Set the Current Controller animal.OnStateChange.AddListener(OnCharacterDead); //Listen to the Animal changes of states animal.Teleport(transform); //Move the Animal to is Start Position animal.OverrideStartState = RespawnState; } else if (activePlayer == null && playerPrefab != null) { InstantiateNewPlayer(); } }
void OnTriggerEnter(Collider other) { if (other.isTrigger) { return; } if (!MalbersTools.CollidersLayer(other, LayerMask.GetMask("Animal"))) { return; //Just accept animal layer only } if (HeadOnly && !other.name.Contains(HeadName)) { return; //If is Head Only and no head was found Skip } MAnimal newAnimal = other.GetComponentInParent <MAnimal>(); //Get the animal on the entering collider if (!newAnimal) { return; //If there's no animal do nothing } if (animal_Colliders.Find(coll => coll == other) == null) //if the entering collider is not already on the list add it { animal_Colliders.Add(other); } if (newAnimal == CurrentAnimal) { return; //if the animal is the same do nothing (when entering two animals on the same Zone) } else { if (CurrentAnimal) { animal_Colliders = new List <Collider>(); //Clean the colliders } CurrentAnimal = newAnimal; //Set a new Animal AnimalStats = CurrentAnimal.GetComponentInParent <Stats>(); StatModifierOnEnter.ModifyStat(AnimalStats); //Modify the stats when exit OnEnter.Invoke(CurrentAnimal); ActivateZone(); } }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animal = animator.GetComponentInParent <MAnimal>(); if (animal.ModeInt == Int_ID.Loop) { return; //Means is Looping } if (ModeID == null) { Debug.LogError("Mode behaviour needs an ID"); } modeOwner = animal.Mode_Get(ModeID); AnimationAbility = modeOwner.ActiveAbility; if (EnterMode) { modeOwner?.AnimationTagEnter(); } }
void PaintRays(MAnimal animal) { float scale = animal.ScaleFactor; var Dir = animal.TerrainSlope > 0 ? animal.Gravity : -animal.Up; var RayMultiplier = animal.Pivot_Multiplier * FallMultiplier; //Get the Multiplier var MainPivotPoint = animal.Pivot_Chest.World(animal.transform); var FrontCenter = MainPivotPoint + (animal.Forward * frontDistance * scale); //Calculate ahead the falling ray var FrontLeft = FrontCenter + (animal.Right * frontSpace * scale); var FrontRight = FrontCenter + (-animal.Right * frontSpace * scale); var BackCenter = MainPivotPoint - (animal.Forward * BackDistance * scale); //Calculate ahead the falling ray var BackLeft = BackCenter + (animal.Right * BackSpace * scale); var BackRight = BackCenter + (-animal.Right * BackSpace * scale); Debug.DrawRay(FrontCenter, Dir * RayMultiplier, DebugColor); Debug.DrawRay(FrontLeft, Dir * RayMultiplier, DebugColor); Debug.DrawRay(FrontRight, Dir * RayMultiplier, DebugColor); Debug.DrawRay(BackCenter, Dir * RayMultiplier, DebugColor); Debug.DrawRay(BackLeft, Dir * RayMultiplier, DebugColor); Debug.DrawRay(BackRight, Dir * RayMultiplier, DebugColor); }
void OnTriggerExit(Collider other) { if (other.isTrigger) { return; } if (HeadOnly && !other.name.Contains(HeadName)) { return; //if is only set to head and there's no head SKIP } MAnimal existing_animal = other.GetComponentInParent <MAnimal>(); if (!existing_animal) { return; //If there's no animal script found skip all } if (existing_animal != CurrentAnimal) { return; //If is another animal exiting the zone SKIP } if (animal_Colliders.Find(item => item == other)) //Remove the collider from the list that is exiting the zone. { animal_Colliders.Remove(other); } if (animal_Colliders.Count == 0) //When all the collides are removed from the list.. { OnExit.Invoke(CurrentAnimal); //Invoke On Exit when all animal's colliders has exited the Zone StatModifierOnExit.ModifyStat(AnimalStats); //Modify the stats when exit if (zoneType == ZoneType.Stance && stanceAction == StanceAction.Stay && CurrentAnimal.Stance == stanceID.ID) { CurrentAnimal.Stance_Reset(); } ResetStoredAnimal(); } }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animal = animator.GetComponent <MAnimal>(); if (animal.IntID == Int_ID.Loop) { return; //Means is Looping } if (ModeID == null) { Debug.LogError("Mode behaviour needs an ID"); } modeOwner = animal.Mode_Get(ModeID); AbilityIndex = modeOwner.ActiveAbility.Index; if (modeOwner != null && EnterMode) { modeOwner.AnimationTagEnter(stateInfo.tagHash); //Debug.Log("Enterstate"); } }
void Start() { anim = GetComponent <Animator>(); if (Dragon) { if (Dragon.IsPrefab()) { Dragon = Instantiate(Dragon); } animal = Dragon.GetComponent <MAnimal>(); if (animal) { animal.transform.position = transform.position; animal.Anim.Play("Hatch"); //Set the egg State (This set on the animator INT -10 which is the transition for the EggHatching Start Animation animal.LockInput = true; animal.LockMovement = true; animal.EnableColliders(false); animal.transform.localPosition += preHatchOffset; } var skinnedMeshes = Dragon.GetComponentsInChildren <Renderer>(); foreach (var item in skinnedMeshes) { item.enabled = false; } } if (hatchtype == HatchType.Time) { StartCoroutine(TimeCrackEgg()); } }
/// <summary>Set all the values for all the States on Awake</summary> public void SetAnimal(MAnimal mAnimal) { animal = mAnimal; transform = animal.transform; }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animal = animator.GetComponent <MAnimal>(); EnterModifier.Modify(animal); }
void Awake() { animal = GetComponent <MAnimal>(); }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animal = animator.GetComponent <MAnimal>(); isOn = isOff = false; //Reset the ON/OFF parameters (to be used on the Range of the animation }
public override void OnModeEnter(Mode mode) { MAnimal animal = mode.animal; Vector3 HitDirection = animal.HitDirection; if (HitDirection == Vector3.zero) //Set it to random if there's no hit direction { mode.AbilityIndex = -1; return; } HitDirection = Vector3.ProjectOnPlane(HitDirection, animal.UpVector); //Remove the Y on the Direction float angle = Vector3.Angle(animal.Forward, HitDirection); //Get The angle bool left = Vector3.Dot(animal.Right, HitDirection) < 0; //Calculate which directions comes the hit Left or right //Debug.Log(angle * (left ? 1:-1)); int Side = -1; if (TwoSided) { mode.AbilityIndex = left ? 1 : 2; return; } if (left) { if (angle > 0 && angle <= 60) { Side = 1; } else if (angle > 60 && angle <= 120) { Side = 2; } else if (angle > 120 && angle <= 180) { Side = 3; } } else { if (angle > 0 && angle <= 60) { Side = 4; } else if (angle > 60 && angle <= 120) { Side = 5; } else if (angle > 120 && angle <= 180) { Side = 6; } } mode.AbilityIndex = Side; }
public override void OnModeEnter(Mode mode) { MAnimal animal = mode.Animal; Vector3 HitDirection = animal.GetComponent <IMDamage>().HitDirection; if (HitDirection == Vector3.zero) { return; //Set it to random if there's no hit direction } HitDirection = Vector3.ProjectOnPlane(HitDirection, animal.UpVector); //Remove the Y on the Direction float angle = Vector3.Angle(animal.Forward, HitDirection); //Get The angle bool left = Vector3.Dot(animal.Right, HitDirection) < 0; //Calculate which directions comes the hit Left or right int Side = -99; switch (hitDirection) { case MDirectionalDamage.HitDirection.TwoSides: mode.AbilityIndex = left ? Left : Right; break; case MDirectionalDamage.HitDirection.FourSides: if (angle <= 45) { Side = Front; } else if (angle >= 45 && angle <= 135) { Side = left ? Right : Left; } else if (angle >= 135) { Side = Back; } if (debug) { var Colordeb = Color.blue; float mult = 4; Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 45, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -45, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 135, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -135, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, angle * (left ? -1 : 1), 0) * animal.transform.forward * mult, Color.red, 3f); } break; case MDirectionalDamage.HitDirection.SixSides: if (debug) { var Colordeb = Color.blue; float mult = 4; Debug.DrawRay(animal.transform.position, animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, -animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 60, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -60, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 120, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -120, 0) * animal.transform.forward * mult, Colordeb, 3f); Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, angle * (left ? -1 : 1), 0) * animal.transform.forward * mult, Color.red, 3f); } if (!left) { if (angle >= 0 && angle <= 60) { Side = FrontRight; } else if (angle > 60 && angle <= 120) { Side = Right; } else if (angle > 120 && angle <= 180) { Side = BackRight; } } else { if (angle >= 0 && angle <= 60) { Side = FrontLeft; } else if (angle > 60 && angle <= 120) { Side = Left; } else if (angle > 120 && angle <= 180) { Side = BackLeft; } } break; default: break; } mode.AbilityIndex = Side; }