交互UI

交互UI

需要注册的接口

资源

public interface IResourcesGetter
{
    T Load<T>(string key) where T : UnityEngine.Object;
}

// Example
[Register(typeof(IResourcesGetter), true)]
public class InteractResourceHelper : IResourcesGetter
{
    public InteractResourceHelper()
    {
        Addressables.InitializeAsync();
    }

    public T Load<T>(string path) where T : UnityEngine.Object
    {
        var op = Addressables.LoadAssetAsync<T>(path);
        return op.WaitForCompletion();
    }
}

相机

public interface ICameraGetter
{
    Camera MainCamera { get; }
    Camera UiCamera { get; }
}

交互事件

public interface IInteractiveEvent
{
    /// <summary>
        /// 为某个物体添加点击回调
        /// </summary>
        /// <param name="target"></param>
        /// <param name="action"></param>
        void AddClickEvent(GameObject target, Action action);

        void AddClickEvent(Action action);

        /// <summary>
        /// 移除某个物体的点击回调
        /// </summary>
        /// <param name="target"></param>
        /// <param name="action"></param>
        void RemoveClickEvent(GameObject target, Action action);

        void RemoveClickEvent(Action action);

        /// <summary>
        /// 为某个物体添加开始移动回调
        /// </summary>
        /// <param name="target"></param>
        /// <param name="action"></param>
        void AddBeginMoveEvent(GameObject target, Action action);

        /// <summary>
        /// 移除某个物体的开始移动回调
        /// </summary>
        /// <param name="target"></param>
        /// <param name="action"></param>
        void RemoveBeginMoveEvent(GameObject target, Action action);

        /// <summary>
        /// 添加点击空白处的回调
        /// </summary>
        /// <param name="action"></param>
        void AddClickBlank(Action action);

        /// <summary>
        /// 移除点击空白处的回调
        /// </summary>
        /// <param name="action"></param>
        void RemoveClickBlank(Action action);

        /// <summary>
        /// 添加任意物体开始移动回调
        /// </summary>
        /// <param name="action"></param>
        void AddBeginMoveEvent(Action action);

        /// <summary>
        /// 移除任意物体开始移动回调
        /// </summary>
        /// <param name="action"></param>
        void RemoveBeginMoveEvent(Action action);
}

平台判断

public interface IJudgePlatform
{
    bool IsAndroid();
    bool IsiOS();
    bool IsVR();
}

多语言

public interface ITranslation
{
    string Translation(string content);
}

需要实现的接口

public interface IProgressmakerHandler
{
    void Init(Transform referenceCoordinateSystem);

    void Init();

    void IsEnable(bool b);

    void SetActive(bool b);

    T GetTargetComponent<T>();

    void OnInfoChange();

    void OnSlideRotationModeChange(SlideRotationMode mode);

    void ReleaseResource();

    void ChangeTrackInfo(TrackInfo trackInfo);

    void AddValueChangeEvent(IInteractiveExecutor executor, bool isInit = true);

    IProgressInfoContainer InfoContainer { get; }

    SlideRotationMode GetSlideRotationMode();
}

// Example
public class RotationProgressHandler : IProgressmakerHandler
{
    public LocalRotationInstance InteractionInstance;
    public IInteractiveInfoContainer InteractiveInfoContainer;

    public RotationProgressHandler(LocalRotationInstance instance)
    {
        InteractionInstance = instance;
    }

    public void Init(Transform referenceCoordinateSystem)
    {
        //DoNothing
    }

    public void Init()
    {
        //DoNothing
    }

    public void IsEnable(bool b)
    {
        //DoNothing
    }

    public void SetActive(bool b)
    {
        //DoNothing
    }

    public T GetTargetComponent<T>()
    {
        if (this is T)
        {
            return (T)(object)this;
        }
        else
        {
            return default(T);
        }
    }

    public void OnInfoChange()
    {
        //DoNothing
    }

    public void OnSlideRotationModeChange(SlideRotationMode mode)
    {
        //DoNothing
    }

    public void ReleaseResource()
    {
        //DoNothing
    }

    public void ChangeTrackInfo(TrackInfo trackInfo)
    {
        //DoNothing
    }

    public void AddValueChangeEvent(IInteractiveExecutor executor, bool isInit = true)
    {
        InteractionInstance.InteractionInstance.RegisterOnValueChangeEvent((container =>
        {
            executor.OnValueChange(InfoContainer);
        }));
        InteractionInstance.InteractionInstance.RegisterOnBeginDragEvent((container =>
        {
            executor.StartToPerform(InfoContainer);
        }));
        InteractionInstance.InteractionInstance.RegisterOnDragEvent((container =>
        {
            executor.Execute(InfoContainer);
        }));
        InteractionInstance.InteractionInstance.RegisterOnEndDragEvent((container =>
        {
            executor.EndToPerform(InfoContainer);
        }));
    }

    public IProgressInfoContainer InfoContainer => new ProgressInfoContainer(InteractionInstance.InteractionInstance.GetInfo());

    public SlideRotationMode GetSlideRotationMode()
    {
        var isFront = InteractionInstance.CheckFront();
        return !isFront ? SlideRotationMode.Side : SlideRotationMode.Front;
    }
}
public interface IProgressInfoContainer
{
    bool GetVector3(ProgressInfoType type, out Vector3 vector3);
    bool GetVector2(ProgressInfoType type, out Vector2 vector2);
    bool GetFloat(ProgressInfoType type, out float f);
    bool GetQuaternion(ProgressInfoType type, out Quaternion quaternion);
    bool GetString(ProgressInfoType type, out string s);
    bool GetMatrix4x4(ProgressInfoType type, out Matrix4x4 mat);
}
namespace Progressmaker
{
    public enum ProgressInfoType
    {
        //【Vector3】

        /// <summary>
        /// 【Vector3】:旋转轴(相对设定的参考系)
        /// </summary>
        LocalAxis = 0,
        /// <summary>
        /// 【Vector3】:旋转轴(世界坐标系)
        /// </summary>
        Axis = 1,
        /// <summary>
        /// 【Vector3】:旋转的初始方向或直线拖动的方向(世界坐标系)
        /// </summary>
        InitialDirection = 2,
        /// <summary>
        /// 【Vector3】:初始方向(相对设定的参考系)
        /// </summary>
        InitialLocalDirection = 3,
        /// <summary>
        /// 【Vector3】:滑块的位置(世界坐标系)
        /// </summary>
        Position = 4,
        /// <summary>
        /// 【Vector3】:滑块的位置(相对设定的参考系)
        /// </summary>
        LocalPosition = 5,
        /// <summary>
        /// 【Vector3】: 输入(鼠标等)的位置(相对设定的参考系)
        /// </summary>
        InputLocalPosition = 6,
        /// <summary>
        /// 【Vector3】: 输入(鼠标等)的位置(世界参考系)
        /// </summary>
        InputPosition = 7,
        /// <summary>
        /// 【Vector3】: 输入起始的位置(相对设定的参考系)
        /// </summary>
        InputStartLocalDirection = 8,
        /// <summary>
        /// 【Vector3】: 输入起始的位置
        /// </summary>
        InputStartDirection = 9,
        /// <summary>
        /// 【Vector3】参考坐标系位置
        /// </summary>
        CoordinateSystemPosition = 10,
        /// <summary>
        /// 【Vector3】参考坐标系缩放
        /// </summary>
        CoordinateSystemScale = 11,
        /// <summary>
        ///【Vector3】平面上的点(相对设定的参考系)
        /// </summary>
        InPointLocal = 12,
        /// <summary>
        ///【Vector3】平面上的点(世界参考系)
        /// </summary>
        InPoint = 13,


        //【Quaternion】

        /// <summary>
        /// 【Quaternion】参考坐标系旋转
        /// </summary>
        CoordinateSystemRotation = 14,
        /// <summary>
        /// 【Quaternion】: 旋转坐标系旋转
        /// </summary>
        RotaryCoordinateSystemRotation = 15,
        /// <summary>
        /// 【Quaternion】:当前的旋转(世界坐标系)
        /// </summary>
        Rotation = 16,
        /// <summary>
        /// 【Quaternion】:当前的旋转(相对设定的参考系)
        /// </summary>
        LocalRotation = 17,
        /// <summary>
        /// 【Quaternion】: 旋转坐标系相对参考系的旋转
        /// </summary>
        RotaryCoordinateSystemOffset = 18,

        //【float】

        /// <summary>
        /// 【float】:相对于上一帧,增加的旋转、拖动量
        /// </summary>
        Increment = 19,
        /// <summary>
        /// 【float】:拖动进度(归一化)
        /// </summary>
        ProgressNormalize = 20,
        /// <summary>
        /// 【float】:拖动进度
        /// </summary>
        Progress = 21,
        /// <summary>
        /// 【float】:轨道半径
        /// </summary>
        Radius = 22,
        /// <summary>
        /// 【float】:从开始旋转、拖动的增量
        /// </summary>
        TotalIncrement = 23,

        // 【Vector2】

        /// <summary>
        /// 【Vector2】:范围
        /// </summary>
        Range = 24,

        // 【String】

        /// <summary>
        /// 【String】:边界状态
        /// </summary>
        BorderState = 25,
        /// <summary>
        /// 【String】:平面朝向
        /// </summary>
        PlaneOrientation = 26,
        /// <summary>
        /// 轨道类型
        /// </summary>
        TrackType = 27,

        // 【Matrix4x4】

        /// <summary>
        /// 参考系 to 世界
        /// </summary>
        LocalToWorld = 28,
        /// <summary>
        /// 世界 to 参考系
        /// </summary>
        WorldToLocal = 29
    }
}

使用方法

GameObject Root;

IProgressmakerHandler handler = new RotationProgressHandler(this);
var defaultMarker = new DefaultProgressmarker(Root);
handler = defaultMarker.Decorate(handler, new AuxiliaryUiInfo(), _operationMode, _trigger, "pad");
handler.Init(_referenceCoordinateSystem);