浏览代码

Added WarnDisabledModule Attribute

/refactor-handle-modules
Thomas ICHÉ 3 年前
当前提交
8180bfc4
共有 7 个文件被更改,包括 73 次插入13 次删除
  1. 14
      Editor/CustomInspectors/PingableEditor.cs
  2. 19
      Runtime/Attributes/CallableAttribute.cs
  3. 13
      Runtime/LevelScripting/Events/OnCollider2DEvent.cs
  4. 11
      Runtime/LevelScripting/Events/OnTrigger2DEvent.cs
  5. 1
      Runtime/LevelScripting/Events/OnTriggerEvent.cs
  6. 17
      Runtime/Attributes/WarnDisabledModuleAttribute.cs
  7. 11
      Runtime/Attributes/WarnDisabledModuleAttribute.cs.meta

14
Editor/CustomInspectors/PingableEditor.cs


using NaughtyAttributes.Editor;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;

{
public bool needRepaint { get => m_pingValue > 0; }
float m_pingValue;
WarnDisabledModuleAttribute m_RequiredModule;
static MonoBehaviour m_NextToPing;
static Dictionary<MonoBehaviour, PingableEditor> trackedEditors;

if (!trackedEditors.ContainsKey(serializedObject.targetObject as MonoBehaviour))
trackedEditors.Add(serializedObject.targetObject as MonoBehaviour, this);
m_RequiredModule = serializedObject.targetObject.GetType().GetCustomAttribute<WarnDisabledModuleAttribute>();
}
protected override void OnDisable()

public override void OnInspectorGUI()
{
if(m_RequiredModule != null)
{
EditorGUILayout.HelpBox($"This Script Requires the {m_RequiredModule.module} module : It will not execute until you enable the module in the Package Manager.", MessageType.Warning);
EditorGUILayout.Space();
}
EditorGUI.BeginDisabledGroup(m_RequiredModule != null);
Rect r = EditorGUILayout.BeginVertical();
UpdatePing(r);

if (needRepaint)
Repaint();
EditorGUI.EndDisabledGroup();
}
public static void PingObject(MonoBehaviour r)

19
Runtime/Attributes/CallableAttribute.cs


using System;
[AttributeUsage(AttributeTargets.Class)]
public class CallableAttribute : Attribute
namespace GameplayIngredients
public string category;
public string iconPath;
public CallableAttribute(string category = "", string iconName = "")
[AttributeUsage(AttributeTargets.Class)]
public class CallableAttribute : Attribute
this.category = category;
this.iconPath = iconName;
public string category;
public string iconPath;
public CallableAttribute(string category = "", string iconName = "")
{
this.category = category;
this.iconPath = iconName;
}

13
Runtime/LevelScripting/Events/OnCollider2DEvent.cs


#if MODULE_PHYSICS2D
using NaughtyAttributes;
using NaughtyAttributes;
#if !MODULE_PHYSICS2D
[WarnDisabledModule("Physics 2D")]
#endif
#if MODULE_PHYSICS2D
#endif
public class OnCollider2DEvent : EventBase
{
public Callable[] onCollisionEnter;

[EnableIf("OnlyInteractWithTag")]
public string Tag = "Player";
#if MODULE_PHYSICS2D
private void OnCollisionEnter2D(Collision2D other)
{
if (OnlyInteractWithTag && other.collider.tag == Tag)

Callable.Call(onCollisionExit, other.collider.gameObject);
}
}
#endif
}
#endif
}

11
Runtime/LevelScripting/Events/OnTrigger2DEvent.cs


#if MODULE_PHYSICS2D
#if !MODULE_PHYSICS2D
[WarnDisabledModule("Physics 2D")]
#endif
#if MODULE_PHYSICS2D
[RequireComponent(typeof(Collider2D))]
#endif
public class OnTrigger2DEvent : EventBase
{
public Callable[] onTriggerEnter;

[EnableIf("OnlyInteractWithTag")]
public string Tag = "Player";
#if MODULE_PHYSICS2D
private void OnTriggerEnter2D(Collider2D other)
{
if (OnlyInteractWithTag && other.tag == Tag )

Callable.Call(onTriggerExit, other.gameObject);
}
}
#endif
#endif

1
Runtime/LevelScripting/Events/OnTriggerEvent.cs


{
[AddComponentMenu(ComponentMenu.eventsPath + "On Trigger Event")]
[AdvancedHierarchyIcon("Packages/net.peeweek.gameplay-ingredients/Icons/Events/ic-event-trigger.png")]
[RequireComponent(typeof(Collider))]
public class OnTriggerEvent : EventBase
{
public Callable[] onTriggerEnter;

17
Runtime/Attributes/WarnDisabledModuleAttribute.cs


using System;
namespace GameplayIngredients
{
[AttributeUsage(AttributeTargets.Class)]
public class WarnDisabledModuleAttribute : Attribute
{
public string module;
public WarnDisabledModuleAttribute(string module)
{
this.module = module;
}
}
}

11
Runtime/Attributes/WarnDisabledModuleAttribute.cs.meta


fileFormatVersion: 2
guid: 74b211a1354ee114ea4d2f79cbe73a69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存