78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using AnimatorPlus;
|
|
using Continentis.MainGame.UI;
|
|
using SLSFramework.General;
|
|
using UnityEngine;
|
|
|
|
namespace Continentis.MainGame.Character
|
|
{
|
|
public partial class CombatCharacterViewBase : MonoBehaviour
|
|
{
|
|
public CharacterBase character;
|
|
|
|
public GameObject mainView;
|
|
public Animator animator;
|
|
public AnimatorPlus2D animatorPlus2D;
|
|
public SerializableDictionary<string, AnimationClip> animations;
|
|
|
|
public Collider selector;
|
|
|
|
public Transform numbersPivot;
|
|
public Transform textsPivot;
|
|
public Transform hudPivot;
|
|
public Transform centerPoint => hudPivot;
|
|
public HUDContainer hudContainer;
|
|
|
|
public List<SpriteRenderer> spriteRenderers;
|
|
public List<Material> materials;
|
|
|
|
public void Initialize(CharacterBase character)
|
|
{
|
|
this.character = character;
|
|
|
|
spriteRenderers = new List<SpriteRenderer>(mainView.GetComponentsInChildren<SpriteRenderer>());
|
|
materials = new List<Material>();
|
|
foreach (SpriteRenderer sr in spriteRenderers)
|
|
{
|
|
materials.Add(sr.material);
|
|
}
|
|
SetOutline(false);
|
|
|
|
animations = new SerializableDictionary<string, AnimationClip>();
|
|
|
|
foreach (KeyValuePair<string, AnimationClip> anim in character.data.animations)
|
|
{
|
|
animations.Add(anim.Key, anim.Value);
|
|
}
|
|
|
|
if (animations.TryGetValue("Idle", out AnimationClip idle))
|
|
{
|
|
animatorPlus2D.defaultIdleClip = idle;
|
|
animatorPlus2D.Initialize();
|
|
}
|
|
else
|
|
{
|
|
throw new Exception($"No Idle animation found for character {character.data.displayName}");
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class CombatCharacterViewBase
|
|
{
|
|
public void SetOutline(bool isEnabled)
|
|
{
|
|
if (isEnabled)
|
|
{
|
|
Color fractionColor = MainGameManager.Instance.basePrefabs.fractionColors[character.fraction];
|
|
materials.ForEach(material => material.SetFloat("_InnerOutlineFade", 1));
|
|
materials.ForEach(material => material.SetColor("_InnerOutlineColor", fractionColor * 2));
|
|
}
|
|
else
|
|
{
|
|
materials.ForEach(material => material.SetFloat("_InnerOutlineFade", 0));
|
|
materials.ForEach(material => material.SetColor("_InnerOutlineColor", Color.white));
|
|
}
|
|
}
|
|
}
|
|
} |