Resolving error
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class AutoSquareSprite : MonoBehaviour
|
||||
{
|
||||
private static Sprite cachedSquare;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
if (spriteRenderer.sprite != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cachedSquare == null)
|
||||
{
|
||||
var texture = Texture2D.whiteTexture;
|
||||
cachedSquare = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0f, 0f, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f),
|
||||
1f);
|
||||
cachedSquare.name = "RuntimeSquare";
|
||||
}
|
||||
|
||||
spriteRenderer.sprite = cachedSquare;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13a3649e0bdf48b4afa233a4a4b64820
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class MainMenuController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string startSceneName = "Level1";
|
||||
private UIDocument uiDocument;
|
||||
private Button startButton;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
uiDocument ??= GetComponent<UIDocument>();
|
||||
if (uiDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var root = uiDocument.rootVisualElement;
|
||||
if (root == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
startButton = root.Q<Button>("Start");
|
||||
if (startButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
startButton.clicked += HandleStartClicked;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (startButton != null)
|
||||
{
|
||||
startButton.clicked -= HandleStartClicked;
|
||||
startButton = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleStartClicked()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(startSceneName))
|
||||
{
|
||||
SceneManager.LoadScene(startSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff915f6cddaa45cea485d96c5fd4a0b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user