private bool OnGui_InputAxis(Rect position, SerializedProperty property, GUIContent label)
    {
        var targetObj     = property.serializedObject.targetObject;
        var propertyField = targetObj.GetType().GetField(property.name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

        SystemDefines.InputAxis propertyInputAxis = propertyField.GetValue(targetObj) as SystemDefines.InputAxis;

        // InputAxisDataスクリプト自体生成されていないとこのスクリプトのコンパイルも通らないので
        // リフレクションでメンバ変数を取得する
        var field = m_InputAxisData.GetType().GetField("Config");
        List <SystemDefines.InputAxis> inputAxes = field.GetValue(m_InputAxisData) as List <SystemDefines.InputAxis>;

        if (inputAxes == null)
        {
            return(false);
        }

        int selectIndex = 0;

        string[] inputAxisNames = new string[inputAxes.Count];
        for (int i = 0; i < inputAxes.Count; ++i)
        {
            inputAxisNames[i] = (i + 1) + ": " + inputAxes[i].Name;
            if (propertyInputAxis != inputAxes[i])
            {
                continue;
            }
            selectIndex = i;
        }
        selectIndex = EditorGUI.Popup(position, property.name, selectIndex, inputAxisNames);

        if (selectIndex < inputAxes.Count)
        {
            propertyInputAxis = inputAxes[selectIndex];
        }

        propertyField.SetValue(targetObj, propertyInputAxis);
        return(true);
    }
Esempio n. 2
0
    private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath)
    {
        var instance = InputAxisDataGeneratorParams.instance;

        s_IsInputManagerUpdated = false;
        // InputManagerの変更チェック
        var InputManagerPath = Array.Find(importedAssets, path => Path.GetFileName(path) == "InputManager.asset");

        if (InputManagerPath == null)
        {
            return;
        }

        s_IsInputManagerUpdated = true;
        // InputManagerの設定情報読み込み
        var serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath(InputManagerPath)[0]);
        var axesProperty     = serializedObject.FindProperty("m_Axes");

        instance.m_InputAxes = new List <SystemDefines.InputAxis>();

        for (int i = 0; i < axesProperty.arraySize; ++i)
        {
            var axis         = new SystemDefines.InputAxis();
            var axisProperty = axesProperty.GetArrayElementAtIndex(i);

            axis.Name                    = GetChildProperty(axisProperty, "m_Name").stringValue;
            axis.DescriptiveName         = GetChildProperty(axisProperty, "descriptiveName").stringValue;
            axis.DescriptiveNegativeName = GetChildProperty(axisProperty, "descriptiveNegativeName").stringValue;
            axis.NegativeButton          = GetChildProperty(axisProperty, "negativeButton").stringValue;
            axis.PositiveButton          = GetChildProperty(axisProperty, "positiveButton").stringValue;
            axis.AltNegativeButton       = GetChildProperty(axisProperty, "altNegativeButton").stringValue;
            axis.AltPositiveButton       = GetChildProperty(axisProperty, "altPositiveButton").stringValue;
            axis.Gravity                 = GetChildProperty(axisProperty, "gravity").floatValue;
            axis.Dead                    = GetChildProperty(axisProperty, "dead").floatValue;
            axis.Sensitivity             = GetChildProperty(axisProperty, "sensitivity").floatValue;
            axis.Snap                    = GetChildProperty(axisProperty, "snap").boolValue;
            axis.Invert                  = GetChildProperty(axisProperty, "invert").boolValue;
            axis.Type                    = (SystemDefines.AxisType)GetChildProperty(axisProperty, "type").intValue;
            axis.Axis                    = GetChildProperty(axisProperty, "axis").intValue;
            axis.JoyNum                  = GetChildProperty(axisProperty, "joyNum").intValue;

            instance.m_InputAxes.Add(axis);
        }

        var    inputAxisDataResult  = Application.dataPath + "/" + instance.m_OutputScriptFilePath + instance.m_GenerateClassName + ".cs";
        bool   isExist              = File.Exists(inputAxisDataResult);
        string outputTemplateSource = string.Format(InputAxisDataTemplate, instance.m_OutputScriptableObjectPath + "/" + instance.m_GenerateClassName);

        if (isExist)
        {
            var fs = new FileStream(inputAxisDataResult, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using (var reader = new StreamReader(fs))
            {
                string sourcefile = reader.ReadToEnd();
                if (sourcefile != outputTemplateSource)                 // 一致しなければ
                {
                    OutputInputAxisDataTemplate(inputAxisDataResult, outputTemplateSource);
                }
                else                 // 一致する場合コンパイルが通らないのでコンパイル後に通る想定だった関数を自前で呼ぶ
                {
                    OnComplied();
                }
            }
        }
        else
        {
            OutputInputAxisDataTemplate(inputAxisDataResult, outputTemplateSource);
        }
    }