BITKit/Packages/Runtime~/Unity/Scripts/Location/LocationMixer.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class LocationMixer : BITBehavior
{
[System.Serializable]
struct LocationInfo
{
public Location location;
public float weight;
}
[SerializeField] Dictionary<int, LocationInfo> locations = new();
public void SetLocation(Location location, int index = 0, float weight = 0)
{
locations.Set(index, new()
{
location = location,
weight = weight
});
}
void LateUpdate()
{
Location currentLocation = new();
locations.ForEach(x =>
{
if (x.Key is 0)
{
currentLocation = x.Value.location * x.Value.weight;
}
else
{
currentLocation=Location.Lerp(currentLocation,x.Value.location,x.Value.weight);
}
});
transform.SetPositionAndRotation(currentLocation, currentLocation);
}
}
}