added scroll thirdparty asset, fixed main menu

This commit is contained in:
dddushesss 2022-02-22 05:10:30 +03:00
parent a690c5b637
commit 0503421766
46 changed files with 88404 additions and 103800 deletions

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:84eabbfc0be363df12205e55cd35551c6634eb773895797bea0c8e121c65fa19
size 6693624

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 591517cbc97ab25469879bccd5718af8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -763,7 +763,7 @@ AnimatorState:
m_MirrorParameterActive: 0 m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0 m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0 m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 46c2b6df43404d447aace3726bf397e3, type: 2} m_Motion: {fileID: 7400000, guid: 591517cbc97ab25469879bccd5718af8, type: 2}
m_Tag: m_Tag:
m_SpeedParameter: m_SpeedParameter:
m_MirrorParameter: m_MirrorParameter:

View File

@ -34,7 +34,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0.3460083, y: 3.835083} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 800, y: 800} m_SizeDelta: {x: 800, y: 800}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &151122389764708870 --- !u!222 &151122389764708870
@ -119,7 +119,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.6925271} m_AnchorMin: {x: 0.5, y: 0.6925271}
m_AnchorMax: {x: 0.5, y: 0.6925271} m_AnchorMax: {x: 0.5, y: 0.6925271}
m_AnchoredPosition: {x: -13, y: -50.5} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 101} m_SizeDelta: {x: 100, y: 101}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!198 &7945853709318545961 --- !u!198 &7945853709318545961
@ -14709,7 +14709,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0.24000001, y: 0.47} m_AnchoredPosition: {x: 0.24000168, y: 0.47}
m_SizeDelta: {x: 100, y: 100} m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!198 &7945853710185188221 --- !u!198 &7945853710185188221
@ -19562,7 +19562,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.6925271} m_AnchorMin: {x: 0.5, y: 0.6925271}
m_AnchorMax: {x: 0.5, y: 0.6925271} m_AnchorMax: {x: 0.5, y: 0.6925271}
m_AnchoredPosition: {x: 0.13, y: -19.05} m_AnchoredPosition: {x: 0.13000107, y: -19.05}
m_SizeDelta: {x: 100, y: 101} m_SizeDelta: {x: 100, y: 101}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!198 &7945853710961685151 --- !u!198 &7945853710961685151
@ -29144,7 +29144,7 @@ ParticleSystemRenderer:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7945853710984940612} m_GameObject: {fileID: 7945853710984940612}
m_Enabled: 0 m_Enabled: 1
m_CastShadows: 0 m_CastShadows: 0
m_ReceiveShadows: 0 m_ReceiveShadows: 0
m_DynamicOccludee: 1 m_DynamicOccludee: 1
@ -29176,7 +29176,7 @@ ParticleSystemRenderer:
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 10
m_RenderMode: 0 m_RenderMode: 0
m_SortMode: 0 m_SortMode: 0
m_MinParticleSize: 0 m_MinParticleSize: 0
@ -29268,7 +29268,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.6925271} m_AnchorMin: {x: 0.5, y: 0.6925271}
m_AnchorMax: {x: 0.5, y: 0.6925271} m_AnchorMax: {x: 0.5, y: 0.6925271}
m_AnchoredPosition: {x: 0.13, y: -19.05} m_AnchoredPosition: {x: 0.13000107, y: -19.05}
m_SizeDelta: {x: 100, y: 101} m_SizeDelta: {x: 100, y: 101}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!198 &7945853711086925321 --- !u!198 &7945853711086925321

View File

@ -15,7 +15,7 @@ MonoBehaviour:
icon: {fileID: 21300000, guid: d199e42b29875f641b7670cd48338056, type: 3} icon: {fileID: 21300000, guid: d199e42b29875f641b7670cd48338056, type: 3}
type: 0 type: 0
_weapon: _weapon:
name: name: Arrow
icon: {fileID: 0} icon: {fileID: 0}
objectToThrow: {fileID: 2042943928877261958, guid: 56c6150849a081a44ad553b57b8f2bd6, type: 3} objectToThrow: {fileID: 2042943928877261958, guid: 56c6150849a081a44ad553b57b8f2bd6, type: 3}
VFXGameObject: {fileID: 0} VFXGameObject: {fileID: 0}

View File

@ -38,7 +38,7 @@ MonoBehaviour:
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0} InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: -1 x: -1
z: 42 z: 42
@ -50,7 +50,7 @@ MonoBehaviour:
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0} InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: -17 x: -17
z: 40 z: 40

View File

@ -14,16 +14,17 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_units: _units:
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: 19 x: 19
z: 4 z: 4
unitPrefa: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055, type: 3} unitPrefa: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055, type: 3}
color: 3 color: 3
manaRegen: 10 manaRegen: 10
maxMana: 100 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
- isPlayer: 1 - isPlayer: 1
isAI: 0 isAI: 0
spawnPos: spawnPos:
@ -35,8 +36,9 @@ MonoBehaviour:
maxMana: 1000 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: -1 x: -1
z: 42 z: 42
@ -46,8 +48,9 @@ MonoBehaviour:
maxMana: 1000 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: -17 x: -17
z: 40 z: 40
@ -57,6 +60,7 @@ MonoBehaviour:
maxMana: 1000 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3} playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3} botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3} attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}

View File

@ -14,7 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_units: _units:
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: 19 x: 19
z: 4 z: 4
@ -24,6 +24,7 @@ MonoBehaviour:
maxMana: 100 maxMana: 100
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
- isPlayer: 1 - isPlayer: 1
isAI: 0 isAI: 0
spawnPos: spawnPos:
@ -35,8 +36,9 @@ MonoBehaviour:
maxMana: 1000 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: -1 x: -1
z: 42 z: 42
@ -46,8 +48,9 @@ MonoBehaviour:
maxMana: 1000 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
- isPlayer: 0 - isPlayer: 0
isAI: 0 isAI: 1
spawnPos: spawnPos:
x: -17 x: -17
z: 40 z: 40
@ -57,6 +60,7 @@ MonoBehaviour:
maxMana: 1000 maxMana: 1000
maxHP: 100 maxHP: 100
inventoryCapacity: 4 inventoryCapacity: 4
InvisibleMaterial: {fileID: 0}
playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3} playerBarCanvas: {fileID: 482855193181693567, guid: dec5dd0d644d5c548a53563e65837162, type: 3}
botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3} botBarCanvas: {fileID: 482855193181693567, guid: 1af9afdbdd132df4989c826eb6cb6562, type: 3}
attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3} attackAimCanvas: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &2267539444992813378 --- !u!1 &854536725
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -8,8 +8,8 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 1223254639636097048} - component: {fileID: 854536727}
- component: {fileID: 4167112940421681381} - component: {fileID: 854536726}
m_Layer: 3 m_Layer: 3
m_Name: Directional Light _Global m_Name: Directional Light _Global
m_TagString: Save m_TagString: Save
@ -17,28 +17,28 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!4 &1223254639636097048 --- !u!4 &854536727
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2267539444992813378} m_GameObject: {fileID: 854536725}
m_LocalRotation: {x: 0.27059805, y: 0.6532815, z: -0.27059805, w: 0.6532815} m_LocalRotation: {x: 0.27059805, y: 0.6532815, z: -0.27059805, w: 0.6532815}
m_LocalPosition: {x: 525.82, y: 971.79, z: 0} m_LocalPosition: {x: 525.82, y: 971.79, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 2301559550879146132} - {fileID: 2019696088}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 45, y: 90, z: 0} m_LocalEulerAnglesHint: {x: 45, y: 90, z: 0}
--- !u!108 &4167112940421681381 --- !u!108 &854536726
Light: Light:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2267539444992813378} m_GameObject: {fileID: 854536725}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 10 serializedVersion: 10
m_Type: 1 m_Type: 1
@ -94,7 +94,7 @@ Light:
m_UseViewFrustumForShadowCasterCull: 1 m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0 m_ShadowRadius: 0
m_ShadowAngle: 0 m_ShadowAngle: 0
--- !u!1 &5088963501171464948 --- !u!1 &2019696087
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -102,8 +102,8 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 2301559550879146132} - component: {fileID: 2019696088}
- component: {fileID: 1774902775368537649} - component: {fileID: 2019696089}
m_Layer: 0 m_Layer: 0
m_Name: Directional Light _Global _2 m_Name: Directional Light _Global _2
m_TagString: Untagged m_TagString: Untagged
@ -111,27 +111,27 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!4 &2301559550879146132 --- !u!4 &2019696088
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5088963501171464948} m_GameObject: {fileID: 2019696087}
m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.70710677} m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.70710677}
m_LocalPosition: {x: -0.000061035156, y: 968.0922, z: 84.69711} m_LocalPosition: {x: -0.000061035156, y: 968.0922, z: 84.69711}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 1223254639636097048} m_Father: {fileID: 854536727}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 135, y: 90, z: 0} m_LocalEulerAnglesHint: {x: 135, y: 90, z: 0}
--- !u!108 &1774902775368537649 --- !u!108 &2019696089
Light: Light:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5088963501171464948} m_GameObject: {fileID: 2019696087}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 10 serializedVersion: 10
m_Type: 1 m_Type: 1

File diff suppressed because it is too large Load Diff

View File

@ -405,7 +405,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &1455205763 --- !u!224 &1455205763
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -51,14 +51,14 @@ namespace Items
} }
container.AimInstance.transform.LookAt(cell.transform); container.AimInstance.transform.LookAt(cell.transform);
container.Direction = direction; container.HexDirection = direction;
} }
public void PlaceItem(ItemContainer container) public void PlaceItem(ItemContainer container)
{ {
container.DeAim(); container.DeAim();
var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.Direction); var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.HexDirection);
if (!isPlacableOnAnotherColor && cell.Color != container.Unit.Color) if (!isPlacableOnAnotherColor && cell.Color != container.Unit.Color)
{ {
return; return;

View File

@ -53,7 +53,7 @@ namespace Items
return; return;
} }
container.AimInstance.transform.LookAt(cell.transform); container.AimInstance.transform.LookAt(cell.transform);
container.Direction = direction; container.HexDirection = direction;
} }
@ -62,7 +62,7 @@ namespace Items
{ {
container.Unit.UseItem(this); container.Unit.UseItem(this);
HexManager.UnitCurrentCell[container.Unit.Color].cell.PaintHex(container.Unit.Color); HexManager.UnitCurrentCell[container.Unit.Color].cell.PaintHex(container.Unit.Color);
var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.Direction); var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.HexDirection);
container.OnItemUsed?.Invoke(); container.OnItemUsed?.Invoke();
container.Unit.UnitView.AnimActionDic[animName] = null; container.Unit.UnitView.AnimActionDic[animName] = null;
@ -79,23 +79,23 @@ namespace Items
itterationMove.ForEach(dir => itterationMove.ForEach(dir =>
{ {
if (!keepGoing) return; if (!keepGoing) return;
container.Direction = dir switch container.HexDirection = dir switch
{ {
Angls.FORWARD => container.Direction, Angls.FORWARD => container.HexDirection,
Angls.PLUS60 => container.Direction.PlusSixtyDeg(), Angls.PLUS60 => container.HexDirection.PlusSixtyDeg(),
Angls.MINUS60 => container.Direction.MinusSixtyDeg(), Angls.MINUS60 => container.HexDirection.MinusSixtyDeg(),
Angls.PLUS120 => container.Direction.Plus120Deg(), Angls.PLUS120 => container.HexDirection.Plus120Deg(),
Angls.MINUS120 => container.Direction.Minus120Deg(), Angls.MINUS120 => container.HexDirection.Minus120Deg(),
Angls.BACK => container.Direction.Back(), Angls.BACK => container.HexDirection.Back(),
_ => throw new ArgumentOutOfRangeException(nameof(dir), dir, null) _ => throw new ArgumentOutOfRangeException(nameof(dir), dir, null)
}; };
if (cell.GetNeighbor(container.Direction) == null) if (cell.GetNeighbor(container.HexDirection) == null)
{ {
keepGoing = false; keepGoing = false;
return; return;
} }
cell = cell.GetNeighbor(container.Direction); cell = cell.GetNeighbor(container.HexDirection);
cell.PaintHex(container.Unit.Color); cell.PaintHex(container.Unit.Color);
}); });
@ -105,7 +105,7 @@ namespace Items
public void UseAbility(ItemContainer container) public void UseAbility(ItemContainer container)
{ {
var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.Direction); var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.HexDirection);
if (cell == null) if (cell == null)
{ {
container.DeAim(); container.DeAim();

View File

@ -20,7 +20,9 @@ namespace Items
public GameObject AimInstance { get; set; } public GameObject AimInstance { get; set; }
public HexDirection Direction { get; set; } public HexDirection HexDirection { get; set; }
public Vector2 Direction { get; set; }
public Unit Value { get; set; } public Unit Value { get; set; }

View File

@ -29,11 +29,12 @@ namespace Items
} }
public void Aim(ItemContainer container, HexDirection direction) public void Aim(ItemContainer container, Vector2 direction)
{ {
container.AimInstance.SetActive(true); container.AimInstance.SetActive(true);
container.AimInstance.transform.LookAt(HexManager.UnitCurrentCell[container.Unit.Color].cell container.AimInstance.transform.LookAt(
.GetNeighbor(container.Direction).transform); new Vector3(direction.x, 0, direction.y) + container.Unit.UnitView.transform.position);
container.Direction = direction; container.Direction = direction;
} }
@ -42,16 +43,15 @@ namespace Items
{ {
container.OnItemUsed.Invoke(); container.OnItemUsed.Invoke();
container.Unit.UseItem(this); container.Unit.UseItem(this);
var cell = HexManager.UnitCurrentCell[container.Unit.Color].cell.GetNeighbor(container.Direction);
container.Unit.RotateUnit(new Vector2((cell.transform.position - container.Unit.Instance.transform.position).normalized.x, container.Unit.RotateUnit(container.Direction);
(cell.transform.position - container.Unit.Instance.transform.position).normalized.z));
_weapon.SetModifiedDamage(0); _weapon.SetModifiedDamage(0);
_weapon.objectToThrow.GetComponent<ISetUp>().SetUp(container.Unit); _weapon.objectToThrow.GetComponent<ISetUp>().SetUp(container.Unit);
container.DeAim(); container.DeAim();
var dir = DirectionHelper.DirectionTo(container.Unit.Instance.transform.position, cell.transform.position);
TimerHelper.Instance.StartTimer(() => TimerHelper.Instance.StartTimer(() =>
{ {
var ball = _weapon.Fire(container.Unit.Instance.transform, new Vector2(dir.x, dir.z), container.Unit); var ball = _weapon.Fire(container.Unit.Instance.transform, container.Direction, container.Unit);
if (isLifeByTime) if (isLifeByTime)
{ {
TimerHelper.Instance.StartTimer(() => TimerHelper.Instance.StartTimer(() =>

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using Data;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using Weapons; using Weapons;
@ -12,9 +13,10 @@ public class ChosenWeapon : MonoBehaviour
[SerializeField] private TMP_Text attackText; [SerializeField] private TMP_Text attackText;
[SerializeField] private TMP_Text reloadText; [SerializeField] private TMP_Text reloadText;
[SerializeField] private string chosenWeaponDataPath; [SerializeField] private string chosenWeaponDataPath;
[SerializeField] private WeaponsData _data;
private Weapon Weapon => private Weapon Weapon =>
JsonUtility.FromJson<Weapon>(File.ReadAllText(Application.persistentDataPath + "/" + chosenWeaponDataPath)); _data.WeaponsList[int.Parse(File.ReadAllText(Application.persistentDataPath + "/" + chosenWeaponDataPath))];
private void Start() private void Start()
{ {

View File

@ -1,4 +1,5 @@
using DG.Tweening; using DanielLochner.Assets.SimpleScrollSnap;
using DG.Tweening;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -11,8 +12,7 @@ namespace MainMenu
[SerializeField] private LevelData _data; [SerializeField] private LevelData _data;
[SerializeField] private LevelView LevelImage; [SerializeField] private LevelView LevelImage;
[SerializeField] private GameObject loadUI; [SerializeField] private GameObject loadUI;
[SerializeField] private Transform parantLevelView; [SerializeField] private SimpleScrollSnap _levelScroll;
[SerializeField] private ScrollerPage _scrollerPage;
private int index = 0; private int index = 0;
private TMP_Text _percentText; private TMP_Text _percentText;
private bool _isLoadingLevel = false; private bool _isLoadingLevel = false;
@ -23,14 +23,18 @@ namespace MainMenu
{ {
loadUI.GetComponent<Image>().DOFade(0f, 0f); loadUI.GetComponent<Image>().DOFade(0f, 0f);
_curLevel = _data.Levels[0]; _curLevel = _data.Levels[0];
var i = 0;
_data.Levels.ForEach(level => _data.Levels.ForEach(level =>
{ {
var lev = Object.Instantiate(LevelImage, parantLevelView);
var lev = Object.Instantiate(LevelImage);
lev.LevelImage.sprite = level.levelSprite; lev.LevelImage.sprite = level.levelSprite;
_levelScroll.Add(lev.gameObject, i++);
}); });
_scrollerPage.Init(); _levelScroll.onPanelChanged.AddListener(() => SelectLevel(_levelScroll.CurrentPanel));
_scrollerPage.OnLevelChanged += SelectLevel;
_percentText = loadUI.GetComponentInChildren<TMP_Text>(); _percentText = loadUI.GetComponentInChildren<TMP_Text>();
} }

View File

@ -1,59 +0,0 @@
using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace MainMenu
{
[RequireComponent(typeof(ScrollRect))]
public class ScrollerPage : MonoBehaviour, IEndDragHandler
{
[SerializeField] private GameObject content;
[SerializeField] private float duration;
[SerializeField] private Ease ease;
private ScrollRect _scrollRect;
private int currentMenu;
private Vector2 startMotion;
public event Action<int> OnLevelChanged;
public void Init()
{
_scrollRect = GetComponent<ScrollRect>();
_scrollRect.onValueChanged.AddListener(FixedScroll);
ScrollToMenu(content.transform.GetChild(0).gameObject);
}
private void ScrollToMenu(GameObject menu)
{
Canvas.ForceUpdateCanvases();
Vector2 viewportLocalPosition = _scrollRect.viewport.localPosition;
Vector2 childLocalPosition = menu.transform.localPosition;
Vector2 result = new Vector2(
0 - (viewportLocalPosition.x + childLocalPosition.x),
0 - (viewportLocalPosition.y + childLocalPosition.y)
);
_scrollRect.content.DOLocalMove(result, duration).SetEase(ease);
}
private void FixedScroll(Vector2 vector2)
{
var step = 1f / (content.transform.childCount - 1);
currentMenu = (int)Math.Round(vector2.x / step);
}
public void OnEndDrag(PointerEventData eventData)
{
ScrollToMenu(content.transform.GetChild(currentMenu).gameObject);
OnLevelChanged?.Invoke(currentMenu);
}
}
}

View File

@ -2,68 +2,52 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using DanielLochner.Assets.SimpleScrollSnap;
using DG.Tweening; using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
[RequireComponent(typeof(ScrollRect))]
public class ToolBarController : MonoBehaviour, IEndDragHandler
{
[SerializeField] private List<GameObject> content;
public class ToolBarController : MonoBehaviour
{
[SerializeField] private List<Button> buttons; [SerializeField] private List<Button> buttons;
[SerializeField] private int startPage; [SerializeField] private SimpleScrollSnap _scrollSnap;
[SerializeField] private float duration; [SerializeField] private bool hasHightlighter;
[SerializeField] private Ease ease;
[SerializeField, ShowIf("hasHightlighter")]
private ScrollRect scrollRect; private GameObject highLighter;
private int currentMenu;
private static readonly int IsSelected = Animator.StringToHash("IsSelected"); [SerializeField, ShowIf("highLighter")] private Ease ease;
[SerializeField, ShowIf("highLighter")] private float duration;
private void Start() private void Start()
{ {
scrollRect = GetComponent<ScrollRect>(); for (var i = 0; i < buttons.Count; i++)
var i = 0;
content.ForEach(con =>
{ {
buttons[i++].onClick.AddListener(delegate { ScrollToMenu(con); }); var i1 = i;
}); buttons[i].onClick.AddListener(() =>
{
scrollRect.content.DOLocalMove(Vector3.zero, 0f); _scrollSnap.GoToPanel(i1);
buttons[startPage].Select(); buttons[i1].Select();
buttons[startPage].onClick.Invoke(); if (hasHightlighter)
scrollRect.onValueChanged.AddListener(FixedScroll); {
Highlight(buttons[i1].transform);
_scrollSnap.onPanelChanged.AddListener(() =>
{
Highlight(buttons[_scrollSnap.CurrentPanel].transform);
buttons[_scrollSnap.CurrentPanel].Select();
});
}
});
}
} }
private void ScrollToMenu(GameObject menu) private void Highlight(Transform buttonTransform)
{ {
Canvas.ForceUpdateCanvases(); highLighter.transform
.DOMove(new Vector3(buttonTransform.position.x, highLighter.transform.position.y, 0), duration)
Vector2 viewportLocalPosition = scrollRect.viewport.localPosition; .SetEase(ease);
Vector2 childLocalPosition = menu.transform.localPosition;
Vector2 result = new Vector2(
0 - (viewportLocalPosition.x + childLocalPosition.x),
0 - (viewportLocalPosition.y + childLocalPosition.y)
);
scrollRect.content.DOLocalMove(result, duration).SetEase(ease);
if(buttons[currentMenu].gameObject.TryGetComponent(typeof(Animator), out var animator))
((Animator)animator).SetBool("IsSelected", true);
}
private void FixedScroll(Vector2 vector2)
{
var step = 1f / (buttons.Count - 1);
currentMenu = (int)Math.Round(vector2.x / step);
}
public void OnEndDrag(PointerEventData eventData)
{
if(buttons[currentMenu].gameObject.TryGetComponent(typeof(Animator), out var animator))
((Animator)animator).SetBool("IsSelected", true);
ScrollToMenu(content[currentMenu]);
} }
} }

View File

@ -157,7 +157,7 @@ namespace Chars
_aimCount = 1; _aimCount = 1;
break; break;
case SpecialWeapon weapon: case SpecialWeapon weapon:
weapon.Aim(_itemToPlace, DirectionHelper.VectorToDirection(placeDir.normalized)); weapon.Aim(_itemToPlace, placeDir.normalized);
break; break;
case SwitchingPlaces switchingPlaces: case SwitchingPlaces switchingPlaces:
switchingPlaces.Aim(placeDir.normalized, _itemToPlace); switchingPlaces.Aim(placeDir.normalized, _itemToPlace);

View File

@ -261,7 +261,7 @@ namespace Units
case "Dead": case "Dead":
_animLength.Death = clip.length; _animLength.Death = clip.length;
break; break;
case "Super_Attack": case "SuperAttack":
_animLength.SuperJump = clip.length; _animLength.SuperJump = clip.length;
break; break;
default: default:
@ -407,7 +407,6 @@ namespace Units
{ {
Aim(_direction); Aim(_direction);
_weapon.Fire(_instance.transform, _direction, this); _weapon.Fire(_instance.transform, _direction, this);
} }

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ecafe02f0a06fb14cb9c2cec664afa0d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e937cf3377017a342be3fabf767a6b4c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:79c88dbbb36904923202d865d6e0d145e85e606a54c0576fe71b10a536db1a4e
size 799004

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9417be83e44ffda408714d0fbcef034e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2119f11b9f187bf48aab7444fc740627
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7763437abd10bcf44abd9146d3ed72d3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a1ec3309957318841a5e68ab2178c627
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,30 @@
<h1>Simple Scroll-Snap</h1>
<i>“Simple Scroll-Snap” is an elegantly designed, intuitive solution that allows for elements within a ScrollView to be snapped to, offering a wide range of customization options.</i>
Try out the demo <a href="https://daniellochner.itch.io/unity3d-assets">here</a>!
<h2>Features:</h2>
<li>Fixed (Horizontal/Vertical) or Free movement system.</li>
<li>Optional Automatic Layout system.</li>
<li>Optional Infinite Scrolling system.</li>
<li>Navigate between panels using Swipe Gestures, a Pagination and/or Next and Previous buttons.</li>
<li>Easily implement Transition Effects (adjusting panels' scale, rotation, opacity etc.) using functions with respect to displacement from the center.</l>
<li>Change to snap to the Nearest, Previous or Next panel.</li>
<li>Define Threshold Swipe and Snap Speeds to best fit your requirements.</li>
<li>Assign methods to be invoked while a panel is being selected, is selected, is being changed or has changed.</l>
<li>Dynamically add/remove panels during runtime.</li>
<li>… and much more!</l>
</ul>
<h2>Included:</h2>
<ul>
<li>Five example projects (macOS Finder (File Explorer), iOS Home Screen, Slot Machine, Pinned Map, Dynamic Content).</li>
<li>Ready-to-use prefabs (Scroll-Snap, Pagination).</li>
<li>In-depth offline documentation.</li>
</ul>
<h2>Contact:</h2>
In the event you are unable to find the information you are looking for or have found a bug, please feel free to send me an email (daniel@daniellochner.com) and I will get back to you as soon as possible.
<h2>Support:</h2>
This asset is 100% free, so please support development, and leave a review if you've found the asset helpful! If you'd like to support me, consider subscribing to my YouTube channel <a href="https://youtube.com/c/daniellochner">here</a>, where I post videos logging the progress of the new game I'm developing! :)

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8f8f35cbaddd4a145b01ef76dc76842e
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ac5becb31a84f784e976e8f3546a5667
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c5e732e29afbbe3428ff2e359bb30b08
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,528 @@
// Simple Scroll-Snap - https://assetstore.unity.com/packages/tools/gui/simple-scroll-snap-140884
// Version: 1.2.1
// Author: Daniel Lochner
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using static DanielLochner.Assets.SimpleScrollSnap.SimpleScrollSnap;
namespace DanielLochner.Assets.SimpleScrollSnap
{
[CustomEditor(typeof(SimpleScrollSnap))]
public class SimpleScrollSnapEditor : UnityEditor.Editor
{
#region Fields
private int selectedProperty;
private float selectedMinValue, selectedMaxValue, selectedMinDisplacement, selectedMaxDisplacement;
private bool showTransitionEffects = true, showMovement = true, showMargin = true, showNavigation = true, showSelection = true, showEvents = true, showDisplacement, showValue;
private SerializedProperty movementType, movementAxis, automaticallyLayout, sizeControl, size, automaticLayoutSpacing, leftMargin, rightMargin, topMargin, bottomMargin, infinitelyScroll, infiniteScrollingEndSpacing, startingPanel, swipeGestures, minimumSwipeSpeed, previousButton, nextButton, pagination, toggleNavigation, snapTarget, snappingSpeed, useUnscaledTime, useOcclusionCulling, thresholdSnappingSpeed, hardSnap, onPanelSelecting, onPanelSelected, onPanelChanging, onPanelChanged;
private SimpleScrollSnap simpleScrollSnap;
private AnimationCurve selectedFunction = AnimationCurve.Constant(0, 1, 1);
#endregion
#region Methods
private void OnEnable()
{
simpleScrollSnap = target as SimpleScrollSnap;
// Serialized Properties
movementType = serializedObject.FindProperty("movementType");
movementAxis = serializedObject.FindProperty("movementAxis");
automaticallyLayout = serializedObject.FindProperty("automaticallyLayout");
sizeControl = serializedObject.FindProperty("sizeControl");
size = serializedObject.FindProperty("size");
automaticLayoutSpacing = serializedObject.FindProperty("automaticLayoutSpacing");
leftMargin = serializedObject.FindProperty("leftMargin");
rightMargin = serializedObject.FindProperty("rightMargin");
topMargin = serializedObject.FindProperty("topMargin");
bottomMargin = serializedObject.FindProperty("bottomMargin");
infinitelyScroll = serializedObject.FindProperty("infinitelyScroll");
useOcclusionCulling = serializedObject.FindProperty("useOcclusionCulling");
infiniteScrollingEndSpacing = serializedObject.FindProperty("infiniteScrollingEndSpacing");
startingPanel = serializedObject.FindProperty("startingPanel");
swipeGestures = serializedObject.FindProperty("swipeGestures");
minimumSwipeSpeed = serializedObject.FindProperty("minimumSwipeSpeed");
previousButton = serializedObject.FindProperty("previousButton");
nextButton = serializedObject.FindProperty("nextButton");
pagination = serializedObject.FindProperty("pagination");
toggleNavigation = serializedObject.FindProperty("toggleNavigation");
snapTarget = serializedObject.FindProperty("snapTarget");
snappingSpeed = serializedObject.FindProperty("snappingSpeed");
thresholdSnappingSpeed = serializedObject.FindProperty("thresholdSnappingSpeed");
hardSnap = serializedObject.FindProperty("hardSnap");
useUnscaledTime = serializedObject.FindProperty("useUnscaledTime");
onPanelSelecting = serializedObject.FindProperty("onPanelSelecting");
onPanelSelected = serializedObject.FindProperty("onPanelSelected");
onPanelChanging = serializedObject.FindProperty("onPanelChanging");
onPanelChanged = serializedObject.FindProperty("onPanelChanged");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
HeaderInformation();
MovementAndLayoutSettings();
NavigationSettings();
SnapSettings();
TransitionEffects();
EventHandlers();
serializedObject.ApplyModifiedProperties();
PrefabUtility.RecordPrefabInstancePropertyModifications(simpleScrollSnap);
}
private void HeaderInformation()
{
GUILayout.BeginVertical("HelpBox");
GUILayout.Label("Simple Scroll-Snap", new GUIStyle() { fontSize = 30, alignment = TextAnchor.MiddleCenter });
GUILayout.Label("Version: 1.2.1", new GUIStyle() { fontSize = 14, alignment = TextAnchor.MiddleCenter });
GUILayout.Label("Author: Daniel Lochner", new GUIStyle() { fontSize = 14, alignment = TextAnchor.MiddleCenter });
GUILayout.EndVertical();
}
private void MovementAndLayoutSettings()
{
EditorGUILayout.Space();
EditorStyles.foldout.fontStyle = FontStyle.Bold;
showMovement = EditorGUILayout.Foldout(showMovement, "Movement and Layout Settings", true);
EditorStyles.foldout.fontStyle = FontStyle.Normal;
if (showMovement)
{
MovementType();
StartingPanel();
}
EditorGUILayout.Space();
}
private void MovementType()
{
EditorGUILayout.PropertyField(movementType, new GUIContent("Movement Type", "Determines how users will be able to move between panels within the ScrollRect."));
if (simpleScrollSnap.movementType == SimpleScrollSnap.MovementType.Fixed)
{
EditorGUI.indentLevel++;
MovementAxis();
AutomaticLayout();
InfiniteScrolling();
UseOcclusionCulling();
EditorGUI.indentLevel--;
}
}
private void MovementAxis()
{
EditorGUILayout.PropertyField(movementAxis, new GUIContent("Movement Axis", "Determines the axis the user's movement will be restricted to."));
}
private void AutomaticLayout()
{
EditorGUILayout.PropertyField(automaticallyLayout, new GUIContent("Automatic Layout", "Should panels be automatically positioned and scaled according to the specified movement axis, spacing, margins and size?"));
if (simpleScrollSnap.automaticallyLayout)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(sizeControl, new GUIContent("Size Control", "Determines how the panels' size should be controlled."));
if (simpleScrollSnap.sizeControl == SimpleScrollSnap.SizeControl.Manual)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(size, new GUIContent("Size", "The size (in pixels) that panels will be when automatically laid out."));
EditorGUI.indentLevel--;
}
EditorGUILayout.Slider(automaticLayoutSpacing, 0, 1, new GUIContent("Spacing", "The spacing between panels, calculated using a fraction of the panels width (if the movement axis is horizontal) or height (if the movement axis is vertical)."));
showMargin = EditorGUILayout.Foldout(showMargin, new GUIContent("Margin", "The size of border (in pixels) for each panel."), true);
if (showMargin)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(leftMargin, new GUIContent("Left"));
EditorGUILayout.PropertyField(rightMargin, new GUIContent("Right"));
EditorGUILayout.PropertyField(topMargin, new GUIContent("Top"));
EditorGUILayout.PropertyField(bottomMargin, new GUIContent("Bottom"));
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}
}
private void InfiniteScrolling()
{
EditorGUILayout.PropertyField(infinitelyScroll, new GUIContent("Infinite Scrolling", "Should panels wrap around to the opposite end once passed, giving the illusion of an infinite list of elements?"));
if (simpleScrollSnap.infinitelyScroll)
{
EditorGUI.indentLevel++;
EditorGUILayout.Slider(infiniteScrollingEndSpacing, 0, 1, new GUIContent("End Spacing", "The spacing maintained between panels once wrapped around to the opposite end."));
EditorGUI.indentLevel--;
}
}
private void UseOcclusionCulling()
{
EditorGUILayout.PropertyField(useOcclusionCulling, new GUIContent("Use Occlusion Culling", "Should panels not visible in the viewport be disabled?"));
}
private void StartingPanel()
{
EditorGUILayout.IntSlider(startingPanel, 0, simpleScrollSnap.NumberOfPanels - 1, new GUIContent("Starting Panel", "The number of the panel that will be displayed first, based on a 0-indexed array."));
}
private void NavigationSettings()
{
EditorStyles.foldout.fontStyle = FontStyle.Bold;
showNavigation = EditorGUILayout.Foldout(showNavigation, "Navigation Settings", true);
EditorStyles.foldout.fontStyle = FontStyle.Normal;
if (showNavigation)
{
SwipeGestures();
PreviousButton();
NextButton();
Pagination();
}
EditorGUILayout.Space();
}
private void SwipeGestures()
{
EditorGUILayout.PropertyField(swipeGestures, new GUIContent("Swipe Gestures", "Should users are able to use swipe gestures to navigate between panels?"));
if (simpleScrollSnap.swipeGestures)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(minimumSwipeSpeed, new GUIContent("Minimum Swipe Speed", "The speed at which the user must be swiping in order for a transition to occur to another panel."));
EditorGUI.indentLevel--;
}
}
private void PreviousButton()
{
EditorGUILayout.ObjectField(previousButton, typeof(Button), new GUIContent("Previous Button", "(Optional) Button used to transition to the previous panel."));
}
private void NextButton()
{
EditorGUILayout.ObjectField(nextButton, typeof(Button), new GUIContent("Next Button", "(Optional) Button used to transition to the next panel."));
}
private void Pagination()
{
EditorGUILayout.ObjectField(pagination, typeof(GameObject), new GUIContent("Pagination", "(Optional) GameObject containing Toggles that shows the current position of the user and can be used to transition to a selected panel."));
if (simpleScrollSnap.pagination != null)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(toggleNavigation, new GUIContent("Toggle Navigation", "Should users be able to transition to panels by clicking on their respective toggle."));
int numberOfToggles = simpleScrollSnap.pagination.transform.childCount;
if (numberOfToggles != simpleScrollSnap.NumberOfPanels)
{
EditorGUILayout.HelpBox("The number of toggles should be equivalent to the number of panels. There are currently " + numberOfToggles + " toggles and " + simpleScrollSnap.NumberOfPanels + " panels.", MessageType.Warning);
}
EditorGUI.indentLevel--;
}
}
private void SnapSettings()
{
EditorStyles.foldout.fontStyle = FontStyle.Bold;
showSelection = EditorGUILayout.Foldout(showSelection, "Snap Settings", true);
EditorStyles.foldout.fontStyle = FontStyle.Normal;
if (showSelection)
{
SnapTarget();
SnapSpeed();
ThresholdSnapSpeed();
HardSnap();
UseUnscaledTime();
}
EditorGUILayout.Space();
}
private void SnapTarget()
{
using (new EditorGUI.DisabledScope(simpleScrollSnap.movementType == SimpleScrollSnap.MovementType.Free))
{
EditorGUILayout.PropertyField(snapTarget, new GUIContent("Snap Target", "Determines what panel should be targeted and snapped to once the threshold snapping speed has been reached."));
}
if (simpleScrollSnap.movementType == SimpleScrollSnap.MovementType.Free)
{
simpleScrollSnap.snapTarget = SimpleScrollSnap.SnapTarget.Nearest;
}
}
private void SnapSpeed()
{
EditorGUILayout.PropertyField(snappingSpeed, new GUIContent("Snap Speed", "The speed at which the targeted panel snaps into position."));
}
private void ThresholdSnapSpeed()
{
EditorGUILayout.PropertyField(thresholdSnappingSpeed, new GUIContent("Threshold Snap Speed", "The speed at which the ScrollRect will stop scrolling and begin snapping to the targeted panel (where -1 is used as infinity)."));
}
private void HardSnap()
{
EditorGUILayout.PropertyField(hardSnap, new GUIContent("Hard Snap", "Should the inertia of the ScrollRect be disabled once a panel has been selected? If enabled, the ScrollRect will not overshoot the targeted panel when snapping into position and instead Lerp precisely towards the targeted panel."));
}
private void UseUnscaledTime()
{
EditorGUILayout.PropertyField(useUnscaledTime, new GUIContent("Use Unscaled Time", "Should the scroll-snap update irrespective of the time scale?"));
}
private void TransitionEffects()
{
EditorStyles.foldout.fontStyle = FontStyle.Bold;
showTransitionEffects = EditorGUILayout.Foldout(showTransitionEffects, new GUIContent("Transition Effects", "Effects applied to panels based on their distance from the center."), true);
EditorStyles.foldout.fontStyle = FontStyle.Normal;
if (showTransitionEffects)
{
EditorGUI.indentLevel++;
AddTransitionEffect();
InitTransitionEffects();
EditorGUI.indentLevel--;
}
EditorGUILayout.Space();
}
private void AddTransitionEffect()
{
// Properties
List<string> properties = new List<string>()
{
"localPosition.z",
"localScale.x",
"localScale.y",
"localRotation.x",
"localRotation.y",
"localRotation.z",
"color.r",
"color.g",
"color.b",
"color.a"
};
for (int i = 0; i < simpleScrollSnap.transitionEffects.Count; i++)
{
properties.Remove(simpleScrollSnap.transitionEffects[i].Label);
}
selectedProperty = EditorGUILayout.Popup(new GUIContent("Property", "The selected property of a panel that will be affected by the distance from the centre."), selectedProperty, properties.ToArray());
// Selected Min/Max Values
showValue = EditorGUILayout.Foldout(showValue, "Value", true);
if (showValue)
{
EditorGUI.indentLevel++;
selectedMinValue = EditorGUILayout.FloatField(new GUIContent("Min", "The minimum value that can be assigned."), selectedMinValue);
selectedMaxValue = EditorGUILayout.FloatField(new GUIContent("Max", "The maximum value that can be assigned."), selectedMaxValue);
EditorGUI.indentLevel--;
}
// Selected Min/Max Displacements
showDisplacement = EditorGUILayout.Foldout(showDisplacement, "Displacement", true);
if (showDisplacement)
{
EditorGUI.indentLevel++;
selectedMinDisplacement = EditorGUILayout.FloatField(new GUIContent("Min", "The minimum displacement at which the value will be affected."), selectedMinDisplacement);
selectedMaxDisplacement = EditorGUILayout.FloatField(new GUIContent("Max", "The maximum displacement at which the value will be affected."), selectedMaxDisplacement);
EditorGUI.indentLevel--;
}
// Selected Function
float x = selectedMinDisplacement;
float y = selectedMinValue;
float width = selectedMaxDisplacement - selectedMinDisplacement;
float height = selectedMaxValue - selectedMinValue;
selectedFunction = EditorGUILayout.CurveField(new GUIContent("Function", "The function (with respect to displacement from centre) that will be used to determine the value."), selectedFunction, Color.white, new Rect(x, y, width, height));
// Add Transition Effect
GUILayout.BeginHorizontal();
GUILayout.Space(EditorGUI.indentLevel * 16);
if (GUILayout.Button("Add Transition Effect"))
{
AnimationCurve function = new AnimationCurve(selectedFunction.keys);
simpleScrollSnap.transitionEffects.Add(new TransitionEffect(properties[selectedProperty], selectedMinValue, selectedMaxValue, selectedMinDisplacement, selectedMaxDisplacement, function, simpleScrollSnap));
}
GUILayout.EndHorizontal();
}
private void InitTransitionEffects()
{
// Initialize
for (int i = 0; i < simpleScrollSnap.transitionEffects.Count; i++)
{
simpleScrollSnap.transitionEffects[i].Init();
}
}
private void EventHandlers()
{
EditorStyles.foldout.fontStyle = FontStyle.Bold;
showEvents = EditorGUILayout.Foldout(showEvents, "Event Handlers", true);
EditorStyles.foldout.fontStyle = FontStyle.Normal;
if (showEvents)
{
EditorGUILayout.PropertyField(onPanelSelecting, new GUIContent("On Panel Selecting"));
EditorGUILayout.PropertyField(onPanelSelected, new GUIContent("On Panel Selected"));
EditorGUILayout.PropertyField(onPanelChanging, new GUIContent("On Panel Changing"));
EditorGUILayout.PropertyField(onPanelChanged, new GUIContent("On Panel Changed"));
}
}
[MenuItem("GameObject/UI/Simple Scroll-Snap/Scroll-Snap", false)]
private static void CreateSimpleScrollSnap()
{
// Canvas
Canvas canvas = FindObjectOfType<Canvas>();
if (canvas == null)
{
GameObject canvasObject = new GameObject("Canvas");
canvas = canvasObject.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.gameObject.AddComponent<GraphicRaycaster>();
Undo.RegisterCreatedObjectUndo(canvasObject, "Create " + canvasObject.name);
}
// Scroll-Snap
GameObject scrollSnap = new GameObject("Scroll-Snap");
RectTransform scrollSnapRectTransform = scrollSnap.AddComponent<RectTransform>();
scrollSnapRectTransform.sizeDelta = new Vector2(400, 250);
ScrollRect scrollSnapScrollRect = scrollSnap.AddComponent<ScrollRect>();
scrollSnapScrollRect.horizontal = true;
scrollSnapScrollRect.vertical = false;
scrollSnapScrollRect.scrollSensitivity = 0f;
scrollSnapScrollRect.decelerationRate = 0.01f;
GameObjectUtility.SetParentAndAlign(scrollSnap, canvas.gameObject);
scrollSnap.AddComponent<SimpleScrollSnap>();
// Viewport
GameObject viewport = new GameObject("Viewport");
RectTransform viewportRectTransform = viewport.AddComponent<RectTransform>();
viewportRectTransform.anchorMin = new Vector2(0, 0);
viewportRectTransform.anchorMax = new Vector2(1, 1);
viewportRectTransform.offsetMin = Vector2.zero;
viewportRectTransform.offsetMax = Vector2.zero;
viewport.AddComponent<Mask>();
Image viewportImage = viewport.AddComponent<Image>();
viewportImage.color = new Color(1, 1, 1, 0.5f);
scrollSnapScrollRect.viewport = viewportRectTransform;
GameObjectUtility.SetParentAndAlign(viewport, scrollSnap.gameObject);
// Content
GameObject content = new GameObject("Content");
RectTransform contentRectTransform = content.AddComponent<RectTransform>();
contentRectTransform.sizeDelta = new Vector2(400, 250);
contentRectTransform.anchorMin = new Vector2(0, 0.5f);
contentRectTransform.anchorMax = new Vector2(0, 0.5f);
contentRectTransform.pivot = new Vector2(0, 0.5f);
scrollSnapScrollRect.content = contentRectTransform;
GameObjectUtility.SetParentAndAlign(content, viewport.gameObject);
GameObject[] panels = new GameObject[5];
for (int i = 0; i < 5; i++)
{
// Panel
string name = (i + 1) + "";
panels[i] = new GameObject(name);
RectTransform panelRectTransform = panels[i].AddComponent<RectTransform>();
panelRectTransform.anchorMin = Vector2.zero;
panelRectTransform.anchorMax = Vector2.one;
panelRectTransform.offsetMin = Vector2.zero;
panelRectTransform.offsetMax = Vector2.zero;
panels[i].AddComponent<Image>();
GameObjectUtility.SetParentAndAlign(panels[i], content.gameObject);
// Text
GameObject text = new GameObject("Text");
RectTransform textRectTransform = text.AddComponent<RectTransform>();
textRectTransform.anchorMin = Vector2.zero;
textRectTransform.anchorMax = Vector2.one;
textRectTransform.offsetMin = Vector2.zero;
textRectTransform.offsetMax = Vector2.zero;
Text textText = text.AddComponent<Text>();
textText.text = name;
textText.fontSize = 50;
textText.alignment = TextAnchor.MiddleCenter;
textText.color = Color.black;
GameObjectUtility.SetParentAndAlign(text, panels[i]);
}
// Event System
if (!FindObjectOfType<EventSystem>())
{
GameObject eventObject = new GameObject("EventSystem", typeof(EventSystem));
eventObject.AddComponent<StandaloneInputModule>();
Undo.RegisterCreatedObjectUndo(eventObject, "Create " + eventObject.name);
}
// Editor
Selection.activeGameObject = scrollSnap;
Undo.RegisterCreatedObjectUndo(scrollSnap, "Create " + scrollSnap.name);
}
[MenuItem("GameObject/UI/Simple Scroll-Snap/Pagination", false)]
private static void CreatePagination()
{
// Canvas
Canvas canvas = FindObjectOfType<Canvas>();
if (canvas == null)
{
GameObject canvasObject = new GameObject("Canvas");
canvas = canvasObject.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.gameObject.AddComponent<GraphicRaycaster>();
Undo.RegisterCreatedObjectUndo(canvasObject, "Create " + canvasObject.name);
}
// Pagination
int numberOfToggles = 5;
int side = 25;
int spacing = 15;
GameObject pagination = new GameObject("Pagination");
RectTransform paginationRectTransform = pagination.AddComponent<RectTransform>();
paginationRectTransform.sizeDelta = new Vector2((numberOfToggles * (side + spacing)) - spacing, side);
GameObjectUtility.SetParentAndAlign(pagination, canvas.gameObject);
for (int i = 0; i < numberOfToggles; i++)
{
// Toggle
GameObject toggle = new GameObject((i + 1) + "");
GameObjectUtility.SetParentAndAlign(toggle, pagination);
RectTransform toggleRectTransform = toggle.AddComponent<RectTransform>();
toggleRectTransform.anchorMin = toggleRectTransform.anchorMax = new Vector2(0, 0.5f);
toggleRectTransform.pivot = new Vector2(0, 0.5f);
toggleRectTransform.sizeDelta = new Vector2(side, side);
toggleRectTransform.anchoredPosition = new Vector2(i * (side + spacing), 0);
Toggle toggleToggle = toggle.AddComponent<Toggle>();
toggleToggle.isOn = false;
toggleToggle.transition = Selectable.Transition.None;
// Background
GameObject background = new GameObject("Background");
GameObjectUtility.SetParentAndAlign(background, toggle);
RectTransform backgroundRectTransform = background.AddComponent<RectTransform>();
backgroundRectTransform.anchorMin = Vector2.zero;
backgroundRectTransform.anchorMax = Vector2.one;
backgroundRectTransform.sizeDelta = Vector2.zero;
Image backgroundImage = background.AddComponent<Image>();
backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd");
backgroundImage.color = new Color(0.75f, 0.75f, 0.75f);
// Selected
GameObject selected = new GameObject("Selected");
GameObjectUtility.SetParentAndAlign(selected, background);
RectTransform selectedRectTransform = selected.AddComponent<RectTransform>();
selectedRectTransform.anchorMin = Vector2.zero;
selectedRectTransform.anchorMax = Vector2.one;
selectedRectTransform.sizeDelta = Vector2.zero;
Image selectedImage = selected.AddComponent<Image>();
selectedImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd");
selectedImage.color = Color.white;
toggleToggle.graphic = selected.GetComponent<Image>();
}
// Event System
if (!FindObjectOfType<EventSystem>())
{
GameObject eventObject = new GameObject("EventSystem", typeof(EventSystem));
eventObject.AddComponent<StandaloneInputModule>();
Undo.RegisterCreatedObjectUndo(eventObject, "Create " + eventObject.name);
}
// Editor
Selection.activeGameObject = pagination;
Undo.RegisterCreatedObjectUndo(pagination, "Create " + pagination.name);
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: abeb93e5032d4644ea121e024894e57c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- saira: {fileID: 12800000, guid: aad56b6bd49460549b1f079904ec3f00, type: 3}
executionOrder: 0
icon: {fileID: 1206586993520771344, guid: 0000000000000000d000000000000000, type: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1d27d9da8339b784e805f0183748c8ac
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,913 @@
// Simple Scroll-Snap - https://assetstore.unity.com/packages/tools/gui/simple-scroll-snap-140884
// Version: 1.2.1
// Author: Daniel Lochner
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace DanielLochner.Assets.SimpleScrollSnap
{
[AddComponentMenu("UI/Simple Scroll-Snap")]
[RequireComponent(typeof(ScrollRect))]
public class SimpleScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler, IPointerDownHandler, IPointerUpHandler
{
#region Fields
public MovementType movementType = MovementType.Fixed;
public MovementAxis movementAxis = MovementAxis.Horizontal;
public bool automaticallyLayout = true;
public SizeControl sizeControl = SizeControl.Fit;
public Vector2 size = new Vector2(400, 250);
public float automaticLayoutSpacing = 0.25f;
public float leftMargin, rightMargin, topMargin, bottomMargin;
public bool infinitelyScroll = false;
public float infiniteScrollingEndSpacing = 0f;
public bool useOcclusionCulling = false;
public int startingPanel = 0;
public bool swipeGestures = true;
public float minimumSwipeSpeed = 0f;
public Button previousButton = null;
public Button nextButton = null;
public GameObject pagination = null;
public bool toggleNavigation = true;
public SnapTarget snapTarget = SnapTarget.Next;
public float snappingSpeed = 10f;
public float thresholdSnappingSpeed = -1f;
public bool hardSnap = true;
public bool useUnscaledTime = false;
public UnityEvent onPanelChanged, onPanelSelecting, onPanelSelected, onPanelChanging;
public List<TransitionEffect> transitionEffects = new List<TransitionEffect>();
private bool dragging, selected = true, pressing;
private float releaseSpeed, contentLength;
private Direction releaseDirection;
private Canvas canvas;
private RectTransform canvasRectTransform;
private CanvasScaler canvasScaler;
private ScrollRect scrollRect;
private Vector2 previousContentAnchoredPosition, velocity;
private Dictionary<int, Graphic[]> panelGraphics = new Dictionary<int, Graphic[]>();
#endregion
#region Properties
public RectTransform Content
{
get { return scrollRect.content; }
}
public RectTransform Viewport
{
get { return scrollRect.viewport; }
}
public int CurrentPanel { get; set; }
public int TargetPanel { get; set; }
public int NearestPanel { get; set; }
private RectTransform[] PanelsRT
{ get; set; }
public GameObject[] Panels { get; set; }
public Toggle[] Toggles { get; set; }
public int NumberOfPanels
{
get { return Content.childCount; }
}
#endregion
#region Enumerators
public enum MovementType
{
Fixed,
Free
}
public enum MovementAxis
{
Horizontal,
Vertical
}
public enum Direction
{
Up,
Down,
Left,
Right
}
public enum SnapTarget
{
Nearest,
Previous,
Next
}
public enum SizeControl
{
Manual,
Fit
}
#endregion
#region Methods
private void Awake()
{
Initialize();
}
private void Start()
{
if (Validate())
{
Setup();
}
else
{
throw new Exception("Invalid configuration.");
}
}
private void Update()
{
if (NumberOfPanels == 0) return;
OnOcclusionCulling();
OnSelectingAndSnapping();
OnInfiniteScrolling();
OnTransitionEffects();
OnSwipeGestures();
DetermineVelocity();
}
#if UNITY_EDITOR
private void OnValidate()
{
Initialize();
}
#endif
public void OnPointerDown(PointerEventData eventData)
{
pressing = true;
}
public void OnPointerUp(PointerEventData eventData)
{
pressing = false;
}
public void OnBeginDrag(PointerEventData eventData)
{
if (hardSnap)
{
scrollRect.inertia = true;
}
selected = false;
dragging = true;
}
public void OnDrag(PointerEventData eventData)
{
if (dragging)
{
onPanelSelecting.Invoke();
}
}
public void OnEndDrag(PointerEventData eventData)
{
dragging = false;
if (movementAxis == MovementAxis.Horizontal)
{
releaseDirection = scrollRect.velocity.x > 0 ? Direction.Right : Direction.Left;
}
else if (movementAxis == MovementAxis.Vertical)
{
releaseDirection = scrollRect.velocity.y > 0 ? Direction.Up : Direction.Down;
}
releaseSpeed = scrollRect.velocity.magnitude;
}
private void Initialize()
{
scrollRect = GetComponent<ScrollRect>();
canvas = GetComponentInParent<Canvas>();
if (canvas != null)
{
canvasScaler = canvas.GetComponentInParent<CanvasScaler>();
canvasRectTransform = canvas.GetComponent<RectTransform>();
}
panelGraphics = new Dictionary<int, Graphic[]>();
for (int i = 0; i < Content.childCount; i++)
{
panelGraphics.Add(i, Content.GetChild(i).GetComponentsInChildren<Graphic>());
}
}
private bool Validate()
{
bool valid = true;
if (pagination != null)
{
int numberOfToggles = pagination.transform.childCount;
if (numberOfToggles != NumberOfPanels)
{
Debug.LogError("<b>[SimpleScrollSnap]</b> The number of Toggles should be equivalent to the number of Panels. There are currently " + numberOfToggles + " Toggles and " + NumberOfPanels + " Panels. If you are adding Panels dynamically during runtime, please update your pagination to reflect the number of Panels you will have before adding.", gameObject);
valid = false;
}
}
if (snappingSpeed < 0)
{
Debug.LogError("<b>[SimpleScrollSnap]</b> Snapping speed cannot be negative.", gameObject);
valid = false;
}
return valid;
}
private void Setup()
{
if (NumberOfPanels == 0) return;
// ScrollRect
if (movementType == MovementType.Fixed)
{
scrollRect.horizontal = (movementAxis == MovementAxis.Horizontal);
scrollRect.vertical = (movementAxis == MovementAxis.Vertical);
}
else
{
scrollRect.horizontal = scrollRect.vertical = true;
}
// Panels
size = (sizeControl == SizeControl.Manual) ? size : new Vector2(GetComponent<RectTransform>().rect.width, GetComponent<RectTransform>().rect.height);
Panels = new GameObject[NumberOfPanels];
PanelsRT = new RectTransform[NumberOfPanels];
for (int i = 0; i < NumberOfPanels; i++)
{
Panels[i] = Content.GetChild(i).gameObject;
PanelsRT[i] = Panels[i].GetComponent<RectTransform>();
if (movementType == MovementType.Fixed && automaticallyLayout)
{
PanelsRT[i].anchorMin = new Vector2(movementAxis == MovementAxis.Horizontal ? 0f : 0.5f, movementAxis == MovementAxis.Vertical ? 0f : 0.5f);
PanelsRT[i].anchorMax = new Vector2(movementAxis == MovementAxis.Horizontal ? 0f : 0.5f, movementAxis == MovementAxis.Vertical ? 0f : 0.5f);
float x = (rightMargin + leftMargin) / 2f - leftMargin;
float y = (topMargin + bottomMargin) / 2f - bottomMargin;
Vector2 marginOffset = new Vector2(x / size.x, y / size.y);
PanelsRT[i].pivot = new Vector2(0.5f, 0.5f) + marginOffset;
PanelsRT[i].sizeDelta = size - new Vector2(leftMargin + rightMargin, topMargin + bottomMargin);
float panelPosX = (movementAxis == MovementAxis.Horizontal) ? i * (automaticLayoutSpacing + 1f) * size.x + (size.x / 2f) : 0f;
float panelPosY = (movementAxis == MovementAxis.Vertical) ? i * (automaticLayoutSpacing + 1f) * size.y + (size.y / 2f) : 0f;
PanelsRT[i].anchoredPosition = new Vector2(panelPosX, panelPosY);
}
}
// Content
if (movementType == MovementType.Fixed)
{
// Automatic Layout
if (automaticallyLayout)
{
Content.anchorMin = new Vector2(movementAxis == MovementAxis.Horizontal ? 0f : 0.5f, movementAxis == MovementAxis.Vertical ? 0f : 0.5f);
Content.anchorMax = new Vector2(movementAxis == MovementAxis.Horizontal ? 0f : 0.5f, movementAxis == MovementAxis.Vertical ? 0f : 0.5f);
Content.pivot = new Vector2(movementAxis == MovementAxis.Horizontal ? 0f : 0.5f, movementAxis == MovementAxis.Vertical ? 0f : 0.5f);
Vector2 min = PanelsRT[0].anchoredPosition;
Vector2 max = PanelsRT[NumberOfPanels - 1].anchoredPosition;
float contentWidth = (movementAxis == MovementAxis.Horizontal) ? (NumberOfPanels * (automaticLayoutSpacing + 1f) * size.x) - (size.x * automaticLayoutSpacing) : size.x;
float contentHeight = (movementAxis == MovementAxis.Vertical) ? (NumberOfPanels * (automaticLayoutSpacing + 1f) * size.y) - (size.y * automaticLayoutSpacing) : size.y;
Content.sizeDelta = new Vector2(contentWidth, contentHeight);
}
// Infinite Scrolling
if (infinitelyScroll)
{
scrollRect.movementType = ScrollRect.MovementType.Unrestricted;
contentLength = (movementAxis == MovementAxis.Horizontal) ? (Content.rect.width + size.x * infiniteScrollingEndSpacing) : Content.rect.height + size.y * infiniteScrollingEndSpacing;
OnInfiniteScrolling(true);
}
// Occlusion Culling
if (useOcclusionCulling)
{
OnOcclusionCulling(true);
}
}
else
{
automaticallyLayout = infinitelyScroll = useOcclusionCulling = false;
}
// Starting Panel
float xOffset = (movementAxis == MovementAxis.Horizontal || movementType == MovementType.Free) ? Viewport.rect.width / 2f : 0f;
float yOffset = (movementAxis == MovementAxis.Vertical || movementType == MovementType.Free) ? Viewport.rect.height / 2f : 0f;
Vector2 offset = new Vector2(xOffset, yOffset);
previousContentAnchoredPosition = Content.anchoredPosition = -PanelsRT[startingPanel].anchoredPosition + offset;
CurrentPanel = TargetPanel = NearestPanel = startingPanel;
// Previous Button
if (previousButton != null)
{
previousButton.onClick.RemoveAllListeners();
previousButton.onClick.AddListener(GoToPreviousPanel);
}
// Next Button
if (nextButton != null)
{
nextButton.onClick.RemoveAllListeners();
nextButton.onClick.AddListener(GoToNextPanel);
}
// Pagination
if (pagination != null)
{
Toggles = pagination.GetComponentsInChildren<Toggle>();
for (int i = 0; i < Toggles.Length; i++)
{
if (Toggles[i] != null)
{
Toggles[i].isOn = (i == startingPanel);
Toggles[i].interactable = (i != TargetPanel);
int panelNum = i;
Toggles[i].onValueChanged.RemoveAllListeners();
Toggles[i].onValueChanged.AddListener(delegate
{
if (Toggles[panelNum].isOn && toggleNavigation)
{
GoToPanel(panelNum);
}
});
}
}
}
}
private Vector2 DisplacementFromCenter(int index)
{
return PanelsRT[index].anchoredPosition + Content.anchoredPosition - new Vector2(Viewport.rect.width * (0.5f - Content.anchorMin.x), Viewport.rect.height * (0.5f - Content.anchorMin.y));
}
private int DetermineNearestPanel()
{
int panelNumber = NearestPanel;
float[] distances = new float[NumberOfPanels];
for (int i = 0; i < Panels.Length; i++)
{
distances[i] = DisplacementFromCenter(i).magnitude;
}
float minDistance = Mathf.Min(distances);
for (int i = 0; i < Panels.Length; i++)
{
if (minDistance == distances[i])
{
panelNumber = i;
break;
}
}
return panelNumber;
}
private void DetermineVelocity()
{
Vector2 displacement = Content.anchoredPosition - previousContentAnchoredPosition;
float time = useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime;
velocity = displacement / time;
previousContentAnchoredPosition = Content.anchoredPosition;
}
private void SelectTargetPanel()
{
Vector2 displacementFromCenter = DisplacementFromCenter(NearestPanel = DetermineNearestPanel());
if (snapTarget == SnapTarget.Nearest || releaseSpeed <= minimumSwipeSpeed)
{
GoToPanel(NearestPanel);
}
else if (snapTarget == SnapTarget.Previous)
{
if ((releaseDirection == Direction.Right && displacementFromCenter.x < 0f) || (releaseDirection == Direction.Up && displacementFromCenter.y < 0f))
{
GoToNextPanel();
}
else if ((releaseDirection == Direction.Left && displacementFromCenter.x > 0f) || (releaseDirection == Direction.Down && displacementFromCenter.y > 0f))
{
GoToPreviousPanel();
}
else
{
GoToPanel(NearestPanel);
}
}
else if (snapTarget == SnapTarget.Next)
{
if ((releaseDirection == Direction.Right && displacementFromCenter.x > 0f) || (releaseDirection == Direction.Up && displacementFromCenter.y > 0f))
{
GoToPreviousPanel();
}
else if ((releaseDirection == Direction.Left && displacementFromCenter.x < 0f) || (releaseDirection == Direction.Down && displacementFromCenter.y < 0f))
{
GoToNextPanel();
}
else
{
GoToPanel(NearestPanel);
}
}
}
private void SnapToTargetPanel()
{
float xOffset = (movementAxis == MovementAxis.Horizontal || movementType == MovementType.Free) ? Viewport.rect.width / 2f : 0f;
float yOffset = (movementAxis == MovementAxis.Vertical || movementType == MovementType.Free) ? Viewport.rect.height / 2f : 0f;
Vector2 offset = new Vector2(xOffset, yOffset);
Vector2 targetPosition = -PanelsRT[TargetPanel].anchoredPosition + offset;
Content.anchoredPosition = Vector2.Lerp(Content.anchoredPosition, targetPosition, (useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime) * snappingSpeed);
if (CurrentPanel != TargetPanel)
{
if (DisplacementFromCenter(TargetPanel).magnitude < (Viewport.rect.width / 10f))
{
CurrentPanel = TargetPanel;
onPanelChanged.Invoke();
}
else
{
onPanelChanging.Invoke();
}
}
}
private void OnSelectingAndSnapping()
{
if (selected)
{
if (!((dragging || pressing) && swipeGestures))
{
SnapToTargetPanel();
}
}
else if (!dragging && (scrollRect.velocity.magnitude <= thresholdSnappingSpeed || thresholdSnappingSpeed == -1f))
{
SelectTargetPanel();
}
}
private void OnOcclusionCulling(bool forceUpdate = false)
{
if (useOcclusionCulling && (velocity.magnitude > 0f || forceUpdate))
{
for (int i = 0; i < NumberOfPanels; i++)
{
if (movementAxis == MovementAxis.Horizontal)
{
Panels[i].SetActive(Mathf.Abs(DisplacementFromCenter(i).x) <= Viewport.rect.width / 2f + size.x);
}
else if (movementAxis == MovementAxis.Vertical)
{
Panels[i].SetActive(Mathf.Abs(DisplacementFromCenter(i).y) <= Viewport.rect.height / 2f + size.y);
}
}
}
}
private void OnInfiniteScrolling(bool forceUpdate = false)
{
if (infinitelyScroll && (velocity.magnitude > 0 || forceUpdate))
{
if (movementAxis == MovementAxis.Horizontal)
{
for (int i = 0; i < NumberOfPanels; i++)
{
if (DisplacementFromCenter(i).x > Content.rect.width / 2f)
{
PanelsRT[i].anchoredPosition -= new Vector2(contentLength, 0);
}
else if (DisplacementFromCenter(i).x < Content.rect.width / -2f)
{
PanelsRT[i].anchoredPosition += new Vector2(contentLength, 0);
}
}
}
else if (movementAxis == MovementAxis.Vertical)
{
for (int i = 0; i < NumberOfPanels; i++)
{
if (DisplacementFromCenter(i).y > Content.rect.height / 2f)
{
PanelsRT[i].anchoredPosition -= new Vector2(0, contentLength);
}
else if (DisplacementFromCenter(i).y < Content.rect.height / -2f)
{
PanelsRT[i].anchoredPosition += new Vector2(0, contentLength);
}
}
}
}
}
private void OnTransitionEffects()
{
if (transitionEffects.Count == 0) return;
for (int i = 0; i < NumberOfPanels; i++)
{
foreach (TransitionEffect transitionEffect in transitionEffects)
{
// Displacement
float displacement = 0f;
if (movementType == MovementType.Fixed)
{
if (movementAxis == MovementAxis.Horizontal)
{
displacement = DisplacementFromCenter(i).x;
}
else if (movementAxis == MovementAxis.Vertical)
{
displacement = DisplacementFromCenter(i).y;
}
}
else
{
displacement = DisplacementFromCenter(i).magnitude;
}
// Value
RectTransform panel = PanelsRT[i];
switch (transitionEffect.Label)
{
case "localPosition.z":
panel.transform.localPosition = new Vector3(panel.transform.localPosition.x, panel.transform.localPosition.y, transitionEffect.GetValue(displacement));
break;
case "localScale.x":
panel.transform.localScale = new Vector2(transitionEffect.GetValue(displacement), panel.transform.localScale.y);
break;
case "localScale.y":
panel.transform.localScale = new Vector2(panel.transform.localScale.x, transitionEffect.GetValue(displacement));
break;
case "localRotation.x":
panel.transform.localRotation = Quaternion.Euler(new Vector3(transitionEffect.GetValue(displacement), panel.transform.localEulerAngles.y, panel.transform.localEulerAngles.z));
break;
case "localRotation.y":
panel.transform.localRotation = Quaternion.Euler(new Vector3(panel.transform.localEulerAngles.x, transitionEffect.GetValue(displacement), panel.transform.localEulerAngles.z));
break;
case "localRotation.z":
panel.transform.localRotation = Quaternion.Euler(new Vector3(panel.transform.localEulerAngles.x, panel.transform.localEulerAngles.y, transitionEffect.GetValue(displacement)));
break;
case "color.r":
foreach (Graphic graphic in panelGraphics[i])
{
graphic.color = new Color(transitionEffect.GetValue(displacement), graphic.color.g, graphic.color.b, graphic.color.a);
}
break;
case "color.g":
foreach (Graphic graphic in panelGraphics[i])
{
graphic.color = new Color(graphic.color.r, transitionEffect.GetValue(displacement), graphic.color.b, graphic.color.a);
}
break;
case "color.b":
foreach (Graphic graphic in panelGraphics[i])
{
graphic.color = new Color(graphic.color.r, graphic.color.g, transitionEffect.GetValue(displacement), graphic.color.a);
}
break;
case "color.a":
foreach (Graphic graphic in panelGraphics[i])
{
graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, transitionEffect.GetValue(displacement));
}
break;
}
}
}
}
private void OnSwipeGestures()
{
if (swipeGestures)
{
scrollRect.horizontal = movementAxis == MovementAxis.Horizontal || movementType == MovementType.Free;
scrollRect.vertical = movementAxis == MovementAxis.Vertical || movementType == MovementType.Free;
}
else
{
scrollRect.horizontal = scrollRect.vertical = !dragging;
}
}
public void GoToPanel(int panelNumber)
{
TargetPanel = panelNumber;
selected = true;
onPanelSelected.Invoke();
if (pagination != null)
{
for (int i = 0; i < Toggles.Length; i++)
{
if (Toggles[i] != null)
{
Toggles[i].isOn = (i == TargetPanel);
Toggles[i].interactable = (i != TargetPanel);
}
}
}
if (hardSnap)
{
scrollRect.inertia = false;
}
}
public void GoToPreviousPanel()
{
NearestPanel = DetermineNearestPanel();
if (NearestPanel != 0)
{
GoToPanel(NearestPanel - 1);
}
else
{
if (infinitelyScroll)
{
GoToPanel(NumberOfPanels - 1);
}
else
{
GoToPanel(NearestPanel);
}
}
}
public void GoToNextPanel()
{
NearestPanel = DetermineNearestPanel();
if (NearestPanel != (NumberOfPanels - 1))
{
GoToPanel(NearestPanel + 1);
}
else
{
if (infinitelyScroll)
{
GoToPanel(0);
}
else
{
GoToPanel(NearestPanel);
}
}
}
public void AddToFront(GameObject panel)
{
Add(panel, 0);
}
public void AddToBack(GameObject panel)
{
Add(panel, NumberOfPanels);
}
public void Add(GameObject panel, int index)
{
if (NumberOfPanels != 0 && (index < 0 || index > NumberOfPanels))
{
Debug.LogError("<b>[SimpleScrollSnap]</b> Index must be an integer from 0 to " + NumberOfPanels + ".", gameObject);
return;
}
else if (!automaticallyLayout)
{
Debug.LogError("<b>[SimpleScrollSnap]</b> \"Automatic Layout\" must be enabled for content to be dynamically added during runtime.");
return;
}
panel = Instantiate(panel, Content, false);
panel.transform.SetSiblingIndex(index);
Initialize();
if (Validate())
{
if (TargetPanel <= index)
{
startingPanel = TargetPanel;
}
else
{
startingPanel = TargetPanel + 1;
}
Setup();
}
}
public void RemoveFromFront()
{
Remove(0);
}
public void RemoveFromBack()
{
if (NumberOfPanels > 0)
{
Remove(NumberOfPanels - 1);
}
else
{
Remove(0);
}
}
public void Remove(int index)
{
if (NumberOfPanels == 0)
{
Debug.LogError("<b>[SimpleScrollSnap]</b> There are no panels to remove.", gameObject);
return;
}
else if (index < 0 || index > (NumberOfPanels - 1))
{
Debug.LogError("<b>[SimpleScrollSnap]</b> Index must be an integer from 0 to " + (NumberOfPanels - 1) + ".", gameObject);
return;
}
else if (!automaticallyLayout)
{
Debug.LogError("<b>[SimpleScrollSnap]</b> \"Automatic Layout\" must be enabled for content to be dynamically removed during runtime.");
return;
}
DestroyImmediate(Panels[index]);
Initialize();
if (Validate())
{
if (TargetPanel == index)
{
if (index == NumberOfPanels)
{
startingPanel = TargetPanel - 1;
}
else
{
startingPanel = TargetPanel;
}
}
else if (TargetPanel < index)
{
startingPanel = TargetPanel;
}
else
{
startingPanel = TargetPanel - 1;
}
Setup();
}
}
public void AddVelocity(Vector2 velocity)
{
scrollRect.velocity += velocity;
selected = false;
}
#endregion
#region Inner Classes
[Serializable] public class TransitionEffect
{
#region Fields
[SerializeField] protected float minDisplacement, maxDisplacement, minValue, maxValue, defaultMinValue, defaultMaxValue, defaultMinDisplacement, defaultMaxDisplacement;
[SerializeField] protected bool showPanel, showDisplacement, showValue;
[SerializeField] private string label;
[SerializeField] private AnimationCurve function;
[SerializeField] private AnimationCurve defaultFunction;
[SerializeField] private SimpleScrollSnap simpleScrollSnap;
#endregion
#region Properties
public string Label
{
get { return label; }
set { label = value; }
}
public float MinValue
{
get { return MinValue; }
set { minValue = value; }
}
public float MaxValue
{
get { return maxValue; }
set { maxValue = value; }
}
public float MinDisplacement
{
get { return minDisplacement; }
set { minDisplacement = value; }
}
public float MaxDisplacement
{
get { return maxDisplacement; }
set { maxDisplacement = value; }
}
public AnimationCurve Function
{
get { return function; }
set { function = value; }
}
#endregion
#region Methods
public TransitionEffect(string label, float minValue, float maxValue, float minDisplacement, float maxDisplacement, AnimationCurve function, SimpleScrollSnap simpleScrollSnap)
{
this.label = label;
this.simpleScrollSnap = simpleScrollSnap;
this.minValue = minValue;
this.maxValue = maxValue;
this.minDisplacement = minDisplacement;
this.maxDisplacement = maxDisplacement;
this.function = function;
SetDefaultValues(minValue, maxValue, minDisplacement, maxDisplacement, function);
#if UNITY_EDITOR
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
#endif
}
private void SetDefaultValues(float minValue, float maxValue, float minDisplacement, float maxDisplacement, AnimationCurve function)
{
defaultMinValue = minValue;
defaultMaxValue = maxValue;
defaultMinDisplacement = minDisplacement;
defaultMaxDisplacement = maxDisplacement;
defaultFunction = function;
}
#if UNITY_EDITOR
public void Init()
{
GUILayout.BeginVertical("HelpBox");
showPanel = EditorGUILayout.Foldout(showPanel, label, true);
if (showPanel)
{
EditorGUI.indentLevel++;
float x = minDisplacement;
float y = minValue;
float width = maxDisplacement - minDisplacement;
float height = maxValue - minValue;
// Min/Max Values
showValue = EditorGUILayout.Foldout(showValue, "Value", true);
if (showValue)
{
EditorGUI.indentLevel++;
minValue = EditorGUILayout.FloatField(new GUIContent("Min"), minValue);
maxValue = EditorGUILayout.FloatField(new GUIContent("Max"), maxValue);
EditorGUI.indentLevel--;
}
// Min/Max Displacements
showDisplacement = EditorGUILayout.Foldout(showDisplacement, "Displacement", true);
if (showDisplacement)
{
EditorGUI.indentLevel++;
minDisplacement = EditorGUILayout.FloatField(new GUIContent("Min"), minDisplacement);
maxDisplacement = EditorGUILayout.FloatField(new GUIContent("Max"), maxDisplacement);
EditorGUI.indentLevel--;
}
// Function
function = EditorGUILayout.CurveField("Function", function, Color.white, new Rect(x, y, width, height));
// Reset
GUILayout.BeginHorizontal();
GUILayout.Space(EditorGUI.indentLevel * 16);
if (GUILayout.Button("Reset"))
{
Reset();
}
// Remove
if (GUILayout.Button("Remove"))
{
simpleScrollSnap.transitionEffects.Remove(this);
}
GUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
GUILayout.EndVertical();
}
#endif
public void Reset()
{
minValue = defaultMinValue;
maxValue = defaultMaxValue;
minDisplacement = defaultMinDisplacement;
maxDisplacement = defaultMaxDisplacement;
function = defaultFunction;
}
public float GetValue(float displacement)
{
return (function != null) ? function.Evaluate(displacement) : 0f;
}
#endregion
}
#endregion
}
}

View File

@ -1,11 +1,11 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: e2dcaf5b0ab94ff40b03030b6920aab1 guid: 54aaa385a9b88e84e9d50b9804aaa24e
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {fileID: 1206586993520771344, guid: 0000000000000000d000000000000000, type: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:

View File

@ -14,6 +14,9 @@ EditorBuildSettings:
- enabled: 1 - enabled: 1
path: Assets/Scenes/Level 2.unity path: Assets/Scenes/Level 2.unity
guid: 65fe93b643a508549b0df7339450a1f4 guid: 65fe93b643a508549b0df7339450a1f4
- enabled: 1
path: Assets/Scenes/Level 3.unity
guid: fd7aee4099792eb409f17466c8edcced
m_configObjects: m_configObjects:
com.unity.adaptiveperformance.loader_settings: {fileID: 11400000, guid: 637cf863a0e12644db881151566fd24a, type: 2} com.unity.adaptiveperformance.loader_settings: {fileID: 11400000, guid: 637cf863a0e12644db881151566fd24a, type: 2}
com.unity.adaptiveperformance.simulator.provider_settings: {fileID: 11400000, guid: f8a8ea9a49e90b5488375c1694dc2d66, type: 2} com.unity.adaptiveperformance.simulator.provider_settings: {fileID: 11400000, guid: f8a8ea9a49e90b5488375c1694dc2d66, type: 2}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long