2021-03-18 17:17:29 +11:00
|
|
|
|
#if MONO
|
|
|
|
|
using System;
|
2021-03-25 18:39:35 +11:00
|
|
|
|
using System.Collections;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityEngine.Events;
|
2021-04-07 17:20:09 +10:00
|
|
|
|
using UnityEngine.EventSystems;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityEngine.SceneManagement;
|
2021-03-26 19:49:53 +11:00
|
|
|
|
using UnityEngine.UI;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Core.Runtime.Mono
|
|
|
|
|
{
|
|
|
|
|
public class MonoProvider : RuntimeProvider
|
|
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2021-04-15 20:18:03 +10:00
|
|
|
|
ExplorerCore.Context = RuntimeContext.Mono;
|
2021-05-07 01:22:55 +10:00
|
|
|
|
//Reflection = new MonoReflection();
|
2021-03-18 17:17:29 +11:00
|
|
|
|
TextureUtil = new MonoTextureUtil();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetupEvents()
|
|
|
|
|
{
|
2021-03-30 19:50:04 +11:00
|
|
|
|
Application.logMessageReceived += Application_logMessageReceived;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
|
|
|
|
|
{
|
2021-04-22 20:11:34 +10:00
|
|
|
|
ExplorerCore.LogUnity(condition, type);
|
2021-03-18 17:17:29 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 17:20:09 +10:00
|
|
|
|
public override void StartCoroutine(IEnumerator routine)
|
2021-03-25 18:39:35 +11:00
|
|
|
|
{
|
2021-05-01 20:55:14 +10:00
|
|
|
|
ExplorerBehaviour.Instance.StartCoroutine(routine);
|
2021-03-25 18:39:35 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 17:20:09 +10:00
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override T AddComponent<T>(GameObject obj, Type type)
|
|
|
|
|
{
|
|
|
|
|
return (T)obj.AddComponent(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ScriptableObject CreateScriptable(Type type)
|
|
|
|
|
{
|
|
|
|
|
return ScriptableObject.CreateInstance(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void GraphicRaycast(GraphicRaycaster raycaster, PointerEventData data, List<RaycastResult> list)
|
|
|
|
|
{
|
|
|
|
|
raycaster.Raycast(data, list);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 17:17:29 +11:00
|
|
|
|
public override string LayerToName(int layer)
|
|
|
|
|
=> LayerMask.LayerToName(layer);
|
|
|
|
|
|
|
|
|
|
public override UnityEngine.Object[] FindObjectsOfTypeAll(Type type)
|
|
|
|
|
=> Resources.FindObjectsOfTypeAll(type);
|
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
//private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionUtility.AllFlags);
|
2021-03-18 17:17:29 +11:00
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
//public override int GetSceneHandle(Scene scene)
|
|
|
|
|
//{
|
|
|
|
|
// return (int)fi_Scene_handle.GetValue(scene);
|
|
|
|
|
//}
|
2021-03-18 17:17:29 +11:00
|
|
|
|
|
|
|
|
|
public override GameObject[] GetRootGameObjects(Scene scene)
|
|
|
|
|
{
|
2021-04-01 17:13:31 +11:00
|
|
|
|
if (!scene.isLoaded)
|
|
|
|
|
return new GameObject[0];
|
|
|
|
|
|
2021-03-18 17:17:29 +11:00
|
|
|
|
return scene.GetRootGameObjects();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetRootCount(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
return scene.rootCount;
|
|
|
|
|
}
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
2021-04-10 20:15:03 +10:00
|
|
|
|
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null,
|
|
|
|
|
Color? disabled = null)
|
2021-03-30 19:50:04 +11:00
|
|
|
|
{
|
2021-04-10 18:25:13 +10:00
|
|
|
|
var colors = selectable.colors;
|
|
|
|
|
|
2021-03-31 22:58:17 +11:00
|
|
|
|
if (normal != null)
|
|
|
|
|
colors.normalColor = (Color)normal;
|
|
|
|
|
|
|
|
|
|
if (highlighted != null)
|
|
|
|
|
colors.highlightedColor = (Color)highlighted;
|
|
|
|
|
|
|
|
|
|
if (pressed != null)
|
|
|
|
|
colors.pressedColor = (Color)pressed;
|
|
|
|
|
|
2021-04-10 20:15:03 +10:00
|
|
|
|
if (disabled != null)
|
|
|
|
|
colors.disabledColor = (Color)disabled;
|
|
|
|
|
|
2021-04-10 18:25:13 +10:00
|
|
|
|
SetColorBlock(selectable, colors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetColorBlock(Selectable selectable, ColorBlock colors)
|
|
|
|
|
{
|
|
|
|
|
selectable.colors = colors;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
}
|
2021-03-18 17:17:29 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 18:39:35 +11:00
|
|
|
|
public static class MonoExtensions
|
|
|
|
|
{
|
2021-03-30 19:50:04 +11:00
|
|
|
|
public static void AddListener(this UnityEvent _event, Action listener)
|
|
|
|
|
{
|
|
|
|
|
_event.AddListener(new UnityAction(listener));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddListener<T>(this UnityEvent<T> _event, Action<T> listener)
|
|
|
|
|
{
|
|
|
|
|
_event.AddListener(new UnityAction<T>(listener));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 20:18:03 +10:00
|
|
|
|
public static void RemoveListener(this UnityEvent _event, Action listener)
|
|
|
|
|
{
|
|
|
|
|
_event.RemoveListener(new UnityAction(listener));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RemoveListener<T>(this UnityEvent<T> _event, Action<T> listener)
|
|
|
|
|
{
|
|
|
|
|
_event.RemoveListener(new UnityAction<T>(listener));
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 18:39:35 +11:00
|
|
|
|
public static void Clear(this StringBuilder sb)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(0, sb.Length);
|
|
|
|
|
}
|
2021-03-26 19:49:53 +11:00
|
|
|
|
|
|
|
|
|
private static PropertyInfo pi_childControlHeight;
|
|
|
|
|
|
|
|
|
|
public static void SetChildControlHeight(this HorizontalOrVerticalLayoutGroup group, bool value)
|
|
|
|
|
{
|
|
|
|
|
if (pi_childControlHeight == null)
|
|
|
|
|
pi_childControlHeight = group.GetType().GetProperty("childControlHeight");
|
|
|
|
|
|
|
|
|
|
pi_childControlHeight?.SetValue(group, value, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static PropertyInfo pi_childControlWidth;
|
|
|
|
|
|
|
|
|
|
public static void SetChildControlWidth(this HorizontalOrVerticalLayoutGroup group, bool value)
|
|
|
|
|
{
|
|
|
|
|
if (pi_childControlWidth == null)
|
|
|
|
|
pi_childControlWidth = group.GetType().GetProperty("childControlWidth");
|
|
|
|
|
|
|
|
|
|
pi_childControlWidth?.SetValue(group, value, null);
|
|
|
|
|
}
|
2021-03-25 18:39:35 +11:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 17:17:29 +11:00
|
|
|
|
#endif
|