Пример #1
0
    void UpdateActionMapScript()
    {
        ActionMap     original  = (ActionMap)serializedObject.targetObject;
        string        className = GetCamelCaseString(original.name, true);
        StringBuilder str       = new StringBuilder();

        str.AppendFormat(@"using UnityEngine;
using UnityEngine.InputNew;

// GENERATED FILE - DO NOT EDIT MANUALLY
public class {0} : ActionMapInput {{
	public {0} (ActionMap actionMap) : base (actionMap) {{ }}
	
", className);

        for (int i = 0; i < m_ActionMapEditCopy.actions.Count; i++)
        {
            Type   controlType = m_ActionMapEditCopy.actions[i].controlData.controlType;
            string typeStr     = controlType.Name;
            str.AppendFormat("	public {2} @{0} {{ get {{ return ({2})this[{1}]; }} }}\n", GetCamelCaseString(m_ActionMapEditCopy.actions[i].name, false), i, typeStr);
        }

        str.AppendLine(@"}");

        string path = AssetDatabase.GetAssetPath(original);

        path = path.Substring(0, path.Length - Path.GetExtension(path).Length) + ".cs";
        File.WriteAllText(path, str.ToString());
        AssetDatabase.ImportAsset(path);

        original.SetMapTypeName(className + ", " + "Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
    }
Пример #2
0
    void UpdateActionMapScript()
    {
        ActionMap     original  = (ActionMap)serializedObject.targetObject;
        string        className = GetCamelCaseString(original.name, true);
        StringBuilder str       = new StringBuilder();

        string indent          = string.Empty;
        string customNamespace = String.Empty;

        if (!string.IsNullOrEmpty(original.customNamespace))
        {
            customNamespace = string.Format("namespace {0}\n{{\n", original.customNamespace);
            indent          = "    ";
        }

        str.AppendFormat(@"using UnityEngine;
using UnityEngine.Experimental.Input;

// GENERATED FILE - DO NOT EDIT MANUALLY
{1}{0}public class {2} : ActionMapInput
{0}{{
{0}    public {2}(ActionMap actionMap) : base(actionMap) {{}}

", indent, customNamespace, className);

        for (int i = 0; i < m_ActionMapEditCopy.actions.Count; i++)
        {
            Type controlType = m_ActionMapEditCopy.actions[i].controlType;
            if (controlType == null)
            {
                continue;
            }
            string typeStr = controlType.Name;
            str.AppendFormat("{0}    public {3} @{1} {{ get {{ return ({3})GetControl({2}); }} }}\n",
                             indent, GetCamelCaseString(m_ActionMapEditCopy.actions[i].name, false), i, typeStr);
        }

        str.AppendFormat("{0}}}\n", indent);
        if (!string.IsNullOrEmpty(customNamespace))
        {
            str.AppendLine("}");
        }

        string path = AssetDatabase.GetAssetPath(original);

        path = path.Substring(0, path.Length - Path.GetExtension(path).Length) + ".cs";
        File.WriteAllText(path, str.ToString());
        AssetDatabase.ImportAsset(path);

        original.SetMapTypeName(className);
    }