public static void BehavioursTemplate(SimpleAI _simpleAI) { EditorGUILayout.Space(); _simpleAI.aiJson = EditorGUILayout.ObjectField("AI asset", _simpleAI.aiJson, typeof(TextAsset), false) as TextAsset; EditorGUILayout.Space(); BehavioursTemplate(_simpleAI.ai, _simpleAI.gameConfig); }
public override IEnumerator perform(SimpleAI _simpleAI) { if (_simpleAI.anim) { _simpleAI.anim.SetBool(boolName, boolValue); } yield return(true); }
public override IEnumerator perform(SimpleAI _simpleAI) { if (_simpleAI.anim) { _simpleAI.anim.SetInteger(integerName, integerValue); } yield return(true); }
public override IEnumerator perform(SimpleAI _simpleAI) { int choosedDirection; if (direction == eDirection.left) { choosedDirection = -1; } else if (direction == eDirection.right) { choosedDirection = 1; } else { System.Random rd = new System.Random(); int randomIndex = rd.Next(0, 2); choosedDirection = directionsAvaliable[randomIndex]; } double tmpDistance = distance; bool haveJustFliped = false; while (tmpDistance > 0) { if (!_simpleAI.target && (_simpleAI.loseTargetCondition == AIBase.LoseTargetConditions.both || _simpleAI.loseTargetCondition == AIBase.LoseTargetConditions.distanceToSpawnArea)) { float distPercent = ((Vector2.Distance(_simpleAI.transform.position, _simpleAI.spawnPoint) * 100) / _simpleAI.maxDistanceFromSpawn) / 100; if (distPercent >= 0.8f) { if (!haveJustFliped) { haveJustFliped = true; choosedDirection *= -1; } } else { haveJustFliped = false; } } _simpleAI._controller.Move(choosedDirection); tmpDistance -= Time.deltaTime; yield return(false); } }
void OnEnable() { _simpleAI = (SimpleAI)target; if (!_simpleAI.gameConfig) { _simpleAI.gameConfig = Resources.Load("Configs/GeneralConfigs") as SimpleAIConfig; } iconMoviment = Resources.Load("Icons/2dsimpleai-moviment") as Texture2D; iconSpeed = Resources.Load("Icons/2dsimpleai-speed") as Texture2D; iconLanding = Resources.Load("Icons/2dsimpleai-landing") as Texture2D; iconConfig = Resources.Load("Icons/2dsimpleai-config") as Texture2D; iconHeart = Resources.Load("Icons/2dsimpleai-heart") as Texture2D; iconPlay = Resources.Load("Icons/2dsimpleai-play") as Texture2D; iconAI = Resources.Load("Icons/2dsimpleai-ai") as Texture2D; }
public static void BehaviourButtons(SimpleAI _simpleAI) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); //TODO: Tradução EditorGUILayout.LabelField(new GUIContent("Behaviours", iconAI), EditorStyles.boldLabel); if (GUILayout.Button(((_simpleAI.showBehaviour) ? Language.hide(_simpleAI.gameConfig.selectedLanguage) : Language.show(_simpleAI.gameConfig.selectedLanguage)))) { _simpleAI.showBehaviour = !_simpleAI.showBehaviour; } EditorGUILayout.EndHorizontal(); if (_simpleAI.showBehaviour) { showBehaviourArea(_simpleAI); } EditorGUILayout.EndVertical(); }
public static void generalsButtons(SimpleAI _simpleAI) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent(Language.generalTitle(_simpleAI.gameConfig.selectedLanguage), iconConfig), EditorStyles.boldLabel); if (GUILayout.Button(((_simpleAI.showGenerals) ? Language.hide(_simpleAI.gameConfig.selectedLanguage) : Language.show(_simpleAI.gameConfig.selectedLanguage)))) { _simpleAI.showGenerals = !_simpleAI.showGenerals; } EditorGUILayout.EndHorizontal(); if (_simpleAI.showGenerals) { SimpleAILayout.showGeneralsArea(_simpleAI.gameConfig); } EditorGUILayout.EndVertical(); }
public static void showBehaviourArea(SimpleAI _simpleAI) { EditorGUILayout.BeginVertical("Box"); switch (_simpleAI.gameConfig.AIType) { case AIBase.AIType.platform: { AIDrawPlatformBehaviours(_simpleAI); break; } case AIBase.AIType.topdown: { AIDrawTopdownBehaviours(_simpleAI); break; } case AIBase.AIType.tactical: { AIDrawTacticalBehaviours(_simpleAI); break; } default: { EditorGUILayout.HelpBox(Language.alertGameMovimentType(_simpleAI.gameConfig.selectedLanguage), MessageType.Warning); EditorGUILayout.Space(); break; } } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); }
public virtual void start(SimpleAI _simpleAI, Transform transform) { }
void findVisibleTargets(SimpleAI _simpleAI, Transform transform) { visibleTargets.Clear(); Collider2D[] targetsInTheRadius = Physics2D.OverlapCircleAll(transform.position, (float)radius, target); for (int i = 0; i < targetsInTheRadius.Length; i++) { Vector2 dirToTarget = (targetsInTheRadius[i].transform.position - transform.position).normalized; dirToTarget = ((!_simpleAI.facingRight) ? dirToTarget * -1 : dirToTarget); float targetDistance = Vector2.Distance(transform.position, targetsInTheRadius[i].transform.position); if (Vector2.Angle(DirFromAngle(getMiddleAngle(_simpleAI), 90), dirToTarget) < angle / 2) { if (!Physics2D.Raycast(transform.position, dirToTarget * ((_simpleAI.facingRight) ? 1 : -1), targetDistance, _simpleAI.gameConfig.obistacleLayer + _simpleAI.gameConfig.groundLayer)) { visibleTargets.Add(targetsInTheRadius[i].gameObject); } } else { bool didItHit = false; float detectionAngle = ((_simpleAI.facingRight)? getFinalAngle(_simpleAI) : getStartAngle(_simpleAI)); Vector3 pos = new Vector3(Mathf.Cos(detectionAngle * Mathf.Deg2Rad), Mathf.Sin(detectionAngle * Mathf.Deg2Rad), 0f); //Debug.DrawRay(transform.position, pos * getRadius(_simpleAI), Color.yellow); RaycastHit2D[] hitTopList = Physics2D.RaycastAll(transform.position, pos, getRadius(_simpleAI), target); for (int hitIndex = 0; i < hitTopList.Length; i++) { if (hitTopList[hitIndex].collider.Equals(targetsInTheRadius[i])) { didItHit = true; break; } } if (!didItHit) { detectionAngle = getMiddleAngle(_simpleAI); pos = new Vector3(Mathf.Cos(detectionAngle * Mathf.Deg2Rad), Mathf.Sin(detectionAngle * Mathf.Deg2Rad), 0f); //Debug.DrawRay(transform.position, pos * getRadius(_simpleAI), Color.yellow); hitTopList = Physics2D.RaycastAll(transform.position, pos, getRadius(_simpleAI), target); for (int hitIndex = 0; i < hitTopList.Length; i++) { if (hitTopList[hitIndex].collider.Equals(targetsInTheRadius[i])) { didItHit = true; break; } } if (!didItHit) { detectionAngle = ((_simpleAI.facingRight) ? getStartAngle(_simpleAI) : getFinalAngle(_simpleAI)); pos = new Vector3(Mathf.Cos(detectionAngle * Mathf.Deg2Rad), Mathf.Sin(detectionAngle * Mathf.Deg2Rad), 0f); //Debug.DrawRay(transform.position, pos * getRadius(_simpleAI), Color.yellow); hitTopList = Physics2D.RaycastAll(transform.position, pos, getRadius(_simpleAI), target); for (int hitIndex = 0; i < hitTopList.Length; i++) { if (hitTopList[hitIndex].collider.Equals(targetsInTheRadius[i])) { didItHit = true; break; } } } } if (didItHit) { if (!Physics2D.Raycast(transform.position, pos, getRadius(_simpleAI), _simpleAI.gameConfig.obistacleLayer + _simpleAI.gameConfig.groundLayer)) { visibleTargets.Add(targetsInTheRadius[i].gameObject); } } } } }
public override void update(SimpleAI _simpleAI, Transform transform) { findVisibleTargets(_simpleAI, transform); }
void Create2DArc(Transform transform, float radius, float angle, SimpleAI _simpleAI) { DrawArc(angle, getRadius(_simpleAI), getStartAngle(_simpleAI), getFinalAngle(_simpleAI), transform); }
float getRadius(SimpleAI _simpleAI) { return((!_simpleAI.facingRight) ? (float)radius * -1 : (float)radius); }
float getMiddleAngle(SimpleAI _simpleAI) { return(0 - ((!_simpleAI.facingRight) ? (float)rotation * -1 : (float)rotation)); }
float getStartAngle(SimpleAI _simpleAI) { return((-angle / 2) + ((!_simpleAI.facingRight) ? (float)rotation * -1 : (float)rotation)); }
public static void AIDrawTacticalBehaviours(SimpleAI _simpleAI) { AIDrawTacticalBehaviours(_simpleAI.ai, _simpleAI.gameConfig); }
public virtual void gizmos(SimpleAI simpleAI, Transform transform, Color color) { }
//TODO: Aperfeiçoar validação de AI void ValidateSelection() { bool isAAssetObject = false; //TODO: COrrigir edição de arquivo direto dos assets /*var path = ""; * var obj = Selection.activeObject; * if (obj == null) path = "Assets"; * else path = AssetDatabase.GetAssetPath(obj.GetGetSingleton()ID()); * if (path.Length > 0) * { * if (Directory.Exists(path)) * { * Debug.Log("Folder"); * } * else * { * try * { * Debug.Log(obj.GetType()); * //isAAssetObject = true; * * }catch * { * isAAssetObject = false; * } * } * } * else * { * Debug.Log("Not in assets folder"); * }*/ if (!isAAssetObject && Selection.gameObjects.Length < 1) { _ai = null; behaviour = -1; moment = windowMoments.error; return; } else { if (!isAAssetObject) { SimpleAI _simpleAI = Selection.gameObjects[0].GetComponent <SimpleAI>(); if (_simpleAI) { _ai = _simpleAI.ai; } } if (_ai != null) { if (moment != windowMoments.second) { moment = windowMoments.main; } if (_ai.actions.Length > 0 && behaviour < 0) { behaviour = 0; } else if (_ai.actions.Length - 1 < behaviour) { behaviour -= 1; } } else { _ai = null; behaviour = -1; moment = windowMoments.error; } } }
public TerrestrialMoviment(SimpleAI aiT) : base(aiT) { }
public AquaticMoviment(SimpleAI aiT) : base(aiT) { }
public AIMoviment(SimpleAI aiT) { AI = aiT; }
public FlyingMoviment(SimpleAI aiT) : base(aiT) { }
public abstract IEnumerator perform(SimpleAI _simpleAI);
public override IEnumerator perform(SimpleAI _simpleAI) { yield return(new WaitForSeconds(2)); }
public virtual void selectedGizmos(SimpleAI simpleAI, Transform transform, Color color) { }
public override void gizmos(SimpleAI _simpleAI, Transform transform, Color color) { Gizmos.color = color; Create2DArc(transform, getRadius(_simpleAI), angle, _simpleAI); }
public virtual void update(SimpleAI _simpleAI, Transform transform) { }
public static void AIDrawPlatformBehaviours(SimpleAI _simpleAI) { BehavioursTemplate(_simpleAI); }