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.
 
 
 
 
 

80 lines
2.1 KiB

using UnityEngine;
using UnityEngine.Rendering;
public class Entity
{
private readonly int entityNum;
private GameObject gameObject;
private SkinnedMeshRenderer meshRenderer;
private AliasModel aliasModel;
private GameObject worldModel;
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 SetWorldModel(GameObject worldModelGO)
{
worldModel = worldModelGO;
worldModel.transform.SetParent(gameObject.transform);
}
public void UpdateAnimation(float frameNum)
{
if (aliasModel != null)
{
aliasModel.Animate(frameNum, out Mesh mesh, out float blendWeight);
meshRenderer.sharedMesh = mesh;
if (mesh != null && mesh.blendShapeCount > 0)
meshRenderer.SetBlendShapeWeight(0, blendWeight);
}
if (worldModel != null)
{
// TODO: update texture animation
}
}
public void SetTransform(Vector3 position, Quaternion rotation)
{
gameObject.transform.position = position;
gameObject.transform.rotation = rotation;
}
}