Make frame properties animatable.
This commit is contained in:
@@ -52,9 +52,9 @@ namespace Cryville.Crtr.Components {
|
|||||||
static readonly ArrayPool<Vector2> _shapePool = new ArrayPool<Vector2>(0x100, 0x10000);
|
static readonly ArrayPool<Vector2> _shapePool = new ArrayPool<Vector2>(0x100, 0x10000);
|
||||||
|
|
||||||
public PolygonSGO() {
|
public PolygonSGO() {
|
||||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
SubmitProperty("head", new PropOp.String(v => head.FrameName = v), 2);
|
||||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
SubmitProperty("body", new PropOp.String(v => body.FrameName = v), 2);
|
||||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v), 2);
|
||||||
SubmitProperty("shape", new op_set_shape(this), 2);
|
SubmitProperty("shape", new op_set_shape(this), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,18 +98,13 @@ namespace Cryville.Crtr.Components {
|
|||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
base.Init();
|
base.Init();
|
||||||
|
|
||||||
head.Load();
|
|
||||||
body.Load();
|
|
||||||
tail.Load();
|
|
||||||
|
|
||||||
mesh.Init(transform);
|
mesh.Init(transform);
|
||||||
|
|
||||||
List<Material> materials = new List<Material>();
|
var mats = mesh.Renderer.materials = new Material[] { mesh.NewMaterial, mesh.NewMaterial, mesh.NewMaterial };
|
||||||
if (head.FrameName != null) AddMat(materials, head.FrameName);
|
head.Bind(mats[0]);
|
||||||
if (body.FrameName != null) AddMat(materials, body.FrameName);
|
body.Bind(mats[1]);
|
||||||
if (tail.FrameName != null) AddMat(materials, tail.FrameName);
|
tail.Bind(mats[2]);
|
||||||
mesh.Renderer.materials = materials.ToArray();
|
|
||||||
UpdateZIndex();
|
UpdateZIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +152,9 @@ namespace Cryville.Crtr.Components {
|
|||||||
int vcpsec = _shapeLength; // Vertex Count Per Section
|
int vcpsec = _shapeLength; // Vertex Count Per Section
|
||||||
float width = GetWidth();
|
float width = GetWidth();
|
||||||
float headLength = 0;
|
float headLength = 0;
|
||||||
if (head.FrameName != null) headLength = width / head.Ratio;
|
if (head.Frame != null) headLength = width / head.Ratio;
|
||||||
float tailLength = 0;
|
float tailLength = 0;
|
||||||
if (tail.FrameName != null) tailLength = width / tail.Ratio;
|
if (tail.Frame != null) tailLength = width / tail.Ratio;
|
||||||
float endLength = headLength + tailLength;
|
float endLength = headLength + tailLength;
|
||||||
if (sumLength <= endLength) {
|
if (sumLength <= endLength) {
|
||||||
// The total length of the two ends is longer than the whole mesh, squeeze the two ends
|
// The total length of the two ends is longer than the whole mesh, squeeze the two ends
|
||||||
@@ -187,17 +182,17 @@ namespace Cryville.Crtr.Components {
|
|||||||
verts = _vertPool.Rent(vc * vcpsec);
|
verts = _vertPool.Rent(vc * vcpsec);
|
||||||
uvs = _uvPool.Rent(vc * vcpsec);
|
uvs = _uvPool.Rent(vc * vcpsec);
|
||||||
int i = 0; int t = 0; float l = 0; int m = 0;
|
int i = 0; int t = 0; float l = 0; int m = 0;
|
||||||
if (head.FrameName != null) { m++; GenerateMeshTo(verts, uvs, out trih, head, ref i, ref t, ref l, 0, headLength, vcpsec, hvc); }
|
if (head.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trih, head, ref i, ref t, ref l, 0, headLength, vcpsec, hvc); }
|
||||||
if (body.FrameName != null) { m++; GenerateMeshTo(verts, uvs, out trib, body, ref i, ref t, ref l, headLength, sumLength - tailLength, vcpsec, hvc + bvc); }
|
if (body.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trib, body, ref i, ref t, ref l, headLength, sumLength - tailLength, vcpsec, hvc + bvc); }
|
||||||
if (tail.FrameName != null) { m++; GenerateMeshTo(verts, uvs, out trit, tail, ref i, ref t, ref l, sumLength - tailLength, sumLength, vcpsec, vc); }
|
if (tail.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trit, tail, ref i, ref t, ref l, sumLength - tailLength, sumLength, vcpsec, vc); }
|
||||||
|
|
||||||
mesh.Mesh.subMeshCount = m;
|
mesh.Mesh.subMeshCount = m;
|
||||||
m = 0;
|
m = 0;
|
||||||
mesh.Mesh.SetVertices(verts);
|
mesh.Mesh.SetVertices(verts);
|
||||||
mesh.Mesh.SetUVs(0, uvs);
|
mesh.Mesh.SetUVs(0, uvs);
|
||||||
if (head.FrameName != null) mesh.Mesh.SetTriangles(trih, m++);
|
if (head.Frame != null) mesh.Mesh.SetTriangles(trih, m++);
|
||||||
if (body.FrameName != null) mesh.Mesh.SetTriangles(trib, m++);
|
if (body.Frame != null) mesh.Mesh.SetTriangles(trib, m++);
|
||||||
if (tail.FrameName != null) mesh.Mesh.SetTriangles(trit, m++);
|
if (tail.Frame != null) mesh.Mesh.SetTriangles(trit, m++);
|
||||||
mesh.Mesh.RecalculateNormals();
|
mesh.Mesh.RecalculateNormals();
|
||||||
|
|
||||||
_vertPool.Return(verts); verts = null;
|
_vertPool.Return(verts); verts = null;
|
||||||
|
@@ -4,7 +4,16 @@ using Logger = Cryville.Common.Logger;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public class SpriteInfo {
|
public class SpriteInfo {
|
||||||
public string FrameName;
|
string m_frameName;
|
||||||
|
public string FrameName {
|
||||||
|
get {
|
||||||
|
return m_frameName;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
m_frameName = value;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
public SpriteFrame Frame {
|
public SpriteFrame Frame {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
@@ -20,21 +29,38 @@ namespace Cryville.Crtr.Components {
|
|||||||
return Rect.width / Rect.height;
|
return Rect.width / Rect.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool _loaded;
|
||||||
|
Material _mat;
|
||||||
|
public void Bind(Material mat) {
|
||||||
|
_loaded = true;
|
||||||
|
_mat = mat;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
public void Load() {
|
public void Load() {
|
||||||
if (FrameName != null) {
|
_loaded = true;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
public void Reload() {
|
||||||
|
if (!_loaded) return;
|
||||||
|
if (!string.IsNullOrEmpty(FrameName)) {
|
||||||
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
||||||
Frame = ChartPlayer.frames[FrameName];
|
Frame = ChartPlayer.frames[FrameName];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.Log("main", 4, "Skin", "Texture {0} not found", FrameName);
|
Logger.Log("main", 4, "Skin", "Texture {0} not found", FrameName);
|
||||||
|
Frame = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else Frame = null;
|
||||||
|
if (_mat != null) {
|
||||||
|
_mat.mainTexture = Frame == null ? null : Frame.Texture;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SpritePlane : SpriteBase {
|
public class SpritePlane : SpriteBase {
|
||||||
public SpritePlane() {
|
public SpritePlane() {
|
||||||
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
SubmitProperty("frame", new PropOp.String(v => Frame = v), 2);
|
||||||
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v));
|
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v));
|
||||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||||
}
|
}
|
||||||
@@ -68,16 +94,11 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
protected void OnFrameUpdate() {
|
protected void OnFrameUpdate() {
|
||||||
if (!mesh.Initialized) return;
|
if (!mesh.Initialized) return;
|
||||||
if (frameInfo.FrameName == null) {
|
if (frameInfo.Frame == null) {
|
||||||
mesh.Renderer.enabled = false;
|
mesh.Renderer.enabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mesh.Renderer.enabled = true;
|
mesh.Renderer.enabled = true;
|
||||||
frameInfo.Load();
|
|
||||||
if (frameInfo.Frame != null)
|
|
||||||
mesh.Renderer.material.mainTexture = frameInfo.Frame.Texture;
|
|
||||||
else
|
|
||||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
|
||||||
UpdateUV();
|
UpdateUV();
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
UpdateZIndex();
|
UpdateZIndex();
|
||||||
@@ -140,8 +161,8 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
frameInfo.Load();
|
|
||||||
InternalInit();
|
InternalInit();
|
||||||
|
frameInfo.Bind(mesh.Renderer.material);
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
UpdateOpacity();
|
UpdateOpacity();
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ namespace Cryville.Crtr {
|
|||||||
MeshObject.AddComponent<MeshRenderer>();
|
MeshObject.AddComponent<MeshRenderer>();
|
||||||
MeshFilter = MeshObject.GetComponent<MeshFilter>();
|
MeshFilter = MeshObject.GetComponent<MeshFilter>();
|
||||||
Renderer = MeshObject.GetComponent<Renderer>();
|
Renderer = MeshObject.GetComponent<Renderer>();
|
||||||
Renderer.material = GenericResources.Materials["-SpriteMat"];
|
Renderer.material = NewMaterial;
|
||||||
Initialized = true;
|
Initialized = true;
|
||||||
}
|
}
|
||||||
public void Destroy() {
|
public void Destroy() {
|
||||||
|
Reference in New Issue
Block a user