Add project files.
This commit is contained in:
291
Assets/Cryville/Crtr/Components/SectionalGameObject.cs
Normal file
291
Assets/Cryville/Crtr/Components/SectionalGameObject.cs
Normal file
@@ -0,0 +1,291 @@
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Common.Pdt;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public abstract class SectionalGameObject : SkinComponent {
|
||||
protected bool headGenerated;
|
||||
protected Vector3 prevpt;
|
||||
protected int vertCount = 0;
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void AppendPoint(Vector3 p) {
|
||||
AppendPoint(p, Quaternion.identity);
|
||||
}
|
||||
|
||||
public void AppendPoint(Vector3 p, Quaternion r) {
|
||||
AppendPointInternal(p, r);
|
||||
// if (!headGenerated) Logger.Log("main", 0, "Skin/Polysec", "{0}", r);
|
||||
headGenerated = true;
|
||||
prevpt = p;
|
||||
vertCount++;
|
||||
}
|
||||
|
||||
protected abstract void AppendPointInternal(Vector3 wp, Quaternion r);
|
||||
|
||||
public abstract void Seal();
|
||||
|
||||
public virtual void Reset() {
|
||||
vertCount = 0;
|
||||
headGenerated = false;
|
||||
}
|
||||
}
|
||||
|
||||
public class PolygonSGO : SectionalGameObject {
|
||||
static readonly SimpleObjectPool<List<Vector3>> _ptPool = new SimpleObjectPool<List<Vector3>>(1024);
|
||||
static readonly SimpleObjectPool<List<float>> _lPool = new SimpleObjectPool<List<float>>(1024);
|
||||
|
||||
static readonly ListPool<int> _indexPool = new ListPool<int>();
|
||||
static readonly ListPool<Vector3> _vertPool = new ListPool<Vector3>();
|
||||
static readonly ListPool<Vector2> _uvPool = new ListPool<Vector2>();
|
||||
static readonly ArrayPool<Vector2> _shapePool = new ArrayPool<Vector2>(0x100, 0x10000);
|
||||
|
||||
public PolygonSGO()
|
||||
: base() {
|
||||
/*
|
||||
SubmitProperty("head", new Property(typeof(string), () => head.frame, v => head.frame = (string)v));
|
||||
SubmitProperty("body", new Property(typeof(string), () => body.frame, v => body.frame = (string)v));
|
||||
SubmitProperty("tail", new Property(typeof(string), () => tail.frame, v => tail.frame = (string)v));
|
||||
SubmitProperty("transparent", new Property(typeof(bool), () => transparent, v => transparent = (bool)v));
|
||||
SubmitProperty("shape", new Property(typeof(Vector2[]), () => _shape, v => _shape = (Vector2[])v));
|
||||
*/
|
||||
|
||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
||||
SubmitProperty("transparent", new PropOp.Boolean(v => transparent = v));
|
||||
SubmitProperty("shape", new op_set_shape(this));
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public class op_set_shape : PdtOperator {
|
||||
readonly PolygonSGO _self;
|
||||
public op_set_shape(PolygonSGO self) : base(1) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
var o = GetOperand(0);
|
||||
if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector");
|
||||
_self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2);
|
||||
var ptr = (Vector2*)o.TrustedAsOfLength(sizeof(Vector2));
|
||||
if (_self._shape != null) _shapePool.Return(_self._shape);
|
||||
_self._shape = _shapePool.Rent(_self._shapeLength);
|
||||
for (int i = 0; i < _self._shapeLength; i++) {
|
||||
_self._shape[i] = ptr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
int _shapeLength = 0;
|
||||
Vector2[] _shape = null;
|
||||
float GetWidth() {
|
||||
float r = 0;
|
||||
for (int i = 1; i < _shapeLength; i++) {
|
||||
r += (_shape[i] - _shape[i-1]).magnitude;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public SpriteInfo head = new SpriteInfo();
|
||||
public SpriteInfo body = new SpriteInfo();
|
||||
public SpriteInfo tail = new SpriteInfo();
|
||||
|
||||
public bool transparent;
|
||||
List<Vector3> vertices;
|
||||
List<float> lengths;
|
||||
float sumLength = 0;
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
|
||||
head.Load();
|
||||
body.Load();
|
||||
tail.Load();
|
||||
|
||||
mesh.Init(transform, transparent);
|
||||
|
||||
List<Material> materials = new List<Material>();
|
||||
if (head.FrameName != null) AddMat(materials, head.FrameName);
|
||||
if (body.FrameName != null) AddMat(materials, body.FrameName);
|
||||
if (tail.FrameName != null) AddMat(materials, tail.FrameName);
|
||||
mesh.Renderer.materials = materials.ToArray();
|
||||
}
|
||||
|
||||
void AddMat(List<Material> list, string frame) {
|
||||
var mat = mesh.NewMaterial;
|
||||
mat.mainTexture = ChartPlayer.frames[frame].Texture;
|
||||
list.Add(mat);
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
base.OnDestroy();
|
||||
Reset();
|
||||
foreach (var m in mesh.Renderer.materials) Material.Destroy(m);
|
||||
if (_shape != null) _shapePool.Return(_shape);
|
||||
if (vertices != null) {
|
||||
_ptPool.Return(vertices);
|
||||
_lPool.Return(lengths);
|
||||
}
|
||||
}
|
||||
|
||||
// Vector3 prevp = Vector3.zero;
|
||||
protected override void AppendPointInternal(Vector3 p, Quaternion r) {
|
||||
if (vertices == null) {
|
||||
vertices = _ptPool.Rent();
|
||||
lengths = _lPool.Rent();
|
||||
}
|
||||
|
||||
/*
|
||||
r = new Vector3(0, 0, 0);
|
||||
|
||||
Quaternion rotq = Quaternion.Euler(r);
|
||||
p = prevp + rotq * (p - prevpt);
|
||||
prevp = p;*/
|
||||
|
||||
for (int i = 0; i < _shapeLength; i++) {
|
||||
Vector2 sp = r * _shape[i];
|
||||
vertices.Add(p + (Vector3)sp);
|
||||
// uv.Add(new Vector2(i / (shape.Length - 1), vertCount));
|
||||
}
|
||||
|
||||
if (headGenerated) {
|
||||
float len = (p - prevpt).magnitude;
|
||||
lengths.Add(len);
|
||||
sumLength += len;
|
||||
}
|
||||
}
|
||||
|
||||
List<Vector3> verts;
|
||||
List<Vector2> uvs;
|
||||
List<int> trih = null, trib = null, trit = null;
|
||||
|
||||
public override void Seal() {
|
||||
if (vertCount <= 1 || sumLength == 0) return;
|
||||
int vcpsec = _shapeLength; // Vertex Count Per Section
|
||||
float width = GetWidth();
|
||||
float headLength = 0;
|
||||
if (head.FrameName != null) headLength = width / head.Ratio;
|
||||
float tailLength = 0;
|
||||
if (tail.FrameName != null) tailLength = width / tail.Ratio;
|
||||
float endLength = headLength + tailLength;
|
||||
if (sumLength <= endLength) {
|
||||
// The total length of the two ends is longer than the whole mesh, squeeze the two ends
|
||||
float ratio = sumLength / endLength;
|
||||
headLength *= ratio;
|
||||
tailLength *= ratio;
|
||||
}
|
||||
|
||||
// Find the vertex counts needed for the three parts from the head
|
||||
float l0 = 0;
|
||||
int hvc = 0;
|
||||
for (; l0 < headLength && hvc < lengths.Count; hvc++)
|
||||
l0 += lengths[hvc];
|
||||
int bvc = 0;
|
||||
for (; l0 < sumLength - tailLength && hvc + bvc < lengths.Count; bvc++)
|
||||
l0 += lengths[hvc + bvc];
|
||||
int tvc = lengths.Count - hvc - bvc + 1;
|
||||
if (hvc > 0) {
|
||||
hvc++;
|
||||
bvc++;
|
||||
}
|
||||
bvc++;
|
||||
int vc = hvc + bvc + tvc;
|
||||
|
||||
verts = _vertPool.Rent(vc * vcpsec);
|
||||
uvs = _uvPool.Rent(vc * vcpsec);
|
||||
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 (body.FrameName != 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); }
|
||||
|
||||
mesh.Mesh.subMeshCount = m;
|
||||
m = 0;
|
||||
mesh.Mesh.SetVertices(verts);
|
||||
mesh.Mesh.SetUVs(0, uvs);
|
||||
if (head.FrameName != null) mesh.Mesh.SetTriangles(trih, m++);
|
||||
if (body.FrameName != null) mesh.Mesh.SetTriangles(trib, m++);
|
||||
if (tail.FrameName != null) mesh.Mesh.SetTriangles(trit, m++);
|
||||
mesh.Mesh.RecalculateNormals();
|
||||
|
||||
_vertPool.Return(verts); verts = null;
|
||||
_uvPool.Return(uvs); uvs = null;
|
||||
if (trih != null) { _indexPool.Return(trih); trih = null; }
|
||||
if (trib != null) { _indexPool.Return(trib); trib = null; }
|
||||
if (trit != null) { _indexPool.Return(trit); trit = null; }
|
||||
}
|
||||
|
||||
void GenerateMeshTo(List<Vector3> verts, List<Vector2> uvs, out List<int> tris, SpriteInfo info, ref int i, ref int t, ref float l, float startl, float endl, int vcpsec, int vend) {
|
||||
if (i >= lengths.Count) {
|
||||
tris = _indexPool.Rent(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int t0 = t;
|
||||
var frame = info.Frame;
|
||||
|
||||
if (startl != 0) {
|
||||
float pl2 = l - lengths[i - 1];
|
||||
float fr2 = (startl - pl2) / (l - pl2);
|
||||
for (int j = 0; j < vcpsec; j++, t++) {
|
||||
verts[t] =
|
||||
vertices[vcpsec*(i-1)+j] * (1-fr2)
|
||||
+ vertices[vcpsec*i+j] * fr2;
|
||||
var u = j / (vcpsec - 1);
|
||||
if (frame != null) uvs[t] = frame.GetUV(u, 0);
|
||||
}
|
||||
}
|
||||
for (; t / vcpsec < vend - 1; i++) {
|
||||
var v = (l - startl) / (endl - startl);
|
||||
for (int j = 0; j < vcpsec; j++, t++) {
|
||||
verts[t] = vertices[vcpsec*i+j];
|
||||
var u = j / (vcpsec - 1);
|
||||
if (frame != null) uvs[t] = frame.GetUV(u, v);
|
||||
}
|
||||
l += lengths[i];
|
||||
}
|
||||
float pl = l - lengths[i - 1];
|
||||
float fr = (endl - pl) / (l - pl);
|
||||
for (int j = 0; j < vcpsec; j++, t++) {
|
||||
verts[t] =
|
||||
vertices[vcpsec*(i-1)+j] * (1-fr)
|
||||
+ vertices[vcpsec*i+j] * fr;
|
||||
var u = j / (vcpsec - 1);
|
||||
if (frame != null) uvs[t] = frame.GetUV(u, 1);
|
||||
}
|
||||
|
||||
tris = _indexPool.Rent((vend - t0 / vcpsec - 1) * (vcpsec - 1) * 6);
|
||||
int i3 = 0;
|
||||
for (int i1 = t0 + vcpsec + 1; i1 < t; i1++) {
|
||||
if (i1 % vcpsec == 0) continue;
|
||||
int i2 = i1 - vcpsec;
|
||||
tris[i3++] = i1 - 1;
|
||||
tris[i3++] = i2;
|
||||
tris[i3++] = i2 - 1;
|
||||
tris[i3++] = i1 - 1;
|
||||
tris[i3++] = i1;
|
||||
tris[i3++] = i2;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset() {
|
||||
base.Reset();
|
||||
if (mesh.Initialized) mesh.Mesh.Clear();
|
||||
if (vertices != null) {
|
||||
vertices.Clear();
|
||||
lengths.Clear();
|
||||
}
|
||||
sumLength = 0;
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SectionalGameObject.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SectionalGameObject.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f2666d577419bd43aec55ad614a43f4
|
||||
timeCreated: 1596633346
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
76
Assets/Cryville/Crtr/Components/SkinComponent.cs
Normal file
76
Assets/Cryville/Crtr/Components/SkinComponent.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Cryville.Common.Pdt;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public abstract class SkinComponent : MonoBehaviour {
|
||||
#if false
|
||||
/// <summary>
|
||||
/// The properties of the component.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public Dictionary<string, Property> Properties { get; private set; }
|
||||
/// <summary>
|
||||
/// Submits a property.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="property">The property itself.</param>
|
||||
[Obsolete]
|
||||
protected void SubmitProperty(string name, Property property) {
|
||||
Properties.Add(name, property);
|
||||
}
|
||||
/// <summary>
|
||||
/// The property of a skin component.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public struct Property {
|
||||
/// <summary>
|
||||
/// The type of the property.
|
||||
/// </summary>
|
||||
public readonly Type Type;
|
||||
/// <summary>
|
||||
/// The callback that gets the property value.
|
||||
/// </summary>
|
||||
public readonly Func<object> Get;
|
||||
/// <summary>
|
||||
/// The callback that sets the property value.
|
||||
/// </summary>
|
||||
public readonly Action<object> Set;
|
||||
/// <summary>
|
||||
/// Creates a property.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the property.</param>
|
||||
/// <param name="get">The callback that gets the property value.</param>
|
||||
/// <param name="set">The callback that sets the property value.</param>
|
||||
public Property(Type type, Func<object> get, Action<object> set) {
|
||||
Type = type; Get = get; Set = set;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The property operators of the component.
|
||||
/// </summary>
|
||||
public Dictionary<string, PdtOperator> PropOps { get; private set; }
|
||||
/// <summary>
|
||||
/// Submits a property.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="property">The property operator.</param>
|
||||
protected void SubmitProperty(string name, PdtOperator property) {
|
||||
PropOps.Add(name, property);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a skin component
|
||||
/// </summary>
|
||||
protected SkinComponent() {
|
||||
// Properties = new Dictionary<string, Property>();
|
||||
PropOps = new Dictionary<string, PdtOperator>();
|
||||
}
|
||||
|
||||
public virtual void Init() { }
|
||||
protected abstract void OnDestroy();
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SkinComponent.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SkinComponent.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a54d8e3558a89f8499fc049afd84e959
|
||||
timeCreated: 1623576806
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
155
Assets/Cryville/Crtr/Components/SpriteBase.cs
Normal file
155
Assets/Cryville/Crtr/Components/SpriteBase.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
using Cryville.Common.Pdt;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public abstract class SpriteBase : SkinComponent {
|
||||
public SpriteBase()
|
||||
: base() {
|
||||
/*
|
||||
SubmitProperty("bound", new Property(typeof(BoundInfo), null, v => Bound = (BoundInfo)v));
|
||||
SubmitProperty("transparent", new Property(typeof(bool), () => transparent, v => transparent = (bool)v));
|
||||
SubmitProperty("pivot", new Property(typeof(Vector2), () => Pivot, v => Pivot = (Vector2)v));
|
||||
SubmitProperty("scale", new Property(typeof(Vector2), () => Scale, v => Scale = (Vector2)v));
|
||||
SubmitProperty("ui", new Property(typeof(bool), () => UI, v => UI = (bool)v));
|
||||
SubmitProperty("zindex", new Property(typeof(short), () => ZIndex, v => ZIndex = (short)v));
|
||||
*/
|
||||
|
||||
SubmitProperty("bound", new op_set_bound(this));
|
||||
SubmitProperty("transparent", new PropOp.Boolean(v => transparent = v));
|
||||
SubmitProperty("pivot", new PropOp.Vector2(v => Pivot = v));
|
||||
SubmitProperty("scale", new PropOp.Vector2(v => Scale = v));
|
||||
SubmitProperty("ui", new PropOp.Boolean(v => UI = v));
|
||||
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
class op_set_bound : PdtOperator {
|
||||
readonly SpriteBase _self;
|
||||
public op_set_bound(SpriteBase self) : base(2) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
_self.SetBound(
|
||||
*(Vector2*)GetOperand(0).TrustedAsOfLength(sizeof(Vector2)),
|
||||
*(Vector3*)GetOperand(1).TrustedAsOfLength(sizeof(Vector3))
|
||||
);
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
}
|
||||
|
||||
Vector2 _scale = Vector2.one;
|
||||
public Vector2 Scale {
|
||||
get { return _scale; }
|
||||
set {
|
||||
_scale = value;
|
||||
UpdateScale();
|
||||
}
|
||||
}
|
||||
protected virtual void UpdateScale() {
|
||||
if (!mesh.Initialized) return;
|
||||
var s = BaseScale;
|
||||
var ss = new Vector3(_scale.x, 1, _scale.y);
|
||||
s.Scale(ss);
|
||||
mesh.MeshTransform.localScale = s;
|
||||
OnPivotUpdate();
|
||||
}
|
||||
protected abstract Vector3 BaseScale {
|
||||
get;
|
||||
}
|
||||
protected virtual Vector3 BaseSize {
|
||||
get { return Vector3.one; }
|
||||
}
|
||||
|
||||
Vector2 _pivot;
|
||||
public Vector2 Pivot {
|
||||
get { return _pivot; }
|
||||
set {
|
||||
_pivot = value;
|
||||
OnPivotUpdate();
|
||||
}
|
||||
}
|
||||
protected void OnPivotUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
var r = new Vector3(_pivot.x - BasePivot.x, 0, _pivot.y - BasePivot.y);
|
||||
r.Scale(mesh.MeshTransform.localScale);
|
||||
r.Scale(BaseSize);
|
||||
mesh.MeshTransform.localPosition = -r;
|
||||
}
|
||||
protected virtual Vector2 BasePivot {
|
||||
get { return Vector2.zero; }
|
||||
}
|
||||
|
||||
#if false
|
||||
[Obsolete]
|
||||
public struct BoundInfo : IConstructable {
|
||||
public Vector2 Pivot;
|
||||
public Vector3 Position;
|
||||
public void Load(object data, IEvaluator etor) {
|
||||
var d = (IList)data;
|
||||
Pivot = (Vector2)etor.Cast(typeof(Vector2), d[0]);
|
||||
Position = (Vector3)etor.Cast(typeof(Vector3), d[1]);
|
||||
}
|
||||
}
|
||||
[Obsolete]
|
||||
public BoundInfo Bound {
|
||||
set {
|
||||
var r = Quaternion.Inverse(transform.rotation);
|
||||
var da = value.Pivot - Pivot;
|
||||
var dp = r * (value.Position - transform.localPosition);
|
||||
if (da.x != 0) _scale.x = dp.x / da.x;
|
||||
if (da.y != 0) _scale.y = dp.z / da.y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
public void SetBound(Vector2 piv, Vector3 pos) {
|
||||
var r = Quaternion.Inverse(transform.rotation);
|
||||
var da = piv - Pivot;
|
||||
var dp = r * (pos - transform.localPosition);
|
||||
if (da.x != 0) _scale.x = dp.x / da.x;
|
||||
if (da.y != 0) _scale.y = dp.z / da.y;
|
||||
}
|
||||
|
||||
short _zindex;
|
||||
public short ZIndex {
|
||||
get {
|
||||
return _zindex;
|
||||
}
|
||||
set {
|
||||
_zindex = value;
|
||||
UpdateZIndex();
|
||||
}
|
||||
}
|
||||
protected void UpdateZIndex() {
|
||||
if (!mesh.Initialized) return;
|
||||
mesh.Renderer.sortingOrder = _zindex;
|
||||
}
|
||||
|
||||
static readonly Quaternion uirot
|
||||
= Quaternion.Euler(new Vector3(-90, 0, 0));
|
||||
bool _ui;
|
||||
public bool UI {
|
||||
get { return _ui; }
|
||||
set {
|
||||
_ui = value;
|
||||
if (_ui) transform.localRotation = uirot;
|
||||
}
|
||||
}
|
||||
|
||||
public bool transparent = false;
|
||||
|
||||
protected void InternalInit(string meshName = "quad") {
|
||||
mesh.Init(transform, transparent);
|
||||
mesh.Mesh = GenericResources.Meshes[meshName];
|
||||
UpdateScale();
|
||||
UpdateZIndex();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SpriteBase.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SpriteBase.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 248ab93b20a0ac9439afaee32357ed5c
|
||||
timeCreated: 1614907140
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
156
Assets/Cryville/Crtr/Components/SpritePlane.cs
Normal file
156
Assets/Cryville/Crtr/Components/SpritePlane.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteInfo {
|
||||
public string FrameName;
|
||||
public Cocos2dFrames.Frame Frame {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Rect Rect {
|
||||
get { return Frame.frame; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The ratio of width divided by height.
|
||||
/// </summary>
|
||||
public float Ratio {
|
||||
get {
|
||||
return Rect.width / Rect.height;
|
||||
}
|
||||
}
|
||||
public void Load() {
|
||||
if (FrameName != null) {
|
||||
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
||||
Frame = ChartPlayer.frames[FrameName];
|
||||
}
|
||||
else {
|
||||
Logger.Log("main", 4, "Skin", "Texture {0} not found", FrameName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SpritePlane : SpriteBase {
|
||||
public SpritePlane()
|
||||
: base() {
|
||||
/*
|
||||
SubmitProperty("frame", new Property(typeof(string), () => Frame, v => Frame = (string)v));
|
||||
SubmitProperty("fit", new Property(typeof(FitMode), () => Fit, v => Fit = (FitMode)v));
|
||||
SubmitProperty("opacity", new Property(typeof(float), () => Opacity, v => Opacity = (float)v));
|
||||
*/
|
||||
|
||||
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
||||
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||
}
|
||||
|
||||
static Vector2[] _origuv;
|
||||
protected static Vector2[] OriginalUV {
|
||||
get {
|
||||
if (_origuv == null) {
|
||||
var m = GenericResources.Meshes["quad"];
|
||||
Vector2[] uv = new Vector2[m.vertices.Length];
|
||||
for (int i = 0; i < uv.Length; i++) {
|
||||
uv[i] = new Vector2(
|
||||
m.vertices[i].x == 0.5 ? 1 : 0,
|
||||
m.vertices[i].z == 0.5 ? 1 : 0
|
||||
);
|
||||
}
|
||||
_origuv = uv;
|
||||
}
|
||||
return _origuv;
|
||||
}
|
||||
}
|
||||
|
||||
protected SpriteInfo frameInfo = new SpriteInfo();
|
||||
|
||||
public string Frame {
|
||||
get { return frameInfo.FrameName; }
|
||||
set {
|
||||
frameInfo.FrameName = value;
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
protected void OnFrameUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
if (frameInfo.FrameName == null) {
|
||||
mesh.Renderer.enabled = false;
|
||||
return;
|
||||
}
|
||||
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();
|
||||
UpdateScale();
|
||||
UpdateZIndex();
|
||||
}
|
||||
protected virtual void UpdateUV() {
|
||||
if (frameInfo.Frame == null) {
|
||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
||||
return;
|
||||
}
|
||||
Vector2[] muv = OriginalUV;
|
||||
Vector2[] uv = new Vector2[muv.Length];
|
||||
for (int i = 0; i < uv.Length; i++) {
|
||||
uv[i] = frameInfo.Frame.GetUV(muv[i]);
|
||||
}
|
||||
mesh.Mesh.uv = uv;
|
||||
}
|
||||
|
||||
float _opacity = 1;
|
||||
public float Opacity {
|
||||
get { return _opacity; }
|
||||
set {
|
||||
_opacity = value;
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
void UpdateOpacity() {
|
||||
if (!mesh.Initialized) return;
|
||||
var c = mesh.Renderer.material.color;
|
||||
c.a = _opacity;
|
||||
mesh.Renderer.material.color = c;
|
||||
}
|
||||
|
||||
private FitMode m_fit = FitMode.height;
|
||||
public FitMode Fit {
|
||||
get { return m_fit; }
|
||||
set {
|
||||
m_fit = value;
|
||||
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
||||
}
|
||||
}
|
||||
public enum FitMode {
|
||||
none, width, height
|
||||
}
|
||||
|
||||
protected override void UpdateScale() {
|
||||
if (frameInfo.Frame == null) return;
|
||||
base.UpdateScale();
|
||||
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
||||
}
|
||||
|
||||
protected override Vector3 BaseScale {
|
||||
get {
|
||||
switch (m_fit) {
|
||||
case FitMode.none: return Vector3.one;
|
||||
case FitMode.width: return new Vector3(1, 1, 1 / frameInfo.Ratio);
|
||||
case FitMode.height: return new Vector3(frameInfo.Ratio, 1, 1);
|
||||
default: throw new NotSupportedException("Unsupported fit mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
frameInfo.Load();
|
||||
InternalInit();
|
||||
OnFrameUpdate();
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SpritePlane.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SpritePlane.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76053cf6896b7304fb0ec26546de1ace
|
||||
timeCreated: 1609142271
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Cryville/Crtr/Components/SpriteRect.cs
Normal file
39
Assets/Cryville/Crtr/Components/SpriteRect.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteRect : SpriteBase {
|
||||
public SpriteRect()
|
||||
: base() {
|
||||
/*
|
||||
SubmitProperty("color", new Property(typeof(Color), () => Color, v => Color = (Color)v));
|
||||
*/
|
||||
|
||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||
|
||||
transparent = true;
|
||||
}
|
||||
|
||||
Color _color;
|
||||
public Color Color {
|
||||
get { return _color; }
|
||||
set {
|
||||
_color = value;
|
||||
OnColorUpdate();
|
||||
}
|
||||
}
|
||||
void OnColorUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
mesh.Renderer.material.SetColor("_Color", _color);
|
||||
}
|
||||
|
||||
protected override Vector3 BaseScale {
|
||||
get { return Vector3.one; }
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
OnColorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SpriteRect.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SpriteRect.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a902fb77646e6eb4eb96d8ac86b3ee0e
|
||||
timeCreated: 1614821846
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
93
Assets/Cryville/Crtr/Components/SpriteScale3.cs
Normal file
93
Assets/Cryville/Crtr/Components/SpriteScale3.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteScale3 : SpritePlane {
|
||||
public SpriteScale3()
|
||||
: base() {
|
||||
/*
|
||||
SubmitProperty("border", new Property(typeof(Vector2), () => Border, v => Border = (Vector2)v));
|
||||
*/
|
||||
|
||||
SubmitProperty("border", new PropOp.Vector2(v => Border = v));
|
||||
}
|
||||
|
||||
readonly static Dictionary<float, int> uvrefl
|
||||
= new Dictionary<float, int>() {
|
||||
{-0.5f, 0}, {-0.4f, 1}, {0.4f, 2}, {0.5f, 3},
|
||||
};
|
||||
static Vector2[] _origuv;
|
||||
protected new static Vector2[] OriginalUV {
|
||||
get {
|
||||
if (_origuv == null) {
|
||||
var m = GenericResources.Meshes["quad_scale3h"];
|
||||
Vector2[] uv = new Vector2[m.vertices.Length];
|
||||
for (int i = 0; i < uv.Length; i++) {
|
||||
uv[i] = new Vector2(
|
||||
uvrefl[m.vertices[i].x],
|
||||
uvrefl[m.vertices[i].z]
|
||||
);
|
||||
}
|
||||
_origuv = uv;
|
||||
}
|
||||
return _origuv;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 _border = new Vector2(0, 1);
|
||||
public Vector2 Border {
|
||||
get { return _border; }
|
||||
set {
|
||||
_border = value;
|
||||
UpdateScale();
|
||||
}
|
||||
}
|
||||
protected override void UpdateScale() {
|
||||
base.UpdateScale();
|
||||
if (!mesh.Initialized) return;
|
||||
UpdateUV();
|
||||
}
|
||||
|
||||
protected override void UpdateUV() {
|
||||
Vector2[] muv = OriginalUV;
|
||||
Vector2[] uv = new Vector2[muv.Length];
|
||||
|
||||
var or = frameInfo.Ratio;
|
||||
var sr = Scale.x / Scale.y;
|
||||
var b = new Vector2(
|
||||
(or / sr) * _border.x,
|
||||
1 - (or / sr) * (1 - _border.y)
|
||||
);
|
||||
Vector3[] vert = mesh.Mesh.vertices;
|
||||
|
||||
for (int i = 0; i < muv.Length; i++) {
|
||||
float x; float bx;
|
||||
switch ((int)muv[i].x) {
|
||||
case 0: x = 0; bx = 0; break;
|
||||
case 1: x = _border.x; bx = b.x; break;
|
||||
case 2: x = _border.y; bx = b.y; break;
|
||||
case 3: x = 1; bx = 1; break;
|
||||
default: throw new Exception();
|
||||
}
|
||||
float y;
|
||||
switch ((int)muv[i].y) {
|
||||
case 0: y = 0; break;
|
||||
case 3: y = 1; break;
|
||||
default: throw new Exception();
|
||||
}
|
||||
uv[i] = frameInfo.Frame.GetUV(x, y);
|
||||
bx -= 0.5f; y -= 0.5f;
|
||||
vert[i] = new Vector3(bx, 0, y);
|
||||
}
|
||||
mesh.Mesh.uv = uv;
|
||||
mesh.Mesh.vertices = vert;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
frameInfo.Load();
|
||||
InternalInit("quad_scale3h");
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SpriteScale3.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SpriteScale3.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31dc4a947b5c7c645aa8fc2b82b4fba7
|
||||
timeCreated: 1615333501
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
201
Assets/Cryville/Crtr/Components/SpriteText.cs
Normal file
201
Assets/Cryville/Crtr/Components/SpriteText.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using Cryville.Common.Pdt;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteText : SpriteBase {
|
||||
public SpriteText() {
|
||||
/*
|
||||
SubmitProperty("frames", new Property(typeof(TextFrames), () => Frames, v => Frames = (TextFrames)v));
|
||||
SubmitProperty("value", new Property(typeof(string), () => Value, v => Value = (string)v));
|
||||
SubmitProperty("size", new Property(typeof(float), () => Size, v => Size = (float)v));
|
||||
SubmitProperty("spacing", new Property(typeof(float), () => Spacing, v => Spacing = (float)v));
|
||||
SubmitProperty("opacity", new Property(typeof(float), () => Opacity, v => Opacity = (float)v));
|
||||
*/
|
||||
|
||||
SubmitProperty("frames", new op_set_frames(this));
|
||||
SubmitProperty("value", new PropOp.String(v => Value = v));
|
||||
SubmitProperty("size", new PropOp.Float(v => Size = v));
|
||||
SubmitProperty("spacing", new PropOp.Float(v => Spacing = v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
class op_set_frames : PdtOperator {
|
||||
readonly SpriteText _self;
|
||||
public op_set_frames(SpriteText self) : base(2) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
var keys = GetOperand(0).AsString();
|
||||
var values = GetOperand(1);
|
||||
int arrtype; int len;
|
||||
values.GetArraySuffix(out arrtype, out len);
|
||||
var result = new Dictionary<char, SpriteInfo>(len);
|
||||
int o = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
string v = values.AsString(o);
|
||||
o += v.Length * sizeof(char) + sizeof(int);
|
||||
result.Add(keys[i], new SpriteInfo { FrameName = v });
|
||||
}
|
||||
_self.Frames = new TextFrames { Frames = result };
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
protected override void OnDestroy() {
|
||||
base.OnDestroy();
|
||||
foreach (var m in meshes) m.Value.Destroy();
|
||||
}
|
||||
|
||||
readonly Dictionary<Texture2D, MeshWrapper> meshes = new Dictionary<Texture2D, MeshWrapper>();
|
||||
public struct TextFrames /*: IConstructable*/ {
|
||||
public Dictionary<char, SpriteInfo> Frames;
|
||||
/*public void Load(object data, IEvaluator etor) {
|
||||
var d = (IList)data;
|
||||
var keys = (string)d[0];
|
||||
var values = (List<object>)d[1];
|
||||
Frames = new Dictionary<char, SpriteInfo>(keys.Length);
|
||||
for (int i = 0; i < keys.Length; i++)
|
||||
Frames.Add(keys[i], new SpriteInfo() { FrameName = (string)values[i] });
|
||||
}*/
|
||||
}
|
||||
TextFrames m_frames;
|
||||
public TextFrames Frames {
|
||||
get { return m_frames; }
|
||||
set { m_frames = value; UpdateFrames(); UpdateScale(); }
|
||||
}
|
||||
|
||||
public string m_value;
|
||||
public string Value {
|
||||
get { return m_value; }
|
||||
set {
|
||||
if (m_value == value) return;
|
||||
m_value = value; UpdateScale();
|
||||
}
|
||||
}
|
||||
|
||||
public float m_size;
|
||||
public float Size {
|
||||
get { return m_size; }
|
||||
set { m_size = value; UpdateScale(); }
|
||||
}
|
||||
|
||||
public float m_spacing;
|
||||
public float Spacing {
|
||||
get { return m_spacing; }
|
||||
set { m_spacing = value; UpdateScale(); }
|
||||
}
|
||||
|
||||
protected override void UpdateScale() {
|
||||
if (!mesh.Initialized) return;
|
||||
UpdateMeshes();
|
||||
base.UpdateScale();
|
||||
}
|
||||
|
||||
void UpdateFrames() {
|
||||
if (!mesh.Initialized) return;
|
||||
float frameHeight = 0;
|
||||
foreach (var m in meshes) m.Value.Destroy();
|
||||
meshes.Clear();
|
||||
foreach (var f in m_frames.Frames) {
|
||||
f.Value.Load();
|
||||
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
|
||||
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height");
|
||||
if (!meshes.ContainsKey(f.Value.Frame.Texture)) {
|
||||
var m = new MeshWrapper();
|
||||
m.Init(mesh.MeshTransform, transparent);
|
||||
m.Mesh = new Mesh();
|
||||
m.Renderer.material.mainTexture = f.Value.Frame.Texture;
|
||||
meshes.Add(f.Value.Frame.Texture, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float sum_x;
|
||||
void UpdateMeshes() {
|
||||
if (meshes.Count == 0) return;
|
||||
sum_x = 0;
|
||||
int vc = m_value.Length * 4;
|
||||
Dictionary<Texture2D, List<Vector3>> verts = new Dictionary<Texture2D, List<Vector3>>();
|
||||
Dictionary<Texture2D, List<Vector2>> uvs = new Dictionary<Texture2D, List<Vector2>>();
|
||||
foreach (var t in meshes.Keys) {
|
||||
verts.Add(t, new List<Vector3>(vc));
|
||||
uvs.Add(t, new List<Vector2>(vc));
|
||||
}
|
||||
foreach (var c in m_value) {
|
||||
var f = m_frames.Frames[c];
|
||||
var t = f.Frame.Texture;
|
||||
float w = f.Ratio * m_size;
|
||||
verts[t].Add(new Vector3(sum_x , 0, 0));
|
||||
verts[t].Add(new Vector3(sum_x + w, 0, 0));
|
||||
verts[t].Add(new Vector3(sum_x + w, 0, m_size));
|
||||
verts[t].Add(new Vector3(sum_x , 0, m_size));
|
||||
uvs[t].Add(f.Frame.GetUV(new Vector2(0, 0)));
|
||||
uvs[t].Add(f.Frame.GetUV(new Vector2(1, 0)));
|
||||
uvs[t].Add(f.Frame.GetUV(new Vector2(1, 1)));
|
||||
uvs[t].Add(f.Frame.GetUV(new Vector2(0, 1)));
|
||||
sum_x += w + m_spacing;
|
||||
}
|
||||
foreach (var t in meshes.Keys) {
|
||||
var m = meshes[t].Mesh;
|
||||
m.Clear();
|
||||
int cc = verts[t].Count / 4;
|
||||
int[] tris = new int[cc * 6];
|
||||
for (int i = 0; i < cc; i++) {
|
||||
tris[i * 6 ] = i * 4 ;
|
||||
tris[i * 6 + 1] = i * 4 + 3;
|
||||
tris[i * 6 + 2] = i * 4 + 1;
|
||||
tris[i * 6 + 3] = i * 4 + 1;
|
||||
tris[i * 6 + 4] = i * 4 + 3;
|
||||
tris[i * 6 + 5] = i * 4 + 2;
|
||||
}
|
||||
m.vertices = verts[t].ToArray();
|
||||
m.uv = uvs[t].ToArray();
|
||||
m.triangles = tris;
|
||||
m.RecalculateNormals();
|
||||
}
|
||||
sum_x -= m_spacing;
|
||||
}
|
||||
|
||||
protected override Vector3 BaseSize {
|
||||
get { return new Vector3(sum_x, 1, m_size); }
|
||||
}
|
||||
protected override Vector3 BaseScale {
|
||||
get {
|
||||
return Vector3.one;
|
||||
}
|
||||
}
|
||||
protected override Vector2 BasePivot {
|
||||
get { return new Vector2(-0.5f, -0.5f); }
|
||||
}
|
||||
|
||||
float _opacity = 1;
|
||||
public float Opacity {
|
||||
get { return _opacity; }
|
||||
set {
|
||||
_opacity = value;
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
void UpdateOpacity() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var m in meshes.Values) {
|
||||
var c = m.Renderer.material.color;
|
||||
c.a = _opacity;
|
||||
m.Renderer.material.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
UpdateFrames();
|
||||
mesh.Mesh.Clear();
|
||||
UpdateScale();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/SpriteText.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/SpriteText.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c3781c012a298849b9276df00b6f59c
|
||||
timeCreated: 1636509150
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
31
Assets/Cryville/Crtr/Components/TrackLine.cs
Normal file
31
Assets/Cryville/Crtr/Components/TrackLine.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class TrackLine : SectionalGameObject {
|
||||
readonly List<Vector3> vertices = new List<Vector3>();
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
}
|
||||
|
||||
protected override void AppendPointInternal(Vector3 p, Quaternion r) {
|
||||
vertices.Add(p);
|
||||
}
|
||||
|
||||
public override void Seal() {
|
||||
var r = GetComponent<LineRenderer>();
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
r.positionCount = vertices.Count;
|
||||
#else
|
||||
r.SetVertexCount(vertices.Count);
|
||||
#endif
|
||||
for (int i = 0; i < vertices.Count; i++) r.SetPosition(i, vertices[i]);
|
||||
}
|
||||
|
||||
public override void Reset() {
|
||||
base.Reset();
|
||||
vertices.Clear();
|
||||
}
|
||||
}
|
||||
}
|
12
Assets/Cryville/Crtr/Components/TrackLine.cs.meta
Normal file
12
Assets/Cryville/Crtr/Components/TrackLine.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7806feaea6d6c2540b2cb950286d379c
|
||||
timeCreated: 1596635435
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Assets/Cryville/Crtr/Components/TransformInterface.cs
Normal file
12
Assets/Cryville/Crtr/Components/TransformInterface.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class TransformInterface : SkinComponent {
|
||||
public TransformInterface() {
|
||||
SubmitProperty("pos", new PropOp.Vector3(v => transform.localPosition = v));
|
||||
SubmitProperty("rot", new PropOp.Vector3(v => transform.localRotation = Quaternion.Euler(v)));
|
||||
SubmitProperty("scale", new PropOp.Vector3(v => transform.localScale = v));
|
||||
}
|
||||
protected override void OnDestroy() { }
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Components/TransformInterface.cs.meta
Normal file
11
Assets/Cryville/Crtr/Components/TransformInterface.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a8a184616fd97d4a877c59c2ff76ba3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user