当前位置: 首页>>代码示例>>C#>>正文


C# MonoScript.GetClass方法代码示例

本文整理汇总了C#中UnityEditor.MonoScript.GetClass方法的典型用法代码示例。如果您正苦于以下问题:C# MonoScript.GetClass方法的具体用法?C# MonoScript.GetClass怎么用?C# MonoScript.GetClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEditor.MonoScript的用法示例。


在下文中一共展示了MonoScript.GetClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

 private void Init(MonoScript script)
 {
     this.m_Initialized = true;
     this.m_ScriptClass = script.GetClass();
     this.m_NetworkChannelLabel = new GUIContent("Network Channel", "QoS channel used for updates. Use the [NetworkSettings] class attribute to change this.");
     this.m_NetworkSendIntervalLabel = new GUIContent("Network Send Interval", "Maximum update rate in seconds. Use the [NetworkSettings] class attribute to change this, or implement GetNetworkSendInterval");
     foreach (System.Reflection.FieldInfo info in this.m_ScriptClass.GetFields(BindingFlags.Public | BindingFlags.Instance))
     {
         Attribute[] customAttributes = (Attribute[]) info.GetCustomAttributes(typeof(SyncVarAttribute), true);
         if (customAttributes.Length > 0)
         {
             this.m_SyncVarNames.Add(info.Name);
         }
     }
     MethodInfo method = script.GetClass().GetMethod("OnSerialize");
     if ((method != null) && (method.DeclaringType != typeof(NetworkBehaviour)))
     {
         this.m_HasOnSerialize = true;
     }
     int num2 = 0;
     foreach (System.Reflection.FieldInfo info3 in base.serializedObject.targetObject.GetType().GetFields())
     {
         if ((info3.FieldType.BaseType != null) && info3.FieldType.BaseType.Name.Contains("SyncList"))
         {
             num2++;
         }
     }
     if (num2 > 0)
     {
         this.m_ShowSyncLists = new bool[num2];
     }
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:32,代码来源:NetworkBehaviourInspector.cs

示例2: IsCustomizableScript

        private static bool IsCustomizableScript(MonoScript script)
        {
            bool isCustomizable = false;

            Type scriptClass = script.GetClass();
            if (scriptClass != null)
            {
                isCustomizable = scriptClass.IsSubclassOf(typeof(MonoBehaviour)) || scriptClass.IsSubclassOf(typeof(ScriptableObject));
            }

            return isCustomizable;
        }
开发者ID:Doy32,项目名称:Samurai,代码行数:12,代码来源:UICreatorContext.cs

示例3: OnInspectorGUI

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (Application.isPlaying)
            return;

        MCP_AI.Environment myTarget = (MCP_AI.Environment)target;
        myTarget.AttackerControllerType =(MCP_AI.AgentAI.OPTIONS)EditorGUILayout.EnumPopup("Attacker Controller Type",myTarget.AttackerControllerType);
        if (myTarget.AttackerControllerType == MCP_AI.AgentAI.OPTIONS.CustomAI)
        {
            aS = EditorGUILayout.ObjectField("Controller Class", aS, typeof(MonoScript), false) as MonoScript;
            if (aS != null && aS.GetClass().BaseType.Equals(typeof(MCP_AI.AIController)))
            {
                myTarget.AttackController = aS.GetClass().Name;
            }
        }
        else
        {
            myTarget.AttackController = GetClassName(myTarget.AttackerControllerType, null);
        }

        myTarget.DefenderControllerType = (MCP_AI.AgentAI.OPTIONS)EditorGUILayout.EnumPopup("Defender Controller Type", myTarget.DefenderControllerType);
        if (myTarget.DefenderControllerType == MCP_AI.AgentAI.OPTIONS.CustomAI)
        {
            dS = EditorGUILayout.ObjectField("Controller Class", dS, typeof(MonoScript), false) as MonoScript;
            if (dS != null && dS.GetClass().BaseType.Equals(typeof(MCP_AI.AIController)))
            {

                myTarget.DefendController = dS.GetClass().Name;
            }
        }
        else
        {
            myTarget.DefendController = GetClassName(myTarget.DefenderControllerType, null);
        }
    }
开发者ID:valentincr,项目名称:MCP20132014,代码行数:37,代码来源:ControllerEditor.cs

示例4: Init

 private void Init(MonoScript script)
 {
   this.m_Initialized = true;
   this.m_ScriptClass = script.GetClass();
   this.m_NetworkChannelLabel = new GUIContent("Network Channel", "QoS channel used for updates. Use the [NetworkSettings] class attribute to change this.");
   this.m_NetworkSendIntervalLabel = new GUIContent("Network Send Interval", "Maximum update rate in seconds. Use the [NetworkSettings] class attribute to change this, or implement GetNetworkSendInterval");
   foreach (System.Reflection.FieldInfo field in this.m_ScriptClass.GetFields(BindingFlags.Instance | BindingFlags.Public))
   {
     if (((Attribute[]) field.GetCustomAttributes(typeof (SyncVarAttribute), true)).Length > 0)
       this.m_SyncVarNames.Add(field.Name);
   }
   MethodInfo method = script.GetClass().GetMethod("OnSerialize");
   if (method != null && method.DeclaringType != typeof (NetworkBehaviour))
     this.m_HasOnSerialize = true;
   int length = 0;
   foreach (System.Reflection.FieldInfo field in this.serializedObject.targetObject.GetType().GetFields())
   {
     if (field.FieldType.BaseType != null && field.FieldType.BaseType.Name.Contains("SyncList"))
       ++length;
   }
   if (length <= 0)
     return;
   this.m_ShowSyncLists = new bool[length];
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:24,代码来源:NetworkBehaviourInspector.cs

示例5: GetClassName

    private string GetClassName(MCP_AI.AgentAI.OPTIONS option,MonoScript ms)
    {
        switch (option)
        {
            case MCP_AI.AgentAI.OPTIONS.FSMAI:
                return typeof(FSM.FSMAI).Name;

            case MCP_AI.AgentAI.OPTIONS.BTAI:
                return typeof(BT.BTAI).Name;

            case MCP_AI.AgentAI.OPTIONS.RandomAI:
                return typeof(RandomAI).Name;
            case MCP_AI.AgentAI.OPTIONS.CustomAI:
                return ms.GetClass().Name;

        }
        return null;
    }
开发者ID:valentincr,项目名称:MCP20132014,代码行数:18,代码来源:ControllerEditor.cs

示例6: GetNameToPropertyDictionary

		GetNameToPropertyDictionary(MonoScript script)
	{
		List<OCPropertyField> allPropertiesAndFields = new List<OCPropertyField>();

		System.Type currentType = script.GetClass();
//		UnityEngine.Object monoBehaviour = AssetDatabase.GetAllAssetPaths().Select(p => AssetDatabase.LoadAssetAtPath(p, currentType) ).FirstOrDefault();

//		Debug.Log("Step 1");

		if(currentType.IsSubclassOf(typeof(MonoBehaviour)))
		{
					Object[] objects = Resources.FindObjectsOfTypeAll(currentType);

//			Debug.Log("Step 2");

			if(objects.Length != 0)
			{

//				Debug.Log("Step 3");
					allPropertiesAndFields =
						OCPropertyField.GetAllPropertiesAndFields
						( objects[0]
						, null
						, OCExposePropertyFieldsAttribute.OCExposure.PropertiesAndFields
						);
			}
		}

		if(allPropertiesAndFields != null)
			return allPropertiesAndFields.ToDictionary( p => p.PrivateName );
		else
			return null;
	}
开发者ID:virneo,项目名称:unity3d-opencog-game,代码行数:33,代码来源:OCAutomatedScriptScanner.cs

示例7: FromMonoScriptAsset

 //PRIVATE
 // PUBLIC STATIC
 /// <summary>
 /// Froms the mono script asset.
 /// </summary>
 /// <returns>
 /// The mono script asset.
 /// </returns>
 /// <param name='aCandidate_monoscript'>
 /// A mono script.
 /// </param>
 /// <param name='aInUseScriptableObjects'>
 /// A scriptable objects.
 /// </param>
 /// <param name='aManagers_serializedproperty'>
 /// A managers_serializedproperty.
 /// </param>
 public static UMOMManagerCandidate FromMonoScriptAsset(MonoScript aCandidate_monoscript, List<ScriptableObject> aInUseScriptableObjects, SerializedProperty aManagers_serializedproperty)
 {
     MonoScript monoScriptMatchingCandidate;
     ScriptableObject winningCandidate_scriptableobject = null;
     //FIND THE SCRIPTABLE OBJECT THAT MATCHES THE MONOSCRIPT
     foreach (ScriptableObject scriptableObject in aInUseScriptableObjects) {
         monoScriptMatchingCandidate  = MonoScript.FromScriptableObject (scriptableObject);
         if (monoScriptMatchingCandidate.GetClass().FullName == aCandidate_monoscript.GetClass().FullName) {
             //Debug.Log ("	s: " + monoScriptMatchingCandidate.GetClass().FullName );
             winningCandidate_scriptableobject = scriptableObject;
             break;
         }
     }
     //Debug.Log (" SO : " + winningCandidate_scriptableobject);
     UMOMManagerCandidate managerCandidate = new UMOMManagerCandidate (aCandidate_monoscript, winningCandidate_scriptableobject, aManagers_serializedproperty);
     return managerCandidate;
 }
开发者ID:RivelloMultimediaConsulting,项目名称:CodeSamplesPrivate,代码行数:34,代码来源:UMOMManagerCandidate.cs

示例8: GetSingletonPath

		/// <summary>
		/// 	Gets the asset path for the SingletonHydraMonoBehaviour.
		/// </summary>
		/// <returns>The singleton path.</returns>
		/// <param name="script">Script.</param>
		private static string GetSingletonPath(MonoScript script)
		{
			string dataPath = Application.dataPath;
			dataPath = Path.GetDirectoryName(dataPath);

			string local = ReflectionUtils.GetPropertyByName(script.GetClass(), "assetPath").GetValue(null, null) as string;
			return string.Format("{0}/{1}", dataPath, local);
		}
开发者ID:JustJessTV,项目名称:GitMergeTest,代码行数:13,代码来源:ScriptableObjectUtils.cs

示例9: IsSingleton

		/// <summary>
		/// 	Determines if the script is a singleton scriptable object.
		/// </summary>
		/// <returns><c>true</c> if is singleton; otherwise, <c>false</c>.</returns>
		/// <param name="script">Script.</param>
		private static bool IsSingleton(MonoScript script)
		{
			Type toCheck = script.GetClass();
			Type generic = typeof(SingletonHydraScriptableObject<>);

			return ReflectionUtils.IsSubclassOfRawGeneric(generic, toCheck);
		}
开发者ID:JustJessTV,项目名称:GitMergeTest,代码行数:12,代码来源:ScriptableObjectUtils.cs

示例10: OnGUI

        private void OnGUI()
        {
            const int X = 3;
            const int Height = 20;
            const int Offset = 2;

            int y = 3;
            float width = this.position.width - 2 * X;

            // Show selection field for the user.
            monoScript =
                (MonoScript)
                EditorGUI.ObjectField(
                    new Rect(X, y, width, Height), "Mono Behaviour", monoScript, typeof(MonoScript), false);

            // Show error message if no mono behaviour selected.
            y += Height + Offset;

            if (monoScript == null)
            {
                EditorGUI.LabelField(new Rect(X, y, width, Height), "Missing:", "Select a behaviour first!");
                return;
            }

            if (monoScript.GetClass() == null || !typeof(MonoBehaviour).IsAssignableFrom(monoScript.GetClass()))
            {
                EditorGUI.LabelField(
                    new Rect(X, y, width, Height),
                    "Missing:",
                    string.Format("{0} is no MonoBehaviour.", monoScript.name));
                return;
            }

            // Clear found usages if selection changed.
            if (monoBehaviourType != monoScript.GetClass())
            {
                monoBehaviourType = monoScript.GetClass();
                usages = null;
            }

            // Show Find Usages button.
            if (GUI.Button(new Rect(X, y, width, Height), "Find Prefabs"))
            {
                FindUsages();
            }

            if (usages == null)
            {
                return;
            }

            // Show found usages.
            foreach (GameObject prefab in usages)
            {
                y += Height + Offset;

                EditorGUILayout.BeginHorizontal();

                EditorGUI.LabelField(new Rect(X, y, width / 2, Height), prefab.name);

                if (GUI.Button(new Rect(X + width / 2, y, width / 2, Height), "Navigate To"))
                {
                    NavigateTo(prefab);
                    return;
                }

                EditorGUILayout.EndHorizontal();
            }
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:69,代码来源:FindMonoBehaviourUsages.cs

示例11: CanHaveEditor

    bool CanHaveEditor(MonoScript m)
    {
        if (m.GetClass() == null)
            return false;

        if (m.GetClass().IsSubclassOf(typeof(MonoBehaviour)))
            return true;

        if (m.GetClass().IsSubclassOf(typeof(ScriptableObject)))
        {
            if (!m.GetClass().IsSubclassOf(typeof(Editor)) && !m.GetClass().IsSubclassOf(typeof(EditorWindow)))
                return true;
        }

        return false;
    }
开发者ID:keplergames,项目名称:TowerDefence2D,代码行数:16,代码来源:InspectorPlusWindow.cs

示例12: ScriptMatcher

		public ScriptMatcher( MonoScript script )
		{
			this.script = script;
			this.type = script.GetClass();
			this.fields = GetAllFields( type ).ToList();
		}
开发者ID:TobyDGosselin,项目名称:Star-Sector,代码行数:6,代码来源:MissingScriptResolver.cs

示例13: OnGUI

    void OnGUI()
    {
        Type targetType;

        if (jsonSerializer == null)
        {
            Start();
        }

        var dirPath = new DirectoryInfo("Assets/Scripts/Abilities/");
        FileInfo[] fileInfo = dirPath.GetFiles();
        List<string> fileNames = new List<string>();
        for(int i = 0; i < fileInfo.Length; i++)
        {
            if (!fileInfo[i].Name.Contains("meta") && !fileInfo[i].Name.Equals("Ability.cs"))
            {
                fileNames.Add(fileInfo[i].Name);
            }
        }
        int newscript = EditorGUILayout.Popup("TasteTranslation:",chosenScript, fileNames.ToArray());
        if(newscript != chosenScript)
        {
            chosenScript = newscript;
            tempAbility = null;
        }
        abilityScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Abilities/"+ fileNames[chosenScript]);
        targetType = abilityScript.GetClass();
        if (tempAbility == null)
        {
            tempAbility = (Ability)Activator.CreateInstance(targetType);
        }
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("id: ", database.Count.ToString());
        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                info.SetValue(tempAbility, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempAbility)));

            }else if(fieldType == typeof(string))
            {
                info.SetValue(tempAbility, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempAbility)));
            }
            else if (fieldType == typeof(bool))
            {
                info.SetValue(tempAbility, EditorGUILayout.Toggle(info.Name, (bool)info.GetValue(tempAbility)));
            }
        }

        EditorGUILayout.EndVertical();

        if (GUILayout.Button("submit"))
        {
            textWriter = new StreamWriter(Application.dataPath + itemFileName);
            jsonWriter = new JsonTextWriter(textWriter);
            database.Add(tempAbility);
            String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            textWriter.Write(text);

            textWriter.Close();
            textWriter.Dispose();
            jsonWriter.Close();

            tempAbility = null;
        }
    }
开发者ID:toninhoPinto,项目名称:Monster-Chef,代码行数:71,代码来源:DBAbilitiesWindow.cs

示例14: OnGUI

    void OnGUI()
    {
        Type targetType;
        charScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Enemies/Enemies.cs");
        if (jsonSerializer == null)
        {
            Start();
        }
        targetType = charScript.GetClass();
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("id: ", database.Count.ToString());

        if (reorderableList == null)
        {
            reorderableList = new ReorderableList(charAbilities, typeof(int),
                false, true, true, true);

            reorderableList.drawElementCallback =
                (Rect rect, int index, bool isActive, bool isFocused) => {
                    var element = reorderableList.list[index];
                    rect.y += 2;
                    reorderableList.list[index] = EditorGUI.IntField(
                        new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
                        (int)element);
                };
        }
        reorderableList.DoLayoutList();

        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                info.SetValue(tempEnemy, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempEnemy)));
            }
            else if (fieldType == typeof(string))
            {
                info.SetValue(tempEnemy, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempEnemy)));
            }
            else if (fieldType == typeof(float))
            {
                info.SetValue(tempEnemy, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempEnemy)));
            }
            else if (fieldType == typeof(Enemies.EnemyStats)) //struct
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (tempStruct == null)
                {
                    tempStruct = new Enemies.EnemyStats();
                    info.SetValue(tempEnemy, (Enemies.EnemyStats)tempStruct);
                }

                foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
                {
                    Type fieldTypeInStruct = infoInStruct.FieldType;

                    if (fieldTypeInStruct == typeof(float))
                    {
                        infoInStruct.SetValue(tempStruct, EditorGUILayout.FloatField(infoInStruct.Name, (float)infoInStruct.GetValue(info.GetValue(tempEnemy)) ));
                    }
                }

                info.SetValue(tempEnemy, (Enemies.EnemyStats)tempStruct);
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }
            else if (fieldType == typeof(List<int>))
            {
                info.SetValue(tempEnemy, charAbilities);
            }

        }

        EditorGUILayout.EndVertical();

        if (GUILayout.Button("submit"))
        {
            textWriter = new StreamWriter(Application.dataPath + itemFileName);
            jsonWriter = new JsonTextWriter(textWriter);
            database.Add(tempEnemy);
            String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            textWriter.Write(text);

            textWriter.Close();
            textWriter.Dispose();
            jsonWriter.Close();

            tempEnemy = new Enemies();
            tempStruct = null;
            reorderableList = null;
            charAbilities = new List<int>();
        }
    }
开发者ID:toninhoPinto,项目名称:Monster-Chef,代码行数:98,代码来源:DBEnemies.cs

示例15: OnGUI

    void OnGUI()
    {
        Type targetType;
        simpleFood = EditorGUILayout.Toggle("Is Simple Food", simpleFood);
        if (simpleFood)
        {
            mainIngredient = EditorGUILayout.Toggle("Is Main Ingredient", mainIngredient);
            if (mainIngredient)
            {
                itemScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Items/Food/MainIngredient.cs");
                targetType = itemScript.GetClass();
                if (tempItem == null || tempItem.GetType() != targetType)
                {
                    tempItem = new MainIngredient();
                }
            }
            else
            {
                itemScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Items/Food/Accompaniment.cs");
                targetType = itemScript.GetClass();
                if (tempItem == null || tempItem.GetType() != targetType)
                {
                    tempItem = new Accompaniment();
                }
            }
        }
        else
        {
            itemScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Items/Food/ComposedFood.cs");
            targetType = itemScript.GetClass();
            if (tempItem == null || tempItem.GetType() != targetType)
            {
                tempItem = new ComposedFood();
            }

            if (reorderableList == null)
            {
                reorderableList = new ReorderableList(listInputRecipe, typeof(int),
                    false, true, true, true);

                reorderableList.drawElementCallback =
                    (Rect rect, int index, bool isActive, bool isFocused) => {
                        var element = reorderableList.list[index];
                        rect.y += 2;
                        reorderableList.list[index] = EditorGUI.IntField(
                            new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
                            (int)element);
                    };
            }
            reorderableList.DoLayoutList();
        }

        if (jsonSerializer == null) {
            Start();
        }

        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                if (info.Name.Contains("id")){
                    info.SetValue(tempItem, database.Count);
                    EditorGUILayout.LabelField("ID of item", database.Count.ToString());
                }
                else
                {
                    info.SetValue(tempItem, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempItem)));
                }
            }
            else if (fieldType.IsEnum) {
                if (info.GetValue(tempItem) == null)
                    info.SetValue(tempItem, Activator.CreateInstance(fieldType));
                info.SetValue(tempItem, EditorGUILayout.EnumPopup(info.Name, (Enum)info.GetValue(tempItem)));
            }
            else if (fieldType == typeof(string))
            {
                string name = (String)info.GetValue(tempItem);
                info.SetValue(tempItem, EditorGUILayout.TextField(info.Name, name));
            }
            else if (fieldType == typeof(float))
            {
                info.SetValue(tempItem, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempItem)));
            }
            else if (fieldType.IsValueType && !fieldType.IsPrimitive && simpleFood) //struct
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (fieldType == typeof(Food.Taste))
                    tempStruct = new Food.Taste();

                foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
                {
                    Type fieldTypeInStruct = infoInStruct.FieldType;

                    if (fieldTypeInStruct == typeof(int))
                    {
                            infoInStruct.SetValue(tempStruct, EditorGUILayout.IntField(infoInStruct.Name, (int)infoInStruct.GetValue(info.GetValue(tempItem))));
//.........这里部分代码省略.........
开发者ID:toninhoPinto,项目名称:Monster-Chef,代码行数:101,代码来源:DBItems.cs


注:本文中的UnityEditor.MonoScript.GetClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。