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: 9823516016a64ab4b8d13a78601b4015
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

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

View File

@@ -0,0 +1,108 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace MoreMountains.Tools
{
[CustomEditor(typeof(MMTriggerAndCollision), true)]
[CanEditMultipleObjects]
public class MMTriggerAndCollisionEditor : Editor
{
protected SerializedProperty _CollisionLayerMask;
protected SerializedProperty _OnCollisionEnterEvent;
protected SerializedProperty _OnCollisionExitEvent;
protected SerializedProperty _OnCollisionStayEvent;
protected SerializedProperty _TriggerLayerMask;
protected SerializedProperty _OnTriggerEnterEvent;
protected SerializedProperty _OnTriggerExitEvent;
protected SerializedProperty _OnTriggerStayEvent;
protected SerializedProperty _Collision2DLayerMask;
protected SerializedProperty _OnCollision2DEnterEvent;
protected SerializedProperty _OnCollision2DExitEvent;
protected SerializedProperty _OnCollision2DStayEvent;
protected SerializedProperty _Trigger2DLayerMask;
protected SerializedProperty _OnTrigger2DEnterEvent;
protected SerializedProperty _OnTrigger2DExitEvent;
protected SerializedProperty _OnTrigger2DStayEvent;
protected bool OnCollision;
protected bool OnTrigger;
protected bool OnCollision2D;
protected bool OnTrigger2D;
protected virtual void OnEnable()
{
_CollisionLayerMask = serializedObject.FindProperty("CollisionLayerMask");
_OnCollisionEnterEvent = serializedObject.FindProperty("OnCollisionEnterEvent");
_OnCollisionExitEvent = serializedObject.FindProperty("OnCollisionExitEvent");
_OnCollisionStayEvent = serializedObject.FindProperty("OnCollisionStayEvent");
_TriggerLayerMask = serializedObject.FindProperty("TriggerLayerMask");
_OnTriggerEnterEvent = serializedObject.FindProperty("OnTriggerEnterEvent");
_OnTriggerExitEvent = serializedObject.FindProperty("OnTriggerExitEvent");
_OnTriggerStayEvent = serializedObject.FindProperty("OnTriggerStayEvent");
_Collision2DLayerMask = serializedObject.FindProperty("Collision2DLayerMask");
_OnCollision2DEnterEvent = serializedObject.FindProperty("OnCollision2DEnterEvent");
_OnCollision2DExitEvent = serializedObject.FindProperty("OnCollision2DExitEvent");
_OnCollision2DStayEvent = serializedObject.FindProperty("OnCollision2DStayEvent");
_Trigger2DLayerMask = serializedObject.FindProperty("Trigger2DLayerMask");
_OnTrigger2DEnterEvent = serializedObject.FindProperty("OnTrigger2DEnterEvent");
_OnTrigger2DExitEvent = serializedObject.FindProperty("OnTrigger2DExitEvent");
_OnTrigger2DStayEvent = serializedObject.FindProperty("OnTrigger2DStayEvent");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
Undo.RecordObject(target, "Modified MMTriggerAndCollision");
OnCollision = EditorGUILayout.Foldout(OnCollision, "OnCollision");
if (OnCollision)
{
EditorGUILayout.PropertyField(_CollisionLayerMask);
EditorGUILayout.PropertyField(_OnCollisionEnterEvent);
EditorGUILayout.PropertyField(_OnCollisionExitEvent);
EditorGUILayout.PropertyField(_OnCollisionStayEvent);
}
OnTrigger = EditorGUILayout.Foldout(OnTrigger, "OnTrigger");
if (OnTrigger)
{
EditorGUILayout.PropertyField(_TriggerLayerMask);
EditorGUILayout.PropertyField(_OnTriggerEnterEvent);
EditorGUILayout.PropertyField(_OnTriggerExitEvent);
EditorGUILayout.PropertyField(_OnTriggerStayEvent);
}
OnCollision2D = EditorGUILayout.Foldout(OnCollision2D, "OnCollision2D");
if (OnCollision2D)
{
EditorGUILayout.PropertyField(_Collision2DLayerMask);
EditorGUILayout.PropertyField(_OnCollision2DEnterEvent);
EditorGUILayout.PropertyField(_OnCollision2DExitEvent);
EditorGUILayout.PropertyField(_OnCollision2DStayEvent);
}
OnTrigger2D = EditorGUILayout.Foldout(OnTrigger2D, "OnTrigger2D");
if (OnTrigger2D)
{
EditorGUILayout.PropertyField(_Trigger2DLayerMask);
EditorGUILayout.PropertyField(_OnTrigger2DEnterEvent);
EditorGUILayout.PropertyField(_OnTrigger2DExitEvent);
EditorGUILayout.PropertyField(_OnTrigger2DStayEvent);
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 58ec23fbdf517a348851de2bb297888e
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/Editor/MMActivation/MMTriggerAndCollisionEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,167 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace MoreMountains.Tools
{
/// <summary>
/// Custom editor for the MMScreenSafeZones component
/// </summary>
[CustomEditor(typeof(MMAspectRatioSafeZones), true)]
[CanEditMultipleObjects]
public class MMAspectRatioSafeZonesEditor : Editor
{
static MMAspectRatioSafeZones safeZones;
/// <summary>
/// On enable, registers to the OnSceneGUI hook
/// </summary>
void OnEnable()
{
SceneView.duringSceneGui -= OnSceneGUI;
safeZones = (MMAspectRatioSafeZones)target;
SceneView.duringSceneGui += OnSceneGUI;
}
/// <summary>
/// OnSceneGUI, draws center and ratios
/// </summary>
/// <param name="sceneView"></param>
private static void OnSceneGUI(SceneView sceneView)
{
DrawFrameCenter(sceneView);
DrawRatios(sceneView);
}
/// <summary>
/// Draws a rectangle for each ratio
/// </summary>
/// <param name="sceneView"></param>
private static void DrawRatios(SceneView sceneView)
{
if (!safeZones.DrawRatios)
{
return;
}
Vector3 center = sceneView.pivot;
float width = sceneView.position.width;
float height = sceneView.position.height;
Vector3 bottomLeft = new Vector3(center.x - width / 2f, center.y - height / 2f, 0f);
Vector3 topRight = new Vector3(center.x + width / 2f, center.y + height / 2f, 0f);
Vector3 topLeft = bottomLeft;
topLeft.y = topRight.y;
Vector3 bottomRight = topRight;
bottomRight.y = bottomLeft.y;
float size = safeZones.CameraSize;
// dotted lines
float spacing = 2f;
Color dottedLineColor = Color.white;
dottedLineColor.a = 0.4f;
Handles.color = dottedLineColor;
// top
Handles.DrawDottedLine(new Vector3(topLeft.x, center.y + size, 0f), new Vector3(topRight.x, center.y + size, 0f), spacing);
// bottom
Handles.DrawDottedLine(new Vector3(topLeft.x, center.y - size, 0f), new Vector3(topRight.x, center.y - size, 0f), spacing);
foreach (Ratio ratio in safeZones.Ratios)
{
if (ratio.DrawRatio)
{
float aspectRatio = ratio.Size.x / ratio.Size.y;
Handles.color = ratio.RatioColor;
// aspect ratio positions
Vector3 ratioTopLeft = new Vector3(center.x - size * aspectRatio, center.y + size, 0f);
Vector3 ratioTopRight = new Vector3(center.x + size * aspectRatio, center.y + size, 0f);
Vector3 ratioBottomLeft = new Vector3(center.x - size * aspectRatio, center.y - size, 0f);
Vector3 ratioBottomRight = new Vector3(center.x + size * aspectRatio, center.y - size, 0f);
Vector3 ratioLabelPosition = ratioBottomLeft + 0.1f * Vector3.down + 0.1f * Vector3.right;
// draws a label under the rectangle
GUIStyle style = new GUIStyle();
style.normal.textColor = ratio.RatioColor;
style.fontSize = 8;
Handles.Label(ratioLabelPosition, ratio.Size.x + ":" + ratio.Size.y, style);
// draws a rectangle around the aspect ratio
Vector3[] verts = new Vector3[] { ratioTopLeft, ratioTopRight, ratioBottomRight, ratioBottomLeft };
Handles.DrawSolidRectangleWithOutline(verts, new Color(0, 0, 0, 0), ratio.RatioColor);
// draws the dead zone of that ratio
Color zoneColor = ratio.RatioColor;
zoneColor.a = zoneColor.a * safeZones.UnsafeZonesOpacity;
// top rectangle
verts = new Vector3[] { topLeft, topRight, new Vector3(topLeft.x, ratioTopLeft.y, 0f), new Vector3(topRight.x, ratioTopRight.y, 0f) };
Handles.DrawSolidRectangleWithOutline(verts, zoneColor, new Color(0, 0, 0, 0));
// bottom rectangle
verts = new Vector3[] { bottomLeft, new Vector3(topLeft.x, ratioBottomLeft.y, 0f), new Vector3(topRight.x, ratioBottomRight.y, 0f), bottomRight };
Handles.DrawSolidRectangleWithOutline(verts, zoneColor, new Color(0, 0, 0, 0));
// left rectangle
verts = new Vector3[] { new Vector3(topLeft.x, ratioTopLeft.y, 0f), ratioTopLeft, ratioBottomLeft, new Vector3(bottomLeft.x, ratioBottomLeft.y, 0f) };
Handles.DrawSolidRectangleWithOutline(verts, zoneColor, new Color(0, 0, 0, 0));
// right rectangle
verts = new Vector3[] { new Vector3(topRight.x, ratioTopRight.y, 0f), new Vector3(bottomRight.x, ratioBottomRight.y, 0f), ratioBottomRight, ratioTopRight};
Handles.DrawSolidRectangleWithOutline(verts, zoneColor, new Color(0, 0, 0, 0));
// dotted line left
Handles.DrawDottedLine(new Vector3(ratioBottomLeft.x, topLeft.y, 0f), new Vector3(ratioTopLeft.x, bottomLeft.y, 0f), spacing);
// dotted line right
Handles.DrawDottedLine(new Vector3(ratioBottomRight.x, topLeft.y, 0f), new Vector3(ratioBottomRight.x, bottomLeft.y, 0f), spacing);
}
}
}
/// <summary>
/// Draws a crosshair at the center
/// </summary>
/// <param name="sceneView"></param>
private static void DrawFrameCenter(SceneView sceneView)
{
if (!safeZones.DrawCenterCrosshair)
{
return;
}
Vector3 center = sceneView.pivot;
float crossHairSize = safeZones.CenterCrosshairSize;
float reticleSize = crossHairSize / 10f;
Handles.color = safeZones.CenterCrosshairColor;
Vector3 crosshairTopLeft = new Vector3(center.x - crossHairSize / 2f, center.y + crossHairSize / 2f, 0f);
Vector3 crosshairTopRight = new Vector3(center.x + crossHairSize / 2f, center.y + crossHairSize / 2f, 0f);
Vector3 crosshairBottomLeft = new Vector3(center.x - crossHairSize / 2f, center.y - crossHairSize / 2f, 0f);
Vector3 crosshairBottomRight = new Vector3(center.x + crossHairSize / 2f, center.y - crossHairSize / 2f, 0f);
// cross
Handles.DrawLine(new Vector3(center.x, center.y + crossHairSize / 2f, 0f), new Vector3(center.x, center.y - crossHairSize / 2f, 0f));
Handles.DrawLine(new Vector3(center.x - crossHairSize / 2f, center.y, 0f), new Vector3(center.x + crossHairSize / 2f, center.y, 0f));
// top left
Handles.DrawLine(crosshairTopLeft, new Vector3(crosshairTopLeft.x + reticleSize, crosshairTopLeft.y, 0f));
Handles.DrawLine(crosshairTopLeft, new Vector3(crosshairTopLeft.x, crosshairTopLeft.y - reticleSize, 0f));
// top right
Handles.DrawLine(crosshairTopRight, new Vector3(crosshairTopRight.x - reticleSize, crosshairTopRight.y, 0f));
Handles.DrawLine(crosshairTopRight, new Vector3(crosshairTopRight.x, crosshairTopRight.y - reticleSize, 0f));
// bottom left
Handles.DrawLine(crosshairBottomLeft, new Vector3(crosshairBottomLeft.x + reticleSize, crosshairBottomLeft.y, 0f));
Handles.DrawLine(crosshairBottomLeft, new Vector3(crosshairBottomLeft.x, crosshairBottomLeft.y + reticleSize, 0f));
// bottom right
Handles.DrawLine(crosshairBottomRight, new Vector3(crosshairBottomRight.x - reticleSize, crosshairBottomRight.y, 0f));
Handles.DrawLine(crosshairBottomRight, new Vector3(crosshairBottomRight.x, crosshairBottomRight.y + reticleSize, 0f));
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3318ec2edbd59284a9d8a7371e84a33e
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/Editor/MMCamera/MMAspectRatioSafeZonesEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,134 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// A class that lets you create polygon collider 2D out of mesh filters
/// </summary>
public class MMMeshToPolygonCollider2D : MonoBehaviour
{
/// <summary>
/// Generates a PolygonCollider2D out of a meshfilter
/// </summary>
/// <param name="meshFilter"></param>
private static void GeneratePolygonCollider2D(MeshFilter meshFilter)
{
// we validate our mesh
if (!ValidateMesh(meshFilter))
{
return;
}
// we grab or create our PolygonCollider2D
PolygonCollider2D polygonCollider2D = InitializePolygonCollider2D(meshFilter);
if (polygonCollider2D == null)
{
return;
}
Vector3[] vectors = MeshFilterToVectors(meshFilter);
Vector2[] newPoints = VectorsToPoints(vectors);
EditorUtility.SetDirty(polygonCollider2D);
polygonCollider2D.SetPath(0, newPoints);
}
/// <summary>
/// Takes an array of vectors and outputs points
/// </summary>
/// <param name="vectors"></param>
/// <returns></returns>
private static Vector2[] VectorsToPoints(Vector3[] vectors)
{
List<Vector2> newColliderVertices = new List<Vector2>();
for (int i = 0; i < vectors.Length; i++)
{
newColliderVertices.Add(new Vector2(vectors[i].x, vectors[i].y));
}
Vector2[] newPoints = newColliderVertices.Distinct().ToArray();
return newPoints;
}
/// <summary>
/// Turns a meshfilter into an array of vectors
/// </summary>
/// <param name="meshFilter"></param>
/// <returns></returns>
private static Vector3[] MeshFilterToVectors(MeshFilter meshFilter)
{
List<Vector3> vertices = new List<Vector3>();
meshFilter.sharedMesh.GetVertices(vertices);
List<MMGeometry.MMEdge> boundaryPath = MMGeometry.GetEdges(meshFilter.sharedMesh.triangles).FindBoundary().SortEdges();
Vector3[] vectors = new Vector3[boundaryPath.Count];
for (int i = 0; i < boundaryPath.Count; i++)
{
vectors[i] = vertices[boundaryPath[i].Vertice1];
}
return vectors;
}
/// <summary>
/// Grabs or creates a polygon collider 2D
/// </summary>
/// <param name="meshFilter"></param>
/// <returns></returns>
private static PolygonCollider2D InitializePolygonCollider2D(MeshFilter meshFilter)
{
PolygonCollider2D polygonCollider2D = meshFilter.GetComponent<PolygonCollider2D>();
if (polygonCollider2D == null)
{
polygonCollider2D = meshFilter.gameObject.AddComponent<PolygonCollider2D>();
}
polygonCollider2D.pathCount = 1;
return polygonCollider2D;
}
/// <summary>
/// Makes sure that
/// </summary>
/// <param name="meshFilter"></param>
/// <returns></returns>
private static bool ValidateMesh(MeshFilter meshFilter)
{
if (meshFilter.sharedMesh == null)
{
Debug.LogWarning("[MMMeshToPolygonCollider2D] "
+ meshFilter.gameObject.name
+ " needs to have at least a mesh set on its mesh filter component.");
return false;
}
return true;
}
/// <summary>
/// A method meant to be called via the Tools menu, that will go through all mesh colliders on an object and generate a polygon collider2D out of it
/// </summary>
[MenuItem("Tools/More Mountains/Collisions/Generate PolygonCollider2D", false, 601)]
public static void GeneratePolygonCollider2DMenu()
{
Transform activeTransform = Selection.activeTransform;
if (activeTransform == null)
{
Debug.LogWarning("[MMMeshToPolygonCollider2D] You need to select a gameobject first.");
return;
}
EditorSceneManager.MarkSceneDirty(activeTransform.gameObject.scene);
MeshFilter[] meshFilters = activeTransform.GetComponentsInChildren<MeshFilter>();
foreach (MeshFilter meshFilter in meshFilters)
{
GeneratePolygonCollider2D(meshFilter);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: ff6c7676065e39545a4f7ccb2f5d67b8
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/Editor/MMCollisions/MMMeshToPolygonCollider2D.cs
uploadId: 830868

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: f9bd36e0fdcb17346bb804d148559eb2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/Editor/MMCurves/MMAntiCurves.curves
uploadId: 830868

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: d7ae097ceef007248a49d4df212cceb7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/Editor/MMCurves/MMCurves.curves
uploadId: 830868

View File

@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// A custom editor displaying a foldable list of MMFeedbacks, a dropdown to add more, as well as test buttons to test your feedbacks at runtime
/// </summary>
[CanEditMultipleObjects]
[CustomEditor(typeof(MMPlotter), true)]
public class MMPlotterEditor : Editor
{
protected string[] _typeDisplays;
protected string[] _excludedProperties = new string[] { "TweenMethod", "m_Script" };
protected MMPlotter _mmPlotter;
protected virtual void OnEnable()
{
_mmPlotter = target as MMPlotter;
_typeDisplays = _mmPlotter.GetMethodsList();
}
public override void OnInspectorGUI()
{
serializedObject.Update();
Undo.RecordObject(target, "Modified Plotter");
EditorGUILayout.Space();
EditorGUILayout.LabelField("Tween Method", EditorStyles.boldLabel);
_mmPlotter.TweenMethodIndex = EditorGUILayout.Popup("Tween Method", _mmPlotter.TweenMethodIndex, _typeDisplays, EditorStyles.popup);
//int newItem = EditorGUILayout.Popup(0, _typeDisplays) - 1;
//DrawDefaultInspector();
DrawPropertiesExcluding(serializedObject, _excludedProperties);
if (GUILayout.Button("Draw Graph"))
{
_mmPlotter.DrawGraph();
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 7e2bca92e67ccd243a920ed5311a183e
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/Editor/MMCurves/MMPlotterEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,43 @@
using UnityEditor;
#if MM_UI
namespace MoreMountains.Tools
{
[CanEditMultipleObjects]
[CustomEditor(typeof(MMHealthBar),true)]
/// <summary>
/// Custom editor for health bars (mostly a switch for prefab based / drawn bars
/// </summary>
public class HealthBarEditor : Editor
{
public MMHealthBar HealthBarTarget
{
get
{
return (MMHealthBar)target;
}
}
public override void OnInspectorGUI()
{
serializedObject.Update();
switch (HealthBarTarget.HealthBarType)
{
case MMHealthBar.HealthBarTypes.Prefab:
Editor.DrawPropertiesExcluding(serializedObject, new string[] {"TargetProgressBar", "NestDrawnHealthBar", "Billboard", "FollowTargetMode", "Size","BackgroundPadding", "SortingLayerName", "InitialRotationAngles", "ForegroundColor", "DelayedColor", "BorderColor", "BackgroundColor", "Delay", "LerpFrontBar", "LerpFrontBarSpeed", "LerpDelayedBar", "LerpDelayedBarSpeed", "BumpScaleOnChange", "BumpDuration", "BumpAnimationCurve" });
break;
case MMHealthBar.HealthBarTypes.Drawn:
Editor.DrawPropertiesExcluding(serializedObject, new string[] {"TargetProgressBar", "HealthBarPrefab" });
break;
case MMHealthBar.HealthBarTypes.Existing:
Editor.DrawPropertiesExcluding(serializedObject, new string[] {"HealthBarPrefab", "NestDrawnHealthBar", "Billboard", "FollowTargetMode", "Size","BackgroundPadding", "SortingLayerName", "InitialRotationAngles", "ForegroundColor", "DelayedColor", "BorderColor", "BackgroundColor", "Delay", "LerpFrontBar", "LerpFrontBarSpeed", "LerpDelayedBar", "LerpDelayedBarSpeed", "BumpScaleOnChange", "BumpDuration", "BumpAnimationCurve" });
break;
}
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0cb989d69836540e780467ed8454742c
timeCreated: 1470860033
licenseType: Store
MonoImporter:
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/Editor/MMGUI/MMHealthBarEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,391 @@
using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// a custom editor for the MMGizmo component
/// </summary>
[CustomEditor(typeof(MMGizmo), true)]
[CanEditMultipleObjects]
public class MMGizmoEditor : Editor
{
/// <summary>
/// Lets you press G when in scene view to toggle gizmos on or off
/// </summary>
[Shortcut("Toggle Gizmos", typeof(SceneView), KeyCode.G, displayName = "ToggleGizmos")]
public static void ToggleGizmos()
{
SceneView.lastActiveSceneView.drawGizmos = !SceneView.lastActiveSceneView.drawGizmos;
}
/// <summary>
/// When the target object is selected, we draw our gizmos
/// </summary>
/// <param name="mmGizmo"></param>
/// <param name="gizmoType"></param>
[DrawGizmo(GizmoType.Selected)]
private static void DrawGizmoSelected(MMGizmo mmGizmo, GizmoType gizmoType)
{
if (!mmGizmo.DisplayGizmo)
{
return;
}
DrawGizmos(mmGizmo);
}
/// <summary>
/// When the target object is not selected, we draw our gizmos if needed
/// </summary>
/// <param name="mmGizmo"></param>
/// <param name="gizmoType"></param>
[DrawGizmo(GizmoType.NonSelected)]
private static void DrawGizmoNonSelected(MMGizmo mmGizmo, GizmoType gizmoType)
{
if (!mmGizmo.DisplayGizmo)
{
return;
}
if (mmGizmo.DisplayMode != MMGizmo.DisplayModes.Always)
{
return;
}
DrawGizmos(mmGizmo);
}
/// <summary>
/// Draws gizmos and text
/// </summary>
/// <param name="mmGizmo"></param>
private static void DrawGizmos(MMGizmo mmGizmo)
{
if (!mmGizmo.Initialized)
{
Initialization(mmGizmo);
}
if (TestDistance(mmGizmo, mmGizmo.ViewDistance))
{
Gizmos.color = mmGizmo.GizmoColor;
Gizmos.matrix = mmGizmo.transform.localToWorldMatrix;
switch (mmGizmo.GizmoType)
{
case MMGizmo.GizmoTypes.Collider:
DrawColliderGizmo(mmGizmo);
break;
case MMGizmo.GizmoTypes.Position:
DrawPositionGizmo(mmGizmo);
break;
}
}
DrawText(mmGizmo);
}
/// <summary>
/// Tests whether or not gizmos should be drawn based on distance to the scene camera
/// </summary>
/// <param name="mmGizmo"></param>
/// <param name="viewDistance"></param>
/// <returns></returns>
private static bool TestDistance(MMGizmo mmGizmo, float viewDistance)
{
float distanceToCamera = 0f;
if (SceneView.currentDrawingSceneView == null)
{
distanceToCamera = Vector3.Distance(mmGizmo.transform.position, Camera.main.transform.position);
return (distanceToCamera < viewDistance);
}
else
{
distanceToCamera = Vector3.Distance(mmGizmo.transform.position, SceneView.currentDrawingSceneView.camera.transform.position);
return (distanceToCamera < viewDistance);
}
}
/// <summary>
/// On Enable we initialize our gizmo
/// </summary>
protected virtual void OnEnable()
{
Initialization(target as MMGizmo);
}
/// <summary>
/// On validate we initialize our gizmo
/// </summary>
protected void OnValidate()
{
Initialization(target as MMGizmo);
}
/// <summary>
/// Initializes the gizmo, caching components, values, and inits the GUIStyle
/// </summary>
/// <param name="mmGizmo"></param>
private static void Initialization(MMGizmo mmGizmo)
{
mmGizmo._sphereCollider = mmGizmo.gameObject.GetComponent<SphereCollider>();
mmGizmo._boxCollider = mmGizmo.gameObject.GetComponent<BoxCollider>();
mmGizmo._meshCollider = mmGizmo.gameObject.GetComponent<MeshCollider>();
#if MM_PHYSICS2D
mmGizmo._circleCollider2D = mmGizmo.gameObject.GetComponent<CircleCollider2D>();
mmGizmo._boxCollider2D = mmGizmo.gameObject.GetComponent<BoxCollider2D>();
#endif
mmGizmo._sphereColliderNotNull = (mmGizmo._sphereCollider != null);
mmGizmo._boxColliderNotNull = (mmGizmo._boxCollider != null);
mmGizmo._meshColliderNotNull = (mmGizmo._meshCollider != null);
#if MM_PHYSICS2D
mmGizmo._circleCollider2DNotNull = (mmGizmo._circleCollider2D != null);
mmGizmo._boxCollider2DNotNull = (mmGizmo._boxCollider2D != null);
#endif
mmGizmo._vector3Zero = Vector3.zero;
mmGizmo._textureRect = new Rect(0f, 0f, mmGizmo.TextureSize.x, mmGizmo.TextureSize.y);
mmGizmo._positionTextureNotNull = (mmGizmo.PositionTexture != null);
mmGizmo._textGUIStyle = new GUIStyle();
mmGizmo._textGUIStyle.normal.textColor = mmGizmo.TextColor;
mmGizmo._textGUIStyle.fontSize = mmGizmo.TextSize;
mmGizmo._textGUIStyle.fontStyle = mmGizmo.TextFontStyle;
mmGizmo._textGUIStyle.padding = new RectOffset((int)mmGizmo.TextPadding.x, (int)mmGizmo.TextPadding.y, (int)mmGizmo.TextPadding.z, (int)mmGizmo.TextPadding.w);
mmGizmo._textGUIStyle.normal.background = MMGUI.MakeTex(600, 100, mmGizmo.TextBackgroundColor);
mmGizmo.Initialized = true;
}
/// <summary>
/// Draws a gizmo for the associated collider
/// </summary>
/// <param name="mmGizmo"></param>
private static void DrawColliderGizmo(MMGizmo mmGizmo)
{
if (mmGizmo._sphereColliderNotNull)
{
if (mmGizmo.ColliderRenderType == MMGizmo.ColliderRenderTypes.Full)
{
Gizmos.DrawSphere(ComputeGizmoPosition(mmGizmo, mmGizmo._sphereCollider.center), mmGizmo._sphereCollider.radius);
}
else
{
Gizmos.DrawWireSphere(ComputeGizmoPosition(mmGizmo, mmGizmo._sphereCollider.center), mmGizmo._sphereCollider.radius);
}
}
if (mmGizmo._boxColliderNotNull)
{
if (mmGizmo.ColliderRenderType == MMGizmo.ColliderRenderTypes.Full)
{
Gizmos.DrawCube(ComputeGizmoPosition(mmGizmo, mmGizmo._boxCollider.center), mmGizmo._boxCollider.size);
}
else
{
Gizmos.DrawWireCube(ComputeGizmoPosition(mmGizmo, mmGizmo._boxCollider.center), mmGizmo._boxCollider.size);
}
}
#if MM_PHYSICS2D
if (mmGizmo._circleCollider2DNotNull)
{
if (mmGizmo.ColliderRenderType == MMGizmo.ColliderRenderTypes.Full)
{
Gizmos.DrawSphere((Vector3)ComputeGizmoPosition(mmGizmo, mmGizmo._circleCollider2D.offset), mmGizmo._circleCollider2D.radius);
}
else
{
Gizmos.DrawWireSphere((Vector3)ComputeGizmoPosition(mmGizmo, mmGizmo._circleCollider2D.offset), mmGizmo._circleCollider2D.radius);
}
}
if (mmGizmo._boxCollider2DNotNull)
{
Vector3 gizmoSize = new Vector3();
gizmoSize.x = mmGizmo._boxCollider2D.size.x ;
gizmoSize.y = mmGizmo._boxCollider2D.size.y ;
gizmoSize.z = 0.1f;
if (mmGizmo.ColliderRenderType == MMGizmo.ColliderRenderTypes.Full)
{
Gizmos.DrawCube(ComputeGizmoPosition(mmGizmo, mmGizmo._boxCollider2D.offset), gizmoSize);
}
else
{
Gizmos.DrawWireCube(ComputeGizmoPosition(mmGizmo, mmGizmo._boxCollider2D.offset), gizmoSize);
}
}
#endif
if (mmGizmo._meshColliderNotNull)
{
if (mmGizmo.ColliderRenderType == MMGizmo.ColliderRenderTypes.Full)
{
Gizmos.DrawMesh(mmGizmo._meshCollider.sharedMesh);
}
else
{
Gizmos.DrawWireMesh(mmGizmo._meshCollider.sharedMesh);
}
}
}
/// <summary>
/// Draws a position gizmo
/// </summary>
/// <param name="mmGizmo"></param>
private static void DrawPositionGizmo(MMGizmo mmGizmo)
{
switch (mmGizmo.PositionMode)
{
case MMGizmo.PositionModes.Point:
MMDebug.DrawGizmoPoint(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), mmGizmo.GizmoColor, mmGizmo.PositionSize);
break;
case MMGizmo.PositionModes.Cube:
Gizmos.DrawCube(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), Vector3.one * mmGizmo.PositionSize);
break;
case MMGizmo.PositionModes.Sphere:
Gizmos.DrawSphere(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), mmGizmo.PositionSize);
break;
case MMGizmo.PositionModes.WireCube:
Gizmos.DrawWireCube(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), Vector3.one * mmGizmo.PositionSize);
break;
case MMGizmo.PositionModes.WireSphere:
Gizmos.DrawWireSphere(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), mmGizmo.PositionSize);
break;
case MMGizmo.PositionModes.Texture:
if (mmGizmo._positionTextureNotNull)
{
Handles.BeginGUI();
mmGizmo._worldToGUIPosition = HandleUtility.WorldToGUIPoint(ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false));
mmGizmo._textureRect = new Rect(mmGizmo._worldToGUIPosition.x - mmGizmo.TextureSize.x/2f, mmGizmo._worldToGUIPosition.y - mmGizmo.TextureSize.y/2f, mmGizmo.TextureSize.x, mmGizmo.TextureSize.y);
GUI.Label(mmGizmo._textureRect, mmGizmo.PositionTexture);
Handles.EndGUI();
}
break;
case MMGizmo.PositionModes.Arrows:
Handles.color = Handles.xAxisColor;
Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
Quaternion.LookRotation(mmGizmo.transform.right, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
Handles.color = Handles.yAxisColor;
Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
Quaternion.LookRotation(mmGizmo.transform.up, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
Handles.color = Handles.zAxisColor;
Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
Quaternion.LookRotation(mmGizmo.transform.forward, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
break;
case MMGizmo.PositionModes.RightArrow:
Handles.color = mmGizmo.GizmoColor;
Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
Quaternion.LookRotation(mmGizmo.transform.right, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
break;
case MMGizmo.PositionModes.UpArrow:
Handles.color = mmGizmo.GizmoColor;
Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
Quaternion.LookRotation(mmGizmo.transform.up, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
break;
case MMGizmo.PositionModes.ForwardArrow:
Handles.color = mmGizmo.GizmoColor;
Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
Quaternion.LookRotation(mmGizmo.transform.forward, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
break;
case MMGizmo.PositionModes.Lines:
Vector3 origin = ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero);
Vector3 destination = origin + Vector3.right * mmGizmo.PositionSize;
Gizmos.DrawLine(origin, destination);
destination = origin + Vector3.up * mmGizmo.PositionSize;
Gizmos.DrawLine(origin, destination);
destination = origin + Vector3.forward * mmGizmo.PositionSize;
Gizmos.DrawLine(origin, destination);
break;
case MMGizmo.PositionModes.RightLine:
Vector3 rightOrigin = ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero);
Vector3 rightDestination = rightOrigin + Vector3.right * mmGizmo.PositionSize;
Gizmos.DrawLine(rightOrigin, rightDestination);
break;
case MMGizmo.PositionModes.UpLine:
Vector3 upOrigin = ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero);
Vector3 upDestination = upOrigin + Vector3.up * mmGizmo.PositionSize;
Gizmos.DrawLine(upOrigin, upDestination);
break;
case MMGizmo.PositionModes.ForwardLine:
Vector3 fwdOrigin = ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero);
Vector3 fwdDestination = fwdOrigin + Vector3.forward * mmGizmo.PositionSize;
Gizmos.DrawLine(fwdOrigin, fwdDestination);
break;
}
}
/// <summary>
/// Draws our gizmo text
/// </summary>
/// <param name="mmGizmo"></param>
private static void DrawText(MMGizmo mmGizmo)
{
if (!mmGizmo.DisplayText)
{
return;
}
if (!TestDistance(mmGizmo, mmGizmo.TextMaxDistance))
{
return;
}
switch (mmGizmo.TextMode)
{
case MMGizmo.TextModes.GameObjectName:
mmGizmo._textToDisplay = mmGizmo.gameObject.name;
break;
case MMGizmo.TextModes.CustomText:
mmGizmo._textToDisplay = mmGizmo.TextToDisplay;
break;
case MMGizmo.TextModes.Position:
mmGizmo._textToDisplay = mmGizmo.transform.position.ToString();
break;
case MMGizmo.TextModes.Rotation:
mmGizmo._textToDisplay = mmGizmo.transform.rotation.ToString();
break;
case MMGizmo.TextModes.Scale:
mmGizmo._textToDisplay = mmGizmo.transform.localScale.ToString();
break;
case MMGizmo.TextModes.Property:
if (mmGizmo.TargetProperty.PropertyFound)
{
mmGizmo._textToDisplay = mmGizmo.TargetProperty.GetRawValue().ToString();
}
break;
}
if (mmGizmo._textToDisplay != "")
{
Handles.Label(mmGizmo.transform.position + mmGizmo.TextOffset, mmGizmo._textToDisplay, mmGizmo._textGUIStyle);
}
}
/// <summary>
/// Computes the position at which to draw the gizmo
/// </summary>
/// <param name="mmGizmo"></param>
/// <param name="position"></param>
/// <param name="relativeLock"></param>
/// <returns></returns>
private static Vector3 ComputeGizmoPosition(MMGizmo mmGizmo, Vector3 position, bool relativeLock = true)
{
mmGizmo._newPosition = position + mmGizmo.GizmoOffset;
if (mmGizmo.LockX || mmGizmo.LockY || mmGizmo.LockZ)
{
Vector3 mmGizmoNewPosition = mmGizmo._newPosition;
if (mmGizmo.LockX) { mmGizmoNewPosition.x = relativeLock ? - mmGizmo.transform.position.x + mmGizmo.LockedX : mmGizmo.LockedX; }
if (mmGizmo.LockY) { mmGizmoNewPosition.y = relativeLock ? - mmGizmo.transform.position.y + mmGizmo.LockedY : mmGizmo.LockedY; }
if (mmGizmo.LockZ) { mmGizmoNewPosition.z = relativeLock ? - mmGizmo.transform.position.z + mmGizmo.LockedZ : mmGizmo.LockedZ; }
mmGizmo._newPosition = mmGizmoNewPosition;
}
return mmGizmo._newPosition;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6b4b64ec300cb6948b1022cd5e3311c0
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/Editor/MMGizmos/MMGizmoEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Text;
using System.Linq;
using System;
namespace MoreMountains.Tools
{
/// <summary>
/// A maintenance class that removes all empty directories from a project via a menu item
/// </summary>
public class MMCleanEmptyFolders : MonoBehaviour
{
static string _consoleLog = "";
static List<DirectoryInfo> _listOfEmptyDirectories = new List<DirectoryInfo>();
/// <summary>
/// Parses the project for empty directories and removes them, as well as their associated meta file
/// </summary>
[MenuItem("Tools/More Mountains/Cleanup empty folders", false, 504)]
protected static void CleanupMissingScripts()
{
_listOfEmptyDirectories.Clear();
var assetsDir = Application.dataPath + Path.DirectorySeparatorChar;
GetEmptyDirectories(new DirectoryInfo(assetsDir), _listOfEmptyDirectories);
if (0 < _listOfEmptyDirectories.Count)
{
_consoleLog = "[MMCleanEmptyFolders] Removed "+ _listOfEmptyDirectories.Count + " empty directories:\n";
foreach (var d in _listOfEmptyDirectories)
{
_consoleLog += "· "+ d.FullName.Replace(assetsDir, "") + "\n";
FileUtil.DeleteFileOrDirectory(d.FullName);
FileUtil.DeleteFileOrDirectory(d.FullName+".meta");
}
MMDebug.DebugLogInfo(_consoleLog);
_consoleLog = "";
AssetDatabase.Refresh();
}
}
/// <summary>
/// Returns true if a directory is empty and updates a list of empty directories
/// </summary>
/// <param name="directory"></param>
/// <param name="listOfEmptyDirectories"></param>
/// <returns></returns>
static bool GetEmptyDirectories(DirectoryInfo directory, List<DirectoryInfo> listOfEmptyDirectories)
{
bool directoryIsEmpty = true;
directoryIsEmpty = (directory.GetDirectories().Count(x => !GetEmptyDirectories(x, listOfEmptyDirectories)) == 0) && (directory.GetFiles("*.*").All(x => x.Extension == ".meta"));
if (directoryIsEmpty)
{
listOfEmptyDirectories.Add(directory);
}
return directoryIsEmpty;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: eef8a54b228d3d148b605064c04e66a4
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/Editor/MMMaintenance/MMCleanEmptyFolders.cs
uploadId: 830868

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This class lets you clean all missing scripts on a selection of gameobjects
/// </summary>
public class MMCleanupMissingScripts : MonoBehaviour
{
/// <summary>
/// Processes the cleaning of gameobjects for all missing scripts on them
/// </summary>
[MenuItem("Tools/More Mountains/Cleanup missing scripts on selected GameObjects", false, 504)]
protected static void CleanupMissingScripts()
{
Object[] collectedDeepHierarchy = EditorUtility.CollectDeepHierarchy(Selection.gameObjects);
int removedComponentsCounter = 0;
int gameobjectsAffectedCounter = 0;
foreach (Object targetObject in collectedDeepHierarchy)
{
if (targetObject is GameObject gameObject)
{
int amountOfMissingScripts = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(gameObject);
if (amountOfMissingScripts > 0)
{
Undo.RegisterCompleteObjectUndo(gameObject, "Removing missing scripts");
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(gameObject);
removedComponentsCounter += amountOfMissingScripts;
gameobjectsAffectedCounter++;
}
}
}
MMDebug.DebugLogInfo("[MMCleanupMissingScripts] Removed " + removedComponentsCounter + " missing scripts from " + gameobjectsAffectedCounter + " GameObjects");
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 05ed97bf9ce684b47ab50ba3bf13134e
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/Editor/MMMaintenance/MMCleanupMissingScripts.cs
uploadId: 830868

View File

@@ -0,0 +1,72 @@
// Original FindMissingScriptsRecursively script by SimTex and Clement
// http://wiki.unity3d.com/index.php?title=FindMissingScripts
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace MoreMountains.Tools
{
public class MMFindMissingScriptsRecursively : EditorWindow
{
static int go_count = 0, components_count = 0, missing_count = 0;
[MenuItem("Tools/More Mountains/Find missing scripts recursively", false, 505)]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(MMFindMissingScriptsRecursively));
}
#if UNITY_EDITOR
public void OnGUI()
{
if (GUILayout.Button("Find Missing Scripts in selected GameObjects"))
{
FindInSelected();
}
}
#endif
private static void FindInSelected()
{
GameObject[] go = Selection.gameObjects;
go_count = 0;
components_count = 0;
missing_count = 0;
foreach (GameObject g in go)
{
FindInGO(g);
}
Debug.Log(string.Format("Searched {0} GameObjects, {1} components, found {2} missing", go_count, components_count, missing_count));
}
private static void FindInGO(GameObject g)
{
go_count++;
Component[] components = g.GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
components_count++;
if (components[i] == null)
{
missing_count++;
string s = g.name;
Transform t = g.transform;
while (t.parent != null)
{
s = t.parent.name +"/"+s;
t = t.parent;
}
Debug.Log (s + " has an empty script attached in position: " + i, g);
}
}
// Now recurse through each child GO (if there are any):
foreach (Transform childT in g.transform)
{
FindInGO(childT.gameObject);
}
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5c87833dd08a8c842823386dde78cb2a
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/Editor/MMMaintenance/MMFindMissingScriptsRecursively.cs
uploadId: 830868

View File

@@ -0,0 +1,283 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// As static class that lets you look for missing scripts on any prefab in your project, or for prefabs equipped with a certain type of MonoBehaviour
/// </summary>
public class MMFindPrefabsByMono : EditorWindow
{
protected Vector2 _scrollView;
protected string[] _tabs = new string[] { "Find prefabs with missing components", "Find prefabs by MonoBehaviour" };
protected int _selectedTab;
protected int _lastSelectedTab = -1;
protected MonoScript _searchedMonoBehaviour;
protected MonoScript _lastSearchedMonoBehaviour;
protected string _searchedMonoBehaviourName = "";
protected List<string> _resultsList;
static GUIStyle _padded;
static GUIStyle _horizontalPadded;
static int _horizontalPadding = 20;
static int _verticalPadding = 20;
static RectOffset _padding;
static RectOffset _horizontalPaddingOnly;
/// <summary>
/// Menu bound method
/// </summary>
[MenuItem("Tools/More Mountains/Prefab Finder", false, 504)]
public static void MenuAction()
{
OpenWindow();
}
/// <summary>
/// Opens and resizes the window
/// </summary>
public static void OpenWindow()
{
InitializePaddingAndStyles();
MMFindPrefabsByMono window = (MMFindPrefabsByMono)EditorWindow.GetWindow(typeof(MMFindPrefabsByMono));
window.position = new Rect(400, 400, 800, 600);
window.titleContent = new GUIContent("MM Prefabs Finder");
window.Show();
}
/// <summary>
/// Initializes padding variables and GUI styles
/// </summary>
static void InitializePaddingAndStyles()
{
if (_padding == null)
{
_padding = new RectOffset(_horizontalPadding, _horizontalPadding, _verticalPadding, _verticalPadding);
_horizontalPaddingOnly = new RectOffset(_horizontalPadding, _horizontalPadding, 0, 0);
_padded = new GUIStyle
{
name = "padded",
padding = _padding
};
_horizontalPadded = new GUIStyle
{
name = "horizontalPadded",
padding = _horizontalPaddingOnly
};
}
}
/// <summary>
/// Draws tab buttons
/// </summary>
protected virtual void DrawTabs()
{
GUI.skin.box.padding = _padding;
GUILayout.BeginHorizontal("box");
GUILayout.Space(10);
_selectedTab = GUILayout.Toolbar(_selectedTab, _tabs);
GUILayout.EndHorizontal();
}
/// <summary>
/// Detects changes in tabs selection
/// </summary>
protected virtual void HandleTabsChange()
{
if (_lastSelectedTab != _selectedTab)
{
_lastSelectedTab = _selectedTab;
_resultsList = new List<string>();
_searchedMonoBehaviourName = _searchedMonoBehaviour == null ? "" : _searchedMonoBehaviour.name;
_lastSearchedMonoBehaviour = null;
}
}
/// <summary>
/// Draws the content of the selected tab
/// </summary>
protected virtual void DrawSelectedTab()
{
switch (_selectedTab)
{
case 0:
DrawSearchMissing();
break;
case 1:
DrawSearchByMonoBehaviour();
break;
}
}
/// <summary>
/// Draws the search by mono form
/// </summary>
protected virtual void DrawSearchByMonoBehaviour()
{
GUILayout.BeginHorizontal("box");
GUILayout.Space(20);
GUILayout.BeginVertical();
GUILayout.Label("Select a MonoBehaviour to search for:");
_searchedMonoBehaviour = (MonoScript)EditorGUILayout.ObjectField(_searchedMonoBehaviour, typeof(MonoScript), false);
GUILayout.EndVertical();
GUILayout.Space(10);
if (_searchedMonoBehaviour != _lastSearchedMonoBehaviour)
{
string[] allPrefabsInProject = GetAllPrefabsInProject();
_lastSearchedMonoBehaviour = _searchedMonoBehaviour;
_searchedMonoBehaviourName = _searchedMonoBehaviour.name;
AssetDatabase.SaveAssets();
string searchedMonoBehaviourPath = AssetDatabase.GetAssetPath(_searchedMonoBehaviour);
_resultsList = new List<string>();
foreach (string prefab in allPrefabsInProject)
{
string[] pathName = new string[] { prefab };
string[] monoDependenciesPaths = AssetDatabase.GetDependencies(pathName, false);
foreach (string monoDependencyPath in monoDependenciesPaths)
{
if (monoDependencyPath == searchedMonoBehaviourPath)
{
_resultsList.Add(prefab);
}
}
}
}
GUILayout.EndHorizontal();
}
/// <summary>
/// Draws the search missing form
/// </summary>
protected virtual void DrawSearchMissing()
{
GUILayout.BeginHorizontal("box");
GUILayout.Space(20);
if (GUILayout.Button("Search the project for prefabs with missing scripts"))
{
string[] allPrefabs = GetAllPrefabsInProject();
_resultsList = new List<string>();
foreach (string prefab in allPrefabs)
{
UnityEngine.Object asset = AssetDatabase.LoadMainAssetAtPath(prefab);
GameObject assetGameObject;
try
{
assetGameObject = (GameObject)asset;
Component[] components = assetGameObject.GetComponentsInChildren<Component>(true);
foreach (Component component in components)
{
if (component == null)
{
_resultsList.Add(prefab);
}
}
}
catch
{
MMDebug.DebugLogInfo("An error occured with prefab " + prefab);
}
}
}
GUILayout.EndHorizontal();
}
/// <summary>
/// Draws the result list
/// </summary>
protected virtual void DrawResultsList()
{
GUILayout.BeginHorizontal(_padded);
if (_resultsList != null)
{
if (_resultsList.Count == 0)
{
switch (_selectedTab)
{
case 0:
GUILayout.Label("No prefabs have missing components.", EditorStyles.boldLabel);
break;
case 1:
if (!string.IsNullOrEmpty(_searchedMonoBehaviourName))
{
GUILayout.Label("No prefabs use component " + _searchedMonoBehaviourName, EditorStyles.boldLabel);
}
break;
}
GUILayout.EndHorizontal(); // end padded
}
else
{
switch (_selectedTab)
{
case 0:
GUILayout.Label("These prefabs have missing components :", EditorStyles.boldLabel);
break;
case 1:
GUILayout.Label("MonoBehaviour " + _searchedMonoBehaviourName + " was found in these prefabs :", EditorStyles.boldLabel);
break;
}
GUILayout.EndHorizontal(); // end padded
GUILayout.BeginHorizontal();
GUI.skin.scrollView.padding = _padding;
_scrollView = GUILayout.BeginScrollView(_scrollView);
foreach (string s in _resultsList)
{
GUILayout.BeginHorizontal(_horizontalPadded);
GUILayout.Label(s, GUILayout.Width(4 * (position.width - 4 * _horizontalPadding) / 5));
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
if (GUILayout.Button("Select prefab", GUILayout.Width((position.width - 4 * _horizontalPadding) / 5 - 20)))
{
Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(s);
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
GUILayout.EndHorizontal();
}
}
}
#if UNITY_EDITOR
/// <summary>
/// On GUI we draw our window's contents
/// </summary>
protected virtual void OnGUI()
{
InitializePaddingAndStyles();
DrawTabs();
HandleTabsChange();
DrawSelectedTab();
DrawResultsList();
}
#endif
/// <summary>
/// Gets all prefabs and sorts them alphabetically
/// </summary>
/// <returns></returns>
public static string[] GetAllPrefabsInProject()
{
string[] assetPaths = AssetDatabase.GetAllAssetPaths();
List<string> results = new List<string>();
foreach (string assetPath in assetPaths)
{
if (assetPath.Contains(".prefab"))
{
results.Add(assetPath);
}
}
results.Sort();
return results.ToArray();
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c6f3cc53c6ac3754bbf1b45956f64a21
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/Editor/MMMaintenance/MMFindPrefabsByMono.cs
uploadId: 830868

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to add a menu item and a shortcut to group objects together under a parent game object
/// </summary>
public class MMGroupSelection
{
/// <summary>
/// Creates a parent object and puts all selected transforms under it
/// </summary>
[MenuItem("Tools/More Mountains/Group Selection %g")]
public static void GroupSelection()
{
if (!Selection.activeTransform)
{
return;
}
GameObject groupObject = new GameObject();
groupObject.name = "Group";
Undo.RegisterCreatedObjectUndo(groupObject, "Group Selection");
groupObject.transform.SetParent(Selection.activeTransform.parent, false);
foreach (Transform selectedTransform in Selection.transforms)
{
Undo.SetTransformParent(selectedTransform, groupObject.transform, "Group Selection");
}
Selection.activeGameObject = groupObject;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: a908ed7f06f3bf34e8ff030a385f46f2
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/Editor/MMMaintenance/MMGroupSelection.cs
uploadId: 830868

View File

@@ -0,0 +1,26 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// A simple class that lets you lock the current inspector by pressing ctrl (or cmd) + L
/// Pressing the same shortcut again unlocks the
/// </summary>
public class MMLockInspector : MonoBehaviour
{
[MenuItem("Tools/More Mountains/Lock Inspector %l")]
static public void LockInspector()
{
Type inspectorType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");
EditorWindow inspectorWindow = EditorWindow.GetWindow(inspectorType);
PropertyInfo isLockedPropertyInfo = inspectorType.GetProperty("isLocked", BindingFlags.Public | BindingFlags.Instance);
bool state = (bool)isLockedPropertyInfo.GetGetMethod().Invoke(inspectorWindow, new object[] { });
isLockedPropertyInfo.GetSetMethod().Invoke(inspectorWindow, new object[] { !state });
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5c0e71f738b287843b432d007a0626bb
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/Editor/MMMaintenance/MMLockInspector.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,67 @@
using UnityEngine;
using UnityEditor;
namespace MoreMountains.Tools
{
/// <summary>
/// Custom editor for the MMAutoRotate component
/// </summary>
[CustomEditor(typeof(MMAutoRotate), true)]
[CanEditMultipleObjects]
public class MMAutoRotateEditor : Editor
{
/// <summary>
///
/// </summary>
/// <param name="autoRotate"></param>
/// <param name="gizmoType"></param>
[DrawGizmo(GizmoType.InSelectionHierarchy)]
static void DrawHandles(MMAutoRotate autoRotate, GizmoType gizmoType)
{
MMAutoRotate myTarget = autoRotate;
// only draw gizmos if orbiting and gizmos enabled
if (!myTarget.Orbiting || !myTarget.DrawGizmos)
{
return;
};
// if we're not playing, we compute our center/axis
if (!Application.isPlaying)
{
if (myTarget.OrbitCenterTransform != null)
{
myTarget._orbitCenter = myTarget.OrbitCenterTransform.transform.position + myTarget.OrbitCenterOffset;
myTarget._worldRotationAxis = myTarget.OrbitCenterTransform.TransformDirection(myTarget.OrbitRotationAxis);
myTarget._rotationPlane.SetNormalAndPosition(myTarget._worldRotationAxis.normalized, myTarget._orbitCenter);
myTarget._snappedPosition = myTarget._rotationPlane.ClosestPointOnPlane(myTarget.transform.position);
myTarget._radius = myTarget.OrbitRadius * Vector3.Normalize(myTarget._snappedPosition - myTarget._orbitCenter);
}
}
// draws a plane disc
Handles.color = myTarget.OrbitPlaneColor;
Handles.DrawSolidDisc(myTarget._orbitCenter, myTarget._rotationPlane.normal, myTarget.OrbitRadius + 0.5f);
// draws a circle to mark the orbit
Handles.color = myTarget.OrbitLineColor;
Handles.DrawWireArc(myTarget._orbitCenter, myTarget._rotationPlane.normal, Vector3.ProjectOnPlane(myTarget._orbitCenter + Vector3.forward, myTarget._rotationPlane.normal), 360f, myTarget.OrbitRadius);
// draws an arrow to mark the direction
Quaternion newRotation = Quaternion.AngleAxis(1f, myTarget._worldRotationAxis);
Vector3 origin = myTarget._orbitCenter + newRotation * myTarget._radius;
newRotation = Quaternion.AngleAxis(15f, myTarget._worldRotationAxis);
Vector3 direction = Vector3.zero;
if (myTarget.OrbitRotationSpeed > 0f)
{
direction = (myTarget._orbitCenter + newRotation * myTarget._radius) - origin;
}
else
{
direction = origin - (myTarget._orbitCenter + newRotation * myTarget._radius);
}
MMDebug.DebugDrawArrow(origin, direction, myTarget.OrbitLineColor);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 9b4bf5a88d386b6428629ffc983eb62c
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/Editor/MMMovement/MMAutoRotateEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,88 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// This class adds names for each LevelMapPathElement next to it on the scene view, for easier setup
/// </summary>
[CustomEditor(typeof(MMPath),true)]
[InitializeOnLoad]
public class MMPathEditor : Editor
{
public MMPath pathTarget
{
get
{
return (MMPath)target;
}
}
/// <summary>
/// OnSceneGUI, draws repositionable handles at every point in the path, for easier setup
/// </summary>
protected virtual void OnSceneGUI()
{
Handles.color=Color.green;
MMPath t = (target as MMPath);
if (t.GetOriginalTransformPositionStatus() == false)
{
return;
}
for (int i=0;i<t.PathElements.Count;i++)
{
EditorGUI.BeginChangeCheck();
Vector3 oldPoint = t.GetOriginalTransformPosition()+t.PathElements[i].PathElementPosition;
GUIStyle style = new GUIStyle();
// draws the path item number
style.normal.textColor = Color.yellow;
Handles.Label(t.GetOriginalTransformPosition()+t.PathElements[i].PathElementPosition+(Vector3.down*0.4f)+(Vector3.right*0.4f), ""+i,style);
// draws a movable handle
var fmh_49_57_638478220619113249 = Quaternion.identity; Vector3 newPoint = Handles.FreeMoveHandle(oldPoint,.5f,new Vector3(.25f,.25f,.25f),Handles.CircleHandleCap);
newPoint = ApplyAxisLock(oldPoint, newPoint);
// records changes
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Free Move Handle");
t.PathElements[i].PathElementPosition = newPoint - t.GetOriginalTransformPosition();
}
}
}
/// <summary>
/// Locks handles movement on x, y, or z axis
/// </summary>
/// <param name="oldPoint"></param>
/// <param name="newPoint"></param>
/// <returns></returns>
protected virtual Vector3 ApplyAxisLock(Vector3 oldPoint, Vector3 newPoint)
{
MMPath t = (target as MMPath);
if (t.LockHandlesOnXAxis)
{
newPoint.x = oldPoint.x;
}
if (t.LockHandlesOnYAxis)
{
newPoint.y = oldPoint.y;
}
if (t.LockHandlesOnZAxis)
{
newPoint.z = oldPoint.z;
}
return newPoint;
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d103290728e03b448829fc4b58e285ac
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/Editor/MMMovement/MMPathMovement/MMPathEditor.cs
uploadId: 830868

View File

@@ -0,0 +1,78 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// This class adds names for each LevelMapPathElement next to it on the scene view, for easier setup
/// </summary>
[CustomEditor(typeof(MMPathMovement),true)]
[InitializeOnLoad]
public class MMPathMovementEditor : Editor
{
public MMPathMovement pathMovementTarget
{
get
{
return (MMPathMovement)target;
}
}
public override void OnInspectorGUI()
{
serializedObject.Update ();
if (pathMovementTarget.AccelerationType == MMPathMovement.PossibleAccelerationType.AnimationCurve)
{
DrawDefaultInspector ();
}
else
{
Editor.DrawPropertiesExcluding (serializedObject, new string [] { "Acceleration" });
}
serializedObject.ApplyModifiedProperties ();
}
/// <summary>
/// OnSceneGUI, draws repositionable handles at every point in the path, for easier setup
/// </summary>
protected virtual void OnSceneGUI()
{
Handles.color = Color.green;
MMPathMovement t = (target as MMPathMovement);
if (t.GetOriginalTransformPositionStatus() == false)
{
return;
}
for (int i=0;i<t.PathElements.Count;i++)
{
EditorGUI.BeginChangeCheck();
Vector3 oldPoint = t.PointPosition(i);
GUIStyle style = new GUIStyle();
// draws the path item number
style.normal.textColor = Color.yellow;
Handles.Label(t.PointPosition(i) + (Vector3.down*0.4f) + (Vector3.right*0.4f), ""+i,style);
// draws a movable handle
var fmh_65_57_638478220619113409 = Quaternion.identity; Vector3 newPoint = Handles.FreeMoveHandle(oldPoint,.5f,new Vector3(.25f,.25f,.25f),Handles.CircleHandleCap);
// records changes
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Free Move Handle");
t.PathElements[i].PathElementPosition = newPoint - t.GetOriginalTransformPosition();
}
}
}
}
}
#endif

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 80063623289ee3e49b584d00f3a90a32
timeCreated: 1523894192
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/Editor/MMMovement/MMPathMovement/MMPathMovementEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,62 @@
using System;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Reflection;
namespace MoreMountains.Tools
{
[CanEditMultipleObjects()]
[CustomEditor(typeof(MMRendererSortingLayer), true)]
public class MMRendererLayerEditor : Editor
{
int popupMenuIndex;
string[] sortingLayerNames;
protected MMRendererSortingLayer _mmRendererSortingLayer;
protected Renderer _renderer;
void OnEnable()
{
sortingLayerNames = GetSortingLayerNames();
_mmRendererSortingLayer = (MMRendererSortingLayer)target;
_renderer = _mmRendererSortingLayer.GetComponent<Renderer> ();
for (int i = 0; i<sortingLayerNames.Length;i++) //here we initialize our popupMenuIndex with the current Sort Layer Name
{
if (sortingLayerNames[i] == _renderer.sortingLayerName)
popupMenuIndex = i;
}
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (_renderer == null)
{
return;
}
popupMenuIndex = EditorGUILayout.Popup("Sorting Layer", popupMenuIndex, sortingLayerNames);
int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", _renderer.sortingOrder);
if (sortingLayerNames[popupMenuIndex] != _renderer.sortingLayerName
|| newSortingLayerOrder != _renderer.sortingOrder)
{
Undo.RecordObject(_renderer, "Change Particle System Renderer Order");
_renderer.sortingLayerName = sortingLayerNames[popupMenuIndex];
_renderer.sortingOrder = newSortingLayerOrder;
EditorUtility.SetDirty(_renderer);
}
}
public string[] GetSortingLayerNames()
{
Type internalEditorUtilityType = typeof(InternalEditorUtility);
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
return (string[])sortingLayersProperty.GetValue(null, new object[0]);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0ca3ff8bc8827e24ab1490c416d7839f
timeCreated: 1491156263
licenseType: Store
MonoImporter:
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/Editor/MMParticles/MMRendererSortingLayerEditor.cs
uploadId: 830868

View File

@@ -0,0 +1,62 @@
using System;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Reflection;
namespace MoreMountains.Tools
{
[CanEditMultipleObjects()]
[CustomEditor(typeof(MMTrailRendererSortingLayer), true)]
public class MMTrailRendererLayerEditor : Editor
{
int popupMenuIndex;
string[] sortingLayerNames;
protected MMTrailRendererSortingLayer _mmTrailRendererSortingLayer;
protected TrailRenderer _trailRenderer;
void OnEnable()
{
sortingLayerNames = GetSortingLayerNames();
_mmTrailRendererSortingLayer = (MMTrailRendererSortingLayer)target;
_trailRenderer = _mmTrailRendererSortingLayer.GetComponent<TrailRenderer> ();
for (int i = 0; i<sortingLayerNames.Length;i++) //here we initialize our popupMenuIndex with the current Sort Layer Name
{
if (sortingLayerNames[i] == _trailRenderer.sortingLayerName)
popupMenuIndex = i;
}
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (_trailRenderer == null)
{
return;
}
popupMenuIndex = EditorGUILayout.Popup("Sorting Layer", popupMenuIndex, sortingLayerNames);
int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", _trailRenderer.sortingOrder);
if (sortingLayerNames[popupMenuIndex] != _trailRenderer.sortingLayerName
|| newSortingLayerOrder != _trailRenderer.sortingOrder)
{
Undo.RecordObject(_trailRenderer, "Change Particle System Renderer Order");
_trailRenderer.sortingLayerName = sortingLayerNames[popupMenuIndex];
_trailRenderer.sortingOrder = newSortingLayerOrder;
EditorUtility.SetDirty(_trailRenderer);
}
}
public string[] GetSortingLayerNames()
{
Type internalEditorUtilityType = typeof(InternalEditorUtility);
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
return (string[])sortingLayersProperty.GetValue(null, new object[0]);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f767333d7f0eaf24892e4778169d0d37
timeCreated: 1491156263
licenseType: Store
MonoImporter:
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/Editor/MMParticles/MMTrailRendererSortingLayerEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
#if MM_PHYSICS2D
/// <summary>
/// Custom editor for the MMTilemapGenerator, handles generate button and reorderable layers
/// </summary>
[CustomEditor(typeof(MMTilemapGenerator), true)]
[CanEditMultipleObjects]
public class MMTilemapGeneratorEditor : Editor
{
protected MMReorderableList _list;
protected virtual void OnEnable()
{
_list = new MMReorderableList(serializedObject.FindProperty("Layers"));
_list.elementNameProperty = "Layer";
_list.elementDisplayType = MMReorderableList.ElementDisplayType.Expandable;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
DrawPropertiesExcluding(serializedObject, "Layers");
EditorGUILayout.Space(10);
_list.DoLayoutList();
serializedObject.ApplyModifiedProperties();
if (GUILayout.Button("Generate"))
{
(target as MMTilemapGenerator).Generate();
}
}
}
#endif
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2fad23a01f1d6df49be8215ff24dbe62
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/Editor/MMProcedural/MMTilemapGeneratorEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,86 @@
using UnityEngine;
using System.Collections;
using MoreMountains.Tools;
using UnityEditor;
namespace MoreMountains.Tools
{
/// <summary>
/// An editor class used to display menu items
/// </summary>
public class MMDebugEditor
{
/// <summary>
/// Adds a menu item to enable debug logs
/// </summary>
[MenuItem("Tools/More Mountains/Enable Debug Logs", false, 100)]
private static void EnableDebugLogs()
{
MMDebug.SetDebugLogsEnabled(true);
}
/// <summary>
/// Conditional method to determine if the "enable debug log" entry should be greyed or not
/// </summary>
[MenuItem("Tools/More Mountains/Enable Debug Logs", true)]
private static bool EnableDebugLogsValidation()
{
return !MMDebug.DebugLogsEnabled;
}
/// <summary>
/// Adds a menu item to disable debug logs
/// </summary>
[MenuItem("Tools/More Mountains/Disable Debug Logs", false, 101)]
private static void DisableDebugLogs()
{
MMDebug.SetDebugLogsEnabled(false);
}
/// <summary>
/// Conditional method to determine if the "disable debug log" entry should be greyed or not
/// </summary>
[MenuItem("Tools/More Mountains/Disable Debug Logs", true)]
private static bool DisableDebugLogsValidation()
{
return MMDebug.DebugLogsEnabled;
}
/// <summary>
/// Adds a menu item to enable debug logs
/// </summary>
[MenuItem("Tools/More Mountains/Enable Debug Draws", false, 102)]
private static void EnableDebugDraws()
{
MMDebug.SetDebugDrawEnabled(true);
}
[MenuItem("Tools/More Mountains/Enable Debug Draws", true)]
/// <summary>
/// Conditional method to determine if the "enable debug log" entry should be greyed or not
/// </summary>
private static bool EnableDebugDrawsValidation()
{
return !MMDebug.DebugDrawEnabled;
}
[MenuItem("Tools/More Mountains/Disable Debug Draws", false, 103)]
/// <summary>
/// Adds a menu item to disable debug logs
/// </summary>
private static void DisableDebugDraws()
{
MMDebug.SetDebugDrawEnabled(false);
}
[MenuItem("Tools/More Mountains/Disable Debug Draws", true)]
/// <summary>
/// Conditional method to determine if the "disable debug log" entry should be greyed or not
/// </summary>
private static bool DisableDebugDrawsValidation()
{
return MMDebug.DebugDrawEnabled;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 75f9cc4cf2ef4324d99f4dc9d5709b63
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/Editor/MMUtilities/MMDebugEditor.cs
uploadId: 830868

View File

@@ -0,0 +1,23 @@
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMLayer))]
public class MMLayerPropertyDrawer : PropertyDrawer
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, GUIContent.none, property);
SerializedProperty layerIndex = property.FindPropertyRelative("_layerIndex");
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
if (layerIndex != null)
{
layerIndex.intValue = EditorGUI.LayerField(position, layerIndex.intValue);
}
EditorGUI.EndProperty();
}
#endif
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2d8d3d62d1a2e8f429db2998bbdeb237
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/Editor/MMUtilities/MMLayerPropertyDrawer.cs
uploadId: 830868

View File

@@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
namespace MoreMountains.Tools
{
[CustomEditor(typeof(MMAspectRatioSafeZones), true)]
public class MMScreenshotEditor : Editor
{
static string FolderName = "Screenshots";
[MenuItem("Tools/More Mountains/Screenshot/Take Screenshot Real Size", false, 801)]
public static void MenuScreenshotSize1()
{
string savePath = TakeScreenCaptureScreenshot(1);
}
[MenuItem("Tools/More Mountains/Screenshot/Take Screenshot Size x2", false, 802)]
public static void MenuScreenshotSize2()
{
string savePath = TakeScreenCaptureScreenshot(2);
}
[MenuItem("Tools/More Mountains/Screenshot/Take Screenshot Size x3 %k", false, 803)]
public static void MenuScreenshotSize3()
{
string savePath = TakeScreenCaptureScreenshot(3);
}
protected static string TakeScreenCaptureScreenshot(int gameViewSizeMultiplier)
{
if (!Directory.Exists(FolderName))
{
Directory.CreateDirectory(FolderName);
}
float width = Screen.width * gameViewSizeMultiplier;
float height = Screen.height * gameViewSizeMultiplier;
string savePath = FolderName + "/screenshot_" + width + "x" + height + "_" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".png";
ScreenCapture.CaptureScreenshot(savePath, gameViewSizeMultiplier);
MMDebug.DebugLogInfo("[MMScreenshot] Screenshot taken with size multiplier of " + gameViewSizeMultiplier + " and saved at " + savePath);
return savePath;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 82c6a6e2f2e591a498214d03f76d9f09
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/Editor/MMUtilities/MMScreenshotEditor.cs
uploadId: 830868

View File

@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace MoreMountains.Tools
{
/// <summary>
/// Custom editor for the MMTransformRandomizer class
/// </summary>
[CustomEditor(typeof(MMTransformRandomizer), true)]
[CanEditMultipleObjects]
public class MMTransformRandomizerEditor : Editor
{
/// <summary>
/// On inspector we handle undo and display a test button
/// </summary>
public override void OnInspectorGUI()
{
serializedObject.Update();
Undo.RecordObject(target, "Modified MMTransformRandomizer");
DrawDefaultInspector();
EditorGUILayout.Space();
EditorGUILayout.LabelField("Test", EditorStyles.boldLabel);
if (GUILayout.Button("Randomize"))
{
foreach (MMTransformRandomizer randomizer in targets)
{
randomizer.Randomize();
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6dbf82cbd8a266041acbda8137fc5b9d
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/Editor/MMUtilities/MMTransformRandomizerEditor.cs
uploadId: 830868

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// This class adds names for each LevelMapPathElement next to it on the scene view, for easier setup
/// </summary>
[CustomEditor(typeof(MMSceneViewIcon))]
[InitializeOnLoad]
public class SceneViewIconEditor : Editor
{
//protected SceneViewIcon _sceneViewIcon;
[DrawGizmo(GizmoType.InSelectionHierarchy | GizmoType.NotInSelectionHierarchy)]
static void DrawGameObjectName(MMSceneViewIcon sceneViewIcon, GizmoType gizmoType)
{
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.blue;
Handles.Label(sceneViewIcon.transform.position, sceneViewIcon.gameObject.name,style);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 22acaeb1b9f9e4fbbb6486133e649e67
timeCreated: 1456229446
licenseType: Store
MonoImporter:
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/Editor/MMUtilities/ManagerIconEditor.cs
uploadId: 830868

View File

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

View File

@@ -0,0 +1,36 @@
using UnityEngine;
using System.Collections;
using MoreMountains.Tools;
using System.Collections.Generic;
using UnityEditor;
namespace MoreMountains.Tools
{
[CustomEditor(typeof(MMConeOfVision2D), true)]
public class MMConeOfVision2DInspector : Editor
{
protected MMConeOfVision2D _coneOfVision;
protected virtual void OnSceneGUI()
{
// draws a circle around the character to represent the cone of vision's radius
_coneOfVision = (MMConeOfVision2D)target;
Handles.color = Color.yellow;
Handles.DrawWireArc(_coneOfVision.transform.position, -Vector3.forward, Vector3.up, 360f, _coneOfVision.VisionRadius);
// draws two lines to mark the vision angle
Vector3 visionAngleLeft = MMMaths.DirectionFromAngle2D(-_coneOfVision.VisionAngle / 2f, _coneOfVision.EulerAngles.y);
Vector3 visionAngleRight = MMMaths.DirectionFromAngle2D(_coneOfVision.VisionAngle / 2f, _coneOfVision.EulerAngles.y);
Handles.DrawLine(_coneOfVision.transform.position, _coneOfVision.transform.position + visionAngleLeft * _coneOfVision.VisionRadius);
Handles.DrawLine(_coneOfVision.transform.position, _coneOfVision.transform.position + visionAngleRight * _coneOfVision.VisionRadius);
foreach (Transform visibleTarget in _coneOfVision.VisibleTargets)
{
Handles.color = MMColors.Orange;
Handles.DrawLine(_coneOfVision.transform.position, visibleTarget.position);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5b5d530aed12d5f41b876b1237c161a7
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/Editor/MMVision/MMConeOfVision2DInspector.cs
uploadId: 830868

View File

@@ -0,0 +1,36 @@
using UnityEngine;
using System.Collections;
using MoreMountains.Tools;
using System.Collections.Generic;
using UnityEditor;
namespace MoreMountains.Tools
{
[CustomEditor(typeof(MMConeOfVision), true)]
public class MMConeOfVisionInspector : Editor
{
protected MMConeOfVision _coneOfVision;
protected virtual void OnSceneGUI()
{
// draws a circle around the character to represent the cone of vision's radius
_coneOfVision = (MMConeOfVision)target;
Handles.color = Color.yellow;
Handles.DrawWireArc(_coneOfVision.Center, Vector3.up, Vector3.forward, 360f, _coneOfVision.VisionRadius);
// draws two lines to mark the vision angle
Vector3 visionAngleLeft = MMMaths.DirectionFromAngle(-_coneOfVision.VisionAngle / 2f, _coneOfVision.EulerAngles.y);
Vector3 visionAngleRight = MMMaths.DirectionFromAngle(_coneOfVision.VisionAngle / 2f, _coneOfVision.EulerAngles.y);
Handles.DrawLine(_coneOfVision.Center, _coneOfVision.Center + visionAngleLeft * _coneOfVision.VisionRadius);
Handles.DrawLine(_coneOfVision.Center, _coneOfVision.Center + visionAngleRight * _coneOfVision.VisionRadius);
foreach (Transform visibleTarget in _coneOfVision.VisibleTargets)
{
Handles.color = MMColors.Orange;
Handles.DrawLine(_coneOfVision.Center, visibleTarget.position);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 887e928caeb50c74593acce11770f85f
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/Editor/MMVision/MMConeOfVisionInspector.cs
uploadId: 830868

View File

@@ -0,0 +1,3 @@
{
"reference": "GUID:d9dbf313afb206f458581847ac758375"
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: e4ca86eeefb9e704a9e99ebb71e8345d
AssemblyDefinitionReferenceImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 183370
packageName: Feel
packageVersion: 5.9.1
assetPath: Assets/Feel/MMTools/Accessories/Editor/MoreMountains.Tools.Accessories.Editor.asmref
uploadId: 830868

View File

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

View File

@@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Use this class to enable or disable other gameobjects automatically on Start or Awake
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Activation On Start")]
public class MMActivationOnStart : MonoBehaviour
{
/// The possible modes that define whether this should run at Awake or Start
public enum Modes { Awake, Start }
/// the selected mode for this instance
public Modes Mode = Modes.Start;
/// if true, objects will be activated on start, disabled otherwise
public bool StateOnStart = true;
/// the list of gameobjects whose active state will be affected on start
public List<GameObject> TargetObjects;
/// <summary>
/// On Awake, we set our state if needed
/// </summary>
protected virtual void Awake()
{
if (Mode != Modes.Awake)
{
return;
}
SetState();
}
/// <summary>
/// On Start, we set our state if needed
/// </summary>
protected virtual void Start()
{
if (Mode != Modes.Start)
{
return;
}
SetState();
}
/// <summary>
/// Sets the state of all target objects
/// </summary>
protected virtual void SetState()
{
foreach (GameObject obj in TargetObjects)
{
obj.SetActive(StateOnStart);
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 55a9829731bf3d3458319a5a829f1f04
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/MMActivation/MMActivationOnStart.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to store bindings
/// </summary>
[Serializable]
public class PlatformBindings
{
public enum PlatformActions { DoNothing, Disable }
public RuntimePlatform Platform = RuntimePlatform.WindowsPlayer;
public PlatformActions PlatformAction = PlatformActions.DoNothing;
}
/// <summary>
/// Add this class to a gameobject, and it'll enable/disable it based on platform context, using Application.platform to detect the platform
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Application Platform Activation")]
public class MMApplicationPlatformActivation : MonoBehaviour
{
/// the possible times at which this script can run
public enum ExecutionTimes { Awake, Start, OnEnable }
[Header("Settings")]
/// the selected execution time
public ExecutionTimes ExecutionTime = ExecutionTimes.Awake;
/// whether or not this should output a debug line in the console
public bool DebugToTheConsole = false;
[Header("Platforms")]
public List<PlatformBindings> Platforms;
/// <summary>
/// On Enable, processes the state if needed
/// </summary>
protected virtual void OnEnable()
{
if (ExecutionTime == ExecutionTimes.OnEnable)
{
Process();
}
}
/// <summary>
/// On Awake, processes the state if needed
/// </summary>
protected virtual void Awake()
{
if (ExecutionTime == ExecutionTimes.Awake)
{
Process();
}
}
/// <summary>
/// On Start, processes the state if needed
/// </summary>
protected virtual void Start()
{
if (ExecutionTime == ExecutionTimes.Start)
{
Process();
}
}
/// <summary>
/// Enables or disables the object based on current platform
/// </summary>
protected virtual void Process()
{
foreach (PlatformBindings platform in Platforms)
{
if (platform.Platform == Application.platform)
{
DisableIfNeeded(platform.PlatformAction, platform.Platform.ToString());
}
}
if (Application.platform == RuntimePlatform.Android)
{
}
}
/// <summary>
/// Disables the object if needed, and outputs a debug log if requested
/// </summary>
/// <param name="platform"></param>
/// <param name="platformName"></param>
protected virtual void DisableIfNeeded(PlatformBindings.PlatformActions platform, string platformName)
{
if (this.gameObject.activeInHierarchy && (platform == PlatformBindings.PlatformActions.Disable))
{
this.gameObject.SetActive(false);
if (DebugToTheConsole)
{
Debug.LogFormat(this.gameObject.name + " got disabled via MMPlatformActivation, platform : " + platformName + ".");
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 4b49077b56e67ff469bc52b6a64e5e17
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/MMActivation/MMApplicationPlatformActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// A data class to store auto execution info to be used in MMAutoExecution
/// </summary>
[System.Serializable]
public class MMAutoExecutionItem
{
/// if this is true, Event will be invoked on Awake
public bool AutoExecuteOnAwake;
/// if this is true, Event will be invoked on Enable
public bool AutoExecuteOnEnable;
/// if this is true, Event will be invoked on Disable
public bool AutoExecuteOnDisable;
/// if this is true, Event will be invoked on Start
public bool AutoExecuteOnStart;
/// if this is true, Event will be invoked on Instantiate (you'll need to send a OnInstantiate message for this to happen
public bool AutoExecuteOnInstantiate;
public UnityEvent Event;
}
/// <summary>
/// This simple class lets you trigger Unity events automatically, on Awake, Enable, Disable, Start, or on instantiate
/// For that last one, you'll want to send a "OnInstantiate" message when instantiating this object
/// </summary>
public class MMAutoExecution : MonoBehaviour
{
/// a list of events to trigger automatically
public List<MMAutoExecutionItem> Events;
/// <summary>
/// On Awake we invoke our events if needed
/// </summary>
protected virtual void Awake()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnAwake) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Start we invoke our events if needed
/// </summary>
protected virtual void Start()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnStart) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Enable we invoke our events if needed
/// </summary>
protected virtual void OnEnable()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnEnable) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Enable we invoke our events if needed
/// </summary>
protected virtual void OnDisable()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnDisable) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
/// <summary>
/// On Instantiate we invoke our events if needed
/// </summary>
protected virtual void OnInstantiate()
{
foreach (MMAutoExecutionItem item in Events)
{
if ((item.AutoExecuteOnInstantiate) && (item.Event != null))
{
item.Event.Invoke();
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 723c68a65280145479e4e0b2f94a6ff0
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/MMActivation/MMAutoExecution.cs
uploadId: 830868

View File

@@ -0,0 +1,46 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to a gameobject, and it'll let you enable target monos after all other targets have been disabled
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Conditional Activation")]
public class MMConditionalActivation : MonoBehaviour
{
/// a list of monos to enable
public MonoBehaviour[] EnableThese;
/// a list of all the monos that have to have been disabled first
public MonoBehaviour[] AfterTheseAreAllDisabled;
protected bool _enabled = false;
/// <summary>
/// On update, we check if we should disable
/// </summary>
protected virtual void Update()
{
if (_enabled)
{
return;
}
bool allDisabled = true;
foreach (MonoBehaviour component in AfterTheseAreAllDisabled)
{
if (component.isActiveAndEnabled)
{
allDisabled = false;
}
}
if (allDisabled)
{
foreach (MonoBehaviour component in EnableThese)
{
component.enabled = true;
}
_enabled = true;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 8434b53deaa9ae04f87f3c24bf70d482
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/MMActivation/MMConditionalActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,18 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to an object and it'll persist across scenes
/// </summary>
public class MMDontDestroyOnLoad : MonoBehaviour
{
/// <summary>
/// On Awake we make sure our object will not destroy on the next scene load
/// </summary>
protected void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c6dc6bc8e4bb2834e80531c648886d13
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/MMActivation/MMDontDestroyOnLoad.cs
uploadId: 830868

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
using UnityEngine.InputSystem;
#endif
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to store MMInputExecution bindings, associating a target keycode to UnityEvents
/// </summary>
[System.Serializable]
public class MMInputExecutionBinding
{
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
public Key TargetInputKey = Key.Space;
#else
/// the key the user needs to press to trigger events
public KeyCode TargetKey = KeyCode.Space;
#endif
/// the event to trigger when the key is pressed down
public UnityEvent OnKeyDown;
/// the event to trigger every frame if the key is being pressed
public UnityEvent OnKey;
/// the event to trigger when the key is released
public UnityEvent OnKeyUp;
/// <summary>
/// Checks for input and invokes events if needed
/// </summary>
public virtual void ProcessInput()
{
bool key = false;
bool keyDown = false;
bool keyUp = false;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
key = Keyboard.current[TargetInputKey].isPressed;
keyDown = Keyboard.current[TargetInputKey].wasPressedThisFrame;
keyUp = Keyboard.current[TargetInputKey].wasReleasedThisFrame;
#else
key = Input.GetKey(TargetKey);
keyDown = Input.GetKeyDown(TargetKey);
keyUp = Input.GetKeyUp(TargetKey);
#endif
if (OnKey != null)
{
if (key)
{
OnKey.Invoke();
}
}
if (OnKeyDown != null)
{
if (keyDown)
{
OnKeyDown.Invoke();
}
}
if (OnKeyUp != null)
{
if (keyUp)
{
OnKeyUp.Invoke();
}
}
}
}
/// <summary>
/// A simple class used to bind target keys to specific events to trigger when the key is pressed or released
/// </summary>
public class MMInputExecution : MonoBehaviour
{
[Header("Bindings")]
/// a list of bindings
public List<MMInputExecutionBinding> Bindings;
/// <summary>
/// On update we process our input
/// </summary>
protected virtual void Update()
{
HandleInput();
}
/// <summary>
/// Parses all bindings and asks them to trigger events if needed
/// </summary>
protected virtual void HandleInput()
{
if (Bindings == null)
{
return;
}
foreach(MMInputExecutionBinding binding in Bindings)
{
binding.ProcessInput();
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: af3876ae77702e24e8e1b06f675c0860
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/MMActivation/MMInputExecution.cs
uploadId: 830868

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// Attach this class to a collider and it'll let you trigger events when the user clicks/drags/enters/etc that collider
/// </summary>
public class MMOnMouse : MonoBehaviour
{
/// OnMouseDown is called when the user has pressed the mouse button while over the Collider.
[Tooltip("OnMouseDown is called when the user has pressed the mouse button while over the Collider.")]
public UnityEvent OnMouseDownEvent;
/// OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse.
[Tooltip("OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse.")]
public UnityEvent OnMouseDragEvent;
/// Called when the mouse enters the Collider.
[Tooltip("Called when the mouse enters the Collider.")]
public UnityEvent OnMouseEnterEvent;
/// Called when the mouse is not any longer over the Collider.
[Tooltip("Called when the mouse is not any longer over the Collider.")]
public UnityEvent OnMouseExitEvent;
/// Called every frame while the mouse is over the Collider.
[Tooltip("Called every frame while the mouse is over the Collider.")]
public UnityEvent OnMouseOverEvent;
/// OnMouseUp is called when the user has released the mouse button.
[Tooltip("OnMouseUp is called when the user has released the mouse button.")]
public UnityEvent OnMouseUpEvent;
/// OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed.
[Tooltip("OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed.")]
public UnityEvent OnMouseUpAsButtonEvent;
protected virtual void OnMouseDown()
{
OnMouseDownEvent.Invoke();
}
protected virtual void OnMouseDrag()
{
OnMouseDragEvent.Invoke();
}
protected virtual void OnMouseEnter()
{
OnMouseEnterEvent.Invoke();
}
protected virtual void OnMouseExit()
{
OnMouseExitEvent.Invoke();
}
protected virtual void OnMouseOver()
{
OnMouseOverEvent.Invoke();
}
protected virtual void OnMouseUp()
{
OnMouseUpEvent.Invoke();
}
protected virtual void OnMouseUpAsButton()
{
OnMouseUpAsButtonEvent.Invoke();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 80361f5e0185bb247a814457c589c1f3
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/MMActivation/MMOnMouse.cs
uploadId: 830868

View File

@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This component lets you parent the transform you put it on to any target parent (or to the root if none is set), on Awake, Start or anytime you call its Parent() method
/// </summary>
public class MMParentingOnStart : MonoBehaviour
{
/// the possible modes this can run on
public enum Modes { Awake, Start, Script }
/// the selected mode
public Modes Mode = Modes.Awake;
/// the parent to parent to, leave empty if you want to unparent completely
public Transform TargetParent;
/// <summary>
/// On Awake we parent if needed
/// </summary>
protected virtual void Awake()
{
if (Mode == Modes.Awake)
{
Parent();
}
}
/// <summary>
/// On Start we parent if needed
/// </summary>
protected virtual void Start()
{
if (Mode == Modes.Start)
{
Parent();
}
}
/// <summary>
/// Sets this transform's parent to the target
/// </summary>
public virtual void Parent()
{
this.transform.SetParent(TargetParent);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 996385a9b56b4d14eb03dc65ed309620
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/MMActivation/MMParentingOnStart.cs
uploadId: 830868

View File

@@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// This class will let you trigger a OnRandomInterval event periodically, at random intervals
/// </summary>
public class MMPeriodicExecution : MonoBehaviour
{
/// the min and max duration of the interval between two events, in seconds
[MMVector("Min", "Max")]
public Vector2 RandomIntervalDuration = new Vector2(1f, 3f);
/// the event to play at the end of each interval
public UnityEvent OnRandomInterval;
protected float _lastUpdateAt = 0f;
protected float _currentInterval = 0f;
/// <summary>
/// On Start we initialize our interval duration
/// </summary>
protected virtual void Start()
{
DetermineNewInterval();
}
/// <summary>
/// On Update we check if we've reached the end of an interval
/// </summary>
protected virtual void Update()
{
if (Time.time - _lastUpdateAt > _currentInterval)
{
OnRandomInterval?.Invoke();
_lastUpdateAt = Time.time;
DetermineNewInterval();
}
}
/// <summary>
/// Randomizes a new duration
/// </summary>
protected virtual void DetermineNewInterval()
{
_currentInterval = Random.Range(RandomIntervalDuration.x, RandomIntervalDuration.y);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b91c53058d9ddc04bbc92506986923a3
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/MMActivation/MMPeriodicExecution.cs
uploadId: 830868

View File

@@ -0,0 +1,230 @@
using UnityEngine;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this class to a gameobject, and it'll enable/disable it based on platform context, using conditional defintions to do so
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Platform Activation")]
public class MMPlatformActivation : MonoBehaviour
{
/// the possible times at which this script can run
public enum ExecutionTimes { Awake, Start, OnEnable }
public enum PlatformActions { DoNothing, Disable }
[Header("Settings")]
/// the selected execution time
public ExecutionTimes ExecutionTime = ExecutionTimes.Awake;
/// whether or not this should output a debug line in the console
public bool DebugToTheConsole = false;
[Header("Desktop")]
/// whether or not this gameobject should be active on Windows
public PlatformActions UNITY_STANDALONE_WIN = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on OSX
public PlatformActions UNITY_STANDALONE_OSX = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Linux
public PlatformActions UNITY_STANDALONE_LINUX = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on standalone
public PlatformActions UNITY_STANDALONE = PlatformActions.DoNothing;
[Header("Mobile")]
/// whether or not this gameobject should be active on iOS
public PlatformActions UNITY_IOS = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on iPhone
public PlatformActions UNITY_IPHONE = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Android
public PlatformActions UNITY_ANDROID = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Tizen
public PlatformActions UNITY_TIZEN = PlatformActions.DoNothing;
[Header("Console")]
/// whether or not this gameobject should be active on Wii
public PlatformActions UNITY_WII = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on PS4
public PlatformActions UNITY_PS4 = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on XBoxOne
public PlatformActions UNITY_XBOXONE = PlatformActions.DoNothing;
[Header("Others")]
/// whether or not this gameobject should be active on WebGL
public PlatformActions UNITY_WEBGL = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Lumin
public PlatformActions UNITY_LUMIN = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on TVOS
public PlatformActions UNITY_TVOS = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on WSA
public PlatformActions UNITY_WSA = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Facebook
public PlatformActions UNITY_FACEBOOK = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Ads
public PlatformActions UNITY_ADS = PlatformActions.DoNothing;
/// whether or not this gameobject should be active on Analytics
public PlatformActions UNITY_ANALYTICS = PlatformActions.DoNothing;
[Header("Active in Editor")]
/// whether or not this gameobject should be active in Editor
public PlatformActions UNITY_EDITOR = PlatformActions.DoNothing;
/// whether or not this gameobject should be active in Editor on Windows
public PlatformActions UNITY_EDITOR_WIN = PlatformActions.DoNothing;
/// whether or not this gameobject should be active in Editor on OSX
public PlatformActions UNITY_EDITOR_OSX = PlatformActions.DoNothing;
/// whether or not this gameobject should be active in Editor on Linux
public PlatformActions UNITY_EDITOR_LINUX = PlatformActions.DoNothing;
/// <summary>
/// On Enable, processes the state if needed
/// </summary>
protected virtual void OnEnable()
{
if (ExecutionTime == ExecutionTimes.OnEnable)
{
Process();
}
}
/// <summary>
/// On Awake, processes the state if needed
/// </summary>
protected virtual void Awake()
{
if (ExecutionTime == ExecutionTimes.Awake)
{
Process();
}
}
/// <summary>
/// On Start, processes the state if needed
/// </summary>
protected virtual void Start()
{
if (ExecutionTime == ExecutionTimes.Start)
{
Process();
}
}
/// <summary>
/// Enables or disables the object based on current platform
/// </summary>
protected virtual void Process()
{
// DESKTOP ----------------------------------------------------------------------------------
#if UNITY_STANDALONE_WIN
DisableIfNeeded(UNITY_STANDALONE_WIN, "Windows");
#endif
#if UNITY_STANDALONE_OSX
DisableIfNeeded(UNITY_STANDALONE_OSX, "OSX");
#endif
#if UNITY_STANDALONE_LINUX
DisableIfNeeded(UNITY_STANDALONE_LINUX, "Linux");
#endif
#if UNITY_STANDALONE
DisableIfNeeded(UNITY_STANDALONE, "Standalone");
#endif
// MOBILE ----------------------------------------------------------------------------------
#if UNITY_IOS
DisableIfNeeded(UNITY_IOS, "iOS");
#endif
#if UNITY_IPHONE
DisableIfNeeded(UNITY_IPHONE, "iPhone");
#endif
#if UNITY_ANDROID
DisableIfNeeded(UNITY_ANDROID, "Android");
#endif
#if UNITY_TIZEN
DisableIfNeeded(UNITY_TIZEN, "Tizen");
#endif
// CONSOLE ----------------------------------------------------------------------------------
#if UNITY_WII
DisableIfNeeded(UNITY_WII, "Wii");
#endif
#if UNITY_PS4
DisableIfNeeded(UNITY_PS4, "PS4");
#endif
#if UNITY_XBOXONE
DisableIfNeeded(UNITY_XBOXONE, "XBoxOne");
#endif
// CONSOLE ----------------------------------------------------------------------------------
#if UNITY_WEBGL
DisableIfNeeded(UNITY_WEBGL, "WebGL");
#endif
#if UNITY_LUMIN
DisableIfNeeded(UNITY_LUMIN, "Lumin");
#endif
#if UNITY_TVOS
DisableIfNeeded(UNITY_TVOS, "TV OS");
#endif
#if UNITY_WSA
DisableIfNeeded(UNITY_WSA, "WSA");
#endif
#if UNITY_FACEBOOK
DisableIfNeeded(UNITY_FACEBOOK, "Facebook");
#endif
#if UNITY_ADS
DisableIfNeeded(UNITY_ADS, "Ads");
#endif
#if UNITY_ANALYTICS
DisableIfNeeded(UNITY_ANALYTICS, "Analytics");
#endif
// EDITOR ----------------------------------------------------------------------------------
#if UNITY_EDITOR
DisableIfNeeded(UNITY_EDITOR, "Editor");
#endif
#if UNITY_EDITOR_WIN
DisableIfNeeded(UNITY_EDITOR_WIN, "Editor Windows");
#endif
#if UNITY_EDITOR_OSX
DisableIfNeeded(UNITY_EDITOR_OSX, "Editor OSX");
#endif
#if UNITY_EDITOR_LINUX
DisableIfNeeded(UNITY_EDITOR_LINUX, "Editor Linux");
#endif
}
/// <summary>
/// Disables the object if needed, and outputs a debug log if requested
/// </summary>
/// <param name="platform"></param>
/// <param name="platformName"></param>
protected virtual void DisableIfNeeded(PlatformActions platform, string platformName)
{
if (this.gameObject.activeInHierarchy && (platform == PlatformActions.Disable))
{
this.gameObject.SetActive(false);
if (DebugToTheConsole)
{
Debug.LogFormat(this.gameObject.name + " got disabled via MMPlatformActivation, platform : " + platformName + ".");
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5a39fcd2b055db14184fbda2b333f40c
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/MMActivation/MMPlatformActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,255 @@
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to an object and it'll be auto destroyed X seconds after its Start()
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Timed Activation")]
public class MMTimedActivation : MonoBehaviour
{
/// the possible activation modes
public enum TimedStatusChange { Enable, Disable, Destroy }
/// the possible trigger modes
public enum ActivationModes { Awake, Start, OnEnable, OnTriggerEnter, OnTriggerExit, OnTriggerEnter2D, OnTriggerExit2D, Script }
/// the possible ways to check if the collider matches
public enum TriggerModes { None, Tag, Layer }
/// the possible delay modes
public enum DelayModes { Time, Frames }
[Header("Trigger Mode")]
/// the moment you want the countdown to state change to start
public ActivationModes ActivationMode = ActivationModes.Start;
/// the target layer for activation if using OnTriggerEnter or OnTriggerExit
[MMEnumCondition("ActivationMode", (int)ActivationModes.OnTriggerEnter, (int)ActivationModes.OnTriggerExit)]
public TriggerModes TriggerMode;
/// the layer the target collider should be on
[MMEnumCondition("TriggerMode", (int)TriggerModes.Layer)]
public LayerMask TargetTriggerLayer;
/// the tag the target collider should have
[MMEnumCondition("TriggerMode", (int)TriggerModes.Tag)]
public string TargetTriggerTag;
[Header("Delay")]
/// the chosen delay mode, whether to wait in seconds or frames
public DelayModes DelayMode = DelayModes.Time;
/// The time (in seconds) before we destroy the object
[MMEnumCondition("DelayMode", (int)DelayModes.Time)]
public float TimeBeforeStateChange = 2;
/// the amount of frames to wait for when in Frames DelayMode
[MMEnumCondition("DelayMode", (int)DelayModes.Frames)]
public int FrameCount = 1;
[Header("Timed Activation")]
/// the possible targets you want the state to change
public List<GameObject> TargetGameObjects;
/// the possible targets you want the state to change
public List<MonoBehaviour> TargetBehaviours;
/// the destruction mode for this object : destroy or disable
public TimedStatusChange TimeDestructionMode = TimedStatusChange.Disable;
[Header("Actions")]
/// Unity events to trigger after the delay
public UnityEvent TimedActions;
/// <summary>
/// On awake, initialize our delay and trigger our change state countdown if needed
/// </summary>
protected virtual void Awake()
{
if (ActivationMode == ActivationModes.Awake)
{
StartChangeState();
}
}
/// <summary>
/// Call this method to start the countdown to activation
/// </summary>
public virtual void TriggerSequence()
{
StartChangeState();
}
/// <summary>
/// On start, trigger our change state countdown if needed
/// </summary>
protected virtual void Start()
{
if (ActivationMode == ActivationModes.Start)
{
StartChangeState();
}
}
/// <summary>
/// On enable, trigger our change state countdown if needed
/// </summary>
protected virtual void OnEnable()
{
if (ActivationMode == ActivationModes.OnEnable)
{
StartChangeState();
}
}
/// <summary>
/// On trigger enter, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerEnter(Collider collider)
{
if ((ActivationMode == ActivationModes.OnTriggerEnter) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
/// <summary>
/// On trigger exit, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerExit(Collider collider)
{
if ((ActivationMode == ActivationModes.OnTriggerExit) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
#if MM_PHYSICS2D
/// <summary>
/// On trigger enter 2D, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerEnter2D(Collider2D collider)
{
if ((ActivationMode == ActivationModes.OnTriggerEnter2D) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
/// <summary>
/// On trigger exit 2D, we start our countdown if needed
/// </summary>
/// <param name="collider"></param>
protected virtual void OnTriggerExit2D(Collider2D collider)
{
if ((ActivationMode == ActivationModes.OnTriggerExit2D) && (CorrectTagOrLayer(collider.gameObject)))
{
StartChangeState();
}
}
#endif
/// <summary>
/// Returns true if the target matches our settings, false otherwise
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
protected virtual bool CorrectTagOrLayer(GameObject target)
{
switch (TriggerMode)
{
case TriggerModes.None:
return true;
case TriggerModes.Layer:
if (((1 << target.layer) & TargetTriggerLayer) != 0)
{
return true;
}
else
{
return false;
}
case TriggerModes.Tag:
return (target.CompareTag(TargetTriggerTag));
}
return false;
}
/// <summary>
/// On start change state, starts the timed activation
/// </summary>
protected virtual void StartChangeState()
{
StartCoroutine(TimedActivationSequence());
}
/// <summary>
/// Waits and triggers state change and events
/// </summary>
protected virtual IEnumerator TimedActivationSequence()
{
if (DelayMode == DelayModes.Time)
{
yield return MMCoroutine.WaitFor(TimeBeforeStateChange);
}
else
{
yield return StartCoroutine(MMCoroutine.WaitForFrames(FrameCount));
}
StateChange();
Activate();
}
/// <summary>
/// Triggers actions if needed
/// </summary>
protected virtual void Activate()
{
if (TimedActions != null)
{
TimedActions.Invoke();
}
}
/// <summary>
/// Changes the object's status or destroys it
/// </summary>
protected virtual void StateChange()
{
foreach(GameObject targetGameObject in TargetGameObjects)
{
switch (TimeDestructionMode)
{
case TimedStatusChange.Destroy:
Destroy(targetGameObject);
break;
case TimedStatusChange.Disable:
targetGameObject.SetActive(false);
break;
case TimedStatusChange.Enable:
targetGameObject.SetActive(true);
break;
}
}
foreach (MonoBehaviour targetBehaviour in TargetBehaviours)
{
switch (TimeDestructionMode)
{
case TimedStatusChange.Destroy:
Destroy(targetBehaviour);
break;
case TimedStatusChange.Disable:
targetBehaviour.enabled = false;
break;
case TimedStatusChange.Enable:
targetBehaviour.enabled = true;
break;
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 46840d8dc203908469ee327b591ae35f
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/MMActivation/MMTimedActivation.cs
uploadId: 830868

View File

@@ -0,0 +1,45 @@
using UnityEngine;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this component to an object and it'll be auto destroyed X seconds after its Start()
/// </summary>
[AddComponentMenu("More Mountains/Tools/Activation/MM Timed Destruction")]
public class MMTimedDestruction : MonoBehaviour
{
/// the possible destruction modes
public enum TimedDestructionModes { Destroy, Disable }
/// the destruction mode for this object : destroy or disable
public TimedDestructionModes TimeDestructionMode = TimedDestructionModes.Destroy;
/// The time (in seconds) before we destroy the object
public float TimeBeforeDestruction=2;
/// <summary>
/// On Start(), we schedule the object's destruction
/// </summary>
protected virtual void Start ()
{
StartCoroutine(Destruction());
}
/// <summary>
/// Destroys the object after TimeBeforeDestruction seconds
/// </summary>
protected virtual IEnumerator Destruction()
{
yield return MMCoroutine.WaitFor(TimeBeforeDestruction);
if (TimeDestructionMode == TimedDestructionModes.Destroy)
{
Destroy(gameObject);
}
else
{
gameObject.SetActive(false);
}
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 9e71ad30bf1524741b90c1bd0354e1e0
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/MMActivation/MMTimedDestruction.cs
uploadId: 830868

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This very simple class simply exposes a method to toggle the GameObject it's on (or a target one if left empty in the inspector) active or inactive
/// </summary>
public class MMToggleActive : MonoBehaviour
{
[Header("Target - leave empty for self")]
/// the target gameobject to toggle. Leave blank for auto grab
public GameObject TargetGameObject;
/// a test button
[MMInspectorButton("ToggleActive")]
public bool ToggleActiveButton;
/// <summary>
/// On awake, grabs self if needed
/// </summary>
protected virtual void Awake()
{
if (TargetGameObject == null)
{
TargetGameObject = this.gameObject;
}
}
/// <summary>
/// Toggles the target gameobject's active state
/// </summary>
public virtual void ToggleActive()
{
TargetGameObject.SetActive(!TargetGameObject.activeInHierarchy);
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 3aad8b45814dc6f4cab32abed0a152b8
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/MMActivation/MMToggleActive.cs
uploadId: 830868

View File

@@ -0,0 +1,141 @@
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
[AddComponentMenu("More Mountains/Tools/Activation/MM Trigger And Collision")]
public class MMTriggerAndCollision : MonoBehaviour
{
public LayerMask CollisionLayerMask;
public UnityEvent OnCollisionEnterEvent;
public UnityEvent OnCollisionExitEvent;
public UnityEvent OnCollisionStayEvent;
public LayerMask TriggerLayerMask;
public UnityEvent OnTriggerEnterEvent;
public UnityEvent OnTriggerExitEvent;
public UnityEvent OnTriggerStayEvent;
public LayerMask Collision2DLayerMask;
public UnityEvent OnCollision2DEnterEvent;
public UnityEvent OnCollision2DExitEvent;
public UnityEvent OnCollision2DStayEvent;
public LayerMask Trigger2DLayerMask;
public UnityEvent OnTrigger2DEnterEvent;
public UnityEvent OnTrigger2DExitEvent;
public UnityEvent OnTrigger2DStayEvent;
// Collision 2D ------------------------------------------------------------------------------------
#if MM_PHYSICS2D
protected virtual void OnCollisionEnter2D (Collision2D collision)
{
if (Collision2DLayerMask.MMContains (collision.gameObject))
{
OnCollision2DEnterEvent.Invoke();
}
}
protected virtual void OnCollisionExit2D (Collision2D collision)
{
if (Collision2DLayerMask.MMContains (collision.gameObject))
{
OnCollision2DExitEvent.Invoke();
}
}
protected virtual void OnCollisionStay2D (Collision2D collision)
{
if (Collision2DLayerMask.MMContains (collision.gameObject))
{
OnCollision2DStayEvent.Invoke();
}
}
// Trigger 2D ------------------------------------------------------------------------------------
protected virtual void OnTriggerEnter2D (Collider2D collider)
{
if (Trigger2DLayerMask.MMContains (collider.gameObject))
{
OnTrigger2DEnterEvent.Invoke();
}
}
protected virtual void OnTriggerExit2D (Collider2D collider)
{
if (Trigger2DLayerMask.MMContains (collider.gameObject))
{
OnTrigger2DExitEvent.Invoke();
}
}
protected virtual void OnTriggerStay2D (Collider2D collider)
{
if (Trigger2DLayerMask.MMContains (collider.gameObject))
{
OnTrigger2DStayEvent.Invoke();
}
}
#endif
// Collision ------------------------------------------------------------------------------------
protected virtual void OnCollisionEnter(Collision c)
{
if (0 != (CollisionLayerMask.value & 1 << c.transform.gameObject.layer))
{
OnCollisionEnterEvent.Invoke();
}
}
protected virtual void OnCollisionExit(Collision c)
{
if (0 != (CollisionLayerMask.value & 1 << c.transform.gameObject.layer))
{
OnCollisionExitEvent.Invoke();
}
}
protected virtual void OnCollisionStay(Collision c)
{
if (0 != (CollisionLayerMask.value & 1 << c.transform.gameObject.layer))
{
OnCollisionStayEvent.Invoke();
}
}
// Trigger ------------------------------------------------------------------------------------
protected virtual void OnTriggerEnter (Collider collider)
{
if (TriggerLayerMask.MMContains (collider.gameObject))
{
OnTriggerEnterEvent.Invoke();
}
}
protected virtual void OnTriggerExit (Collider collider)
{
if (TriggerLayerMask.MMContains (collider.gameObject))
{
OnTriggerExitEvent.Invoke();
}
}
protected virtual void OnTriggerStay (Collider collider)
{
if (TriggerLayerMask.MMContains (collider.gameObject))
{
OnTriggerStayEvent.Invoke();
}
}
protected virtual void Reset()
{
Collision2DLayerMask = LayerMask.NameToLayer("Everything");
CollisionLayerMask = LayerMask.NameToLayer("Everything");
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 007ea1391362e4845aee91886eb0cda3
timeCreated: 1523908029
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/MMActivation/MMTriggerAndCollision.cs
uploadId: 830868

Some files were not shown because too many files have changed in this diff Show More