Support 2D Mode

This commit is contained in:
Steven Lai
2025-03-30 19:19:50 +08:00
parent 9d04d709b1
commit 044a1cc5ef
22 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e49351aca911a5c4ca7a4d096973051c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 685c5a3f45f7b8a45abe1c16ff7d0f78
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d6bb04fa27ab9c5479f687815ba7baca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;