void Start() { _flowAI = GetComponent <FlowAIHolder>().flowAI; proc1 = new ProcessNode(); proc2 = new ProcessNode(); proc3 = new ProcessNode(); proc4 = new ProcessNode(); proc5 = new ProcessNode(); rand1 = new BranchNode(); proc1.Initialize(1.0f, rand1, () => TFDebug.Log("visualizer", "proc1 finished"), "PROCESS1"); proc2.Initialize(1.0f, proc3, () => TFDebug.Log("visualizer", "proc2 finished"), "PROCESS2"); proc3.Initialize(1.0f, proc1, () => TFDebug.Log("visualizer", "proc3 finished"), "PROCESS3"); proc4.Initialize(1.0f, proc5, () => TFDebug.Log("visualizer", "proc4 finished"), "PROCESS4"); proc5.Initialize(1.0f, proc1, () => TFDebug.Log("visualizer", "proc5 finished"), "PROCESS5"); rand1.Initialize(proc2, 1.0f, proc4, 1.0f, () => { bool result = Random.Range(0, 2) == 0; TFDebug.Log("visualizer", "rand1 {0}", result.ToString()); return(result); }); rand1.summary = "RANDOM"; _flowAI.AddNode(proc1, proc2, proc3, proc4, proc5, rand1); _flowAI.entryPointNode.nextNode = proc1; _flowAI.Entry(); }
/// <summary>描画関数</summary> void OnGUI() { Color[] colors = { TFColor.GetColorFromCode(0x2a2a2a), TFColor.GetColorFromCode(0x303030) }; //Assets側からデータを取得 var columns = TFDebug.columns; //カラム幅の計算 var width = this.position.width / columns.Count; using (var h1 = new EditorGUILayout.HorizontalScope()) { foreach (var elem in columns) { var prop = TFDebug.GetLogColumnProperty(elem.Key); using (var v1 = new EditorGUILayout.VerticalScope()) { using (var h2 = new EditorGUILayout.HorizontalScope()) { //カラムヘッダーの描画 EditorGUILayout.LabelField(elem.Key, GUILayout.Width(width / 2f)); } using (var h2 = new EditorGUILayout.HorizontalScope()) { //ログ消去ボタン if (GUILayout.Button("Clear", EditorStyles.miniButtonLeft, GUILayout.Width(width / 2f))) { TFDebug.ClearLogColumn(elem.Key); } prop.collapsed = GUILayout.Toggle(prop.collapsed, "Collapse", EditorStyles.miniButtonRight); } prop.scrollPosition = EditorGUILayout.BeginScrollView(prop.scrollPosition, GUILayout.Height(v1.rect.height)); //ログ配列の取得 var logs = elem.Value.ToArray(); for (int f2 = logs.Length - 1; f2 >= 0; f2--) { //GUIStyleをラップ(折り返し)/リッチテキスト(カラータグが使えるようになる等)に設定 GUIStyle style = new GUIStyle(); style.wordWrap = true; style.richText = true; using (var h2 = new EditorGUILayout.HorizontalScope()) { //ログ背景の描画 EditorGUI.DrawRect(h2.rect, colors[f2 % 2]); //ログ本文の描画 EditorGUILayout.LabelField(logs[f2].text, style, GUILayout.Width(width)); } } EditorGUILayout.EndScrollView(); } } } }
// Update is called once per frame void Update() { fireTimer = Mathf.Max(0.0f, fireTimer - Time.deltaTime); // プレイヤーの情報が何も入ってない場合 if (Player == null) { GameplayChannel.GetInstance().SendRequestPlayerEvent(); return; } //更新処理 Update. _flowAI.Update(Time.deltaTime); time += Time.deltaTime; bool canSeePlayer = UpdatePlayerLastKnownPosition(); _visionCone.CreateVisionConeMesh(); // 敵を見ているかの判定 //if (_visionCone.IsTargetInVisionCone(gameObject, Player)) if (CanSeePlayer()) { _isFound = true; //Debug.Log("Can see target! 主人公を見ています!"); } else { _isFound = false; //Debug.Log("Cannot see target! 主人公を見ていません!"); } //Any process... if (_isRot) { //head.transform.Rotate(new Vector3(0,0, 60f * Time.deltaTime)); this.transform.Rotate(new Vector3(0, 60f * Time.deltaTime)); head.transform.Rotate(new Vector3(0, (((-1) * 60f) * Time.deltaTime))); } if (_isBullet) { Shoot(); } canSeePlayerPrevious = canSeePlayer; TFDebug.ClearMonitor("enemy"); TFDebug.Write("enemy", "isRot:{0}\n", _isRot.ToString()); TFDebug.Write("enemy", "isFound:{0}\n", _isFound.ToString()); }
void DrawFocus() { foreach (var item in _prepares) { if (item.isFocus && item.node is ProcessNode) { TFDebug.Log("x", "LID:{0}", item.node.localId); var temp = GUI.color; GUI.color = _focusNodeTexColor; GUI.DrawTexture(item.rect, _focusNodeTex); GUI.color = temp; } } }
/// <summary>擬似的にノードを交換する. Swap two nodes for imitative.</summary> /// <param name="fromId"></param> /// <param name="toId"></param> public void ImitativeSwap(int fromId, int toId) { if (fromId == toId) { return; } var temp1 = _nodes.Find(item => item.localId == fromId); var temp2 = _nodes.Find(item => item.localId == toId); var from = temp1 as ProcessNode; var to = temp2 as ProcessNode; //エラー処理 bool isFailed = false; //fromが不明 if (temp1 == null) { TFDebug.Log("FlowAIBasis", "fromノードが見つかりません"); isFailed = true; } //toが不明 if (temp2 == null) { TFDebug.Log("FlowAIBasis", "toノードが見つかりません"); isFailed = true; } //交換するノードが処理ノードではない if (from == null || to == null) { TFDebug.Log("FlowAIBasis", "処理ノード以外をSwapすることはできません"); isFailed = true; } //交換失敗 if (isFailed) { TFDebug.Log("FlowAIBasis", "Swapに失敗しました"); return; } var ft = from.Copy(); var tt = to.Copy(); from.Imitate(tt); to.Imitate(ft); TFDebug.Log("FlowAIBasis", "Swapping finished! from LID:{0} to LID:{1}", from.localId, to.localId); }
// Update is called once per frame void Update() { //更新処理 Update. _flowAI.Update(Time.deltaTime); //Any process... if (_isRot) { this.transform.Rotate(new Vector3(0f, 60f * Time.deltaTime)); } TFDebug.ClearMonitor("enemy"); TFDebug.Write("enemy", "isRot:{0}\n", _isRot.ToString()); TFDebug.Write("enemy", "isFound:{0}\n", _isFound.ToString()); }
/// <summary>チャンネル使用状況の更新</summary> public static void Checkout() { for (int f1 = 0; f1 < _capacity; f1++) { _channels[f1].used = _channels[f1].audioSrc.isPlaying; } int count = _channels.Count(elem => elem.used); var usageKeys = _channels.Where(elem => elem.used); var keys = usageKeys.ToArray(); TFDebug.ClearMonitor("@sound"); TFDebug.Write("@sound", string.Format("now using {0}/{1} channels\n", count.ToString(), _capacity.ToString())); for (int f1 = 0; f1 < keys.Count(); f1++) { TFDebug.Write("@sound", keys[f1].audioSrc.clip.name + "\n"); } }
/// <summary>遷移 Transition</summary> /// <param name="localId">遷移先のノードID LocalID of next node</param> public void Transition(int localId) { var node = _nodes.FirstOrDefault(item => item.localId == localId); //そのIDのノードが存在しない場合 if (node == null) { TFDebug.Log("FlowAIBasis", "[TRNS]この基盤に存在しないローカルID:{0}", localId); _isStopped = true; return; } _currentNode = node; _currentNode.Processing(); //終端ノードだった場合 if (_currentNode.GetNextNode() == null) { _isStopped = true; TFDebug.Log("FlowAIBasis", "[TRNS]終端ノードに到達しました ローカルID:{0}", localId); return; } }
void Update() { TFDebug.ClearMonitor("visualizer"); if (_isInSwapping) { _swappingElapsed += Time.unscaledDeltaTime; if (_swappingElapsed > _swappingDuration) { _isInSwapping = false; _swappingFromId = -1; _swappingToId = -1; } } if (!_isInHacking) { _showElapsed += Time.deltaTime; if (_showElapsed > _showDuration) { _isVisible = false; } } }
void OnGUI() { /*if (!_isInHacking) * { * if (GUI.Button(new Rect(0, 0, 100, 33), "hack begin")) * { * BeginHacking(0.05f); * } * }*/ TFDebug.Write("visualizer", "show time:{0}\n", _showElapsed); //非表示 if (!_isVisible) { return; } GUI.Box(new Rect(_windowPosition, _windowSize), ""); //ターゲットにするAIがnull if (_targetBasis == null) { var temp = GUI.color; GUI.color = Color.red; GUI.Label(new Rect(_windowPosition + _globalOffset, new Vector2(100f, 100f)), "Target AI not found"); GUI.color = temp; return; } Prepare(_targetBasis.entryPointNode); DrawLines(); DrawNodes(); DrawFocus(); if (_isInHacking) { ExitButton(new Rect(_exitButtonPosX + _windowPosition.x, _exitButtonPosY + _windowPosition.y, _exitButtonWidth, _exitButtonHeight)); PrepareData?focused = _prepares .Select(item => item as PrepareData?) .FirstOrDefault(item => item.Value.isFocus); if (Input.GetMouseButtonDown(0) && focused.HasValue && focused.Value.node is ProcessNode) { _isInDrag = true; _from = focused.Value.node; } if (Input.GetMouseButtonUp(0) && _isInDrag && focused.HasValue && focused.Value.node is ProcessNode) { _isInDrag = false; _to = focused.Value.node; if (!_isInSwapping) { _targetBasis.ImitativeSwap(_from.localId, _to.localId); _isInSwapping = true; _swappingElapsed = 0f; _swappingFromId = _from.localId; _swappingToId = _to.localId; } } else if (Input.GetMouseButtonUp(0) && _isInDrag) { _isInDrag = false; _from = null; } if (_isInDrag) { OnSwap(); } TFDebug.Write("visualizer", "is in swap:{0}\n", _isInDrag.ToString()); } }
/// <summary>ノードを描画する</summary> void DrawNodes() { foreach (var item in _prepares) { //スワップ中ならスキップする if (item.node.localId == _swappingFromId || item.node.localId == _swappingToId) { continue; } //位置 Vector2 pos = new Vector2(item.depthX * _nodeHorizontalSpace, item.depthY * _nodeVerticalSpace); pos += _globalOffset; //矩形 Rect nodeRect = new Rect(Vector2.zero, _nodeSize); nodeRect.center = pos; //テクスチャ描画 //使用色 Color usedColor = _nodeColor; //使用テクスチャ Texture2D usedTex = item.node is BranchNode ? _branchTex : _processTex; //アスペクト比 float aspect = nodeRect.width / nodeRect.height; //描画 GUI.DrawTexture(nodeRect, usedTex, ScaleMode.ScaleToFit, true, aspect, usedColor, 0f, 0f); if (item.isActive) { GUIStyle progStyle = new GUIStyle(); progStyle.font = _font; progStyle.fontSize = _fontSize; GUIStyleState progState = new GUIStyleState(); progState.textColor = _fontColor; progStyle.normal = progState; Rect progRect = nodeRect; progRect.position = new Vector2(progRect.position.x, progRect.position.y - _fontSize * 1.1f); float progress = _targetBasis.elapsed / item.node.duration; string bar = ""; for (int f1 = 0; f1 < (int)(progress * 20f); f1++) { bar += "|"; } GUI.Label(progRect, "progress:" + bar, progStyle); GUI.DrawTexture(nodeRect, usedTex, ScaleMode.ScaleToFit, true, aspect, _activeNodeColor, 0f, 0f); } //summaryの描画 GUIStyle style = new GUIStyle(); style.font = _font; style.fontSize = _fontSize; style.alignment = TextAnchor.MiddleCenter; GUIStyleState state = new GUIStyleState(); state.textColor = _fontColor; style.normal = state; GUI.Label(nodeRect, item.node.summary, style); } //スワップアニメーション if (_isInSwapping) { var swpFrom = _prepares.Find(item => item.node.localId == _swappingFromId); var swpTo = _prepares.Find(item => item.node.localId == _swappingToId); float t = _swappingElapsed / _swappingDuration; var swpFromRect = swpFrom.rect; var swpToRect = swpTo.rect; swpFromRect.position = Vector2.Lerp(swpFrom.rect.position, swpTo.rect.position, t); swpToRect.position = Vector2.Lerp(swpTo.rect.position, swpFrom.rect.position, t); TFDebug.Write("visualizer", "lerp t:{0}\n", t); GUI.DrawTexture(swpFromRect, _processTex, ScaleMode.ScaleToFit, true, _nodeSize.x / _nodeSize.y, _nodeColor, 0f, 0f); GUI.DrawTexture(swpToRect, _processTex, ScaleMode.ScaleToFit, true, _nodeSize.x / _nodeSize.y, _nodeColor, 0f, 0f); //summaryの描画 GUIStyle style = new GUIStyle(); style.font = _font; style.fontSize = _fontSize; style.alignment = TextAnchor.MiddleCenter; GUIStyleState state = new GUIStyleState(); state.textColor = _fontColor; style.normal = state; GUI.Label(swpFromRect, swpTo.node.summary, style); GUI.Label(swpToRect, swpFrom.node.summary, style); } }