Commit 708d3dee authored by BlackAngle233's avatar BlackAngle233
Browse files

update final design

parent 1444629e
fileFormatVersion: 2
guid: eae2a981bb78d5a4fba23f0322efce2a
PluginImporter:
serializedVersion: 2
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
data:
first:
'': Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux: 0
Exclude Linux64: 0
Exclude LinuxUniversal: 0
Exclude OSXIntel: 1
Exclude OSXIntel64: 1
Exclude OSXUniversal: 1
Exclude Win: 0
Exclude Win64: 1
Exclude iOS: 1
data:
first:
'': Editor
second:
enabled: 0
settings:
CPU: x86
OS: AnyOS
data:
first:
Android: Android
second:
enabled: 0
settings:
CPU: ARMv7
data:
first:
Any:
second:
enabled: 0
settings: {}
data:
first:
Editor: Editor
second:
enabled: 1
settings:
CPU: x86
DefaultValueInitialized: true
OS: Windows
data:
first:
Facebook: Win
second:
enabled: 0
settings:
CPU: AnyCPU
data:
first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: None
data:
first:
Standalone: Linux
second:
enabled: 1
settings:
CPU: x86
data:
first:
Standalone: Linux64
second:
enabled: 1
settings:
CPU: x86_64
data:
first:
Standalone: LinuxUniversal
second:
enabled: 1
settings:
CPU: AnyCPU
data:
first:
Standalone: OSXIntel
second:
enabled: 0
settings:
CPU: AnyCPU
data:
first:
Standalone: OSXIntel64
second:
enabled: 0
settings:
CPU: AnyCPU
data:
first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
data:
first:
Standalone: Win
second:
enabled: 1
settings:
CPU: AnyCPU
data:
first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
data:
first:
iPhone: iOS
second:
enabled: 0
settings:
AddToEmbeddedBinaries: false
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 556ecd39e0ee30446bbe81ddbf660b45
folderAsset: yes
timeCreated: 1532602291
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 63dfebc23cc4fb64bbc6995e8731e492
folderAsset: yes
timeCreated: 1576048222
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 57f96bb4cd2b11444bb7b49f27a855b4
folderAsset: yes
timeCreated: 1566369821
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 281bb0c2d2f613c4089e4685aca62334
folderAsset: yes
timeCreated: 1576044625
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1570995156389318}
m_IsPrefabParent: 1
--- !u!1 &1050682128600786
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224825816383952840}
- component: {fileID: 222933945021573820}
- component: {fileID: 114356467954403100}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1570995156389318
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224837540539784396}
- component: {fileID: 222135567510852256}
- component: {fileID: 114634193976092408}
- component: {fileID: 114318062896510640}
- component: {fileID: 114648338187804948}
m_Layer: 5
m_Name: Back
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &114318062896510640
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1570995156389318}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 114634193976092408}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 114648338187804948}
m_MethodName: OpenScene
m_Mode: 5
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument: Samples/Scenes/AllSamplesLauncher
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &114356467954403100
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1050682128600786}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 5
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Back
--- !u!114 &114634193976092408
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1570995156389318}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &114648338187804948
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1570995156389318}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 583b62c5dde65b1488f3239f4edcb0ee, type: 3}
m_Name:
m_EditorClassIdentifier:
Buttons: []
--- !u!222 &222135567510852256
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1570995156389318}
--- !u!222 &222933945021573820
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1050682128600786}
--- !u!224 &224825816383952840
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1050682128600786}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 224837540539784396}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.1, y: 0.1}
m_AnchorMax: {x: 0.9, y: 0.9}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224837540539784396
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1570995156389318}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 224825816383952840}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.039340753, y: 0.89054614}
m_AnchorMax: {x: 0.22000001, y: 0.9463192}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
fileFormatVersion: 2
guid: e784795a17447b340b9cf47dc1398916
timeCreated: 1566372792
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f591f9eebc476124aa31f9593cb58e7c
folderAsset: yes
timeCreated: 1576044626
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
//================================================================================================================================
//
// Copyright (c) 2015-2021 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
// EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
// and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//================================================================================================================================
using easyar;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace AllSamplesLauncher
{
public class MainScene : MonoBehaviour
{
public List<Button> Buttons = new List<Button>();
private static SceneRecorder sceneRecorder;
private void Awake()
{
if (sceneRecorder == null)
{
var go = new GameObject("SceneRecorder");
sceneRecorder = go.AddComponent<SceneRecorder>();
DontDestroyOnLoad(go);
foreach (var item in Buttons)
{
if (item.gameObject.name == "SparseSpatialMap")
{
sceneRecorder.Record(item, this);
}
}
}
else
{
sceneRecorder.Recover(this);
}
foreach (var item in Buttons)
{
item.onClick.AddListener(() =>
{
sceneRecorder.Record(item, this);
});
}
}
public void OpenScene(string sceneName)
{
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
StartCoroutine(AliveChecker(sceneName));
}
private IEnumerator AliveChecker(string name)
{
yield return new WaitForSeconds(2);
GUIPopup.EnqueueMessage(name + Environment.NewLine +
"Looks like the above scene couldn't be loaded." + Environment.NewLine +
"Please check if the scene has been added to the build settings." + Environment.NewLine +
"To add a scene to the build settings use the menu File->Build Settings...", 10);
}
}
}
fileFormatVersion: 2
guid: 583b62c5dde65b1488f3239f4edcb0ee
timeCreated: 1566369935
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
//================================================================================================================================
//
// Copyright (c) 2015-2021 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
// EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
// and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//================================================================================================================================
using UnityEngine;
using UnityEngine.UI;
namespace AllSamplesLauncher
{
public class SceneRecorder : MonoBehaviour
{
private string buttonName;
public void Record(Button button, MainScene main)
{
Button recordButton = null;
foreach (var item in main.Buttons)
{
if (item.gameObject.name == buttonName)
{
recordButton = item;
}
}
if (recordButton == button)
{
return;
}
else
{
if (recordButton != null)
recordButton.targetGraphic.color *= 2f;
}
buttonName = button.gameObject.name;
button.targetGraphic.color *= 0.5f;
}
public void Recover(MainScene main)
{
Button recordButton = null;
foreach (var item in main.Buttons)
{
if (item.gameObject.name == buttonName)
{
recordButton = item;
}
}
if (recordButton != null)
{
recordButton.targetGraphic.color *= 0.5f;
recordButton.onClick.Invoke();
}
}
}
}
fileFormatVersion: 2
guid: 2391dde451e50c948a888e8440202108
timeCreated: 1576051320
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 890f95dfe5feaed4baaab881516878a2
folderAsset: yes
timeCreated: 1575950027
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7692892ce304de44f9d67a198dff3258
folderAsset: yes
timeCreated: 1575950265
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a1465c83c7325974c986aae3dbc342bd
timeCreated: 1575884845
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 25800000
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 7a67e18f6d895364aa41563e8ad4780e
folderAsset: yes
timeCreated: 1576404286
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
//================================================================================================================================
//
// Copyright (c) 2015-2021 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
// EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
// and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//================================================================================================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Common
{
public class TouchController : MonoBehaviour
{
private const float rotateSpeed = 270;
private const float gestureEnableDistanceThreshold = 10;
private Transform controlTarget;
private Camera cameraTarget;
private bool isOneFingerDraggable;
private bool isTwoFingerDraggable;
private bool isTwoFingerScalable;
private bool isTwoFingerRotatable;
private Dictionary<int, Vector2> originalPosition = new Dictionary<int, Vector2>();
private GestureControl curGesture;
private float targetCamDistance;
private enum GestureControl
{
NoTouch,
OneMove,
TwoWait,
TwoMove,
TwoRotate,
TwoScale,
OutOfControl,
}
private void Update()
{
if (!controlTarget) { return; }
foreach (var touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
originalPosition[touch.fingerId] = touch.position;
}
else if (touch.phase == TouchPhase.Ended)
{
originalPosition.Remove(touch.fingerId);
}
}
if (curGesture == GestureControl.OutOfControl)
{
if (Input.touchCount == 0)
{
StopAllCoroutines();
curGesture = GestureControl.NoTouch;
}
}
else if (curGesture == GestureControl.TwoMove || curGesture == GestureControl.TwoRotate || curGesture == GestureControl.TwoScale)
{
if (Input.touchCount != 2)
{
StopAllCoroutines();
curGesture = GestureControl.OutOfControl;
}
}
else if (curGesture == GestureControl.TwoWait)
{
if (Input.touchCount != 2)
{
StopAllCoroutines();
curGesture = GestureControl.OutOfControl;
}
else
{
Vector2 touch1Delta = Input.GetTouch(0).position - originalPosition[Input.GetTouch(0).fingerId];
Vector2 touch2Delta = Input.GetTouch(1).position - originalPosition[Input.GetTouch(1).fingerId];
if (touch1Delta.magnitude > gestureEnableDistanceThreshold && touch2Delta.magnitude > gestureEnableDistanceThreshold)
{
StopAllCoroutines();
if (Vector2.Dot(touch1Delta, touch2Delta) > 0)
{
Vector3 xMov;
Vector3 yMov;
GetRelativeTouch(touch1Delta + touch2Delta, out xMov, out yMov);
if (xMov.sqrMagnitude > yMov.sqrMagnitude)
{
curGesture = GestureControl.TwoRotate;
if (isTwoFingerRotatable)
{
StartCoroutine(OnTwoRotate());
}
}
else
{
curGesture = GestureControl.TwoMove;
if (isTwoFingerDraggable)
{
StartCoroutine(OnTwoMove());
}
}
}
else
{
curGesture = GestureControl.TwoScale;
if (isTwoFingerScalable)
{
StartCoroutine(OnTwoScale());
}
}
}
}
}
else if (curGesture == GestureControl.OneMove)
{
if (Input.touchCount == 2)
{
StopAllCoroutines();
curGesture = GestureControl.TwoWait;
}
else if (Input.touchCount != 1)
{
StopAllCoroutines();
curGesture = GestureControl.OutOfControl;
}
}
else if (curGesture == GestureControl.NoTouch)
{
if (Input.touchCount == 1)
{
curGesture = GestureControl.OneMove;
if (isOneFingerDraggable)
{
StopAllCoroutines();
StartCoroutine(OnOneMove());
}
}
else if (Input.touchCount == 2)
{
curGesture = GestureControl.TwoWait;
StopAllCoroutines();
}
}
if (controlTarget != null)
{
targetCamDistance = (cameraTarget.transform.position - controlTarget.position).magnitude;
}
}
public void TurnOn(Transform target, Camera cam, bool isOneFingerDraggable, bool isTwoFingerDraggable, bool isTwoFingerScalable, bool isTwoFingerRotatable)
{
StopAllCoroutines();
controlTarget = target;
cameraTarget = cam;
this.isOneFingerDraggable = isOneFingerDraggable;
this.isTwoFingerDraggable = isTwoFingerDraggable;
this.isTwoFingerScalable = isTwoFingerScalable;
this.isTwoFingerRotatable = isTwoFingerRotatable;
curGesture = GestureControl.NoTouch;
}
public void TurnOff()
{
StopAllCoroutines();
controlTarget = null;
cameraTarget = null;
curGesture = GestureControl.NoTouch;
}
private IEnumerator OnOneMove()
{
yield return new WaitForSeconds(0.1f);
foreach (var touch in Input.touches)
{
originalPosition[touch.fingerId] = touch.position;
}
while (Input.touchCount == 1 && originalPosition.ContainsKey(Input.GetTouch(0).fingerId))
{
if (!controlTarget) { yield break; }
var touchV3 = new Vector3(Input.GetTouch(0).deltaPosition.x / Screen.width, Input.GetTouch(0).deltaPosition.y / Screen.height, 0);
var addV3 = cameraTarget.transform.localToWorldMatrix.MultiplyVector(touchV3);
var newPos = controlTarget.position + addV3 * targetCamDistance;
controlTarget.position = newPos;
yield return 0;
}
}
private IEnumerator OnTwoMove()
{
Vector3 xMovement;
Vector3 yMovement;
var rawTargetPos = controlTarget.position;
foreach (var touch in Input.touches)
{
originalPosition[touch.fingerId] = touch.position;
}
while (Input.touchCount == 2 &&
originalPosition.ContainsKey(Input.GetTouch(0).fingerId) &&
originalPosition.ContainsKey(Input.GetTouch(1).fingerId))
{
if (!controlTarget) { yield break; }
Vector2 fixedDelta = (Input.GetTouch(0).position + Input.GetTouch(1).position - originalPosition[Input.GetTouch(0).fingerId] - originalPosition[Input.GetTouch(1).fingerId]);
GetRelativeTouch(fixedDelta, out xMovement, out yMovement);
if (yMovement != Vector3.zero)
{
var Cam_Forward = cameraTarget.transform.forward;
var Cam_Forward_XZ = Vector3.ProjectOnPlane(Cam_Forward, Vector3.up);
var newPos = rawTargetPos + (Vector3.Dot(yMovement, Cam_Forward) > 0 ? Cam_Forward_XZ : -Cam_Forward_XZ) * yMovement.magnitude * targetCamDistance * 2 / 1000;
controlTarget.position = newPos;
}
yield return 0;
}
}
private IEnumerator OnTwoRotate()
{
Vector3 xMovement;
Vector3 yMovement;
Quaternion rawRotation = controlTarget.rotation;
foreach (var touch in Input.touches)
{
originalPosition[touch.fingerId] = touch.position;
}
while (Input.touchCount == 2 &&
originalPosition.ContainsKey(Input.GetTouch(0).fingerId) &&
originalPosition.ContainsKey(Input.GetTouch(1).fingerId))
{
if (!controlTarget) { yield break; }
Vector2 fixedDelta = (Input.GetTouch(0).position + Input.GetTouch(1).position - originalPosition[Input.GetTouch(0).fingerId] - originalPosition[Input.GetTouch(1).fingerId]) * 0.5f / Screen.width * rotateSpeed;
GetRelativeTouch(fixedDelta, out xMovement, out yMovement);
if (xMovement != Vector3.zero)
{
if (Vector3.Dot(Vector3.Cross(xMovement.normalized, Vector3.up), Camera.main.transform.forward) < 0f)
{
controlTarget.rotation = rawRotation * Quaternion.Euler(0f, xMovement.sqrMagnitude / Mathf.PI, 0f);
}
else
{
controlTarget.rotation = rawRotation * Quaternion.Euler(0f, -xMovement.sqrMagnitude / Mathf.PI, 0f);
}
}
yield return 0;
}
}
private IEnumerator OnTwoScale()
{
Vector3 rawScale = controlTarget.localScale;
foreach (var touch in Input.touches)
{
originalPosition[touch.fingerId] = touch.position;
}
float rawFingersDistance = Vector2.Distance(originalPosition[Input.GetTouch(0).fingerId], originalPosition[Input.GetTouch(1).fingerId]);
while (Input.touchCount == 2 &&
originalPosition.ContainsKey(Input.GetTouch(0).fingerId) &&
originalPosition.ContainsKey(Input.GetTouch(1).fingerId))
{
if (!controlTarget) { yield break; }
float scaleFactor = rawFingersDistance / Vector2.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);
controlTarget.localScale = rawScale / scaleFactor;
yield return 0;
}
}
private void GetRelativeTouch(Vector2 delta, out Vector3 xMovement, out Vector3 yMovement)
{
if (delta != Vector2.zero)
{
Vector3 startPoint = Camera.main.ScreenToWorldPoint(new Vector3(0f, 0f, 300f));
Vector3 endPoint = Camera.main.ScreenToWorldPoint(new Vector3(delta.x, delta.y, 300f));
Vector3 moveDirection = endPoint - startPoint;
Vector3 relaForward = Vector3.ProjectOnPlane(Camera.main.transform.forward, Vector3.up).normalized;
if (relaForward == Vector3.zero)
{
xMovement = moveDirection;
yMovement = Vector3.zero;
}
else
{
Vector3 relaRight = Vector3.Cross(Vector3.up, relaForward);
xMovement = Vector3.Project(moveDirection, relaRight);
Vector3 temp = moveDirection - xMovement;
if (temp != Vector3.zero)
{
if (Vector3.Dot(Vector3.up, temp.normalized) == 0)
{
yMovement = temp.magnitude * ((Vector3.Dot(relaForward, temp.normalized) > 0 ? relaForward : -relaForward));
}
else
{
yMovement = temp.magnitude * ((Vector3.Dot(Vector3.up, temp.normalized) > 0 ? relaForward : -relaForward));
}
}
else
{
yMovement = Vector3.zero;
}
}
}
else
{
xMovement = Vector3.zero;
yMovement = Vector3.zero;
}
}
}
}
fileFormatVersion: 2
guid: 668fa50fe7ad94742aa6d3a631d7b31e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 183f4ea3d28ff5949a5e5e5958d1dbdc
folderAsset: yes
timeCreated: 1576045508
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment