MonoScript

2019-10-15  本文已影响0人  泱千澈

Unity的cs脚本文件属于MonoScript资源,先来看看MonoScript的类定义

using System;
using UnityEngine;
using UnityEngine.Bindings;

namespace UnityEditor
{
    //
    // 摘要:
    //     Representation of Script assets.
    [NativeClass(null)]
    [NativeType("Editor/Mono/MonoScript.bindings.h")]
    public class MonoScript : TextAsset
    {
        public MonoScript();

        //
        // 摘要:
        //     Returns the MonoScript object containing specified MonoBehaviour.
        //
        // 参数:
        //   behaviour:
        //     The MonoBehaviour whose MonoScript should be returned.
        [FreeFunction]
        public static MonoScript FromMonoBehaviour(MonoBehaviour behaviour);
        //
        // 摘要:
        //     Returns the MonoScript object containing specified ScriptableObject.
        //
        // 参数:
        //   scriptableObject:
        //     The ScriptableObject whose MonoScript should be returned.
        [FreeFunction]
        public static MonoScript FromScriptableObject(ScriptableObject scriptableObject);
        //
        // 摘要:
        //     Returns the System.Type object of the class implemented by this script.
        public Type GetClass();
    }
}

MonoScript.FromMonoBehaviour来通过MonoBehaviour得到脚本MonoScript, MonoScript.text来得到整个类脚本文本
MonoScript.GetClass()这个方法有点特殊,返回Type

namespace TestFrame
{
    public class ClassA
    {
    }

    public class ClassB
    {
    }
}
namespace TestFrame
{
    public class ClassA
    {
    }

    public class SomeClass
    {
    }
}
namespace TestFrame
{
    public class SomeGenericClass<T>
    {
    }
}
上一篇 下一篇

猜你喜欢

热点阅读