You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
public class Entity
|
|
{
|
|
private readonly int entityNum;
|
|
|
|
private GameObject gameObject;
|
|
private SkinnedMeshRenderer meshRenderer;
|
|
|
|
private AliasModel aliasModel;
|
|
|
|
public Entity(int entityNum)
|
|
{
|
|
this.entityNum = entityNum;
|
|
CreateGameObject();
|
|
}
|
|
|
|
private void CreateGameObject()
|
|
{
|
|
gameObject = new GameObject($"Entity_{entityNum}");
|
|
|
|
// DEBUG - we'll want to instantiate a prefab and assign materials from a preset collection
|
|
meshRenderer = gameObject.AddComponent<SkinnedMeshRenderer>();
|
|
meshRenderer.material = new Material(Shader.Find("Universal Render Pipeline/Simple Lit"));
|
|
meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
|
|
meshRenderer.receiveShadows = false;
|
|
meshRenderer.lightProbeUsage = LightProbeUsage.Off;
|
|
meshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
Object.Destroy(gameObject);
|
|
}
|
|
|
|
public void ClearModel()
|
|
{
|
|
aliasModel = null;
|
|
meshRenderer.sharedMesh = null;
|
|
}
|
|
|
|
public void SetAliasModel(AliasModel model)
|
|
{
|
|
aliasModel = model;
|
|
|
|
// Set a default pose based on the first animation frame
|
|
UpdateAnimation(0);
|
|
}
|
|
|
|
public void UpdateAnimation(int frameNum)
|
|
{
|
|
if (aliasModel != null)
|
|
{
|
|
aliasModel.Animate(frameNum, out Mesh mesh, out float blendWeight);
|
|
meshRenderer.sharedMesh = mesh;
|
|
|
|
if (mesh.blendShapeCount > 0)
|
|
meshRenderer.SetBlendShapeWeight(0, blendWeight);
|
|
}
|
|
}
|
|
|
|
public void SetTransform(Vector3 position, Quaternion rotation)
|
|
{
|
|
gameObject.transform.position = position;
|
|
gameObject.transform.rotation = rotation;
|
|
}
|
|
}
|