I have on the hard disk some images and saved files. Each image have his saved file. 10 images and 10 saved files :
images and saved games files on the hard disk
Then I'm loading the images to rawimages and when running the game it looks like that :
Images in raw images
This script is loading the images to raw images :
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class SavedGamesSlots : MonoBehaviour
{
public GameObject saveSlotPrefab;
public float gap;
private Transform slots;
private string[] imagesToLoad;
// Start is called before the first frame update
void Start()
{
imagesToLoad = Directory.GetFiles(Application.dataPath + "/screenshots", "*.png");
slots = GameObject.FindGameObjectWithTag("Slots Content").transform;
for (int i = 0; i < imagesToLoad.Length; i++)
{
var go = Instantiate(saveSlotPrefab);
go.transform.SetParent(slots);
Texture2D thisTexture = new Texture2D(100, 100);
string fileName = imagesToLoad[i];
byte[] bytes = File.ReadAllBytes(fileName);
thisTexture.LoadImage(bytes);
thisTexture.name = fileName;
go.GetComponent<RawImage>().texture = thisTexture;
}
}
// Update is called once per frame
void Update()
{
}
}
And the last script is for moving the mouse over the raw images and then it's making each image the mouse cursor is over to be brighter :
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class MouseHover : MonoBehaviour
{
public SaveLoad saveLoad;
public SceneFader sceneFader;
public RawImagePixelsChange rawImagePixelsChange;
private bool loadGame = false;
public void OnHover()
{
Debug.Log("Enter");
rawImagePixelsChange.modifyPixels(0.3f);
PlaySoundEffect();
loadGame = true;
}
public void OnHoverExit()
{
Debug.Log("Exit");
rawImagePixelsChange.restorePixels();
loadGame = false;
}
private void Update()
{
if(loadGame)
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, "Game"));
loadGame = false;
}
}
}
private void PlaySoundEffect()
{
transform.GetComponent<AudioSource>().Play();
}
}
Because I have the files names of the images in the SavedGamesSlots script, How can I bring this files names of each belonging image to the other script MouseHover ?
string fileName = imagesToLoad[i];
In this script the MouseHover I want to find and get the save file name the mouse cursor is over the image that belong to the saved file. Either inside the OnHover function or inside the GetMouseButtonDown.
Maybe it's be if I will save each image and it's saved file in another folder to identify easier what image belong to what saved file.
question from:
https://stackoverflow.com/questions/65945713/how-can-i-find-when-moving-the-mouse-pointer-over-raw-image-to-what-file-it-belo 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…