first commit
This commit is contained in:
8
Assets/Materials/JusticeScale/Demo.meta
Normal file
8
Assets/Materials/JusticeScale/Demo.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d54349b8fcfed645b8418495d5f0d2d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Demo/Materials.meta
Normal file
8
Assets/Materials/JusticeScale/Demo/Materials.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 282a0ccb827d994479810da8b5dde61a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Assets/Materials/JusticeScale/Demo/Materials/Gray.mat
Normal file
128
Assets/Materials/JusticeScale/Demo/Materials/Gray.mat
Normal file
@@ -0,0 +1,128 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Gray
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.23423356, g: 0.23139185, b: 0.26037726, a: 1}
|
||||
- _Color: {r: 0.23423353, g: 0.23139182, b: 0.26037723, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &7091203286646534079
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 5
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5927a6e33f31f7649992673def661779
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Demo/Models.meta
Normal file
8
Assets/Materials/JusticeScale/Demo/Models.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab797149bfc715e4d8eec15c9a88289d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Materials/JusticeScale/Demo/Models/Kettlebell.fbx
Normal file
BIN
Assets/Materials/JusticeScale/Demo/Models/Kettlebell.fbx
Normal file
Binary file not shown.
107
Assets/Materials/JusticeScale/Demo/Models/Kettlebell.fbx.meta
Normal file
107
Assets/Materials/JusticeScale/Demo/Models/Kettlebell.fbx.meta
Normal file
@@ -0,0 +1,107 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9fdcd8ba368330488bc6d2193f8282f
|
||||
ModelImporter:
|
||||
serializedVersion: 22200
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
materials:
|
||||
materialImportMode: 2
|
||||
materialName: 0
|
||||
materialSearch: 1
|
||||
materialLocation: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 4
|
||||
bakeSimulation: 0
|
||||
resampleCurves: 1
|
||||
optimizeGameObjects: 0
|
||||
removeConstantScaleCurves: 0
|
||||
motionNodeName:
|
||||
animationImportErrors:
|
||||
animationImportWarnings:
|
||||
animationRetargetingWarnings:
|
||||
animationDoRetargetingWarnings: 0
|
||||
importAnimatedCustomProperties: 0
|
||||
importConstraints: 0
|
||||
animationCompression: 1
|
||||
animationRotationError: 0.5
|
||||
animationPositionError: 0.5
|
||||
animationScaleError: 0.5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
extraUserProperties: []
|
||||
clipAnimations: []
|
||||
isReadable: 0
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: 1
|
||||
meshCompression: 0
|
||||
addColliders: 0
|
||||
useSRGBMaterialColor: 1
|
||||
sortHierarchyByName: 1
|
||||
importPhysicalCameras: 1
|
||||
importVisibility: 1
|
||||
importBlendShapes: 1
|
||||
importCameras: 1
|
||||
importLights: 1
|
||||
nodeNameCollisionStrategy: 1
|
||||
fileIdsGeneration: 2
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 0
|
||||
useFileUnits: 1
|
||||
keepQuads: 0
|
||||
weldVertices: 1
|
||||
bakeAxisConversion: 1
|
||||
preserveHierarchy: 0
|
||||
skinWeightsMode: 0
|
||||
maxBonesPerVertex: 4
|
||||
minBoneWeight: 0.001
|
||||
optimizeBones: 1
|
||||
meshOptimizationFlags: -1
|
||||
indexFormat: 0
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVMarginMethod: 1
|
||||
secondaryUVMinLightmapResolution: 40
|
||||
secondaryUVMinObjectScale: 1
|
||||
secondaryUVPackMargin: 4
|
||||
useFileScale: 1
|
||||
strictVertexDataChecks: 0
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 3
|
||||
normalCalculationMode: 4
|
||||
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
|
||||
blendShapeNormalImportMode: 1
|
||||
normalSmoothingSource: 0
|
||||
referencedClips: []
|
||||
importAnimation: 1
|
||||
humanDescription:
|
||||
serializedVersion: 3
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: 0.5
|
||||
foreArmTwist: 0.5
|
||||
upperLegTwist: 0.5
|
||||
legTwist: 0.5
|
||||
armStretch: 0.05
|
||||
legStretch: 0.05
|
||||
feetSpacing: 0
|
||||
globalScale: 1
|
||||
rootMotionBoneName:
|
||||
hasTranslationDoF: 0
|
||||
hasExtraRoot: 0
|
||||
skeletonHasParents: 1
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
autoGenerateAvatarMappingIfUnspecified: 1
|
||||
animationType: 2
|
||||
humanoidOversampling: 1
|
||||
avatarSetup: 0
|
||||
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
|
||||
importBlendShapeDeformPercent: 1
|
||||
remapMaterialsIfMaterialImportModeIsNone: 0
|
||||
additionalBone: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Demo/Scripts.meta
Normal file
8
Assets/Materials/JusticeScale/Demo/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a93b6b6ec1eaa43448ec1518ee9b3948
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Materials/JusticeScale/Demo/Scripts/ClickAndClone.cs
Normal file
35
Assets/Materials/JusticeScale/Demo/Scripts/ClickAndClone.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Demo.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class ClickAndClone : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject prefabToClone;
|
||||
[SerializeField] private float customMass;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
GetComponent<Collider>().isTrigger = true;
|
||||
}
|
||||
|
||||
private void OnMouseDown()
|
||||
{
|
||||
if (prefabToClone == null) return;
|
||||
|
||||
var clone = Instantiate(prefabToClone, transform.position, transform.rotation);
|
||||
|
||||
var dragScript = clone.GetComponent<DragAndDrop>();
|
||||
clone.GetComponent<Rigidbody>().mass = customMass;
|
||||
clone.transform.localScale = transform.lossyScale;
|
||||
clone.layer = gameObject.layer;
|
||||
|
||||
if (dragScript != null)
|
||||
{
|
||||
dragScript.isDragging = true;
|
||||
dragScript.StartDrag();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 601e2d9933b5441c806242732c65e8d5
|
||||
timeCreated: 1730344731
|
||||
12
Assets/Materials/JusticeScale/Demo/Scripts/DestroyObjects.cs
Normal file
12
Assets/Materials/JusticeScale/Demo/Scripts/DestroyObjects.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Demo.Scripts
|
||||
{
|
||||
public class DestroyObjects : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aada9d88d1d9ad34bb4210ccaf7a0950
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/Materials/JusticeScale/Demo/Scripts/DragAndDrop.cs
Normal file
84
Assets/Materials/JusticeScale/Demo/Scripts/DragAndDrop.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using JusticeScale.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Demo.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody)),RequireComponent(typeof(Collider))]
|
||||
public class DragAndDrop : MonoBehaviour
|
||||
{
|
||||
private Vector3 _mousePosition, _mouseCameraPos, _initialPosition;
|
||||
private Transform _scaleTransform;
|
||||
|
||||
private Rigidbody _objectRigidbody;
|
||||
private float _lerpPosition;
|
||||
|
||||
[HideInInspector] public bool isDragging;
|
||||
private Camera _camera;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_objectRigidbody = GetComponent<Rigidbody>();
|
||||
_scaleTransform = FindAnyObjectByType<ScaleController>().transform;
|
||||
}
|
||||
|
||||
private Vector3 GetMousePos()
|
||||
{
|
||||
return Camera.main != null ? Camera.main.WorldToScreenPoint(transform.position) : Vector3.zero;
|
||||
}
|
||||
|
||||
public void StartDrag()
|
||||
{
|
||||
if (_objectRigidbody == null) return;
|
||||
|
||||
_objectRigidbody.useGravity = false;
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
_objectRigidbody.linearVelocity = Vector3.zero;
|
||||
#else
|
||||
_objectRigidbody.velocity = Vector3.zero;
|
||||
#endif
|
||||
|
||||
_initialPosition = transform.position;
|
||||
_mousePosition = Input.mousePosition - GetMousePos();
|
||||
isDragging = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isDragging && _camera)
|
||||
{
|
||||
_objectRigidbody.angularVelocity = Vector3.zero;
|
||||
_mouseCameraPos = _camera.ScreenToWorldPoint(Input.mousePosition - _mousePosition);
|
||||
|
||||
_lerpPosition = Mathf.InverseLerp(_initialPosition.x, _scaleTransform.position.x, _mouseCameraPos.x);
|
||||
|
||||
if (Mathf.Approximately(_lerpPosition, 1)) _initialPosition = _scaleTransform.transform.position;
|
||||
|
||||
transform.position = new Vector3(
|
||||
_mouseCameraPos.x,
|
||||
_mouseCameraPos.y,
|
||||
Mathf.Lerp(_initialPosition.z, _scaleTransform.position.z, _lerpPosition));
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
EndDrag();
|
||||
}
|
||||
}
|
||||
|
||||
private void EndDrag()
|
||||
{
|
||||
if (!_objectRigidbody) return;
|
||||
|
||||
isDragging = false;
|
||||
_objectRigidbody.useGravity = true;
|
||||
}
|
||||
|
||||
private void OnMouseDown()
|
||||
{
|
||||
StartDrag();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f45618ea93ba6c44bba244f917e13c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Materials/JusticeScale/Demo/Scripts/SliderWeight.cs
Normal file
19
Assets/Materials/JusticeScale/Demo/Scripts/SliderWeight.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using JusticeScale.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace JusticeScale.Demo.Scripts
|
||||
{
|
||||
public class SliderWeight : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private ScaleController scaleController;
|
||||
[SerializeField] private Text weightText;
|
||||
|
||||
|
||||
public void SetWeightValue(float value)
|
||||
{
|
||||
scaleController.maxWeightDifference = value;
|
||||
weightText.text = $"Max weight difference between scales set to {(int)value} kg";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1aec17a504e99c4e9df01b69c23e2aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Materials.meta
Normal file
8
Assets/Materials/JusticeScale/Materials.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 859f9d66402eb064fb8e4e69ddc951fc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Assets/Materials/JusticeScale/Materials/Scale Material.mat
Normal file
128
Assets/Materials/JusticeScale/Materials/Scale Material.mat
Normal file
@@ -0,0 +1,128 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Scale Material
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 2800000, guid: 2dc6ebd5c25b30941ad5a918726df2ce, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 2800000, guid: 4fef29b6c07bf45419c6aacc9cd63a76, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 2800000, guid: 2dc6ebd5c25b30941ad5a918726df2ce, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.807
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 1
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.807
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &8180631315674384172
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 5
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 420237c116853014f8edb92c2be7192a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Models.meta
Normal file
8
Assets/Materials/JusticeScale/Models.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bfe70a0576096740b53f3f68e397981
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Materials/JusticeScale/Models/Scale.fbx
Normal file
BIN
Assets/Materials/JusticeScale/Models/Scale.fbx
Normal file
Binary file not shown.
112
Assets/Materials/JusticeScale/Models/Scale.fbx.meta
Normal file
112
Assets/Materials/JusticeScale/Models/Scale.fbx.meta
Normal file
@@ -0,0 +1,112 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8030ac516a6bdc49bcc7766bb7cf880
|
||||
ModelImporter:
|
||||
serializedVersion: 22200
|
||||
internalIDToNameTable: []
|
||||
externalObjects:
|
||||
- first:
|
||||
type: UnityEngine:Material
|
||||
assembly: UnityEngine.CoreModule
|
||||
name: Material
|
||||
second: {fileID: 2100000, guid: 420237c116853014f8edb92c2be7192a, type: 2}
|
||||
materials:
|
||||
materialImportMode: 2
|
||||
materialName: 0
|
||||
materialSearch: 1
|
||||
materialLocation: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 4
|
||||
bakeSimulation: 0
|
||||
resampleCurves: 1
|
||||
optimizeGameObjects: 0
|
||||
removeConstantScaleCurves: 0
|
||||
motionNodeName:
|
||||
animationImportErrors:
|
||||
animationImportWarnings:
|
||||
animationRetargetingWarnings:
|
||||
animationDoRetargetingWarnings: 0
|
||||
importAnimatedCustomProperties: 0
|
||||
importConstraints: 0
|
||||
animationCompression: 1
|
||||
animationRotationError: 0.5
|
||||
animationPositionError: 0.5
|
||||
animationScaleError: 0.5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
extraUserProperties: []
|
||||
clipAnimations: []
|
||||
isReadable: 1
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: 1
|
||||
meshCompression: 0
|
||||
addColliders: 0
|
||||
useSRGBMaterialColor: 1
|
||||
sortHierarchyByName: 1
|
||||
importPhysicalCameras: 1
|
||||
importVisibility: 0
|
||||
importBlendShapes: 1
|
||||
importCameras: 0
|
||||
importLights: 0
|
||||
nodeNameCollisionStrategy: 1
|
||||
fileIdsGeneration: 2
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 0
|
||||
useFileUnits: 1
|
||||
keepQuads: 0
|
||||
weldVertices: 1
|
||||
bakeAxisConversion: 1
|
||||
preserveHierarchy: 0
|
||||
skinWeightsMode: 0
|
||||
maxBonesPerVertex: 4
|
||||
minBoneWeight: 0.001
|
||||
optimizeBones: 1
|
||||
meshOptimizationFlags: -1
|
||||
indexFormat: 0
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVMarginMethod: 1
|
||||
secondaryUVMinLightmapResolution: 40
|
||||
secondaryUVMinObjectScale: 1
|
||||
secondaryUVPackMargin: 4
|
||||
useFileScale: 1
|
||||
strictVertexDataChecks: 0
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 3
|
||||
normalCalculationMode: 4
|
||||
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
|
||||
blendShapeNormalImportMode: 1
|
||||
normalSmoothingSource: 0
|
||||
referencedClips: []
|
||||
importAnimation: 0
|
||||
humanDescription:
|
||||
serializedVersion: 3
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: 0.5
|
||||
foreArmTwist: 0.5
|
||||
upperLegTwist: 0.5
|
||||
legTwist: 0.5
|
||||
armStretch: 0.05
|
||||
legStretch: 0.05
|
||||
feetSpacing: 0
|
||||
globalScale: 1
|
||||
rootMotionBoneName:
|
||||
hasTranslationDoF: 0
|
||||
hasExtraRoot: 0
|
||||
skeletonHasParents: 1
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
autoGenerateAvatarMappingIfUnspecified: 1
|
||||
animationType: 2
|
||||
humanoidOversampling: 1
|
||||
avatarSetup: 0
|
||||
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
|
||||
importBlendShapeDeformPercent: 1
|
||||
remapMaterialsIfMaterialImportModeIsNone: 0
|
||||
additionalBone: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Scripts.meta
Normal file
8
Assets/Materials/JusticeScale/Scripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4b4688c4439e954ebf92c802175af43
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Materials/JusticeScale/Scripts/ScaleBeamRotation.cs
Normal file
40
Assets/Materials/JusticeScale/Scripts/ScaleBeamRotation.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(ScaleController))]
|
||||
public class ScaleBeamRotation : MonoBehaviour
|
||||
{
|
||||
[SerializeField] [Tooltip("Reference to the ScaleController that manages the balance logic.")]
|
||||
private ScaleController scaleController;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The Transform representing the balance beam that rotates based on the weight difference.")]
|
||||
private Transform balanceBeam;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0, 75)]
|
||||
[Tooltip(
|
||||
"Maximum rotation angle of the balance beam in degrees. The beam will rotate between -blendRotation and +blendRotation. " +
|
||||
"It's recommended to test different values in the editor to see how the beam rotates visually.")]
|
||||
private float blendRotation = 15;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Automatically get the ScaleController component attached to the same GameObject
|
||||
if (scaleController == null) scaleController = GetComponent<ScaleController>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// Calculates the rotation based on the normalized balance value.
|
||||
// If BalanceNormalized is 0, the beam is fully tilted to the left (-blendRotation).
|
||||
// If BalanceNormalized is 1, the beam is fully tilted to the right (+blendRotation).
|
||||
// If BalanceNormalized is 0.5, the beam is perfectly balanced (rotation = 0).
|
||||
var rotation = Mathf.Lerp(-blendRotation, blendRotation, scaleController.BalanceNormalized);
|
||||
|
||||
// Apply the calculated rotation to the balance beam's local rotation.
|
||||
balanceBeam.localRotation = Quaternion.Euler(0, 0, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57bc8f46e7805e1498eca027f3419f66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Materials/JusticeScale/Scripts/ScaleController.cs
Normal file
55
Assets/Materials/JusticeScale/Scripts/ScaleController.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using JusticeScale.Scripts.Scales;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Scripts
|
||||
{
|
||||
public class ScaleController : MonoBehaviour
|
||||
{
|
||||
[Header("Scales")]
|
||||
[SerializeField]
|
||||
[Tooltip("Reference to the left scale. Should be assigned to the left side of the balance.")]
|
||||
private Scale leftScale;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Reference to the right scale. Should be assigned to the right side of the balance.")]
|
||||
private Scale rightScale;
|
||||
|
||||
[Tooltip("Normalized value representing the current balance. 0 means fully tilted to the left, 1 means fully tilted to the right, and 0.5 is perfectly balanced.")]
|
||||
public float BalanceNormalized { get; private set; } = 0.5f;
|
||||
|
||||
[Tooltip("The difference in weight between the left and right scales. A positive value means the left scale is heavier, while a negative value means the right scale is heavier.")]
|
||||
public float WeightDifference { get; private set; }
|
||||
|
||||
[Header("Configuration")]
|
||||
[Min(0.01f)]
|
||||
[Tooltip("The maximum weight difference between the two sides for the scale to reach its limit. A higher value makes the balance less sensitive.")]
|
||||
public float maxWeightDifference = 10f;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("The smoothing time for updating the balance. This helps to avoid abrupt changes that could cause erratic behavior or glitches in the balance's operation.")]
|
||||
private float balanceSmoothTime = 0.05f;
|
||||
|
||||
[SerializeField] [Tooltip("Internal smoothed result for the balance. Used for gradual balance adjustments.")]
|
||||
private float weightResultSmoothed;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!leftScale || !rightScale)
|
||||
{
|
||||
Debug.LogWarning("The scale references are not assigned.");
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateBalance();
|
||||
}
|
||||
|
||||
private void UpdateBalance()
|
||||
{
|
||||
var targetWeightDifference = leftScale.TotalWeight - rightScale.TotalWeight;
|
||||
WeightDifference = targetWeightDifference;
|
||||
weightResultSmoothed = Mathf.Lerp(weightResultSmoothed, targetWeightDifference, balanceSmoothTime);
|
||||
|
||||
BalanceNormalized = Mathf.InverseLerp(-maxWeightDifference, maxWeightDifference, weightResultSmoothed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77cc71e5d9b8ba643813860e7cf4b299
|
||||
timeCreated: 1719307373
|
||||
8
Assets/Materials/JusticeScale/Scripts/Scales.meta
Normal file
8
Assets/Materials/JusticeScale/Scripts/Scales.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02bd81f2c0c1782429beed52556f5e7b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
122
Assets/Materials/JusticeScale/Scripts/Scales/OverlapScale.cs
Normal file
122
Assets/Materials/JusticeScale/Scripts/Scales/OverlapScale.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Scripts.Scales
|
||||
{
|
||||
public class OverlapScale : Scale
|
||||
{
|
||||
[Header("Capsule Config")]
|
||||
|
||||
[Min(0)] [SerializeField]
|
||||
private float capsuleLength = 1.5f; // The vertical length of the capsule used to detect objects above the scale
|
||||
|
||||
[Min(0)] [SerializeField]
|
||||
private float capsuleRadius = 0.5f; // The radius of the capsule, determining its width
|
||||
|
||||
[Min(0)] [SerializeField]
|
||||
private float capsuleOffsetHeight = 0.5f; // The vertical offset from the scale’s position to the start of the capsule
|
||||
|
||||
private Vector3 _startPoint, _endPoint; // The calculated start and end points of the capsule
|
||||
|
||||
private readonly HashSet<Rigidbody> _detectedObjects = new(); // Set of detected rigidbodies to avoid duplicates
|
||||
private readonly List<Rigidbody> _objectsInContainer = new(); // List of objects currently inside the capsule area
|
||||
private GameObject _objectContainer; // A container object to parent detected objects
|
||||
|
||||
private float _previousWeight; // Stores the previous total weight to optimize calculations
|
||||
|
||||
// Returns the calculated total weight of objects detected inside the capsule
|
||||
public override float TotalWeight => CalculateWeightInCapsule();
|
||||
|
||||
private float CalculateWeightInCapsule()
|
||||
{
|
||||
weight = 0f;
|
||||
_detectedObjects.Clear();
|
||||
|
||||
// Adjust the capsule variables by the scale of the GameObject
|
||||
var scaledCapsuleLength = capsuleLength * transform.lossyScale.normalized.magnitude;
|
||||
var scaledCapsuleRadius = capsuleRadius * transform.lossyScale.normalized.magnitude;
|
||||
var scaledCapsuleOffsetHeight = capsuleOffsetHeight * transform.lossyScale.normalized.magnitude;
|
||||
|
||||
// Define capsule start and end points based on configuration, adjusted for the scale
|
||||
_startPoint = transform.position + Vector3.up * scaledCapsuleOffsetHeight;
|
||||
_endPoint = _startPoint + Vector3.up * scaledCapsuleLength;
|
||||
|
||||
// Perform the OverlapCapsule detection, gathering all colliders within the volume
|
||||
// ReSharper disable once Unity.PreferNonAllocApi
|
||||
Collider[] colliders = Physics.OverlapCapsule(_startPoint, _endPoint, scaledCapsuleRadius, layerMask);
|
||||
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
var rb = collider.GetComponent<Rigidbody>();
|
||||
if (rb != null && !_detectedObjects.Contains(rb))
|
||||
{
|
||||
_detectedObjects.Add(rb);
|
||||
ManageObjectContainer(rb);
|
||||
|
||||
weight += rb.mass;
|
||||
|
||||
if (!_objectsInContainer.Contains(rb)) _objectsInContainer.Add(rb);
|
||||
}
|
||||
}
|
||||
|
||||
RemoveDetectedObjectsNotInCapsule(_detectedObjects);
|
||||
|
||||
// Exit early if the weight hasn't changed significantly
|
||||
if (Mathf.Abs(weight - _previousWeight) < 0.001f) return _previousWeight;
|
||||
|
||||
_previousWeight = weight;
|
||||
return weight;
|
||||
}
|
||||
|
||||
private void ManageObjectContainer(Rigidbody rb)
|
||||
{
|
||||
if (_objectContainer == null)
|
||||
{
|
||||
_objectContainer = new GameObject("Objects Container");
|
||||
_objectContainer.transform.parent = transform;
|
||||
}
|
||||
|
||||
rb.transform.SetParent(_objectContainer.transform, true);
|
||||
}
|
||||
|
||||
private void RemoveDetectedObjectsNotInCapsule(HashSet<Rigidbody> detectedObjects)
|
||||
{
|
||||
foreach (var obj in _objectsInContainer.ToList())
|
||||
if (!detectedObjects.Contains(obj))
|
||||
{
|
||||
obj.transform.parent = null;
|
||||
_objectsInContainer.Remove(obj);
|
||||
}
|
||||
|
||||
if (detectedObjects.Count == 0) Destroy(_objectContainer);
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (transform == null) return;
|
||||
|
||||
// Adjust the capsule variables by the scale of the GameObject
|
||||
float scaledCapsuleLength = capsuleLength * 0.1f * transform.lossyScale.magnitude;
|
||||
float scaledCapsuleRadius = capsuleRadius * 0.1f * transform.lossyScale.magnitude;
|
||||
float scaledCapsuleOffsetHeight = capsuleOffsetHeight * 0.1f * transform.lossyScale.magnitude;
|
||||
|
||||
// Define the start and end points, adjusted for the object's scale
|
||||
_startPoint = transform.position + Vector3.up * scaledCapsuleOffsetHeight;
|
||||
_endPoint = _startPoint + Vector3.up * scaledCapsuleLength;
|
||||
|
||||
// Draw the capsule in the editor (with scaling applied)
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawWireSphere(_startPoint, scaledCapsuleRadius);
|
||||
Gizmos.DrawWireSphere(_endPoint, scaledCapsuleRadius);
|
||||
Gizmos.DrawLine(
|
||||
_startPoint + Vector3.up * scaledCapsuleRadius,
|
||||
_endPoint + Vector3.up * scaledCapsuleRadius
|
||||
);
|
||||
Gizmos.DrawLine(
|
||||
_startPoint - Vector3.up * scaledCapsuleRadius,
|
||||
_endPoint - Vector3.up * scaledCapsuleRadius
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b64e6584f3a49a5b30287827ab3f516
|
||||
timeCreated: 1731300775
|
||||
18
Assets/Materials/JusticeScale/Scripts/Scales/Scale.cs
Normal file
18
Assets/Materials/JusticeScale/Scripts/Scales/Scale.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Scripts.Scales
|
||||
{
|
||||
public abstract class Scale : MonoBehaviour
|
||||
{
|
||||
public abstract float TotalWeight { get; }
|
||||
[SerializeField] protected LayerMask layerMask = -1; // LayerMask specifying which layers to include in the scale detection
|
||||
|
||||
[SerializeField] [Tooltip("The current weight of the scale (not visible in the Inspector), for easy developer testing.")]
|
||||
protected float weight; // Current weight for inspector display; TotalWeight is the actual calculated value.
|
||||
|
||||
private void Update()
|
||||
{
|
||||
weight = TotalWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Materials/JusticeScale/Scripts/Scales/Scale.cs.meta
Normal file
11
Assets/Materials/JusticeScale/Scripts/Scales/Scale.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a958ddeab399d44eb4e129be0ea1cc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Assets/Materials/JusticeScale/Scripts/Scales/TriggerScale.cs
Normal file
80
Assets/Materials/JusticeScale/Scripts/Scales/TriggerScale.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JusticeScale.Scripts.Scales
|
||||
{
|
||||
[RequireComponent(typeof(MeshCollider))]
|
||||
public class TriggerScale : Scale
|
||||
{
|
||||
[Tooltip("The total weight of the objects currently on this scale trigger.")]
|
||||
public override float TotalWeight => weight;
|
||||
|
||||
// Container for objects detected by the scale
|
||||
private GameObject _objectContainer;
|
||||
|
||||
// HashSet to track objects on the scale, ensuring each is only counted once
|
||||
// (useful if the GameObject has multiple triggers that could detect the same object).
|
||||
private HashSet<Transform> _detectedObjects = new HashSet<Transform>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Initialize the object container at the start
|
||||
_objectContainer = new GameObject("Objects Container");
|
||||
_objectContainer.transform.parent = transform;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var rb = other.GetComponent<Rigidbody>();
|
||||
if (rb != null && IsInDetectableLayer(other.gameObject) && _detectedObjects.Add(rb.transform))
|
||||
{
|
||||
AddObjectToContainer(rb.transform);
|
||||
weight += rb.mass;
|
||||
// Round the total weight to 2 decimal places
|
||||
weight = Mathf.Round(weight * 100f) / 100f;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
var rb = other.GetComponent<Rigidbody>();
|
||||
if (rb != null && _detectedObjects.Remove(rb.transform))
|
||||
{
|
||||
weight -= rb.mass;
|
||||
// Ensure total weight doesn't drop below zero
|
||||
weight = Mathf.Max(0, weight);
|
||||
weight = Mathf.Round(weight * 100f) / 100f;
|
||||
|
||||
RemoveObjectFromContainer(rb.transform);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddObjectToContainer(Transform objectTransform)
|
||||
{
|
||||
if (_objectContainer == null)
|
||||
{
|
||||
// Create a new container for the objects if it doesn't exist
|
||||
_objectContainer = new GameObject("Objects Container");
|
||||
_objectContainer.transform.parent = transform;
|
||||
}
|
||||
|
||||
// Set the parent of the object to the container
|
||||
objectTransform.SetParent(_objectContainer.transform, true);
|
||||
}
|
||||
|
||||
private void RemoveObjectFromContainer(Transform objectTransform)
|
||||
{
|
||||
// Unparent the object from the container
|
||||
if (_objectContainer != null) objectTransform.parent = null;
|
||||
|
||||
// Destroy the container if it has no child objects left
|
||||
if (_objectContainer.transform.childCount == 0) Destroy(_objectContainer);
|
||||
}
|
||||
|
||||
private bool IsInDetectableLayer(GameObject obj)
|
||||
{
|
||||
// Check if the object is in the correct layer
|
||||
return ((layerMask.value & (1 << obj.layer)) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76c938acc67ae6746ad167809e6b86e8
|
||||
timeCreated: 1728533272
|
||||
8
Assets/Materials/JusticeScale/Scripts/UI.meta
Normal file
8
Assets/Materials/JusticeScale/Scripts/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e12ae2f22708f164e9a713227f37bbc0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/Materials/JusticeScale/Scripts/UI/ScaleUI.cs
Normal file
38
Assets/Materials/JusticeScale/Scripts/UI/ScaleUI.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using JusticeScale.Scripts.Scales;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace JusticeScale.Scripts.UI
|
||||
{
|
||||
public class ScaleUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Scale scale; // Reference to the Scale component
|
||||
[SerializeField] private Text balanceText;
|
||||
|
||||
[SerializeField] private bool isInPounds;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Automatically get the TriggerScale component attached to the parent GameObject
|
||||
if (scale == null) scale = GetComponentInParent<TriggerScale>();
|
||||
|
||||
// Automatically get the Text component attached to the child GameObject
|
||||
if (balanceText == null) balanceText = GetComponentInChildren<Text>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Update the balance text based on the selected unit
|
||||
balanceText.text = isInPounds
|
||||
? $"{ConvertKgToPound(scale.TotalWeight)} pounds"
|
||||
: $"{scale.TotalWeight} kg";
|
||||
}
|
||||
|
||||
private float ConvertKgToPound(float massKg)
|
||||
{
|
||||
var poundConverse = massKg * 2.20f;
|
||||
return (float)Math.Round(poundConverse, 2); // Round to 2 decimal places
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Materials/JusticeScale/Scripts/UI/ScaleUI.cs.meta
Normal file
11
Assets/Materials/JusticeScale/Scripts/UI/ScaleUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f638d3b30aee7c34286179635223e13c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Materials/JusticeScale/Textures.meta
Normal file
8
Assets/Materials/JusticeScale/Textures.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af98762767ce4ae42b6bdc60e021ba7f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Materials/JusticeScale/Textures/ScaleAlbedo.png
Normal file
BIN
Assets/Materials/JusticeScale/Textures/ScaleAlbedo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 932 KiB |
156
Assets/Materials/JusticeScale/Textures/ScaleAlbedo.png.meta
Normal file
156
Assets/Materials/JusticeScale/Textures/ScaleAlbedo.png.meta
Normal file
@@ -0,0 +1,156 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dc6ebd5c25b30941ad5a918726df2ce
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 4
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Win64
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
customData:
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user