361 lines
7.4 KiB
C#
361 lines
7.4 KiB
C#
using System;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class KGFMapIcon : KGFObject, KGFIMapIcon, KGFIValidator
|
|
{
|
|
[Serializable]
|
|
public class KGFDataMapIcon
|
|
{
|
|
public string itsCategory = string.Empty;
|
|
|
|
public Texture2D itsTextureIcon;
|
|
|
|
public Texture2D itsTextureArrow;
|
|
|
|
public bool itsRotate;
|
|
|
|
public Color itsColor = Color.white;
|
|
|
|
public bool itsIsVisible = true;
|
|
|
|
public bool itsUseArrow = true;
|
|
|
|
public bool itsRevealFogOfWar;
|
|
|
|
public bool itsShowToolTip = true;
|
|
|
|
public string itsToolTip = string.Empty;
|
|
|
|
public float itsIconScale = 1f;
|
|
|
|
public bool itsBlinking;
|
|
|
|
public int itsDepth;
|
|
|
|
public GameObject itsRepresentation;
|
|
}
|
|
|
|
public KGFDataMapIcon itsDataMapIcon = new KGFDataMapIcon();
|
|
|
|
private bool itsMapIconIsVisible;
|
|
|
|
private KGFMapSystem itsMapSystem;
|
|
|
|
private Shader itsShaderMapIcon;
|
|
|
|
private Transform itsTransformCache;
|
|
|
|
private Material itsMaterial;
|
|
|
|
private HUDManager hudManager;
|
|
|
|
private bool myBlinking;
|
|
|
|
public float blinkSpeed = 1f;
|
|
|
|
public string appearSound = string.Empty;
|
|
|
|
protected override void KGFAwake()
|
|
{
|
|
SetVisibility(itsDataMapIcon.itsIsVisible);
|
|
itsTransformCache = base.transform;
|
|
base.KGFAwake();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
SetVisibility(true);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
SetVisibility(false);
|
|
}
|
|
|
|
public int GetDepth()
|
|
{
|
|
return itsDataMapIcon.itsDepth;
|
|
}
|
|
|
|
public void SetToolTipText(string theToolTipText)
|
|
{
|
|
itsDataMapIcon.itsToolTip = theToolTipText;
|
|
}
|
|
|
|
public bool GetShowToolTip()
|
|
{
|
|
return itsDataMapIcon.itsShowToolTip;
|
|
}
|
|
|
|
public void SetShowToolTip(bool theShowToolTip)
|
|
{
|
|
itsDataMapIcon.itsShowToolTip = theShowToolTip;
|
|
}
|
|
|
|
public string GetToolTipText()
|
|
{
|
|
return itsDataMapIcon.itsToolTip;
|
|
}
|
|
|
|
public float GetIconScale()
|
|
{
|
|
return itsDataMapIcon.itsIconScale;
|
|
}
|
|
|
|
private GameObject CreateRepresentation()
|
|
{
|
|
if (itsShaderMapIcon == null)
|
|
{
|
|
itsShaderMapIcon = Shader.Find("ColorTextureAlpha");
|
|
if (itsShaderMapIcon == null)
|
|
{
|
|
LogError("Cannot find shader ColorTextureAlpha", typeof(KGFMapSystem).Name, this);
|
|
return null;
|
|
}
|
|
}
|
|
if (itsDataMapIcon.itsTextureIcon == null)
|
|
{
|
|
LogError("itsDataMapIcon.itsTextureIcon is null", typeof(KGFMapSystem).Name, this);
|
|
return null;
|
|
}
|
|
if ((itsShaderMapIcon != null) & (itsDataMapIcon.itsTextureIcon != null))
|
|
{
|
|
GameObject gameObject = KGFMapSystem.GenerateTexturePlane(itsDataMapIcon.itsTextureIcon, itsShaderMapIcon);
|
|
itsMaterial = gameObject.GetComponent<Renderer>().sharedMaterial;
|
|
return gameObject;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public bool GetIsBlinking()
|
|
{
|
|
return itsDataMapIcon.itsBlinking;
|
|
}
|
|
|
|
public void SetIsBlinking(bool theActivate)
|
|
{
|
|
itsDataMapIcon.itsBlinking = theActivate;
|
|
if (!theActivate)
|
|
{
|
|
itsMaterial.color = new Color(itsDataMapIcon.itsColor.r, itsDataMapIcon.itsColor.g, itsDataMapIcon.itsColor.b, 1f);
|
|
}
|
|
}
|
|
|
|
public Transform GetTransform()
|
|
{
|
|
if (this == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (base.gameObject == null)
|
|
{
|
|
return null;
|
|
}
|
|
return base.transform;
|
|
}
|
|
|
|
public string GetGameObjectName()
|
|
{
|
|
return base.gameObject.name;
|
|
}
|
|
|
|
public virtual string GetCategory()
|
|
{
|
|
return itsDataMapIcon.itsCategory;
|
|
}
|
|
|
|
public Color GetColor()
|
|
{
|
|
return itsDataMapIcon.itsColor;
|
|
}
|
|
|
|
public Texture2D GetTextureArrow()
|
|
{
|
|
return itsDataMapIcon.itsTextureArrow;
|
|
}
|
|
|
|
public bool GetRotate()
|
|
{
|
|
return itsDataMapIcon.itsRotate;
|
|
}
|
|
|
|
public virtual bool GetIsVisible()
|
|
{
|
|
return itsMapIconIsVisible;
|
|
}
|
|
|
|
public bool GetIsArrowVisible()
|
|
{
|
|
return itsDataMapIcon.itsUseArrow;
|
|
}
|
|
|
|
public GameObject GetRepresentation()
|
|
{
|
|
if (itsDataMapIcon.itsRepresentation == null)
|
|
{
|
|
itsDataMapIcon.itsRepresentation = CreateRepresentation();
|
|
}
|
|
return itsDataMapIcon.itsRepresentation;
|
|
}
|
|
|
|
public KGFMessageList Validate()
|
|
{
|
|
KGFMessageList kGFMessageList = new KGFMessageList();
|
|
if (itsDataMapIcon.itsCategory == string.Empty)
|
|
{
|
|
kGFMessageList.AddError("itsDataMapIcon.itsCategory is empty");
|
|
}
|
|
if (itsDataMapIcon.itsTextureIcon == null)
|
|
{
|
|
kGFMessageList.AddError("itsDataMapIcon.itsTextureIcon is null");
|
|
}
|
|
if (itsDataMapIcon.itsDepth < 0)
|
|
{
|
|
kGFMessageList.AddError("itsDataMapIcon.itsDepth must be > 0");
|
|
}
|
|
return kGFMessageList;
|
|
}
|
|
|
|
public void SetColor(Color theColor)
|
|
{
|
|
itsDataMapIcon.itsColor = theColor;
|
|
if (itsMapSystem == null)
|
|
{
|
|
itsMapSystem = KGFAccessor.GetObject<KGFMapSystem>();
|
|
}
|
|
if (itsMapSystem != null)
|
|
{
|
|
itsMapSystem.UpdateIcon(this);
|
|
}
|
|
}
|
|
|
|
public void SetCategory(string theCategory)
|
|
{
|
|
itsDataMapIcon.itsCategory = theCategory;
|
|
}
|
|
|
|
public void SetVisibility(bool theVisibility)
|
|
{
|
|
if (!itsMapIconIsVisible && theVisibility && !string.IsNullOrEmpty(appearSound))
|
|
{
|
|
AudioController.Play(appearSound);
|
|
}
|
|
itsMapIconIsVisible = theVisibility;
|
|
if (itsMapSystem == null)
|
|
{
|
|
itsMapSystem = KGFAccessor.GetObject<KGFMapSystem>();
|
|
}
|
|
if (itsMapSystem != null)
|
|
{
|
|
itsMapSystem.RefreshIconsVisibility();
|
|
}
|
|
}
|
|
|
|
public void SetTextureIcon(Texture2D theTexture)
|
|
{
|
|
itsDataMapIcon.itsTextureIcon = theTexture;
|
|
if (itsDataMapIcon.itsRepresentation == null)
|
|
{
|
|
itsDataMapIcon.itsRepresentation = CreateRepresentation();
|
|
}
|
|
if (itsDataMapIcon.itsRepresentation != null)
|
|
{
|
|
MeshRenderer component = itsDataMapIcon.itsRepresentation.GetComponent<MeshRenderer>();
|
|
if (component != null)
|
|
{
|
|
component.material.mainTexture = itsDataMapIcon.itsTextureIcon;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetTextureArrow(Texture2D theTexture)
|
|
{
|
|
itsDataMapIcon.itsTextureArrow = theTexture;
|
|
if (itsMapSystem == null)
|
|
{
|
|
itsMapSystem = KGFAccessor.GetObject<KGFMapSystem>();
|
|
}
|
|
if (itsMapSystem != null)
|
|
{
|
|
itsMapSystem.UpdateIcon(this);
|
|
}
|
|
}
|
|
|
|
public void SetArrowUsage(bool theIsArrowUsed)
|
|
{
|
|
itsDataMapIcon.itsUseArrow = theIsArrowUsed;
|
|
if (itsMapSystem == null)
|
|
{
|
|
itsMapSystem = KGFAccessor.GetObject<KGFMapSystem>();
|
|
}
|
|
if (itsMapSystem != null)
|
|
{
|
|
itsMapSystem.RefreshIconsVisibility();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!itsMapSystem || itsMapSystem.gameObject.activeSelf)
|
|
{
|
|
if (itsDataMapIcon.itsRevealFogOfWar && itsMapSystem != null)
|
|
{
|
|
itsMapSystem.RevealFogOfWarAtPoint(itsTransformCache.position);
|
|
}
|
|
if (itsDataMapIcon.itsBlinking)
|
|
{
|
|
float a = KGFUtility.PingPong(Time.time, 1f, 0f, 0f, 0.6f);
|
|
itsMaterial.color = new Color(itsDataMapIcon.itsColor.r, itsDataMapIcon.itsColor.g, itsDataMapIcon.itsColor.b, a);
|
|
}
|
|
UpdateBlink();
|
|
}
|
|
}
|
|
|
|
public void UpdateBlink()
|
|
{
|
|
if (!HUDManager.Instance)
|
|
{
|
|
return;
|
|
}
|
|
if (HUDManager.Instance.minimapGui.activeSelf)
|
|
{
|
|
if (!base.gameObject.activeSelf)
|
|
{
|
|
itsMaterial.color = new Color(itsDataMapIcon.itsColor.r, itsDataMapIcon.itsColor.g, itsDataMapIcon.itsColor.b, 0f);
|
|
}
|
|
else if (myBlinking)
|
|
{
|
|
Color color = itsMaterial.color;
|
|
color.a -= Time.deltaTime * blinkSpeed;
|
|
if (color.a <= 0f)
|
|
{
|
|
color.a = 0f;
|
|
myBlinking = false;
|
|
}
|
|
itsMaterial.color = color;
|
|
}
|
|
if (HUDManager.Instance.LineCrossingOver(base.transform.parent.gameObject))
|
|
{
|
|
Blink();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
itsMaterial.color = new Color(itsDataMapIcon.itsColor.r, itsDataMapIcon.itsColor.g, itsDataMapIcon.itsColor.b, 0f);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void Blink()
|
|
{
|
|
itsMaterial.color = new Color(itsDataMapIcon.itsColor.r, itsDataMapIcon.itsColor.g, itsDataMapIcon.itsColor.b, 1f);
|
|
myBlinking = true;
|
|
}
|
|
|
|
public static void LogError(string theError, string theCategory, MonoBehaviour theObject)
|
|
{
|
|
Debug.LogError(string.Format("{0} - {1}", theCategory, theError));
|
|
}
|
|
}
|