UniversalViewer/Assets/KF3/Scripts/Handles/UIHandleEyes.cs

53 lines
1.5 KiB
C#
Raw Permalink Normal View History

using UnityEngine;
public class UIHandleEyes : UIHandle
{
public static UIHandleEyes Create(KF3FriendContainer owner, Transform head)
{
var handle = new GameObject().AddComponent<UIHandleEyes>();
handle.Init(owner, handle.transform)
.SetScale(2)
.SetColor(Color.red);
handle.name = $"Eyes_{owner.ModelId}";
handle.transform.localScale = 0.1f * Vector3.one;
handle.transform.SetParent(head);
handle.transform.position = head.position + head.forward;
return handle;
}
public override UIHandle Init(ObjectContainer friend)
{
base.Init(friend);
Popup.AddButton("Reset Position", () => LookAtPositionReset());
Popup.AddButton("Change mode", () => SwapLookAtMode());
return this;
}
public override void UpdateManual(Camera camera, bool linesEnabled)
{
base.UpdateManual(camera, linesEnabled);
transform.localEulerAngles = _defaultTransform.Rotation;
}
void SwapLookAtMode()
{
var mContainer = (KF3FriendContainer)Owner;
if (transform.parent == mContainer.HumanBones[HumanBodyBones.Head])
{
transform.SetParent(mContainer.Body.transform);
}
else
{
transform.SetParent(mContainer.HumanBones[HumanBodyBones.Head]);
}
}
void LookAtPositionReset()
{
transform.position = transform.parent.position + Vector3.forward;
}
}