import successful, grid has visuals

cell values and grid lines are displayed. no interaction available yet.
This commit is contained in:
Simon O'Shea
2023-07-31 18:45:01 -04:00
parent 4699ce7287
commit 5f9e8f979d
56 changed files with 4851 additions and 7 deletions
@@ -0,0 +1,46 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CodeMonkey {
/*
* Global Asset references
* Edit Asset references in the prefab CodeMonkey/Resources/CodeMonkeyAssets
* */
public class Assets : MonoBehaviour {
// Internal instance reference
private static Assets _i;
// Instance reference
public static Assets i {
get {
if (_i == null) _i = Instantiate(Resources.Load<Assets>("CodeMonkeyAssets"));
return _i;
}
}
// All references
public Sprite s_White;
public Sprite s_Circle;
public Material m_White;
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: eda7ff5f6e8175c4da119ea9ed256f6d
timeCreated: 1524393850
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 87d70cfb1e610ac4dadb3551cb1dc28b
folderAsset: yes
timeCreated: 1524395615
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

@@ -0,0 +1,92 @@
fileFormatVersion: 2
guid: a0e35f6b808bb7447826cc6c69ffe448
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: White_1x1
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 170577bce7cbda144b82578f81308d23, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7d5e8e2c082a4c44a9abd7d650cf0a15
timeCreated: 1527582754
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@@ -0,0 +1,104 @@
fileFormatVersion: 2
guid: 170577bce7cbda144b82578f81308d23
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 0
spriteMeshType: 0
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 1
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,173 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
using CodeMonkey.Utils;
namespace CodeMonkey {
/*
* Debug Class with various helper functions to quickly create buttons, text, etc
* */
public static class CMDebug {
// Creates a Button in the World
public static World_Sprite Button(Transform parent, Vector3 localPosition, string text, System.Action ClickFunc, int fontSize = 30, float paddingX = 5, float paddingY = 5) {
return World_Sprite.CreateDebugButton(parent, localPosition, text, ClickFunc, fontSize, paddingX, paddingY);
}
// Creates a Button in the UI
public static UI_Sprite ButtonUI(Vector2 anchoredPosition, string text, Action ClickFunc) {
return UI_Sprite.CreateDebugButton(anchoredPosition, text, ClickFunc);
}
public static UI_Sprite ButtonUI(Transform parent, Vector2 anchoredPosition, string text, Action ClickFunc) {
return UI_Sprite.CreateDebugButton(parent, anchoredPosition, text, ClickFunc);
}
// Creates a World Text object at the world position
public static void Text(string text, Vector3 localPosition = default(Vector3), Transform parent = null, int fontSize = 40, Color? color = null, TextAnchor textAnchor = TextAnchor.UpperLeft, TextAlignment textAlignment = TextAlignment.Left, int sortingOrder = UtilsClass.sortingOrderDefault) {
UtilsClass.CreateWorldText(text, parent, localPosition, fontSize, color, textAnchor, textAlignment, sortingOrder);
}
// World text pop up at mouse position
public static void TextPopupMouse(string text, Vector3? offset = null) {
if (offset == null) {
offset = Vector3.one;
}
UtilsClass.CreateWorldTextPopup(text, UtilsClass.GetMouseWorldPosition() + (Vector3)offset);
}
// World text pop up at mouse position
public static void TextPopupMouse(object obj, Vector3? offset = null) {
TextPopupMouse(obj.ToString(), offset);
}
// Creates a Text pop up at the world position
public static void TextPopup(string text, Vector3 position, float popupTime = 1f) {
UtilsClass.CreateWorldTextPopup(text, position, popupTime);
}
// Text Updater in World, (parent == null) = world position
public static FunctionUpdater TextUpdater(Func<string> GetTextFunc, Vector3 localPosition, Transform parent = null, int fontSize = 40, Color? color = null, TextAnchor textAnchor = TextAnchor.UpperLeft, TextAlignment textAlignment = TextAlignment.Left, int sortingOrder = UtilsClass.sortingOrderDefault) {
return UtilsClass.CreateWorldTextUpdater(GetTextFunc, localPosition, parent, fontSize, color, textAnchor, textAlignment, sortingOrder);
}
// Text Updater in UI
public static FunctionUpdater TextUpdaterUI(Func<string> GetTextFunc, Vector2 anchoredPosition) {
return UtilsClass.CreateUITextUpdater(GetTextFunc, anchoredPosition);
}
// Text Updater always following mouse
public static void MouseTextUpdater(Func<string> GetTextFunc, Vector3 positionOffset = default(Vector3)) {
GameObject gameObject = new GameObject();
FunctionUpdater.Create(() => {
gameObject.transform.position = UtilsClass.GetMouseWorldPosition() + positionOffset;
return false;
});
TextUpdater(GetTextFunc, Vector3.zero, gameObject.transform);
}
// Trigger Action on Key
public static FunctionUpdater KeyCodeAction(KeyCode keyCode, Action onKeyDown) {
return UtilsClass.CreateKeyCodeAction(keyCode, onKeyDown);
}
// Debug DrawLine to draw a projectile, turn Gizmos On
public static void DebugProjectile(Vector3 from, Vector3 to, float speed, float projectileSize) {
Vector3 dir = (to - from).normalized;
Vector3 pos = from;
FunctionUpdater.Create(() => {
Debug.DrawLine(pos, pos + dir * projectileSize);
float distanceBefore = Vector3.Distance(pos, to);
pos += dir * speed * Time.deltaTime;
float distanceAfter = Vector3.Distance(pos, to);
if (distanceBefore < distanceAfter) {
return true;
}
return false;
});
}
public static void SpritePopupMouse(Sprite sprite, float scale = 1f) {
SpritePopup(UtilsClass.GetMouseWorldPosition(), sprite, scale);
}
public static void SpritePopup(Vector3 position, Sprite sprite, float scale) {
float popupTime = 1f;
GameObject gameObject = DrawSpriteTimedAlpha(position, sprite, scale, popupTime);
Vector3 finalPopupPosition = position + new Vector3(0, 1, 0) * 20f;
Transform transform = gameObject.transform;
Vector3 moveAmount = (finalPopupPosition - position) / popupTime;
FunctionUpdater.Create(delegate () {
if (gameObject == null) {
return true;
}
transform.position += moveAmount * Time.unscaledDeltaTime;
return false;
}, "SpritePopup");
}
public static GameObject DrawSpriteTimed(Sprite sprite, float scale, float timer) {
return DrawSpriteTimed(UtilsClass.GetMouseWorldPosition(), sprite, scale, timer);
}
public static GameObject DrawSpriteTimed(Vector3 position, Sprite sprite, float scale, float timer) {
GameObject gameObject = new GameObject("SpriteTimed", typeof(SpriteRenderer));
gameObject.transform.position = position;
gameObject.transform.localScale = Vector3.one * scale;
gameObject.GetComponent<SpriteRenderer>().sprite = sprite;
GameObject.Destroy(gameObject, timer);
return gameObject;
}
public static GameObject DrawSpriteTimedAlpha(Sprite sprite, float scale, float timer, float startDecayTimeNormalized = .8f) {
return DrawSpriteTimedAlpha(UtilsClass.GetMouseWorldPosition(), sprite, scale, timer, startDecayTimeNormalized);
}
public static GameObject DrawSpriteTimedAlpha(Vector3 position, Sprite sprite, float scale, float timer, float startDecayTimeNormalized = .8f) {
GameObject gameObject = DrawSpriteTimed(position, sprite, scale, timer);
SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
float startAlphaDecayTime = timer * startDecayTimeNormalized;
float totalAlphaDecayTime = timer - startAlphaDecayTime;
float currentTime = 0f;
FunctionUpdater.Create(() => {
if (gameObject == null) {
return true;
}
currentTime += Time.unscaledDeltaTime;
if (currentTime >= startAlphaDecayTime) {
spriteRenderer.color = new Color(1, 1, 1, Mathf.Lerp(1f, 0f, 1 - ((timer - currentTime) / totalAlphaDecayTime)));
}
return false;
});
return gameObject;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d6005648898e7f647ad2202fe256c311
timeCreated: 1524945727
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5abf4c77cbf61d94995a40be42eeaee0
folderAsset: yes
timeCreated: 1527582733
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,117 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using System.Collections.Generic;
using UnityEngine;
namespace CodeMonkey.MonoBehaviours {
/*
* Script to handle Camera Movement and Zoom
* Place on Camera GameObject
* */
public class CameraFollow : MonoBehaviour {
public static CameraFollow Instance { get; private set; }
private Camera myCamera;
private Func<Vector3> GetCameraFollowPositionFunc;
private Func<float> GetCameraZoomFunc;
public void Setup(Func<Vector3> GetCameraFollowPositionFunc, Func<float> GetCameraZoomFunc, bool teleportToFollowPosition, bool instantZoom) {
this.GetCameraFollowPositionFunc = GetCameraFollowPositionFunc;
this.GetCameraZoomFunc = GetCameraZoomFunc;
if (teleportToFollowPosition) {
Vector3 cameraFollowPosition = GetCameraFollowPositionFunc();
cameraFollowPosition.z = transform.position.z;
transform.position = cameraFollowPosition;
}
if (instantZoom) {
myCamera.orthographicSize = GetCameraZoomFunc();
}
}
private void Awake() {
Instance = this;
myCamera = transform.GetComponent<Camera>();
}
public void SetCameraFollowPosition(Vector3 cameraFollowPosition) {
SetGetCameraFollowPositionFunc(() => cameraFollowPosition);
}
public void SetGetCameraFollowPositionFunc(Func<Vector3> GetCameraFollowPositionFunc) {
this.GetCameraFollowPositionFunc = GetCameraFollowPositionFunc;
}
public void SetCameraZoom(float cameraZoom) {
SetGetCameraZoomFunc(() => cameraZoom);
}
public void SetGetCameraZoomFunc(Func<float> GetCameraZoomFunc) {
this.GetCameraZoomFunc = GetCameraZoomFunc;
}
private void Update() {
HandleMovement();
HandleZoom();
}
private void HandleMovement() {
if (GetCameraFollowPositionFunc == null) return;
Vector3 cameraFollowPosition = GetCameraFollowPositionFunc();
cameraFollowPosition.z = transform.position.z;
Vector3 cameraMoveDir = (cameraFollowPosition - transform.position).normalized;
float distance = Vector3.Distance(cameraFollowPosition, transform.position);
float cameraMoveSpeed = 3f;
if (distance > 0) {
Vector3 newCameraPosition = transform.position + cameraMoveDir * distance * cameraMoveSpeed * Time.deltaTime;
float distanceAfterMoving = Vector3.Distance(newCameraPosition, cameraFollowPosition);
if (distanceAfterMoving > distance) {
// Overshot the target
newCameraPosition = cameraFollowPosition;
}
transform.position = newCameraPosition;
}
}
private void HandleZoom() {
if (GetCameraZoomFunc == null) return;
float cameraZoom = GetCameraZoomFunc();
float cameraZoomDifference = cameraZoom - myCamera.orthographicSize;
float cameraZoomSpeed = 1f;
myCamera.orthographicSize += cameraZoomDifference * cameraZoomSpeed * Time.deltaTime;
if (cameraZoomDifference > 0) {
if (myCamera.orthographicSize > cameraZoom) {
myCamera.orthographicSize = cameraZoom;
}
} else {
if (myCamera.orthographicSize < cameraZoom) {
myCamera.orthographicSize = cameraZoom;
}
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f73a3eab49f30d344a207d7d3d931d98
timeCreated: 1527867131
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,37 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System.Collections.Generic;
using UnityEngine;
namespace CodeMonkey.MonoBehaviours {
/*
* Easy set up for CameraFollow, it will follow the transform with zoom
* */
public class CameraFollowSetup : MonoBehaviour {
[SerializeField] private CameraFollow cameraFollow = null;
[SerializeField] private Transform followTransform = null;
[SerializeField] private float zoom = 50f;
private void Start() {
if (followTransform == null) {
Debug.LogError("followTransform is null! Intended?");
cameraFollow.Setup(() => Vector3.zero, () => zoom, true, true);
} else {
cameraFollow.Setup(() => followTransform.position, () => zoom, true, true);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 31e947e7eb3216d40b72c592fa6847a3
timeCreated: 1527867131
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,60 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
namespace CodeMonkey.MonoBehaviours {
/*
* Trigger Actions on MonoBehaviour Component events
* */
public class ComponentActions : MonoBehaviour {
public Action OnDestroyFunc;
public Action OnEnableFunc;
public Action OnDisableFunc;
public Action OnUpdate;
private void OnDestroy() {
if (OnDestroyFunc != null) OnDestroyFunc();
}
private void OnEnable() {
if (OnEnableFunc != null) OnEnableFunc();
}
private void OnDisable() {
if (OnDisableFunc != null) OnDisableFunc();
}
private void Update() {
if (OnUpdate != null) OnUpdate();
}
public static void CreateComponent(Action OnDestroyFunc = null, Action OnEnableFunc = null, Action OnDisableFunc = null, Action OnUpdate = null) {
GameObject gameObject = new GameObject("ComponentActions");
AddComponent(gameObject, OnDestroyFunc, OnEnableFunc, OnDisableFunc, OnUpdate);
}
public static void AddComponent(GameObject gameObject, Action OnDestroyFunc = null, Action OnEnableFunc = null, Action OnDisableFunc = null, Action OnUpdate = null) {
ComponentActions componentFuncs = gameObject.AddComponent<ComponentActions>();
componentFuncs.OnDestroyFunc = OnDestroyFunc;
componentFuncs.OnEnableFunc = OnEnableFunc;
componentFuncs.OnDisableFunc = OnDisableFunc;
componentFuncs.OnUpdate = OnUpdate;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cb3e855e7fda2944b91078893f9e8fd8
timeCreated: 1511794191
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using UnityEngine;
namespace CodeMonkey.MonoBehaviours {
/*
* Automatically sort a Renderer (SpriteRenderer, MeshRenderer) based on his Y position
* */
public class PositionRendererSorter : MonoBehaviour {
[SerializeField] private int sortingOrderBase = 5000; // This number should be higher than what any of your sprites will be on the position.y
[SerializeField] private int offset = 0;
[SerializeField] private bool runOnlyOnce = false;
private float timer;
private float timerMax = .1f;
private Renderer myRenderer;
private void Awake() {
myRenderer = gameObject.GetComponent<Renderer>();
}
private void LateUpdate() {
timer -= Time.deltaTime;
if (timer <= 0f) {
timer = timerMax;
myRenderer.sortingOrder = (int)(sortingOrderBase - transform.position.y - offset);
if (runOnlyOnce) {
Destroy(this);
}
}
}
public void SetOffset(int offset) {
this.offset = offset;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b330b302c69005c4f98a928f7d71b877
timeCreated: 1526502963
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
Version: 1.03
Date: 06-02-2021
Version: 1.02
Date: 01-06-2018
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f59bf2b41588bd44780fc5218f7864e1
timeCreated: 1526276062
licenseType: Pro
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9c480003fd87d3548ae91e921a89a579
folderAsset: yes
timeCreated: 1524394058
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,48 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1010336202903800
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4240258222200348}
- component: {fileID: 114165315123428144}
m_Layer: 0
m_Name: CodeMonkeyAssets
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4240258222200348
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1010336202903800}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 991.20996, y: 137.51582, z: 149.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &114165315123428144
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1010336202903800}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eda7ff5f6e8175c4da119ea9ed256f6d, type: 3}
m_Name:
m_EditorClassIdentifier:
s_White: {fileID: 21300000, guid: 170577bce7cbda144b82578f81308d23, type: 3}
s_Circle: {fileID: 21300000, guid: a0e35f6b808bb7447826cc6c69ffe448, type: 3}
m_White: {fileID: 2100000, guid: 7d5e8e2c082a4c44a9abd7d650cf0a15, type: 2}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6cb9ffb1fe7e89d4a890b91c62fa7e8b
timeCreated: 1524393897
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d900c58c01968cd42bb98e37d8e4d05c
folderAsset: yes
timeCreated: 1524300187
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,212 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
//#define SOUND_MANAGER // Has Sound_Manager in project
//#define CURSOR_MANAGER // Has Cursor_Manager in project
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.EventSystems;
namespace CodeMonkey.Utils {
/*
* Button Actions on a World BoxCollider
* */
public class Button_Sprite : MonoBehaviour {
private static Func<Camera> GetWorldCamera;
public static void SetGetWorldCamera(Func<Camera> GetWorldCamera) {
Button_Sprite.GetWorldCamera = GetWorldCamera;
}
public Action ClickFunc = null;
public Action MouseRightDownOnceFunc = null;
public Action MouseRightDownFunc = null;
public Action MouseRightUpFunc = null;
public Action MouseDownOnceFunc = null;
public Action MouseUpOnceFunc = null;
public Action MouseOverOnceFunc = null;
public Action MouseOutOnceFunc = null;
public Action MouseOverOnceTooltipFunc = null;
public Action MouseOutOnceTooltipFunc = null;
private bool draggingMouseRight;
private Vector3 mouseRightDragStart;
public Action<Vector3, Vector3> MouseRightDragFunc = null;
public Action<Vector3, Vector3> MouseRightDragUpdateFunc = null;
public bool triggerMouseRightDragOnEnter = false;
public enum HoverBehaviour {
Custom,
Change_Color,
Change_Image,
Change_SetActive,
}
public HoverBehaviour hoverBehaviourType = HoverBehaviour.Custom;
private Action hoverBehaviourFunc_Enter, hoverBehaviourFunc_Exit;
public Color hoverBehaviour_Color_Enter = new Color(1, 1, 1, 1), hoverBehaviour_Color_Exit = new Color(1, 1, 1, 1);
public SpriteRenderer hoverBehaviour_Image;
public Sprite hoverBehaviour_Sprite_Exit, hoverBehaviour_Sprite_Enter;
public bool hoverBehaviour_Move = false;
public Vector2 hoverBehaviour_Move_Amount = Vector2.zero;
private Vector3 posExit, posEnter;
public bool triggerMouseOutFuncOnClick = false;
public bool clickThroughUI = false;
private Action internalOnMouseDownFunc = null, internalOnMouseEnterFunc = null, internalOnMouseExitFunc = null;
#if SOUND_MANAGER
public Sound_Manager.Sound mouseOverSound, mouseClickSound;
#endif
#if CURSOR_MANAGER
public CursorManager.CursorType cursorMouseOver, cursorMouseOut;
#endif
public void SetHoverBehaviourChangeColor(Color colorOver, Color colorOut) {
hoverBehaviourType = HoverBehaviour.Change_Color;
hoverBehaviour_Color_Enter = colorOver;
hoverBehaviour_Color_Exit = colorOut;
if (hoverBehaviour_Image == null) hoverBehaviour_Image = transform.GetComponent<SpriteRenderer>();
hoverBehaviour_Image.color = hoverBehaviour_Color_Exit;
SetupHoverBehaviour();
}
void OnMouseDown() {
if (!clickThroughUI && IsPointerOverUI()) return; // Over UI!
if (internalOnMouseDownFunc != null) internalOnMouseDownFunc();
if (ClickFunc != null) ClickFunc();
if (MouseDownOnceFunc != null) MouseDownOnceFunc();
if (triggerMouseOutFuncOnClick) OnMouseExit();
}
public void Manual_OnMouseExit() {
OnMouseExit();
}
void OnMouseUp() {
if (MouseUpOnceFunc != null) MouseUpOnceFunc();
}
void OnMouseEnter() {
if (!clickThroughUI && IsPointerOverUI()) return; // Over UI!
if (internalOnMouseEnterFunc != null) internalOnMouseEnterFunc();
if (hoverBehaviour_Move) transform.localPosition = posEnter;
if (hoverBehaviourFunc_Enter != null) hoverBehaviourFunc_Enter();
if (MouseOverOnceFunc != null) MouseOverOnceFunc();
if (MouseOverOnceTooltipFunc != null) MouseOverOnceTooltipFunc();
}
void OnMouseExit() {
if (internalOnMouseExitFunc != null) internalOnMouseExitFunc();
if (hoverBehaviour_Move) transform.localPosition = posExit;
if (hoverBehaviourFunc_Exit != null) hoverBehaviourFunc_Exit();
if (MouseOutOnceFunc != null) MouseOutOnceFunc();
if (MouseOutOnceTooltipFunc != null) MouseOutOnceTooltipFunc();
}
void OnMouseOver() {
if (!clickThroughUI && IsPointerOverUI()) return; // Over UI!
if (Input.GetMouseButton(1)) {
if (MouseRightDownFunc != null) MouseRightDownFunc();
if (!draggingMouseRight && triggerMouseRightDragOnEnter) {
draggingMouseRight = true;
mouseRightDragStart = GetWorldPositionFromUI();
}
}
if (Input.GetMouseButtonDown(1)) {
draggingMouseRight = true;
mouseRightDragStart = GetWorldPositionFromUI();
if (MouseRightDownOnceFunc != null) MouseRightDownOnceFunc();
}
}
void Update() {
if (draggingMouseRight) {
if (MouseRightDragUpdateFunc != null) MouseRightDragUpdateFunc(mouseRightDragStart, GetWorldPositionFromUI());
}
if (Input.GetMouseButtonUp(1)) {
if (draggingMouseRight) {
draggingMouseRight = false;
if (MouseRightDragFunc != null) MouseRightDragFunc(mouseRightDragStart, GetWorldPositionFromUI());
}
if (MouseRightUpFunc != null) MouseRightUpFunc();
}
}
void Awake() {
if (GetWorldCamera == null) SetGetWorldCamera(() => Camera.main); // Set default World Camera
posExit = transform.localPosition;
posEnter = transform.localPosition + (Vector3)hoverBehaviour_Move_Amount;
SetupHoverBehaviour();
#if SOUND_MANAGER
// Sound Manager
internalOnMouseDownFunc += () => { if (mouseClickSound != Sound_Manager.Sound.None) Sound_Manager.PlaySound(mouseClickSound); };
internalOnMouseEnterFunc += () => { if (mouseOverSound != Sound_Manager.Sound.None) Sound_Manager.PlaySound(mouseOverSound); };
#endif
#if CURSOR_MANAGER
// Cursor Manager
internalOnMouseExitFunc += () => { if (cursorMouseOut != CursorManager.CursorType.None) CursorManager.SetCursor(cursorMouseOut); };
internalOnMouseEnterFunc += () => { if (cursorMouseOver != CursorManager.CursorType.None) CursorManager.SetCursor(cursorMouseOver); };
#endif
}
private void SetupHoverBehaviour() {
switch (hoverBehaviourType) {
case HoverBehaviour.Change_Color:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Exit; };
break;
case HoverBehaviour.Change_Image:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Exit; };
break;
case HoverBehaviour.Change_SetActive:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.gameObject.SetActive(true); };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.gameObject.SetActive(false); };
break;
}
}
private static Vector3 GetWorldPositionFromUI() {
Vector3 worldPosition = GetWorldCamera().ScreenToWorldPoint(Input.mousePosition);
return worldPosition;
}
private static bool IsPointerOverUI() {
if (EventSystem.current.IsPointerOverGameObject()) {
return true;
} else {
PointerEventData pe = new PointerEventData(EventSystem.current);
pe.position = Input.mousePosition;
List<RaycastResult> hits = new List<RaycastResult>();
EventSystem.current.RaycastAll(pe, hits);
return hits.Count > 0;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4771330f098d1db4898ad07204154d04
timeCreated: 1513255758
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,228 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
//#define SOUND_MANAGER // Has Sound_Manager in project
//#define CURSOR_MANAGER // Has Cursor_Manager in project
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace CodeMonkey.Utils {
/*
* Button in the UI
* */
public class Button_UI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler {
public Action ClickFunc = null;
public Action MouseRightClickFunc = null;
public Action MouseMiddleClickFunc = null;
public Action MouseDownOnceFunc = null;
public Action MouseUpFunc = null;
public Action MouseOverOnceTooltipFunc = null;
public Action MouseOutOnceTooltipFunc = null;
public Action MouseOverOnceFunc = null;
public Action MouseOutOnceFunc = null;
public Action MouseOverFunc = null;
public Action MouseOverPerSecFunc = null; //Triggers every sec if mouseOver
public Action MouseUpdate = null;
public Action<PointerEventData> OnPointerClickFunc;
public enum HoverBehaviour {
Custom,
Change_Color,
Change_Color_Auto,
Change_Image,
Change_SetActive,
}
public HoverBehaviour hoverBehaviourType = HoverBehaviour.Custom;
private Action hoverBehaviourFunc_Enter, hoverBehaviourFunc_Exit;
public Color hoverBehaviour_Color_Enter, hoverBehaviour_Color_Exit;
public Image hoverBehaviour_Image;
public Sprite hoverBehaviour_Sprite_Exit, hoverBehaviour_Sprite_Enter;
public bool hoverBehaviour_Move = false;
public Vector2 hoverBehaviour_Move_Amount = Vector2.zero;
private Vector2 posExit, posEnter;
public bool triggerMouseOutFuncOnClick = false;
private bool mouseOver;
private float mouseOverPerSecFuncTimer;
private Action internalOnPointerEnterFunc = null, internalOnPointerExitFunc = null, internalOnPointerClickFunc = null;
#if SOUND_MANAGER
public Sound_Manager.Sound mouseOverSound, mouseClickSound;
#endif
#if CURSOR_MANAGER
public CursorManager.CursorType cursorMouseOver, cursorMouseOut;
#endif
public virtual void OnPointerEnter(PointerEventData eventData) {
if (internalOnPointerEnterFunc != null) internalOnPointerEnterFunc();
if (hoverBehaviour_Move) transform.GetComponent<RectTransform>().anchoredPosition = posEnter;
if (hoverBehaviourFunc_Enter != null) hoverBehaviourFunc_Enter();
if (MouseOverOnceFunc != null) MouseOverOnceFunc();
if (MouseOverOnceTooltipFunc != null) MouseOverOnceTooltipFunc();
mouseOver = true;
mouseOverPerSecFuncTimer = 0f;
}
public virtual void OnPointerExit(PointerEventData eventData) {
if (internalOnPointerExitFunc != null) internalOnPointerExitFunc();
if (hoverBehaviour_Move) transform.GetComponent<RectTransform>().anchoredPosition = posExit;
if (hoverBehaviourFunc_Exit != null) hoverBehaviourFunc_Exit();
if (MouseOutOnceFunc != null) MouseOutOnceFunc();
if (MouseOutOnceTooltipFunc != null) MouseOutOnceTooltipFunc();
mouseOver = false;
}
public virtual void OnPointerClick(PointerEventData eventData) {
if (internalOnPointerClickFunc != null) internalOnPointerClickFunc();
if (OnPointerClickFunc != null) OnPointerClickFunc(eventData);
if (eventData.button == PointerEventData.InputButton.Left) {
if (triggerMouseOutFuncOnClick) {
OnPointerExit(eventData);
}
if (ClickFunc != null) ClickFunc();
}
if (eventData.button == PointerEventData.InputButton.Right)
if (MouseRightClickFunc != null) MouseRightClickFunc();
if (eventData.button == PointerEventData.InputButton.Middle)
if (MouseMiddleClickFunc != null) MouseMiddleClickFunc();
}
public void Manual_OnPointerExit() {
OnPointerExit(null);
}
public bool IsMouseOver() {
return mouseOver;
}
public void OnPointerDown(PointerEventData eventData) {
if (MouseDownOnceFunc != null) MouseDownOnceFunc();
}
public void OnPointerUp(PointerEventData eventData) {
if (MouseUpFunc != null) MouseUpFunc();
}
private void Update() {
if (mouseOver) {
if (MouseOverFunc != null) MouseOverFunc();
mouseOverPerSecFuncTimer -= Time.unscaledDeltaTime;
if (mouseOverPerSecFuncTimer <= 0) {
mouseOverPerSecFuncTimer += 1f;
if (MouseOverPerSecFunc != null) MouseOverPerSecFunc();
}
}
if (MouseUpdate != null) MouseUpdate();
}
private void Awake() {
posExit = transform.GetComponent<RectTransform>().anchoredPosition;
posEnter = transform.GetComponent<RectTransform>().anchoredPosition + hoverBehaviour_Move_Amount;
SetHoverBehaviourType(hoverBehaviourType);
#if SOUND_MANAGER
// Sound Manager
internalOnPointerEnterFunc += () => { if (mouseOverSound != Sound_Manager.Sound.None) Sound_Manager.PlaySound(mouseOverSound); };
internalOnPointerClickFunc += () => { if (mouseClickSound != Sound_Manager.Sound.None) Sound_Manager.PlaySound(mouseClickSound); };
#endif
#if CURSOR_MANAGER
// Cursor Manager
internalOnPointerEnterFunc += () => { if (cursorMouseOver != CursorManager.CursorType.None) CursorManager.SetCursor(cursorMouseOver); };
internalOnPointerExitFunc += () => { if (cursorMouseOut != CursorManager.CursorType.None) CursorManager.SetCursor(cursorMouseOut); };
#endif
}
public void SetHoverBehaviourType(HoverBehaviour hoverBehaviourType) {
this.hoverBehaviourType = hoverBehaviourType;
switch (hoverBehaviourType) {
case HoverBehaviour.Change_Color:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Exit; };
break;
case HoverBehaviour.Change_Image:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Exit; };
break;
case HoverBehaviour.Change_SetActive:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.gameObject.SetActive(true); };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.gameObject.SetActive(false); };
break;
case HoverBehaviour.Change_Color_Auto:
Color color = hoverBehaviour_Image.color;
if (color.r >= 1f) color.r = .9f;
if (color.g >= 1f) color.g = .9f;
if (color.b >= 1f) color.b = .9f;
Color colorOver = color * 1.3f; // Over color lighter
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.color = colorOver; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.color = color; };
break;
}
}
public void RefreshHoverBehaviourType() {
SetHoverBehaviourType(hoverBehaviourType);
}
/*
* Class for temporarily intercepting a button action
* Useful for Tutorial disabling specific buttons
* */
public class InterceptActionHandler {
private Action removeInterceptFunc;
public InterceptActionHandler(Action removeInterceptFunc) {
this.removeInterceptFunc = removeInterceptFunc;
}
public void RemoveIntercept() {
removeInterceptFunc();
}
}
public InterceptActionHandler InterceptActionClick(Func<bool> testPassthroughFunc) {
return InterceptAction("ClickFunc", testPassthroughFunc);
}
public InterceptActionHandler InterceptAction(string fieldName, Func<bool> testPassthroughFunc) {
return InterceptAction(GetType().GetField(fieldName), testPassthroughFunc);
}
public InterceptActionHandler InterceptAction(System.Reflection.FieldInfo fieldInfo, Func<bool> testPassthroughFunc) {
Action backFunc = fieldInfo.GetValue(this) as Action;
InterceptActionHandler interceptActionHandler = new InterceptActionHandler(() => fieldInfo.SetValue(this, backFunc));
fieldInfo.SetValue(this, (Action)delegate () {
if (testPassthroughFunc()) {
// Passthrough
interceptActionHandler.RemoveIntercept();
backFunc();
}
});
return interceptActionHandler;
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 602f74cbbbd80034b96f88091a8e7c1d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,187 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using System.Collections.Generic;
using UnityEngine;
namespace CodeMonkey.Utils {
/*
* Executes a Function periodically
* */
public class FunctionPeriodic {
/*
* Class to hook Actions into MonoBehaviour
* */
private class MonoBehaviourHook : MonoBehaviour {
public Action OnUpdate;
private void Update() {
if (OnUpdate != null) OnUpdate();
}
}
private static List<FunctionPeriodic> funcList; // Holds a reference to all active timers
private static GameObject initGameObject; // Global game object used for initializing class, is destroyed on scene change
private static void InitIfNeeded() {
if (initGameObject == null) {
initGameObject = new GameObject("FunctionPeriodic_Global");
funcList = new List<FunctionPeriodic>();
}
}
// Persist through scene loads
public static FunctionPeriodic Create_Global(Action action, Func<bool> testDestroy, float timer) {
FunctionPeriodic functionPeriodic = Create(action, testDestroy, timer, "", false, false, false);
MonoBehaviour.DontDestroyOnLoad(functionPeriodic.gameObject);
return functionPeriodic;
}
// Trigger [action] every [timer], execute [testDestroy] after triggering action, destroy if returns true
public static FunctionPeriodic Create(Action action, Func<bool> testDestroy, float timer) {
return Create(action, testDestroy, timer, "", false);
}
public static FunctionPeriodic Create(Action action, float timer) {
return Create(action, null, timer, "", false, false, false);
}
public static FunctionPeriodic Create(Action action, float timer, string functionName) {
return Create(action, null, timer, functionName, false, false, false);
}
public static FunctionPeriodic Create(Action callback, Func<bool> testDestroy, float timer, string functionName, bool stopAllWithSameName) {
return Create(callback, testDestroy, timer, functionName, false, false, stopAllWithSameName);
}
public static FunctionPeriodic Create(Action action, Func<bool> testDestroy, float timer, string functionName, bool useUnscaledDeltaTime, bool triggerImmediately, bool stopAllWithSameName) {
InitIfNeeded();
if (stopAllWithSameName) {
StopAllFunc(functionName);
}
GameObject gameObject = new GameObject("FunctionPeriodic Object " + functionName, typeof(MonoBehaviourHook));
FunctionPeriodic functionPeriodic = new FunctionPeriodic(gameObject, action, timer, testDestroy, functionName, useUnscaledDeltaTime);
gameObject.GetComponent<MonoBehaviourHook>().OnUpdate = functionPeriodic.Update;
funcList.Add(functionPeriodic);
if (triggerImmediately) action();
return functionPeriodic;
}
public static void RemoveTimer(FunctionPeriodic funcTimer) {
InitIfNeeded();
funcList.Remove(funcTimer);
}
public static void StopTimer(string _name) {
InitIfNeeded();
for (int i = 0; i < funcList.Count; i++) {
if (funcList[i].functionName == _name) {
funcList[i].DestroySelf();
return;
}
}
}
public static void StopAllFunc(string _name) {
InitIfNeeded();
for (int i = 0; i < funcList.Count; i++) {
if (funcList[i].functionName == _name) {
funcList[i].DestroySelf();
i--;
}
}
}
public static bool IsFuncActive(string name) {
InitIfNeeded();
for (int i = 0; i < funcList.Count; i++) {
if (funcList[i].functionName == name) {
return true;
}
}
return false;
}
private GameObject gameObject;
private float timer;
private float baseTimer;
private bool useUnscaledDeltaTime;
private string functionName;
public Action action;
public Func<bool> testDestroy;
private FunctionPeriodic(GameObject gameObject, Action action, float timer, Func<bool> testDestroy, string functionName, bool useUnscaledDeltaTime) {
this.gameObject = gameObject;
this.action = action;
this.timer = timer;
this.testDestroy = testDestroy;
this.functionName = functionName;
this.useUnscaledDeltaTime = useUnscaledDeltaTime;
baseTimer = timer;
}
public void SkipTimerTo(float timer) {
this.timer = timer;
}
public void SetBaseTimer(float baseTimer) {
this.baseTimer = baseTimer;
}
public float GetBaseTimer() {
return baseTimer;
}
private void Update() {
if (useUnscaledDeltaTime) {
timer -= Time.unscaledDeltaTime;
} else {
timer -= Time.deltaTime;
}
if (timer <= 0) {
action();
if (testDestroy != null && testDestroy()) {
//Destroy
DestroySelf();
} else {
//Repeat
timer += baseTimer;
}
}
}
public void DestroySelf() {
RemoveTimer(this);
if (gameObject != null) {
UnityEngine.Object.Destroy(gameObject);
}
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f522bd6f08a5c984a9512bb60ebc1818
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,183 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
using System.Collections.Generic;
namespace CodeMonkey.Utils {
/*
* Triggers a Action after a certain time
* */
public class FunctionTimer {
/*
* Class to hook Actions into MonoBehaviour
* */
private class MonoBehaviourHook : MonoBehaviour {
public Action OnUpdate;
private void Update() {
if (OnUpdate != null) OnUpdate();
}
}
private static List<FunctionTimer> timerList; // Holds a reference to all active timers
private static GameObject initGameObject; // Global game object used for initializing class, is destroyed on scene change
private static void InitIfNeeded() {
if (initGameObject == null) {
initGameObject = new GameObject("FunctionTimer_Global");
timerList = new List<FunctionTimer>();
}
}
public static FunctionTimer Create(Action action, float timer) {
return Create(action, timer, "", false, false);
}
public static FunctionTimer Create(Action action, float timer, string functionName) {
return Create(action, timer, functionName, false, false);
}
public static FunctionTimer Create(Action action, float timer, string functionName, bool useUnscaledDeltaTime) {
return Create(action, timer, functionName, useUnscaledDeltaTime, false);
}
public static FunctionTimer Create(Action action, float timer, string functionName, bool useUnscaledDeltaTime, bool stopAllWithSameName) {
InitIfNeeded();
if (stopAllWithSameName) {
StopAllTimersWithName(functionName);
}
GameObject obj = new GameObject("FunctionTimer Object "+functionName, typeof(MonoBehaviourHook));
FunctionTimer funcTimer = new FunctionTimer(obj, action, timer, functionName, useUnscaledDeltaTime);
obj.GetComponent<MonoBehaviourHook>().OnUpdate = funcTimer.Update;
timerList.Add(funcTimer);
return funcTimer;
}
public static void RemoveTimer(FunctionTimer funcTimer) {
InitIfNeeded();
timerList.Remove(funcTimer);
}
public static void StopAllTimersWithName(string functionName) {
InitIfNeeded();
for (int i = 0; i < timerList.Count; i++) {
if (timerList[i].functionName == functionName) {
timerList[i].DestroySelf();
i--;
}
}
}
public static void StopFirstTimerWithName(string functionName) {
InitIfNeeded();
for (int i = 0; i < timerList.Count; i++) {
if (timerList[i].functionName == functionName) {
timerList[i].DestroySelf();
return;
}
}
}
private GameObject gameObject;
private float timer;
private string functionName;
private bool active;
private bool useUnscaledDeltaTime;
private Action action;
public FunctionTimer(GameObject gameObject, Action action, float timer, string functionName, bool useUnscaledDeltaTime) {
this.gameObject = gameObject;
this.action = action;
this.timer = timer;
this.functionName = functionName;
this.useUnscaledDeltaTime = useUnscaledDeltaTime;
}
private void Update() {
if (useUnscaledDeltaTime) {
timer -= Time.unscaledDeltaTime;
} else {
timer -= Time.deltaTime;
}
if (timer <= 0) {
// Timer complete, trigger Action
action();
DestroySelf();
}
}
private void DestroySelf() {
RemoveTimer(this);
if (gameObject != null) {
UnityEngine.Object.Destroy(gameObject);
}
}
/*
* Class to trigger Actions manually without creating a GameObject
* */
public class FunctionTimerObject {
private float timer;
private Action callback;
public FunctionTimerObject(Action callback, float timer) {
this.callback = callback;
this.timer = timer;
}
public bool Update() {
return Update(Time.deltaTime);
}
public bool Update(float deltaTime) {
timer -= deltaTime;
if (timer <= 0) {
callback();
return true;
} else {
return false;
}
}
}
// Create a Object that must be manually updated through Update();
public static FunctionTimerObject CreateObject(Action callback, float timer) {
return new FunctionTimerObject(callback, timer);
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9c8b5f0217e73fa47827cf77f22c2f8d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,157 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
using System.Collections.Generic;
namespace CodeMonkey.Utils {
/*
* Calls function on every Update until it returns true
* */
public class FunctionUpdater {
/*
* Class to hook Actions into MonoBehaviour
* */
private class MonoBehaviourHook : MonoBehaviour {
public Action OnUpdate;
private void Update() {
if (OnUpdate != null) OnUpdate();
}
}
private static List<FunctionUpdater> updaterList; // Holds a reference to all active updaters
private static GameObject initGameObject; // Global game object used for initializing class, is destroyed on scene change
private static void InitIfNeeded() {
if (initGameObject == null) {
initGameObject = new GameObject("FunctionUpdater_Global");
updaterList = new List<FunctionUpdater>();
}
}
public static FunctionUpdater Create(Action updateFunc) {
return Create(() => { updateFunc(); return false; }, "", true, false);
}
public static FunctionUpdater Create(Action updateFunc, string functionName) {
return Create(() => { updateFunc(); return false; }, functionName, true, false);
}
public static FunctionUpdater Create(Func<bool> updateFunc) {
return Create(updateFunc, "", true, false);
}
public static FunctionUpdater Create(Func<bool> updateFunc, string functionName) {
return Create(updateFunc, functionName, true, false);
}
public static FunctionUpdater Create(Func<bool> updateFunc, string functionName, bool active) {
return Create(updateFunc, functionName, active, false);
}
public static FunctionUpdater Create(Func<bool> updateFunc, string functionName, bool active, bool stopAllWithSameName) {
InitIfNeeded();
if (stopAllWithSameName) {
StopAllUpdatersWithName(functionName);
}
GameObject gameObject = new GameObject("FunctionUpdater Object " + functionName, typeof(MonoBehaviourHook));
FunctionUpdater functionUpdater = new FunctionUpdater(gameObject, updateFunc, functionName, active);
gameObject.GetComponent<MonoBehaviourHook>().OnUpdate = functionUpdater.Update;
updaterList.Add(functionUpdater);
return functionUpdater;
}
private static void RemoveUpdater(FunctionUpdater funcUpdater) {
InitIfNeeded();
updaterList.Remove(funcUpdater);
}
public static void DestroyUpdater(FunctionUpdater funcUpdater) {
InitIfNeeded();
if (funcUpdater != null) {
funcUpdater.DestroySelf();
}
}
public static void StopUpdaterWithName(string functionName) {
InitIfNeeded();
for (int i = 0; i < updaterList.Count; i++) {
if (updaterList[i].functionName == functionName) {
updaterList[i].DestroySelf();
return;
}
}
}
public static void StopAllUpdatersWithName(string functionName) {
InitIfNeeded();
for (int i = 0; i < updaterList.Count; i++) {
if (updaterList[i].functionName == functionName) {
updaterList[i].DestroySelf();
i--;
}
}
}
private GameObject gameObject;
private string functionName;
private bool active;
private Func<bool> updateFunc; // Destroy Updater if return true;
public FunctionUpdater(GameObject gameObject, Func<bool> updateFunc, string functionName, bool active) {
this.gameObject = gameObject;
this.updateFunc = updateFunc;
this.functionName = functionName;
this.active = active;
}
public void Pause() {
active = false;
}
public void Resume() {
active = true;
}
private void Update() {
if (!active) return;
if (updateFunc()) {
DestroySelf();
}
}
public void DestroySelf() {
RemoveUpdater(this);
if (gameObject != null) {
UnityEngine.Object.Destroy(gameObject);
}
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7eacfbf662ad34e46932f36084c15e11
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,170 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace CodeMonkey.Utils {
/*
* Bar in the UI with scaleable Bar and Background
* */
public class UI_Bar {
public GameObject gameObject;
private RectTransform rectTransform;
private RectTransform background;
private RectTransform bar;
private Vector2 size;
/*
* Outline into for Bar
* */
public class Outline {
public float size = 1f;
public Color color = Color.black;
public Outline(float size, Color color) {
this.size = size;
this.color = color;
}
}
public UI_Bar(GameObject gameObject, RectTransform background, RectTransform bar) {
this.gameObject = gameObject;
rectTransform = gameObject.GetComponent<RectTransform>();
this.background = background;
this.bar = bar;
size = background.GetComponent<RectTransform>().sizeDelta;
}
public UI_Bar(GameObject gameObject, Transform background, Transform bar) {
this.gameObject = gameObject;
rectTransform = gameObject.GetComponent<RectTransform>();
this.background = background.GetComponent<RectTransform>();
this.bar = bar.GetComponent<RectTransform>();
size = background.GetComponent<RectTransform>().sizeDelta;
}
public UI_Bar(Transform parent, Vector2 anchoredPosition, Vector2 size, Color barColor, float sizeRatio) {
SetupParent(parent, anchoredPosition, size);
SetupBar(barColor);
SetSize(sizeRatio);
}
public UI_Bar(Transform parent, Vector2 anchoredPosition, Vector2 size, Color barColor, float sizeRatio, Outline outline) {
SetupParent(parent, anchoredPosition, size);
if (outline != null) SetupOutline(outline, size);
SetupBar(barColor);
SetSize(sizeRatio);
}
public UI_Bar(Transform parent, Vector2 anchoredPosition, Vector2 size, Color backgroundColor, Color barColor, float sizeRatio) {
SetupParent(parent, anchoredPosition, size);
SetupBackground(backgroundColor);
SetupBar(barColor);
SetSize(sizeRatio);
}
public UI_Bar(Transform parent, Vector2 anchoredPosition, Vector2 size, Color backgroundColor, Color barColor, float sizeRatio, Outline outline) {
SetupParent(parent, anchoredPosition, size);
if (outline != null) SetupOutline(outline, size);
SetupBackground(backgroundColor);
SetupBar(barColor);
SetSize(sizeRatio);
}
private void SetupParent(Transform parent, Vector2 anchoredPosition, Vector2 size) {
this.size = size;
gameObject = new GameObject("UI_Bar", typeof(RectTransform));
rectTransform = gameObject.GetComponent<RectTransform>();
rectTransform.SetParent(parent, false);
rectTransform.sizeDelta = size;
rectTransform.anchorMin = new Vector2(0, .5f);
rectTransform.anchorMax = new Vector2(0, .5f);
rectTransform.pivot = new Vector2(0, .5f);
rectTransform.anchoredPosition = anchoredPosition;
}
private RectTransform SetupOutline(Outline outline, Vector2 size) {
return UtilsClass.DrawSprite(outline.color, gameObject.transform, Vector2.zero, size + new Vector2(outline.size, outline.size), "Outline");
}
private void SetupBackground(Color backgroundColor) {
background = UtilsClass.DrawSprite(backgroundColor, gameObject.transform, Vector2.zero, Vector2.zero, "Background");
background.anchorMin = new Vector2(0,0);
background.anchorMax = new Vector2(1,1);
}
private void SetupBar(Color barColor) {
bar = UtilsClass.DrawSprite(barColor, gameObject.transform, Vector2.zero, Vector2.zero, "Bar");
bar.anchorMin = new Vector2(0,0);
bar.anchorMax = new Vector2(0,1f);
bar.pivot = new Vector2(0,.5f);
}
public void SetSize(float sizeRatio) {
bar.sizeDelta = new Vector2(sizeRatio * size.x, 0f);
}
public void SetColor(Color color) {
bar.GetComponent<Image>().color = color;
}
public void SetActive(bool active) {
gameObject.SetActive(active);
}
public Vector2 GetAnchoredPosition() {
return rectTransform.anchoredPosition;
}
public Vector2 GetSize() {
return rectTransform.sizeDelta;
}
public void AddOutline(Outline outline) {
RectTransform outlineRectTransform = SetupOutline(outline, size);
outlineRectTransform.transform.SetAsFirstSibling();
}
public void SetRaycastTarget(bool set) {
foreach (Transform trans in gameObject.transform) {
if (trans.GetComponent<Image>() != null) {
trans.GetComponent<Image>().raycastTarget = set;
}
}
}
public void DestroySelf() {
UnityEngine.Object.Destroy(gameObject);
}
public Button_UI AddButton() {
return AddButton(null, null, null);
}
public Button_UI AddButton(Action ClickFunc, Action MouseOverOnceFunc, Action MouseOutOnceFunc) {
Button_UI buttonUI = gameObject.AddComponent<Button_UI>();
if (ClickFunc != null)
buttonUI.ClickFunc = ClickFunc;
if (MouseOverOnceFunc != null)
buttonUI.MouseOverOnceFunc = MouseOverOnceFunc;
if (MouseOutOnceFunc != null)
buttonUI.MouseOutOnceFunc = MouseOutOnceFunc;
return buttonUI;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 49ffd25ff4b0ca3429d1b1e2dc0ff037
timeCreated: 1524300423
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,104 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace CodeMonkey.Utils {
/*
* UI Container with multiple bars, useful for displaying one bar with multiple inner bars like success chance and failure chance
* */
public class UI_BarMultiple {
private GameObject gameObject;
private RectTransform rectTransform;
private RectTransform[] barArr;
private Image[] barImageArr;
private Vector2 size;
public class Outline {
public float size = 1f;
public Color color = Color.black;
public Outline(float size, Color color) {
this.size = size;
this.color = color;
}
}
public UI_BarMultiple(Transform parent, Vector2 anchoredPosition, Vector2 size, Color[] barColorArr, Outline outline) {
this.size = size;
SetupParent(parent, anchoredPosition, size);
if (outline != null) SetupOutline(outline, size);
List<RectTransform> barList = new List<RectTransform>();
List<Image> barImageList = new List<Image>();
List<float> defaultSizeList = new List<float>();
foreach (Color color in barColorArr) {
barList.Add(SetupBar(color));
defaultSizeList.Add(1f / barColorArr.Length);
}
barArr = barList.ToArray();
barImageArr = barImageList.ToArray();
SetSizes(defaultSizeList.ToArray());
}
private void SetupParent(Transform parent, Vector2 anchoredPosition, Vector2 size) {
gameObject = new GameObject("UI_BarMultiple", typeof(RectTransform));
rectTransform = gameObject.GetComponent<RectTransform>();
rectTransform.SetParent(parent, false);
rectTransform.sizeDelta = size;
rectTransform.anchorMin = new Vector2(0, .5f);
rectTransform.anchorMax = new Vector2(0, .5f);
rectTransform.pivot = new Vector2(0, .5f);
rectTransform.anchoredPosition = anchoredPosition;
}
private void SetupOutline(Outline outline, Vector2 size) {
UtilsClass.DrawSprite(outline.color, gameObject.transform, Vector2.zero, size + new Vector2(outline.size, outline.size), "Outline");
}
private RectTransform SetupBar(Color barColor) {
RectTransform bar = UtilsClass.DrawSprite(barColor, gameObject.transform, Vector2.zero, Vector2.zero, "Bar");
bar.anchorMin = new Vector2(0,0);
bar.anchorMax = new Vector2(0,1f);
bar.pivot = new Vector2(0,.5f);
return bar;
}
public void SetSizes(float[] sizeArr) {
if (sizeArr.Length != barArr.Length) {
throw new System.Exception("Length doesn't match!");
}
Vector2 pos = Vector2.zero;
for (int i=0; i<sizeArr.Length; i++) {
float scaledSize = sizeArr[i] * size.x;
barArr[i].anchoredPosition = pos;
barArr[i].sizeDelta = new Vector2(scaledSize, 0f);
pos.x += scaledSize;
}
}
public RectTransform GetBar(int index) {
return barArr[index];
}
public Vector2 GetSize() {
return size;
}
public void DestroySelf() {
UnityEngine.Object.Destroy(gameObject);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 9cf7b152002fbca49b6a1a4623f200a7
timeCreated: 1524300429
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,131 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
using UnityEngine.UI;
namespace CodeMonkey.Utils {
/*
* Sprite in the UI
* */
public class UI_Sprite {
private static Transform GetCanvasTransform() {
return UtilsClass.GetCanvasTransform();
}
public static UI_Sprite CreateDebugButton(Vector2 anchoredPosition, Vector2 size, Action ClickFunc) {
return CreateDebugButton(anchoredPosition, size, ClickFunc, Color.green);
}
public static UI_Sprite CreateDebugButton(Vector2 anchoredPosition, Vector2 size, Action ClickFunc, Color color) {
UI_Sprite uiSprite = new UI_Sprite(GetCanvasTransform(), Assets.i.s_White, anchoredPosition, size, color);
uiSprite.AddButton(ClickFunc, null, null);
return uiSprite;
}
public static UI_Sprite CreateDebugButton(Transform parent, Vector2 anchoredPosition, string text, Action ClickFunc) {
return CreateDebugButton(parent, anchoredPosition, text, ClickFunc, Color.green);
}
public static UI_Sprite CreateDebugButton(Vector2 anchoredPosition, string text, Action ClickFunc) {
return CreateDebugButton(anchoredPosition, text, ClickFunc, Color.green);
}
public static UI_Sprite CreateDebugButton(Transform parent, Vector2 anchoredPosition, string text, Action ClickFunc, Color color) {
return CreateDebugButton(parent, anchoredPosition, text, ClickFunc, color, new Vector2(30, 20));
}
public static UI_Sprite CreateDebugButton(Vector2 anchoredPosition, string text, Action ClickFunc, Color color) {
return CreateDebugButton(GetCanvasTransform(), anchoredPosition, text, ClickFunc, color, new Vector2(30, 20));
}
public static UI_Sprite CreateDebugButton(Transform parent, Vector2 anchoredPosition, string text, Action ClickFunc, Color color, Vector2 padding) {
UI_TextComplex uiTextComplex;
UI_Sprite uiSprite = CreateDebugButton(parent, anchoredPosition, Vector2.zero, ClickFunc, color, text, out uiTextComplex);
uiSprite.SetSize(new Vector2(uiTextComplex.GetTotalWidth(), uiTextComplex.GetTotalHeight()) + padding);
return uiSprite;
}
public static UI_Sprite CreateDebugButton(Vector2 anchoredPosition, Vector2 size, Action ClickFunc, Color color, string text) {
UI_TextComplex uiTextComplex;
return CreateDebugButton(anchoredPosition, size, ClickFunc, color, text, out uiTextComplex);
}
public static UI_Sprite CreateDebugButton(Vector2 anchoredPosition, Vector2 size, Action ClickFunc, Color color, string text, out UI_TextComplex uiTextComplex) {
return CreateDebugButton(GetCanvasTransform(), anchoredPosition, size, ClickFunc, color, text, out uiTextComplex);
}
public static UI_Sprite CreateDebugButton(Transform parent, Vector2 anchoredPosition, Vector2 size, Action ClickFunc, Color color, string text, out UI_TextComplex uiTextComplex) {
if (color.r >= 1f) color.r = .9f;
if (color.g >= 1f) color.g = .9f;
if (color.b >= 1f) color.b = .9f;
Color colorOver = color * 1.1f; // button over color lighter
UI_Sprite uiSprite = new UI_Sprite(parent, Assets.i.s_White, anchoredPosition, size, color);
uiSprite.AddButton(ClickFunc, () => uiSprite.SetColor(colorOver), () => uiSprite.SetColor(color));
uiTextComplex = new UI_TextComplex(uiSprite.gameObject.transform, Vector2.zero, 12, '#', text, null, null);
uiTextComplex.SetTextColor(Color.black);
uiTextComplex.SetAnchorMiddle();
uiTextComplex.CenterOnPosition(Vector2.zero);
return uiSprite;
}
public GameObject gameObject;
public Image image;
public RectTransform rectTransform;
public UI_Sprite(Transform parent, Sprite sprite, Vector2 anchoredPosition, Vector2 size, Color color) {
rectTransform = UtilsClass.DrawSprite(sprite, parent, anchoredPosition, size, "UI_Sprite");
gameObject = rectTransform.gameObject;
image = gameObject.GetComponent<Image>();
image.color = color;
}
public void SetColor(Color color) {
image.color = color;
}
public void SetSprite(Sprite sprite) {
image.sprite = sprite;
}
public void SetSize(Vector2 size) {
rectTransform.sizeDelta = size;
}
public void SetAnchoredPosition(Vector2 anchoredPosition) {
rectTransform.anchoredPosition = anchoredPosition;
}
public Button_UI AddButton(Action ClickFunc, Action MouseOverOnceFunc, Action MouseOutOnceFunc) {
Button_UI buttonUI = gameObject.AddComponent<Button_UI>();
if (ClickFunc != null)
buttonUI.ClickFunc = ClickFunc;
if (MouseOverOnceFunc != null)
buttonUI.MouseOverOnceFunc = MouseOverOnceFunc;
if (MouseOutOnceFunc != null)
buttonUI.MouseOutOnceFunc = MouseOutOnceFunc;
return buttonUI;
}
public void DestroySelf() {
UnityEngine.Object.Destroy(gameObject);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d0052e8fbe8cbcd4d8c48038d364333b
timeCreated: 1524300216
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,151 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using UnityEngine;
using UnityEngine.UI;
namespace CodeMonkey.Utils {
/*
* Displays text with icons in between the text
* */
public class UI_TextComplex {
private static Transform GetCanvasTransform() {
return UtilsClass.GetCanvasTransform();
}
public struct Icon {
public Sprite sprite;
public Vector2 size;
public Color color;
public Icon(Sprite sprite, Vector2 size, Color? color = null) {
this.sprite = sprite;
this.size = size;
if (color == null) {
this.color = Color.white;
} else {
this.color = (Color) color;
}
}
}
public GameObject gameObject;
private Transform transform;
private RectTransform rectTransform;
// iconChar prepends the iconArr index;
// Example using iconChar '#':
// test #0 asdf
// Displays "test [iconArr[0]] asdf"
public UI_TextComplex(Transform parent, Vector2 anchoredPosition, int fontSize, char iconChar, string text, Icon[] iconArr, Font font) {
SetupParent(parent, anchoredPosition);
string tmp = text;
float textPosition = 0f;
while (tmp.IndexOf(iconChar) != -1) {
string untilTmp = tmp.Substring(0, tmp.IndexOf(iconChar));
string iconNumber = tmp.Substring(tmp.IndexOf(iconChar)+1);
int indexOfSpaceAfterIconNumber = iconNumber.IndexOf(" ");
if (indexOfSpaceAfterIconNumber != -1) {
// Still has more space after iconNumber
iconNumber = iconNumber.Substring(0, indexOfSpaceAfterIconNumber);
} else {
// No more space after iconNumber
}
tmp = tmp.Substring(tmp.IndexOf(iconChar+iconNumber) + (iconChar+iconNumber).Length);
if (untilTmp.Trim() != "") {
Text uiText = UtilsClass.DrawTextUI(untilTmp, transform, new Vector2(textPosition,0), fontSize, font);
textPosition += uiText.preferredWidth;
}
// Draw Icon
int iconIndex = UtilsClass.Parse_Int(iconNumber, 0);
Icon icon = iconArr[iconIndex];
UtilsClass.DrawSprite(icon.sprite, transform, new Vector2(textPosition + icon.size.x / 2f, 0), icon.size);
textPosition += icon.size.x;
}
if (tmp.Trim() != "") {
UtilsClass.DrawTextUI(tmp, transform, new Vector2(textPosition,0), fontSize, font);
}
}
private void SetupParent(Transform parent, Vector2 anchoredPosition) {
gameObject = new GameObject("UI_TextComplex", typeof(RectTransform));
transform = gameObject.transform;
rectTransform = gameObject.GetComponent<RectTransform>();
rectTransform.SetParent(parent, false);
rectTransform.sizeDelta = new Vector2(0, 0);
rectTransform.anchorMin = new Vector2(0, .5f);
rectTransform.anchorMax = new Vector2(0, .5f);
rectTransform.pivot = new Vector2(0, .5f);
rectTransform.anchoredPosition = anchoredPosition;
}
public void SetTextColor(Color color) {
foreach (Transform trans in transform) {
Text text = trans.GetComponent<Text>();
if (text != null) {
text.color = color;
}
}
}
public float GetTotalWidth() {
float textPosition = 0f;
foreach (Transform trans in transform) {
Text text = trans.GetComponent<Text>();
if (text != null) {
textPosition += text.preferredWidth;
}
Image image = trans.GetComponent<Image>();
if (image != null) {
textPosition += image.GetComponent<RectTransform>().sizeDelta.x;
}
}
return textPosition;
}
public float GetTotalHeight() {
foreach (Transform trans in transform) {
Text text = trans.GetComponent<Text>();
if (text != null) {
return text.preferredHeight;
}
}
return 0f;
}
public void AddTextOutline(Color color, float size) {
foreach (Transform textComplexTrans in transform) {
if (textComplexTrans.GetComponent<Text>() != null) {
Outline outline = textComplexTrans.gameObject.AddComponent<Outline>();
outline.effectColor = color;
outline.effectDistance = new Vector2(size, size);
}
}
}
public void SetAnchorMiddle() {
rectTransform.anchorMin = new Vector2(.5f, .5f);
rectTransform.anchorMax = new Vector2(.5f, .5f);
}
public void CenterOnPosition(Vector2 position) {
rectTransform.anchoredPosition = position + new Vector2(-GetTotalWidth() / 2f, 0);
}
public void DestroySelf() {
Object.Destroy(gameObject);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 8ba4b604c0e9db241bb3d130165415cd
timeCreated: 1524300347
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: ce2355f335dcae94abba806390b1bd76
timeCreated: 1524300728
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,150 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using UnityEngine;
namespace CodeMonkey.Utils {
/*
* Bar in the World, great for quickly making a health bar
* */
public class World_Bar {
private Outline outline;
private GameObject gameObject;
private Transform transform;
private Transform background;
private Transform bar;
public static int GetSortingOrder(Vector3 position, int offset, int baseSortingOrder = 5000) {
return (int)(baseSortingOrder - position.y) + offset;
}
public class Outline {
public float size = 1f;
public Color color = Color.black;
}
public static World_Bar Create(Vector3 localPosition, Vector3 localScale, Color? backgroundColor, Color barColor, float sizeRatio, Outline outline = null) {
return Create(null, localPosition, localScale, backgroundColor, barColor, sizeRatio, 0, outline);
}
public static World_Bar Create(Transform parent, Vector3 localPosition, Vector3 localScale, Color? backgroundColor, Color barColor, float sizeRatio, int sortingOrder, Outline outline = null) {
return new World_Bar(parent, localPosition, localScale, backgroundColor, barColor, sizeRatio, sortingOrder, outline);
}
public World_Bar(Transform parent, Vector3 localPosition, Vector3 localScale, Color? backgroundColor, Color barColor, float sizeRatio, int sortingOrder, Outline outline = null) {
this.outline = outline;
SetupParent(parent, localPosition);
if (outline != null) SetupOutline(outline, localScale, sortingOrder - 1);
if (backgroundColor != null) SetupBackground((Color)backgroundColor, localScale, sortingOrder);
SetupBar(barColor, localScale, sortingOrder + 1);
SetSize(sizeRatio);
}
private void SetupParent(Transform parent, Vector3 localPosition) {
gameObject = new GameObject("World_Bar");
transform = gameObject.transform;
transform.SetParent(parent);
transform.localPosition = localPosition;
}
private void SetupOutline(Outline outline, Vector3 localScale, int sortingOrder) {
UtilsClass.CreateWorldSprite(transform, "Outline", Assets.i.s_White, new Vector3(0,0), localScale + new Vector3(outline.size, outline.size), sortingOrder, outline.color);
}
private void SetupBackground(Color backgroundColor, Vector3 localScale, int sortingOrder) {
background = UtilsClass.CreateWorldSprite(transform, "Background", Assets.i.s_White, new Vector3(0,0), localScale, sortingOrder, backgroundColor).transform;
}
private void SetupBar(Color barColor, Vector3 localScale, int sortingOrder) {
GameObject barGO = new GameObject("Bar");
bar = barGO.transform;
bar.SetParent(transform);
bar.localPosition = new Vector3(-localScale.x / 2f, 0, 0);
bar.localScale = new Vector3(1,1,1);
Transform barIn = UtilsClass.CreateWorldSprite(bar, "BarIn", Assets.i.s_White, new Vector3(localScale.x / 2f, 0), localScale, sortingOrder, barColor).transform;
}
public void SetLocalScale(Vector3 localScale) {
// Outline
if (transform.Find("Outline") != null) {
// Has outline
transform.Find("Outline").localScale = localScale + new Vector3(outline.size, outline.size);
}
//Background
background.localScale = localScale;
// Set Bar Scale
bar.localPosition = new Vector3(-localScale.x / 2f, 0, 0);
Transform barIn = bar.Find("BarIn");
barIn.localScale = localScale;
barIn.localPosition = new Vector3(localScale.x / 2f, 0);
}
public void SetSortingOrder(int sortingOrder) {
bar.Find("BarIn").GetComponent<SpriteRenderer>().sortingOrder = sortingOrder;
if (background != null) background.GetComponent<SpriteRenderer>().sortingOrder = sortingOrder - 1;
if (transform.Find("Outline") != null) transform.Find("Outline").GetComponent<SpriteRenderer>().sortingOrder = sortingOrder - 2;
}
public void SetSortingLayerName(string sortingLayerName) {
bar.Find("BarIn").GetComponent<SpriteRenderer>().sortingLayerName = sortingLayerName;
if (background != null) background.GetComponent<SpriteRenderer>().sortingLayerName = sortingLayerName;
if (transform.Find("Outline") != null) transform.Find("Outline").GetComponent<SpriteRenderer>().sortingLayerName = sortingLayerName;
}
public void SetRotation(float rotation) {
transform.localEulerAngles = new Vector3(0, 0, rotation);
}
public void SetSize(float sizeRatio) {
bar.localScale = new Vector3(sizeRatio, 1, 1);
}
public void SetColor(Color color) {
bar.Find("BarIn").GetComponent<SpriteRenderer>().color = color;
}
public void SetActive(bool isActive) {
gameObject.SetActive(isActive);
}
public void Show() {
gameObject.SetActive(true);
}
public void Hide() {
gameObject.SetActive(false);
}
public Button_Sprite AddButton(System.Action ClickFunc, System.Action MouseOverOnceFunc, System.Action MouseOutOnceFunc) {
Button_Sprite buttonSprite = gameObject.AddComponent<Button_Sprite>();
if (ClickFunc != null)
buttonSprite.ClickFunc = ClickFunc;
if (MouseOverOnceFunc != null)
buttonSprite.MouseOverOnceFunc = MouseOverOnceFunc;
if (MouseOutOnceFunc != null)
buttonSprite.MouseOutOnceFunc = MouseOutOnceFunc;
return buttonSprite;
}
public void DestroySelf() {
if (gameObject != null) {
Object.Destroy(gameObject);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: cc20fdc736e8c9442b35e4bcc04c596c
timeCreated: 1524300272
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,237 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using UnityEngine;
namespace CodeMonkey.Utils {
/*
* Mesh in the World
* */
public class World_Mesh {
private const int sortingOrderDefault = 5000;
public GameObject gameObject;
public Transform transform;
private Material material;
private Vector3[] vertices;
private Vector2[] uv;
private int[] triangles;
private Mesh mesh;
public static World_Mesh CreateEmpty(Vector3 position, float eulerZ, Material material, int sortingOrderOffset = 0) {
return new World_Mesh(null, position, Vector3.one, eulerZ, material, new Vector3[0], new Vector2[0], new int[0], sortingOrderOffset);
}
public static World_Mesh Create(Vector3 position, float eulerZ, Material material, Vector3[] vertices, Vector2[] uv, int[] triangles, int sortingOrderOffset = 0) {
return new World_Mesh(null, position, Vector3.one, eulerZ, material, vertices, uv, triangles, sortingOrderOffset);
}
public static World_Mesh Create(Vector3 position, float eulerZ, float meshWidth, float meshHeight, Material material, UVCoords uvCoords, int sortingOrderOffset = 0) {
return new World_Mesh(null, position, Vector3.one, eulerZ, meshWidth, meshHeight, material, uvCoords, sortingOrderOffset);
}
public static World_Mesh Create(Vector3 lowerLeftCorner, float width, float height, Material material, UVCoords uvCoords, int sortingOrderOffset = 0) {
return Create(lowerLeftCorner, lowerLeftCorner + new Vector3(width, height), material, uvCoords, sortingOrderOffset);
}
public static World_Mesh Create(Vector3 lowerLeftCorner, Vector3 upperRightCorner, Material material, UVCoords uvCoords, int sortingOrderOffset = 0) {
float width = upperRightCorner.x - lowerLeftCorner.x;
float height = upperRightCorner.y - lowerLeftCorner.y;
Vector3 localScale = upperRightCorner - lowerLeftCorner;
Vector3 position = lowerLeftCorner + localScale * .5f;
return new World_Mesh(null, position, Vector3.one, 0f, width, height, material, uvCoords, sortingOrderOffset);
}
private static int GetSortingOrder(Vector3 position, int offset, int baseSortingOrder = sortingOrderDefault) {
return (int)(baseSortingOrder - position.y) + offset;
}
public class UVCoords {
public int x, y, width, height;
public UVCoords(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}
public World_Mesh(Transform parent, Vector3 localPosition, Vector3 localScale, float eulerZ, float meshWidth, float meshHeight, Material material, UVCoords uvCoords, int sortingOrderOffset) {
this.material = material;
vertices = new Vector3[4];
uv = new Vector2[4];
triangles = new int[6];
/* 0,1
* 1,1
* 0,0
* 1,0
*/
float meshWidthHalf = meshWidth / 2f;
float meshHeightHalf = meshHeight / 2f;
vertices[0] = new Vector3(-meshWidthHalf, meshHeightHalf);
vertices[1] = new Vector3( meshWidthHalf, meshHeightHalf);
vertices[2] = new Vector3(-meshWidthHalf, -meshHeightHalf);
vertices[3] = new Vector3( meshWidthHalf, -meshHeightHalf);
if (uvCoords == null) {
uvCoords = new UVCoords(0, 0, material.mainTexture.width, material.mainTexture.height);
}
Vector2[] uvArray = GetUVRectangleFromPixels(uvCoords.x, uvCoords.y, uvCoords.width, uvCoords.height, material.mainTexture.width, material.mainTexture.height);
ApplyUVToUVArray(uvArray, ref uv);
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 2;
triangles[3] = 2;
triangles[4] = 1;
triangles[5] = 3;
mesh = new Mesh();
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
gameObject = new GameObject("Mesh", typeof(MeshFilter), typeof(MeshRenderer));
gameObject.transform.parent = parent;
gameObject.transform.localPosition = localPosition;
gameObject.transform.localScale = localScale;
gameObject.transform.localEulerAngles = new Vector3(0, 0, eulerZ);
gameObject.GetComponent<MeshFilter>().mesh = mesh;
gameObject.GetComponent<MeshRenderer>().material = material;
transform = gameObject.transform;
SetSortingOrderOffset(sortingOrderOffset);
}
public World_Mesh(Transform parent, Vector3 localPosition, Vector3 localScale, float eulerZ, Material material, Vector3[] vertices, Vector2[] uv, int[] triangles, int sortingOrderOffset) {
this.material = material;
this.vertices = vertices;
this.uv = uv;
this.triangles = triangles;
mesh = new Mesh();
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
gameObject = new GameObject("Mesh", typeof(MeshFilter), typeof(MeshRenderer));
gameObject.transform.parent = parent;
gameObject.transform.localPosition = localPosition;
gameObject.transform.localScale = localScale;
gameObject.transform.localEulerAngles = new Vector3(0, 0, eulerZ);
gameObject.GetComponent<MeshFilter>().mesh = mesh;
gameObject.GetComponent<MeshRenderer>().material = material;
transform = gameObject.transform;
SetSortingOrderOffset(sortingOrderOffset);
}
private Vector2 ConvertPixelsToUVCoordinates(int x, int y, int textureWidth, int textureHeight) {
return new Vector2((float)x / textureWidth, (float)y / textureHeight);
}
private Vector2[] GetUVRectangleFromPixels(int x, int y, int width, int height, int textureWidth, int textureHeight) {
/* 0, 1
* 1, 1
* 0, 0
* 1, 0
* */
return new Vector2[] {
ConvertPixelsToUVCoordinates(x, y + height, textureWidth, textureHeight),
ConvertPixelsToUVCoordinates(x + width, y + height, textureWidth, textureHeight),
ConvertPixelsToUVCoordinates(x, y, textureWidth, textureHeight),
ConvertPixelsToUVCoordinates(x + width, y, textureWidth, textureHeight)
};
}
private void ApplyUVToUVArray(Vector2[] uv, ref Vector2[] mainUV) {
if (uv == null || uv.Length < 4 || mainUV == null || mainUV.Length < 4) throw new System.Exception();
mainUV[0] = uv[0];
mainUV[1] = uv[1];
mainUV[2] = uv[2];
mainUV[3] = uv[3];
}
public void SetUVCoords(UVCoords uvCoords) {
Vector2[] uvArray = GetUVRectangleFromPixels(uvCoords.x, uvCoords.y, uvCoords.width, uvCoords.height, material.mainTexture.width, material.mainTexture.height);
ApplyUVToUVArray(uvArray, ref uv);
mesh.uv = uv;
}
public void SetSortingOrderOffset(int sortingOrderOffset) {
SetSortingOrder(GetSortingOrder(gameObject.transform.position, sortingOrderOffset));
}
public void SetSortingOrder(int sortingOrder) {
gameObject.GetComponent<Renderer>().sortingOrder = sortingOrder;
}
public void SetLocalScale(Vector3 localScale) {
transform.localScale = localScale;
}
public void SetPosition(Vector3 localPosition) {
transform.localPosition = localPosition;
}
public void AddPosition(Vector3 addPosition) {
transform.localPosition += addPosition;
}
public Vector3 GetPosition() {
return transform.localPosition;
}
public int GetSortingOrder() {
return gameObject.GetComponent<Renderer>().sortingOrder;
}
public Mesh GetMesh() {
return mesh;
}
public void Show() {
gameObject.SetActive(true);
}
public void Hide() {
gameObject.SetActive(false);
}
public void DestroySelf() {
Object.Destroy(gameObject);
}
public static void CreateMesh() {
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 91ce8dcaef210db41a183b4558f16bb2
timeCreated: 1524300280
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,225 @@
/*
------------------- Code Monkey -------------------
Thank you for downloading the Code Monkey Utilities
I hope you find them useful in your projects
If you have any questions use the contact form
Cheers!
unitycodemonkey.com
--------------------------------------------------
*/
using System;
using UnityEngine;
namespace CodeMonkey.Utils {
/*
* Sprite in the World
* */
public class World_Sprite {
private const int sortingOrderDefault = 5000;
public GameObject gameObject;
public Transform transform;
private SpriteRenderer spriteRenderer;
public static World_Sprite CreateDebugButton(Vector3 position, System.Action ClickFunc) {
World_Sprite worldSprite = new World_Sprite(null, position, new Vector3(10, 10), Assets.i.s_White, Color.green, sortingOrderDefault);
worldSprite.AddButton(ClickFunc, null, null);
return worldSprite;
}
public static World_Sprite CreateDebugButton(Transform parent, Vector3 localPosition, System.Action ClickFunc) {
World_Sprite worldSprite = new World_Sprite(parent, localPosition, new Vector3(10, 10), Assets.i.s_White, Color.green, sortingOrderDefault);
worldSprite.AddButton(ClickFunc, null, null);
return worldSprite;
}
public static World_Sprite CreateDebugButton(Transform parent, Vector3 localPosition, string text, System.Action ClickFunc, int fontSize = 30, float paddingX = 5, float paddingY = 5) {
GameObject gameObject = new GameObject("DebugButton");
gameObject.transform.parent = parent;
gameObject.transform.localPosition = localPosition;
TextMesh textMesh = UtilsClass.CreateWorldText(text, gameObject.transform, Vector3.zero, fontSize, Color.white, TextAnchor.MiddleCenter, TextAlignment.Center, 20000);
Bounds rendererBounds = textMesh.GetComponent<MeshRenderer>().bounds;
Color color = UtilsClass.GetColorFromString("00BA00FF");
if (color.r >= 1f) color.r = .9f;
if (color.g >= 1f) color.g = .9f;
if (color.b >= 1f) color.b = .9f;
Color colorOver = color * 1.1f; // button over color lighter
World_Sprite worldSprite = new World_Sprite(gameObject.transform, Vector3.zero, rendererBounds.size + new Vector3(paddingX, paddingY), Assets.i.s_White, color, sortingOrderDefault);
worldSprite.AddButton(ClickFunc, () => worldSprite.SetColor(colorOver), () => worldSprite.SetColor(color));
return worldSprite;
}
public static World_Sprite Create(Transform parent, Vector3 localPosition, Vector3 localScale, Sprite sprite, Color color, int sortingOrderOffset) {
return new World_Sprite(parent, localPosition, localScale, sprite, color, sortingOrderOffset);
}
public static World_Sprite Create(Transform parent, Vector3 localPosition, Vector3 localScale, Sprite sprite = null, Color? color = null, int sortingOrderOffset = 0) {
if (sprite == null) {
sprite = Assets.i.s_White;
}
if (color == null) {
color = Color.white;
}
return new World_Sprite(parent, localPosition, localScale, sprite, (Color)color, sortingOrderOffset);
}
public static World_Sprite Create(Vector3 worldPosition, Sprite sprite) {
return new World_Sprite(null, worldPosition, new Vector3(1, 1, 1), sprite, Color.white, 0);
}
public static World_Sprite Create(Vector3 worldPosition, Vector3 localScale, Sprite sprite, Color color, int sortingOrderOffset) {
return new World_Sprite(null, worldPosition, localScale, sprite, color, sortingOrderOffset);
}
public static World_Sprite Create(Vector3 worldPosition, Vector3 localScale, Sprite sprite, Color color) {
return new World_Sprite(null, worldPosition, localScale, sprite, color, 0);
}
public static World_Sprite Create(Vector3 worldPosition, Vector3 localScale, Color color) {
return new World_Sprite(null, worldPosition, localScale, Assets.i.s_White, color, 0);
}
public static World_Sprite Create(Vector3 worldPosition, Vector3 localScale, Color color, int sortingOrderOffset) {
return new World_Sprite(null, worldPosition, localScale, Assets.i.s_White, color, sortingOrderOffset);
}
public static World_Sprite Create(Vector3 worldPosition, Vector3 localScale) {
return new World_Sprite(null, worldPosition, localScale, Assets.i.s_White, Color.white, 0);
}
public static World_Sprite Create(Vector3 worldPosition, Vector3 localScale, int sortingOrderOffset) {
return new World_Sprite(null, worldPosition, localScale, Assets.i.s_White, Color.white, sortingOrderOffset);
}
public static int GetSortingOrder(Vector3 position, int offset, int baseSortingOrder = sortingOrderDefault) {
return (int)(baseSortingOrder - position.y) + offset;
}
public World_Sprite(Transform parent, Vector3 localPosition, Vector3 localScale, Sprite sprite, Color color, int sortingOrderOffset) {
Vector3 position = localPosition;
if (parent != null) {
position = parent.TransformPoint(position);
}
int sortingOrder = GetSortingOrder(position, sortingOrderOffset);
gameObject = UtilsClass.CreateWorldSprite(parent, "Sprite", sprite, localPosition, localScale, sortingOrder, color);
transform = gameObject.transform;
spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
}
public void SetActive(bool isActive) {
gameObject.SetActive(isActive);
}
public SpriteRenderer GetSpriteRenderer() {
return spriteRenderer;
}
public void SetName(string name) {
gameObject.name = name;
}
public void SetSortingOrderOffset(int sortingOrderOffset) {
SetSortingOrder(GetSortingOrder(gameObject.transform.position, sortingOrderOffset));
}
public void SetSortingOrder(int sortingOrder) {
gameObject.GetComponent<SpriteRenderer>().sortingOrder = sortingOrder;
}
public void SetSortingLayerName(string layerName) {
gameObject.GetComponent<SpriteRenderer>().sortingLayerName = layerName;
}
public int GetSortingOrder() {
return gameObject.GetComponent<SpriteRenderer>().sortingOrder;
}
public void SetParent(GameObject parentGameObject) {
SetParent(parentGameObject.transform);
}
public void SetParent(Transform parent) {
transform.parent = parent;
}
public void SetLocalScale(Vector3 localScale) {
transform.localScale = localScale;
}
public void SetPosition(Vector3 localPosition) {
transform.localPosition = localPosition;
}
public void SetPosition(Func<Vector3> getLocalPosition) {
FunctionUpdater.Create(() => {
transform.localPosition = getLocalPosition();
});
}
public Vector3 GetPosition() {
return transform.position;
}
public Vector3 GetLocalScale() {
return transform.localScale;
}
public float GetRotation() {
return transform.localEulerAngles.z;
}
public void SetRotation(float rotation) {
transform.localEulerAngles = new Vector3(0, 0, rotation);
}
public void SetColor(Color color) {
spriteRenderer.color = color;
}
public void SetSprite(Sprite sprite) {
spriteRenderer.sprite = sprite;
}
public void SetFlip(bool flipX, bool flipY) {
spriteRenderer.flipX = flipX;
spriteRenderer.flipY = flipY;
}
public void Show() {
gameObject.SetActive(true);
}
public void Hide() {
gameObject.SetActive(false);
}
public Button_Sprite AddButton(System.Action ClickFunc, System.Action MouseOverOnceFunc, System.Action MouseOutOnceFunc) {
gameObject.AddComponent<BoxCollider2D>();
Button_Sprite buttonSprite = gameObject.AddComponent<Button_Sprite>();
if (ClickFunc != null)
buttonSprite.ClickFunc = ClickFunc;
if (MouseOverOnceFunc != null)
buttonSprite.MouseOverOnceFunc = MouseOverOnceFunc;
if (MouseOutOnceFunc != null)
buttonSprite.MouseOutOnceFunc = MouseOutOnceFunc;
return buttonSprite;
}
public void DestroySelf() {
UnityEngine.Object.Destroy(gameObject);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 1460472c3006fb44daea959dda2c4d81
timeCreated: 1524300280
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: