浏览代码

Handle Presence of Modules (#48)

* Updated Changelog

* Handle Physics2D module

* Added WarnDisabledModule Attribute

* Handle Screen Capture Module
/main
GitHub 3 年前
当前提交
7a8b672f
共有 11 个文件被更改,包括 100 次插入9 次删除
  1. 1
      CHANGELOG.md
  2. 14
      Editor/CustomInspectors/PingableEditor.cs
  3. 19
      Runtime/Attributes/CallableAttribute.cs
  4. 14
      Runtime/GameplayIngredients.asmdef
  5. 7
      Runtime/LevelScripting/Actions/TakeScreenshotAction.cs
  6. 9
      Runtime/LevelScripting/Events/OnCollider2DEvent.cs
  7. 9
      Runtime/LevelScripting/Events/OnTrigger2DEvent.cs
  8. 1
      Runtime/LevelScripting/Events/OnTriggerEvent.cs
  9. 7
      Runtime/Managers/Implementations/ScreenshotManager.cs
  10. 17
      Runtime/Attributes/WarnDisabledModuleAttribute.cs
  11. 11
      Runtime/Attributes/WarnDisabledModuleAttribute.cs.meta

1
CHANGELOG.md


* Fixed Callable Reorderable List Undo
* Fixed Out of sync Ingredients explorer Window : now Syncs upon Selection Change.
* Handle Presence of Optional Modules
## 2020.2.5

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;
}

14
Runtime/GameplayIngredients.asmdef


{
"name": "GameplayIngredients",
"rootNamespace": "",
"references": [
"NaughtyAttributes.Core",
"Cinemachine",

"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "MODULE_PHYSICS2D"
},
{
"name": "com.unity.modules.screencapture",
"expression": "1.0.0",
"define": "MODULE_SCREENCAPTURE"
}
],
"noEngineReferences": false
}

7
Runtime/LevelScripting/Actions/TakeScreenshotAction.cs


namespace GameplayIngredients.Actions
{
#if !MODULE_SCREENCAPTURE
[WarnDisabledModule("Screen Capture")]
#endif
[AddComponentMenu(ComponentMenu.actionsPath + "Take Screenshot Action")]
[Callable("Screen", "Actions/ic-action-screen.png")]
public class TakeScreenshotAction : ActionBase

public override void Execute(GameObject instigator = null)
{
#if MODULE_SCREENCAPTURE
#else
Debug.Log("TakeScreenshotAction Cannot Take Screenshot : Unity Module Screen Capture is Disabled.");
#endif
}
public override string GetDefaultName()

9
Runtime/LevelScripting/Events/OnCollider2DEvent.cs


namespace GameplayIngredients.Events
{
#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
}
}

9
Runtime/LevelScripting/Events/OnTrigger2DEvent.cs


namespace GameplayIngredients.Events
{
#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

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;

7
Runtime/Managers/Implementations/ScreenshotManager.cs


namespace GameplayIngredients
{
#if !MODULE_SCREENCAPTURE
[WarnDisabledModule("Screen Capture")]
#endif
[AddComponentMenu(ComponentMenu.managersPath + "Screenshot Manager")]
[ManagerDefaultPrefab("ScreenshotManager")]
public class ScreenshotManager : Manager

{
if (Input.GetKeyDown(ScreenshotKeyCode))
{
#if MODULE_SCREENCAPTURE
var now = System.DateTime.Now;
Callable.Call(OnBeforeScreenshot);
string path = $"{Application.dataPath}/../{Prefix}-{now.Year}{now.Month}{now.Day}-{now.Hour}{now.Minute}{now.Second}{now.Millisecond}.png";

#else
Debug.Log("Screenshot Manager Cannot Take Screenshot : Unity Module Screen Capture is Disabled.");
#endif
}
}
}

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:
正在加载...
取消
保存