273 lines
8.5 KiB
C#
273 lines
8.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SettingsMain : MonoBehaviourSingletonTemplate<SettingsMain>
|
|
{
|
|
public GameObject go_Tables, go_Edit, go_event;
|
|
public SettingsSelectPopup m_SettingsSelectPopup;
|
|
public Image[] btns_anim; // 0 Idle ~
|
|
public Slider slider;
|
|
public TextMeshProUGUI label_frame, label_runrepeat;
|
|
public TMP_InputField Input_speed;
|
|
|
|
Actor m_Actor;
|
|
float AnimSpeed;
|
|
string CurAnimName;
|
|
bool bcomboattack, run_repeat, runAnimOnce = false;
|
|
List<AnimEventData> list_AED = new List<AnimEventData>();
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
DSUtil.Get_Clone(go_Tables);
|
|
Application.targetFrameRate = 60;
|
|
label_runrepeat.text = "재생하기";
|
|
AnimSpeed = 1f;
|
|
}
|
|
|
|
public void OnSliderValueChange()
|
|
{
|
|
if (!run_repeat && m_Actor)
|
|
{
|
|
m_Actor.m_animation.Play(CurAnimName, 0, slider.value);
|
|
Set_FrameInfo(slider.value);
|
|
}
|
|
}
|
|
|
|
public void SelectObj(ClassConfigTableData pcdata, MonsterTableData mobdata)
|
|
{
|
|
m_SettingsSelectPopup.OnClick_Back();
|
|
go_Edit.SetActive(true);
|
|
|
|
if (m_Actor) Destroy(m_Actor.gameObject);
|
|
|
|
if (pcdata != null)
|
|
{
|
|
AddrResourceMgr.Ins.LoadObject<GameObject>("Assets/Res_Addr/PC/MainPC.prefab", handle =>
|
|
{
|
|
m_Actor = DSUtil.Get_Clone<Actor>(handle.Result);
|
|
m_Actor.Set(false, null, new ServerData(), pcdata.n_ClassID, false);
|
|
m_Actor.transform.eulerAngles = Vector3.up * 90f;
|
|
|
|
var go = new GameObject("idle");
|
|
OnClick_Anim(go);
|
|
Destroy(go);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
m_Actor = DSUtil.Get_Clone<Actor>(DSUtil.Format("Mobs/Monster/{0}", mobdata.s_MonsterPrefab));
|
|
(m_Actor as MobActor).Set_NoUpdate_byTool(mobdata);
|
|
}
|
|
}
|
|
|
|
public void OnClick_ObjSelect()
|
|
{
|
|
m_SettingsSelectPopup.Set();
|
|
}
|
|
|
|
public void OnSubmit_Speed()
|
|
{
|
|
float.TryParse(Input_speed.text, out AnimSpeed);
|
|
if (m_Actor) m_Actor.m_animation.speed = AnimSpeed;
|
|
}
|
|
|
|
public void OnClick_Anim(GameObject go)
|
|
{
|
|
Refresh_Common();
|
|
Run_Anim(go.name);
|
|
}
|
|
void Run_Anim(string aniname, bool resetpos = true)
|
|
{
|
|
for (int i = 0; i < btns_anim.Length; i++)
|
|
btns_anim[i].color = Color.white;
|
|
|
|
m_Actor.Init_CurAnim(resetpos);
|
|
CurAnimName = aniname;
|
|
switch (aniname)
|
|
{
|
|
case "idle":
|
|
m_Actor.Play_Idle();
|
|
btns_anim[0].color = Color.gray;
|
|
break;
|
|
case "run":
|
|
m_Actor.Play_Run();
|
|
btns_anim[1].color = Color.gray;
|
|
break;
|
|
case "hit":
|
|
m_Actor.Play_Hit();
|
|
btns_anim[2].color = Color.gray;
|
|
break;
|
|
case "die":
|
|
m_Actor.Play_Die();
|
|
btns_anim[3].color = Color.gray;
|
|
break;
|
|
case "attack":
|
|
m_Actor.Play_Attack(0, 1f);
|
|
btns_anim[4].color = Color.gray;
|
|
break;
|
|
case "attack2":
|
|
m_Actor.Play_Attack(1, 1f);
|
|
btns_anim[5].color = Color.gray;
|
|
break;
|
|
case "attack3":
|
|
m_Actor.Play_Attack(2, 1f);
|
|
btns_anim[6].color = Color.gray;
|
|
break;
|
|
case "skill1":
|
|
m_Actor.Play_Skill(aniname);
|
|
btns_anim[7].color = Color.gray;
|
|
break;
|
|
case "skill2":
|
|
m_Actor.Play_Skill(aniname);
|
|
btns_anim[8].color = Color.gray;
|
|
break;
|
|
case "comboattack":
|
|
bcomboattack = true;
|
|
m_Actor.Play_Attack(0, 1f);
|
|
btns_anim[9].color = Color.gray;
|
|
break;
|
|
case "dodge":
|
|
m_Actor.Play_Dodge();
|
|
btns_anim[10].color = Color.gray;
|
|
break;
|
|
case "stun":
|
|
m_Actor.AnimationPlay("stun");
|
|
btns_anim[11].color = Color.gray;
|
|
break;
|
|
}
|
|
|
|
m_Actor.m_animation.speed = run_repeat ? AnimSpeed : 0f;
|
|
Set_FrameInfo();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (run_repeat && m_Actor)
|
|
{
|
|
var curState = m_Actor.m_animation.GetCurrentAnimatorStateInfo(0);
|
|
if (!curState.IsName(CurAnimName))
|
|
{
|
|
if (bcomboattack)
|
|
{
|
|
if (CurAnimName.Equals("comboattack"))
|
|
Run_Anim("attack1");
|
|
else
|
|
Run_Anim(CurAnimName, false);
|
|
}
|
|
else
|
|
Run_Anim(CurAnimName);
|
|
|
|
return;
|
|
}
|
|
|
|
Set_FrameInfo();
|
|
}
|
|
}
|
|
|
|
List<int> list_frame = new List<int> { 0, 0 }; // [현재 프레임, 총 프레임]
|
|
List<int> Get_Frame(float normaltime = -1f)
|
|
{
|
|
list_frame[0] = list_frame[1] = 0;
|
|
|
|
var curState = m_Actor.m_animation.GetCurrentAnimatorStateInfo(0);
|
|
|
|
// 애니메이션 클립 배열 확인
|
|
var clips = m_Actor.m_animation.GetCurrentAnimatorClipInfo(0);
|
|
if (clips.Length == 0) return list_frame; // 배열이 비어 있으면 함수 종료
|
|
|
|
var currentClip = clips[0].clip;
|
|
|
|
// 전체 프레임 수 계산
|
|
list_frame[1] = Mathf.RoundToInt(currentClip.frameRate * currentClip.length);
|
|
|
|
// 현재 normalizedTime 계산
|
|
float normalizedTime = normaltime < 0f ? curState.normalizedTime % 1 : normaltime;
|
|
|
|
// 현재 프레임 계산
|
|
list_frame[0] = (int)(normalizedTime * list_frame[1]);
|
|
|
|
// 애니메이션 완료 체크
|
|
if (!runAnimOnce && normalizedTime >= 0.9f)
|
|
runAnimOnce = true;
|
|
|
|
if (bcomboattack)
|
|
{
|
|
if (curState.IsName("attack") && normalizedTime >= 0.9f)
|
|
CurAnimName = "attack2";
|
|
else if (curState.IsName("attack2") && normalizedTime >= 0.9f)
|
|
CurAnimName = "attack3";
|
|
else if (curState.IsName("attack3") && normalizedTime >= 0.9f)
|
|
CurAnimName = "attack";
|
|
}
|
|
|
|
return list_frame;
|
|
}
|
|
void Set_FrameInfo(float normaltime = -1f)
|
|
{
|
|
var frames = Get_Frame(normaltime);
|
|
if (frames.Count > 1 && frames[1] != 0) // 배열 길이와 분모가 0이 아닌지 확인
|
|
slider.value = (float)frames[0] / frames[1];
|
|
else
|
|
slider.value = 0f; // 또는 다른 기본값을 설정할 수 있습니다.
|
|
|
|
|
|
var curState = m_Actor.m_animation.GetCurrentAnimatorStateInfo(0);
|
|
var curtime = curState.normalizedTime % 1;
|
|
|
|
label_frame.text = DSUtil.Format("{0}/{1}\n{2}", frames[0], frames[1], curtime.ToString("N2"));
|
|
}
|
|
|
|
void Refresh_Common()
|
|
{
|
|
list_AED.ForEach(f => Destroy(f.gameObject));
|
|
list_AED.Clear();
|
|
bcomboattack = runAnimOnce = false;
|
|
}
|
|
|
|
public void OnClick_RunRepeat()
|
|
{
|
|
run_repeat = !run_repeat;
|
|
m_Actor.m_animation.speed = run_repeat ? AnimSpeed : 0f;
|
|
label_runrepeat.text = run_repeat ? "재생중" : "재생하기";
|
|
}
|
|
public void OnClick_Refresh()
|
|
{
|
|
Refresh_Common();
|
|
Run_Anim(CurAnimName);
|
|
}
|
|
|
|
public void Add_Event(string eventName, int index = 0, int a = 0, float b = 0f, string c = "")
|
|
{
|
|
// index 가 0 이면 매개변수 없음
|
|
// index 가 1 이면 int 매개변수
|
|
// index 가 2 이면 float 매개변수
|
|
// index 가 3 이면 string 매개변수
|
|
|
|
if (!runAnimOnce)
|
|
{
|
|
var frames = Get_Frame();
|
|
var mark = DSUtil.Get_Clone<AnimEventData>(go_event, slider.transform, slider.handleRect.localPosition);
|
|
list_AED.Add(mark);
|
|
switch (index)
|
|
{
|
|
case 0:
|
|
mark.Set_Data(frames[0], eventName);
|
|
break;
|
|
case 1:
|
|
mark.Set_Data(frames[0], eventName, a);
|
|
break;
|
|
case 2:
|
|
mark.Set_Data(frames[0], eventName, b);
|
|
break;
|
|
case 3:
|
|
mark.Set_Data(frames[0], eventName, c);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |