VirtualFramework/Assets/Scripts/Actions/SkinnedBakeAction.cs

82 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QFramework;
using System;
using QFramework.Example;
using DG.Tweening;
using System.ComponentModel.Design;
public class SkinnedBakeAction : IAction
{
public ulong ActionID { get; set; }
public bool Deinited { get; set; }
public bool Paused { get; set; }
public ActionStatus Status { get; set; }
private static readonly SimpleObjectPool<SkinnedBakeAction> mPool =
new SimpleObjectPool<SkinnedBakeAction>(() => new SkinnedBakeAction(), null, 10);
string path;
string deviceName;
public static SkinnedBakeAction Allocate(string path, Dictionary<string, string> datas, System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.path = path;
retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : string.Empty;
return retNode;
}
public void Deinit()
{
if (!Deinited)
{
Deinited = true;
mPool.Recycle(this);
}
}
public void OnExecute(float dt)
{
}
public void OnFinish()
{
}
public void OnStart()
{
GameObject obj = null;
if (string.IsNullOrEmpty(deviceName) == false)
{
obj = DeviceController.Instance.GetDeviceObj(deviceName);
}
else
{
obj = Utility.FindObj(path);
}
if (obj == null)
{
Debug.LogError("ûÓÐÕÒµ½ÎïÌå :" + path);
}
else
{
Mesh mesh = new Mesh();
obj.GetComponent<SkinnedMeshRenderer>().BakeMesh(mesh);
obj.GetComponent<MeshCollider>().sharedMesh = mesh;
}
this.Finish();
}
public void Reset()
{
Status = ActionStatus.NotStart;
Paused = false;
}
}