Support 2D Mode
This commit is contained in:
8
EasyInteractive/Editor.meta
Normal file
8
EasyInteractive/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e49351aca911a5c4ca7a4d096973051c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
EasyInteractive/Editor/EditorToolBarExtension.cs
Normal file
31
EasyInteractive/Editor/EditorToolBarExtension.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using System.Linq;
|
||||
|
||||
namespace HalfDog.EasyInteractive
|
||||
{
|
||||
public static class EditorToolBarExtension
|
||||
{
|
||||
private static NamedBuildTarget buildTarget => NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
[MenuItem("Settings/Interactive/Use 2D Mode")]
|
||||
private static void Change2DSymbol()
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbols(buildTarget).Split(';').ToList();
|
||||
bool is2DMode = defines.Contains("INTERACTIVE_2D_MODE");
|
||||
Menu.SetChecked("Settings/Interactive/Use 2D Mode",!is2DMode);
|
||||
if (is2DMode)
|
||||
{
|
||||
defines.Remove("INTERACTIVE_2D_MODE");
|
||||
}
|
||||
else
|
||||
{
|
||||
defines.Add("INTERACTIVE_2D_MODE");
|
||||
}
|
||||
string strDef = string.Join(";", defines);
|
||||
PlayerSettings.SetScriptingDefineSymbols(buildTarget, strDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
EasyInteractive/Editor/EditorToolBarExtension.cs.meta
Normal file
11
EasyInteractive/Editor/EditorToolBarExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 685c5a3f45f7b8a45abe1c16ff7d0f78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
EasyInteractive/Runtime.meta
Normal file
8
EasyInteractive/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6bb04fa27ab9c5479f687815ba7baca
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -132,7 +132,35 @@ namespace HalfDog.EasyInteractive
|
||||
if (Camera.main == null) return;
|
||||
_isPointerOverUI = false;
|
||||
//射线检测
|
||||
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
#if INTERACTIVE_2D_MODE
|
||||
mousePos.z = -Camera.main.transform.position.z;
|
||||
Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
RaycastHit2D raycastHit2D = Physics2D.Raycast(mouseWorldPos, Vector2.zero,0);
|
||||
if (raycastHit2D.transform != null)
|
||||
{
|
||||
if (raycastHit2D.transform.TryGetComponent(out IFocusable focus))
|
||||
{
|
||||
if (focus != _currentFocused && focus.enableFocus)
|
||||
SetCurrentFocused(focus);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCurrentFocused(null);
|
||||
}
|
||||
|
||||
if (raycastHit2D.transform.TryGetComponent(out ISelectable selectable) && selectable.enableSelect)
|
||||
_readySelect = selectable;
|
||||
else
|
||||
_readySelect = null;
|
||||
|
||||
if (raycastHit2D.transform.TryGetComponent(out IDragable dragable) && dragable.enableDrag)
|
||||
_readyDrag = dragable;
|
||||
else
|
||||
_readyDrag = null;
|
||||
}
|
||||
#else
|
||||
Ray mouseRay = Camera.main.ScreenPointToRay(mousePos);
|
||||
if (Physics.Raycast(mouseRay, out RaycastHit hitInfo, Mathf.Infinity))
|
||||
{
|
||||
if (hitInfo.transform.TryGetComponent(out IFocusable focus))
|
||||
@@ -155,6 +183,7 @@ namespace HalfDog.EasyInteractive
|
||||
else
|
||||
_readyDrag = null;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
_readyDrag = null;
|
||||
Reference in New Issue
Block a user