mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 13:37:40 +02:00
add cursor toggle, master volume
This commit is contained in:
8
Assets/GUIWindows/Cursors.meta
Normal file
8
Assets/GUIWindows/Cursors.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e2cc9380e05e994ca36eafd84612971
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/GUIWindows/Cursors/cursor_diag_a.png
Normal file
BIN
Assets/GUIWindows/Cursors/cursor_diag_a.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 256 B |
96
Assets/GUIWindows/Cursors/cursor_diag_a.png.meta
Normal file
96
Assets/GUIWindows/Cursors/cursor_diag_a.png.meta
Normal file
@ -0,0 +1,96 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b69212126b91114ea8f0a926d77c519
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 1
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 1
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -3
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 7
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 1
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/GUIWindows/Cursors/cursor_diag_b.png
Normal file
BIN
Assets/GUIWindows/Cursors/cursor_diag_b.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 253 B |
96
Assets/GUIWindows/Cursors/cursor_diag_b.png.meta
Normal file
96
Assets/GUIWindows/Cursors/cursor_diag_b.png.meta
Normal file
@ -0,0 +1,96 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b62059c6b03f004db5a180b61188820
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 1
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 1
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -3
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 7
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 1
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/GUIWindows/Cursors/cursor_horizontal.png
Normal file
BIN
Assets/GUIWindows/Cursors/cursor_horizontal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 B |
96
Assets/GUIWindows/Cursors/cursor_horizontal.png.meta
Normal file
96
Assets/GUIWindows/Cursors/cursor_horizontal.png.meta
Normal file
@ -0,0 +1,96 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5704ce039ab9a4d41bce815832591a2f
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 1
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 1
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -3
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 7
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 1
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/GUIWindows/Cursors/cursor_vertical.png
Normal file
BIN
Assets/GUIWindows/Cursors/cursor_vertical.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 249 B |
96
Assets/GUIWindows/Cursors/cursor_vertical.png.meta
Normal file
96
Assets/GUIWindows/Cursors/cursor_vertical.png.meta
Normal file
@ -0,0 +1,96 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40a8ef17dc9780c4085eb2001e1c9ac1
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 1
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 1
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -3
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 0
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 7
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 1
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/GUIWindows/Resources.meta
Normal file
8
Assets/GUIWindows/Resources.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a10780de139895143a5169586497425c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3235
Assets/GUIWindows/Resources/WindowUIComponent.prefab
Normal file
3235
Assets/GUIWindows/Resources/WindowUIComponent.prefab
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e35aeb23d52d724cb7fe53502b35ed6
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/GUIWindows/Scripts.meta
Normal file
8
Assets/GUIWindows/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8883473590307544898c90d1e7efef00
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/GUIWindows/Scripts/Editor.meta
Normal file
8
Assets/GUIWindows/Scripts/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 074e01de92c223544965cecb3408cd66
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/GUIWindows/Scripts/Editor/GUIPointerObjectEditor.cs
Normal file
35
Assets/GUIWindows/Scripts/Editor/GUIPointerObjectEditor.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
[CustomEditor(typeof(GUIPointerObject))]
|
||||
[CanEditMultipleObjects]
|
||||
public class GUIPointerObjectEditor : Editor
|
||||
{
|
||||
|
||||
SerializedProperty onPointerUp;
|
||||
SerializedProperty onPointerDown;
|
||||
SerializedProperty onPointerEnter;
|
||||
SerializedProperty onPointerExit;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
onPointerUp = serializedObject.FindProperty("onPointerUp");
|
||||
onPointerDown = serializedObject.FindProperty("onPointerDown");
|
||||
onPointerEnter = serializedObject.FindProperty("onPointerEnter");
|
||||
onPointerExit = serializedObject.FindProperty("onPointerExit");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(onPointerUp);
|
||||
EditorGUILayout.PropertyField(onPointerDown);
|
||||
EditorGUILayout.PropertyField(onPointerEnter);
|
||||
EditorGUILayout.PropertyField(onPointerExit);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e208f13f49d1a4c42b716cbde5c0ba97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/GUIWindows/Scripts/GUIBorderParent.cs
Normal file
29
Assets/GUIWindows/Scripts/GUIBorderParent.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a reference to all GUIWindowHandle objects below this Transform for ease of referencing
|
||||
/// </summary>
|
||||
public class GUIBorderParent : MonoBehaviour
|
||||
{
|
||||
private GUIWindowHandle[] handles;
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
handles = GetComponentsInChildren<GUIWindowHandle>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle interactivity of handles
|
||||
/// </summary>
|
||||
/// <param name="input">is interactive</param>
|
||||
public void SetIsLocked(bool input)
|
||||
{
|
||||
for (int i = 0; i < handles.Length; i++)
|
||||
{
|
||||
handles[i].SetIsLocked(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIBorderParent.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIBorderParent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7522e6e31c695a24eab781c580d37a59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
66
Assets/GUIWindows/Scripts/GUIPointerObject.cs
Normal file
66
Assets/GUIWindows/Scripts/GUIPointerObject.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains events referencing IPointerHandlers
|
||||
/// </summary>
|
||||
public class GUIPointerObject : MonoBehaviour, IPointerUpHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Fires when a pointer up is detected
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
[Tooltip("Fires when a pointer up is detected")]
|
||||
public UnityEvent onPointerUp = null;
|
||||
/// <summary>
|
||||
/// Fires when a pointer down is detected
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
[Tooltip("Fires when a pointer down is detected")]
|
||||
public UnityEvent onPointerDown = null;
|
||||
/// <summary>
|
||||
/// Fires when a pointer enter is detected
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
[Tooltip("Fires when a pointer enter is detected")]
|
||||
public UnityEvent onPointerEnter = null;
|
||||
/// <summary>
|
||||
/// Fires when a pointer exit is detected
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
[Tooltip("Fires when a pointer exit is detected")]
|
||||
public UnityEvent onPointerExit = null;
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (onPointerUp != null)
|
||||
{
|
||||
onPointerUp.Invoke();
|
||||
}
|
||||
}
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (onPointerDown != null)
|
||||
{
|
||||
onPointerDown.Invoke();
|
||||
}
|
||||
}
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (onPointerEnter != null)
|
||||
{
|
||||
onPointerEnter.Invoke();
|
||||
}
|
||||
}
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (onPointerExit != null)
|
||||
{
|
||||
onPointerExit.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIPointerObject.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIPointerObject.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4817080b0d03dd846b5ee72dfd97c993
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Assets/GUIWindows/Scripts/GUIWindow.cs
Normal file
18
Assets/GUIWindows/Scripts/GUIWindow.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple script to destroy the target GameObject when window is closed
|
||||
/// </summary>
|
||||
public class GUIWindow : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Close window by destroying this GameObject
|
||||
/// </summary>
|
||||
public void CloseWindow()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIWindow.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIWindow.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53f10846845fcf9489fc69eccfbd24c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
186
Assets/GUIWindows/Scripts/GUIWindowExpander.cs
Normal file
186
Assets/GUIWindows/Scripts/GUIWindowExpander.cs
Normal file
@ -0,0 +1,186 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Script to handle expanding and restoring a window to/from screen size
|
||||
/// </summary>
|
||||
public class GUIWindowExpander : GUIPointerObject
|
||||
{
|
||||
|
||||
private const float MaxTimeForDoubleClick = 0.5f;
|
||||
/// <summary>
|
||||
/// Window to apply expand effect to
|
||||
/// </summary>
|
||||
[Tooltip("")]
|
||||
[SerializeField] private RectTransform parentWindow = null;
|
||||
/// <summary>
|
||||
/// Expander is locked and unusable
|
||||
/// </summary>
|
||||
[Tooltip("")]
|
||||
[SerializeField] private bool isLocked = false;
|
||||
/// <summary>
|
||||
/// Allows you to double click this target image to minimise/maximise
|
||||
/// </summary>
|
||||
[Tooltip("Allows you to double click this target image to minimise/maximise")]
|
||||
[SerializeField] private bool doubleClick = true;
|
||||
/// <summary>
|
||||
/// Fires when window starts restoring to a smaller size
|
||||
/// </summary>
|
||||
public UnityEvent onMinimised = null;
|
||||
/// <summary>
|
||||
/// Fires when window starts expanding
|
||||
/// </summary>
|
||||
public UnityEvent onMaximised = null;
|
||||
|
||||
private bool isMaximised = false;
|
||||
private bool doAction = false;
|
||||
|
||||
private Vector2 initialPosition;
|
||||
private Vector2 initialMinAnchor;
|
||||
private Vector2 initialMaxAnchor;
|
||||
private Vector2 initialSize;
|
||||
private Vector2 initialPivot = Vector2.one * -1;
|
||||
|
||||
private Vector2 targetPosition;
|
||||
private Vector2 targetSize;
|
||||
|
||||
private int numClicks;
|
||||
|
||||
void Start()
|
||||
{
|
||||
onPointerDown.AddListener(parentWindow.SetAsLastSibling);
|
||||
onPointerDown.AddListener(TryDoubleClick);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (doAction)
|
||||
{
|
||||
// Lerp to position & size
|
||||
parentWindow.sizeDelta = Vector2.MoveTowards(parentWindow.sizeDelta, targetSize, Time.deltaTime * 10000);
|
||||
parentWindow.anchoredPosition = Vector2.MoveTowards(parentWindow.anchoredPosition, targetPosition, Time.deltaTime * 5000);
|
||||
// reached target
|
||||
if (parentWindow.sizeDelta == targetSize && parentWindow.anchoredPosition == targetPosition)
|
||||
{
|
||||
doAction = false;
|
||||
if (isMaximised)
|
||||
{ // set to a full stretched rect
|
||||
parentWindow.anchorMin = Vector2.zero;
|
||||
parentWindow.anchorMax = Vector2.one;
|
||||
parentWindow.sizeDelta = Vector2.zero;
|
||||
parentWindow.anchoredPosition = Vector2.zero;
|
||||
if (onMaximised != null)
|
||||
{
|
||||
onMaximised.Invoke();
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // just invoke the event for a minimised window
|
||||
if (onMinimised != null)
|
||||
{
|
||||
onMinimised.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle interactivity of expander
|
||||
/// </summary>
|
||||
/// <param name="input">is interactive</param>
|
||||
public void SetIsLocked(bool input)
|
||||
{
|
||||
isLocked = input;
|
||||
parentWindow.SetAsLastSibling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set window to fill screen
|
||||
/// </summary>
|
||||
public void MaximiseWindow()
|
||||
{
|
||||
if (isLocked) return;
|
||||
|
||||
initialPosition = parentWindow.anchoredPosition;
|
||||
initialMinAnchor = parentWindow.anchorMin;
|
||||
initialMaxAnchor = parentWindow.anchorMax;
|
||||
initialSize = parentWindow.sizeDelta;
|
||||
initialPivot = parentWindow.pivot;
|
||||
|
||||
parentWindow.SetPivot(Vector2.one * 0.5f);
|
||||
|
||||
targetPosition = Vector2.zero;
|
||||
targetSize = new Vector2(Screen.width, Screen.height);
|
||||
|
||||
isMaximised = true;
|
||||
doAction = true;
|
||||
parentWindow.SetAsLastSibling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set window to small size
|
||||
/// </summary>
|
||||
public void MinimiseWindow()
|
||||
{
|
||||
if (isLocked) return;
|
||||
parentWindow.anchorMin = initialMinAnchor;
|
||||
parentWindow.anchorMax = initialMaxAnchor;
|
||||
|
||||
parentWindow.sizeDelta = new Vector2(Screen.width, Screen.height);
|
||||
|
||||
if (initialPivot != Vector2.one * -1)
|
||||
{
|
||||
parentWindow.SetPivot(initialPivot);
|
||||
}
|
||||
|
||||
targetPosition = initialPosition;
|
||||
targetSize = initialSize;
|
||||
|
||||
isMaximised = false;
|
||||
doAction = true;
|
||||
parentWindow.SetAsLastSibling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do a click for attempting to expand by double click
|
||||
/// </summary>
|
||||
public void TryDoubleClick()
|
||||
{
|
||||
parentWindow.SetAsLastSibling();
|
||||
if (isLocked || !doubleClick) return;
|
||||
numClicks++;
|
||||
if (numClicks == 1)
|
||||
{
|
||||
Invoke("ResetDoubleClick", MaxTimeForDoubleClick);
|
||||
}
|
||||
else if (numClicks >= 2)
|
||||
{
|
||||
Invoke("Swap", 0.1f); // wait in case we're interrupting a mover
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swap between minimised and maximised
|
||||
/// </summary>
|
||||
public void Swap()
|
||||
{
|
||||
if (isMaximised)
|
||||
{
|
||||
MinimiseWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
MaximiseWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetDoubleClick()
|
||||
{
|
||||
numClicks = 0;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIWindowExpander.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIWindowExpander.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14001084fe201b84d9804ee3eafd2b7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
278
Assets/GUIWindows/Scripts/GUIWindowHandle.cs
Normal file
278
Assets/GUIWindows/Scripts/GUIWindowHandle.cs
Normal file
@ -0,0 +1,278 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Script to handle pull handles to expand the windows
|
||||
/// </summary>
|
||||
public class GUIWindowHandle : GUIPointerObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Window to apply pull effect to
|
||||
/// </summary>
|
||||
[Tooltip("Window to apply pull effect to")]
|
||||
[SerializeField] private RectTransform parentWindow = null;
|
||||
/// <summary>
|
||||
/// Handle is locked and unusable
|
||||
/// </summary>
|
||||
[Tooltip("Handle is locked and unusable")]
|
||||
[SerializeField] private bool isLocked = false;
|
||||
/// <summary>
|
||||
/// Minimum width parent window can be set to
|
||||
/// </summary>
|
||||
[Tooltip("Minimum width parent window can be set to")]
|
||||
[SerializeField] private float minWidth = 50;
|
||||
/// <summary>
|
||||
/// Minimum height parent window can be set to
|
||||
/// </summary>
|
||||
[Tooltip("Minimum height parent window can be set to")]
|
||||
[SerializeField] private float minHeight = 50;
|
||||
/// <summary>
|
||||
/// Sprite to show for cursor when this handle is highlighted
|
||||
/// </summary>
|
||||
[Tooltip("Sprite to show for cursor when this handle is highlighted")]
|
||||
[SerializeField] private Texture2D cursor = null;
|
||||
/// <summary>
|
||||
/// Directional axis to pull window with this handle
|
||||
/// </summary>
|
||||
[Tooltip("Directional axis to pull window with this handle")]
|
||||
[SerializeField] private Axis axis = Axis.Horizontal;
|
||||
/// <summary>
|
||||
/// Fired when user pulls on the handle
|
||||
/// </summary>
|
||||
public UnityEvent onWindowPulled = null;
|
||||
|
||||
Direction direction;
|
||||
private bool isGrabbed = false;
|
||||
|
||||
|
||||
private Vector2 initialMousePos;
|
||||
private Vector2 initialSize;
|
||||
private Vector2 initialPivot;
|
||||
|
||||
void Start()
|
||||
{
|
||||
//register to pointer events
|
||||
onPointerDown.AddListener(SetIsGrabbed);
|
||||
onPointerDown.AddListener(parentWindow.SetAsLastSibling);
|
||||
// onPointerEnter.AddListener(ShowCursor);
|
||||
// onPointerExit.AddListener(ResetCursor);
|
||||
|
||||
// find what direction we're pulling with this handle
|
||||
switch (axis)
|
||||
{
|
||||
|
||||
case Axis.Horizontal:
|
||||
if (transform.position.x > parentWindow.position.x)
|
||||
{
|
||||
direction = Direction.Right;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = Direction.Left;
|
||||
}
|
||||
break;
|
||||
|
||||
case Axis.Vertical:
|
||||
if (transform.position.y > parentWindow.position.y)
|
||||
{
|
||||
direction = Direction.Up;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = Direction.Down;
|
||||
}
|
||||
break;
|
||||
|
||||
case Axis.Diagonal:
|
||||
if (transform.position.y > parentWindow.position.y)
|
||||
{
|
||||
if (transform.position.x > parentWindow.position.x)
|
||||
{
|
||||
direction = Direction.UpRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = Direction.UpLeft;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (transform.position.x > parentWindow.position.x)
|
||||
{
|
||||
direction = Direction.DownRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = Direction.DownLeft;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isGrabbed)
|
||||
return;
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
isGrabbed = false;
|
||||
parentWindow.SetPivot(initialPivot);
|
||||
if (onWindowPulled != null)
|
||||
{
|
||||
onWindowPulled.Invoke();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 scaleOffset = (Vector2.one - (Vector2)transform.lossyScale) + Vector2.one;
|
||||
Vector2 parentScale = parentWindow.transform.parent.GetComponent<RectTransform>().rect.size;
|
||||
Vector2 mouseDelta = Vector2.Scale((Vector2)Camera.main.ScreenToWorldPoint(GUIWindowUtils.MousePosition()) - initialMousePos, scaleOffset*parentScale);
|
||||
Vector2 size = initialSize;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
size += new Vector2(0, mouseDelta.y);
|
||||
break;
|
||||
case Direction.Down:
|
||||
size -= new Vector2(0, mouseDelta.y);
|
||||
break;
|
||||
case Direction.Left:
|
||||
size -= new Vector2(mouseDelta.x, 0);
|
||||
break;
|
||||
case Direction.Right:
|
||||
size += new Vector2(mouseDelta.x, 0);
|
||||
break;
|
||||
case Direction.UpRight:
|
||||
size += new Vector2(mouseDelta.x, mouseDelta.y);
|
||||
break;
|
||||
case Direction.UpLeft:
|
||||
size += new Vector2(-mouseDelta.x, mouseDelta.y);
|
||||
break;
|
||||
case Direction.DownRight:
|
||||
size += new Vector2(mouseDelta.x, -mouseDelta.y);
|
||||
break;
|
||||
case Direction.DownLeft:
|
||||
size += new Vector2(-mouseDelta.x, -mouseDelta.y);
|
||||
break;
|
||||
}
|
||||
|
||||
// Keep Window within minimum size
|
||||
if (size.x < minWidth || size.y < minHeight)
|
||||
{
|
||||
Vector2 newsize = size;
|
||||
if (size.x < minWidth)
|
||||
{
|
||||
newsize.x = minWidth;
|
||||
}
|
||||
if (size.y < minHeight)
|
||||
{
|
||||
newsize.y = minHeight;
|
||||
}
|
||||
parentWindow.sizeDelta = newsize;
|
||||
return;
|
||||
}
|
||||
|
||||
// set position & size
|
||||
parentWindow.sizeDelta = size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle interactivity of handle
|
||||
/// </summary>
|
||||
/// <param name="input">is interactive</param>
|
||||
public void SetIsLocked(bool input)
|
||||
{
|
||||
isLocked = input;
|
||||
parentWindow.SetAsLastSibling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trigger that this handle has been grabbed
|
||||
/// </summary>
|
||||
public void SetIsGrabbed()
|
||||
{
|
||||
if (isLocked) return;
|
||||
isGrabbed = true;
|
||||
|
||||
initialMousePos = Camera.main.ScreenToWorldPoint(GUIWindowUtils.MousePosition());
|
||||
initialSize = parentWindow.sizeDelta;
|
||||
initialPivot = parentWindow.pivot;
|
||||
|
||||
// Set Pivot to correct value based on direction so we don't need to offset movement
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Up:
|
||||
parentWindow.SetPivot(new Vector2(0.5f, 0));
|
||||
break;
|
||||
case Direction.Down:
|
||||
parentWindow.SetPivot(new Vector2(0.5f, 1));
|
||||
break;
|
||||
case Direction.Left:
|
||||
parentWindow.SetPivot(new Vector2(1, 0.5f));
|
||||
break;
|
||||
case Direction.Right:
|
||||
parentWindow.SetPivot(new Vector2(0, 0.5f));
|
||||
break;
|
||||
case Direction.UpRight:
|
||||
parentWindow.SetPivot(new Vector2(0, 0));
|
||||
break;
|
||||
case Direction.UpLeft:
|
||||
parentWindow.SetPivot(new Vector2(1, 0));
|
||||
break;
|
||||
case Direction.DownRight:
|
||||
parentWindow.SetPivot(new Vector2(0, 1));
|
||||
break;
|
||||
case Direction.DownLeft:
|
||||
parentWindow.SetPivot(new Vector2(1, 1));
|
||||
break;
|
||||
}
|
||||
parentWindow.SetAsLastSibling();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the changed cursor when this handle is highlighted
|
||||
/// </summary>
|
||||
public void ShowCursor()
|
||||
{
|
||||
if (!isLocked && cursor != null)
|
||||
{
|
||||
Cursor.SetCursor(cursor, new Vector2(16, 16), CursorMode.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the cursor to the default state
|
||||
/// </summary>
|
||||
public void ResetCursor()
|
||||
{
|
||||
if (cursor != null)
|
||||
{
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
private enum Axis
|
||||
{
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Diagonal
|
||||
}
|
||||
|
||||
private enum Direction
|
||||
{
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
UpLeft,
|
||||
UpRight,
|
||||
DownLeft,
|
||||
DownRight
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIWindowHandle.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIWindowHandle.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff5cd5446e2fdea43a48057e3e0e0b8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
70
Assets/GUIWindows/Scripts/GUIWindowMover.cs
Normal file
70
Assets/GUIWindows/Scripts/GUIWindowMover.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Script to handle moving windows
|
||||
/// </summary>
|
||||
public class GUIWindowMover : GUIPointerObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Window to move
|
||||
/// </summary>
|
||||
[Tooltip("Window to move")]
|
||||
[SerializeField] private RectTransform parentWindow = null;
|
||||
/// <summary>
|
||||
/// Mover is locked and unusable
|
||||
/// </summary>
|
||||
[Tooltip("Mover is locked and unusable")]
|
||||
[SerializeField] private bool isLocked = false;
|
||||
/// <summary>
|
||||
/// Fires when a window has been moved
|
||||
/// </summary>
|
||||
[Tooltip("Fires when a window has been moved")]
|
||||
[SerializeField] private UnityEvent onWindowMoved = null;
|
||||
|
||||
private Vector2 mouseOffset;
|
||||
private bool isGrabbed = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
onPointerDown.AddListener(SetIsGrabbed);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isGrabbed || isLocked) return;
|
||||
|
||||
parentWindow.position = (Vector2)GUIWindowUtils.MousePosition() + mouseOffset;
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
isGrabbed = false;
|
||||
if (onWindowMoved != null)
|
||||
{
|
||||
onWindowMoved.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle interactivity of handle
|
||||
/// </summary>
|
||||
/// <param name="input">is interactive</param>
|
||||
public void SetIsLocked(bool input)
|
||||
{
|
||||
isLocked = input;
|
||||
isGrabbed = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trigger that window has started to be moved
|
||||
/// </summary>
|
||||
public void SetIsGrabbed()
|
||||
{
|
||||
mouseOffset = parentWindow.position - GUIWindowUtils.MousePosition();
|
||||
isGrabbed = true;
|
||||
parentWindow.SetAsLastSibling();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIWindowMover.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIWindowMover.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc20c44b0e31b64193a5ccaa228b5f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
67
Assets/GUIWindows/Scripts/GUIWindowUtils.cs
Normal file
67
Assets/GUIWindows/Scripts/GUIWindowUtils.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
namespace Rellac.Windows
|
||||
{
|
||||
public static class GUIWindowUtils
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[MenuItem("GameObject/UI/Window")]
|
||||
public static void InstantiateWindow()
|
||||
{
|
||||
NewWindow();
|
||||
}
|
||||
#endif
|
||||
|
||||
public static GameObject NewWindow()
|
||||
{
|
||||
Object prefab = Resources.Load("WindowUIComponent");
|
||||
Canvas canvas = GameObject.FindObjectOfType<Canvas>();
|
||||
if (canvas == null)
|
||||
{
|
||||
// Create default canvas
|
||||
GameObject newCanvas = new GameObject("Canvas");
|
||||
canvas = newCanvas.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
newCanvas.AddComponent<CanvasScaler>();
|
||||
newCanvas.AddComponent<GraphicRaycaster>();
|
||||
if (GameObject.FindObjectOfType<EventSystem>() == null)
|
||||
{
|
||||
// Create defalut EventSystem
|
||||
new GameObject("EventSystem").AddComponent<EventSystem>(). // create new GameObject with EventSystem
|
||||
gameObject.AddComponent<StandaloneInputModule>() // add Input Module
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
; // we don't need the Touch Input Module at 5.3+
|
||||
#else
|
||||
.gameObject.AddComponent<TouchInputModule>();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
GameObject go = (GameObject)GameObject.Instantiate(prefab);
|
||||
go.transform.SetParent(canvas.transform);
|
||||
go.transform.localPosition = Vector2.zero;
|
||||
go.name = "Window";
|
||||
return go;
|
||||
}
|
||||
|
||||
public static void SetPivot(this RectTransform rectTransform, Vector2 pivot)
|
||||
{
|
||||
if (rectTransform == null) return;
|
||||
|
||||
Vector2 size = rectTransform.rect.size;
|
||||
Vector2 deltaPivot = rectTransform.pivot - pivot;
|
||||
Vector3 deltaPosition = new Vector3(deltaPivot.x * size.x, deltaPivot.y * size.y);
|
||||
rectTransform.pivot = pivot;
|
||||
rectTransform.localPosition -= deltaPosition;
|
||||
}
|
||||
|
||||
public static Vector3 MousePosition()
|
||||
{
|
||||
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
return new Vector3(mousePos.x, mousePos.y, 0);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUIWindows/Scripts/GUIWindowUtils.cs.meta
Normal file
11
Assets/GUIWindows/Scripts/GUIWindowUtils.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f1db78fc458ea44ebcab0c6ce456cfe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user