简要笔记
判断脚本是否继承了某个对象
public TestForCheck obj
void Start()
{
#region 方法1,判断是否继承了某个接口或者类
Type t = typeof(IActionForLicenseCheck);
Type tt = typeof(TestForCheck);
Debug.Log("方法1:"+t.IsAssignableFrom(tt));
#endregion
#region 方法2,判断是否继承了某个接口
Debug.Log("方法2:" + obj.GetType().GetInterfaces().Contains(typeof(IActionForLicenseCheck)));
#endregion
}
返回指定游戏对象的指定接口
///
/// 返回指定游戏对象上是否存在指定的接口
///
/// 指定的接口
/// 指定的游戏对象
/// 返回接口
public static Interface GetInterface(GameObject Go) where Interface : class
{
return Go.GetComponent(typeof(Interface)) as Interface;
}
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;