向Train Mode中添加LevelPanel调整

创建UI滑动进入和收回动画控制
创建一个通用的LevelProbabilityPanel而不是Start页面专用
将AddEventTrigger作为Extension添加到EventTrigger上
修改LevelPanel的Material为UniversalBlur
This commit is contained in:
Koha9 2023-10-21 04:54:42 +09:00
parent 39a7a340b8
commit 6603b23eb2
19 changed files with 677 additions and 575 deletions

View File

@ -1 +1 @@
{"count":1,"self":96.1897728,"total":96.582275299999992,"children":{"InitializeActuators":{"count":16,"self":0.00099899999999999989,"total":0.00099899999999999989,"children":null},"InitializeSensors":{"count":16,"self":0.0009993,"total":0.0009993,"children":null},"AgentSendState":{"count":867,"self":0.019012499999999998,"total":0.1588117,"children":{"CollectObservations":{"count":6936,"self":0.1277917,"total":0.1277917,"children":null},"WriteActionMask":{"count":6936,"self":0.0040009,"total":0.0040009,"children":null},"RequestDecision":{"count":6936,"self":0.0080066,"total":0.0080066,"children":null}}},"DecideAction":{"count":867,"self":0.0100142,"total":0.0100142,"children":null},"AgentAct":{"count":867,"self":0.2216761,"total":0.2216761,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1697442592","unity_version":"2021.3.14f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.14f1\\Editor\\Unity.exe -projectpath C:\\Users\\UCUNI\\OneDrive\\Unity\\ML-Agents\\Aimbot-ParallelEnv -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-UCUNI -hubSessionId e4e811a4-b1b9-40c9-bb87-1f58481c4f0b -accessToken CFEM6A4XwpAEfTmhoY1tJ77LSedBMNIqUlXBOmvKzJY00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"StartScene","end_time_seconds":"1697442688"}}
{"count":1,"self":165.6871296,"total":169.0971951,"children":{"InitializeActuators":{"count":16,"self":0.00099859999999999988,"total":0.00099859999999999988,"children":null},"InitializeSensors":{"count":16,"self":0.0004997,"total":0.0004997,"children":null},"AgentSendState":{"count":6284,"self":0.08416549999999999,"total":0.87303159999999991,"children":{"CollectObservations":{"count":50272,"self":0.7153004,"total":0.7153004,"children":null},"WriteActionMask":{"count":50272,"self":0.0220018,"total":0.0220018,"children":null},"RequestDecision":{"count":50272,"self":0.051563899999999996,"total":0.051563899999999996,"children":null}}},"DecideAction":{"count":6284,"self":0.1001521,"total":0.1001521,"children":null},"AgentAct":{"count":6284,"self":2.4353849999999997,"total":2.4353849999999997,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1697829167","unity_version":"2021.3.14f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.14f1\\Editor\\Unity.exe -projectpath C:\\Users\\UCUNI\\OneDrive\\Unity\\ML-Agents\\Aimbot-ParallelEnv -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-M0b7qtNNiWSON4XAp_iL2 -hubSessionId 2e5314ca-a4fa-4b7b-b736-755d2bd8b319 -accessToken ssCXQThs6ymBJJ5mKPBKm_froyZ-ddlXWkrjBDwnhZw00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"StartScene","end_time_seconds":"1697829337"}}

View File

@ -1 +1 @@
{"count":1,"self":28.5910528,"total":28.601550099999997,"children":{"InitializeActuators":{"count":16,"self":0.0010008,"total":0.0010008,"children":null},"InitializeSensors":{"count":16,"self":0.001,"total":0.001,"children":null},"AgentSendState":{"count":1,"self":0.0009989,"total":0.0034985,"children":{"CollectObservations":{"count":8,"self":0.0014998,"total":0.0014998,"children":null},"WriteActionMask":{"count":8,"self":0,"total":0,"children":null},"RequestDecision":{"count":8,"self":0.0009998,"total":0.0009998,"children":null}}},"DecideAction":{"count":1,"self":0.0005,"total":0.0005,"children":null},"AgentAct":{"count":1,"self":0.0044989,"total":0.0044989,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1697452285","unity_version":"2021.3.14f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.14f1\\Editor\\Unity.exe -projectpath C:\\Users\\UCUNI\\OneDrive\\Unity\\ML-Agents\\Aimbot-ParallelEnv -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-UCUNI -hubSessionId e4e811a4-b1b9-40c9-bb87-1f58481c4f0b -accessToken CFEM6A4XwpAEfTmhoY1tJ77LSedBMNIqUlXBOmvKzJY00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Train","end_time_seconds":"1697452314"}}
{"count":1,"self":155.8538496,"total":164.5160273,"children":{"InitializeActuators":{"count":16,"self":0.0009985,"total":0.0009985,"children":null},"InitializeSensors":{"count":16,"self":0.001,"total":0.001,"children":null},"AgentSendState":{"count":7148,"self":0.097526099999999991,"total":1.0346207,"children":{"CollectObservations":{"count":57184,"self":0.8580802,"total":0.8580802,"children":null},"WriteActionMask":{"count":57184,"self":0.020496499999999997,"total":0.020496499999999997,"children":null},"RequestDecision":{"count":57184,"self":0.0585179,"total":0.0585179,"children":null}}},"DecideAction":{"count":7148,"self":0.10903289999999999,"total":0.10903289999999999,"children":null},"AgentAct":{"count":7148,"self":7.5160247999999994,"total":7.5160247,"children":null}},"gauges":{"AKMAgent.CumulativeReward":{"count":32,"max":4010,"min":-7125.913,"runningAverage":-2807.06714,"value":4010,"weightedAverage":3303.63574}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1697829961","unity_version":"2021.3.14f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.14f1\\Editor\\Unity.exe -projectpath C:\\Users\\UCUNI\\OneDrive\\Unity\\ML-Agents\\Aimbot-ParallelEnv -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-M0b7qtNNiWSON4XAp_iL2 -hubSessionId 2e5314ca-a4fa-4b7b-b736-755d2bd8b319 -accessToken ssCXQThs6ymBJJ5mKPBKm_froyZ-ddlXWkrjBDwnhZw00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Train","end_time_seconds":"1697830125"}}

View File

@ -1005,8 +1005,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 2100000, guid: f6d46f1e916b3486c90a448a441fac6a, type: 2}
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1

View File

@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 5589415219770305708}
- component: {fileID: 5589415219770305697}
m_Layer: 5
m_Name: SingleTargetLevelProbabilityPanel
m_Name: SingleTargetProbabilityPanel
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -60,8 +60,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
m_Material: {fileID: 2100000, guid: f6d46f1e916b3486c90a448a441fac6a, type: 2}
m_Color: {r: 0.8862745, g: 0.8862745, b: 0.8862745, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
@ -92,6 +92,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
singleLevelProbabilityPanel: {fileID: 6536015492050286218, guid: 81d4d787c82b5174caf00af00e9a3cd1, type: 3}
targetTitleText: {fileID: 8396012208200061614, guid: 8a180acb9a0ba8b4aacd888419f082ed, type: 3}
singleLevelPanelsObjs: []
singleLevelPanels: []
--- !u!114 &5589415219770305697
MonoBehaviour:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public static class EventTriggerExtensions
{
public static void AddEventTrigger(this EventTrigger trigger, EventTriggerType type, UnityEngine.Events.UnityAction<BaseEventData> action)
{
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = type;
entry.callback.AddListener(action);
trigger.triggers.Add(entry);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2fd51a74b20da1040b8f0d4db7d9ef70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Vector3PositionExtensions
{
public static Vector3 FixCanvas(this Vector3 position,Vector3 originalVanvas,Vector3 nowVanvas)
{
return position + nowVanvas - originalVanvas;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60aebf9c97041a74eaa7c10ce97e7ba0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public static class targetTypeExtensions
public static class TargetTypeExtensions
{
public static int ToIndex(this Targets targetType)
{

View File

@ -170,9 +170,9 @@ public void UpdateTargetType(int targetInt)
// update state text
// public TextMeshProUGUI stateText;
// targetState[0] = targetTypeInt;
// targetState[1] = targetPosition.x / raySensors.viewDistance; // normalization
// targetState[2] = targetPosition.y / raySensors.viewDistance;
// targetState[3] = targetPosition.z / raySensors.viewDistance;
// targetState[1] = targetEndPosition.x / raySensors.viewDistance; // normalization
// targetState[2] = targetEndPosition.y / raySensors.viewDistance;
// targetState[3] = targetEndPosition.z / raySensors.viewDistance;
// targetState[4] = blockCont.thisBlock.firebasesAreaDiameter / raySensors.viewDistance;
// targetState[5] = blockCont.thisBlock.belongRatio;
// float[] myObserve = { transform.localPosition.x/raySensors.viewDistance, transform.localPosition.y / raySensors.viewDistance, transform.localPosition.z / raySensors.viewDistance, transform.eulerAngles.y/360f }

View File

@ -44,18 +44,6 @@ public void OnChartOnToggleChange()
chartOn = chartOnToggleObj.isOn;
}
public void OnEnemyNumTextChange()
{
try
{
enemyNum = Math.Abs(int.Parse(enemyNumInputObj.GetComponent<TMP_InputField>().text));
}
catch (NullReferenceException)
{
enemyNum = 3;
}
}
public void OnChartTimeOutTextChange()
{
try

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelProbabilityPanel : MonoBehaviour
{
public GameObject singleTargetLevelProbabilityPanel;
public GameObject startSceneData;
private SceneBlocksSet scenePrefabSet;
public List<TargetLevelProbabilityPanel> targetLevelProbabilityPanel = new List<TargetLevelProbabilityPanel>();
private void Start()
{
if (startSceneData == null)
{
try
{
// try get start scene data
scenePrefabSet = GameObject.Find("StartSceneDataTransfer").GetComponent<StartSeneData>().scenePrefabSet;
}
catch
{
// if not found, find dummy StartSeneData
scenePrefabSet = GameObject.Find("StartSceneDataTransferDummy").GetComponent<StartSeneData>().scenePrefabSet;
}
}
else
{
scenePrefabSet = startSceneData.GetComponent<StartSeneData>().scenePrefabSet;
}
for (int i = 0; i < scenePrefabSet.targetLevels.Length; i++)
{
Targets nowTarget = scenePrefabSet.targets[i];
targetLevelProbabilityPanel.Add(Instantiate(singleTargetLevelProbabilityPanel, transform).GetComponent<TargetLevelProbabilityPanel>());
targetLevelProbabilityPanel[i].IntializePanels(scenePrefabSet.GetLevelNumber(nowTarget), nowTarget.ToString());
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 44d064c42ee56374e94671f4f9f9d650
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -109,8 +109,6 @@ private void MaximizeMaskObj()
private Vector3 fixCanvas(Vector3 vector)
{
// fix position of button while canvas is changed
Vector3 fixedV = vector;
fixedV += (transform.parent.position - originalCanvas);
return fixedV;
return vector.FixCanvas(originalCanvas,transform.parent.position);
}
}

View File

@ -0,0 +1,151 @@
using DG.Tweening; // Importing the DOTween library for smooth animations.
using UnityEngine;
using UnityEngine.EventSystems; // Using the EventSystem to handle UI interactions.
public class UIVisibilityController : MonoBehaviour
{
[SerializeField]
private GameObject targetUIObj;
[SerializeField]
private GameObject triggerUIObj;
[SerializeField]
private GameObject canvasObj;
[SerializeField]
private Vector3 slideDirection = Vector3.zero;
[SerializeField]
private Vector3 slideDistance = Vector3.zero;
[SerializeField]
private float slideDuration = 0.2f;
// Cached positions and states for logic and animation.
private Vector3 targetOriginalPosition;
private Vector3 triggerOriginalPosition;
private Vector3 targetEndPosition;
private Vector3 triggerEndPosition;
private Vector3 originalCanvasPosition;
private bool isInActive = true; // Indicates if the UI is currently inactive.
private bool isOutActive = false; // Indicates if the UI is currently active.
private bool isMouseInTarget = false; // Is the mouse currently over the target UI?
private bool isMouseInTrigger = false; // Is the mouse currently over the trigger UI?
private void Start()
{
// Initial setup of component's states and values.
InitializeCanvasPosition();
InitializeSlideValues();
InitializeEventTrigger();
}
private void InitializeCanvasPosition()
{
if (canvasObj == null)
{
// Set canvasObj to the parent if not assigned.
canvasObj = transform.parent.gameObject;
}
originalCanvasPosition = canvasObj.transform.position;
}
private void InitializeSlideValues()
{
if (slideDirection == Vector3.zero)
{
// default slide direction is up (set to right).
slideDirection = Vector3.right;
Debug.LogError("SliderDirection not set, set default right");
}
if (slideDistance == Vector3.zero)
{
// default slide distance is based on targetUIObj dimensions.
RectTransform targetRT = targetUIObj.GetComponent<RectTransform>();
slideDistance = new Vector3(targetRT.rect.width, targetRT.rect.height, 0);
}
// Determine the start and end positions for sliding.
targetOriginalPosition = targetUIObj.transform.position;
triggerOriginalPosition = triggerUIObj.transform.position;
targetEndPosition = targetOriginalPosition + Vector3.Scale(slideDirection, slideDistance);
triggerEndPosition = triggerOriginalPosition + Vector3.Scale(slideDirection, slideDistance);
}
private void InitializeEventTrigger()
{
// Setting up event triggers for mouse interactions.
EventTrigger triggerObjET = triggerUIObj.GetComponent<EventTrigger>();
if (triggerObjET == null)
{
triggerObjET = triggerUIObj.AddComponent<EventTrigger>();
}
EventTrigger targetObjET = targetUIObj.GetComponent<EventTrigger>();
if (targetObjET == null)
{
targetObjET = targetUIObj.AddComponent<EventTrigger>();
}
triggerObjET.AddEventTrigger(EventTriggerType.PointerEnter, (eventData) => OnMouseIn(triggerUIObj));
triggerObjET.AddEventTrigger(EventTriggerType.PointerExit, (eventData) => OnMouseOut(triggerUIObj));
targetObjET.AddEventTrigger(EventTriggerType.PointerEnter, (eventData) => OnMouseIn(targetUIObj));
targetObjET.AddEventTrigger(EventTriggerType.PointerExit, (eventData) => OnMouseOut(targetUIObj));
}
private void Update()
{
// Check mouse interactions to determine whether to slide in or out the UI.
if ((isMouseInTrigger || isMouseInTarget) && isInActive)
{
SlideInScreen();
isInActive = false;
isOutActive = true;
}
else if (!isMouseInTrigger && !isMouseInTarget && isOutActive)
{
SlideOutScreen();
isInActive = true;
isOutActive = false;
}
}
private void OnMouseIn(GameObject type)
{
// Update flags based on which UI object the mouse enters.
if (type == triggerUIObj)
{
isMouseInTrigger = true;
}
else if (type == targetUIObj)
{
isMouseInTarget = true;
}
}
private void OnMouseOut(GameObject type)
{
// Update flags based on which UI object the mouse exits.
if (type == triggerUIObj)
{
isMouseInTrigger = false;
}
else if (type == targetUIObj)
{
isMouseInTarget = false;
}
}
private void SlideInScreen()
{
// Animate the UI objects to slide in.
triggerUIObj.transform.DOMove(triggerEndPosition, slideDuration).SetEase(Ease.OutCirc).Play();
targetUIObj.transform.DOMove(targetEndPosition, slideDuration).SetEase(Ease.OutCirc).Play();
}
private void SlideOutScreen()
{
// Animate the UI objects to slide out.
triggerUIObj.transform.DOMove(triggerOriginalPosition, slideDuration).SetEase(Ease.OutCirc).Play();
targetUIObj.transform.DOMove(targetOriginalPosition, slideDuration).SetEase(Ease.OutCirc).Play();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b459fcafb205c9540a282b421abdf6d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,13 +9,13 @@ EditorUserSettings:
value: 55090405535008090b5608764626074415151c79747c74602b7c1861e4b96c6c
flags: 0
RecentlyUsedSceneGuid-1:
value: 06570c0704040b0e5a575520137b5e44154f192e292d22367c2c4866b7b3376f
value: 5703025650035e5d090f087148715d4443161e2c7e2c20357b281b31b0e43060
flags: 0
RecentlyUsedSceneGuid-2:
value: 5453565f53020f085f5d0e72157a0844454f4c2b757d7265757a4f64b7b4313c
flags: 0
RecentlyUsedSceneGuid-3:
value: 5703025650035e5d090f087148715d4443161e2c7e2c20357b281b31b0e43060
value: 06570c0704040b0e5a575520137b5e44154f192e292d22367c2c4866b7b3376f
flags: 0
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d