Esempio n. 1
0
    public static void Export()
    {
        SettingsImport   asset      = CreateInstance <SettingsImport> ();
        SerializedObject tagManager = GetTagManager();

        SerializedProperty tags = tagManager.FindProperty("tags");

        asset.tags = new string[tags.arraySize];
        for (int i = 0; i < tags.arraySize; ++i)
        {
            asset.tags[i] = tags.GetArrayElementAtIndex(i).stringValue;
        }

        for (int i = 8; i < 32; ++i)
        {
            asset.layers[i - 8] = tagManager.FindProperty(kUserLayerPrefix + i).stringValue;
        }

        asset.axes = InputInterface.GetAxes();

        string path = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(asset));

        Debug.Log(path);
        path = path.Substring(0, path.LastIndexOf('/')) + "/SettingsExport.asset";

        AssetDatabase.CreateAsset(asset, path);
        Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path);
    }
Esempio n. 2
0
    public static void Import(bool manual = false)
    {
        Object[] assets = Resources.FindObjectsOfTypeAll(typeof(SettingsImport));

        if (assets.Length < 1)
        {
            if (manual)
            {
                Debug.LogError("Did not find a settings export asset for importing");
            }
            return;
        }

        SettingsImport   asset      = (SettingsImport)assets[0];
        SerializedObject tagManager = GetTagManager();

        Debug.Log("Importing settings...", asset);

        SerializedProperty tags = tagManager.FindProperty("tags");

        for (int i = 0; i < asset.tags.Length; ++i)
        {
            if (i > tags.arraySize - 1)
            {
                tags.InsertArrayElementAtIndex(i);
                SerializedProperty userTag = tags.GetArrayElementAtIndex(i);
                userTag.stringValue = asset.tags[i];
            }
            else
            {
                SerializedProperty userTag = tags.GetArrayElementAtIndex(i);

                if (asset.Collision(userTag.stringValue, asset.tags[i], "Tag", manual))
                {
                    tagManager.ApplyModifiedProperties();
                    return;
                }

                userTag.stringValue = asset.tags[i];
            }
        }

        for (int i = 0; i < asset.layers.Length; ++i)
        {
            SerializedProperty userLayer = tagManager.FindProperty(kUserLayerPrefix + (i + 8));

            if (asset.Collision(userLayer.stringValue, asset.layers[i], "Layer", manual))
            {
                tagManager.ApplyModifiedProperties();
                return;
            }

            userLayer.stringValue = asset.layers[i];
        }

        List <AxisDefinition> axes = InputInterface.GetAxes();

        foreach (AxisDefinition axis in asset.axes)
        {
            if (axes.Contains(axis))
            {
                continue;
            }

            AxisDefinition collision = axes.Where(other => axis.InterfaceEquals(other)).FirstOrDefault();

            if (collision != null)
            {
                InputInterface.SaveAxis(axis, axes.IndexOf(collision));
                axes = InputInterface.GetAxes();
                continue;
            }

            InputInterface.AddAxis(axis);
            axes = InputInterface.GetAxes();
        }


        tagManager.ApplyModifiedProperties();
    }