formatting

This commit is contained in:
klemek
2020-12-19 17:21:06 +01:00
parent 63e8f2c5f6
commit 205a663e07
56 changed files with 1690 additions and 1297 deletions
+1
View File
@@ -0,0 +1 @@
*.cs filter=tabify
+370
View File
@@ -0,0 +1,370 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &3755469950790061681
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 8387739526954179449}
m_Modifications:
- target: {fileID: -7307756874029176930, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: Name
value: Q
objectReference: {fileID: 0}
- target: {fileID: -7307756874029176930, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: Orientation.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1824742176375353076, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_Name
value: Q
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalPosition.x
value: 2.5
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalPosition.y
value: -1.5
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalPosition.z
value: -1
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
--- !u!1001 &6953158164962515518
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 8387739526954179449}
m_Modifications:
- target: {fileID: -7307756874029176930, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: Name
value: A
objectReference: {fileID: 0}
- target: {fileID: -7307756874029176930, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: IsInput
value: 1
objectReference: {fileID: 0}
- target: {fileID: -7307756874029176930, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: Orientation.x
value: -1
objectReference: {fileID: 0}
- target: {fileID: 1824742176375353076, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_Name
value: A
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalPosition.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalPosition.y
value: -1.5
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalPosition.z
value: -1
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8599692958760628507, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d2ad1e1266d8af64ca87541a40be7e9f, type: 3}
--- !u!1001 &7555383740349455498
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 347446582494478752, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Name
value: 200 Buffer gate
objectReference: {fileID: 0}
- target: {fileID: 1658337153186624383, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalScale.x
value: 2.5
objectReference: {fileID: 0}
- target: {fileID: 1658337153186624383, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalScale.y
value: 2.5
objectReference: {fileID: 0}
- target: {fileID: 1658337153186624383, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalPosition.x
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 1658337153186624383, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalPosition.y
value: -1.5
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2169103976044701791, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_BodyType
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2169103976044701791, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_GravityScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_SpriteTilingProperty.pivot.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_SpriteTilingProperty.newSize.x
value: 3
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_SpriteTilingProperty.newSize.y
value: 3
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_SpriteTilingProperty.oldSize.x
value: 3
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_SpriteTilingProperty.oldSize.y
value: 3
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.size
value: 13
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[0].x
value: 2.46
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[0].y
value: -1.61
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[1].x
value: 2.61
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[1].y
value: -1.52
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[2].x
value: 2.61
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[2].y
value: -1.49
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[3].x
value: 2.6
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[3].y
value: -1.4699999
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[4].x
value: 2.35
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[4].y
value: -1.3299999
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[5].x
value: 0.55
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[5].y
value: -0.32999998
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[6].x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[6].y
value: -0.32
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[7].x
value: 0.48
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[7].y
value: -0.34
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[8].x
value: 0.48
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[8].y
value: -2.6599998
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[9].x
value: 0.48999998
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[9].y
value: -2.6799998
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_SpriteTilingProperty.adaptiveTilingThreshold
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[10].x
value: 0.52
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[10].y
value: -2.6799998
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[11].x
value: 0.57
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[11].y
value: -2.6699998
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[12].x
value: 0.75
objectReference: {fileID: 0}
- target: {fileID: 4542802031506979094, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Points.m_Paths.Array.data[0].Array.data[12].y
value: -2.56
objectReference: {fileID: 0}
- target: {fileID: 9216698528057375618, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Size.x
value: 3
objectReference: {fileID: 0}
- target: {fileID: 9216698528057375618, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Size.y
value: 3
objectReference: {fileID: 0}
- target: {fileID: 9216698528057375618, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_Sprite
value:
objectReference: {fileID: 3286163911610860551, guid: 9b1c4145c6340064297ab349609dd56c, type: 3}
- target: {fileID: 9216698528057375618, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
propertyPath: m_WasSpriteAssigned
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
--- !u!4 &8387739526954179449 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 2070848596161447923, guid: e13798a14679ee74fa71d11caea77e78, type: 3}
m_PrefabInstance: {fileID: 7555383740349455498}
m_PrefabAsset: {fileID: 0}
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 368a8d7e21df7914f808163c111f710d
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+54 -54
View File
@@ -4,77 +4,77 @@ using UnityEngine;
namespace UntitledLogicGame namespace UntitledLogicGame
{ {
public class CameraManager : MonoBehaviour public class CameraManager : MonoBehaviour
{ {
#region Unity Properties #region Unity Properties
[Header("Zooming")] [Header("Zooming")]
public int MinSize; public int MinSize;
public int MaxSize; public int MaxSize;
public float ScrollSensitivity; public float ScrollSensitivity;
[Header("Moving")] [Header("Moving")]
public Camera Camera101; public Camera Camera101;
#endregion #endregion
#region Public Properties #region Public Properties
#endregion #endregion
#region Private Properties #region Private Properties
private Vector3 _startDragMousePos; private Vector3 _startDragMousePos;
private Vector3? _startDragPos; private Vector3? _startDragPos;
#endregion #endregion
#region Unity Methods #region Unity Methods
private void FixedUpdate() private void FixedUpdate()
{ {
UpdateZoom(); UpdateZoom();
UpdateDrag(); UpdateDrag();
} }
#endregion #endregion
#region Public Methods #region Public Methods
#endregion #endregion
#region Private Methods #region Private Methods
private void UpdateZoom() private void UpdateZoom()
{ {
var size = Camera.main.orthographicSize; var size = Camera.main.orthographicSize;
size -= Input.GetAxis("Mouse ScrollWheel") * ScrollSensitivity; size -= Input.GetAxis("Mouse ScrollWheel") * ScrollSensitivity;
size = Mathf.Clamp(size, MinSize, MaxSize); size = Mathf.Clamp(size, MinSize, MaxSize);
Camera.main.orthographicSize = size; Camera.main.orthographicSize = size;
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -size); Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -size);
} }
private void UpdateDrag() private void UpdateDrag()
{ {
if (Input.GetMouseButton(2)) if (Input.GetMouseButton(2))
{ {
var mousePos = Camera101.ScreenToWorldPoint(Input.mousePosition); var mousePos = Camera101.ScreenToWorldPoint(Input.mousePosition);
mousePos.z = 0f; mousePos.z = 0f;
if (_startDragPos == null) if (_startDragPos == null)
{ {
_startDragMousePos = mousePos; _startDragMousePos = mousePos;
_startDragPos = Camera.main.transform.position; _startDragPos = Camera.main.transform.position;
} }
Camera.main.transform.position = _startDragPos.Value - (mousePos - _startDragMousePos) * Camera.main.orthographicSize; Camera.main.transform.position = _startDragPos.Value - (mousePos - _startDragMousePos) * Camera.main.orthographicSize;
} }
else if (_startDragPos != null) else if (_startDragPos != null)
{ {
_startDragPos = null; _startDragPos = null;
} }
} }
#endregion #endregion
} }
} }
+15 -15
View File
@@ -5,31 +5,31 @@ using UnityEngine;
namespace UntitledLogicGame namespace UntitledLogicGame
{ {
//public class TODO : MonoBehaviour //public class TODO : MonoBehaviour
//{ //{
// #region Unity Properties // #region Unity Properties
// #endregion // #endregion
// #region Public Properties // #region Public Properties
// #endregion // #endregion
// #region Private Properties // #region Private Properties
// #endregion // #endregion
// #region Unity Methods // #region Unity Methods
// #endregion // #endregion
// #region Public Methods // #region Public Methods
// #endregion // #endregion
// #region Private Methods // #region Private Methods
// #endregion // #endregion
//} //}
} }
+54 -54
View File
@@ -6,80 +6,80 @@ using UntitledLogicGame.Workspace;
namespace UntitledLogicGame namespace UntitledLogicGame
{ {
public class GameManager : MonoBehaviour public class GameManager : MonoBehaviour
{ {
#region Static Properties #region Static Properties
public static GameManager Instance { public static GameManager Instance {
get get
{ {
if (_instance == null) if (_instance == null)
_instance = FindObjectOfType<GameManager>(); _instance = FindObjectOfType<GameManager>();
return _instance; return _instance;
} }
} }
private static GameManager _instance; private static GameManager _instance;
#endregion #endregion
#region Unity Properties #region Unity Properties
[Header("Prefabs")] [Header("Prefabs")]
public Cable CablePrefab; public Cable CablePrefab;
[Header("Groups")] [Header("Groups")]
public Transform GatesGroup; public Transform GatesGroup;
public Transform CablesGroup; public Transform CablesGroup;
[Header("Colors")] [Header("Colors")]
public Color DeadColor; public Color DeadColor;
public Color ActivatedColor; public Color ActivatedColor;
[Header("Gates")] [Header("Gates")]
public List<Gate> GatePrefabs; public List<Gate> GatePrefabs;
#endregion #endregion
#region Public Properties #region Public Properties
public Anchor CurrentAnchor { get; set; } public Anchor CurrentAnchor { get; set; }
public Gate CurrentGate { get; set; } public Gate CurrentGate { get; set; }
public PointerManager PointerManager public PointerManager PointerManager
{ {
get get
{ {
if (_pointerManager == null) if (_pointerManager == null)
_pointerManager = GetComponent<PointerManager>(); _pointerManager = GetComponent<PointerManager>();
return _pointerManager; return _pointerManager;
} }
} }
#endregion #endregion
#region Private Properties #region Private Properties
private PointerManager _pointerManager; private PointerManager _pointerManager;
#endregion #endregion
#region Unity Methods #region Unity Methods
#endregion #endregion
#region Public Methods #region Public Methods
public void CreateGate(Gate gatePrefab) public void CreateGate(Gate gatePrefab)
{ {
var gate = Instantiate(gatePrefab, GatesGroup); var gate = Instantiate(gatePrefab, GatesGroup);
gate.transform.position = PointerManager.MousePos - gate.Box.transform.position; gate.transform.position = PointerManager.MousePos - gate.Box.transform.position;
PointerManager.DragGate(gate, true); PointerManager.DragGate(gate, true);
} }
#endregion #endregion
#region Private Methods #region Private Methods
#endregion #endregion
} }
} }
+191 -191
View File
@@ -7,226 +7,226 @@ using UntitledLogicGame.Workspace;
namespace UntitledLogicGame namespace UntitledLogicGame
{ {
public class PointerManager : MonoBehaviour public class PointerManager : MonoBehaviour
{ {
#region Static Properties #region Static Properties
public static PointerManager Instance => GameManager.Instance.PointerManager; public static PointerManager Instance => GameManager.Instance.PointerManager;
#endregion #endregion
#region Unity Properties #region Unity Properties
[Header("Click")] [Header("Click")]
public float DoubleClickThreshold; public float DoubleClickThreshold;
public float DoubleClickDelay; public float DoubleClickDelay;
[Header("Cursor")] [Header("Cursor")]
public Texture2D DefaultCursor; public Texture2D DefaultCursor;
public Texture2D PointerCursor; public Texture2D PointerCursor;
public Texture2D MoveCursor; public Texture2D MoveCursor;
#endregion #endregion
#region Public Properties #region Public Properties
public static Vector3 MousePos { get; set; } public static Vector3 MousePos { get; set; }
public bool Interacting => _currentCable != null || _currentGate != null; public bool Interacting => _currentCable != null || _currentGate != null;
public bool MovingObject => _currentGate != null; public bool MovingObject => _currentGate != null;
public bool Clicking => Input.GetButton("Fire1"); public bool Clicking => Input.GetButton("Fire1");
public bool DeleteOnRelease { get; set; } public bool DeleteOnRelease { get; set; }
#endregion #endregion
#region Private Properties #region Private Properties
private Cable _currentCable; private Cable _currentCable;
private Gate _currentGate; private Gate _currentGate;
private Vector3? _currentGateInitialPos; private Vector3? _currentGateInitialPos;
private Vector3 _currentGateDelta; private Vector3 _currentGateDelta;
private Texture2D _currentCursor; private Texture2D _currentCursor;
private float _clicked = 0f; private float _clicked = 0f;
private float _clicktime = 0f; private float _clicktime = 0f;
#endregion #endregion
#region Unity Methods #region Unity Methods
private void FixedUpdate() private void FixedUpdate()
{ {
UpdateMousePos(); UpdateMousePos();
if (Clicking) if (Clicking)
{ {
UpdateDrag(); UpdateDrag();
} }
else else
{ {
UpdateDrop(); UpdateDrop();
} }
UpdateCursor(); UpdateCursor();
} }
#endregion #endregion
#region Public Methods #region Public Methods
public void DragGate(Gate gate, bool created) public void DragGate(Gate gate, bool created)
{ {
_currentGate = gate; _currentGate = gate;
_currentGateDelta = MousePos - _currentGate.transform.position; _currentGateDelta = MousePos - _currentGate.transform.position;
_currentGateInitialPos = created ? (Vector3?)null : _currentGate.transform.position; _currentGateInitialPos = created ? (Vector3?)null : _currentGate.transform.position;
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>()) foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
{ {
renderer.sortingLayerName = "moving"; renderer.sortingLayerName = "moving";
} }
} }
public void RequestDelete() public void RequestDelete()
{ {
if (_currentGate != null) if (_currentGate != null)
{ {
Destroy(_currentGate.gameObject); Destroy(_currentGate.gameObject);
_currentGate = null; _currentGate = null;
} }
} }
public bool DoubleClick() public bool DoubleClick()
{ {
if (Clicking) if (Clicking)
{ {
_clicked += Time.deltaTime; _clicked += Time.deltaTime;
} }
else else
{ {
if(_clicked >= DoubleClickThreshold) if(_clicked >= DoubleClickThreshold)
{ {
if(Time.time - _clicktime < DoubleClickDelay) if(Time.time - _clicktime < DoubleClickDelay)
{ {
_clicked = 0f; _clicked = 0f;
_clicktime = 0f; _clicktime = 0f;
return true; return true;
} }
else else
{ {
_clicktime = Time.time; _clicktime = Time.time;
} }
} }
_clicked = 0f; _clicked = 0f;
} }
return false; return false;
} }
#endregion #endregion
#region Private Methods #region Private Methods
private static void UpdateMousePos() private static void UpdateMousePos()
{ {
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos.z = 0f; mousePos.z = 0f;
MousePos = mousePos; MousePos = mousePos;
} }
private void UpdateCursor() private void UpdateCursor()
{ {
var cursor = DefaultCursor; var cursor = DefaultCursor;
var position = Vector2.zero; var position = Vector2.zero;
if (!Interacting && GameManager.Instance.CurrentAnchor != null || Interacting && _currentCable != null) if (!Interacting && GameManager.Instance.CurrentAnchor != null || Interacting && _currentCable != null)
{ {
cursor = PointerCursor; cursor = PointerCursor;
position = new Vector2(cursor.width / 2f, 0f); position = new Vector2(cursor.width / 2f, 0f);
} }
else if (!Interacting && GameManager.Instance.CurrentGate != null || Interacting && _currentGate != null) else if (!Interacting && GameManager.Instance.CurrentGate != null || Interacting && _currentGate != null)
{ {
cursor = MoveCursor; cursor = MoveCursor;
position = new Vector2(cursor.width / 2f, cursor.height / 2f); position = new Vector2(cursor.width / 2f, cursor.height / 2f);
} }
if(_currentCursor != cursor) if(_currentCursor != cursor)
{ {
//TODO Invalid texture used for cursor - check importer settings or texture creation. Texture must be RGBA32, readable, have alphaIsTransparency enabled and have no mip chain. //TODO Invalid texture used for cursor - check importer settings or texture creation. Texture must be RGBA32, readable, have alphaIsTransparency enabled and have no mip chain.
Cursor.SetCursor(cursor, position, CursorMode.Auto); Cursor.SetCursor(cursor, position, CursorMode.Auto);
_currentCursor = cursor; _currentCursor = cursor;
} }
} }
private void UpdateDrag() private void UpdateDrag()
{ {
if (_currentCable != null) // Dragging cable if (_currentCable != null) // Dragging cable
{ {
_currentCable.FallbackEndPos = MousePos; _currentCable.FallbackEndPos = MousePos;
} }
else if (_currentGate != null) // Dragging gate else if (_currentGate != null) // Dragging gate
{ {
_currentGate.transform.position = MousePos - _currentGateDelta; _currentGate.transform.position = MousePos - _currentGateDelta;
} }
else if (GameManager.Instance.CurrentAnchor != null) // Dragging new cable else if (GameManager.Instance.CurrentAnchor != null) // Dragging new cable
{ {
_currentCable = Instantiate(GameManager.Instance.CablePrefab, GameManager.Instance.CablesGroup, true); _currentCable = Instantiate(GameManager.Instance.CablePrefab, GameManager.Instance.CablesGroup, true);
_currentCable.StartAnchor = GameManager.Instance.CurrentAnchor; _currentCable.StartAnchor = GameManager.Instance.CurrentAnchor;
_currentCable.FallbackEndPos = MousePos; _currentCable.FallbackEndPos = MousePos;
} }
else if (GameManager.Instance.CurrentGate != null) // Dragging new gate else if (GameManager.Instance.CurrentGate != null) // Dragging new gate
{ {
DragGate(GameManager.Instance.CurrentGate, false); DragGate(GameManager.Instance.CurrentGate, false);
} }
} }
private void UpdateDrop() private void UpdateDrop()
{ {
if (_currentCable != null) // Dropping cable if (_currentCable != null) // Dropping cable
{ {
if (GameManager.Instance.CurrentAnchor == null || _currentCable.StartAnchor.IsInput == GameManager.Instance.CurrentAnchor.IsInput) if (GameManager.Instance.CurrentAnchor == null || _currentCable.StartAnchor.IsInput == GameManager.Instance.CurrentAnchor.IsInput)
{ {
Destroy(_currentCable.gameObject); Destroy(_currentCable.gameObject);
} }
else else
{ {
_currentCable.EndAnchor = GameManager.Instance.CurrentAnchor; _currentCable.EndAnchor = GameManager.Instance.CurrentAnchor;
} }
_currentCable = null; _currentCable = null;
} }
else if (_currentGate != null) // Dropping gate else if (_currentGate != null) // Dropping gate
{ {
if (DeleteOnRelease) if (DeleteOnRelease)
{ {
Destroy(_currentGate.gameObject); Destroy(_currentGate.gameObject);
} }
else else
{ {
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>()) foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
{ {
renderer.sortingLayerName = "default"; renderer.sortingLayerName = "default";
} }
_currentGate.transform.position = _currentGate.transform.position.Round(); _currentGate.transform.position = _currentGate.transform.position.Round();
var currentBox = _currentGate.Box; var currentBox = _currentGate.Box;
if (FindObjectsOfType<Gate>() if (FindObjectsOfType<Gate>()
.Where(g => !g.Equals(_currentGate)) .Where(g => !g.Equals(_currentGate))
.Select(g => g.Box) .Select(g => g.Box)
.Any(b => currentBox.IsTouching(b))) .Any(b => currentBox.IsTouching(b)))
{ {
// Collision with another gate // Collision with another gate
if (_currentGateInitialPos == null) if (_currentGateInitialPos == null)
{ {
Destroy(_currentGate.gameObject); Destroy(_currentGate.gameObject);
} }
else else
{ {
_currentGate.transform.position = _currentGateInitialPos.Value; // Reset pos _currentGate.transform.position = _currentGateInitialPos.Value; // Reset pos
} }
} }
} }
_currentGate = null; _currentGate = null;
DeleteOnRelease = false; DeleteOnRelease = false;
} }
} }
#endregion #endregion
} }
} }
+18 -18
View File
@@ -6,20 +6,20 @@ using UnityEngine.EventSystems;
namespace UntitledLogicGame.UI namespace UntitledLogicGame.UI
{ {
public class UIDelete : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler public class UIDelete : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{ {
#region Unity Properties #region Unity Properties
public SVGImage closedImage; public SVGImage closedImage;
public SVGImage openImage; public SVGImage openImage;
#endregion #endregion
#region Public Properties #region Public Properties
#endregion #endregion
#region Private Properties #region Private Properties
private SVGImage Image private SVGImage Image
{ {
@@ -31,23 +31,23 @@ namespace UntitledLogicGame.UI
} }
} }
private SVGImage _image; private SVGImage _image;
#endregion #endregion
#region Unity Methods #region Unity Methods
public void OnPointerEnter(PointerEventData eventData) public void OnPointerEnter(PointerEventData eventData)
{ {
Image.sprite = openImage.sprite; Image.sprite = openImage.sprite;
PointerManager.Instance.DeleteOnRelease = true; PointerManager.Instance.DeleteOnRelease = true;
} }
public void OnPointerExit(PointerEventData eventData) public void OnPointerExit(PointerEventData eventData)
{ {
Image.sprite = closedImage.sprite; Image.sprite = closedImage.sprite;
PointerManager.Instance.DeleteOnRelease = false; PointerManager.Instance.DeleteOnRelease = false;
} }
private void OnEnable() private void OnEnable()
{ {
+8 -8
View File
@@ -34,18 +34,18 @@ namespace UntitledLogicGame.UI
#region Private Properties #region Private Properties
#endregion #endregion
#region Unity Methods #region Unity Methods
#endregion #endregion
#region Public Methods #region Public Methods
#endregion #endregion
#region Private Methods #region Private Methods
#endregion #endregion
} }
} }
+32 -32
View File
@@ -7,16 +7,16 @@ using UntitledLogicGame.Workspace.Gates;
namespace UntitledLogicGame.UI namespace UntitledLogicGame.UI
{ {
public class UIManager : MonoBehaviour public class UIManager : MonoBehaviour
{ {
#region Unity Properties #region Unity Properties
[Header("Components")] [Header("Components")]
public GameObject GateBar; public GameObject GateBar;
public GameObject MovingBar; public GameObject MovingBar;
[Header("Prefabs")] [Header("Prefabs")]
public UIGate UIGatePrefab; public UIGate UIGatePrefab;
public UIFolder UIFolderPrefab; public UIFolder UIFolderPrefab;
#endregion #endregion
@@ -33,11 +33,11 @@ namespace UntitledLogicGame.UI
} }
} }
#endregion #endregion
#region Private Properties #region Private Properties
private bool _lastMouseInteracting; private bool _lastMouseInteracting;
private GateCategory _gateBarState; private GateCategory _gateBarState;
private Dictionary<GateCategory, GameObject> _gateBarSateList; private Dictionary<GateCategory, GameObject> _gateBarSateList;
@@ -46,35 +46,35 @@ namespace UntitledLogicGame.UI
#region Unity Methods #region Unity Methods
private IEnumerator Start() private IEnumerator Start()
{ {
yield return new WaitUntil(() => GameManager.Instance != null); yield return new WaitUntil(() => GameManager.Instance != null);
CreateGateBar(); CreateGateBar();
UpdateUI(); UpdateUI();
} }
private void FixedUpdate() private void FixedUpdate()
{ {
UpdateUI(); UpdateUI();
} }
#endregion #endregion
#region Public Methods #region Public Methods
#endregion #endregion
#region Private Methods #region Private Methods
private void UpdateUI() private void UpdateUI()
{ {
if (PointerManager.Instance.Interacting != _lastMouseInteracting) if (PointerManager.Instance.Interacting != _lastMouseInteracting)
{ {
//TODO animate go down //TODO animate go down
GateBar.SetActive(!PointerManager.Instance.Interacting); GateBar.SetActive(!PointerManager.Instance.Interacting);
MovingBar.SetActive(PointerManager.Instance.MovingObject); MovingBar.SetActive(PointerManager.Instance.MovingObject);
_lastMouseInteracting = PointerManager.Instance.Interacting; _lastMouseInteracting = PointerManager.Instance.Interacting;
} }
} }
private void CreateGateBar() private void CreateGateBar()
{ {
@@ -144,6 +144,6 @@ namespace UntitledLogicGame.UI
_gateBarSateList[category].SetActive(category == GateBarState); _gateBarSateList[category].SetActive(category == GateBarState);
} }
#endregion #endregion
} }
} }
+1 -1
View File
@@ -8,7 +8,7 @@ using UnityEngine.EventSystems;
namespace UntitledLogicGame.UI namespace UntitledLogicGame.UI
{ {
public class UIToolbarButton : MonoBehaviour, IPointerDownHandler public class UIToolbarButton : MonoBehaviour, IPointerDownHandler
{ {
#region Unity Properties #region Unity Properties
+40 -40
View File
@@ -6,57 +6,57 @@ using Random = UnityEngine.Random;
namespace UntitledLogicGame namespace UntitledLogicGame
{ {
public static class Utils public static class Utils
{ {
#region String Utils #region String Utils
public static string RandomString(int length) public static string RandomString(int length)
{ {
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length) return new string(Enumerable.Repeat(chars, length)
.Select(s => s[Random.Range(0, s.Length)]).ToArray()); .Select(s => s[Random.Range(0, s.Length)]).ToArray());
} }
#endregion #endregion
#region Bool Utils #region Bool Utils
public static bool[][] AllBoolArrayValues(int length) public static bool[][] AllBoolArrayValues(int length)
{ {
if (length == 0) if (length == 0)
return new bool[0][]; return new bool[0][];
var count = (int)Math.Pow(2, length); var count = (int)Math.Pow(2, length);
return new ArrayList[count].Select((v, i) => i.ToBoolArray(length)).ToArray(); return new ArrayList[count].Select((v, i) => i.ToBoolArray(length)).ToArray();
} }
#endregion #endregion
#region Unity Utils #region Unity Utils
public static void RandomName(string prefix, GameObject obj) public static void RandomName(string prefix, GameObject obj)
{ {
obj.name = $"{prefix}_{RandomString(5)}"; obj.name = $"{prefix}_{RandomString(5)}";
} }
#endregion #endregion
} }
public static class Extensions public static class Extensions
{ {
public static bool[] ToBoolArray(this int value, int length) public static bool[] ToBoolArray(this int value, int length)
{ {
var str = Convert.ToString(value, 2).PadLeft(length, '0'); var str = Convert.ToString(value, 2).PadLeft(length, '0');
return str.Select((x) => x == '1').ToArray(); return str.Select((x) => x == '1').ToArray();
} }
public static int ToInt(this bool[] array) public static int ToInt(this bool[] array)
{ {
return array.Select((v, i) => (v ? 1 : 0) << (array.Length - i - 1)).Sum(); return array.Select((v, i) => (v ? 1 : 0) << (array.Length - i - 1)).Sum();
} }
public static Vector3 Round(this Vector3 v) public static Vector3 Round(this Vector3 v)
{ {
return new Vector3(Mathf.Round(v.x), Mathf.Round(v.y), Mathf.Round(v.z)); return new Vector3(Mathf.Round(v.x), Mathf.Round(v.y), Mathf.Round(v.z));
} }
} }
} }
+91 -91
View File
@@ -5,116 +5,116 @@ using UnityEngine;
namespace UntitledLogicGame.Workspace namespace UntitledLogicGame.Workspace
{ {
public class Anchor : MonoBehaviour public class Anchor : MonoBehaviour
{ {
#region Unity Properties #region Unity Properties
public string Name; public string Name;
public bool IsInput; public bool IsInput;
public float ScaleIncrease; public float ScaleIncrease;
public Vector2 Orientation; public Vector2 Orientation;
#endregion #endregion
#region Public Properties #region Public Properties
public List<Cable> Cables { get; set; } public List<Cable> Cables { get; set; }
public Gate Gate { get; set; } public Gate Gate { get; set; }
public bool Activated public bool Activated
{ {
get get
{ {
if (IsInput) if (IsInput)
return Cables.Count > 0 && Cables.First().Activated; return Cables.Count > 0 && Cables.First().Activated;
else else
return _activated; return _activated;
} }
set set
{ {
if (!IsInput) if (!IsInput)
_activated = value; _activated = value;
} }
} }
public bool Hovering { get; internal set; } public bool Hovering { get; internal set; }
#endregion #endregion
#region Private Properties #region Private Properties
private Vector3 _scale; private Vector3 _scale;
private SpriteRenderer _sprite; private SpriteRenderer _sprite;
private bool _activated; private bool _activated;
private bool? _lastActivated; private bool? _lastActivated;
#endregion #endregion
#region Unity Methods #region Unity Methods
// Start is called before the first frame update // Start is called before the first frame update
private void Start() private void Start()
{ {
Gate = GetComponentInParent<Gate>(); Gate = GetComponentInParent<Gate>();
Utils.RandomName($"{Gate.GateType}_{Name}", gameObject); Utils.RandomName($"{Gate.GateType}_{Name}", gameObject);
_scale = transform.localScale; _scale = transform.localScale;
_sprite = GetComponent<SpriteRenderer>(); _sprite = GetComponent<SpriteRenderer>();
Cables = new List<Cable>(); Cables = new List<Cable>();
Orientation = Orientation.normalized; Orientation = Orientation.normalized;
} }
// Update is called once per frame // Update is called once per frame
private void Update() private void Update()
{ {
UpdateState(); UpdateState();
} }
private void OnMouseEnter() private void OnMouseEnter()
{ {
transform.localScale = _scale * ScaleIncrease; transform.localScale = _scale * ScaleIncrease;
GameManager.Instance.CurrentAnchor = this; GameManager.Instance.CurrentAnchor = this;
Hovering = true; Hovering = true;
} }
private void OnMouseExit() private void OnMouseExit()
{ {
transform.localScale = _scale; transform.localScale = _scale;
if (Equals(GameManager.Instance.CurrentAnchor)) if (Equals(GameManager.Instance.CurrentAnchor))
GameManager.Instance.CurrentAnchor = null; GameManager.Instance.CurrentAnchor = null;
Hovering = false; Hovering = false;
} }
private void OnDestroy() private void OnDestroy()
{ {
foreach(var cable in Cables) foreach(var cable in Cables)
{ {
Destroy(cable.gameObject); Destroy(cable.gameObject);
} }
} }
#endregion #endregion
#region Public Methods #region Public Methods
public bool HasInputAnchor(Anchor target) public bool HasInputAnchor(Anchor target)
{ {
if (IsInput) if (IsInput)
return Cables.Any(c => c.HasInputAnchor(target)); return Cables.Any(c => c.HasInputAnchor(target));
else else
return Gate.HasInputAnchor(target); return Gate.HasInputAnchor(target);
} }
#endregion #endregion
#region Private Methods #region Private Methods
private void UpdateState() private void UpdateState()
{ {
if (_lastActivated == null || _lastActivated != Activated) if (_lastActivated == null || _lastActivated != Activated)
{ {
_sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor; _sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
_lastActivated = Activated; _lastActivated = Activated;
} }
} }
#endregion #endregion
} }
} }
+153 -153
View File
@@ -5,183 +5,183 @@ using UnityEngine;
namespace UntitledLogicGame.Workspace namespace UntitledLogicGame.Workspace
{ {
public class Cable : MonoBehaviour public class Cable : MonoBehaviour
{ {
#region Unity Properties #region Unity Properties
#endregion #endregion
#region Public Properties #region Public Properties
public Anchor StartAnchor public Anchor StartAnchor
{ {
get => _startAnchor; get => _startAnchor;
set set
{ {
_startAnchor = value; _startAnchor = value;
if (value.IsInput) if (value.IsInput)
{ {
if (value.Cables.Count > 0) if (value.Cables.Count > 0)
Destroy(value.Cables.First().gameObject); Destroy(value.Cables.First().gameObject);
} }
} }
} }
public Anchor EndAnchor public Anchor EndAnchor
{ {
get => _endAnchor; get => _endAnchor;
set set
{ {
if (!value.IsInput) if (!value.IsInput)
{ {
_endAnchor = StartAnchor; _endAnchor = StartAnchor;
StartAnchor = value; StartAnchor = value;
} }
else else
{ {
_endAnchor = value; _endAnchor = value;
} }
if (StartAnchor.HasInputAnchor(EndAnchor)) if (StartAnchor.HasInputAnchor(EndAnchor))
{ {
// Loop detected // Loop detected
Destroy(gameObject); Destroy(gameObject);
} }
else else
{ {
StartAnchor.Cables.Add(this); StartAnchor.Cables.Add(this);
if (EndAnchor.Cables.Count > 0) if (EndAnchor.Cables.Count > 0)
Destroy(EndAnchor.Cables.First().gameObject); Destroy(EndAnchor.Cables.First().gameObject);
EndAnchor.Cables = new List<Cable> { this }; EndAnchor.Cables = new List<Cable> { this };
} }
} }
} }
public bool Activated => StartAnchor != null && !StartAnchor.IsInput && StartAnchor.Activated; public bool Activated => StartAnchor != null && !StartAnchor.IsInput && StartAnchor.Activated;
public Vector3 FallbackEndPos { get; set; } public Vector3 FallbackEndPos { get; set; }
#endregion #endregion
#region Private Properties #region Private Properties
private Vector3 _lastStartPos; private Vector3 _lastStartPos;
private Vector3 _lastEndPos; private Vector3 _lastEndPos;
private Anchor _startAnchor; private Anchor _startAnchor;
private Anchor _endAnchor; private Anchor _endAnchor;
private LineRenderer _line; private LineRenderer _line;
private bool? _lastActivated; private bool? _lastActivated;
#endregion #endregion
#region Unity Methods #region Unity Methods
// Start is called before the first frame update // Start is called before the first frame update
private void Start() private void Start()
{ {
_line = GetComponent<LineRenderer>(); _line = GetComponent<LineRenderer>();
Utils.RandomName("Cable", gameObject); Utils.RandomName("Cable", gameObject);
} }
// Update is called once per frame // Update is called once per frame
private void Update() private void Update()
{ {
UpdateColor(); UpdateColor();
UpdateLine(); UpdateLine();
} }
private void OnDestroy() private void OnDestroy()
{ {
if(StartAnchor != null) if(StartAnchor != null)
StartAnchor.Cables.Remove(this); StartAnchor.Cables.Remove(this);
if (EndAnchor != null) if (EndAnchor != null)
EndAnchor.Cables.Remove(this); EndAnchor.Cables.Remove(this);
} }
#endregion #endregion
#region Public Methods #region Public Methods
public bool HasInputAnchor(Anchor target) public bool HasInputAnchor(Anchor target)
{ {
return StartAnchor.HasInputAnchor(target); return StartAnchor.HasInputAnchor(target);
} }
#endregion #endregion
#region Private Methods #region Private Methods
private void UpdateColor() private void UpdateColor()
{ {
if (_lastActivated == null || _lastActivated != Activated) if (_lastActivated == null || _lastActivated != Activated)
{ {
_line.startColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor; _line.startColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
_line.endColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor; _line.endColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
_lastActivated = Activated; _lastActivated = Activated;
} }
} }
private void UpdateLine() private void UpdateLine()
{ {
if (StartAnchor != null) if (StartAnchor != null)
{ {
var startPos = StartAnchor.transform.position; var startPos = StartAnchor.transform.position;
var endPos = EndAnchor == null ? FallbackEndPos : EndAnchor.transform.position; var endPos = EndAnchor == null ? FallbackEndPos : EndAnchor.transform.position;
if (startPos != _lastStartPos || endPos != _lastEndPos) if (startPos != _lastStartPos || endPos != _lastEndPos)
{ {
if (EndAnchor == null) if (EndAnchor == null)
{ {
_line.positionCount = 2; _line.positionCount = 2;
_line.SetPosition(0, startPos); _line.SetPosition(0, startPos);
_line.SetPosition(1, endPos); _line.SetPosition(1, endPos);
} }
else else
{ {
var startOr = StartAnchor.Orientation; var startOr = StartAnchor.Orientation;
var endOr = StartAnchor.Orientation; var endOr = StartAnchor.Orientation;
_line.positionCount = 4; _line.positionCount = 4;
_line.SetPosition(0, startPos); _line.SetPosition(0, startPos);
if (Mathf.Abs(startOr.x) > 0) if (Mathf.Abs(startOr.x) > 0)
{ {
if (Mathf.Abs(endOr.x) > 0) if (Mathf.Abs(endOr.x) > 0)
{ {
var middle = (startPos.x + endPos.x) / 2; var middle = (startPos.x + endPos.x) / 2;
_line.SetPosition(1, new Vector3(middle, startPos.y, startPos.z)); _line.SetPosition(1, new Vector3(middle, startPos.y, startPos.z));
_line.SetPosition(2, new Vector3(middle, endPos.y, startPos.z)); _line.SetPosition(2, new Vector3(middle, endPos.y, startPos.z));
} }
else else
{ {
_line.SetPosition(1, new Vector3(startPos.x, endPos.y, startPos.z)); _line.SetPosition(1, new Vector3(startPos.x, endPos.y, startPos.z));
_line.SetPosition(2, new Vector3(startPos.x, endPos.y, startPos.z)); _line.SetPosition(2, new Vector3(startPos.x, endPos.y, startPos.z));
} }
} }
else else
{ {
if (Mathf.Abs(endOr.x) > 0) if (Mathf.Abs(endOr.x) > 0)
{ {
var middle = (startPos.y + endPos.y) / 2; var middle = (startPos.y + endPos.y) / 2;
_line.SetPosition(1, new Vector3(startPos.x, middle, startPos.z)); _line.SetPosition(1, new Vector3(startPos.x, middle, startPos.z));
_line.SetPosition(2, new Vector3(endPos.x, middle, startPos.z)); _line.SetPosition(2, new Vector3(endPos.x, middle, startPos.z));
} }
else else
{ {
_line.SetPosition(1, new Vector3(endPos.x, startPos.y, startPos.z)); _line.SetPosition(1, new Vector3(endPos.x, startPos.y, startPos.z));
_line.SetPosition(2, new Vector3(endPos.x, startPos.y, startPos.z)); _line.SetPosition(2, new Vector3(endPos.x, startPos.y, startPos.z));
} }
} }
_line.SetPosition(3, endPos); _line.SetPosition(3, endPos);
} }
} }
} }
else else
{ {
_line.positionCount = 0; _line.positionCount = 0;
} }
} }
#endregion #endregion
} }
} }
+83 -83
View File
@@ -6,106 +6,106 @@ using UntitledLogicGame.Workspace.Gates;
namespace UntitledLogicGame.Workspace namespace UntitledLogicGame.Workspace
{ {
public class Gate : MonoBehaviour public class Gate : MonoBehaviour
{ {
#region Unity Properties #region Unity Properties
public GateType GateType; public GateType GateType;
#endregion #endregion
#region Public Properties #region Public Properties
public IEnumerable<Anchor> Anchors public IEnumerable<Anchor> Anchors
{ {
get get
{ {
if(_anchors == null) if(_anchors == null)
_anchors = GetComponentsInChildren<Anchor>().ToList(); _anchors = GetComponentsInChildren<Anchor>().ToList();
return _anchors; return _anchors;
} }
} }
public IEnumerable<Anchor> InputAnchors => Anchors.Where(a => a.IsInput); public IEnumerable<Anchor> InputAnchors => Anchors.Where(a => a.IsInput);
public IEnumerable<Anchor> OutputAnchors => Anchors.Where(a => !a.IsInput); public IEnumerable<Anchor> OutputAnchors => Anchors.Where(a => !a.IsInput);
public BoxCollider2D Box { public BoxCollider2D Box {
get get
{ {
if (_box == null) if (_box == null)
_box = GetComponentInChildren<BoxCollider2D>(); _box = GetComponentInChildren<BoxCollider2D>();
return _box; return _box;
} }
} }
public GateSprite Sprite public GateSprite Sprite
{ {
get get
{ {
if(_sprite == null) if(_sprite == null)
_sprite = GetComponentInChildren<GateSprite>(); _sprite = GetComponentInChildren<GateSprite>();
return _sprite; return _sprite;
} }
} }
public GateDefinition Definition public GateDefinition Definition
{ {
get get
{ {
if(_definition == null) if(_definition == null)
_definition = GateDefinition.Get(GateType, this); _definition = GateDefinition.Get(GateType, this);
return _definition; return _definition;
} }
} }
#endregion #endregion
#region Private Properties #region Private Properties
private IEnumerable<Anchor> _anchors; private IEnumerable<Anchor> _anchors;
private GateDefinition _definition; private GateDefinition _definition;
private int _lastState = -1; private int _lastState = -1;
private BoxCollider2D _box; private BoxCollider2D _box;
private GateSprite _sprite; private GateSprite _sprite;
#endregion #endregion
#region Unity Methods #region Unity Methods
private void Start() private void Start()
{ {
Utils.RandomName(Definition.Name, gameObject); Utils.RandomName(Definition.Name, gameObject);
} }
// Update is called once per frame // Update is called once per frame
private void Update() private void Update()
{ {
UpdateState(); UpdateState();
} }
#endregion #endregion
#region Public Methods #region Public Methods
public bool HasInputAnchor(Anchor target) public bool HasInputAnchor(Anchor target)
{ {
return !Definition.HasState && ( return !Definition.HasState && (
InputAnchors.Contains(target) || InputAnchors.Contains(target) ||
InputAnchors.Any(a => a.HasInputAnchor(target)) InputAnchors.Any(a => a.HasInputAnchor(target))
); );
} }
#endregion #endregion
#region Private Methods #region Private Methods
private void UpdateState() private void UpdateState()
{ {
var state = Definition.GetState(this).ToInt(); var state = Definition.GetState(this).ToInt();
if (state != _lastState) if (state != _lastState)
{ {
Definition.Compute(this); Definition.Compute(this);
_lastState = state; _lastState = state;
} }
} }
#endregion #endregion
} }
} }
+32 -32
View File
@@ -6,53 +6,53 @@ using UntitledLogicGame.Workspace.Gates;
namespace UntitledLogicGame.Workspace namespace UntitledLogicGame.Workspace
{ {
public class GateSprite : MonoBehaviour public class GateSprite : MonoBehaviour
{ {
#region Unity Properties #region Unity Properties
#endregion #endregion
#region Public Properties #region Public Properties
public bool Hovering { get; internal set; } public bool Hovering { get; internal set; }
#endregion #endregion
#region Private Properties #region Private Properties
private Gate _gate; private Gate _gate;
#endregion #endregion
#region Unity Methods #region Unity Methods
private void Start() private void Start()
{ {
_gate = GetComponentInParent<Gate>(); _gate = GetComponentInParent<Gate>();
} }
private void OnMouseEnter() private void OnMouseEnter()
{ {
GameManager.Instance.CurrentGate = _gate; GameManager.Instance.CurrentGate = _gate;
Hovering = true; Hovering = true;
} }
private void OnMouseExit() private void OnMouseExit()
{ {
if (_gate.Equals(GameManager.Instance.CurrentGate)) if (_gate.Equals(GameManager.Instance.CurrentGate))
GameManager.Instance.CurrentGate = null; GameManager.Instance.CurrentGate = null;
Hovering = false; Hovering = false;
} }
#endregion #endregion
#region Public Methods #region Public Methods
#endregion #endregion
#region Private Methods #region Private Methods
#endregion #endregion
} }
} }
+24 -24
View File
@@ -1,35 +1,35 @@
namespace UntitledLogicGame.Workspace.Gates namespace UntitledLogicGame.Workspace.Gates
{ {
public enum GateType public enum GateType
{ {
// 000 - Technical // 000 - Technical
None = 000, None = 000,
// 100 - I/O // 100 - I/O
IN = 100, IN = 100,
OUT = 110, OUT = 110,
// 200 - Basic // 200 - Basic
BUF = 200, BUF = 200,
AND = 210, AND = 210,
OR = 220, OR = 220,
XOR = 230, XOR = 230,
NOT = 240, NOT = 240,
NAND = 250, NAND = 250,
NOR = 260, NOR = 260,
XNOR = 270, XNOR = 270,
// 300 - Latches // 300 - Latches
SRLatch = 300, SRLatch = 300,
JKLatch = 310, JKLatch = 310,
DLatch = 320, DLatch = 320,
// 500 - Flip-Flops // 500 - Flip-Flops
SRFlipFlop = 400, SRFlipFlop = 400,
JKFlipFlop = 410, JKFlipFlop = 410,
DFlipFlop = 420, DFlipFlop = 420,
TFlipFlop = 430, TFlipFlop = 430,
// 500 - Arithmetic // 500 - Arithmetic
HalfAdd = 500, HalfAdd = 500,
FullAdd = 510, FullAdd = 510,
HalfSub = 520, HalfSub = 520,
FullSub = 530, FullSub = 530,
// 600 - Data // 600 - Data
Mux = 610, Mux = 610,
Demux = 620, Demux = 620,
+57 -57
View File
@@ -3,77 +3,77 @@ using System.Linq;
namespace UntitledLogicGame.Workspace.Gates namespace UntitledLogicGame.Workspace.Gates
{ {
public class InputState : State public class InputState : State
{ {
public InputState(IEnumerable<bool> args) : base(args) { } public InputState(IEnumerable<bool> args) : base(args) { }
public InputState(params bool[] args) : base(args) { } public InputState(params bool[] args) : base(args) { }
public InputState(int len) : base(len) { } public InputState(int len) : base(len) { }
} }
public class OutputState : State public class OutputState : State
{ {
public OutputState(IEnumerable<bool> args) : base(args) { } public OutputState(IEnumerable<bool> args) : base(args) { }
public OutputState(params bool[] args) : base(args) { } public OutputState(params bool[] args) : base(args) { }
public OutputState(int len) : base(len) { } public OutputState(int len) : base(len) { }
} }
public abstract class State public abstract class State
{ {
internal int Length => values.Length; internal int Length => values.Length;
internal bool[] values; internal bool[] values;
public State(IEnumerable<bool> args) public State(IEnumerable<bool> args)
{ {
values = args.ToArray(); values = args.ToArray();
} }
public State(params bool[] args) public State(params bool[] args)
{ {
values = args; values = args;
} }
public State(int len) public State(int len)
{ {
values = new bool[len]; values = new bool[len];
} }
public bool this[int index] public bool this[int index]
{ {
get get
{ {
if (index < 0 || index >= values.Length) if (index < 0 || index >= values.Length)
return false; return false;
return values[index]; return values[index];
} }
set set
{ {
if (index >= 0 && index < values.Length) if (index >= 0 && index < values.Length)
values[index] = value; values[index] = value;
} }
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return obj is State state && Enumerable.SequenceEqual(values, state.values); return obj is State state && Enumerable.SequenceEqual(values, state.values);
} }
public override int GetHashCode() public override int GetHashCode()
{ {
//https://stackoverflow.com/questions/6832139/gethashcode-from-booleans-only //https://stackoverflow.com/questions/6832139/gethashcode-from-booleans-only
int hash = 17; int hash = 17;
for (int index = 0; index < values.Length; index++) for (int index = 0; index < values.Length; index++)
hash = hash * 23 + values[index].GetHashCode(); hash = hash * 23 + values[index].GetHashCode();
return hash; return hash;
} }
public override string ToString() public override string ToString()
{ {
return string.Join(",", values); return string.Join(",", values);
} }
} }
} }
+41 -41
View File
@@ -5,62 +5,62 @@ using UnityEngine;
namespace UntitledLogicGame.Workspace namespace UntitledLogicGame.Workspace
{ {
public class InputGate : Gate public class InputGate : Gate
{ {
#region Unity Properties #region Unity Properties
#endregion #endregion
#region Public Properties #region Public Properties
public bool State { get; set; } public bool State { get; set; }
#endregion #endregion
#region Private Properties #region Private Properties
private Anchor OutputAnchor { private Anchor OutputAnchor {
get get
{ {
if (_outputAnchor == null) if (_outputAnchor == null)
_outputAnchor = Anchors.First(g => g.Name == "Q"); _outputAnchor = Anchors.First(g => g.Name == "Q");
return _outputAnchor; return _outputAnchor;
} }
} }
private Anchor _outputAnchor; private Anchor _outputAnchor;
#endregion #endregion
#region Unity Methods #region Unity Methods
private void Start() private void Start()
{ {
Utils.RandomName("Input", gameObject); Utils.RandomName("Input", gameObject);
} }
private void Update() private void Update()
{ {
UpdateState(); UpdateState();
} }
#endregion #endregion
#region Public Methods #region Public Methods
#endregion #endregion
#region Private Methods #region Private Methods
private void UpdateState() private void UpdateState()
{ {
if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick()) if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick())
{ {
State = !State; State = !State;
OutputAnchor.Activated = State; OutputAnchor.Activated = State;
} }
} }
#endregion #endregion
} }
} }
+34 -34
View File
@@ -5,53 +5,53 @@ using UnityEngine;
namespace UntitledLogicGame.Workspace namespace UntitledLogicGame.Workspace
{ {
public class OutputGate : Gate public class OutputGate : Gate
{ {
#region Unity Properties #region Unity Properties
#endregion #endregion
#region Public Properties #region Public Properties
public bool State { public bool State {
get get
{ {
return InputAnchor.Activated; return InputAnchor.Activated;
} }
} }
#endregion #endregion
#region Private Properties #region Private Properties
private Anchor InputAnchor { private Anchor InputAnchor {
get get
{ {
if (_inputAnchor == null) if (_inputAnchor == null)
_inputAnchor = Anchors.First(g => g.Name == "A"); _inputAnchor = Anchors.First(g => g.Name == "A");
return _inputAnchor; return _inputAnchor;
} }
} }
private Anchor _inputAnchor; private Anchor _inputAnchor;
#endregion #endregion
#region Unity Methods #region Unity Methods
private void Start() private void Start()
{ {
Utils.RandomName("Output", gameObject); Utils.RandomName("Output", gameObject);
} }
#endregion #endregion
#region Public Methods #region Public Methods
#endregion #endregion
#region Private Methods #region Private Methods
#endregion #endregion
} }
} }
@@ -87,7 +87,7 @@ Properties {
SubShader { SubShader {
Tags Tags
{ {
"Queue"="Overlay" "Queue"="Overlay"
"IgnoreProjector"="True" "IgnoreProjector"="True"
"RenderType"="Transparent" "RenderType"="Transparent"
+237 -237
View File
@@ -1,308 +1,308 @@
Shader "TextMeshPro/Distance Field SSD" { Shader "TextMeshPro/Distance Field SSD" {
Properties { Properties {
_FaceTex ("Face Texture", 2D) = "white" {} _FaceTex ("Face Texture", 2D) = "white" {}
_FaceUVSpeedX ("Face UV Speed X", Range(-5, 5)) = 0.0 _FaceUVSpeedX ("Face UV Speed X", Range(-5, 5)) = 0.0
_FaceUVSpeedY ("Face UV Speed Y", Range(-5, 5)) = 0.0 _FaceUVSpeedY ("Face UV Speed Y", Range(-5, 5)) = 0.0
[HDR]_FaceColor ("Face Color", Color) = (1,1,1,1) [HDR]_FaceColor ("Face Color", Color) = (1,1,1,1)
_FaceDilate ("Face Dilate", Range(-1,1)) = 0 _FaceDilate ("Face Dilate", Range(-1,1)) = 0
[HDR]_OutlineColor ("Outline Color", Color) = (0,0,0,1) [HDR]_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_OutlineTex ("Outline Texture", 2D) = "white" {} _OutlineTex ("Outline Texture", 2D) = "white" {}
_OutlineUVSpeedX ("Outline UV Speed X", Range(-5, 5)) = 0.0 _OutlineUVSpeedX ("Outline UV Speed X", Range(-5, 5)) = 0.0
_OutlineUVSpeedY ("Outline UV Speed Y", Range(-5, 5)) = 0.0 _OutlineUVSpeedY ("Outline UV Speed Y", Range(-5, 5)) = 0.0
_OutlineWidth ("Outline Thickness", Range(0, 1)) = 0 _OutlineWidth ("Outline Thickness", Range(0, 1)) = 0
_OutlineSoftness ("Outline Softness", Range(0,1)) = 0 _OutlineSoftness ("Outline Softness", Range(0,1)) = 0
_Bevel ("Bevel", Range(0,1)) = 0.5 _Bevel ("Bevel", Range(0,1)) = 0.5
_BevelOffset ("Bevel Offset", Range(-0.5,0.5)) = 0 _BevelOffset ("Bevel Offset", Range(-0.5,0.5)) = 0
_BevelWidth ("Bevel Width", Range(-.5,0.5)) = 0 _BevelWidth ("Bevel Width", Range(-.5,0.5)) = 0
_BevelClamp ("Bevel Clamp", Range(0,1)) = 0 _BevelClamp ("Bevel Clamp", Range(0,1)) = 0
_BevelRoundness ("Bevel Roundness", Range(0,1)) = 0 _BevelRoundness ("Bevel Roundness", Range(0,1)) = 0
_LightAngle ("Light Angle", Range(0.0, 6.2831853)) = 3.1416 _LightAngle ("Light Angle", Range(0.0, 6.2831853)) = 3.1416
[HDR]_SpecularColor ("Specular", Color) = (1,1,1,1) [HDR]_SpecularColor ("Specular", Color) = (1,1,1,1)
_SpecularPower ("Specular", Range(0,4)) = 2.0 _SpecularPower ("Specular", Range(0,4)) = 2.0
_Reflectivity ("Reflectivity", Range(5.0,15.0)) = 10 _Reflectivity ("Reflectivity", Range(5.0,15.0)) = 10
_Diffuse ("Diffuse", Range(0,1)) = 0.5 _Diffuse ("Diffuse", Range(0,1)) = 0.5
_Ambient ("Ambient", Range(1,0)) = 0.5 _Ambient ("Ambient", Range(1,0)) = 0.5
_BumpMap ("Normal map", 2D) = "bump" {} _BumpMap ("Normal map", 2D) = "bump" {}
_BumpOutline ("Bump Outline", Range(0,1)) = 0 _BumpOutline ("Bump Outline", Range(0,1)) = 0
_BumpFace ("Bump Face", Range(0,1)) = 0 _BumpFace ("Bump Face", Range(0,1)) = 0
_ReflectFaceColor ("Reflection Color", Color) = (0,0,0,1) _ReflectFaceColor ("Reflection Color", Color) = (0,0,0,1)
_ReflectOutlineColor("Reflection Color", Color) = (0,0,0,1) _ReflectOutlineColor("Reflection Color", Color) = (0,0,0,1)
_Cube ("Reflection Cubemap", Cube) = "black" { /* TexGen CubeReflect */ } _Cube ("Reflection Cubemap", Cube) = "black" { /* TexGen CubeReflect */ }
_EnvMatrixRotation ("Texture Rotation", vector) = (0, 0, 0, 0) _EnvMatrixRotation ("Texture Rotation", vector) = (0, 0, 0, 0)
[HDR]_UnderlayColor ("Border Color", Color) = (0,0,0, 0.5) [HDR]_UnderlayColor ("Border Color", Color) = (0,0,0, 0.5)
_UnderlayOffsetX ("Border OffsetX", Range(-1,1)) = 0 _UnderlayOffsetX ("Border OffsetX", Range(-1,1)) = 0
_UnderlayOffsetY ("Border OffsetY", Range(-1,1)) = 0 _UnderlayOffsetY ("Border OffsetY", Range(-1,1)) = 0
_UnderlayDilate ("Border Dilate", Range(-1,1)) = 0 _UnderlayDilate ("Border Dilate", Range(-1,1)) = 0
_UnderlaySoftness ("Border Softness", Range(0,1)) = 0 _UnderlaySoftness ("Border Softness", Range(0,1)) = 0
[HDR]_GlowColor ("Color", Color) = (0, 1, 0, 0.5) [HDR]_GlowColor ("Color", Color) = (0, 1, 0, 0.5)
_GlowOffset ("Offset", Range(-1,1)) = 0 _GlowOffset ("Offset", Range(-1,1)) = 0
_GlowInner ("Inner", Range(0,1)) = 0.05 _GlowInner ("Inner", Range(0,1)) = 0.05
_GlowOuter ("Outer", Range(0,1)) = 0.05 _GlowOuter ("Outer", Range(0,1)) = 0.05
_GlowPower ("Falloff", Range(1, 0)) = 0.75 _GlowPower ("Falloff", Range(1, 0)) = 0.75
_WeightNormal ("Weight Normal", float) = 0 _WeightNormal ("Weight Normal", float) = 0
_WeightBold ("Weight Bold", float) = 0.5 _WeightBold ("Weight Bold", float) = 0.5
_ShaderFlags ("Flags", float) = 0 _ShaderFlags ("Flags", float) = 0
_ScaleRatioA ("Scale RatioA", float) = 1 _ScaleRatioA ("Scale RatioA", float) = 1
_ScaleRatioB ("Scale RatioB", float) = 1 _ScaleRatioB ("Scale RatioB", float) = 1
_ScaleRatioC ("Scale RatioC", float) = 1 _ScaleRatioC ("Scale RatioC", float) = 1
_MainTex ("Font Atlas", 2D) = "white" {} _MainTex ("Font Atlas", 2D) = "white" {}
_TextureWidth ("Texture Width", float) = 512 _TextureWidth ("Texture Width", float) = 512
_TextureHeight ("Texture Height", float) = 512 _TextureHeight ("Texture Height", float) = 512
_GradientScale ("Gradient Scale", float) = 5.0 _GradientScale ("Gradient Scale", float) = 5.0
_ScaleX ("Scale X", float) = 1.0 _ScaleX ("Scale X", float) = 1.0
_ScaleY ("Scale Y", float) = 1.0 _ScaleY ("Scale Y", float) = 1.0
_PerspectiveFilter ("Perspective Correction", Range(0, 1)) = 0.875 _PerspectiveFilter ("Perspective Correction", Range(0, 1)) = 0.875
_Sharpness ("Sharpness", Range(-1,1)) = 0 _Sharpness ("Sharpness", Range(-1,1)) = 0
_VertexOffsetX ("Vertex OffsetX", float) = 0 _VertexOffsetX ("Vertex OffsetX", float) = 0
_VertexOffsetY ("Vertex OffsetY", float) = 0 _VertexOffsetY ("Vertex OffsetY", float) = 0
_MaskCoord ("Mask Coordinates", vector) = (0, 0, 32767, 32767) _MaskCoord ("Mask Coordinates", vector) = (0, 0, 32767, 32767)
_ClipRect ("Clip Rect", vector) = (-32767, -32767, 32767, 32767) _ClipRect ("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
_MaskSoftnessX ("Mask SoftnessX", float) = 0 _MaskSoftnessX ("Mask SoftnessX", float) = 0
_MaskSoftnessY ("Mask SoftnessY", float) = 0 _MaskSoftnessY ("Mask SoftnessY", float) = 0
_StencilComp ("Stencil Comparison", Float) = 8 _StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0 _Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255 _StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255
_CullMode ("Cull Mode", Float) = 0 _CullMode ("Cull Mode", Float) = 0
_ColorMask ("Color Mask", Float) = 15 _ColorMask ("Color Mask", Float) = 15
} }
SubShader { SubShader {
Tags Tags
{ {
"Queue" = "Transparent" "Queue" = "Transparent"
"IgnoreProjector" = "True" "IgnoreProjector" = "True"
"RenderType" = "Transparent" "RenderType" = "Transparent"
} }
Stencil Stencil
{ {
Ref[_Stencil] Ref[_Stencil]
Comp[_StencilComp] Comp[_StencilComp]
Pass[_StencilOp] Pass[_StencilOp]
ReadMask[_StencilReadMask] ReadMask[_StencilReadMask]
WriteMask[_StencilWriteMask] WriteMask[_StencilWriteMask]
} }
Cull[_CullMode] Cull[_CullMode]
ZWrite Off ZWrite Off
Lighting Off Lighting Off
Fog { Mode Off } Fog { Mode Off }
ZTest[unity_GUIZTestMode] ZTest[unity_GUIZTestMode]
Blend One OneMinusSrcAlpha Blend One OneMinusSrcAlpha
ColorMask[_ColorMask] ColorMask[_ColorMask]
Pass { Pass {
CGPROGRAM CGPROGRAM
#pragma target 3.0 #pragma target 3.0
#pragma vertex VertShader #pragma vertex VertShader
#pragma fragment PixShader #pragma fragment PixShader
#pragma shader_feature __ BEVEL_ON #pragma shader_feature __ BEVEL_ON
#pragma shader_feature __ UNDERLAY_ON UNDERLAY_INNER #pragma shader_feature __ UNDERLAY_ON UNDERLAY_INNER
#pragma shader_feature __ GLOW_ON #pragma shader_feature __ GLOW_ON
#pragma shader_feature __ FORCE_LINEAR #pragma shader_feature __ FORCE_LINEAR
#pragma multi_compile __ UNITY_UI_CLIP_RECT #pragma multi_compile __ UNITY_UI_CLIP_RECT
#pragma multi_compile __ UNITY_UI_ALPHACLIP #pragma multi_compile __ UNITY_UI_ALPHACLIP
#include "UnityCG.cginc" #include "UnityCG.cginc"
#include "UnityUI.cginc" #include "UnityUI.cginc"
#include "TMPro_Properties.cginc" #include "TMPro_Properties.cginc"
#include "TMPro.cginc" #include "TMPro.cginc"
struct vertex_t { struct vertex_t {
UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
float4 position : POSITION; float4 position : POSITION;
float3 normal : NORMAL; float3 normal : NORMAL;
float4 color : COLOR; float4 color : COLOR;
float2 texcoord0 : TEXCOORD0; float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1; float2 texcoord1 : TEXCOORD1;
}; };
struct pixel_t { struct pixel_t {
UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO UNITY_VERTEX_OUTPUT_STEREO
float4 position : SV_POSITION; float4 position : SV_POSITION;
float4 color : COLOR; float4 color : COLOR;
float2 atlas : TEXCOORD0; float2 atlas : TEXCOORD0;
float weight : TEXCOORD1; float weight : TEXCOORD1;
float2 mask : TEXCOORD2; // Position in object space(xy) float2 mask : TEXCOORD2; // Position in object space(xy)
float3 viewDir : TEXCOORD3; float3 viewDir : TEXCOORD3;
#if (UNDERLAY_ON || UNDERLAY_INNER) #if (UNDERLAY_ON || UNDERLAY_INNER)
float2 texcoord2 : TEXCOORD4; float2 texcoord2 : TEXCOORD4;
float4 underlayColor : COLOR1; float4 underlayColor : COLOR1;
#endif #endif
float4 textures : TEXCOORD5; float4 textures : TEXCOORD5;
}; };
// Used by Unity internally to handle Texture Tiling and Offset. // Used by Unity internally to handle Texture Tiling and Offset.
float4 _FaceTex_ST; float4 _FaceTex_ST;
float4 _OutlineTex_ST; float4 _OutlineTex_ST;
float4 SRGBToLinear(float4 rgba) { float4 SRGBToLinear(float4 rgba) {
return float4(lerp(rgba.rgb / 12.92f, pow((rgba.rgb + 0.055f) / 1.055f, 2.4f), step(0.04045f, rgba.rgb)), rgba.a); return float4(lerp(rgba.rgb / 12.92f, pow((rgba.rgb + 0.055f) / 1.055f, 2.4f), step(0.04045f, rgba.rgb)), rgba.a);
} }
pixel_t VertShader(vertex_t input) pixel_t VertShader(vertex_t input)
{ {
pixel_t output; pixel_t output;
UNITY_INITIALIZE_OUTPUT(pixel_t, output); UNITY_INITIALIZE_OUTPUT(pixel_t, output);
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input,output); UNITY_TRANSFER_INSTANCE_ID(input,output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float bold = step(input.texcoord1.y, 0); float bold = step(input.texcoord1.y, 0);
float4 vert = input.position; float4 vert = input.position;
vert.x += _VertexOffsetX; vert.x += _VertexOffsetX;
vert.y += _VertexOffsetY; vert.y += _VertexOffsetY;
float4 vPosition = UnityObjectToClipPos(vert); float4 vPosition = UnityObjectToClipPos(vert);
float weight = lerp(_WeightNormal, _WeightBold, bold) / 4.0; float weight = lerp(_WeightNormal, _WeightBold, bold) / 4.0;
weight = (weight + _FaceDilate) * _ScaleRatioA * 0.5; weight = (weight + _FaceDilate) * _ScaleRatioA * 0.5;
#if (UNDERLAY_ON || UNDERLAY_INNER) #if (UNDERLAY_ON || UNDERLAY_INNER)
float4 underlayColor = _UnderlayColor; float4 underlayColor = _UnderlayColor;
underlayColor.rgb *= underlayColor.a; underlayColor.rgb *= underlayColor.a;
float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth; float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth;
float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight; float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight;
float2 bOffset = float2(x, y); float2 bOffset = float2(x, y);
#endif #endif
// Generate UV for the Masking Texture // Generate UV for the Masking Texture
float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
// Support for texture tiling and offset // Support for texture tiling and offset
float2 textureUV = UnpackUV(input.texcoord1.x); float2 textureUV = UnpackUV(input.texcoord1.x);
float2 faceUV = TRANSFORM_TEX(textureUV, _FaceTex); float2 faceUV = TRANSFORM_TEX(textureUV, _FaceTex);
float2 outlineUV = TRANSFORM_TEX(textureUV, _OutlineTex); float2 outlineUV = TRANSFORM_TEX(textureUV, _OutlineTex);
float4 color = input.color; float4 color = input.color;
#if (FORCE_LINEAR && !UNITY_COLORSPACE_GAMMA) #if (FORCE_LINEAR && !UNITY_COLORSPACE_GAMMA)
color = SRGBToLinear(input.color); color = SRGBToLinear(input.color);
#endif #endif
output.position = vPosition; output.position = vPosition;
output.color = color; output.color = color;
output.atlas = input.texcoord0; output.atlas = input.texcoord0;
output.weight = weight; output.weight = weight;
output.mask = half2(vert.xy * 2 - clampedRect.xy - clampedRect.zw); output.mask = half2(vert.xy * 2 - clampedRect.xy - clampedRect.zw);
output.viewDir = mul((float3x3)_EnvMatrix, _WorldSpaceCameraPos.xyz - mul(unity_ObjectToWorld, vert).xyz); output.viewDir = mul((float3x3)_EnvMatrix, _WorldSpaceCameraPos.xyz - mul(unity_ObjectToWorld, vert).xyz);
#if (UNDERLAY_ON || UNDERLAY_INNER) #if (UNDERLAY_ON || UNDERLAY_INNER)
output.texcoord2 = input.texcoord0 + bOffset; output.texcoord2 = input.texcoord0 + bOffset;
output.underlayColor = underlayColor; output.underlayColor = underlayColor;
#endif #endif
output.textures = float4(faceUV, outlineUV); output.textures = float4(faceUV, outlineUV);
return output; return output;
} }
fixed4 PixShader(pixel_t input) : SV_Target fixed4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
float c = tex2D(_MainTex, input.atlas).a; float c = tex2D(_MainTex, input.atlas).a;
float2 pixelSize = float2(ddx(input.atlas.y), ddy(input.atlas.y)); float2 pixelSize = float2(ddx(input.atlas.y), ddy(input.atlas.y));
pixelSize *= _TextureWidth * .75; pixelSize *= _TextureWidth * .75;
float scale = rsqrt(dot(pixelSize, pixelSize)) * _GradientScale * (_Sharpness + 1); float scale = rsqrt(dot(pixelSize, pixelSize)) * _GradientScale * (_Sharpness + 1);
float weight = input.weight; float weight = input.weight;
float bias = (.5 - weight) + (.5 / scale); float bias = (.5 - weight) + (.5 / scale);
float sd = (bias - c) * scale; float sd = (bias - c) * scale;
float outline = (_OutlineWidth * _ScaleRatioA) * scale; float outline = (_OutlineWidth * _ScaleRatioA) * scale;
float softness = (_OutlineSoftness * _ScaleRatioA) * scale; float softness = (_OutlineSoftness * _ScaleRatioA) * scale;
half4 faceColor = _FaceColor; half4 faceColor = _FaceColor;
half4 outlineColor = _OutlineColor; half4 outlineColor = _OutlineColor;
faceColor.rgb *= input.color.rgb; faceColor.rgb *= input.color.rgb;
faceColor *= tex2D(_FaceTex, input.textures.xy + float2(_FaceUVSpeedX, _FaceUVSpeedY) * _Time.y); faceColor *= tex2D(_FaceTex, input.textures.xy + float2(_FaceUVSpeedX, _FaceUVSpeedY) * _Time.y);
outlineColor *= tex2D(_OutlineTex, input.textures.zw + float2(_OutlineUVSpeedX, _OutlineUVSpeedY) * _Time.y); outlineColor *= tex2D(_OutlineTex, input.textures.zw + float2(_OutlineUVSpeedX, _OutlineUVSpeedY) * _Time.y);
faceColor = GetColor(sd, faceColor, outlineColor, outline, softness); faceColor = GetColor(sd, faceColor, outlineColor, outline, softness);
#if BEVEL_ON #if BEVEL_ON
float3 dxy = float3(0.5 / _TextureWidth, 0.5 / _TextureHeight, 0); float3 dxy = float3(0.5 / _TextureWidth, 0.5 / _TextureHeight, 0);
float3 n = GetSurfaceNormal(input.atlas, weight, dxy); float3 n = GetSurfaceNormal(input.atlas, weight, dxy);
float3 bump = UnpackNormal(tex2D(_BumpMap, input.textures.xy + float2(_FaceUVSpeedX, _FaceUVSpeedY) * _Time.y)).xyz; float3 bump = UnpackNormal(tex2D(_BumpMap, input.textures.xy + float2(_FaceUVSpeedX, _FaceUVSpeedY) * _Time.y)).xyz;
bump *= lerp(_BumpFace, _BumpOutline, saturate(sd + outline * 0.5)); bump *= lerp(_BumpFace, _BumpOutline, saturate(sd + outline * 0.5));
n = normalize(n - bump); n = normalize(n - bump);
float3 light = normalize(float3(sin(_LightAngle), cos(_LightAngle), -1.0)); float3 light = normalize(float3(sin(_LightAngle), cos(_LightAngle), -1.0));
float3 col = GetSpecular(n, light); float3 col = GetSpecular(n, light);
faceColor.rgb += col * faceColor.a; faceColor.rgb += col * faceColor.a;
faceColor.rgb *= 1 - (dot(n, light) * _Diffuse); faceColor.rgb *= 1 - (dot(n, light) * _Diffuse);
faceColor.rgb *= lerp(_Ambient, 1, n.z * n.z); faceColor.rgb *= lerp(_Ambient, 1, n.z * n.z);
fixed4 reflcol = texCUBE(_Cube, reflect(input.viewDir, -n)); fixed4 reflcol = texCUBE(_Cube, reflect(input.viewDir, -n));
faceColor.rgb += reflcol.rgb * lerp(_ReflectFaceColor.rgb, _ReflectOutlineColor.rgb, saturate(sd + outline * 0.5)) * faceColor.a; faceColor.rgb += reflcol.rgb * lerp(_ReflectFaceColor.rgb, _ReflectOutlineColor.rgb, saturate(sd + outline * 0.5)) * faceColor.a;
#endif #endif
#if (UNDERLAY_ON || UNDERLAY_INNER) #if (UNDERLAY_ON || UNDERLAY_INNER)
float bScale = scale; float bScale = scale;
bScale /= 1 + ((_UnderlaySoftness * _ScaleRatioC) * bScale); bScale /= 1 + ((_UnderlaySoftness * _ScaleRatioC) * bScale);
float bBias = (0.5 - weight) * bScale - 0.5 - ((_UnderlayDilate * _ScaleRatioC) * 0.5 * bScale); float bBias = (0.5 - weight) * bScale - 0.5 - ((_UnderlayDilate * _ScaleRatioC) * 0.5 * bScale);
#endif #endif
#if UNDERLAY_ON #if UNDERLAY_ON
float d = tex2D(_MainTex, input.texcoord2.xy).a * bScale; float d = tex2D(_MainTex, input.texcoord2.xy).a * bScale;
faceColor += input.underlayColor * saturate(d - bBias) * (1 - faceColor.a); faceColor += input.underlayColor * saturate(d - bBias) * (1 - faceColor.a);
#endif #endif
#if UNDERLAY_INNER #if UNDERLAY_INNER
float d = tex2D(_MainTex, input.texcoord2.xy).a * bScale; float d = tex2D(_MainTex, input.texcoord2.xy).a * bScale;
faceColor += input.underlayColor * (1 - saturate(d - bBias)) * saturate(1 - sd) * (1 - faceColor.a); faceColor += input.underlayColor * (1 - saturate(d - bBias)) * saturate(1 - sd) * (1 - faceColor.a);
#endif #endif
#if GLOW_ON #if GLOW_ON
float4 glowColor = GetGlowColor(sd, scale); float4 glowColor = GetGlowColor(sd, scale);
faceColor.rgb += glowColor.rgb * glowColor.a; faceColor.rgb += glowColor.rgb * glowColor.a;
#endif #endif
// Alternative implementation to UnityGet2DClipping with support for softness. // Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
float2 maskZW = 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + (1 / scale)); float2 maskZW = 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + (1 / scale));
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * maskZW); half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * maskZW);
faceColor *= m.x * m.y; faceColor *= m.x * m.y;
#endif #endif
#if UNITY_UI_ALPHACLIP #if UNITY_UI_ALPHACLIP
clip(faceColor.a - 0.001); clip(faceColor.a - 0.001);
#endif #endif
return faceColor * input.color.a; return faceColor * input.color.a;
} }
ENDCG ENDCG
} }
} }
Fallback "TextMeshPro/Mobile/Distance Field" Fallback "TextMeshPro/Mobile/Distance Field"
@@ -233,7 +233,7 @@ SubShader {
c *= input.texcoord1.z; c *= input.texcoord1.z;
#endif #endif
#if UNITY_UI_ALPHACLIP #if UNITY_UI_ALPHACLIP
clip(c.a - 0.001); clip(c.a - 0.001);
#endif #endif
@@ -55,7 +55,7 @@ Properties {
SubShader { SubShader {
Tags Tags
{ {
"Queue"="Overlay" "Queue"="Overlay"
"IgnoreProjector"="True" "IgnoreProjector"="True"
"RenderType"="Transparent" "RenderType"="Transparent"
@@ -226,7 +226,7 @@ SubShader {
c *= input.texcoord1.z; c *= input.texcoord1.z;
#endif #endif
#if UNITY_UI_ALPHACLIP #if UNITY_UI_ALPHACLIP
clip(c.a - 0.001); clip(c.a - 0.001);
#endif #endif
@@ -54,7 +54,7 @@ Properties {
_StencilWriteMask ("Stencil Write Mask", Float) = 255 _StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255
_CullMode ("Cull Mode", Float) = 0 _CullMode ("Cull Mode", Float) = 0
_ColorMask ("Color Mask", Float) = 15 _ColorMask ("Color Mask", Float) = 15
} }
@@ -6,7 +6,7 @@
Shader "TextMeshPro/Mobile/Distance Field" { Shader "TextMeshPro/Mobile/Distance Field" {
Properties { Properties {
[HDR]_FaceColor ("Face Color", Color) = (1,1,1,1) [HDR]_FaceColor ("Face Color", Color) = (1,1,1,1)
_FaceDilate ("Face Dilate", Range(-1,1)) = 0 _FaceDilate ("Face Dilate", Range(-1,1)) = 0
[HDR]_OutlineColor ("Outline Color", Color) = (0,0,0,1) [HDR]_OutlineColor ("Outline Color", Color) = (0,0,0,1)
@@ -74,7 +74,7 @@ SubShader {
fixed4 color : COLOR; fixed4 color : COLOR;
float2 uv_MainTex; float2 uv_MainTex;
float2 uv2_FaceTex; float2 uv2_FaceTex;
float2 uv2_OutlineTex; float2 uv2_OutlineTex;
float2 param; // Weight, Scale float2 param; // Weight, Scale
float3 viewDirEnv; float3 viewDirEnv;
}; };
@@ -24,11 +24,11 @@ Properties {
_BumpOutline ("Bump Outline", Range(0,1)) = 0.5 _BumpOutline ("Bump Outline", Range(0,1)) = 0.5
_BumpFace ("Bump Face", Range(0,1)) = 0.5 _BumpFace ("Bump Face", Range(0,1)) = 0.5
_ReflectFaceColor ("Face Color", Color) = (0,0,0,1) _ReflectFaceColor ("Face Color", Color) = (0,0,0,1)
_ReflectOutlineColor ("Outline Color", Color) = (0,0,0,1) _ReflectOutlineColor ("Outline Color", Color) = (0,0,0,1)
_Cube ("Reflection Cubemap", Cube) = "black" { /* TexGen CubeReflect */ } _Cube ("Reflection Cubemap", Cube) = "black" { /* TexGen CubeReflect */ }
_EnvMatrixRotation ("Texture Rotation", vector) = (0, 0, 0, 0) _EnvMatrixRotation ("Texture Rotation", vector) = (0, 0, 0, 0)
[HDR]_SpecColor ("Specular Color", Color) = (0,0,0,1) [HDR]_SpecColor ("Specular Color", Color) = (0,0,0,1)
_FaceShininess ("Face Shininess", Range(0,1)) = 0 _FaceShininess ("Face Shininess", Range(0,1)) = 0
_OutlineShininess ("Outline Shininess", Range(0,1)) = 0 _OutlineShininess ("Outline Shininess", Range(0,1)) = 0
@@ -89,7 +89,7 @@ SubShader {
fixed4 color : COLOR; fixed4 color : COLOR;
float2 uv_MainTex; float2 uv_MainTex;
float2 uv2_FaceTex; float2 uv2_FaceTex;
float2 uv2_OutlineTex; float2 uv2_OutlineTex;
float2 param; // Weight, Scale float2 param; // Weight, Scale
float3 viewDirEnv; float3 viewDirEnv;
}; };
+1 -1
View File
@@ -305,7 +305,7 @@ SubShader {
clip(faceColor.a - 0.001); clip(faceColor.a - 0.001);
#endif #endif
return faceColor * input.color.a; return faceColor * input.color.a;
} }
ENDCG ENDCG
@@ -59,16 +59,16 @@ Shader "TextMeshPro/Sprite"
struct appdata_t struct appdata_t
{ {
float4 vertex : POSITION; float4 vertex : POSITION;
float4 color : COLOR; float4 color : COLOR;
float2 texcoord : TEXCOORD0; float2 texcoord : TEXCOORD0;
}; };
struct v2f struct v2f
{ {
float4 vertex : SV_POSITION; float4 vertex : SV_POSITION;
fixed4 color : COLOR; fixed4 color : COLOR;
half2 texcoord : TEXCOORD0; half2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1; float4 worldPosition : TEXCOORD1;
}; };
+2 -2
View File
@@ -30,7 +30,7 @@ float3 GetSurfaceNormal(float4 h, float bias)
float bevelWidth = max(.01, _OutlineWidth+_BevelWidth); float bevelWidth = max(.01, _OutlineWidth+_BevelWidth);
// Track outline // Track outline
h -= .5; h -= .5;
h /= bevelWidth; h /= bevelWidth;
h = saturate(h+.5); h = saturate(h+.5);
@@ -49,7 +49,7 @@ float3 GetSurfaceNormal(float4 h, float bias)
float3 GetSurfaceNormal(float2 uv, float bias, float3 delta) float3 GetSurfaceNormal(float2 uv, float bias, float3 delta)
{ {
// Read "height field" // Read "height field"
float4 h = {tex2D(_MainTex, uv - delta.xz).a, float4 h = {tex2D(_MainTex, uv - delta.xz).a,
tex2D(_MainTex, uv + delta.xz).a, tex2D(_MainTex, uv + delta.xz).a,
tex2D(_MainTex, uv - delta.zy).a, tex2D(_MainTex, uv - delta.zy).a,
tex2D(_MainTex, uv + delta.zy).a}; tex2D(_MainTex, uv + delta.zy).a};
+112 -112
View File
@@ -1,157 +1,157 @@
struct vertex_t { struct vertex_t {
UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
float4 position : POSITION; float4 position : POSITION;
float3 normal : NORMAL; float3 normal : NORMAL;
float4 color : COLOR; float4 color : COLOR;
float2 texcoord0 : TEXCOORD0; float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1; float2 texcoord1 : TEXCOORD1;
}; };
struct pixel_t { struct pixel_t {
UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO UNITY_VERTEX_OUTPUT_STEREO
float4 position : SV_POSITION; float4 position : SV_POSITION;
float4 faceColor : COLOR; float4 faceColor : COLOR;
float4 outlineColor : COLOR1; float4 outlineColor : COLOR1;
float4 texcoord0 : TEXCOORD0; float4 texcoord0 : TEXCOORD0;
float4 param : TEXCOORD1; // weight, scaleRatio float4 param : TEXCOORD1; // weight, scaleRatio
float2 mask : TEXCOORD2; float2 mask : TEXCOORD2;
#if (UNDERLAY_ON || UNDERLAY_INNER) #if (UNDERLAY_ON || UNDERLAY_INNER)
float4 texcoord2 : TEXCOORD3; float4 texcoord2 : TEXCOORD3;
float4 underlayColor : COLOR2; float4 underlayColor : COLOR2;
#endif #endif
}; };
float4 SRGBToLinear(float4 rgba) { float4 SRGBToLinear(float4 rgba) {
return float4(lerp(rgba.rgb / 12.92f, pow((rgba.rgb + 0.055f) / 1.055f, 2.4f), step(0.04045f, rgba.rgb)), rgba.a); return float4(lerp(rgba.rgb / 12.92f, pow((rgba.rgb + 0.055f) / 1.055f, 2.4f), step(0.04045f, rgba.rgb)), rgba.a);
} }
pixel_t VertShader(vertex_t input) pixel_t VertShader(vertex_t input)
{ {
pixel_t output; pixel_t output;
UNITY_INITIALIZE_OUTPUT(pixel_t, output); UNITY_INITIALIZE_OUTPUT(pixel_t, output);
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output); UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float bold = step(input.texcoord1.y, 0); float bold = step(input.texcoord1.y, 0);
float4 vert = input.position; float4 vert = input.position;
vert.x += _VertexOffsetX; vert.x += _VertexOffsetX;
vert.y += _VertexOffsetY; vert.y += _VertexOffsetY;
float4 vPosition = UnityObjectToClipPos(vert); float4 vPosition = UnityObjectToClipPos(vert);
float weight = lerp(_WeightNormal, _WeightBold, bold) / 4.0; float weight = lerp(_WeightNormal, _WeightBold, bold) / 4.0;
weight = (weight + _FaceDilate) * _ScaleRatioA * 0.5; weight = (weight + _FaceDilate) * _ScaleRatioA * 0.5;
// Generate UV for the Masking Texture // Generate UV for the Masking Texture
float4 clampedRect = clamp(_ClipRect, -2e10, 2e10); float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
float2 maskUV = (vert.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy); float2 maskUV = (vert.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy);
float4 color = input.color; float4 color = input.color;
#if (FORCE_LINEAR && !UNITY_COLORSPACE_GAMMA) #if (FORCE_LINEAR && !UNITY_COLORSPACE_GAMMA)
color = SRGBToLinear(input.color); color = SRGBToLinear(input.color);
#endif #endif
float opacity = color.a; float opacity = color.a;
#if (UNDERLAY_ON | UNDERLAY_INNER) #if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0; opacity = 1.0;
#endif #endif
float4 faceColor = float4(color.rgb, opacity) * _FaceColor; float4 faceColor = float4(color.rgb, opacity) * _FaceColor;
faceColor.rgb *= faceColor.a; faceColor.rgb *= faceColor.a;
float4 outlineColor = _OutlineColor; float4 outlineColor = _OutlineColor;
outlineColor.a *= opacity; outlineColor.a *= opacity;
outlineColor.rgb *= outlineColor.a; outlineColor.rgb *= outlineColor.a;
output.position = vPosition; output.position = vPosition;
output.faceColor = faceColor; output.faceColor = faceColor;
output.outlineColor = outlineColor; output.outlineColor = outlineColor;
output.texcoord0 = float4(input.texcoord0.xy, maskUV.xy); output.texcoord0 = float4(input.texcoord0.xy, maskUV.xy);
output.param = float4(0.5 - weight, 1.3333 * _GradientScale * (_Sharpness + 1) / _TextureWidth, _OutlineWidth * _ScaleRatioA * 0.5, 0); output.param = float4(0.5 - weight, 1.3333 * _GradientScale * (_Sharpness + 1) / _TextureWidth, _OutlineWidth * _ScaleRatioA * 0.5, 0);
float2 mask = float2(0, 0); float2 mask = float2(0, 0);
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
mask = vert.xy * 2 - clampedRect.xy - clampedRect.zw; mask = vert.xy * 2 - clampedRect.xy - clampedRect.zw;
#endif #endif
output.mask = mask; output.mask = mask;
#if (UNDERLAY_ON || UNDERLAY_INNER) #if (UNDERLAY_ON || UNDERLAY_INNER)
float4 underlayColor = _UnderlayColor; float4 underlayColor = _UnderlayColor;
underlayColor.rgb *= underlayColor.a; underlayColor.rgb *= underlayColor.a;
float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth; float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth;
float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight; float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight;
output.texcoord2 = float4(input.texcoord0 + float2(x, y), input.color.a, 0); output.texcoord2 = float4(input.texcoord0 + float2(x, y), input.color.a, 0);
output.underlayColor = underlayColor; output.underlayColor = underlayColor;
#endif #endif
return output; return output;
} }
float4 PixShader(pixel_t input) : SV_Target float4 PixShader(pixel_t input) : SV_Target
{ {
UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_INSTANCE_ID(input);
float d = tex2D(_MainTex, input.texcoord0.xy).a; float d = tex2D(_MainTex, input.texcoord0.xy).a;
float2 UV = input.texcoord0.xy; float2 UV = input.texcoord0.xy;
float scale = rsqrt(abs(ddx(UV.x) * ddy(UV.y) - ddy(UV.x) * ddx(UV.y))) * input.param.y; float scale = rsqrt(abs(ddx(UV.x) * ddy(UV.y) - ddy(UV.x) * ddx(UV.y))) * input.param.y;
#if (UNDERLAY_ON | UNDERLAY_INNER) #if (UNDERLAY_ON | UNDERLAY_INNER)
float layerScale = scale; float layerScale = scale;
layerScale /= 1 + ((_UnderlaySoftness * _ScaleRatioC) * layerScale); layerScale /= 1 + ((_UnderlaySoftness * _ScaleRatioC) * layerScale);
float layerBias = input.param.x * layerScale - .5 - ((_UnderlayDilate * _ScaleRatioC) * .5 * layerScale); float layerBias = input.param.x * layerScale - .5 - ((_UnderlayDilate * _ScaleRatioC) * .5 * layerScale);
#endif #endif
scale /= 1 + (_OutlineSoftness * _ScaleRatioA * scale); scale /= 1 + (_OutlineSoftness * _ScaleRatioA * scale);
float4 faceColor = input.faceColor * saturate((d - input.param.x) * scale + 0.5); float4 faceColor = input.faceColor * saturate((d - input.param.x) * scale + 0.5);
#ifdef OUTLINE_ON #ifdef OUTLINE_ON
float4 outlineColor = lerp(input.faceColor, input.outlineColor, sqrt(min(1.0, input.param.z * scale * 2))); float4 outlineColor = lerp(input.faceColor, input.outlineColor, sqrt(min(1.0, input.param.z * scale * 2)));
faceColor = lerp(outlineColor, input.faceColor, saturate((d - input.param.x - input.param.z) * scale + 0.5)); faceColor = lerp(outlineColor, input.faceColor, saturate((d - input.param.x - input.param.z) * scale + 0.5));
faceColor *= saturate((d - input.param.x + input.param.z) * scale + 0.5); faceColor *= saturate((d - input.param.x + input.param.z) * scale + 0.5);
#endif #endif
#if UNDERLAY_ON #if UNDERLAY_ON
d = tex2D(_MainTex, input.texcoord2.xy).a * layerScale; d = tex2D(_MainTex, input.texcoord2.xy).a * layerScale;
faceColor += float4(_UnderlayColor.rgb * _UnderlayColor.a, _UnderlayColor.a) * saturate(d - layerBias) * (1 - faceColor.a); faceColor += float4(_UnderlayColor.rgb * _UnderlayColor.a, _UnderlayColor.a) * saturate(d - layerBias) * (1 - faceColor.a);
#endif #endif
#if UNDERLAY_INNER #if UNDERLAY_INNER
float bias = input.param.x * scale - 0.5; float bias = input.param.x * scale - 0.5;
float sd = saturate(d * scale - bias - input.param.z); float sd = saturate(d * scale - bias - input.param.z);
d = tex2D(_MainTex, input.texcoord2.xy).a * layerScale; d = tex2D(_MainTex, input.texcoord2.xy).a * layerScale;
faceColor += float4(_UnderlayColor.rgb * _UnderlayColor.a, _UnderlayColor.a) * (1 - saturate(d - layerBias)) * sd * (1 - faceColor.a); faceColor += float4(_UnderlayColor.rgb * _UnderlayColor.a, _UnderlayColor.a) * (1 - saturate(d - layerBias)) * sd * (1 - faceColor.a);
#endif #endif
#ifdef MASKING #ifdef MASKING
float a = abs(_MaskInverse - tex2D(_MaskTex, input.texcoord0.zw).a); float a = abs(_MaskInverse - tex2D(_MaskTex, input.texcoord0.zw).a);
float t = a + (1 - _MaskWipeControl) * _MaskEdgeSoftness - _MaskWipeControl; float t = a + (1 - _MaskWipeControl) * _MaskEdgeSoftness - _MaskWipeControl;
a = saturate(t / _MaskEdgeSoftness); a = saturate(t / _MaskEdgeSoftness);
faceColor.rgb = lerp(_MaskEdgeColor.rgb * faceColor.a, faceColor.rgb, a); faceColor.rgb = lerp(_MaskEdgeColor.rgb * faceColor.a, faceColor.rgb, a);
faceColor *= a; faceColor *= a;
#endif #endif
// Alternative implementation to UnityGet2DClipping with support for softness // Alternative implementation to UnityGet2DClipping with support for softness
#if UNITY_UI_CLIP_RECT #if UNITY_UI_CLIP_RECT
float2 maskZW = 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + (1 / scale)); float2 maskZW = 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + (1 / scale));
float2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * maskZW); float2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * maskZW);
faceColor *= m.x * m.y; faceColor *= m.x * m.y;
#endif #endif
#if (UNDERLAY_ON | UNDERLAY_INNER) #if (UNDERLAY_ON | UNDERLAY_INNER)
faceColor *= input.texcoord2.z; faceColor *= input.texcoord2.z;
#endif #endif
#if UNITY_UI_ALPHACLIP #if UNITY_UI_ALPHACLIP
clip(faceColor.a - 0.001); clip(faceColor.a - 0.001);
#endif #endif
return faceColor; return faceColor;
} }
@@ -27,7 +27,7 @@ uniform fixed4 _ReflectFaceColor; // RGB intensity
uniform fixed4 _ReflectOutlineColor; uniform fixed4 _ReflectOutlineColor;
//uniform float _EnvTiltX; // v[-1, 1] //uniform float _EnvTiltX; // v[-1, 1]
//uniform float _EnvTiltY; // v[-1, 1] //uniform float _EnvTiltY; // v[-1, 1]
uniform float3 _EnvMatrixRotation; uniform float3 _EnvMatrixRotation;
uniform float4x4 _EnvMatrix; uniform float4x4 _EnvMatrix;
uniform fixed4 _SpecularColor; // RGB intensity uniform fixed4 _SpecularColor; // RGB intensity
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 48757dac925275d4f96aeee179368303
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
View File
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b1a9b9bb9f39fef44b3e7b76dea70d42
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: