Added Feel plugin

This commit is contained in:
journaliciouz
2025-12-11 14:49:16 +01:00
parent 97dce4aaf6
commit 1942a531d4
2820 changed files with 257786 additions and 9 deletions

View File

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

View File

@@ -0,0 +1,111 @@
using UnityEngine;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this class to a line renderer and it'll add control points that let you turn your line into a bezier curve
/// </summary>
[ExecuteAlways]
[RequireComponent(typeof(LineRenderer))]
[AddComponentMenu("More Mountains/Tools/Sprites/MM Bezier Line Renderer")]
public class MMBezierLineRenderer : MonoBehaviour
{
/// a list of handles to control your line. Usually 4, but you can have more.
public Transform[] AdjustmentHandles;
/// the amount of segments of the line renderer (more segments, less visible straight lines)
public int NumberOfSegments = 50;
/// the sorting layer for this line renderer
public string SortingLayerName = "Default";
/// the amount of curves we're working with
[MMReadOnly]
public int NumberOfCurves = 0;
protected int _sortingLayerID;
protected LineRenderer _lineRenderer;
protected Vector3 _point;
protected Vector3 _p;
protected bool _initialized = false;
/// <summary>
/// On Awake we initialize our line renderer
/// </summary>
protected virtual void Awake()
{
Initialization();
}
/// <summary>
/// Grabs the sorting layer, computes the amount of curves
/// </summary>
protected virtual void Initialization()
{
if (_initialized)
{
return;
}
_sortingLayerID = SortingLayer.NameToID(SortingLayerName);
NumberOfCurves = (int)AdjustmentHandles.Length / 3;
_lineRenderer = GetComponent<LineRenderer>();
if (_lineRenderer != null)
{
_lineRenderer.sortingLayerID = _sortingLayerID;
}
_initialized = true;
}
/// <summary>
/// On Update we draw our curve
/// </summary>
protected virtual void LateUpdate()
{
DrawCurve();
}
/// <summary>
/// For each point, determines the bezier position and feeds it to the line renderer
/// </summary>
protected virtual void DrawCurve()
{
for (int i = 0; i < NumberOfCurves; i++)
{
for (int j = 1; j <= NumberOfSegments; j++)
{
float t = (j - 1) / (float)(NumberOfSegments - 1);
int pointIndex = i * 3;
_point = BezierPoint(t, AdjustmentHandles[pointIndex].position, AdjustmentHandles[pointIndex + 1].position, AdjustmentHandles[pointIndex + 2].position, AdjustmentHandles[pointIndex + 3].position);
_lineRenderer.positionCount = (i * NumberOfSegments) + j;
_lineRenderer.SetPosition((i * NumberOfSegments) + (j - 1), _point);
}
}
}
/// <summary>
/// Computes the coordinates of a point on the bezier curve controlled by p0, p1, p2 and p3
/// </summary>
/// <param name="t"></param>
/// <param name="p0"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <returns></returns>
protected virtual Vector3 BezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
{
float u = 1 - t;
float tt = t * t;
float uu = u * u;
float uuu = uu * u;
float ttt = tt * t;
_p = uuu * p0;
_p += 3 * uu * t * p1;
_p += 3 * u * tt * p2;
_p += ttt * p3;
return _p;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 177926c7a52cdb247b4ea692ea51aa68
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMSprites/BezierLineRenderer/MMBezierLineRenderer.cs
uploadId: 830868

View File

@@ -0,0 +1,117 @@
using UnityEngine;
using System.Collections;
namespace MoreMountains.Tools
{
[RequireComponent(typeof(SpriteRenderer))]
/// <summary>
/// Add this component to an object to have it pick a new order in layer on start, useful to have unique sorting layer numbers
/// </summary>
[AddComponentMenu("More Mountains/Tools/Sprites/MM Auto Order In Layer")]
public class MMAutoOrderInLayer : MonoBehaviour
{
static int CurrentMaxCharacterOrderInLayer = 0;
[Header("Global Counter")]
[MMInformation("Add this component to an object with a sprite renderer, and it'll give it a new order in layer based on the settings defined here. First is the global counter increment, or how much you'd like to increment the layer order between two objects on that same layer.",MoreMountains.Tools.MMInformationAttribute.InformationType.Info,false)]
/// the number by which to increment each new object's order in layer
public int GlobalCounterIncrement = 5;
[Header("Parent")]
[MMInformation("You can also decide to determine the new layer order based on the parent sprite's order (it'll have to be on the same layer).",MoreMountains.Tools.MMInformationAttribute.InformationType.Info,false)]
/// if this is true, the new order in layer value will be based on the highest order value found on a parent with a similar sorting layer
public bool BasedOnParentOrder = false;
/// if BasedOnParentOrder is true, the new value will be the parent's order value + this value
public int ParentIncrement = 1;
[Header("Children")]
[MMInformation("And here you can decide to apply your new layer order to all children.",MoreMountains.Tools.MMInformationAttribute.InformationType.Info,false)]
/// if this is true, the new order value will be passed to all children with a similar sorting layer
public bool ApplyNewOrderToChildren = false;
/// the value by which the new order value should be incremented to pass it to children
public int ChildrenIncrement = 0;
protected SpriteRenderer _spriteRenderer;
/// <summary>
/// On Start, we get our sprite renderer and determine the new order in layer
/// </summary>
protected virtual void Start()
{
Initialization();
AutomateLayerOrder();
}
/// <summary>
/// Gets the sprite renderer component and stores it
/// </summary>
protected virtual void Initialization()
{
_spriteRenderer = GetComponent<SpriteRenderer>();
}
/// <summary>
/// Picks a new order in layer based on the inspector's settings
/// </summary>
protected virtual void AutomateLayerOrder()
{
int newOrder = 0;
// if there's no sprite renderer on this object, we do nothing and exit
if (_spriteRenderer == null)
{
return;
}
// if we're supposed to base our new order in layer value on the parent's value
if (BasedOnParentOrder)
{
int maxLayerOrder = 0;
Component[] spriteRenderers = GetComponentsInParent( typeof(SpriteRenderer) );
// we look for all sprite renderers in parent objects
if( spriteRenderers != null )
{
foreach( SpriteRenderer spriteRenderer in spriteRenderers )
{
// if we find a parent with a sprite renderer, on the same sorting layer and with a higher sorting value than previously found
if ( (spriteRenderer.sortingLayerID == _spriteRenderer.sortingLayerID)
&& (spriteRenderer.sortingOrder > maxLayerOrder))
{
// we store the new value
maxLayerOrder = spriteRenderer.sortingOrder;
}
}
// we set our new value to the highest value found, plus our increment
newOrder = maxLayerOrder + ParentIncrement;
}
}
else
{
// if we're not based on parent, we base our pick on the current max order in layer
newOrder = CurrentMaxCharacterOrderInLayer + GlobalCounterIncrement;
// we increment the global order index
CurrentMaxCharacterOrderInLayer += GlobalCounterIncrement;
}
// we apply our new order value
_spriteRenderer.sortingOrder = newOrder;
// if we need to apply that new value to all children, we do it
if (ApplyNewOrderToChildren)
{
Component[] childrenSpriteRenderers = GetComponentsInChildren( typeof(SpriteRenderer) );
if( childrenSpriteRenderers != null )
{
foreach( SpriteRenderer childSpriteRenderer in childrenSpriteRenderers )
{
if (childSpriteRenderer.sortingLayerID == _spriteRenderer.sortingLayerID)
{
childSpriteRenderer.sortingOrder = newOrder + ChildrenIncrement;
}
}
}
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: aeb67f1f5c67282488b877818e410f30
timeCreated: 1523894079
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMSprites/MMAutoOrderInLayer.cs
uploadId: 830868

View File

@@ -0,0 +1,175 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
[RequireComponent(typeof(LineRenderer))]
public class MMLineRendererCircle : MonoBehaviour
{
/// the possible axis
public enum DrawAxis { X, Y, Z };
[Header("Draw Axis")]
/// the axis on which to draw the circle
[Tooltip("the axis on which to draw the circle")]
public DrawAxis Axis = DrawAxis.Z;
/// the distance by which to push the circle on the draw axis
[Tooltip("the distance by which to push the circle on the draw axis")]
public float NormalOffset = 0;
[Header("Geometry")]
/// the amount of segments on the line renderer. More segments, more smoothness, more performance cost
[Tooltip("the amount of segments on the line renderer. More segments, more smoothness, more performance cost")]
[Range(0, 2000)]
public int PositionsCount = 60;
[Header("Shape")]
/// the length of the circle's horizontal radius
[Tooltip("the length of the circle's horizontal radius")]
public float HorizontalRadius = 10;
/// the length of the circle's vertical radius
[Tooltip("the length of the circle's vertical radius")]
public float VerticalRadius = 10;
[Header("Debug")]
/// if this is true, the circle will be redrawn every time you change a value in the inspector, otherwise you'll have to call the DrawCircle method (or press the debug button below)
[Tooltip("if this is true, the circle will be redrawn every time you change a value in the inspector, otherwise you'll have to call the DrawCircle method (or press the debug button below)")]
public bool AutoRedrawOnValuesChange = false;
/// a test button used to call the DrawCircle method
[MMInspectorButton("DrawCircle")]
public bool DrawCircleButton;
protected LineRenderer _line;
protected Vector3 _newPosition;
protected float _angle, _x, _y, _z;
/// <summary>
/// On Awake we initialize our line renderer and draw our circle
/// </summary>
protected virtual void Awake()
{
Initialization();
DrawCircle();
}
/// <summary>
/// Grabs the line renderer and sets it up
/// </summary>
protected virtual void Initialization()
{
_line = gameObject.GetComponent<LineRenderer>();
_line.positionCount = PositionsCount + 1;
_line.useWorldSpace = false;
}
/// <summary>
/// Sets all point positions for our line renderer
/// </summary>
public virtual void DrawCircle()
{
_angle = 0f;
_z = NormalOffset;
switch(Axis)
{
case DrawAxis.X:
DrawCircleX();
break;
case DrawAxis.Y:
DrawCircleY();
break;
case DrawAxis.Z:
DrawCircleZ();
break;
}
}
/// <summary>
/// Computes the x position of the new point
/// </summary>
/// <returns></returns>
protected virtual float ComputeX()
{
return Mathf.Cos (Mathf.Deg2Rad * _angle) * HorizontalRadius;
}
/// <summary>
/// Computes the y position of the new point
/// </summary>
/// <returns></returns>
protected virtual float ComputeY()
{
return Mathf.Sin (Mathf.Deg2Rad * _angle) * VerticalRadius;
}
/// <summary>
/// Draws a circle on the x axis
/// </summary>
protected virtual void DrawCircleX()
{
for (int i = 0; i < (PositionsCount + 1); i++)
{
_x = ComputeX();
_y = ComputeY();
_newPosition.x = _z;
_newPosition.y = _y;
_newPosition.z = _x;
_line.SetPosition(i, _newPosition);
_angle += (360f / PositionsCount);
}
}
/// <summary>
/// Draws a circle on the y axis
/// </summary>
protected virtual void DrawCircleY()
{
for (int i = 0; i < (PositionsCount + 1); i++)
{
_x = ComputeX();
_y = ComputeY();
_newPosition.x = _y;
_newPosition.y = _z;
_newPosition.z = _x;
_line.SetPosition(i, _newPosition);
_angle += (360f / PositionsCount);
}
}
/// <summary>
/// Draws a circle on the z axis
/// </summary>
protected virtual void DrawCircleZ()
{
for (int i = 0; i < (PositionsCount + 1); i++)
{
_x = ComputeX();
_y = ComputeY();
_newPosition.x = _x;
_newPosition.y = _y;
_newPosition.z = _z;
_line.SetPosition(i, _newPosition);
_angle += (360f / PositionsCount);
}
}
/// <summary>
/// On Validate we redraw our circle if needed
/// </summary>
protected virtual void OnValidate()
{
if (AutoRedrawOnValuesChange)
{
DrawCircle();
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: afc6104c5fc7fe244bf333c8d59aaa10
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMSprites/MMLineRendererCircle.cs
uploadId: 830868

View File

@@ -0,0 +1,95 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This component, added to a line renderer, will let you fill a list of transforms, and bind their positions to the linerenderer's positions.
/// </summary>
[RequireComponent(typeof(LineRenderer))]
public class MMLineRendererDriver : MonoBehaviour
{
[Header("Position Drivers")]
/// the list of targets - their quantity has to match the LineRenderer's positions count
public List<Transform> Targets;
/// whether or not to keep both in sync at update
public bool BindPositionsToTargetsAtUpdate = true;
[Header("Binding")]
/// a test button
[MMInspectorButton("Bind")]
public bool BindButton;
protected LineRenderer _lineRenderer;
protected bool _countsMatch = false;
/// <summary>
/// On Awake we initialize our driver
/// </summary>
protected virtual void Awake()
{
Initialization();
}
/// <summary>
/// Grabs the line renderer, tests counts
/// </summary>
protected virtual void Initialization()
{
_lineRenderer = this.gameObject.GetComponent<LineRenderer>();
_countsMatch = CheckPositionCounts();
if (!_countsMatch)
{
Debug.LogWarning(this.name + ", MMLineRendererDriver's Targets list doesn't have the same amount of entries as the LineRender's Positions array. It won't work.");
}
}
/// <summary>
/// On Update we bind our positions to targets if needed
/// </summary>
protected virtual void Update()
{
if (BindPositionsToTargetsAtUpdate)
{
BindPositionsToTargets();
}
}
/// <summary>
/// A method meant to be called by the inspector button
/// </summary>
protected virtual void Bind()
{
Initialization();
BindPositionsToTargets();
}
/// <summary>
/// Goes through all the targets and assigns their positions to the LineRenderer's positions
/// </summary>
public virtual void BindPositionsToTargets()
{
if (!_countsMatch)
{
return;
}
for (int i = 0; i < Targets.Count; i++)
{
_lineRenderer.SetPosition(i, Targets[i].position);
}
}
/// <summary>
/// Makes sure the counts match
/// </summary>
/// <returns></returns>
protected virtual bool CheckPositionCounts()
{
return Targets.Count == _lineRenderer.positionCount;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ca735d93c2b69c247951881f5d6f1be2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/MMSprites/MMLineRendererDriver.cs
uploadId: 830868