├── .gitignore ├── Boids.meta ├── Boids ├── Boid.cs ├── Boid.cs.meta ├── Swarm.cs └── Swarm.cs.meta ├── BoneSystem.meta ├── BoneSystem ├── Bone.cs ├── Bone.cs.meta ├── BoneDragWell.cs ├── BoneDragWell.cs.meta ├── BoneDragger.cs ├── BoneDragger.cs.meta ├── BoneRectBridge.cs ├── BoneRectBridge.cs.meta ├── BoneSnapEvents.cs ├── BoneSnapEvents.cs.meta ├── BoneSnapTarget.cs └── BoneSnapTarget.cs.meta ├── Bresenham.meta ├── Bresenham ├── Bresenham.cs └── Bresenham.cs.meta ├── Camera.meta ├── Camera ├── BetterCameraFollow2D.cs ├── BetterCameraFollow2D.cs.meta ├── BetterCameraFollow3D.cs └── BetterCameraFollow3D.cs.meta ├── Collections.meta ├── Collections ├── Generic.meta └── Generic │ ├── MultiMap.cs │ ├── MultiMap.cs.meta │ ├── Pair.cs │ ├── Pair.cs.meta │ ├── PriorityQueue.cs │ ├── PriorityQueue.cs.meta │ ├── RingBuffer.cs │ ├── RingBuffer.cs.meta │ ├── SerializableDictionary.cs │ ├── SerializableDictionary.cs.meta │ ├── ShuffleBag.cs │ └── ShuffleBag.cs.meta ├── Color.meta ├── Color ├── GradientPalette.cs ├── GradientPalette.cs.meta ├── Helpers.cs ├── Helpers.cs.meta ├── SimplePalette.cs └── SimplePalette.cs.meta ├── Coroutines.meta ├── Coroutines ├── Coroutines.cs └── Coroutines.cs.meta ├── Debug.meta ├── Debug ├── DebugX.cs └── DebugX.cs.meta ├── Economy.meta ├── Editor.meta ├── Editor ├── PlayerPrefsEditor.cs └── PlayerPrefsEditor.cs.meta ├── EditorHelpers.cs ├── EditorHelpers.cs.meta ├── FSM.meta ├── FSM ├── EnumStateMachine.cs ├── EnumStateMachine.cs.meta ├── ReflectionUtils.cs ├── ReflectionUtils.cs.meta ├── SimpleStateMachine.cs ├── SimpleStateMachine.cs.meta ├── State.cs ├── State.cs.meta ├── StateMachine.cs └── StateMachine.cs.meta ├── File.meta ├── File ├── ArrayPrefs.cs ├── ArrayPrefs.cs.meta ├── FolderInfo.cs ├── FolderInfo.cs.meta ├── SimpleJSON.cs ├── SimpleJSON.cs.meta ├── TextFileReader.cs └── TextFileReader.cs.meta ├── FrameInterpolater.meta ├── FrameInterpolater ├── InterpolatedTransform.cs ├── InterpolatedTransform.cs.meta ├── InterpolatedTransformUpdater.cs ├── InterpolatedTransformUpdater.cs.meta ├── InterpolationController.cs └── InterpolationController.cs.meta ├── Gameplay.meta ├── Gameplay ├── ActivateTrigger2D.cs ├── ActivateTrigger2D.cs.meta ├── OnTriggerMoveAlong.cs ├── OnTriggerMoveAlong.cs.meta ├── TimedDeactivator.cs ├── TimedDeactivator.cs.meta ├── TimedTransformReset.cs └── TimedTransformReset.cs.meta ├── Graph.meta ├── Graph ├── Graph.cs ├── Graph.cs.meta ├── GraphNode.cs ├── GraphNode.cs.meta ├── Node.cs └── Node.cs.meta ├── Grid.meta ├── Grid ├── GridUtils.cs ├── GridUtils.cs.meta ├── HexGrid.cs ├── HexGrid.cs.meta ├── QuadGrid.cs └── QuadGrid.cs.meta ├── LICENSE ├── LICENSE.meta ├── Math.meta ├── Math ├── MathParser.cs ├── MathParser.cs.meta ├── Mathi.cs ├── Mathi.cs.meta ├── Utils.cs ├── Utils.cs.meta ├── Vector2i.cs └── Vector2i.cs.meta ├── Notification.meta ├── Notification ├── Notification.cs ├── Notification.cs.meta ├── NotificationCenter.cs ├── NotificationCenter.cs.meta ├── SuperNotification.cs ├── SuperNotification.cs.meta ├── SystemNotifications.cs └── SystemNotifications.cs.meta ├── ObjectPool.meta ├── ObjectPool ├── ObjectPool.cs ├── ObjectPool.cs.meta ├── Pool.cs └── Pool.cs.meta ├── Pathfinding.meta ├── Pathfinding ├── AStar.cs ├── AStar.cs.meta ├── FlowGrid.cs ├── FlowGrid.cs.meta ├── FlowGridFollow.cs ├── FlowGridFollow.cs.meta ├── FlowGridRayCaster.cs ├── FlowGridRayCaster.cs.meta ├── FlowGridTarget.cs ├── FlowGridTarget.cs.meta ├── PathFinder.cs ├── PathFinder.cs.meta ├── PathNode.cs ├── PathNode.cs.meta ├── PathSeeker.cs ├── PathSeeker.cs.meta ├── TilemapPathFinder.cs ├── TilemapPathFinder.cs.meta ├── TilemapPathNode.cs ├── TilemapPathNode.cs.meta ├── WeightedPathFinder.cs ├── WeightedPathFinder.cs.meta ├── WeightedPathNode.cs └── WeightedPathNode.cs.meta ├── Physics.meta ├── Physics ├── Follow.cs └── Follow.cs.meta ├── README.md ├── README.md.meta ├── Random.meta ├── Random ├── Plugins.meta └── Plugins │ ├── MarchingCubes.cs │ ├── MarchingCubes.cs.meta │ ├── MarkovChain.cs │ ├── MarkovChain.cs.meta │ ├── PerlinNoise.cs │ ├── PerlinNoise.cs.meta │ ├── Permutations.cs │ ├── Permutations.cs.meta │ ├── Triangulator.cs │ ├── Triangulator.cs.meta │ ├── VoronoiNoise.cs │ ├── VoronoiNoise.cs.meta │ ├── VoxelChunk.cs │ ├── VoxelChunk.cs.meta │ ├── WorleyNoise.cs │ └── WorleyNoise.cs.meta ├── Rendering.meta ├── Rendering ├── PixelTextureRenderer.cs └── PixelTextureRenderer.cs.meta ├── Screenshot.meta ├── Screenshot ├── Screenshooter.cs └── Screenshooter.cs.meta ├── Simulation.meta ├── Sound.meta ├── Sound ├── Gain.cs ├── Gain.cs.meta ├── Noise.cs ├── Noise.cs.meta ├── SpookyDNBBeat.cs └── SpookyDNBBeat.cs.meta ├── TimeDynamics.meta ├── TimeDynamics ├── Playtime.cs ├── Playtime.cs.meta ├── PlaytimeController.cs └── PlaytimeController.cs.meta ├── UI.meta ├── UI ├── DragArea.cs ├── DragArea.cs.meta ├── DragHandler.cs ├── DragHandler.cs.meta ├── DragSensor.cs ├── DragSensor.cs.meta ├── DragWell.cs ├── DragWell.cs.meta ├── Draggable.cs ├── Draggable.cs.meta ├── Hexagon.cs ├── Hexagon.cs.meta ├── IHasChanged.cs ├── IHasChanged.cs.meta ├── ImageAsLine.cs ├── ImageAsLine.cs.meta ├── Line.cs ├── Line.cs.meta ├── MultiDragArea.cs ├── MultiDragArea.cs.meta ├── MultiLine.cs ├── MultiLine.cs.meta ├── OnDragOver.cs ├── OnDragOver.cs.meta ├── PercentButton.cs ├── PercentButton.cs.meta ├── PercentFromParent.cs ├── PercentFromParent.cs.meta ├── PointerCallbacks.cs ├── PointerCallbacks.cs.meta ├── Rectangle.cs └── Rectangle.cs.meta ├── Unity.meta ├── Unity ├── CustomAssetUtility.cs └── CustomAssetUtility.cs.meta ├── Utils.meta └── Utils ├── CanvasExtensions.cs ├── CanvasExtensions.cs.meta ├── Helpers.cs ├── Helpers.cs.meta ├── NaturalStringComparer.cs ├── NaturalStringComparer.cs.meta ├── Singleton.cs └── Singleton.cs.meta /.gitignore: -------------------------------------------------------------------------------- 1 | # =============== # 2 | # Unity generated # 3 | # =============== # 4 | **/Temp/* 5 | **/Obj/* 6 | **/UnityGenerated/* 7 | **/Library/* 8 | **/Scripts - external/* 9 | 10 | # ===================================== # 11 | # Visual Studio / MonoDevelop generated # 12 | # ===================================== # 13 | **/ExportedObj/ 14 | *.svd 15 | *.userprefs 16 | *.csproj 17 | *.pidb 18 | *.suo 19 | *.sln 20 | *.user 21 | *.unityproj 22 | *.booproj 23 | 24 | # ============ # 25 | # OS generated # 26 | # ============ # 27 | .DS_Store 28 | .DS_Store? 29 | ._* 30 | .Spotlight-V100 31 | .Trashes 32 | Icon? 33 | ehthumbs.db 34 | Thumbs.db 35 | 36 | -------------------------------------------------------------------------------- /Boids.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f7c684e228d54158817b544b52af4c3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Boids/Boid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddd6abfd79dcb45e8a2d421a79fe9478 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Boids/Swarm.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 robosoup 2 | // www.robosoup.com 3 | 4 | using UnityEngine; 5 | using System.Collections.Generic; 6 | using Unitilities; 7 | 8 | namespace Unitilities.Boids 9 | { 10 | public class Swarm 11 | { 12 | public float sight = 200f; 13 | public float speed = 12f; 14 | public float flockDistance = 3f; 15 | public float huntDistance = 10f; 16 | public float collisionSize = 1f; 17 | public float agility = 0.7f; 18 | public Rect cameraArea; 19 | public Rect swarmArea; 20 | public int killed = 0; 21 | 22 | public List Boids = new List(); 23 | public static List AllBoids = new List(); 24 | 25 | public Vector2i GetSector(Vector2 coordinates) { 26 | // sectors begin in the lower left corner. the whole swarm area is a 9-patch (3x3) - with rim it's 5x5 27 | return new Vector2i( 28 | (int) ((coordinates.x - swarmArea.xMin) / swarmArea.width/3f), 29 | (int) ((coordinates.y - swarmArea.yMin) / swarmArea.height/3f) 30 | ); 31 | } 32 | 33 | public List BoidsAroundSector(Vector2i sector) { 34 | List boids = new List(); 35 | 36 | Vector2i boidSector; 37 | for (var i = 0; i < AllBoids.Count; i++) { 38 | AllBoids[i].sector = boidSector = GetSector(AllBoids[i].pos); 39 | if (boidSector.x >= (sector.x-1 + 3) % 3 && boidSector.x <= (sector.x+1) % 3 && 40 | boidSector.y >= (sector.y-1 + 3) % 3 && boidSector.y <= (sector.y+1) % 3 ) { 41 | 42 | boids.Add(AllBoids[i]); 43 | } 44 | } 45 | 46 | return boids; 47 | } 48 | 49 | public Swarm(float hunterPercentage, Rect area, int number, int type) 50 | { 51 | swarmArea = area; 52 | 53 | for (var i = 0; i < number; i++) { 54 | Boid b = new Boid(this, i<(number * (int)(100f * hunterPercentage)/100), area, type); 55 | Boids.Add(b); 56 | AllBoids.Add(b); 57 | } 58 | } 59 | 60 | public void RegisterSwarm() { 61 | for (var i = 0; i < Boids.Count; i++) { 62 | AllBoids.Add(Boids[i]); 63 | } 64 | } 65 | 66 | public static void MoveAllBoids(Vector2 target, float deltaTime, float cameraSize) 67 | { 68 | foreach (var boid in AllBoids) { 69 | boid.Move(AllBoids,target,deltaTime,cameraSize); 70 | // boid.Respawn(); 71 | } 72 | } 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Boids/Swarm.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6a3faced9b994cbc83194ca0209940d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /BoneSystem.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21790ac1068d046bf83e2fc1a6ff614f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /BoneSystem/Bone.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | using UnityEngine; 27 | 28 | namespace Unitilities.BoneSystem { 29 | 30 | public class Bone : MonoBehaviour { 31 | 32 | public Vector2 From = Vector2.zero; 33 | public Vector2 To = Vector2.zero; 34 | public Vector2 Distance { get { return (To - From); } } 35 | 36 | void OnDrawGizmos() { 37 | Gizmos.color = UnityEngine.Color.red; 38 | Gizmos.DrawLine(From.Vector3XY(), To.Vector3XY()); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /BoneSystem/Bone.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2ae13ecd6873a4ae8ade9a0bb605ab73 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /BoneSystem/BoneDragWell.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | using UnityEngine; 27 | using Unitilities.Utils; 28 | 29 | namespace Unitilities.BoneSystem { 30 | 31 | public class BoneDragWell : MonoBehaviour { 32 | 33 | public GameObject _Prefab; 34 | private GameObject _object; 35 | public BoneDragger Dragger { get { return _object.GetComponent(); } } 36 | 37 | void Awake() { 38 | TryCreate(); 39 | _object.SetActive(false); 40 | } 41 | 42 | void TryCreate() { 43 | if (_Prefab != null && _object == null) { 44 | _object = Helpers.CreateObjectAt(_Prefab, Vector3.zero, gameObject); 45 | } 46 | } 47 | 48 | public void CreateDragger() { 49 | TryCreate(); 50 | if (_object == null) return; 51 | 52 | _object.transform.position = transform.position; 53 | _object.GetComponent().Init(); 54 | _object.SetActive(true); 55 | } 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /BoneSystem/BoneDragWell.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 15df309af4ae346d680fbfc524215a42 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /BoneSystem/BoneDragger.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94ea7e1aeacaf4f38affc9b318959a5e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /BoneSystem/BoneRectBridge.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | using UnityEngine; 27 | using UnityEngine.UI; 28 | using System.Collections; 29 | 30 | namespace Unitilities.BoneSystem { 31 | 32 | [RequireComponent(typeof(RectTransform))] 33 | [RequireComponent(typeof(Bone))] 34 | public class BoneRectBridge : MonoBehaviour { 35 | 36 | private RectTransform _rectTransform; 37 | private Bone _bone; 38 | 39 | private Vector2 _worldPivot; 40 | private Vector2 _originalPivot; 41 | 42 | void Awake() { 43 | _rectTransform = this.transform as RectTransform; 44 | _bone = GetComponent(); 45 | Init(); 46 | } 47 | 48 | public void Init() { 49 | _originalPivot = _rectTransform.pivot; 50 | _worldPivot = TransformVector(_originalPivot); 51 | 52 | _bone.From = _rectTransform.anchoredPosition; 53 | _bone.To = _bone.From + Vector2.up * _rectTransform.sizeDelta.y - 2f * _worldPivot.y * Vector2.up; 54 | } 55 | 56 | private Vector2 TransformVector(Vector2 vec) { 57 | vec.x *= _rectTransform.sizeDelta.x; 58 | vec.y *= _rectTransform.sizeDelta.y; 59 | return vec; 60 | } 61 | 62 | void FixedUpdate() { 63 | 64 | // pivot remains unchanged, bone is just distance between two pivots 65 | Vector2 targetSize = Vector2.zero; 66 | targetSize.x = _rectTransform.sizeDelta.x; 67 | targetSize.y = 2f * _worldPivot.y + _bone.Distance.magnitude; 68 | _rectTransform.anchoredPosition = _bone.From; 69 | _rectTransform.sizeDelta = targetSize; 70 | 71 | // pivot is relative, so put it back 72 | Vector2 pivot = _rectTransform.pivot; 73 | pivot.y = _worldPivot.y / targetSize.y; 74 | _rectTransform.pivot = pivot; 75 | 76 | // set angle 77 | Vector2 targetDirection = _bone.Distance; 78 | _rectTransform.localRotation = Quaternion.AngleAxis(90f - Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg, Vector3.back); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /BoneSystem/BoneRectBridge.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e0e59fd4a8fe44a39366f4c49eaf44a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /BoneSystem/BoneSnapEvents.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | using UnityEngine; 27 | using UnityEngine.Events; 28 | using System.Collections; 29 | 30 | 31 | namespace Unitilities.BoneSystem { 32 | 33 | public class BoneSnapEvents : MonoBehaviour { 34 | 35 | public UnityEvent Snapped; 36 | public UnityEvent CanSnapped; 37 | public UnityEvent Unsnapped; 38 | 39 | public delegate void SnapAction(BoneDragger dragger, BoneSnapEvents target); 40 | public event SnapAction OnSnap; 41 | public event SnapAction OnCanSnap; 42 | public event SnapAction OnUnsnap; 43 | 44 | public void CanSnap(BoneDragger dragger) { 45 | if (OnCanSnap != null) OnCanSnap(dragger, this); 46 | CanSnapped.Invoke(); 47 | } 48 | 49 | public void Snap(BoneDragger dragger) { 50 | if (OnSnap != null) OnSnap(dragger, this); 51 | Snapped.Invoke(); 52 | } 53 | 54 | public void Unsnap(BoneDragger dragger) { 55 | if (OnUnsnap != null) OnUnsnap(dragger, this); 56 | Unsnapped.Invoke(); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /BoneSystem/BoneSnapEvents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8f025944ca44d48e3ad0499fa0c837a8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /BoneSystem/BoneSnapTarget.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | using UnityEngine; 27 | using System.Collections; 28 | 29 | namespace Unitilities.BoneSystem { 30 | 31 | public class BoneSnapTarget : MonoBehaviour { 32 | public BoneSnapEvents Events { get { return GetComponent(); } } 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /BoneSystem/BoneSnapTarget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 073b5f237abcc4c3e85751581daa1981 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Bresenham.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6e923dafd64b4fd298c4bbf3012a56a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Bresenham/Bresenham.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Unitilities { 6 | 7 | public class Gridtools { 8 | public delegate void CallbackXY(int x, int y); 9 | public delegate void CallbackXYValue(int x, int y, int value); 10 | public delegate bool CheckXY(int x, int y); 11 | 12 | // Bresenham 13 | public static void CallbackForLineFromTo(CallbackXY cb, Vector2Int from, Vector2Int to) { 14 | Vector2Int s = new Vector2Int(from.x < to.x ? 1 : -1, from.y < to.y ? 1 : -1); 15 | Vector2Int d = new Vector2Int(Mathi.Abs(to.x - from.x), Mathi.Abs(to.y - from.y)); 16 | 17 | int err = (d.x > d.y ? d.x : -d.y) / 2, e2; 18 | for (; ; ) { 19 | cb(from.x, from.y); 20 | if (from.x == to.x && from.y == to.y) break; 21 | e2 = err; 22 | if (e2 > -d.x) { err -= d.y; from.x += s.x; } 23 | if (e2 < d.y) { err += d.x; from.y += s.y; } 24 | } 25 | } 26 | /** 27 | Check if callback for all tiles between to and from is true. 28 | */ 29 | public static bool CheckForLineFromTo(CheckXY cb, Vector2Int from, Vector2Int to) { 30 | Vector2Int s = new Vector2Int(from.x < to.x ? 1 : -1, from.y < to.y ? 1 : -1); 31 | Vector2Int d = new Vector2Int(Mathi.Abs(to.x - from.x), Mathi.Abs(to.y - from.y)); 32 | 33 | bool clear = true; 34 | int err = (d.x > d.y ? d.x : -d.y) / 2, e2; 35 | for (; ; ) { 36 | clear &= cb(from.x, from.y); 37 | if (from.x == to.x && from.y == to.y) break; 38 | e2 = err; 39 | if (e2 > -d.x) { err -= d.y; from.x += s.x; } 40 | if (e2 < d.y) { err += d.x; from.y += s.y; } 41 | } 42 | return clear; 43 | } 44 | 45 | // Dijkstra 46 | public static void CallbackForFillFrom(CallbackXYValue cb, Vector2Int from, CheckXY check, int distance) { 47 | if (!check(from.x, from.y)) return; 48 | if (distance < 0) return; 49 | cb(from.x, from.y, distance); 50 | CallbackForFillFrom(cb, from + Vector2Int.left, check, distance - 1); 51 | CallbackForFillFrom(cb, from + Vector2Int.right, check, distance - 1); 52 | CallbackForFillFrom(cb, from + Vector2Int.up, check, distance - 1); 53 | CallbackForFillFrom(cb, from + Vector2Int.down, check, distance - 1); 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Bresenham/Bresenham.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6fee894bedeb843bfacef2389542ce4e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Camera.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c31145a3b2b3d40988baf108edd9e338 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Camera/BetterCameraFollow2D.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using UnityEngine; 27 | 28 | namespace Unitilities 29 | { 30 | public class BetterCameraFollow2D : MonoBehaviour 31 | { 32 | public float LookAheadFactor { get { return lookAheadFactor; } set { lookAheadFactor = value; } } 33 | public float Damping { get { return damping; } set { damping = value; } } 34 | 35 | public Transform target; 36 | public float damping = 1; 37 | public float lookAheadFactor = 3; 38 | public float lookAheadReturnSpeed = 0.5f; 39 | public float lookAheadMoveThreshold = 0.1f; 40 | public bool fixedX = false; 41 | public bool fixedY = false; 42 | 43 | public bool unidirectionalX = false; 44 | public bool unidirectionalY = false; 45 | 46 | private Vector3 m_Offset; 47 | private Vector3 m_LastTargetPosition; 48 | private Vector3 m_CurrentVelocity; 49 | private Vector3 m_LookAheadPos; 50 | 51 | void Start() { 52 | m_LastTargetPosition = target.position; 53 | m_Offset = (transform.position - target.position); 54 | transform.parent = null; 55 | } 56 | 57 | public void JumpToTarget() { 58 | JumpTo(target.position); 59 | } 60 | 61 | public void JumpTo(Vector3 position) { 62 | position.z = transform.position.z; 63 | m_LookAheadPos = Vector3.zero; 64 | transform.position = m_LastTargetPosition = position; 65 | } 66 | 67 | void Update() { 68 | Vector3 moveDirection = (target.position - m_LastTargetPosition); 69 | bool updateLookAheadTarget = Mathf.Abs(moveDirection.magnitude) > lookAheadMoveThreshold; 70 | 71 | if (updateLookAheadTarget) 72 | m_LookAheadPos = lookAheadFactor*moveDirection; 73 | else 74 | m_LookAheadPos = Vector3.MoveTowards(m_LookAheadPos, Vector3.zero, UnityEngine.Time.deltaTime*lookAheadReturnSpeed); 75 | 76 | Vector3 aheadTargetPos = target.position + m_LookAheadPos + Vector3.forward*m_Offset.z; 77 | Vector3 newPos = Vector3.SmoothDamp(transform.position, aheadTargetPos, ref m_CurrentVelocity, damping ); 78 | 79 | if (fixedX) newPos.x = m_Offset.x; 80 | if (fixedY) newPos.y = m_Offset.y; 81 | 82 | if (unidirectionalX && newPos.x < transform.position.x) newPos.x = transform.position.x; 83 | if (unidirectionalY && newPos.y < transform.position.y) newPos.y = transform.position.y; 84 | 85 | transform.position = newPos; 86 | 87 | m_LastTargetPosition = target.position; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Camera/BetterCameraFollow2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e50109065ccb4a3789318f1d2f2618f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Camera/BetterCameraFollow3D.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System; 26 | using UnityEngine; 27 | 28 | namespace Unitilities 29 | { 30 | public class BetterCameraFollow3D : MonoBehaviour 31 | { 32 | public float LookAheadFactor { get { return lookAheadFactor; } set { lookAheadFactor = value; } } 33 | public float Damping { get { return damping; } set { damping = value; } } 34 | 35 | public Transform target; 36 | public float damping = 1; 37 | public float lookAheadFactor = 3; 38 | public float lookAheadReturnSpeed = 0.5f; 39 | public float lookAheadMoveThreshold = 0.1f; 40 | public bool fixedX = false; 41 | public bool fixedY = false; 42 | 43 | // map min .. max to (current y) .. (current y + speedZoomMax) 44 | public float speedZoomMax = 0f; 45 | public float speedMin = 0f; 46 | public float speedMax = 1f; 47 | 48 | public bool unidirectionalX = false; 49 | public bool unidirectionalY = false; 50 | 51 | private Vector3 m_Offset; 52 | private Vector3 m_LastTargetPosition; 53 | private Vector3 m_CurrentVelocity; 54 | private Vector3 m_LookAheadPos; 55 | 56 | void Start() { 57 | m_LastTargetPosition = target.position; 58 | m_Offset = (transform.position - target.position); 59 | transform.parent = null; 60 | } 61 | 62 | public void JumpToTarget() { 63 | m_LookAheadPos = Vector3.zero; 64 | transform.position = m_LastTargetPosition = target.position; 65 | } 66 | 67 | void Update() { 68 | Vector3 moveDirection = (target.position - m_LastTargetPosition); 69 | bool updateLookAheadTarget = Mathf.Abs(moveDirection.magnitude) > lookAheadMoveThreshold; 70 | 71 | if (updateLookAheadTarget) 72 | m_LookAheadPos = lookAheadFactor*moveDirection; 73 | else 74 | m_LookAheadPos = Vector3.MoveTowards(m_LookAheadPos, Vector3.zero, UnityEngine.Time.deltaTime*lookAheadReturnSpeed); 75 | 76 | float speedZoom = Mathf.Clamp01(moveDirection.magnitude - speedMin)/(speedMax-speedMin) * speedZoomMax; 77 | 78 | Vector3 aheadTargetPos = target.position + m_LookAheadPos + Vector3.up * m_Offset.y + Vector3.up * speedZoom; 79 | 80 | Vector3 newPos = Vector3.SmoothDamp(transform.position, aheadTargetPos, ref m_CurrentVelocity, damping ); 81 | 82 | if (fixedX) newPos.x = m_Offset.x; 83 | if (fixedY) newPos.y = m_Offset.y; 84 | 85 | if (unidirectionalX && newPos.x < transform.position.x) newPos.x = transform.position.x; 86 | if (unidirectionalY && newPos.y < transform.position.y) newPos.y = transform.position.y; 87 | 88 | transform.position = newPos; 89 | 90 | m_LastTargetPosition = target.position; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Camera/BetterCameraFollow3D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a8b18e097a0f452c80be34ef80f2113 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Collections.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 338f66246b5ef414b9b9a34212e6ffee 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Collections/Generic.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac4da88a587bc40e08281ac8ad6f3bc3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Collections/Generic/MultiMap.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | 28 | namespace Unitilities.Collections.Generic { 29 | public class MultiMap { 30 | Dictionary> _dictionary = new Dictionary>(); 31 | 32 | public void Add( float key, V value ) { 33 | List list; 34 | if (this._dictionary.TryGetValue(key, out list)) { 35 | list.Add(value); 36 | } else { 37 | list = new List(); 38 | list.Add(value); 39 | this._dictionary[key] = list; 40 | } 41 | } 42 | 43 | public void Remove( float key ) { 44 | this._dictionary.Remove(key); 45 | } 46 | 47 | public IEnumerable Keys { 48 | get { 49 | return this._dictionary.Keys; 50 | } 51 | } 52 | 53 | public List this [float key] { 54 | get { 55 | List list; 56 | if (!this._dictionary.TryGetValue(key, out list)) { 57 | list = new List(); 58 | this._dictionary[key] = list; 59 | } 60 | return list; 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /Collections/Generic/MultiMap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e9c6b938638c441ca048794c06a857d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Collections/Generic/Pair.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | 28 | namespace Unitilities.Collections.Generic { 29 | 30 | public class Pair { 31 | public T1 First { get; private set; } 32 | public T2 Second { get; private set; } 33 | internal Pair(T1 first, T2 second) 34 | { 35 | First = first; 36 | Second = second; 37 | } 38 | } 39 | 40 | public static class Pair { 41 | public static Pair New(T1 first, T2 second) { 42 | return new Pair(first, second); 43 | } 44 | } 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Collections/Generic/Pair.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 85614d60f9cb5401a885af25c771004e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Collections/Generic/PriorityQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3476f8445ace94cddbaada6a960ab1f3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Collections/Generic/RingBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fdd94557a4e34d3490f4350689fc958 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Collections/Generic/SerializableDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using UnityEngine; 7 | 8 | namespace Unitilities.Collections.Generic { 9 | 10 | [Serializable] 11 | public class SerializableDictionary : Dictionary, ISerializationCallbackReceiver { 12 | [SerializeField] 13 | private List keys = new List(); 14 | 15 | [SerializeField] 16 | private List values = new List(); 17 | 18 | // save the dictionary to lists 19 | public void OnBeforeSerialize() { 20 | keys.Clear(); 21 | values.Clear(); 22 | foreach (KeyValuePair pair in this) { 23 | keys.Add(pair.Key); 24 | values.Add(pair.Value); 25 | } 26 | } 27 | 28 | // load dictionary from lists 29 | public void OnAfterDeserialize() { 30 | this.Clear(); 31 | 32 | if (keys.Count != values.Count) 33 | throw new System.Exception(string.Format("there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable.")); 34 | 35 | for (int i = 0; i < keys.Count; i++) 36 | this.Add(keys[i], values[i]); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Collections/Generic/SerializableDictionary.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b3850d5e11274b5087f13ae3914d818 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Collections/Generic/ShuffleBag.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa4e491f884b34e8e80ef940bab261b4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Color.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4823506c26cd64e388b1e1a678853459 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Color/GradientPalette.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | 27 | namespace Unitilities { 28 | 29 | namespace Color { 30 | 31 | public class GradientPalette : MonoBehaviour { 32 | 33 | public UnityEngine.Color start = UnityEngine.Color.white; 34 | public UnityEngine.Color finish = UnityEngine.Color.black; 35 | 36 | public int paletteSize = 10; 37 | public Color32[] palette; 38 | 39 | void Start () { 40 | Recreate(); 41 | } 42 | 43 | public void SetFromTo(UnityEngine.Color start, UnityEngine.Color finish) { 44 | this.start = start; 45 | this.finish = finish; 46 | 47 | for (int i=0; i 8 | where TEnum : struct, IComparable, IFormattable { 9 | class StateMethodCache { 10 | public Action EnterState; 11 | public Action ExitState; 12 | } 13 | 14 | protected float elapsedTimeInState = 0f; 15 | protected TEnum previousState; 16 | Dictionary _stateCache; 17 | StateMethodCache _stateMethods; 18 | 19 | TEnum _currentState; 20 | 21 | protected TEnum CurrentState { 22 | get => _currentState; 23 | set { 24 | // dont change to the current state 25 | if (_stateCache.Comparer.Equals(_currentState, value)) 26 | return; 27 | 28 | // swap previous/current 29 | previousState = _currentState; 30 | _currentState = value; 31 | 32 | // exit the state, fetch the next cached state methods then enter that state 33 | if (_stateMethods.ExitState != null) 34 | _stateMethods.ExitState(); 35 | 36 | elapsedTimeInState = 0f; 37 | _stateMethods = _stateCache[_currentState]; 38 | 39 | if (_stateMethods.EnterState != null) 40 | _stateMethods.EnterState(); 41 | } 42 | } 43 | 44 | protected TEnum InitialState { 45 | set { 46 | _currentState = value; 47 | _stateMethods = _stateCache[_currentState]; 48 | 49 | if (_stateMethods.EnterState != null) 50 | _stateMethods.EnterState(); 51 | } 52 | } 53 | 54 | public EnumStateMachine(IEqualityComparer customComparer = null) { 55 | _stateCache = new Dictionary(customComparer); 56 | 57 | // cache all of our state methods 58 | var enumValues = (TEnum[])Enum.GetValues(typeof(TEnum)); 59 | foreach (var e in enumValues) 60 | ConfigureAndCacheState(e); 61 | } 62 | 63 | void ConfigureAndCacheState(TEnum stateEnum) { 64 | var stateName = stateEnum.ToString(); 65 | 66 | var state = new StateMethodCache(); 67 | state.EnterState = GetDelegateForMethod(stateName + "_Enter"); 68 | state.ExitState = GetDelegateForMethod(stateName + "_Exit"); 69 | 70 | _stateCache[stateEnum] = state; 71 | } 72 | 73 | Action GetDelegateForMethod(string methodName) { 74 | var methodInfo = ReflectionUtils.GetMethodInfo(this, methodName); 75 | if (methodInfo != null) 76 | return ReflectionUtils.CreateDelegate(this, methodInfo); 77 | 78 | return null; 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /FSM/EnumStateMachine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1486c63ce90ae4b7d8732c81b7e9fb81 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /FSM/ReflectionUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d55707b45daf943f9b362abebdee6c7f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /FSM/SimpleStateMachine.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Unitilities.FSM; 5 | 6 | /* 7 | A simple text class for the state machine implementation 8 | */ 9 | 10 | public class SimpleStateMachine : MonoBehaviour { 11 | 12 | public enum States { 13 | Init, 14 | Normal, 15 | None 16 | } 17 | 18 | class InternalStateMachine : EnumStateMachine { 19 | 20 | SimpleStateMachine _context; 21 | 22 | public InternalStateMachine(SimpleStateMachine context) { 23 | _context = context; 24 | InitialState = States.Init; 25 | } 26 | public void SetState(States state) { 27 | CurrentState = state; 28 | } 29 | 30 | public void Init_Enter() { 31 | Debug.Log("Enter Init"); 32 | } 33 | public void Init_Exit() { 34 | Debug.Log("Exit Init"); 35 | } 36 | public void Normal_Enter() { 37 | Debug.Log("Enter Normal"); 38 | } 39 | public void Normal_Exit() { 40 | Debug.Log("Exit Normal"); 41 | } 42 | 43 | } 44 | 45 | private InternalStateMachine _machine; 46 | 47 | private void Awake() { 48 | _machine = new InternalStateMachine(this); 49 | _machine.SetState(States.Normal); 50 | _machine.SetState(States.Init); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /FSM/SimpleStateMachine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6f16b36d22ed4b7ab65017e4740fab0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /FSM/State.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace Unitilities.FSM { 5 | 6 | public abstract class State { 7 | 8 | protected StateMachine _machine; 9 | protected T _context; 10 | 11 | public void Init(StateMachine machine, T context) { 12 | _machine = machine; 13 | _context = context; 14 | OnInitialized(); 15 | } 16 | 17 | public virtual void OnInitialized() { 18 | } 19 | 20 | public virtual void Begin() { 21 | } 22 | 23 | /// 24 | /// called before update allowing the state to have one last chance to change state 25 | /// 26 | public virtual void Reason() { 27 | } 28 | 29 | /// 30 | /// called when this state is no longer the active state 31 | /// 32 | public virtual void End() { 33 | } 34 | } 35 | } 36 | 37 | /* 38 | protected StateMachine _machine; 39 | protected T _context; 40 | 41 | 42 | public void SetMachineAndContext(StateMachine machine, T context) 43 | { 44 | _machine = machine; 45 | _context = context; 46 | OnInitialized(); 47 | } 48 | 49 | 50 | /// 51 | /// called directly after the machine and context are set allowing the state to do any required setup 52 | /// 53 | public virtual void OnInitialized() 54 | { 55 | } 56 | 57 | 58 | /// 59 | /// called when the state becomes the active state 60 | /// 61 | public virtual void Begin() 62 | { 63 | } 64 | 65 | 66 | /// 67 | /// called before update allowing the state to have one last chance to change state 68 | /// 69 | public virtual void Reason() 70 | { 71 | } 72 | 73 | 74 | /// 75 | /// called every frame this state is the active state 76 | /// 77 | /// Delta time. 78 | public abstract void Update(float deltaTime); 79 | 80 | 81 | /// 82 | /// called when this state is no longer the active state 83 | /// 84 | public virtual void End() 85 | { 86 | } 87 | } 88 | */ -------------------------------------------------------------------------------- /FSM/State.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a87532d8840d546198ecaf920d5bcada 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /FSM/StateMachine.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System; 4 | 5 | namespace Unitilities.FSM { 6 | 7 | public class StateMachine { 8 | public delegate void voidAction(); 9 | public event voidAction OnStateChanged; 10 | 11 | public State currentState => _currentState; 12 | 13 | public State previousState; 14 | 15 | protected State _currentState; 16 | protected T _context; 17 | Dictionary> _states = new Dictionary>(); 18 | 19 | 20 | public StateMachine(T context, State initialState) { 21 | _context = context; 22 | 23 | // setup our initial state 24 | AddState(initialState); 25 | _currentState = initialState; 26 | _currentState.Begin(); 27 | } 28 | 29 | 30 | /// 31 | /// adds the state to the machine 32 | /// 33 | public void AddState(State state) { 34 | state.Init(this, _context); 35 | _states[state.GetType()] = state; 36 | } 37 | 38 | 39 | /// 40 | /// ticks the state machine with the provided delta time 41 | /// 42 | public virtual void Update(float deltaTime) { 43 | // elapsedTimeInState += deltaTime; 44 | // _currentState.Reason(); 45 | // _currentState.Update(deltaTime); 46 | } 47 | 48 | /// 49 | /// Gets a specific state from the machine without having to 50 | /// change to it. 51 | /// 52 | public virtual R GetState() where R : State { 53 | var type = typeof(R); 54 | // Debug.Assert(_states.ContainsKey(type), 55 | // "{0}: state {1} does not exist. Did you forget to add it by calling addState?", GetType(), type); 56 | 57 | return (R)_states[type]; 58 | } 59 | 60 | 61 | /// 62 | /// changes the current state 63 | /// 64 | public R ChangeState() where R : State { 65 | // avoid changing to the same state 66 | var newType = typeof(R); 67 | if (_currentState.GetType() == newType) 68 | return _currentState as R; 69 | 70 | // only call end if we have a currentState 71 | if (_currentState != null) 72 | _currentState.End(); 73 | 74 | // Insist.IsTrue(_states.ContainsKey(newType), 75 | // "{0}: state {1} does not exist. Did you forget to add it by calling addState?", GetType(), newType); 76 | 77 | // swap states and call begin 78 | previousState = _currentState; 79 | _currentState = _states[newType]; 80 | _currentState.Begin(); 81 | 82 | // fire the changed event if we have a listener 83 | if (OnStateChanged != null) 84 | OnStateChanged(); 85 | 86 | return _currentState as R; 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /FSM/StateMachine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e387af70adda49eeaa9b04a1452625f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /File.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4dc72995e9571411db2a48c68dfb68b6 3 | folderAsset: yes 4 | timeCreated: 1428938711 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /File/ArrayPrefs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a4760a287ae34ef7be5cd2449f62b4f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /File/FolderInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | using System.IO; 28 | 29 | namespace Utils { 30 | public class FolderInfo { 31 | 32 | /* based on http://forum.unity3d.com/threads/how-to-get-list-of-assets-at-asset-path.18898/ */ 33 | /* usage: Object[] objects = Utils.GetObjectsAtPath("/Path/To/Music"); */ 34 | 35 | #if UNITY_EDITOR 36 | public static T[] GetObjectsAtPath(string path) { 37 | 38 | ArrayList al = new ArrayList(); 39 | string[] fileEntries = Directory.GetFiles(Application.dataPath + "/" + path); 40 | 41 | foreach (string fileName in fileEntries) 42 | { 43 | int assetPathIndex = fileName.IndexOf("Resources"); 44 | string localPath = fileName.Substring(assetPathIndex); 45 | 46 | Object t = UnityEditor.AssetDatabase.LoadAssetAtPath(localPath, typeof(T)); 47 | 48 | if (t != null) { 49 | al.Add(t); 50 | } 51 | } 52 | T[] result = new T[al.Count]; 53 | for (int i = 0; i < al.Count; i++) 54 | result[i] = (T)al[i]; 55 | 56 | return result; 57 | } 58 | #endif 59 | 60 | public static string[] ListObjectsAtPath(string path, string extension) { 61 | ArrayList al = new ArrayList(); 62 | string fullPath = Application.dataPath + "/" + path; 63 | string[] fileEntries = Directory.GetFiles(fullPath); 64 | 65 | foreach (string fileName in fileEntries) { 66 | string localPath = fileName.Substring(fullPath.Length+1); 67 | if (localPath.EndsWith(extension)) 68 | al.Add(localPath); 69 | } 70 | string[] result = new string[al.Count]; 71 | for (int i = 0; i < al.Count; i++) 72 | result[i] = (string)al[i]; 73 | 74 | return result; 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /File/FolderInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38e2e2bded6534e56b62cc6ba922e2ce 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /File/SimpleJSON.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 43aa704ce09254990ac22634545bdb80 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /File/TextFileReader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74967a585bded4adcbbc34b97dd6be62 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /FrameInterpolater.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5198c857f31d470eba967d0b2e5dbb1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /FrameInterpolater/InterpolatedTransform.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0fe6598be86e4c6db3f6ab31b9f6c8a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /FrameInterpolater/InterpolatedTransformUpdater.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | Based on http://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8 by Scott Sewell 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | 27 | using UnityEngine; 28 | using System.Collections; 29 | 30 | /* 31 | Used to call a couple methods in InterpolatedTransform both before and after other script’s FixedUpdates. Must be placed on objects that also have InterpolatedTransform attached. 32 | */ 33 | 34 | namespace Unitilities.FrameInterpolater { 35 | 36 | public class InterpolatedTransformUpdater : MonoBehaviour { 37 | private InterpolatedTransform m_interpolatedTransform; 38 | 39 | void Awake() { 40 | m_interpolatedTransform = GetComponent(); 41 | } 42 | 43 | void FixedUpdate() { 44 | m_interpolatedTransform.LateFixedUpdate(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /FrameInterpolater/InterpolatedTransformUpdater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 47f6aa3ab4f3b443cb0fa452fcb58f17 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /FrameInterpolater/InterpolationController.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | Based on http://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8 by Scott Sewell 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | 27 | using UnityEngine; 28 | using System.Collections; 29 | 30 | /* 31 | Execution Order: 32 | InterpolationController -100 33 | InterpolatedTransform -50 34 | InterpolatedTransformUpdater 100 35 | 36 | Source: http://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8 37 | 38 | HOWTO: 39 | Attach InterpolationController to a single gameobject in the scene. 40 | Attach InterpolatedTransform + Updater to any objects moved during a FixedUpdate. 41 | 42 | 43 | Do all movement/state update in FixedUpdate! 44 | */ 45 | 46 | namespace Unitilities.FrameInterpolater { 47 | 48 | public class InterpolationController : MonoBehaviour { 49 | private float[] m_lastFixedUpdateTimes; 50 | private int m_newTimeIndex; 51 | 52 | private static float m_interpolationFactor; 53 | 54 | public static float InterpolationFactor { 55 | get { return m_interpolationFactor; } 56 | } 57 | 58 | public void Start() { 59 | m_lastFixedUpdateTimes = new float[2]; 60 | m_newTimeIndex = 0; 61 | } 62 | 63 | public void FixedUpdate() { 64 | m_newTimeIndex = OldTimeIndex(); 65 | m_lastFixedUpdateTimes[m_newTimeIndex] = UnityEngine.Time.fixedTime; 66 | } 67 | 68 | public void Update() { 69 | float newerTime = m_lastFixedUpdateTimes[m_newTimeIndex]; 70 | float olderTime = m_lastFixedUpdateTimes[OldTimeIndex()]; 71 | 72 | if (newerTime != olderTime) { 73 | m_interpolationFactor = (UnityEngine.Time.time - newerTime) / (newerTime - olderTime); 74 | } else { 75 | m_interpolationFactor = 1; 76 | } 77 | } 78 | 79 | private int OldTimeIndex() { 80 | return (m_newTimeIndex == 0 ? 1 : 0); 81 | } 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /FrameInterpolater/InterpolationController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5526354d2501c46e19395588ccd47802 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Gameplay.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b6133d7a08ae466a853edf752ca70aa 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Gameplay/ActivateTrigger2D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using Object = UnityEngine.Object; 4 | 5 | namespace Unitilities.Gameplay 6 | { 7 | public class ActivateTrigger2D : MonoBehaviour 8 | { 9 | // A multi-purpose script which causes an action to occur when 10 | // a trigger collider is entered. 11 | public enum Mode 12 | { 13 | Trigger = 0, // Just broadcast the action on to the target 14 | Replace = 1, // replace target with source 15 | Activate = 2, // Activate the target GameObject 16 | Enable = 3, // Enable a component 17 | Animate = 4, // Start animation on target 18 | Deactivate = 5 // Decativate target GameObject 19 | } 20 | 21 | public Mode action = Mode.Activate; // The action to accomplish 22 | public Object target; // The game object to affect. If none, the trigger work on this game object 23 | public GameObject source; 24 | public int triggerCount = 1; 25 | public bool repeatTrigger = false; 26 | 27 | 28 | private void DoActivateTrigger() 29 | { 30 | triggerCount--; 31 | 32 | if (triggerCount == 0 || repeatTrigger) 33 | { 34 | Object currentTarget = target ?? gameObject; 35 | Behaviour targetBehaviour = currentTarget as Behaviour; 36 | GameObject targetGameObject = currentTarget as GameObject; 37 | if (targetBehaviour != null) 38 | { 39 | targetGameObject = targetBehaviour.gameObject; 40 | } 41 | 42 | switch (action) 43 | { 44 | case Mode.Trigger: 45 | if (targetGameObject != null) 46 | { 47 | targetGameObject.BroadcastMessage("DoActivateTrigger"); 48 | } 49 | break; 50 | case Mode.Replace: 51 | if (source != null) 52 | { 53 | if (targetGameObject != null) 54 | { 55 | Instantiate(source, targetGameObject.transform.position, 56 | targetGameObject.transform.rotation); 57 | Destroy(targetGameObject); 58 | } 59 | } 60 | break; 61 | case Mode.Activate: 62 | if (targetGameObject != null) 63 | { 64 | targetGameObject.SetActive(true); 65 | } 66 | break; 67 | case Mode.Enable: 68 | if (targetBehaviour != null) 69 | { 70 | targetBehaviour.enabled = true; 71 | } 72 | break; 73 | case Mode.Animate: 74 | if (targetGameObject != null) 75 | { 76 | targetGameObject.GetComponent().Play(); 77 | } 78 | break; 79 | case Mode.Deactivate: 80 | if (targetGameObject != null) 81 | { 82 | targetGameObject.SetActive(false); 83 | } 84 | break; 85 | } 86 | } 87 | } 88 | 89 | 90 | private void OnTriggerEnter2D(Collider2D other) 91 | { 92 | DoActivateTrigger(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Gameplay/ActivateTrigger2D.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f2cf4b4271804afa85b8d2dedfb50a3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Gameplay/OnTriggerMoveAlong.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Unitilities.Gameplay { 6 | 7 | public class OnTriggerMoveAlong : MonoBehaviour { 8 | 9 | private Vector2 _offset; 10 | private Vector3 _lastPos; 11 | private Rigidbody2D _body = null; 12 | public float Force = 100f; 13 | 14 | void OnTriggerEnter2D(Collider2D col) { 15 | Rigidbody2D rb = col.attachedRigidbody; 16 | if (rb != null && col.tag == "Player") { 17 | _offset = rb.position - transform.position.Vector2XY(); 18 | _body = rb; 19 | _body.isKinematic = true; 20 | 21 | Debug.Log("enter trigger"); 22 | } 23 | } 24 | 25 | void OnTriggerExit2D(Collider2D col) { 26 | if (_body != null) { 27 | _body.isKinematic = false; 28 | _body = null; 29 | 30 | Debug.Log("exit trigger"); 31 | } 32 | } 33 | 34 | void FixedUpdate() { 35 | if (_body != null && _body.isKinematic) { 36 | _body.MovePosition(transform.position.Vector2XY() + _offset); 37 | } 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Gameplay/OnTriggerMoveAlong.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3392e717e73b4e8297e989ddf17de4c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Gameplay/TimedDeactivator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Unitilities.Gameplay { 6 | 7 | public class TimedDeactivator : MonoBehaviour { 8 | 9 | public float Delay = 1f; 10 | 11 | private IEnumerator Deactivate(float delay) { 12 | yield return new WaitForSeconds(delay); 13 | gameObject.SetActive(false); 14 | } 15 | 16 | private void OnEnable() { 17 | StartCoroutine(Deactivate(Delay)); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Gameplay/TimedDeactivator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1e99f5382f914e108b50e4b0af881c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Gameplay/TimedTransformReset.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Unitilities.Gameplay { 6 | 7 | public class TimedTransformReset : MonoBehaviour { 8 | 9 | public Transform Target; 10 | public float Timeout = 1f; 11 | public bool Deactivate = false; 12 | float _startTime; 13 | 14 | Vector3 _position; 15 | Vector3 _scale; 16 | Quaternion _rotation; 17 | bool _active; 18 | 19 | void OnEnable() { 20 | _startTime = UnityEngine.Time.time; 21 | _position = Target.position; 22 | _scale = Target.localScale; 23 | _rotation = Target.rotation; 24 | } 25 | 26 | void Update() { 27 | if (UnityEngine.Time.time - _startTime > Timeout) { 28 | Target.position = _position; 29 | Target.localScale = _scale; 30 | Target.rotation = _rotation; 31 | if (Deactivate) 32 | Target.gameObject.SetActive(false); 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Gameplay/TimedTransformReset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7dbc2845a7c8f410d8a3305f6a676e48 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Graph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0982c560f04bf46118fdbd712961713a 3 | folderAsset: yes 4 | timeCreated: 1428938711 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Graph/Graph.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ed28edb9d0b7418aa061dc6611c9b76 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Graph/GraphNode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System.Collections.Generic; 26 | 27 | public class GraphNode : Node 28 | { 29 | private List costs; 30 | 31 | public GraphNode() : base() { } 32 | public GraphNode(T value) : base(value) { } 33 | public GraphNode(T value, NodeList neighbors) : base(value, neighbors) { } 34 | 35 | new public NodeList Neighbors 36 | { 37 | get 38 | { 39 | if (base.Neighbors == null) 40 | base.Neighbors = new NodeList(); 41 | 42 | return base.Neighbors; 43 | } 44 | } 45 | 46 | public List Costs 47 | { 48 | get 49 | { 50 | if (costs == null) 51 | costs = new List(); 52 | 53 | return costs; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Graph/GraphNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db43adef0b5e24e08bf1c31e5bd02eb0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Graph/Node.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | 28 | public class NodeList : List> 29 | { 30 | public NodeList() : base() { } 31 | 32 | public NodeList(int initialSize) 33 | { 34 | for (int i = 0; i < initialSize; i++) 35 | base.Add(default(Node)); 36 | } 37 | 38 | public Node FindByValue(T value) 39 | { 40 | for (int i = 0; i < Count; i++) { 41 | if (base[i].Value.Equals(value)) return base[i]; 42 | } 43 | 44 | // foreach (Node node in Items) 45 | // if (node.Value.Equals(value)) 46 | // return node; 47 | 48 | return null; 49 | } 50 | } 51 | 52 | public class Node 53 | { 54 | private T data; 55 | private NodeList neighbors = null; 56 | 57 | public Node() {} 58 | public Node(T data) : this(data, null) {} 59 | public Node(T data, NodeList neighbors) 60 | { 61 | this.data = data; 62 | this.neighbors = neighbors; 63 | } 64 | 65 | public T Value 66 | { 67 | get 68 | { 69 | return data; 70 | } 71 | set 72 | { 73 | data = value; 74 | } 75 | } 76 | 77 | protected NodeList Neighbors 78 | { 79 | get 80 | { 81 | return neighbors; 82 | } 83 | set 84 | { 85 | neighbors = value; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Graph/Node.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23477e394fd794594a555e4de9b4e35e 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Grid.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 342b1de4d966d48cbb1574cfae360fb4 3 | folderAsset: yes 4 | timeCreated: 1429013404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Grid/GridUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | 28 | namespace Unitilities.Grid { 29 | public static class GridUtils { 30 | public static float[,] average(float[,] grid, int radius, float strength) { 31 | float f = Mathf.Clamp01(strength); 32 | float p = 1f / (float)((2 * radius + 1) * (2 * radius + 1)); 33 | float a = 0f; 34 | 35 | float[,] g = new float[grid.GetLength(0), grid.GetLength(1)]; 36 | 37 | for (int x = 0; x < grid.GetLength(0); ++x) { 38 | for (int y = 0; y < grid.GetLength(1); ++y) { 39 | 40 | a = 0f; 41 | for (int xx = -radius; xx <= radius; ++xx) { 42 | for (int yy = -radius; yy <= radius; ++yy) { 43 | int px = Mathi.Clamp(xx + x, 0, grid.GetLength(0) - 1); 44 | int py = Mathi.Clamp(yy + y, 0, grid.GetLength(1) - 1); 45 | 46 | a += grid[px, py] * p; 47 | } 48 | } 49 | g[x, y] = (1.0f - f) * grid[x, y] + f * a; 50 | } 51 | } 52 | return g; 53 | } 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Grid/GridUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aadd581e78c8e498582420684d8d0935 3 | timeCreated: 1429013629 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Grid/HexGrid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dfb81a7f59d574061979fca57bd95321 3 | timeCreated: 1429016344 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Grid/QuadGrid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 363227ec583c147239a8738e463ceb88 3 | timeCreated: 1429021915 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Martin Pichlmair 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe0d0abfdabab44ed8f4795d9288e7d7 3 | timeCreated: 1428938711 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Math.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4f857baf92144ea7b97b292c474c1ca 3 | folderAsset: yes 4 | timeCreated: 1428938711 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Math/MathParser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2b6f31d862bf412a8858ca944d791f8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Math/Mathi.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | 27 | public struct Mathi { 28 | public static int Min(int x, int y) { return x < y ? x : y; } 29 | public static int Max(int x, int y) { return x > y ? x : y; } 30 | public static int Abs(int x) { return x >= 0 ? x : -x; } 31 | public static int Clamp(int value, int min, int max) { return Max(Min(value,max), min); } 32 | public static int Lerp(int from, int to, float t) { return Mathf.FloorToInt((float)(to-from)*Mathf.Clamp01(t)+(float)from); } 33 | public static int RandomBetween(int from, int to) { return (int)from + (int)Mathf.Floor((float)(to-from+1) * Random.value); } 34 | } 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Math/Mathi.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c8245c2908734d7095f9f71f5ebf593 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Math/Utils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5c39b0480cc2a4ae5acdcd268e9e55ac 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Math/Vector2i.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64038f03281634e1696ece9eeee53938 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Notification.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a0cd9a5ecf2647fd9478bf9faf05245 3 | folderAsset: yes 4 | timeCreated: 1428938711 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Notification/Notification.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | 26 | // Standard notification class. Derive subclass for specific needs 27 | namespace Unitilities.Notifications { 28 | public class Notification { 29 | public string key; 30 | public object userInfo; 31 | 32 | public Notification( string type ) { 33 | this.key = type; 34 | this.userInfo = null; 35 | } 36 | 37 | 38 | public Notification( string type, object userInfo ) { 39 | this.key = type; 40 | this.userInfo = userInfo; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Notification/Notification.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2dffa943aa46946b695160e7c5b04d6a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Notification/NotificationCenter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c5a49878bda8449eb6bc6cf538913fc 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Notification/SuperNotification.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | 28 | namespace Unitilities.Notifications { 29 | 30 | public class SuperNotification : Notification 31 | { 32 | public float varFloat; 33 | public int varInt; 34 | 35 | 36 | public SuperNotification( string type, float varFloat, int varInt ) : base( type ) 37 | { 38 | this.varFloat = varFloat; 39 | this.varInt = varInt; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Notification/SuperNotification.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 31880c89566dd4e1ba751fd60c1e22ae 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Notification/SystemNotifications.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | using System.Collections.Generic; 28 | 29 | namespace Unitilities.Notifications { 30 | public class SystemNotifications : MonoBehaviour { 31 | 32 | bool FirstUpdate = true; 33 | 34 | /* Be sure to execute this script with the lowest execution order, e.g. -1000! */ 35 | 36 | void Update () { 37 | if (!FirstUpdate) return; 38 | FirstUpdate = false; 39 | 40 | NotificationCenter.Instance.PostNotification("Init"); 41 | NotificationCenter.Instance.PostNotification("PostInit"); 42 | NotificationCenter.Instance.PostNotification("PostPostInit"); 43 | NotificationCenter.Instance.PostNotification("InitDone"); 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Notification/SystemNotifications.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b2a2055f305947b288f3cac8535d73a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /ObjectPool.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c14b824eb666442c3a6cf05dc2ede5e8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ObjectPool/ObjectPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58bf894e74a0341b39ddcddfb40ed262 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: -80 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /ObjectPool/Pool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e067e36b71da34e778e30b53ac6877c4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa80594c275804e9e9350da261856422 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Pathfinding/AStar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d629a9a387206448491c4eef978d26b8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/FlowGrid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19dd5498668ff4f9db216c4756a99176 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/FlowGridFollow.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2018 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | using UnityEngine; 28 | 29 | public class FlowGridFollow : MonoBehaviour { 30 | 31 | public FlowGrid FlowGrid; 32 | public float Force = 1f; 33 | public bool RandomStartPosition = true; 34 | 35 | private bool _active = false; 36 | private Rigidbody2D _body2D; 37 | 38 | void Start () { 39 | _body2D = GetComponent(); 40 | StartCoroutine(StartMoving(2f)); 41 | if (RandomStartPosition) { 42 | Vector2 pos = Vector2.zero; 43 | pos.x = ((float)FlowGrid.Width) * Random.value; 44 | pos.y = ((float)FlowGrid.Height) * Random.value; 45 | // _body2D.MovePosition(pos); 46 | transform.position = pos.Vector3XY(); 47 | } 48 | } 49 | 50 | void Update () { 51 | if (!_active) return; 52 | 53 | Vector3 dir = FlowGrid.getInterpolatedForces(transform.position); 54 | _body2D.AddForce(Force * dir.Vector2XY()); 55 | } 56 | 57 | IEnumerator StartMoving(float delay) { 58 | yield return new WaitForSeconds(delay); 59 | _active = true; 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Pathfinding/FlowGridFollow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a8d12609fb2dc4efca4f73cd76f253a3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/FlowGridRayCaster.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2018 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | using UnityEngine; 28 | 29 | [RequireComponent(typeof(FlowGrid))] 30 | public class FlowGridRayCaster : MonoBehaviour { 31 | 32 | public float Frequency = 1f; 33 | public float Altitude = 5f; 34 | 35 | private FlowGrid _grid; 36 | 37 | void Start () { 38 | _grid = GetComponent(); 39 | StartCoroutine(CastRays(Frequency)); 40 | } 41 | 42 | // void OnDrawGizmosSelected() { 43 | // Gizmos.color = Color.white; 44 | // Vector3Int gridPos = Vector3Int.zero; 45 | // // Vector3 halfSize = (_grid.getWorldPosition(new Vector3Int(1,1,0)) - transform.position)/2f; 46 | // for (gridPos.x = 0; gridPos.x < _grid.Width; gridPos.x++) { 47 | // for (gridPos.y = 0; gridPos.y < _grid.Height; gridPos.y++) { 48 | 49 | // Gizmos.DrawRay( 50 | // _grid.getWorldPosition(gridPos), Vector3.back 51 | // ); 52 | // } 53 | // } 54 | // } 55 | 56 | private IEnumerator CastRays(float frequency) { 57 | yield return new WaitForSecondsRealtime(frequency); 58 | 59 | RaycastHit hit; 60 | Vector3Int gridPos = Vector3Int.zero; 61 | gridPos.z = (int)(transform.position.z + Altitude); 62 | 63 | // Vector3 halfSize = _grid.getWorldPosition(new Vector3Int(1,1,0)) - transform.position; 64 | 65 | for (gridPos.x = 0; gridPos.x < _grid.Width; gridPos.x++) { 66 | for (gridPos.y = 0; gridPos.y < _grid.Height; gridPos.y++) { 67 | bool wall = Physics.Raycast(_grid.getWorldPosition(gridPos), Vector3.back, out hit, Altitude+1f, 1< _aStar; 34 | 35 | public void CreateGrid( int width, int height ) { 36 | _grid = new Pathfinding.EPathNode[width, height]; 37 | } 38 | 39 | public void SetPathNode( int x, int y, bool walkable ) { 40 | _grid[x, y] = new Pathfinding.EPathNode() { 41 | Walkable = walkable, 42 | X = x, 43 | Y = y, 44 | }; 45 | } 46 | 47 | public void AddPathNode( Pathfinding.EPathNode node ) { 48 | _grid[node.X, node.Y] = node; 49 | } 50 | 51 | public void UpdateGrid() { 52 | _aStar = new Pathfinding.AStar(_grid); 53 | } 54 | 55 | public LinkedList FindPath( Vector2 from, Vector2 to ) { 56 | return _aStar.Search(from, to, null); 57 | } 58 | 59 | public bool IsReachable( Vector2 from, Vector2 to, int steps ) { 60 | return (_aStar.Search(from, to, null).Count <= steps); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Pathfinding/PathFinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0799e962d67b41af81d85cdad7a5484 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/PathNode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using Unitilities.Collections.Generic; 27 | 28 | namespace Unitilities.Pathfinding { 29 | public class EPathNode : IPathNode { 30 | public int X { get; set; } 31 | public int Y { get; set; } 32 | public bool Walkable {get; set;} 33 | public bool IsWalkable(Object userContext) { 34 | return Walkable; 35 | } 36 | 37 | public float Heuristic(IPathNode toNode, Object userContext) { 38 | return (Mathf.Abs(X - toNode.X) + Mathf.Abs(Y - toNode.Y)); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Pathfinding/PathNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe287388c53404ff1a2479eac94d01f9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/PathSeeker.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | using System.Collections.Generic; 28 | 29 | /* Interact with the global Pathfinder */ 30 | namespace Unitilities.Pathfinding { 31 | 32 | public class PathSeeker : MonoBehaviour { 33 | 34 | public PathFinder _pathFinder = null; 35 | public WeightedPathFinder _wPathFinder = null; 36 | public int Steps = 5; 37 | 38 | public float GridScale = 1f; 39 | public Vector3 GridPosition = Vector3.zero; 40 | 41 | public delegate void OnPathDelegate ( LinkedList> path ); 42 | 43 | public OnPathDelegate pathCallback; 44 | 45 | 46 | void Reset() { 47 | if (_pathFinder == null) 48 | _pathFinder = GetComponent(); 49 | if (_wPathFinder == null) 50 | _wPathFinder = GetComponent(); 51 | } 52 | 53 | // public LinkedList> Path(Vector3 worldPos, Vector3 targetWorldPos) { 54 | // Vector3 gp = worldPos * GridScale - GridPosition; 55 | // Vector3 tgp = targetWorldPos * GridScale - GridPosition; 56 | // Vector2i gridPos = new Vector2i(gp.x, gp.y); 57 | // Vector2i targetGridPos = new Vector2i(tgp.x, tgp.y); 58 | // return Path(gridPos, targetGridPos); 59 | // } 60 | 61 | // public LinkedList> Path(Vector2i gridPos, Vector2i targetGridPos) { 62 | // LinkedList> path; 63 | // 64 | // if (_wPathFinder != null) 65 | // path = _wPathFinder.FindPath(gridPos, targetGridPos); 66 | // else 67 | // path = _pathFinder.FindPath(gridPos, targetGridPos); 68 | // pathCallback(path); 69 | // 70 | // return path; 71 | // } 72 | 73 | public void SetGrid( bool[,] grid ) { 74 | int w = grid.GetLength(0); 75 | int h = grid.GetLength(1); 76 | for (int x = 0; x < w; ++x) { 77 | for (int y = 0; y < h; ++y) { 78 | if (_wPathFinder != null) 79 | _wPathFinder.SetPathNode(x, y, grid[x, y]); 80 | else 81 | _pathFinder.SetPathNode(x, y, grid[x, y]); 82 | } 83 | } 84 | if (_wPathFinder != null) 85 | _wPathFinder.UpdateGrid(); 86 | else 87 | _pathFinder.UpdateGrid(); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /Pathfinding/PathSeeker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75bb1835db8da422b88544a11335dfaf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/TilemapPathFinder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2019 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEngine.Tilemaps; 27 | using System.Collections.Generic; 28 | 29 | namespace Unitilities.Pathfinding { 30 | 31 | public class TilemapPathFinder : MonoBehaviour { 32 | 33 | public Tilemap walkableMap; 34 | public Tilemap wallMap; 35 | 36 | private Vector3Int _offset; 37 | private Pathfinding.TilemapPathNode[,] _grid; 38 | private Pathfinding.AStar _aStar; 39 | 40 | public void CreateGrid( int width, int height ) { 41 | _grid = new Pathfinding.TilemapPathNode[width, height]; 42 | } 43 | 44 | public void SetPathNode( int x, int y, bool walkable ) { 45 | _grid[x, y] = new Pathfinding.TilemapPathNode() { 46 | Walkable = walkable, 47 | X = x+_offset.x, 48 | Y = y+_offset.y, 49 | }; 50 | } 51 | 52 | public void AddPathNode( Pathfinding.TilemapPathNode node ) { 53 | _grid[node.X, node.Y] = node; 54 | } 55 | 56 | public void UpdateGrid() { 57 | _aStar = new Pathfinding.AStar(_grid); 58 | } 59 | 60 | public LinkedList FindPath( Vector3Int from, Vector3Int to ) { 61 | BoundsInt bounds = walkableMap.cellBounds; 62 | if (!bounds.Contains(from) || !bounds.Contains(to)) return null; 63 | return _aStar.Search(from.x-_offset.x, from.y-_offset.y, to.x-_offset.x, to.y-_offset.y, walkableMap); 64 | } 65 | 66 | public void GetWalkableAreas( ) { 67 | BoundsInt bounds = walkableMap.cellBounds; 68 | 69 | for (int x = bounds.min.x; x < bounds.max.x; ++x) { 70 | for (int y = bounds.min.y; y < bounds.max.y; ++y) { 71 | Vector3Int pos = new Vector3Int(x,y,0); 72 | SetPathNode(x-bounds.min.x, y-bounds.min.y, walkableMap.HasTile(pos) && !wallMap.HasTile(pos)); 73 | } 74 | } 75 | UpdateGrid(); 76 | } 77 | 78 | private void OnEnable() { 79 | _offset = walkableMap.cellBounds.min; 80 | CreateGrid(walkableMap.cellBounds.size.x, walkableMap.cellBounds.size.y); 81 | GetWalkableAreas(); 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Pathfinding/TilemapPathFinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fec0c85166ee441c787de008dfad851f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/TilemapPathNode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2019 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEngine.Tilemaps; 27 | using Unitilities.Collections.Generic; 28 | 29 | namespace Unitilities.Pathfinding { 30 | public class TilemapPathNode : IPathNode { 31 | public int X { get; set; } 32 | public int Y { get; set; } 33 | // public bool IsWalkable(Tilemap userContext) { 34 | // return userContext.HasTile(new Vector3Int(X, Y, 0)); 35 | // } 36 | public bool Walkable {get; set;} 37 | public bool IsWalkable(Tilemap userContext) { 38 | return Walkable; 39 | } 40 | public Vector3Int position { get { return new Vector3Int(X, Y, 0); } } 41 | 42 | public float Heuristic(IPathNode toNode, Tilemap userContext) { 43 | return (Mathf.Abs(X - toNode.X) + Mathf.Abs(Y - toNode.Y)); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Pathfinding/TilemapPathNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a42e3691980cc43be9a8deb9fc22f3fc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/WeightedPathFinder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections.Generic; 27 | 28 | namespace Unitilities.Pathfinding { 29 | public class WeightedPathFinder : MonoBehaviour { 30 | 31 | public int Width = 10; 32 | public int Height = 10; 33 | 34 | private WPathNode[,] _grid; 35 | private AStar _aStar; 36 | 37 | public void CreateGrid( int width, int height ) { 38 | _grid = new WPathNode[width, height]; 39 | } 40 | 41 | public void SetPathNode( int x, int y, bool walkable ) { 42 | _grid[x, y] = new WPathNode() { 43 | Walkable = walkable, 44 | X = x, 45 | Y = y, 46 | }; 47 | } 48 | 49 | public void AddPathNode( WPathNode node ) { 50 | _grid[node.X, node.Y] = node; 51 | } 52 | 53 | public void UpdateGrid() { 54 | _aStar = new AStar(_grid); 55 | } 56 | 57 | public LinkedList FindPath( Vector2 from, Vector2 to, float[,] grid ) { 58 | return _aStar.Search(from, to, grid); 59 | } 60 | 61 | public bool IsReachable( Vector2 from, Vector2 to, int steps, float[,] grid ) { 62 | return (_aStar.Search(from, to, grid).Count <= steps); 63 | } 64 | 65 | void Test() { 66 | int w = Width, h = Height; 67 | CreateGrid(w, h); 68 | float[,] test = new float[w, h]; 69 | for (int x = 0; x < w; ++x) { 70 | for (int y = 0; y < h; ++y) { 71 | SetPathNode(x, y, true); 72 | test[x, y] = 0.1f; 73 | } 74 | } 75 | UpdateGrid(); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Pathfinding/WeightedPathFinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5aac09d2a48824ac3b4cf6442959bf95 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pathfinding/WeightedPathNode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | 28 | namespace Unitilities.Pathfinding 29 | { 30 | public class WPathNode : IPathNode { 31 | public int X { get; set; } 32 | public int Y { get; set; } 33 | public bool Walkable {get; set;} 34 | public bool IsWalkable(float[,] userContext) 35 | { 36 | return userContext[X,Y]<1f; 37 | } 38 | 39 | public float Heuristic(IPathNode toNode, float[,] userContext) { 40 | return (Mathf.Abs(X - toNode.X) + Mathf.Abs(Y - toNode.Y))*userContext[X,Y]; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Pathfinding/WeightedPathNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8353cd32203f64dd18720e7f00a57c8b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Physics.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e9bcc1c7e64d745f69306585b198c8d0 3 | folderAsset: yes 4 | timeCreated: 1430294703 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Physics/Follow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Follow : MonoBehaviour { 5 | 6 | public Transform Target = null; 7 | private Rigidbody2D _body2D = null; 8 | private Rigidbody _body = null; 9 | 10 | public float Factor = 15f; 11 | 12 | void Start() { 13 | if (_body2D == null) 14 | _body2D = GetComponent(); 15 | if (_body == null) 16 | _body = GetComponent(); 17 | } 18 | 19 | void FixedUpdate () { 20 | if (Target != null) { 21 | Vector3 distance = Target.position - transform.position; 22 | if (_body2D != null) { 23 | _body2D.velocity = distance.Vector2XY() * _body2D.drag * Factor; 24 | } 25 | if (_body != null) { 26 | _body.velocity = distance * _body.drag * Factor; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Physics/Follow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fb4dfbafed2644267b28657f8be58841 3 | timeCreated: 1430294712 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unitilities 2 | A bunch of helpful utilities for Unity. 3 | 4 | ### What have we here? 5 | 6 | Here's a short overview what's here. Be aware that this is a bunch of objects that I drag from project to project. Some of them are pretty stable. Others not so much. I'd rather use them as inspiration than for anything else. 7 | 8 | - A* implementation based on [Christoph Husse's](http://www.codeproject.com/Articles/118015/Fast-A-Star-D-Implementation-for-C) original code but greatly enhanced so that user context can be provided per search call 9 | - Three collection types: A multimap based on Microsoft's examples, a priority queue that the A* needs and a shuffle bag because all other random is unsuited for Tetris 10 | - A couple of economy simulation stubs (very much work in progress) 11 | - A TextFile asset and JSON reader 12 | - An arbitrary Graph type based on Microsoft's sample code 13 | - Integer math and integer vectors 14 | - A math parser based on [Yerzhan Kalzhani's](http://www.codeproject.com/Tips/381509/Math-Parser-NET-Csharp 15 | ) code 16 | - A cleaned up version of this [Notification Center](http://wiki.unity3d.com/index.php?title=CSharpNotificationCenter) 17 | - A neural network implementation 18 | - Realtime sound tools and examples 19 | - A couple of UI components for Unity 5's built-in UI system. Here you find dragable elements, drag areas, lines and multilines and other useful widgets 20 | - A custom asset utility for wrapping custom assets 21 | - Some helper functions to make the cloning of objects from prefabs easier 22 | 23 | 24 | ### License 25 | 26 | All files are licensed under MIT license except if otherwise noted (SimpleJSON, SpookyDNBBeat, MathParser). Feel free to copy and clone. If you use Unitilities in your games it would be great if you'd give me a shout-out. 27 | 28 | Contact me on twitter [@martinpi](http://twitter.com/martinpi) if you need help. -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 11202af95c7cd423f969dd6a880d6627 3 | timeCreated: 1428938711 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Random.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18017a297f149442b9f0286c4f41ccb5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Random/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5560952fefc9b49f29ae36831c812b17 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Random/Plugins/MarchingCubes.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 48e6c91f5a54e4f22b7023b7886a0cd0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/MarkovChain.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace Unitilities.R { 5 | public class MarkovChain { 6 | 7 | public static float[,] GetChain(int dim) { 8 | float[,] chain = new float[dim,dim]; 9 | for (int x=0; x= running_sum) 29 | running_sum += chain[column, ++i]; 30 | 31 | return i; 32 | } 33 | 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Random/Plugins/MarkovChain.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7325300bb1e064219be31af69ce82017 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/PerlinNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 98a6bbabedccf4c4c89012047a038e9d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/Permutations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Unitilities.Random { 4 | 5 | public class Permutations { 6 | public static bool NextPermutation( int[] numList ) { 7 | /* 8 | Knuths 9 | 1. Find the largest index j such that a[j] < a[j + 1]. If no such index exists, the permutation is the last permutation. 10 | 2. Find the largest index l such that a[j] < a[l]. Since j + 1 is such an index, l is well defined and satisfies j < l. 11 | 3. Swap a[j] with a[l]. 12 | 4. Reverse the sequence from a[j + 1] up to and including the final element a[n]. 13 | 14 | */ 15 | var largestIndex = -1; 16 | for (var i = numList.Length - 2; i >= 0; i--) { 17 | if (numList[i] < numList[i + 1]) { 18 | largestIndex = i; 19 | break; 20 | } 21 | } 22 | 23 | if (largestIndex < 0) 24 | return false; 25 | 26 | var largestIndex2 = -1; 27 | for (var i = numList.Length - 1; i >= 0; i--) { 28 | if (numList[largestIndex] < numList[i]) { 29 | largestIndex2 = i; 30 | break; 31 | } 32 | } 33 | 34 | var tmp = numList[largestIndex]; 35 | numList[largestIndex] = numList[largestIndex2]; 36 | numList[largestIndex2] = tmp; 37 | 38 | for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--) { 39 | tmp = numList[i]; 40 | numList[i] = numList[j]; 41 | numList[j] = tmp; 42 | } 43 | 44 | return true; 45 | } 46 | 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /Random/Plugins/Permutations.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e169e09ea9f534b9a80fae0dedf5b5db 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/Triangulator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | public class Triangulator 5 | { 6 | /* 7 | * from http://wiki.unity3d.com/index.php?title=Triangulator 8 | * 9 | // Use the triangulator to get indices for creating triangles 10 | Triangulator tr = new Triangulator(vertices2D); 11 | int[] indices = tr.Triangulate(); 12 | */ 13 | 14 | private List m_points = new List(); 15 | 16 | public Triangulator (Vector2[] points) { 17 | m_points = new List(points); 18 | } 19 | 20 | public int[] Triangulate() { 21 | List indices = new List(); 22 | 23 | int n = m_points.Count; 24 | if (n < 3) 25 | return indices.ToArray(); 26 | 27 | int[] V = new int[n]; 28 | if (Area() > 0) { 29 | for (int v = 0; v < n; v++) 30 | V[v] = v; 31 | } 32 | else { 33 | for (int v = 0; v < n; v++) 34 | V[v] = (n - 1) - v; 35 | } 36 | 37 | int nv = n; 38 | int count = 2 * nv; 39 | for (int m = 0, v = nv - 1; nv > 2; ) { 40 | if ((count--) <= 0) 41 | return indices.ToArray(); 42 | 43 | int u = v; 44 | if (nv <= u) 45 | u = 0; 46 | v = u + 1; 47 | if (nv <= v) 48 | v = 0; 49 | int w = v + 1; 50 | if (nv <= w) 51 | w = 0; 52 | 53 | if (Snip(u, v, w, nv, V)) { 54 | int a, b, c, s, t; 55 | a = V[u]; 56 | b = V[v]; 57 | c = V[w]; 58 | indices.Add(a); 59 | indices.Add(b); 60 | indices.Add(c); 61 | m++; 62 | for (s = v, t = v + 1; t < nv; s++, t++) 63 | V[s] = V[t]; 64 | nv--; 65 | count = 2 * nv; 66 | } 67 | } 68 | 69 | indices.Reverse(); 70 | return indices.ToArray(); 71 | } 72 | 73 | private float Area () { 74 | int n = m_points.Count; 75 | float A = 0.0f; 76 | for (int p = n - 1, q = 0; q < n; p = q++) { 77 | Vector2 pval = m_points[p]; 78 | Vector2 qval = m_points[q]; 79 | A += pval.x * qval.y - qval.x * pval.y; 80 | } 81 | return (A * 0.5f); 82 | } 83 | 84 | private bool Snip (int u, int v, int w, int n, int[] V) { 85 | int p; 86 | Vector2 A = m_points[V[u]]; 87 | Vector2 B = m_points[V[v]]; 88 | Vector2 C = m_points[V[w]]; 89 | if (Mathf.Epsilon > (((B.x - A.x) * (C.y - A.y)) - ((B.y - A.y) * (C.x - A.x)))) 90 | return false; 91 | for (p = 0; p < n; p++) { 92 | if ((p == u) || (p == v) || (p == w)) 93 | continue; 94 | Vector2 P = m_points[V[p]]; 95 | if (InsideTriangle(A, B, C, P)) 96 | return false; 97 | } 98 | return true; 99 | } 100 | 101 | private bool InsideTriangle (Vector2 A, Vector2 B, Vector2 C, Vector2 P) { 102 | float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy; 103 | float cCROSSap, bCROSScp, aCROSSbp; 104 | 105 | ax = C.x - B.x; ay = C.y - B.y; 106 | bx = A.x - C.x; by = A.y - C.y; 107 | cx = B.x - A.x; cy = B.y - A.y; 108 | apx = P.x - A.x; apy = P.y - A.y; 109 | bpx = P.x - B.x; bpy = P.y - B.y; 110 | cpx = P.x - C.x; cpy = P.y - C.y; 111 | 112 | aCROSSbp = ax * bpy - ay * bpx; 113 | cCROSSap = cx * apy - cy * apx; 114 | bCROSScp = bx * cpy - by * cpx; 115 | 116 | return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); 117 | } 118 | } -------------------------------------------------------------------------------- /Random/Plugins/Triangulator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b9c8b2f7490246ea8bd6ed6896ee248 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/VoronoiNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f352c8b75d7ef4452be3fac09b609850 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/VoxelChunk.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f580252c97cd40c7a567c6abcff5a9d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Random/Plugins/WorleyNoise.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36174ab0db2504c2ea9897ab3776086b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Rendering.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6360489e436c94765b180cdbd48df593 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Rendering/PixelTextureRenderer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2016 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | 27 | namespace Unitilities { 28 | namespace Rendering { 29 | 30 | [ExecuteInEditMode] 31 | [RequireComponent(typeof(Renderer))] 32 | public class PixelTextureRenderer : MonoBehaviour { 33 | 34 | private Texture2D _texture = null; 35 | 36 | // public Palette palette; 37 | 38 | void Awake() { 39 | // palette = GetComponent(); 40 | } 41 | 42 | public void Recreate(int width, int height) { 43 | _texture = new Texture2D(width, height); 44 | GetComponent().sharedMaterial.mainTexture = _texture; 45 | _texture.filterMode = FilterMode.Point; 46 | _texture.wrapMode = TextureWrapMode.Clamp; 47 | _texture.Apply(); 48 | } 49 | 50 | public void SetPixel(int x, int y, UnityEngine.Color color) { 51 | if (_texture != null) _texture.SetPixel(x,y,color); 52 | } 53 | 54 | // public void SetPixel(int x, int y, int index) { 55 | // if (_texture != null && palette != null) _texture.SetPixel(x,y,palette.palette[index % palette.paletteSize].ToColor()); 56 | // } 57 | 58 | public void SetPixels32(Color32[] colors) { 59 | if (_texture != null) _texture.SetPixels32(colors); 60 | } 61 | 62 | public void Clear() { 63 | int textureSize = _texture.width * _texture.height; 64 | Color32[] clear = new Color32[textureSize]; 65 | for (int i=0; i _defaultScale) { 25 | _maxUp = Mathf.Max(value, _maxUp); 26 | } else { 27 | _maxDown = Mathf.Clamp(value, 0, _maxDown); // automatically takes the minimum 28 | } 29 | } 30 | 31 | public float GetTimescaleModifier() { 32 | float timescale = _defaultScale; 33 | if (_maxUp > _defaultScale && _maxDown < _defaultScale) { 34 | timescale = (_maxUp + _maxDown) / 2f; 35 | } else { 36 | if (_maxUp > _defaultScale) { 37 | timescale = _maxUp; 38 | } 39 | if (_maxDown < _defaultScale) { 40 | timescale = _maxDown; 41 | } 42 | } 43 | _maxUp = _maxDown = _defaultScale; 44 | return timescale; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /TimeDynamics/Playtime.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 638d383220e0449bc91ee0f31ee96bd5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /TimeDynamics/PlaytimeController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using Prime31.ZestKit; 5 | 6 | namespace Unitilities.TimeDynamics { 7 | 8 | public class PlaytimeController : MonoBehaviour, ITweenTarget { 9 | 10 | private float _fixedDeltaTime; 11 | private float _timeScale = 1f; 12 | private float _defaultScale; 13 | 14 | // FPS tracking 15 | public float _updateRateSeconds = 4f; 16 | private int _frameCount = 0; 17 | private float _dt = 0f; 18 | private float _fps = 0f; 19 | 20 | private Playtime _playtime; 21 | 22 | public void setTweenedValue(float value) { 23 | SetTimeScale(value); 24 | _playtime.SetTimescaleModifier(value); 25 | } 26 | public float getTweenedValue() { 27 | return _timeScale; 28 | } 29 | public object getTargetObject() { 30 | return this; 31 | } 32 | public void AddBounce(float duration, float timeScale = 0f, EaseType easeType = EaseType.ElasticOut) { 33 | SetTimeScale(timeScale); 34 | new FloatTween(this, _timeScale, _defaultScale, duration) 35 | .setIsTimeScaleIndependent() 36 | .start(); 37 | } 38 | public void AddFreeze(float duration, float timeScale = 0f) { 39 | SetTimeScale(timeScale); 40 | new FloatTween(this, _timeScale, _timeScale, duration) 41 | .setIsTimeScaleIndependent() 42 | .setContext( this ) 43 | .setCompletionHandler( tween => { 44 | var self = (PlaytimeController)tween.context; 45 | self.Reset(); 46 | } ) 47 | .start(); 48 | } 49 | public void AddFreezeFrames(int frames, float timeScale = 0f) { 50 | float duration = 1f / _fps * (float)frames; 51 | AddFreeze(duration, timeScale); 52 | } 53 | 54 | private void Reset() { 55 | UnityEngine.Time.timeScale = _timeScale = _defaultScale; 56 | _playtime.Reset(_defaultScale); 57 | } 58 | 59 | private void SetTimeScale(float value) { 60 | _timeScale = Mathf.Clamp(value, 0.0001f, 100f); 61 | } 62 | private void ApplyTimeScale(float timeScale) { 63 | UnityEngine.Time.timeScale = timeScale; 64 | UnityEngine.Time.fixedDeltaTime = _fixedDeltaTime * UnityEngine.Time.timeScale; 65 | } 66 | void Awake() { 67 | _fixedDeltaTime = UnityEngine.Time.fixedDeltaTime; 68 | _defaultScale = UnityEngine.Time.timeScale; 69 | _playtime = new Playtime(_defaultScale); 70 | } 71 | private void LateUpdate() { 72 | ApplyTimeScale(_playtime.GetTimescaleModifier()); 73 | // GraphDbg.Log(Time.timeScale); 74 | } 75 | 76 | 77 | 78 | void Update() { 79 | // if (Input.GetKeyDown(KeyCode.A)) AddBounce(2f, 2f); 80 | // if (Input.GetKeyDown(KeyCode.S)) AddBounce(1f, 0.3f, EaseType.BounceIn); 81 | // if (Input.GetKeyDown(KeyCode.D)) AddBounce(0.05f, 0.3f, EaseType.QuintInOut); 82 | 83 | // if (Input.GetKeyDown(KeyCode.Q)) AddFreeze(2f, 2f); 84 | // if (Input.GetKeyDown(KeyCode.W)) AddFreeze(1f, 0.3f); 85 | // if (Input.GetKeyDown(KeyCode.E)) AddFreeze(0.05f); 86 | 87 | // if (Input.GetKeyDown(KeyCode.Z)) AddFreezeFrames(60, 2f); 88 | // if (Input.GetKeyDown(KeyCode.X)) AddFreezeFrames(30, 0.3f); 89 | // if (Input.GetKeyDown(KeyCode.C)) AddFreezeFrames(10); 90 | 91 | 92 | 93 | _frameCount++; 94 | _dt += UnityEngine.Time.unscaledDeltaTime; 95 | if (_dt > 1.0 / _updateRateSeconds) { 96 | _fps = _frameCount / _dt; 97 | _frameCount = 0; 98 | _dt -= 1.0F / _updateRateSeconds; 99 | } 100 | 101 | _playtime.SetTimescaleModifier(_timeScale); 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /TimeDynamics/PlaytimeController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c670f23e4684a40b78300f30f563b6fe 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32b7aadc0610d4ecea41b8e9c544434b 3 | folderAsset: yes 4 | timeCreated: 1428938711 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /UI/DragArea.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 10186f1bb16cf4c318b2fe6a07f46545 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /UI/DragHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | Based on this tutorial: https://www.youtube.com/watch?v=c47QYgsJrWc&app=desktop 25 | */ 26 | 27 | using UnityEngine; 28 | using UnityEngine.EventSystems; 29 | 30 | namespace Unitilities.UI { 31 | public class DragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { 32 | 33 | public static GameObject DraggedObject = null; 34 | 35 | private Vector3 _offset; 36 | private Vector3 _originalPosition; 37 | private Transform _originalParent = null; 38 | 39 | public void OnBeginDrag(PointerEventData eventData) { 40 | DraggedObject = gameObject; 41 | Vector2 ppos = eventData.position; 42 | _offset = new Vector3(ppos.x - transform.position.x, 43 | ppos.y - transform.position.y, 44 | 0); 45 | _originalPosition = transform.position; 46 | _originalParent = transform.parent; 47 | 48 | transform.SetParent(transform.root); 49 | 50 | GetComponent().blocksRaycasts = false; 51 | } 52 | public void OnDrag(PointerEventData eventData) { 53 | transform.position = Input.mousePosition - _offset; 54 | } 55 | public void OnEndDrag(PointerEventData eventData) { 56 | DraggedObject = null; 57 | 58 | if (transform.parent == transform.root) { 59 | transform.SetParent(_originalParent); 60 | transform.position = _originalPosition; 61 | } 62 | GetComponent().blocksRaycasts = true; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /UI/DragHandler.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: caeabcc6aa9f54a4aa7e03b3316c06dd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI/DragSensor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEngine.UI; 6 | using UnityEngine.EventSystems; 7 | using UnityEngine.Events; 8 | using UnityEngine.Serialization; 9 | 10 | namespace Unitilities.UI { 11 | 12 | [AddComponentMenu("UI/Drag Sensor", 55)] 13 | [RequireComponent(typeof(RectTransform))] 14 | public class DragSensor : MonoBehaviour { 15 | 16 | public bool activateOnAwake = false; 17 | 18 | private RectTransform _rect = null; 19 | private Draggable[] _allDraggables; 20 | private List _insideDraggables = new List(); 21 | 22 | [Serializable] 23 | public class DragEvent : UnityEvent { } 24 | public DragEvent onDropped = new DragEvent(); 25 | public DragEvent onOver = new DragEvent(); 26 | public DragEvent onEnter = new DragEvent(); 27 | public DragEvent onExit = new DragEvent(); 28 | 29 | private bool IsInside(Vector2 point) { 30 | return _rect.rect.Contains(point - _rect.anchoredPosition); 31 | } 32 | 33 | private void OnDrag(Draggable d) { 34 | if (IsInside(d.GetComponent().anchoredPosition)) { 35 | onOver.Invoke(d, this); 36 | if (!_insideDraggables.Contains(d)) { 37 | _insideDraggables.Add(d); 38 | onEnter.Invoke(d, this); 39 | } 40 | } else { 41 | if (_insideDraggables.Contains(d)) { 42 | _insideDraggables.Remove(d); 43 | onExit.Invoke(d, this); 44 | } 45 | } 46 | } 47 | private void OnDrop(Draggable d) { 48 | if (IsInside(d.GetComponent().anchoredPosition)) { 49 | onDropped.Invoke(d, this); 50 | if (_insideDraggables.Contains(d)) 51 | _insideDraggables.Remove(d); 52 | } 53 | } 54 | 55 | public void ActivateSensor() { 56 | _allDraggables = FindObjectsOfType(); 57 | foreach (Draggable d in _allDraggables) { 58 | d.onDrag.AddListener(OnDrag); 59 | d.onEndDrag.AddListener(OnDrop); 60 | } 61 | } 62 | public void DeactivateSensor() { 63 | foreach (Draggable d in _allDraggables) { 64 | d.onDrag.RemoveListener(OnDrag); 65 | d.onEndDrag.RemoveListener(OnDrop); 66 | } 67 | } 68 | 69 | private void Awake() { 70 | _rect = gameObject.GetComponent(); 71 | if (activateOnAwake) 72 | ActivateSensor(); 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /UI/DragSensor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df4854dece36a49cd8423216d4e688d5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI/DragWell.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | Based on this tutorial: https://www.youtube.com/watch?v=c47QYgsJrWc&app=desktop 25 | */ 26 | 27 | using UnityEngine; 28 | using UnityEngine.UI; 29 | using UnityEngine.EventSystems; 30 | 31 | namespace Unitilities.UI { 32 | public class DragWell : MonoBehaviour, IDropHandler { 33 | 34 | public GameObject Draggable { get { if (transform.childCount > 0) return transform.GetChild(0).gameObject; else return null; } } 35 | 36 | #region IDropHandler implementation 37 | public void OnDrop(PointerEventData eventData) { 38 | if (Draggable == null) { 39 | DragHandler.DraggedObject.transform.SetParent(transform, true); 40 | ExecuteEvents.ExecuteHierarchy(gameObject, null, (x, y) => { x.HasChanged(y); }); 41 | } 42 | } 43 | #endregion 44 | } 45 | } -------------------------------------------------------------------------------- /UI/DragWell.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c6d9f8c3e49b424cbc3e1720e74c5c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI/Draggable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | 2019: Rewrote based on https://forum.unity.com/threads/drag-window-script-with-window-clamped-within-canvas.453340/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | using System; 28 | using UnityEngine; 29 | using UnityEngine.UI; 30 | using UnityEngine.EventSystems; 31 | using UnityEngine.Events; 32 | using UnityEngine.Serialization; 33 | 34 | namespace Unitilities.UI { 35 | 36 | [AddComponentMenu("UI/Draggable", 55)] 37 | [RequireComponent(typeof(RectTransform))] 38 | public class Draggable : Selectable, IBeginDragHandler, IDragHandler, IEndDragHandler { 39 | 40 | private RectTransform _rect = null; 41 | private RectTransform _parentRect = null; 42 | 43 | private Vector2 _offset = Vector2.zero; 44 | 45 | [Serializable] 46 | public class DragEvent : UnityEvent { } 47 | public DragEvent onDrag = new DragEvent(); 48 | public DragEvent onBeginDrag = new DragEvent(); 49 | public DragEvent onEndDrag = new DragEvent(); 50 | 51 | protected override void Start() { 52 | _parentRect = transform.parent.GetComponent(); 53 | _rect = gameObject.GetComponent(); 54 | } 55 | 56 | public void OnBeginDrag(PointerEventData eventData) { 57 | RectTransformUtility.ScreenPointToLocalPointInRectangle(_rect, eventData.position, eventData.pressEventCamera, out _offset); 58 | onBeginDrag.Invoke(this); 59 | } 60 | public void OnEndDrag(PointerEventData eventData) { 61 | onEndDrag.Invoke(this); 62 | } 63 | public void OnDrag(PointerEventData eventData) { 64 | Vector2 localPointerPosition; 65 | if (RectTransformUtility.ScreenPointToLocalPointInRectangle(_parentRect, eventData.position, eventData.pressEventCamera, out localPointerPosition)) { 66 | 67 | Vector2 clampedPosition = localPointerPosition - _offset; 68 | // clampedPosition.x = (ParentRect.rect.width * 0.5f) - (HandleRect.rect.width * (1 - HandleRect.pivot.x)); 69 | // clampedPosition.x = (-ParentRect.rect.width * 0.5f) + (HandleRect.rect.width * HandleRect.pivot.x); 70 | // clampedPosition.y = (ParentRect.rect.height * 0.5f) - (HandleRect.rect.height * (1 - HandleRect.pivot.y)); 71 | // clampedPosition.y = (-ParentRect.rect.height * 0.5f) + (HandleRect.rect.height * HandleRect.pivot.y); 72 | 73 | _rect.localPosition = clampedPosition; 74 | } 75 | 76 | onDrag.Invoke(this); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /UI/Draggable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 855ee0d12a4f7414a90c66d5c8421279 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /UI/Hexagon.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEngine.UI; 27 | using System.Collections.Generic; 28 | 29 | namespace Unitilities.UI { 30 | 31 | [AddComponentMenu("UI/Hexagon", 56)] 32 | [RequireComponent(typeof(RectTransform))] 33 | [ExecuteInEditMode] 34 | public class Hexagon : Graphic { 35 | protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs) { 36 | UIVertex[] vbo = new UIVertex[4]; 37 | for (int i = 0; i < vertices.Length; i++) { 38 | var vert = UIVertex.simpleVert; 39 | vert.color = color; 40 | vert.position = vertices[i]; 41 | vert.uv0 = uvs[i]; 42 | vbo[i] = vert; 43 | } 44 | return vbo; 45 | } 46 | 47 | protected override void OnPopulateMesh(VertexHelper vh) { 48 | 49 | float r = rectTransform.rect.width / 2f; 50 | float h = Mathf.Sin(2f * Mathf.PI / 6f) * 2f * r; 51 | float t = h / 2f; 52 | 53 | float rr = 0.5f; 54 | float p = h / 2f - rr; 55 | float s = 3f / 2f * rr; 56 | Vector2[] uv = new Vector2[] { 57 | new Vector2(2f * rr - s, p), 58 | new Vector2(0f, rr), 59 | new Vector2(2f * rr - s, 2f * rr - p), 60 | new Vector2(s, 2f * rr - p), 61 | new Vector2(1f, rr), 62 | new Vector2(s, p) 63 | }; 64 | 65 | Vector2[] verts = new Vector2[] { 66 | new Vector2(-r/2f, -t), 67 | new Vector2(-r, 0f), 68 | new Vector2(-r/2f, t), 69 | new Vector2( r/2f, t), 70 | new Vector2( r, 0f), 71 | new Vector2( r/2f, -t) 72 | }; 73 | 74 | vh.Clear(); 75 | vh.AddUIVertexQuad(SetVbo( 76 | new[] { verts[0], verts[1], verts[2], verts[3] }, 77 | new[] { uv[0], uv[1], uv[2], uv[3] })); 78 | vh.AddUIVertexQuad(SetVbo( 79 | new[] { verts[0], verts[3], verts[4], verts[5] }, 80 | new[] { uv[0], uv[3], uv[4], uv[5] })); 81 | 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /UI/Hexagon.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 457ca6cd309e842239c160e5b8f26bf9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI/IHasChanged.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | Based on this tutorial: https://www.youtube.com/watch?v=c47QYgsJrWc&app=desktop 25 | */ 26 | 27 | using UnityEngine; 28 | using UnityEngine.EventSystems; 29 | 30 | namespace UnityEngine.EventSystems { 31 | public interface IHasChanged : IEventSystemHandler { 32 | void HasChanged(BaseEventData data); 33 | } 34 | } 35 | 36 | /* 37 | * Implement like this: 38 | public void HasChanged(BaseEventData data) { 39 | 40 | } 41 | 42 | Fire like this: 43 | ExecuteEvents.ExecuteHierarchy(gameObject, null, (x,y) => { x.HasChanged(y); } ); 44 | 45 | */ -------------------------------------------------------------------------------- /UI/IHasChanged.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d533671af92942e8b31dc87a3899d4d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI/ImageAsLine.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using System.Collections; 27 | 28 | namespace Unitilities.UI { 29 | 30 | [RequireComponent(typeof(RectTransform))] 31 | [ExecuteInEditMode] 32 | public class ImageAsLine : MonoBehaviour { 33 | 34 | [SerializeField] 35 | public GameObject Source = null; 36 | [SerializeField] 37 | public GameObject Destination = null; 38 | 39 | public float Width = 1f; 40 | 41 | void Update() { 42 | if (Source == null || Destination == null) return; 43 | 44 | RectTransform rectTransform = GetComponent(); 45 | Vector3 differenceVector = Destination.transform.position - Source.transform.position; 46 | rectTransform.sizeDelta = new Vector2(differenceVector.magnitude, Width); 47 | rectTransform.pivot = new Vector2(0, 0.5f); 48 | rectTransform.position = Source.transform.position; 49 | float angle = Mathf.Atan2(differenceVector.y, differenceVector.x) * Mathf.Rad2Deg; 50 | rectTransform.rotation = Quaternion.Euler(0, 0, angle); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /UI/ImageAsLine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ebe15d561a1040b3b24d622a90f208e 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /UI/Line.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEngine.UI; 27 | using System.Collections.Generic; 28 | 29 | namespace Unitilities.UI { 30 | 31 | [AddComponentMenu("UI/Line", 56)] 32 | [RequireComponent (typeof (RectTransform))] 33 | [ExecuteInEditMode] 34 | public class Line : Graphic { 35 | public float Width = 1f; 36 | 37 | protected override void OnPopulateMesh(VertexHelper vh) { 38 | Vector2 corner1 = Vector2.zero; 39 | Vector2 corner2 = Vector2.one; 40 | 41 | corner1.x -= rectTransform.pivot.x; 42 | corner1.y -= rectTransform.pivot.y; 43 | corner2.x -= rectTransform.pivot.x; 44 | corner2.y -= rectTransform.pivot.y; 45 | 46 | corner1.x *= rectTransform.rect.width; 47 | corner1.y *= rectTransform.rect.height; 48 | corner2.x *= rectTransform.rect.width; 49 | corner2.y *= rectTransform.rect.height; 50 | 51 | Vector2 normal = (corner2 - corner1).normalized; 52 | 53 | var uv = new Vector4(0f, 0f, 1f, 1f); 54 | 55 | var color32 = color; 56 | 57 | vh.AddVert(new Vector3(corner1.x + normal.y * Width / 2f, corner1.y - normal.x * Width / 2f), color32, new Vector2(uv.x, uv.y)); 58 | vh.AddVert(new Vector3(corner1.x - normal.y * Width / 2f, corner1.y + normal.x * Width / 2f), color32, new Vector2(uv.x, uv.w)); 59 | vh.AddVert(new Vector3(corner2.x - normal.y * Width / 2f, corner2.y + normal.x * Width / 2f), color32, new Vector2(uv.z, uv.w)); 60 | vh.AddVert(new Vector3(corner2.x + normal.y * Width / 2f, corner2.y - normal.x * Width / 2f), color32, new Vector2(uv.z, uv.y)); 61 | 62 | vh.AddTriangle(0, 1, 2); 63 | vh.AddTriangle(2, 3, 0); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /UI/Line.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84072d9925bed4fe5bb1fd7f953ac39a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /UI/MultiDragArea.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cbc8da92a15354eb888bab2b2ac81c41 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /UI/MultiLine.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEngine.UI; 27 | using System.Collections.Generic; 28 | using System.Collections; 29 | 30 | namespace Unitilities.UI { 31 | 32 | 33 | [AddComponentMenu("UI/MultiLine", 57)] 34 | [RequireComponent(typeof(RectTransform))] 35 | [ExecuteInEditMode] 36 | public class MultiLine : Graphic { 37 | public float Width = 1f; 38 | 39 | [SerializeField] 40 | public List Points; 41 | 42 | protected override void OnPopulateMesh(VertexHelper vh) { 43 | vh.Clear(); 44 | UIVertex vert = UIVertex.simpleVert; 45 | 46 | for (int i = 1; i < Points.Count; ++i) { 47 | 48 | Vector2 corner1 = Points[i - 1]; 49 | Vector2 corner2 = Points[i]; 50 | 51 | Vector2 normal = (corner2 - corner1).normalized; 52 | 53 | vert.position = new Vector2(corner1.x + normal.y * Width / 2f, corner1.y - normal.x * Width / 2f); 54 | vert.color = color; 55 | vh.AddVert(vert); 56 | 57 | vert.position = new Vector2(corner1.x - normal.y * Width / 2f, corner1.y + normal.x * Width / 2f); 58 | vert.color = color; 59 | vh.AddVert(vert); 60 | 61 | vert.position = new Vector2(corner2.x - normal.y * Width / 2f, corner2.y + normal.x * Width / 2f); 62 | vert.color = color; 63 | vh.AddVert(vert); 64 | 65 | vert.position = new Vector2(corner2.x + normal.y * Width / 2f, corner2.y - normal.x * Width / 2f); 66 | vert.color = color; 67 | vh.AddVert(vert); 68 | } 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /UI/MultiLine.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 85a31ac6f9be34a56ae834d602eb8218 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /UI/OnDragOver.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using UnityEngine.EventSystems; 4 | using UnityEngine.Events; 5 | using System.Collections; 6 | 7 | namespace Unitilities.UI { 8 | 9 | [RequireComponent(typeof(RectTransform))] 10 | public class OnDragOver : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { 11 | 12 | // private RectTransform m_RectTransform; 13 | // public DragAble m_TargetDragAble = null; 14 | 15 | void Awake() { 16 | // if (m_TargetDragAble != null) { 17 | // m_TargetDragAble.onDrag.AddListener(OnDrag); 18 | // } 19 | // m_RectTransform = transform as RectTransform; 20 | } 21 | 22 | public virtual void OnPointerEnter(PointerEventData data) { 23 | if (data.dragging && data.pointerDrag != null) { 24 | Debug.Log("Dragged inside: " + data.pointerDrag.name); 25 | 26 | // var currentOverGo = data.pointerCurrentRaycast.gameObject; 27 | 28 | } 29 | } 30 | public virtual void OnPointerExit(PointerEventData data) { 31 | if (data.dragging && data.pointerDrag != null) { 32 | Debug.Log("Dragged outside: " + data.pointerDrag.name); 33 | } 34 | 35 | } 36 | 37 | 38 | // protected virtual void OnDrag(Vector2 location) { 39 | // Debug.Log(location); 40 | // 41 | // Vector3 localLocation = (m_RectTransform.worldToLocalMatrix * location.Vector3XY()); 42 | // 43 | // if (m_RectTransform.rect.Contains(localLocation.Vector2XY())) 44 | // Debug.Log("inside"); 45 | // 46 | // } 47 | 48 | void Update() { 49 | 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /UI/OnDragOver.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dc9950cd384324f8d99dd0f3e7b66003 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /UI/PercentButton.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2015 Martin Pichlmair 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEngine.UI; 27 | using System.Collections; 28 | 29 | namespace Unitilities.UI { 30 | 31 | public class PercentButton : MonoBehaviour { 32 | 33 | private Text _label; 34 | private Image _image; 35 | 36 | public bool ActivateOnFull = false; 37 | 38 | private float _percent = 0f; 39 | public float Percent { 40 | get { return _percent; } 41 | set { SetPercent(value); } 42 | } 43 | 44 | void Start() { 45 | _label = transform.Find("Percent").GetComponent(); 46 | _image = gameObject.GetComponent(); 47 | 48 | CheckInteractive(); 49 | 50 | gameObject.GetComponent