125 lines
3.4 KiB
C#
125 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace QFramework
|
|
{
|
|
internal class MatAction : IAction
|
|
{
|
|
|
|
public System.Action OnFinished { get; set; }
|
|
|
|
|
|
private MatAction()
|
|
{
|
|
}
|
|
|
|
private static readonly SimpleObjectPool<MatAction> mPool =
|
|
new SimpleObjectPool<MatAction>(() => new MatAction(), null, 10);
|
|
|
|
|
|
|
|
|
|
string value;
|
|
string deviceName;
|
|
string matName;
|
|
string index;
|
|
string mainTexture;
|
|
public static MatAction Allocate(Dictionary<string, string> datas, System.Action OnFinished = null)
|
|
{
|
|
var retNode = mPool.Allocate();
|
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
|
retNode.Deinited = false;
|
|
retNode.Reset();
|
|
retNode.value = datas.ContainsKey("value") ? datas["value"] : "";
|
|
retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : "";
|
|
retNode.matName = datas.ContainsKey("matName") ? datas["matName"] : "";
|
|
retNode.index = datas.ContainsKey("index") ? datas["index"] : "0";
|
|
retNode.mainTexture = datas.ContainsKey("mainTexture") ? datas["mainTexture"] : null;
|
|
retNode.OnFinished = OnFinished;
|
|
return retNode;
|
|
}
|
|
|
|
|
|
public ulong ActionID { get; set; }
|
|
public ActionStatus Status { get; set; }
|
|
|
|
public void OnStart()
|
|
{
|
|
GameObject obj;
|
|
if (string.IsNullOrEmpty(deviceName))
|
|
{
|
|
obj = Utility.FindObj(value);
|
|
}
|
|
else
|
|
{
|
|
obj = DeviceController.Instance.GetDeviceObj(deviceName);
|
|
}
|
|
var mesh = obj.GetComponent<Renderer>();
|
|
int matIndex = 0;
|
|
int.TryParse(index, out matIndex);
|
|
if (string.IsNullOrEmpty(matName) == false)
|
|
{
|
|
//mesh.materials[matIndex].CopyMatchingPropertiesFromMaterial();
|
|
var mat = Resources.Load<Material>("Mat/" + matName);
|
|
var mats = new Material[mesh.materials.Length];
|
|
for (int i = 0; i < mesh.materials.Length; i++)
|
|
{
|
|
if (i == matIndex)
|
|
{
|
|
mats[i] = mat;
|
|
}
|
|
else
|
|
{
|
|
mats[i] = mesh.materials[i];
|
|
}
|
|
}
|
|
|
|
mesh.materials = mats;
|
|
}
|
|
if (mainTexture != null)
|
|
{
|
|
if (mainTexture == "")
|
|
{
|
|
mesh.materials[matIndex].mainTexture = null;
|
|
}
|
|
else
|
|
{
|
|
mesh.materials[matIndex].mainTexture = Resources.Load<Texture>("Mat/" + mainTexture);
|
|
}
|
|
}
|
|
|
|
this.Finish();
|
|
}
|
|
|
|
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;
|
|
mPool.Recycle(this);
|
|
}
|
|
}
|
|
|
|
public bool Deinited { get; set; }
|
|
}
|
|
|
|
|
|
} |