概要
neosでlogixやってみる。
TouchToggleコンポーネントを使ってみる。
写真
TouchToggle
Name Type Description
persistent Bool Determines whether or not this item will be saved to the server.
UpdateOrder Int Controls the order in which this component is updated
Enabled Bool Controls whether or not this component is enabled
State Bool
EventType TouchEventType
ToggleEvent EventState
OnEvent EventState
OffEvent EventState
AcceptOutOfSightTouch Bool
AcceptPhysicalTouch Bool
AcceptRemoteTouch Bool
Vibrate VibratePreset
EditModeOnly Bool
ActiveUserFilter ActiveUserHandling
__legacyActiveUserRootOnly Bool
手順
- devtooltipを装着。
- 新規->3d->box
- インスペクターを開き、コンポーネントを追加
- Transform>Interaction>TouchToggle
- logixtooltipを装着。
- インターフェースを取り出す。
サンプルコード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FrooxEngine
{
[Category("Transform/Interaction")]
public class TouchToggle : Component, ITouchable {
public readonly Sync<bool> State;
public readonly Sync<TouchEventType> EventType;
public readonly Sync<EventState> ToggleEvent;
public readonly Sync<EventState> OnEvent;
public readonly Sync<EventState> OffEvent;
public readonly Sync<bool> AcceptPhysicalTouch;
public readonly Sync<bool> AcceptRemoteTouch;
public readonly Sync<VibratePreset> Vibrate;
protected override void OnAwake() {
ToggleEvent.Value = EventState.Begin;
EventType.Value = TouchEventType.Touch;
AcceptPhysicalTouch.Value = true;
AcceptRemoteTouch.Value = true;
Vibrate.Value = VibratePreset.Short;
}
public void OnTouch(TouchEventInfo eventInfo) {
switch(eventInfo.type)
{
case TouchType.Physical:
if (!AcceptPhysicalTouch)
return;
break;
case TouchType.Remote:
if (!AcceptRemoteTouch)
return;
break;
default:
Debug.Warning("Unknown touch type: " + eventInfo.type);
return;
}
bool prevState = State.Value;
if (ToggleEvent.Value != EventState.None && eventInfo.GetEventState(EventType) == ToggleEvent.Value)
State.Value = !State.Value;
if (OnEvent.Value != EventState.None && eventInfo.GetEventState(EventType) == OnEvent.Value)
State.Value = true;
if (OffEvent.Value != EventState.None && eventInfo.GetEventState(EventType) == OffEvent.Value)
State.Value = false;
if (State.Value != prevState)
eventInfo.source?.Slot.TryVibrate(Vibrate);
}
}
}
以上。