备份CatanBuilding瘦身独立工程
This commit is contained in:
61
Assets/Scripts/UI/UIImage.cs
Normal file
61
Assets/Scripts/UI/UIImage.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIImage : Image
|
||||
{
|
||||
ShowImageData imageData;
|
||||
IUIService uiService;
|
||||
public void Sprite(string spriteName)
|
||||
{
|
||||
if (imageData == null)
|
||||
{
|
||||
imageData = new ShowImageData(this);
|
||||
}
|
||||
if (uiService == null)
|
||||
{
|
||||
uiService = GContext.container.Resolve<IUIService>();
|
||||
}
|
||||
if (uiService != null)
|
||||
{
|
||||
imageData.SetName(spriteName);
|
||||
uiService.SetImageSprite(imageData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("IUIService is not resolved.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ShowImageData : IShowImageData
|
||||
{
|
||||
public string spriteName { set; get; }
|
||||
public Image image { set; get; }
|
||||
string otherName;
|
||||
/// <summary>
|
||||
/// image 赋值必须新new一个对象,防止sprite 给的一个错误的对象
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
public ShowImageData(Image image)
|
||||
{
|
||||
this.image = image;
|
||||
}
|
||||
public ShowImageData(Image image, string spriteName)
|
||||
{
|
||||
this.image = image;
|
||||
SetName(spriteName);
|
||||
}
|
||||
public void SetName(string spriteName)
|
||||
{
|
||||
this.spriteName = spriteName;
|
||||
otherName = spriteName + "(Clone)";
|
||||
}
|
||||
public void SetImage(Sprite sprite)
|
||||
{
|
||||
if (image != null && (sprite.name == otherName || sprite.name == spriteName))
|
||||
{
|
||||
image.sprite = sprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user