feat:1、添加项目
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a405f67bd764ee4ba3cbb08847007d5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Uni2SDK;
|
||||
|
||||
namespace UNSDK
|
||||
{
|
||||
|
||||
public class Uni2SdkDemo : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
//初始化sdk时,如果不确定unity中是否填入了包名,你这里最好填写你的包名
|
||||
SdkConfigMgr.Init("com.your.package.name");
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19f42161b9e34bc4fa15dcabf69fe812
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd1a17c754b6b374f800265176706eb3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UNSDK
|
||||
{
|
||||
public class ConfigEditor : EditorWindow
|
||||
{
|
||||
private static ConfigEditor _view;
|
||||
|
||||
[MenuItem("Tools/CreateConfig")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
if (_view != null)
|
||||
{
|
||||
CloseView();
|
||||
return;
|
||||
}
|
||||
_view = GetWindow<ConfigEditor>();
|
||||
_view.titleContent = new GUIContent("ConfigEditor");
|
||||
}
|
||||
|
||||
static void CloseView()
|
||||
{
|
||||
_view.Close();
|
||||
_view = null;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
DrawWindow();
|
||||
EditorUtility.SetDirty(SdkConfigMgr.Instance);
|
||||
}
|
||||
|
||||
private void DrawWindow()
|
||||
{
|
||||
TextLabel("Sdk 配置",Color.white);
|
||||
EditorGUILayout.BeginVertical("frameBox");
|
||||
SdkConfigMgr.Instance.secret = EditorGUILayout.TextField("Secret", SdkConfigMgr.Instance.secret);
|
||||
SdkConfigMgr.Instance.host = EditorGUILayout.TextField("Host", SdkConfigMgr.Instance.host);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
|
||||
TextLabel("Debug Log",Color.white);
|
||||
EditorGUILayout.BeginVertical("frameBox");
|
||||
SdkConfigMgr.Instance.isLog = EditorGUILayout.Toggle("IsLog", SdkConfigMgr.Instance.isLog);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void TextLabel(string content, Color color = new Color())
|
||||
{
|
||||
if (color.Equals(Color.clear))
|
||||
{
|
||||
color = Color.gray;
|
||||
}
|
||||
GUIStyle style = new GUIStyle();
|
||||
style.contentOffset = new Vector2(8, 0);
|
||||
style.normal.textColor = color;
|
||||
style.fontSize = 14;
|
||||
style.padding = new RectOffset(0, 0, 3, 0);
|
||||
GUILayout.Label(content, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68fcbeb7d5bbfbb4db4304eb591872db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0729286c16e0bb94f9ec7cbade888be0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Uni2SDK;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace UNSDK
|
||||
{
|
||||
public class SdkConfigMgr : ScriptableObject
|
||||
{
|
||||
[FormerlySerializedAs("Secret")] public string secret;
|
||||
[FormerlySerializedAs("Host")] public string host;
|
||||
[FormerlySerializedAs("IsLog")] public bool isLog;
|
||||
|
||||
public static bool IsInitSuccess = false;
|
||||
|
||||
private static SdkConfigMgr _instance;
|
||||
|
||||
public static SdkConfigMgr Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance) return _instance;
|
||||
_instance = AssetTools.GetScriptableObject<SdkConfigMgr>(typeof(SdkConfigMgr).Name, "Assets/Resources", false, false);
|
||||
return _instance;
|
||||
}
|
||||
set => _instance = value;
|
||||
}
|
||||
|
||||
|
||||
public static void Init(string packageName = "")
|
||||
{
|
||||
var package = StringExtensions.IsNullOrWhiteSpace(packageName) ? Application.identifier: packageName;
|
||||
|
||||
Uni2SDKManager.Instance.SetPackage(package);
|
||||
|
||||
Uni2SDKManager.Instance.SetLog(Instance.isLog);
|
||||
|
||||
Uni2SDKManager.Instance.Init(Instance.host,Instance.secret, (b, msg) =>
|
||||
{
|
||||
IsInitSuccess = b;
|
||||
Debug.Log($"init SDK bool===={b} WvManager.Instance.Init s==={msg}");
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭有感
|
||||
/// 必须调用,且在退出有感界界面时调用
|
||||
/// 调用此方法后,可以将其他游戏界面等显示了
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
Uni2SDKManager.Instance.Close();
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// 开启有感
|
||||
/// 开启时:需要将其他游戏界面等隐藏,注意,是隐藏,不是在其界面上再添加一个界面
|
||||
/// </summary>
|
||||
public void Open()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
Uni2SDKManager.Instance.Open(0,164,0,0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb2c9d85afdd3d34c88a57c51b02fa84
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fe3549a90795f54e822612affc22b6d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,152 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace UNSDK
|
||||
{
|
||||
public static class AssetTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a reference to a scriptable object of type T with the given fileName at the relative resourcesPath.
|
||||
/// <para/> If the asset is not found, one will get created automatically (in the Editor only)
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="resourcesPath"></param>
|
||||
/// <param name="saveAssetDatabase"></param>
|
||||
/// <param name="refreshAssetDatabase"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static T GetScriptableObject<T>(string fileName,
|
||||
string resourcesPath,
|
||||
bool saveAssetDatabase,
|
||||
bool refreshAssetDatabase)
|
||||
where T : ScriptableObject
|
||||
{
|
||||
if (string.IsNullOrEmpty(resourcesPath)) return null;
|
||||
if (string.IsNullOrEmpty(fileName)) return null;
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
// if (!resourcesPath[resourcesPath.Length - 1].Equals(@"\")) resourcesPath += @"\";
|
||||
// resourcesPath = resourcesPath.Replace(@"\", "/");
|
||||
resourcesPath = CleanPath(resourcesPath);
|
||||
|
||||
var obj = (T)Resources.Load(fileName, typeof(T));
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
string simpleResourcesPath = resourcesPath.Replace(resourcesPath.Substring(0, resourcesPath.LastIndexOf("Resources", StringComparison.Ordinal)), "");
|
||||
simpleResourcesPath = simpleResourcesPath.Replace("Resources", "").Remove(0, 1);
|
||||
obj = (T)Resources.Load(Path.Combine(simpleResourcesPath, fileName), typeof(T));
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (obj != null) return obj;
|
||||
if (!Directory.Exists("Assets/Resources"))
|
||||
{
|
||||
Directory.CreateDirectory("Assets/Resources");
|
||||
}
|
||||
obj = CreateAsset<T>(resourcesPath, fileName, ".asset", saveAssetDatabase, refreshAssetDatabase);
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static T GetResource<T>(string resourcesPath, string fileName) where T : ScriptableObject
|
||||
{
|
||||
if (string.IsNullOrEmpty(resourcesPath)) return null;
|
||||
if (string.IsNullOrEmpty(fileName)) return null;
|
||||
resourcesPath = CleanPath(resourcesPath);
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
// if (!resourcesPath[resourcesPath.Length - 1].Equals(@"\")) resourcesPath += @"\";
|
||||
// resourcesPath = resourcesPath.Replace(@"\", "/");
|
||||
|
||||
return (T)Resources.Load(resourcesPath + fileName, typeof(T));
|
||||
}
|
||||
|
||||
public static string CleanPath(string path)
|
||||
{
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
if (!path[path.Length - 1].Equals(@"\")) path += @"\";
|
||||
path = path.Replace(@"\\", @"\");
|
||||
path = path.Replace(@"\", "/");
|
||||
return path;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static T CreateAsset<T>(string relativePath,
|
||||
string fileName,
|
||||
string extension = ".asset",
|
||||
bool saveAssetDatabase = true,
|
||||
bool refreshAssetDatabase = true)
|
||||
where T : ScriptableObject
|
||||
{
|
||||
if (string.IsNullOrEmpty(relativePath)) return null;
|
||||
if (string.IsNullOrEmpty(fileName)) return null;
|
||||
relativePath = CleanPath(relativePath);
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
// if (!relativePath[relativePath.Length - 1].Equals(@"\")) relativePath += @"\";
|
||||
// relativePath = relativePath.Replace(@"\\", @"\");
|
||||
var asset = ScriptableObject.CreateInstance<T>();
|
||||
AssetDatabase.CreateAsset(asset, relativePath + fileName + extension);
|
||||
EditorUtility.SetDirty(asset);
|
||||
if (saveAssetDatabase) AssetDatabase.SaveAssets();
|
||||
if (refreshAssetDatabase) AssetDatabase.Refresh();
|
||||
return asset;
|
||||
}
|
||||
|
||||
public static List<T> GetAssets<T>() where T : ScriptableObject
|
||||
{
|
||||
var list = new List<T>();
|
||||
string[] guids = AssetDatabase.FindAssets("t:" + typeof(T).Name);
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
var asset = AssetDatabase.LoadAssetAtPath<T>(AssetDatabase.GUIDToAssetPath(guid));
|
||||
if (asset == null) continue;
|
||||
list.Add(asset);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void MoveAssetToTrash(string relativePath, string fileName, bool saveAssetDatabase = true,
|
||||
bool refreshAssetDatabase = true, bool printDebugMessage = true)
|
||||
{
|
||||
if (string.IsNullOrEmpty(relativePath)) return;
|
||||
if (string.IsNullOrEmpty(fileName)) return;
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
// if (!relativePath[relativePath.Length - 1].Equals(@"\")) relativePath += @"\";
|
||||
relativePath = CleanPath(relativePath);
|
||||
if (!AssetDatabase.MoveAssetToTrash(relativePath + fileName + ".asset")) return;
|
||||
if (printDebugMessage) Debug.Log("The " + fileName + ".asset file has been moved to trash.");
|
||||
if (saveAssetDatabase) AssetDatabase.SaveAssets();
|
||||
if (refreshAssetDatabase) AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
public static Texture GetTexture(string filePath, string fileName, string fileExtension = ".png")
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath)) return null;
|
||||
if (string.IsNullOrEmpty(fileName)) return null;
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
// if (!filePath[filePath.Length - 1].Equals(@"\")) filePath += @"\";
|
||||
filePath = CleanPath(filePath);
|
||||
return AssetDatabase.LoadAssetAtPath<Texture>(filePath + fileName + fileExtension);
|
||||
}
|
||||
|
||||
public static Texture2D GetTexture2D(string filePath, string fileName, string fileExtension = ".png")
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath)) return null;
|
||||
if (string.IsNullOrEmpty(fileName)) return null;
|
||||
// ReSharper disable once SuspiciousTypeConversion.Global
|
||||
// if (!filePath[filePath.Length - 1].Equals(@"\")) filePath += @"\";
|
||||
filePath = CleanPath(filePath);
|
||||
return AssetDatabase.LoadAssetAtPath<Texture2D>(filePath + fileName + fileExtension);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbce9d27e5ed4d74ab0313e576cc3766
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d96be196b7f1334e97f1e5ef43a6813
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user