104 lines
2.8 KiB
C#
104 lines
2.8 KiB
C#
|
|
using QFramework.Example;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using static UnityEditor.Progress;
|
||
|
|
|
||
|
|
namespace QFramework
|
||
|
|
{
|
||
|
|
internal class LineAction : IAction
|
||
|
|
{
|
||
|
|
ResLoader loader;
|
||
|
|
public System.Action OnFinished { get; set; }
|
||
|
|
|
||
|
|
|
||
|
|
private LineAction()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
private static readonly SimpleObjectPool<LineAction> mPool =
|
||
|
|
new SimpleObjectPool<LineAction>(() => new LineAction(), null, 10);
|
||
|
|
|
||
|
|
public string paths;
|
||
|
|
public string name;
|
||
|
|
Color color = Color.green;
|
||
|
|
public static LineAction Allocate(string name, string paths, string color, System.Action OnFinished = null)
|
||
|
|
{
|
||
|
|
var retNode = mPool.Allocate();
|
||
|
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
||
|
|
retNode.Deinited = false;
|
||
|
|
retNode.Reset();
|
||
|
|
retNode.paths = paths;
|
||
|
|
retNode.name = name;
|
||
|
|
if (string.IsNullOrEmpty(color) == false)
|
||
|
|
{
|
||
|
|
retNode.color = Utility.ToColor(color);
|
||
|
|
}
|
||
|
|
retNode.OnFinished = OnFinished;
|
||
|
|
return retNode;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public ulong ActionID { get; set; }
|
||
|
|
public ActionStatus Status { get; set; }
|
||
|
|
|
||
|
|
public void OnStart()
|
||
|
|
{
|
||
|
|
loader = ResLoader.Allocate();
|
||
|
|
loader.Add2Load(QAssetBundle.Line_prefab.LINE, (success, res) =>
|
||
|
|
{
|
||
|
|
if (success)
|
||
|
|
{
|
||
|
|
GameObject obj = GameObject.Instantiate(res.Asset.As<GameObject>());
|
||
|
|
|
||
|
|
obj.name = name;
|
||
|
|
var render = obj.GetOrAddComponent<LineRenderer>();
|
||
|
|
render.material.color = color;
|
||
|
|
var pathsArr = paths.Split('|');
|
||
|
|
for (int i = 0; i < pathsArr.Length; i++)
|
||
|
|
{
|
||
|
|
Vector3 point = Utility.GetVector3FromStrArray(pathsArr[i]);
|
||
|
|
render.positionCount += 1;
|
||
|
|
render.SetPosition(i, point);
|
||
|
|
}
|
||
|
|
obj.GetOrAddComponent<LineRendererToMesh>().BakeMesh();
|
||
|
|
|
||
|
|
}
|
||
|
|
this.Finish();
|
||
|
|
});
|
||
|
|
loader.LoadAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnExecute(float dt)
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnFinish()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Reset()
|
||
|
|
{
|
||
|
|
Status = ActionStatus.NotStart;
|
||
|
|
Paused = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool Paused { get; set; }
|
||
|
|
|
||
|
|
public void Deinit()
|
||
|
|
{
|
||
|
|
if (!Deinited)
|
||
|
|
{
|
||
|
|
OnFinished = null;
|
||
|
|
Deinited = true;
|
||
|
|
loader.Recycle2Cache();
|
||
|
|
mPool.Recycle(this);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool Deinited { get; set; }
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|