1
This commit is contained in:
40
Unity/Scripts/Location/LocationMixer.cs
Normal file
40
Unity/Scripts/Location/LocationMixer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user