//void MoveDownPath() //{ // Vector2 currenWaypoint = path[0]; // while (true) // { // if (Vector2.Distance(transform.position, currenWaypoint) < 0.02f) // { // targetIndex++; // if (targetIndex >= path.Length) // { // targetIndex = 0; // finishedPath = true; // } // currenWaypoint = path[targetIndex]; // } // transform.position = Vector2.MoveTowards(transform.position, currenWaypoint, speed * Time.deltaTime); // } //} protected virtual void FindEnemy() { hit = Physics2D.Raycast(transform.position, transform.up, 10); if (hit) { if (hit.collider.gameObject.tag != gameObject.tag && hit.collider.gameObject.GetComponent <Actor>()) { foundEnemy = true; currentLookCounter = 0; lastSighted = hit.point; behaviour = AIBehaviour.ATTACK; StopCoroutine("FollowPath"); lookHere = lastSighted; } else { if (foundEnemy) { targetEnemy = lastSighted; PlayerFoundCoolDown(); } } } Debug.DrawRay(transform.position, transform.up * 10, Color.red, Time.deltaTime, true); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { me = animator.GetComponent <AIBehaviour>(); // Bench Aisle Node if (me.left) { targetA = me.myBench.aisleLeft; } else { targetA = me.myBench.aisleRight; } // Bench Seat Node targetB = me.myBench.Seats[me.mySeat].TargetB; // Confession Node targetC = AIManager.instance.confessionSeatLocation; if (me.agent.isOnNavMesh) { me.agent.SetDestination(targetA.position); } }
public override ActionResult Execute(RAIN.Core.AI ai) { m_aiBehaviour = new AIBehaviour (ai,_children,"Run"); //Is monster in certain animation return m_aiBehaviour.CheckAndAccess(); }
protected override void OnStateExit(AIBehaviour aiBehaviour) { if (navMeshMovement != null) { navMeshMovement.speed = lastSpeed; } }
protected override void OnStart(AIBehaviour aiBehaviour) { if (!aiBehaviour.TryGetExposedObject(fieldOfViewParameter, out fov)) { Debug.LogWarning("The Can See Condition has no Field Of View."); } }
private void Start() { xBounds = arena.GetComponent <Renderer>().bounds.size.x / 2f; yBounds = arena.GetComponent <Renderer>().bounds.size.z / 2f; scoreRed = 0; scoreBlue = 0; blueTeam = new List <NPC>(); redTeam = new List <NPC>(); redFlagTargeted = blueFlagTargeted = isRedFlagTargeted = isBlueFlagTargeted = false; var npcs = FindObjectsOfType <NPC>(); foreach (var npc in npcs) { if (npc.gameObject.tag == "BlueTeam") { blueTeam.Add(npc); } else if (npc.gameObject.tag == "RedTeam") { redTeam.Add(npc); } } aiBehaviour = AIBehaviour.AI_BEHAVIOUR_2; }
protected override void init() { base.init(); GameObject g; if (Behaviour == null) { g = GameObject.Find((GoalVariables["ExecutePrefab"])); if (g == null) { g = (GameObject)Resources.Load(GoalVariables["ExecutePrefab"]); } } else { g = Behaviour; GoalVariables["ExecutePrefab"] = Behaviour.name; } if (g != null) { b = new AIBehaviour("AutoSet", g, this, Priority); } else if (GoalVariables["ExecutePrefab"] == "ExecuteThisBehaviour") { b = new AIBehaviour("AutoSet", gameObject, this, Priority); } }
private void Awake() { aiBehaviour = GetComponent <AIBehaviour>(); FSMFnCondition fSMFnCondition = new FSMFnCondition(); fSMFnCondition.fn = aiBehaviour.isNeedPatrol; FSMTransition transition = new FSMTransition(); transition.condition = fSMFnCondition; transition.target = PatrolSate; /* * FSMFnCondition fSMFnCondition1 = new FSMFnCondition(); * fSMFnCondition1.fn = AIBehaviour.isArrived; * FSMFnCondition fSMFnCondition2 = new FSMFnCondition(); * fSMFnCondition2.fn = AIBehaviour.isTargetCapture; * ConditionOr conditionOr = new ConditionOr(); * conditionOr.condition1 = fSMFnCondition1; * conditionOr.condition2 = fSMFnCondition2; * FSMTransition transition = new FSMTransition(); * transition.condition = conditionOr; * transition.target = PatrolSate;*/ transitions.Add(transition); /* * fSMFnCondition.fn = AIBehaviour.isArrived; * transition.condition = fSMFnCondition; * transition.target = PatrolSate; * transitions.Add(transition); */ }
//Convert from AIBehaviour to ParagonAI.CustomBehaviour public CustomAIBehaviour GetNewBehaviour(AIBehaviour t) { ParagonAI.CustomAIBehaviour bToReturn = null; switch (t) { case AIBehaviour.Search: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Search)); break; case AIBehaviour.Dodging: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Dodge)); break; case AIBehaviour.Cover: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Cover)); break; case AIBehaviour.Patrolling: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Patrol)); break; case AIBehaviour.Wander: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Wander)); break; case AIBehaviour.GoToMoveTarget: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.ChargeTarget)); break; case AIBehaviour.UseDynamicObject: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.DynamicObject)); break; case AIBehaviour.InvestigateSound: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.InvestigateSound)); break; case AIBehaviour.MoveToTransform: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.MoveToTransform)); break; case AIBehaviour.RunFromGrenade: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.RunAwayFromGrenade)); break; } bToReturn.Initiate(); return(bToReturn); }
protected override void OnPerform(AIBehaviour aiBehaviour) { if (aiBehaviour.TryGetExposedObject(gameObjectParameter, out GameObject gameObject)) { gameObject.SetActive(enableGameObject); } }
public void SetBehaviour(AIBehaviour behaviour) { _behaviour = behaviour; _behaviour.BindAgent(Agent); behaviour.SetSensor(Sensor); //Update(); }
protected override void OnPerform(AIBehaviour aiBehaviour) { if (aiBehaviour.TryGetExposedObject(rendererParameter, out Renderer renderer)) { renderer.material = material; } }
// Will trigger the effects in the AIBehaviour Script private void UseEffect(AIBehaviour ai, ElementEffect effect) { if (effect == null) { return; } if (effect.willDamage) { ai.Damage(effect.damage); } if (effect.willPush) { Vector3 offset = transform.position - ai.transform.position; ai.Push(Mathf.Sign(offset.x), effect.pushForce); } if (effect.willFreeze) { ai.Freeze(effect.activeTime); } if (effect.willStun) { ai.Stun(effect.activeTime); } }
/// <summary> /// Load the given controller and draw all of it's nodes.. /// </summary> public static void LoadController(AIController controller, AIBehaviour aiBehaviour = null, bool forceLoad = false) { if (aiBehaviour != null && aiBehaviour.sharedController != controller && aiBehaviour.runtimeController != controller) { Debug.Log("[AI Graph]: Try Load controller with an ai behaviour with a different controller"); return; } if (controller != null && !controller.isCopy) { controllerBeforeGraphClosed = controller; aiBehaviourBeforeGraphClosed = aiBehaviour; } else { controllerBeforeGraphClosed = null; aiBehaviourBeforeGraphClosed = null; } if (instance != null) { instance.LoadControllerInternal(controller, aiBehaviour, forceLoad); instance.Repaint(); } }
// Start is called before the first frame update void Start() { arrived = false; // movement = gameObject.GetComponent<MovementControl>(); ai = gameObject.GetComponent <AIBehaviour>(); movement = gameObject.GetComponent <MovementControl>(); }
protected override bool OnDecide(AIBehaviour aiBehaviour) { if (fov != null) { fov.targetMask = targetMask; fov.obstacleMask = obstacleMask; fov.viewAngle = viewAngle; fov.viewRadius = viewRadius; fov.FindVisibleTargets(ref visibleTargetsList); if (visibleTargetsList.Count > 0) { bool flag1 = false; bool flag2 = false; if (visibleTargetParameter != null) { flag1 = aiBehaviour.TrySetValue(visibleTargetParameter, visibleTargetsList.ToArray()[0]); } if (visibleTargetsParameter != null) { flag2 = aiBehaviour.TrySetValue(visibleTargetsParameter, visibleTargetsList.ToArray()); } return(flag1 || flag2); } } return(false); }
private void OnEnable() { agentBehaviour = GetComponent <AgentBehaviour>(); aiBehaviour = GetComponent <AIBehaviour>(); layerMask = LayerMask.NameToLayer("Elemnet"); m_Ai.AddBehaviours( BT.Selector().AddBehaviours( BT.Sequence().AddBehaviours( BT.Condition(() => { return(aiBehaviour.getCircleElementsNum() > 2); }), //如果没有发现敌人和方块则自由移动 BT.Sequence().AddBehaviours( //如果没有发现 BT.If(() => { return(!isFindElement && !isFindPlayer); }).AddBehaviours( //进行随机移动 BT.Call(agentBehaviour.RandomWalk) //进行随搜 //BT.Call(CheckForAround) ), //如果有发现 BT.If(() => { return(isFindElement); }).AddBehaviours( BT.Call(agentBehaviour.Pursue) ) ) ) ) ); }
/** * Returns the highest behaviour in the tree that is executable. */ public AIBehaviour getBehaviourToExecute() { if (isExecutable()) { return(this); } if (behaviours == null) { return(null); } foreach (var behaviour in behaviours) { if (behaviour.isExecutable()) { return(behaviour); } } foreach (var behaviour in behaviours) { AIBehaviour b = behaviour.getBehaviourToExecute(); if (b != null && !b.isLeaf()) { return(b); } } return(null); }
public bool CalledForNextAI() { if (waitingAI.Count > 0) { if (currentAI != null) { if (currentAI.madePrayer) { currentAI = waitingAI[0]; currentAI.callForPrayer(); waitingAI.Remove(currentAI); return(true); } } else { currentAI = waitingAI[0]; currentAI.callForPrayer(); waitingAI.Remove(currentAI); return(true); } } return(false); }
public void Start() { animator = GetComponent <TinkerAnimator>(); at_t = 0; aiBehaviour = SeekPlayer; //target = GameObject.FindWithTag("Player"); }
// Update is called once per frame void Update() { waited += Time.deltaTime; if (waited < Frequency) { return; } string ailog = ""; float BestAIValue = float.MinValue; AIBehaviour bestAI = null; aiSupport.GetSupport(gameObject).refresh(); foreach (var ai in aiBehaviours) { ai.TimePassed += waited; var aiValue = (ai.GetWeight() * ai.WeightMultiplier) + Random.Range(0, Confusion); ailog += ai.GetType().Name + ":" + aiValue + "\n"; if (aiValue > BestAIValue) { BestAIValue = aiValue; bestAI = ai; } } //Debug.Log(ailog); bestAI.Execute(); waited = 0; }
// ================================================================= // OnTriggerExit for when a character exits the enemy area. // ================================================================= void OnTriggerExit(Collider other) { if (team == Team.RED) { if (other.gameObject.tag == "Blue") { ai_script = other.GetComponent <AIBehaviour>(); if (ai_script.has_flag == false) { ai_script.enemy_area = false; } } } else if (team == Team.BLUE) { if (other.gameObject.tag == "Red") { ai_script = other.GetComponent <AIBehaviour>(); if (ai_script.has_flag == false) { ai_script.enemy_area = false; } } } else { return; } }
public static AIBehaviour AIBehaviourSettings(AIBehaviour ai, int index) { GUILayout.Label("Priority "+(index+1).ToString(), EditorStyles.boldLabel); ai.battleAI = EditorGUILayout.Popup("Battle AI", ai.battleAI, DataHolder.BattleAIs().GetNameList(true), GUILayout.Width(mWidth)); ai.difficultyID = EditorGUILayout.Popup("Difficulty", ai.difficultyID, DataHolder.Difficulties().GetNameList(true), GUILayout.Width(mWidth)); EditorGUILayout.Separator(); if(GUILayout.Button("Add action", GUILayout.Width(mWidth*0.5f))) { ai.AddAction(); } for(int i=0; i<ai.attackSelection.Length; i++) { EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Action "+(i+1).ToString(), EditorStyles.boldLabel); EditorGUILayout.Separator(); if(GUILayout.Button("Remove", GUILayout.Width(mWidth*0.3f))) { ai.RemoveAction(i); break; } if(GUILayout.Button("Copy", GUILayout.Width(mWidth*0.3f))) { ai.CopyAction(i); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); ai.actionDifficultyID[i] = EditorGUILayout.Popup("Difficulty", ai.actionDifficultyID[i], DataHolder.Difficulties().GetNameList(true), GUILayout.Width(mWidth)); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); ai.attackSelection[i] = (AttackSelection)EditorGUILayout.EnumPopup( ai.attackSelection[i], GUILayout.Width(mWidth*0.5f)); if(AttackSelection.SKILL.Equals(ai.attackSelection[i])) { ai.useID[i] = EditorGUILayout.Popup(ai.useID[i], DataHolder.Skills().GetNameList(true), GUILayout.Width(mWidth*0.7f)); ai.useLevel[i] = EditorGUILayout.IntField("Skill level", ai.useLevel[i], GUILayout.Width(mWidth*0.7f)); ai.useLevel[i] = EditorTab.MinMaxCheck(ai.useLevel[i], 1, DataHolder.Skill(ai.useID[i]).level.Length); } else if(AttackSelection.ITEM.Equals(ai.attackSelection[i])) { ai.useID[i] = EditorGUILayout.Popup(ai.useID[i], DataHolder.Items().GetNameList(true), GUILayout.Width(mWidth*0.7f)); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.EndVertical(); } EditorGUILayout.Separator(); return ai; }
public bool AddBehaviourNow(AIBehaviour _behaviour) { FuckYouUnity(); _behaviour.SetIterationCount(1); behaviours.Insert(currentBehaviour, _behaviour); behaviourCount++; return(true); }
protected override void OnStateUpdate(AIBehaviour aiBehaviour) { if (navMeshMovement != null && followObject != null) { navMeshMovement.speed = speed; navMeshMovement.MoveToDestination(followObject.transform.position, stoppingDistance); } }
public void ReplaceAIBehaviour(AIBehaviour newValue) { var index = CoreComponentsLookup.AIBehaviour; var component = (AIBehaviourComponent)CreateComponent(index, typeof(AIBehaviourComponent)); component.value = newValue; ReplaceComponent(index, component); }
void OnEnable() { behaviour = target as AIBehaviour; sharedController = serializedObject.FindProperty("m_sharedController"); parameterReferences = serializedObject.FindProperty("m_parameterReferences"); m_startOnAwake = serializedObject.FindProperty("m_startOnAwake"); }
internal sealed override void Initialize(NodeCanvas canvas, AIBehaviour aiBehaviour) { node = target as T; this.canvas = canvas; this.aiBehaviour = aiBehaviour; OnViewCreated(); }
public void SetActiveAI() { int r = Random.Range(0, numAI); AIBehaviour aiToActivate = preGeneratedAI[r].GetComponent <AIBehaviour>(); aiToActivate.myInformation.timesVisited++; preGeneratedAI[r].SetActive(true); waitingAI.Add(aiToActivate); }
public bool AddBehaviour(AIBehaviour _behaviour) { FuckYouUnity(); behaviours.Add(_behaviour); behaviours[behaviourCount].complete = COMPLETION_STATE.NOT_STARTED; behaviourCount++; return(true); }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody2D>(); rend = this.GetComponent <SpriteRenderer>(); ai = GetComponent <AIBehaviour>(); characterRotation = transform.rotation.eulerAngles; }
void HandleHit(RaycastHit h) { if (h.transform.tag == "Enemy") { AIBehaviour ab = h.transform.gameObject.GetComponent <AIBehaviour>(); ab.Damage(7); ab.ToggleGotHit(); } }
public override void BehaviourCancelled(AIBehaviour.CancelReason reason) { switch (reason) { case AIBehaviour.CancelReason.CannotMove: break; } base.BehaviourCancelled(reason); }
//Convert from AIBehaviour to ParagonAI.CustomBehaviour public CustomAIBehaviour GetNewBehaviour(AIBehaviour t) { ParagonAI.CustomAIBehaviour bToReturn = null; switch(t) { case AIBehaviour.Search : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Search)); break; case AIBehaviour.Dodging : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Dodge)); break; case AIBehaviour.Cover : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Cover)); break; case AIBehaviour.Patrolling : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Patrol)); break; case AIBehaviour.Wander : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.Wander)); break; case AIBehaviour.GoToMoveTarget : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.ChargeTarget)); break; case AIBehaviour.UseDynamicObject : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.DynamicObject)); break; case AIBehaviour.InvestigateSound : bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.InvestigateSound)); break; case AIBehaviour.MoveToTransform: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.MoveToTransform)); break; case AIBehaviour.RunFromGrenade: bToReturn = (ParagonAI.CustomAIBehaviour)gameObject.AddComponent(typeof(ParagonAI.RunAwayFromGrenade)); break; } bToReturn.Initiate(); return bToReturn; }
public static AIBehaviour[] Remove(int index, AIBehaviour[] list) { ArrayList tmp = new ArrayList(); foreach(AIBehaviour str in list) tmp.Add(str); tmp.RemoveAt(index); return tmp.ToArray(typeof(AIBehaviour)) as AIBehaviour[]; }
public static AIBehaviour[] Add(AIBehaviour n, AIBehaviour[] list) { ArrayList tmp = new ArrayList(); foreach(AIBehaviour str in list) tmp.Add(str); tmp.Add(n); return tmp.ToArray(typeof(AIBehaviour)) as AIBehaviour[]; }
public bool AddBehaviour(AIBehaviour _behaviour) { FuckYouUnity(); behaviours.Add(_behaviour); behaviours[behaviourCount].complete = COMPLETION_STATE.NOT_STARTED; behaviourCount++; return true; }
public bool AddBehaviourNow(AIBehaviour _behaviour) { FuckYouUnity(); _behaviour.SetIterationCount(1); behaviours.Insert(currentBehaviour, _behaviour); behaviourCount++; return true; }
public void AdAibehaviourToList(AIBehaviour aiBeh) { aiBehaviourList.Add (aiBeh); }
protected void StartNewBehaviour(AIBehaviour newBehaviour) { StopCurrentBehaviour(); currentAIBehaviour = newBehaviour; currentAIBehaviour.BehaviourFinishedEvent += BehaviourFinished; currentAIBehaviour.BehaviourStoppedEvent += BehaviourStopped; currentAIBehaviour.BehaviourCancelledEvent += BehaviourCancelled; currentAIBehaviour.Start(); }
public void StopCurrentBehaviour(AIBehaviour.StopReason reason) { if (currentAIBehaviour != null && !currentAIBehaviour.Finished && !currentAIBehaviour.Stopped) { Debug.Log("currentAIBehaviour.Stop " + currentAIBehaviour.GetType()); currentAIBehaviour.Stop(reason, null); } if(currentAIBehaviour == null) Debug.Log("no current behaviour "); currentAIBehaviour = null; }
public void StopCurrentBehaviour() { if (currentAIBehaviour != null && !currentAIBehaviour.Finished && !currentAIBehaviour.Stopped) { Debug.Log("currentAIBehaviour.Stop " + currentAIBehaviour.GetType()); currentAIBehaviour.Stop(AIBehaviour.StopReason.None, null); } currentAIBehaviour = null; }
public virtual void BehaviourStopped(AIBehaviour.StopReason reason, GameObject interuptionObject) { //Debug.Log("Stopped" + reason); }
public virtual void BehaviourFinished(AIBehaviour.FinishedBehaviour behaviorType) { //Debug.Log("Finished" + behaviorType); }
public virtual void BehaviourCancelled(AIBehaviour.CancelReason reason) { //Debug.Log("Cancelled" + reason); }
public override void BehaviourFinished(AIBehaviour.FinishedBehaviour behaviorType) { Patrol(); base.BehaviourFinished(behaviorType); }
public override void BehaviourStopped(AIBehaviour.StopReason reason, GameObject interuptionObject) { base.BehaviourStopped(reason, interuptionObject); }