V3.4 追加Save Model按钮
追加Save Model按钮,对应按钮按下时显示message修改了font
This commit is contained in:
@@ -206,7 +206,7 @@ public class AgentController : MonoBehaviour
|
||||
lastShootTime = Time.time;
|
||||
if (Physics.Raycast(ray, out hit, 100))
|
||||
{
|
||||
if (hit.collider.tag != myTag && hit.collider.tag != "Wall")
|
||||
if (hit.collider.tag != myTag && hit.collider.tag != "Wall" && hit.collider.tag != "Untagged")
|
||||
{
|
||||
// kill enemy
|
||||
GameObject gotHitObj = hit.transform.gameObject;//获取受到Ray撞击的对象
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
using Unity.MLAgents;
|
||||
using Unity.MLAgents.SideChannels;
|
||||
using UnityEngine;
|
||||
|
||||
public class AimBotSideChennelController : MonoBehaviour
|
||||
{
|
||||
public AimbotSideChannel aimbotSideChannel;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
// We create the Side Channel
|
||||
aimbotSideChannel = new AimbotSideChannel();
|
||||
|
||||
// When a Debug.Log message is created, we send it to the stringChannel
|
||||
Application.logMessageReceived += aimbotSideChannel.SendDebugStatementToPython;
|
||||
|
||||
// The channel must be registered with the SideChannelManager class
|
||||
SideChannelManager.RegisterSideChannel(aimbotSideChannel);
|
||||
}
|
||||
|
||||
// Side Channel
|
||||
public void OnDestroy()
|
||||
{
|
||||
// De-register the Debug.Log callback
|
||||
Application.logMessageReceived -= aimbotSideChannel.SendDebugStatementToPython;
|
||||
if (Academy.IsInitialized)
|
||||
{
|
||||
SideChannelManager.UnregisterSideChannel(aimbotSideChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea781484763623c438c1806e3a965667
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using Unity.MLAgents.SideChannels;
|
||||
using UnityEngine;
|
||||
|
||||
public class AimbotSideChannel : SideChannel
|
||||
{
|
||||
public AimbotSideChannel()
|
||||
{
|
||||
ChannelId = new Guid("8bbfb62a-99b4-457c-879d-b78b69066b5e");
|
||||
}
|
||||
|
||||
protected override void OnMessageReceived(IncomingMessage msg)
|
||||
{
|
||||
var receivedString = msg.ReadString();
|
||||
Debug.Log("From Python : " + receivedString);
|
||||
}
|
||||
|
||||
public void SendDebugStatementToPython(string logString, string stackTrace, LogType type)
|
||||
{
|
||||
if (type == LogType.Warning)
|
||||
{
|
||||
var stringToSend = "Warning|" + logString;
|
||||
using (var msgOut = new OutgoingMessage())
|
||||
{
|
||||
msgOut.WriteString(stringToSend);
|
||||
QueueMessageToSend(msgOut);
|
||||
}
|
||||
}
|
||||
if (type == LogType.Error)
|
||||
{
|
||||
var stringToSend = "Error|" + logString;
|
||||
using (var msgOut = new OutgoingMessage())
|
||||
{
|
||||
msgOut.WriteString(stringToSend);
|
||||
QueueMessageToSend(msgOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6836d727b536dd54e893311318779b9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -6,13 +7,24 @@ using UnityEngine.UI;
|
||||
public class HUDController : MonoBehaviour
|
||||
{
|
||||
public bool chartOn = false;
|
||||
public GameObject sideChannelObj;
|
||||
public Toggle chartOnToggleObj;
|
||||
public Button saveModelButton;
|
||||
public TMP_InputField chartOnTimeOutInputObj;
|
||||
public TMP_InputField enemyNumInputObj;
|
||||
public float chartOnTimeOut = 1;
|
||||
public int enemyNum = 3;
|
||||
public float chartOnTimeOutDefault = 120f;
|
||||
|
||||
private float chatOntimeStart = 0;
|
||||
private AimBotSideChannelController sideChannelController;
|
||||
private MessageBoxController messageBox;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
sideChannelController = sideChannelObj.GetComponent<AimBotSideChannelController>();
|
||||
messageBox = gameObject.GetComponent<MessageBoxController>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@@ -55,4 +67,11 @@ public class HUDController : MonoBehaviour
|
||||
chartOnTimeOut = chartOnTimeOutDefault;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSaveModelButtonPressed()
|
||||
{
|
||||
// Send message to python to save model
|
||||
sideChannelController.SendSideChannelMessage("Command", "SaveModel");
|
||||
messageBox.PushMessage(new List<string> { "☑Model Will be Saved In Next Train Episode:)" }, new List<string> { messageBox.goodColor });
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ public class MLAgentsCustomController : Agent
|
||||
public GameObject paramContainerObj;
|
||||
public GameObject targetControllerObj;
|
||||
public GameObject environmentUIObj;
|
||||
public GameObject sideChannelObj;
|
||||
public GameObject hudUIObj;
|
||||
|
||||
[Header("Env")]
|
||||
@@ -25,6 +26,7 @@ public class MLAgentsCustomController : Agent
|
||||
private TargetUIController targetUIController;
|
||||
private RaySensors raySensors;
|
||||
private MessageBoxController messageBoxController;
|
||||
private AimBotSideChannelController sideChannelController;
|
||||
|
||||
// observation
|
||||
private float[] myObserve = new float[4];
|
||||
@@ -50,6 +52,7 @@ public class MLAgentsCustomController : Agent
|
||||
hudController = hudUIObj.GetComponent<HUDController>();
|
||||
targetUIController = hudUIObj.GetComponent<TargetUIController>();
|
||||
messageBoxController = hudUIObj.GetComponent<MessageBoxController>();
|
||||
sideChannelController = sideChannelObj.GetComponent<AimBotSideChannelController>();
|
||||
}
|
||||
|
||||
#region On episode begin function
|
||||
@@ -175,14 +178,14 @@ public class MLAgentsCustomController : Agent
|
||||
switch (finishedState)
|
||||
{
|
||||
case (int)TargetController.EndType.Win:
|
||||
Debug.LogWarning("Result|" + targetString + "|Win");
|
||||
sideChannelController.SendSideChannelMessage("Result",targetString+ "|Win");
|
||||
messageBoxController.PushMessage(
|
||||
new List<string> { "Game Win" },
|
||||
new List<string> { "green" });
|
||||
break;
|
||||
|
||||
case (int)TargetController.EndType.Lose:
|
||||
Debug.LogWarning("Result|" + targetString + "|Lose");
|
||||
sideChannelController.SendSideChannelMessage("Result", targetString + "|Lose");
|
||||
messageBoxController.PushMessage(
|
||||
new List<string> { "Game Lose" },
|
||||
new List<string> { "red" });
|
||||
|
||||
Reference in New Issue
Block a user