public AIAction Decide(AIInfo aiInfo) { float cutoff = float.MinValue; aiInfo.lastDecisionTime = GameTimer.Instance.GetFrameTimestamp(); ScoreResult bestResult = new ScoreResult(); List <Decision> decisions = aiInfo.decisions; for (int i = 0; i < decisions.Count; i++) { Decision decision = decisions[i]; ScoreResult result = decision.evaluator.Score(aiInfo.Entity, decision, cutoff); if (result.score > cutoff) { cutoff = result.score; bestResult = result; } } bestResult.action.SetContext(bestResult.context); aiInfo.action = bestResult.action; return(bestResult.action); }
public void Tick() { int count = agents.Count; //todo need to 'instantiate' decisions. Right now they are all the same references for (int i = 0; i < count; i++) { AIInfo agent = agents[i]; agent.decisionDuration = 1f; if (GameTimer.Instance.FrameTimeElapsed(agent.decisionDuration, agent.lastDecisionTime)) { if (agent.action != null) { actionsToSetup.Remove(agent.action); actionsToTeardown.Remove(agent.action); actionsToTick.Remove(agent.action); agent.action.Teardown(); } AIAction action = Decide(agent); Debug.Assert(action != null, "action != null"); actionsToSetup.Add(action); } } count = actionsToSetup.Count; for (int i = 0; i < count; i++) { actionsToSetup[i].OnSetup(); actionsToTick.Add(actionsToSetup[i]); } actionsToSetup.Clear(); count = actionsToTick.Count; for (int i = 0; i < count; i++) { AIAction action = actionsToTick[i]; if (action.Tick()) { // todo use double buffer instead of remove actionsToTick.RemoveAt(i); actionsToTeardown.Add(action); i--; } } count = actionsToTeardown.Count; for (int i = 0; i < count; i++) { actionsToTeardown[i].Teardown(); } actionsToTeardown.Clear(); }
private void OnEntityActivated(Evt_EntityActivated evt) { AIInfo aiInfo = GameData.Instance.aiInfoMap[evt.entityId]; if (aiInfo.decisions != null && aiInfo.decisions.Count > 0) { agents.Add(aiInfo); } }
private void Awake() { if (instance != null) { Debug.Log("Too many AIInfo scripts!"); return; } instance = this; }
} //Singleton loop private void Start() { msgD = MsgDisplay.instance; cH = GetComponent <CityHandler>(); decks = GetComponent <Decks>(); deckHandUI = GameObject.Find("UIScripts").GetComponent <DeckHandUI>(); rP = GetComponent <ResolutionPhase>(); aiI = GetComponent <AIInfo>(); aiC = GetComponent <AICities>(); }
private void Start() { PopulateAttackDeck(); PopulateDefenceDeck(); PopulateReconDeck(); playerHand = GetComponent <Hands>(); dhUI = Script.GetComponent <DeckHandUI>(); aiInfo = GetComponent <AIInfo>(); PrepareDecks(); }
public void ViewMonster(int bt) { // 获取索引 GameObject Img_Lift = gameObject.transform.Find("MonsterViewPanel/Img_Lift").gameObject; GameObject Text_CubeName = gameObject.transform.Find("MonsterViewPanel/Text_CubeName").gameObject; GameObject Text_CubeName_Shadow = gameObject.transform.Find("MonsterViewPanel/Text_CubeName_Shadow").gameObject; GameObject Text_Describe = gameObject.transform.Find("MonsterViewPanel/Text_Describe").gameObject; GameObject Text_Attack = gameObject.transform.Find("MonsterViewPanel/Text_Attack").gameObject; GameObject Text_Health = gameObject.transform.Find("MonsterViewPanel/Text_Health").gameObject; GameObject Text_Speed = gameObject.transform.Find("MonsterViewPanel/Text_Speed").gameObject; // 清空上次 for (int i = 0; i < monsterItemList.Count; i++) { Imagecolor = new Color(255, 255, 255, 255); monsterItemList[i].transform.Find("Img_shadow").gameObject.GetComponent <Image>().color = Imagecolor; Text_Describe.GetComponent <Text>().text = " ???"; Text_Attack.GetComponent <Text>().text = "???"; Text_Health.GetComponent <Text>().text = "???"; Text_Speed.GetComponent <Text>().text = "???"; } AIInfo monster = Consts.AIList[bt]; // 点击后小图无效果 或者 none无,name有,shadow无,role有 // 点击后大图效果:if已有图鉴 Img_Lift.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Texture/MonsterList")[Consts.AIList[bt].Aiid]; Img_Lift.GetComponent <Image>().SetNativeSize(); Img_Lift.GetComponent <Image>().color = Color.black; Text_CubeName.GetComponent <Text>().text = "" + monsterItemList[bt].transform.Find("Text_name").gameObject.GetComponent <Text>().text; Text_CubeName_Shadow.GetComponent <Text>().text = "" + monsterItemList[bt].transform.Find("Text_name").gameObject.GetComponent <Text>().text; if (Consts.AIList[bt].IsFirst == true) { Imagecolor.a = 0; monsterItemList[bt].transform.Find("Img_shadow").gameObject.GetComponent <Image>().color = Imagecolor; Debug.Log("如果当前图鉴已存在,图片显示,颜色正常,文字正常"); Img_Lift.GetComponent <Image>().color = Color.white; Text_Describe.GetComponent <Text>().text = " " + monster.Describe1; Text_Attack.GetComponent <Text>().text = "" + monster.Attack; Text_Health.GetComponent <Text>().text = "" + monster.Health; Text_Speed.GetComponent <Text>().text = "" + monster.Speed; Img_Lift.GetComponent <Image>().color = Color.white; } }
/// <summary> /// 每次见到新的怪物调用 /// </summary> /// <param name="aiid"></param> void MeetMonsterHander(int bt) { Debug.Log("当前吃到的方块类型" + bt); if (Consts.cubeList[bt].isFirst == false) { // PauseOrContinue(true); GameObject Img_Tip1 = maskLayerMonsterFirst.transform.Find("Img_Tip1").gameObject; GameObject Img_Lift = monsterViewPanel.transform.Find("Img_Lift").gameObject; GameObject Text_CubeName = monsterViewPanel.transform.Find("Text_CubeName").gameObject; GameObject Text_CubeName_Shadow = monsterViewPanel.transform.Find("Text_CubeName_Shadow").gameObject; GameObject Text_Describe = monsterViewPanel.transform.Find("Text_Describe").gameObject; GameObject Text_Attack = monsterViewPanel.transform.Find("Text_Attack").gameObject; GameObject Text_Health = monsterViewPanel.transform.Find("Text_Health").gameObject; GameObject Text_Speed = monsterViewPanel.transform.Find("Text_Speed").gameObject; AIInfo monster = Consts.AIList[bt]; // 展示panel,文字、文字阴影、描述、类型、图片 maskLayerMonsterFirst.gameObject.SetActive(true); Text_CubeName.GetComponent <Text>().text = monster.AiName + ""; Text_CubeName_Shadow.GetComponent <Text>().text = monster.AiName + ""; Text_Describe.GetComponent <Text>().text = " " + monster.Describe1; Text_Attack.GetComponent <Text>().text = monster.Attack + ""; Text_Health.GetComponent <Text>().text = monster.Health + ""; Text_Speed.GetComponent <Text>().text = monster.Speed + ""; Img_Lift.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Texture/MonsterList")[Consts.AIList[bt].Aiid]; Img_Lift.GetComponent <Image>().SetNativeSize(); GameObject g = IllustrationSystem.GetComponent <Illustration>().monsterItemList[bt]; Debug.Log("初始化图鉴小图"); g.transform.Find("Text_name").gameObject.GetComponent <Text>().text = Consts.AIList[bt].AiName; Color Imagecolor = new Color(); Imagecolor.a = 0; g.transform.Find("Img_none").gameObject.GetComponent <Image>().color = Imagecolor; g.transform.Find("Img_role").gameObject.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Texture/MonsterList")[Consts.AIList[bt].Aiid]; g.transform.Find("Img_role").gameObject.GetComponent <Image>().SetNativeSize(); g.transform.Find("Img_role").gameObject.GetComponent <Image>().color = Color.white; Consts.AIList[bt].IsFirst = true; } #endregion }
public void Init() { nowAI = Consts.AIList[ID]; MaxHp = nowAI.Hp; HP = nowAI.Hp; if (nowAI.Aiid == 0) { skinMaterial = transform.GetChild(0).GetComponent <MeshRenderer>().material; } else if (nowAI.Aiid == 5) { skinMaterial = transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material; } else { skinMaterial = transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material; } skinColor = skinMaterial.color; backTimer = 0.8f; hurtTimer = 0.3f; isHurt = false; isDeath = false; /*if (hasStar) * { * GameObject game= Resources.Load<GameObject>("Star"); * GameObject te = Instantiate(game); * te.transform.position = transform.position; * te.transform.SetParent(transform); * }*/ if (nowAI.AttackOtherAi) { GameObject obj = new GameObject("CheckMonster"); obj.AddComponent <SphereCollider>().isTrigger = true; obj.layer = LayerMask.NameToLayer("CheckRole"); obj.transform.SetParent(transform); obj.transform.localPosition = Vector3.zero; obj.AddComponent <CheckMonster>().SetFollowRange(nowAI.FollowDistance); } }
float m_shockTime = 0.6f; // 정지 시간 /// <summary> /// AIController로부터 데이터 가져오기 + AIAnim /// 값 세팅하기 /// </summary> void Start() { aiCon = GetComponent <AIController>(); aiInfo = aiCon.aiInfo; aiAggro = GetComponent <AIAggro>(); aiAnim = transform.GetChild(0).GetComponent <AIAnim>(); cNetworkIdentity = GetComponent <CNetworkIdentity>(); skillProcess = GetComponent <SkillProcess>(); rd = GetComponent <Rigidbody>(); col = GetComponent <CapsuleCollider>(); agent = GetComponent <NavMeshAgent>(); highlighter = GetComponent <Highlighter>(); m_stun = false; isDie = false; enviroLayer = 1 << (int)SkillJudgeTarget.ENVIRO; // 환경레이어 -> 데칼 확인 ChangeClothes(); // 옷 조정 GetComponent <AIController>().DieAction += () => { isDie = false; }; }
/// <summary> /// 1. DB관련 초기설정하기(스폰, 필드) : anim, aggro /// 2. 랜덤된 크기 조정(모델, 콜라이더) /// 3. 호스트만 판단하게 하기 /// </summary> protected virtual void Start() { // 1. **미리 깔린 애들은 실행 전 id 넣어주고, db가 비어있는지를 확인해서 넣어주기 if (aiInfo.hp == 0) { aiInfo = CSV_AI.instance.aiDictionary[ID]; aiInfo.type = AIType.FIELD; // **AIPoolingManager가 게스트에 없기 때문 } else { ID = aiInfo.id; aiInfo.type = AIType.SPAWN; } aiAnim.GetBasicState(aiInfo.idleState, aiInfo.patrolState, aiInfo.normalSpeed, aiInfo.chaseSpeed); if (cNetworkIdentity.isHost) { aiAggro.AggroDBSetting(aiInfo.id); aggroTickCount = (int)(aiAggro.aggroData.aggroTime * 2); } // 2. aiAnim.gameObject.transform.localScale *= aiInfo.scale; col.height *= aiInfo.scale; col.radius *= aiInfo.scale; LiveReset(); DieAction += LiveReset; //AINetworkManager.instance.AIAddList(this.gameObject); // 3. //baseState.dictStateAction[state].enabled = true; //baseState.dictStateAction[state].StartAction(); }
public override void ExecuteAction() { base.ExecuteAction(); foreach (Hextile item in targets) { GameObject hextileObject = item.gameObject; Transform gfx = hextileObject.transform.Find("Main"); Renderer hextileRenderer = gfx.GetComponent <Renderer>(); hextileRenderer.material.color = Color.blue; item.visible = true; if (playedByAI) { if (item.isCity) { Debug.Log("Added a city tile to AI Enmy tiles."); GameObject cM = GameObject.Find("ClientMaster"); AIInfo aiI = cM.GetComponent <AIInfo>(); aiI.enemyTiles.Add(item); } } } }
public override void DoFixedUpdate() { // Store initial AI if (initialAI == null && ai != null) initialAI = ai; if (this.inferenceEngine != null && UFE.config.aiOptions.engine == AIEngine.FuzzyAI){ ControlsScript self = UFE.GetControlsScript(this.player); if (this.inputReferences != null && this.inputBuffer != null && self != null){ ControlsScript opponent = self.opControlsScript; if (opponent != null){ //------------------------------------------------------------------------------------------------- // Check the information stored in the input buffer... //------------------------------------------------------------------------------------------------- if (this.inputBuffer.Count == 0){ //--------------------------------------------------------------------------------------------- // If the we don't have the input of the previous frame, use the default input... //--------------------------------------------------------------------------------------------- Dictionary<InputReferences, InputEvents> frame = new Dictionary<InputReferences, InputEvents>(); foreach (InputReferences input in this.inputReferences){ frame[input] = InputEvents.Default; } this.inputBuffer.Add(frame); }else if (this.inputBuffer.Count >= 2){ this.inputBuffer.RemoveAt(0); } //------------------------------------------------------------------------------------------------- // If we haven't decided the input for the current frame yet... //------------------------------------------------------------------------------------------------- if (this.inputBuffer.Count < 2){ //--------------------------------------------------------------------------------------------- // Ask the AI to choose the most appropriated movement... //--------------------------------------------------------------------------------------------- MovementInfo chosenMovement = this.ChooseMovement(self, opponent, Time.fixedDeltaTime); //--------------------------------------------------------------------------------------------- // And simulate the input required for executing the next movement //--------------------------------------------------------------------------------------------- if (chosenMovement != null && chosenMovement.simulatedInput.Length > 0){ // HACK: added debug information, we should place this code in a more appropriated place /* RenderTexture renderTexture = new RenderTexture(300,40,24); RenderTexture.active = renderTexture; GameObject tempObject = new GameObject("Temporary"); tempObject.transform.position = new Vector3(-10000f, -10000f, -10000f); tempObject.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); Camera myCamera = tempObject.AddComponent<Camera>(); myCamera.orthographic = true; myCamera.orthographicSize = 4; myCamera.targetTexture = renderTexture; GameObject childObject = new GameObject("TextMesh"); childObject.transform.parent = tempObject.transform; childObject.transform.localPosition = new Vector3(0f, 0f, 1f); childObject.transform.localScale = Vector3.one; childObject.transform.localRotation = Quaternion.identity; TextMesh tm = childObject.AddComponent<TextMesh>(); tm.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; tm.renderer.material = new Material(Shader.Find("GUI/Text Shader")); tm.renderer.material.mainTexture = tm.font.material.mainTexture; tm.renderer.material.color = Color.black; tm.fontSize = 36; tm.fontStyle = FontStyle.Bold; tm.alignment = TextAlignment.Center; tm.anchor = TextAnchor.MiddleCenter; tm.text = (self.currentMove == null) + " -> " + chosenMovement.name; myCamera.Render(); RenderTexture.active = null; GameObject.Destroy(tempObject); */ //UFE.CastInput(InputType.Button, 0f, renderTexture, this.player); //---------------------------------------------------------------------------------// float sign = Mathf.Sign(opponent.transform.position.x - self.transform.position.x); foreach (ButtonPress[] buttonPresses in chosenMovement.simulatedInput){ Dictionary<InputReferences,InputEvents> frame = new Dictionary<InputReferences,InputEvents>(); foreach (InputReferences input in this.inputReferences){ frame[input] = InputEvents.Default; } foreach (InputReferences input in this.inputReferences){ if (input.inputType == InputType.HorizontalAxis){ foreach (ButtonPress buttonPress in buttonPresses){ if (buttonPress == ButtonPress.Back){ frame[input] = new InputEvents(-1f * sign); }else if (buttonPress == ButtonPress.Foward){ frame[input] = new InputEvents(1f * sign); } } }else if (input.inputType == InputType.VerticalAxis){ foreach (ButtonPress buttonPress in buttonPresses){ if (buttonPress == ButtonPress.Up){ frame[input] = new InputEvents(1f); }else if (buttonPress == ButtonPress.Down){ frame[input] = new InputEvents(-1f); } } }else{ foreach (ButtonPress buttonPress in buttonPresses){ if (input.engineRelatedButton == buttonPress){ frame[input] = new InputEvents(true); } } } } this.inputBuffer.Add(frame); } }else{ Dictionary<InputReferences, InputEvents> frame = new Dictionary<InputReferences, InputEvents>(); foreach (InputReferences input in this.inputReferences){ frame[input] = InputEvents.Default; } this.inputBuffer.Add(frame); } } } } /* string debug = "Player " + this.player; foreach (InputReferences input in this.inputReferences){ if (input.inputType == InputType.HorizontalAxis){ debug += "\nHorizontal: " + this.GetAxis(input); }else if (input.inputType == InputType.VerticalAxis){ debug += "\nVertical: " + this.GetAxis(input); }else{ debug += "\n" + input.engineRelatedButton + ": " + this.GetButton(input); } } Debug.Log(debug); */ }else{ base.DoFixedUpdate(); } }
public virtual void SetAIInformation(AIInfo ai) { this.ai = ai; if (ai != null){ AI4Unity.Fuzzy.InferenceSystem inferenceSystem = ai.GenerateInferenceSystem(); if (inferenceSystem != null){ this.inferenceEngine = new InferenceSystemThread( inferenceSystem, ai.GetDesirabilityScore(ai.advancedOptions.defaultDesirability) ); this.gaugeVar = this.inferenceEngine.GetInputVariable(AICondition.Attacking_GaugeUsage_Self); this.damageVar = this.inferenceEngine.GetInputVariable(AICondition.Attacking_Damage_Self); }else{ this.inferenceEngine = null; this.gaugeVar = null; this.damageVar = null; } }else{ this.inferenceEngine = null; this.gaugeVar = null; this.damageVar = null; } UFE.OnGameBegin -= this.OnGameBegin; UFE.OnGameBegin += this.OnGameBegin; base.Initialize(this.inputReferences); }