115 lines
3.5 KiB
C#
115 lines
3.5 KiB
C#
|
using Thousandto.Code.Logic;
|
|||
|
using Thousandto.Core.Asset;
|
|||
|
using Thousandto.SkillEditor;
|
|||
|
using Thousandto.SkillEditor.DIY;
|
|||
|
using Thousandto.SkillEditor.Support;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.SkillEditor.DIY
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 简单技能召唤物
|
|||
|
/// </summary>
|
|||
|
public class EditorSimpleSkillObject : EditorBaseObject
|
|||
|
{
|
|||
|
public EditorEntity Owner { get; private set; }
|
|||
|
public PlaySimpleSkillObjectEventInfo EventInfo { get; private set; }
|
|||
|
public EditorVFXScript Vfx { get; private set; }
|
|||
|
public bool IsFinish { get; private set; }
|
|||
|
public int CurFrame { get; private set; }
|
|||
|
private float _frameTimer = 0f;
|
|||
|
private int _curHitCount = 0;
|
|||
|
private const float OneFrameTime = 1f / 30f;
|
|||
|
|
|||
|
public EditorSimpleSkillObject(EditorEntity owner, PlaySimpleSkillObjectEventInfo eventInfo) :
|
|||
|
base(new GameObject("[SimpleSkillObject]"), EditorObjType.SkillSimpleObj)
|
|||
|
{
|
|||
|
Owner = owner;
|
|||
|
EventInfo = eventInfo;
|
|||
|
}
|
|||
|
|
|||
|
public void Start()
|
|||
|
{
|
|||
|
var vfxPath = AssetUtils.GetModelAssetPath(ModelTypeCode.SkillVFX, EventInfo.VfxID);
|
|||
|
Vfx = EditorVFXPlayer.Instance.PlayVFX(vfxPath, RootTrans);
|
|||
|
var pos = Vector3.zero;
|
|||
|
if(EventInfo.PosType == 0)
|
|||
|
{
|
|||
|
pos = Owner.Position;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var target = SkillEditorScene.FindMainTarget(Owner);
|
|||
|
if(target != null )
|
|||
|
{
|
|||
|
if(Vector3.SqrMagnitude(target.Position - Owner.Position) <= EventInfo.MaxDis * EventInfo.MaxDis)
|
|||
|
{
|
|||
|
pos = target.Position;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var dir = (target.Position - Owner.Position);
|
|||
|
dir.y = 0f;
|
|||
|
pos = Owner.Position + dir.normalized * EventInfo.MaxDis;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pos = Owner.Position + Owner.RootTrans.forward * EventInfo.MaxDis;
|
|||
|
}
|
|||
|
}
|
|||
|
pos.y = 0f;
|
|||
|
RootTrans.position = pos;
|
|||
|
CurFrame = 0;
|
|||
|
_frameTimer = 0f;
|
|||
|
_curHitCount = 0;
|
|||
|
IsFinish = false;
|
|||
|
CheckHitEvent(CurFrame);
|
|||
|
}
|
|||
|
|
|||
|
private void CheckHitEvent(int frame)
|
|||
|
{
|
|||
|
if((CurFrame >= EventInfo.StartHitFrame && (CurFrame - EventInfo.StartHitFrame) % EventInfo.HitInterval == 0) && _curHitCount < EventInfo.HitCount)
|
|||
|
{
|
|||
|
SkillEditorScene.PlayHitEvent(this);
|
|||
|
AddWarningField(EventInfo.FindInfo);
|
|||
|
++_curHitCount;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Stop()
|
|||
|
{
|
|||
|
if(Vfx != null)
|
|||
|
{
|
|||
|
Vfx.Stop();
|
|||
|
}
|
|||
|
GameObject.DestroyImmediate(RootGo);
|
|||
|
IsFinish = true;
|
|||
|
}
|
|||
|
|
|||
|
public void Update(float dt)
|
|||
|
{
|
|||
|
_frameTimer += dt;
|
|||
|
if (IsFinish)
|
|||
|
return;
|
|||
|
_frameTimer += dt;
|
|||
|
while (_frameTimer >= OneFrameTime)
|
|||
|
{
|
|||
|
++CurFrame;
|
|||
|
CheckHitEvent(CurFrame);
|
|||
|
_frameTimer -= OneFrameTime;
|
|||
|
}
|
|||
|
|
|||
|
if (CurFrame >= EventInfo.LifeFrame)
|
|||
|
{
|
|||
|
Stop();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|