Init
This commit is contained in:
8
Assets/Scripts/Editor.meta
Normal file
8
Assets/Scripts/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 653e3f9a8bc8ffe46a9b706558a79177
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Scripts/Editor/AddressablePathSetter.cs
Normal file
22
Assets/Scripts/Editor/AddressablePathSetter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using UnityEngine;
|
||||
|
||||
public static class AddressablePathSetter
|
||||
{
|
||||
public static void SetCustomPaths(string relativePath)
|
||||
{
|
||||
var settings = AddressableAssetSettingsDefaultObject.Settings;
|
||||
// <20><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>·<EFBFBD><C2B7>
|
||||
settings.profileSettings.SetValue(
|
||||
settings.activeProfileId,
|
||||
"Remote.BuildPath",
|
||||
$"{Application.dataPath}/{relativePath}/[BuildTarget]");
|
||||
|
||||
// <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>·<EFBFBD><C2B7>
|
||||
settings.profileSettings.SetValue(
|
||||
settings.activeProfileId,
|
||||
"Remote.LoadPath",
|
||||
$"{relativePath}/ServerData");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/AddressablePathSetter.cs.meta
Normal file
11
Assets/Scripts/Editor/AddressablePathSetter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef459a98d98d962448e8063cd219f434
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/Editor/BuildTool.cs
Normal file
24
Assets/Scripts/Editor/BuildTool.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using UnityEngine;
|
||||
|
||||
public class BuildTool
|
||||
{
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %g")] // Ctrl+G (Windows) or Command+G (Mac)
|
||||
public static void BuildIncremental()
|
||||
{
|
||||
CopyHotDll.CreateDllByte();
|
||||
AddressableAssetSettings.BuildPlayerContent();
|
||||
Debug.Log("Addressables <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (Ctrl+G)");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD> %#g")] // Ctrl+Shift+G (Windows) or Command+Shift+G (Mac)
|
||||
public static void BuildClearCache()
|
||||
{
|
||||
CopyHotDll.CreateDllByte();
|
||||
AddressableAssetSettings.CleanPlayerContent();
|
||||
AddressableAssetSettings.BuildPlayerContent();
|
||||
Debug.Log("Addressables ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (Ctrl+Shift+G)");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/BuildTool.cs.meta
Normal file
11
Assets/Scripts/Editor/BuildTool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae66b515223d332499794e4292efe9ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Editor/CopyHotDll.cs
Normal file
32
Assets/Scripts/Editor/CopyHotDll.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
public class CopyHotDll
|
||||
{
|
||||
[MenuItem("Tools/<2F><><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD>Dll<6C><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>")]
|
||||
public static void CreateDllByte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
BuildTarget buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
|
||||
foreach (var dll in Boot.Inst.dllMap)
|
||||
{
|
||||
string sourcePath = dll.Value == 0 ?
|
||||
$"{KeyManager.TDllSourceDir}/{buildTarget}/{dll.Key}.dll" :
|
||||
$"{KeyManager.HotDllSourceDir}/{buildTarget}/{dll.Key}.dll";
|
||||
string destPath = $"{KeyManager.AssetDllDir}/{dll.Key}.dll.bytes";
|
||||
if (File.Exists(destPath))
|
||||
File.Delete(destPath);
|
||||
File.Copy(sourcePath, destPath);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourcePath} to {destPath}");
|
||||
}
|
||||
Debug.Log($"<22><><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD>Dll<6C><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Editor/CopyHotDll.cs.meta
Normal file
11
Assets/Scripts/Editor/CopyHotDll.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54f422773e0842b41a6ad5488368667d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/Editor/UnityScripts.Editor.asmdef
Normal file
20
Assets/Scripts/Editor/UnityScripts.Editor.asmdef
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "UnityScripts.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:2373f786d14518f44b0f475db77ba4de",
|
||||
"GUID:231d2189f0e1fc546999766032d5c36d",
|
||||
"GUID:69448af7b92c7f342b298e06a37122aa"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/Editor/UnityScripts.Editor.asmdef.meta
Normal file
7
Assets/Scripts/Editor/UnityScripts.Editor.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0d1c4909ca503145a96825c04c64d1d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/HotUpdate.meta
Normal file
8
Assets/Scripts/HotUpdate.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5505f192c652dc24ab961135790781ee
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/HotUpdate/GameStart.cs
Normal file
24
Assets/Scripts/HotUpdate/GameStart.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
public class GameStart : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Debug.Log("Game Start");
|
||||
Addressables.LoadSceneAsync("Assets/GameRes/Scene/Test.unity").Completed+=(handle)=>
|
||||
{
|
||||
Debug.Log("Load Scene\"Test\"");
|
||||
};
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HotUpdate/GameStart.cs.meta
Normal file
11
Assets/Scripts/HotUpdate/GameStart.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91a52e294219f0242be13de2ba0471f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
180
Assets/Scripts/HotUpdate/MyActions.inputactions
Normal file
180
Assets/Scripts/HotUpdate/MyActions.inputactions
Normal file
@@ -0,0 +1,180 @@
|
||||
{
|
||||
"name": "MyActions",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Map",
|
||||
"id": "9b2dac95-d312-427d-8a31-ce291063a847",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Move",
|
||||
"type": "Value",
|
||||
"id": "c600010c-741d-4ca9-aa4c-530804b962cd",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Jump",
|
||||
"type": "Button",
|
||||
"id": "d80c1257-09a3-4e8e-b96f-bc85555fbf9e",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Zoom",
|
||||
"type": "Value",
|
||||
"id": "d42a56f1-abed-47ce-8eba-da4bb48e2303",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Esc",
|
||||
"type": "Button",
|
||||
"id": "2cc7fb6d-38ed-46cd-8733-8da61480105a",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Alt",
|
||||
"type": "Button",
|
||||
"id": "469ee5e2-ba9d-485e-b0c5-764d70e16a2d",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "Move",
|
||||
"id": "7fe7158f-cccd-4fdd-913e-a274c55e0fcd",
|
||||
"path": "2DVector",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "d49bf5a2-1859-4517-b4a7-b4f4a8abfd2d",
|
||||
"path": "<Keyboard>/w",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "0a084e7e-94f2-4bb5-80aa-58d3f1f63f45",
|
||||
"path": "<Keyboard>/s",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "4a6fe744-a732-4176-a41d-d72cbc9c173a",
|
||||
"path": "<Keyboard>/a",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "f9a32fde-1141-48d4-a638-50962544314e",
|
||||
"path": "<Keyboard>/d",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "cd94b74d-2756-4fce-9067-8b7dd9b18c45",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Jump",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "1D Axis",
|
||||
"id": "7ee6a4b1-c1a1-4b1b-92cc-cc05c3ccb1f6",
|
||||
"path": "1DAxis",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Zoom",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "negative",
|
||||
"id": "7a62b1f0-5da3-4eb6-8252-233fea59b5cd",
|
||||
"path": "<Mouse>/scroll/up",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Zoom",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "positive",
|
||||
"id": "7b9d0a02-0a80-4f55-a9bb-60e0687621d9",
|
||||
"path": "<Mouse>/scroll/down",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Zoom",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "dac47152-10fb-4236-b70e-b0e17e9f51b4",
|
||||
"path": "<Keyboard>/escape",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Esc",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "89df66f5-0bf3-496f-83fa-7bb55f960ea3",
|
||||
"path": "<Keyboard>/leftAlt",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Alt",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": []
|
||||
}
|
||||
14
Assets/Scripts/HotUpdate/MyActions.inputactions.meta
Normal file
14
Assets/Scripts/HotUpdate/MyActions.inputactions.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c599bdae20876e4a819e335af6dd11b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
122
Assets/Scripts/HotUpdate/ThirdCharacterController.cs
Normal file
122
Assets/Scripts/HotUpdate/ThirdCharacterController.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class ThirdCharacterController : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
public float moveSpeed = 5f;
|
||||
public float turnSpeed = 10f;
|
||||
public float jumpSpeed = 8f;
|
||||
public float gravity = 20f;
|
||||
public float minCameraDistance = 2f;
|
||||
public float maxCameraDistance = 10f;
|
||||
public float cameraZoomSpeed = 0.1f;
|
||||
[Header("Components")]
|
||||
public CharacterController controller;
|
||||
public Animator animator;
|
||||
public CinemachineVirtualCamera vCam;
|
||||
public Transform forwardReference;
|
||||
public Transform model;
|
||||
|
||||
private CinemachineFramingTransposer framingTransposer;
|
||||
private CinemachinePOV pov;
|
||||
private Vector3 moveDirection;
|
||||
private Vector3 verticalVelocity;
|
||||
private Vector2 moveInput;
|
||||
private bool isGrounded;
|
||||
private bool isCursorLocked = true;
|
||||
void Awake()
|
||||
{
|
||||
framingTransposer = vCam.GetCinemachineComponent<CinemachineFramingTransposer>();
|
||||
pov = vCam.GetCinemachineComponent<CinemachinePOV>();
|
||||
UpdateCursorState();
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
ApplyGravity();
|
||||
Move();
|
||||
RotateModel();
|
||||
UpdateAnimator();
|
||||
}
|
||||
private void UpdateCursorState()
|
||||
{
|
||||
Cursor.lockState = isCursorLocked ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
Cursor.visible = !isCursorLocked;
|
||||
if (pov == null) return;
|
||||
pov.m_HorizontalAxis.m_InputAxisName = isCursorLocked ? "Mouse X" : "";
|
||||
pov.m_VerticalAxis.m_InputAxisName = isCursorLocked ? "Mouse Y" : "";
|
||||
pov.m_HorizontalAxis.m_MaxSpeed = isCursorLocked ? 300 : 0;
|
||||
pov.m_VerticalAxis.m_MaxSpeed = isCursorLocked ? 300 : 0;
|
||||
}
|
||||
private void ApplyGravity()
|
||||
{
|
||||
isGrounded = controller.isGrounded;
|
||||
if (isGrounded && verticalVelocity.y < 0)
|
||||
{
|
||||
verticalVelocity.y = -2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalVelocity.y -= gravity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
private void Move()
|
||||
{
|
||||
forwardReference.rotation = Quaternion.AngleAxis(pov.m_HorizontalAxis.Value, Vector3.up);
|
||||
Vector3 horizontalMovement = forwardReference.TransformDirection(
|
||||
new Vector3(moveInput.x, 0, moveInput.y)) * moveSpeed;
|
||||
moveDirection = horizontalMovement + verticalVelocity;
|
||||
controller.Move(moveDirection * Time.deltaTime);
|
||||
}
|
||||
private void RotateModel()
|
||||
{
|
||||
if (moveInput == Vector2.zero) return;
|
||||
float targetAngle = Mathf.Atan2(moveInput.x, moveInput.y) * Mathf.Rad2Deg;
|
||||
Quaternion targetRotation = forwardReference.rotation * Quaternion.AngleAxis(targetAngle, Vector3.up);
|
||||
model.rotation = Quaternion.Slerp(model.rotation, targetRotation, turnSpeed * Time.deltaTime);
|
||||
}
|
||||
private void UpdateAnimator()
|
||||
{
|
||||
animator.SetBool("Move", moveInput != Vector2.zero);
|
||||
}
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
moveInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed && isGrounded)
|
||||
{
|
||||
verticalVelocity.y = jumpSpeed;
|
||||
}
|
||||
}
|
||||
public void OnEsc(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
isCursorLocked = !isCursorLocked;
|
||||
UpdateCursorState();
|
||||
}
|
||||
}
|
||||
public void OnAlt(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
isCursorLocked = false;
|
||||
UpdateCursorState();
|
||||
}
|
||||
else if (context.canceled)
|
||||
{
|
||||
isCursorLocked = true;
|
||||
UpdateCursorState();
|
||||
}
|
||||
}
|
||||
public void OnZoom(InputAction.CallbackContext context)
|
||||
{
|
||||
if (framingTransposer == null) return;
|
||||
float scrollValue = context.ReadValue<float>();
|
||||
float newDistance = framingTransposer.m_CameraDistance + (scrollValue * cameraZoomSpeed * 0.01f);
|
||||
framingTransposer.m_CameraDistance = Mathf.Clamp(newDistance, minCameraDistance, maxCameraDistance);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/HotUpdate/ThirdCharacterController.cs.meta
Normal file
11
Assets/Scripts/HotUpdate/ThirdCharacterController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de36ff070be69284da71fd9b44a5aea6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/HotUpdate/UnityScripts.HotUpdate.asmdef
Normal file
19
Assets/Scripts/HotUpdate/UnityScripts.HotUpdate.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "UnityScripts.HotUpdate",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bbba614ff545384c97bd498ddb816ce
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Runtime.meta
Normal file
8
Assets/Scripts/Runtime.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43f231cd58b44ab4099bb2ca6241d840
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
94
Assets/Scripts/Runtime/Boot.cs
Normal file
94
Assets/Scripts/Runtime/Boot.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using HybridCLR;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
|
||||
public class Boot : SingletonBehaviour<Boot>
|
||||
{
|
||||
public AssetReferenceGameObject patchWindowRef;
|
||||
// DLL<4C><4C><EFBFBD>ã<EFBFBD>0=<3D><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>, 1=<3D>ȸ<EFBFBD><C8B8>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
public Dictionary<string, int> dllMap = new Dictionary<string, int>()
|
||||
{
|
||||
{ "mscorlib", 0 },
|
||||
{ "System", 0 },
|
||||
{ "System.Core", 0 },
|
||||
{ "UnityScripts.HotUpdate", 1 },
|
||||
};
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
Application.runInBackground = true;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
StartCoroutine(Initialize());
|
||||
}
|
||||
|
||||
IEnumerator Initialize()
|
||||
{
|
||||
// <20><>ʼ<EFBFBD><CABC>Addressables
|
||||
var initHandle = Addressables.InitializeAsync();
|
||||
yield return initHandle;
|
||||
|
||||
// <20><><EFBFBD>ظ<EFBFBD><D8B8>´<EFBFBD><C2B4><EFBFBD>
|
||||
var windowHandle = patchWindowRef.LoadAssetAsync<GameObject>();
|
||||
yield return windowHandle;
|
||||
|
||||
var windowObj = Instantiate(windowHandle.Result, GameManager.Inst.MainCanvasUI.transform);
|
||||
var patchWindow = windowObj.GetComponent<PatchWindow>();
|
||||
|
||||
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA>ص<EFBFBD>LoadDll
|
||||
patchWindow.StartCheckUpdate(() => StartCoroutine(LoadDllAndStartGame()));
|
||||
}
|
||||
|
||||
IEnumerator LoadDllAndStartGame()
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DLL
|
||||
foreach (var dll in dllMap)
|
||||
{
|
||||
yield return LoadSingleDll(dll.Key, dll.Value);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ
|
||||
yield return LoadGameStart();
|
||||
}
|
||||
|
||||
IEnumerator LoadSingleDll(string dllName, int dllType)
|
||||
{
|
||||
var handle = Addressables.LoadAssetAsync<TextAsset>(KeyManager.LoadDllKey(dllName));
|
||||
yield return handle;
|
||||
|
||||
if (dllType == 0)
|
||||
{
|
||||
// <20><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>
|
||||
RuntimeApi.LoadMetadataForAOTAssembly(handle.Result.bytes, HomologousImageMode.SuperSet);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// <20>༭<EFBFBD><E0BCAD>ģʽ<C4A3><CABD>ֱ<EFBFBD>ӻ<EFBFBD>ȡ<EFBFBD>Ѽ<EFBFBD><D1BC>صij<D8B5><C4B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
var hotUpdateAss = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.First(a => a.GetName().Name == "UnityScripts.HotUpdate");
|
||||
#else
|
||||
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ȸ<EFBFBD><C8B8>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
var hotUpdateAss = Assembly.Load(handle.Result.bytes);
|
||||
#endif
|
||||
Debug.Log($"<22>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD> {dllName}");
|
||||
}
|
||||
|
||||
Addressables.Release(handle);
|
||||
}
|
||||
|
||||
IEnumerator LoadGameStart()
|
||||
{
|
||||
var handle = Addressables.LoadAssetAsync<GameObject>(KeyManager.LoadPrefabKey("GameStart"));
|
||||
yield return handle;
|
||||
|
||||
Instantiate(handle.Result);
|
||||
Addressables.Release(handle);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Runtime/Boot.cs.meta
Normal file
11
Assets/Scripts/Runtime/Boot.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81691e75f675cbc4e9769f6a711387ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Scripts/Runtime/ConsoleToScreen.cs
Normal file
55
Assets/Scripts/Runtime/ConsoleToScreen.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConsoleToScreen : MonoBehaviour
|
||||
{
|
||||
const int maxLines = 50;
|
||||
const int maxLineLength = 120;
|
||||
private string _logStr = "";
|
||||
|
||||
private readonly List<string> _lines = new List<string>();
|
||||
|
||||
public int fontSize = 15;
|
||||
|
||||
void OnEnable() { Application.logMessageReceived += Log; }
|
||||
void OnDisable() { Application.logMessageReceived -= Log; }
|
||||
|
||||
public void Log(string logString, string stackTrace, LogType type)
|
||||
{
|
||||
foreach (var line in logString.Split('\n'))
|
||||
{
|
||||
if (line.Length <= maxLineLength)
|
||||
{
|
||||
_lines.Add(line);
|
||||
continue;
|
||||
}
|
||||
var lineCount = line.Length / maxLineLength + 1;
|
||||
for (int i = 0; i < lineCount; i++)
|
||||
{
|
||||
if ((i + 1) * maxLineLength <= line.Length)
|
||||
{
|
||||
_lines.Add(line.Substring(i * maxLineLength, maxLineLength));
|
||||
}
|
||||
else
|
||||
{
|
||||
_lines.Add(line.Substring(i * maxLineLength, line.Length - i * maxLineLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_lines.Count > maxLines)
|
||||
{
|
||||
_lines.RemoveRange(0, _lines.Count - maxLines);
|
||||
}
|
||||
_logStr = string.Join("\n", _lines);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,
|
||||
new Vector3(Screen.width / 1200.0f, Screen.height / 800.0f, 1.0f));
|
||||
GUI.Label(new Rect(10, 10, 800, 370), _logStr, new GUIStyle() { fontSize = Math.Max(10, fontSize) });
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/Scripts/Runtime/ConsoleToScreen.cs.meta
Normal file
11
Assets/Scripts/Runtime/ConsoleToScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c738b4a94a68ae745bb437925f4d0323
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/Runtime/GameManager.cs
Normal file
20
Assets/Scripts/Runtime/GameManager.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : SingletonBehaviour<GameManager>
|
||||
{
|
||||
public GameObject MainCanvasUI;
|
||||
public Camera MainCamera;
|
||||
public Camera UICamera;
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(MainCanvasUI);
|
||||
DontDestroyOnLoad(MainCamera);
|
||||
DontDestroyOnLoad(UICamera);
|
||||
}
|
||||
public bool HasNetwork()
|
||||
{
|
||||
return Application.internetReachability != NetworkReachability.NotReachable;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Runtime/GameManager.cs.meta
Normal file
11
Assets/Scripts/Runtime/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc5687e4bc5e6bd4a91f5b510565efec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/Runtime/KeyManager.cs
Normal file
21
Assets/Scripts/Runtime/KeyManager.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class KeyManager
|
||||
{
|
||||
public static string AssetDllDir = "Assets/GameRes/HotUpdate";
|
||||
public static string AssetEntityDir = "Assets/GameRes/Entity";
|
||||
public static string HybridCLRDataDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData";
|
||||
public static string HotDllSourceDir = $"{HybridCLRDataDir}/HotUpdateDlls";
|
||||
public static string TDllSourceDir = $"{HybridCLRDataDir}/AssembliesPostIl2CppStrip";
|
||||
public static string LoadDllKey(string dllName)
|
||||
{
|
||||
return $"{AssetDllDir}/{dllName}.dll.bytes";
|
||||
}
|
||||
public static string LoadPrefabKey(string prefabName)
|
||||
{
|
||||
return $"{AssetEntityDir}/{prefabName}.prefab";
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Runtime/KeyManager.cs.meta
Normal file
11
Assets/Scripts/Runtime/KeyManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 980c47b91ea1bf9469ac5fee0b4d95c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
152
Assets/Scripts/Runtime/PatchWindow.cs
Normal file
152
Assets/Scripts/Runtime/PatchWindow.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Video;
|
||||
public class PatchWindow : MonoBehaviour
|
||||
{
|
||||
public Text statusText;
|
||||
public Slider progressBar;
|
||||
public Text downloadSizeText;
|
||||
public VideoPlayer video;
|
||||
public Button actionButton;
|
||||
public Text buttonText;
|
||||
|
||||
private bool hasUpdate;
|
||||
private bool updateCompleted;
|
||||
private System.Action onUpdateComplete;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
video.targetCamera = GameManager.Inst.UICamera;
|
||||
actionButton.onClick.AddListener(OnActionButtonClick);
|
||||
}
|
||||
public void StartCheckUpdate(System.Action callback)
|
||||
{
|
||||
this.onUpdateComplete = callback;
|
||||
if (GameManager.Inst.HasNetwork())
|
||||
{
|
||||
StartCoroutine(CheckForCatalogUpdates());
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(ReadyStart("<22><><EFBFBD><EFBFBD><EFBFBD>磬ʹ<E7A3AC>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>Դ"));
|
||||
}
|
||||
}
|
||||
IEnumerator CheckForCatalogUpdates()
|
||||
{
|
||||
statusText.text = "<22><><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD><E5B5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...";
|
||||
var catalogHandle = Addressables.CheckForCatalogUpdates(false);
|
||||
yield return catalogHandle;
|
||||
if (catalogHandle.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
StartCoroutine(ReadyStart("<22><><EFBFBD><EFBFBD><EFBFBD>嵥<EFBFBD><E5B5A5><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>Դ"));
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
var catalogs = catalogHandle.Result;
|
||||
if (catalogs.Count > 0)
|
||||
{
|
||||
StartCoroutine(UpdateCatalogs(catalogs));
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(CheckNeedDownLoad());
|
||||
}
|
||||
}
|
||||
}
|
||||
IEnumerator UpdateCatalogs(List<string> catalogs)
|
||||
{
|
||||
statusText.text = "<22>嵥<EFBFBD><E5B5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...";
|
||||
var updateHandle = Addressables.UpdateCatalogs(catalogs, false);
|
||||
yield return updateHandle;
|
||||
if (updateHandle.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
StartCoroutine(ReadyStart("<22>嵥<EFBFBD><E5B5A5><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>Դ"));
|
||||
Addressables.Release(updateHandle);
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(CheckNeedDownLoad());
|
||||
}
|
||||
Addressables.Release(updateHandle);
|
||||
}
|
||||
IEnumerator CheckNeedDownLoad()
|
||||
{
|
||||
statusText.text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
var sizeHandle = Addressables.GetDownloadSizeAsync("preload");
|
||||
yield return sizeHandle;
|
||||
if (sizeHandle.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
StartCoroutine(ReadyStart("<22><>Դ<EFBFBD><D4B4><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>Դ"));
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
long downloadSize = sizeHandle.Result;
|
||||
if(downloadSize > 0)
|
||||
{
|
||||
hasUpdate = true;
|
||||
statusText.text = "<22>п<EFBFBD><D0BF>ø<EFBFBD><C3B8><EFBFBD>";
|
||||
downloadSizeText.text = $"<22><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>: {downloadSize / 1024f / 1024f:F1}MB";
|
||||
buttonText.text = "<22><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>";
|
||||
actionButton.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(ReadyStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
private IEnumerator Download()
|
||||
{
|
||||
statusText.text = "<22><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>...";
|
||||
progressBar.gameObject.SetActive(true);
|
||||
var downloadHandle = Addressables.DownloadDependenciesAsync("preload");
|
||||
while (!downloadHandle.IsDone)
|
||||
{
|
||||
float smoothProgress = Mathf.Lerp(progressBar.value, downloadHandle.PercentComplete, Time.deltaTime * 5f);
|
||||
progressBar.value = smoothProgress;
|
||||
var status = downloadHandle.GetDownloadStatus();
|
||||
downloadSizeText.text = $"{status.DownloadedBytes / 1024f / 1024f:F1}MB / {status.TotalBytes / 1024f / 1024f:F1}MB";
|
||||
yield return null;
|
||||
}
|
||||
if (downloadHandle.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
StartCoroutine(ReadyStart("<22><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>Դ"));
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(ReadyStart());
|
||||
}
|
||||
Addressables.Release(downloadHandle);
|
||||
}
|
||||
IEnumerator ReadyStart(string text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!")
|
||||
{
|
||||
yield return null;
|
||||
statusText.text = text;
|
||||
progressBar.value = 1f;
|
||||
updateCompleted = true;
|
||||
buttonText.text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ";
|
||||
actionButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnActionButtonClick()
|
||||
{
|
||||
if (hasUpdate && !updateCompleted)
|
||||
{
|
||||
StartCoroutine(Download());
|
||||
}
|
||||
else
|
||||
{
|
||||
onUpdateComplete?.Invoke();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
actionButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Runtime/PatchWindow.cs.meta
Normal file
11
Assets/Scripts/Runtime/PatchWindow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1307162eec63e749b95009246ee8f59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/Runtime/Singleton.cs
Normal file
30
Assets/Scripts/Runtime/Singleton.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class Singleton<T> where T : class, new()
|
||||
{
|
||||
protected Singleton() { }
|
||||
~Singleton() { singleton = null; }
|
||||
private static T singleton;
|
||||
private static readonly object locker = new object();
|
||||
public static T Inst
|
||||
{
|
||||
get
|
||||
{
|
||||
if (singleton == null)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
if (singleton == null)
|
||||
singleton = new T();
|
||||
Debug.Log($"Create {typeof(T)}");
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/Scripts/Runtime/Singleton.cs.meta
Normal file
11
Assets/Scripts/Runtime/Singleton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07bb4600bac3e6949a61c0cc16a3151f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/Runtime/SingletonBehaviour.cs
Normal file
24
Assets/Scripts/Runtime/SingletonBehaviour.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SingletonBehaviour<T> : MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
public static T Inst
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = FindAnyObjectByType<T>();
|
||||
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject singletonObject = new GameObject(typeof(T).Name);
|
||||
_instance = singletonObject.AddComponent<T>();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Runtime/SingletonBehaviour.cs.meta
Normal file
11
Assets/Scripts/Runtime/SingletonBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33b4b3e41e9aa7c44a53a27292c4ab51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/Runtime/UnityScripts.Runtime.asmdef
Normal file
18
Assets/Scripts/Runtime/UnityScripts.Runtime.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "UnityScripts.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||
"GUID:13ba8ce62aa80c74598530029cb2d649"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/Runtime/UnityScripts.Runtime.asmdef.meta
Normal file
7
Assets/Scripts/Runtime/UnityScripts.Runtime.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 231d2189f0e1fc546999766032d5c36d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user