Beispiel #1
0
        private void Init()
        {
            // load achievements
            definitions            = (AchievementDefinitions)Resources.Load("achievements");
            achievementDefinitions = new Dictionary <string, AchievementDefinition>();
            achievementStates      = new Dictionary <string, AchievementState>();
            foreach (AchievementDefinition definition in definitions.definitions)
            {
                achievementDefinitions.Add(definition.name, definition);
                AchievementState state = new AchievementState();
                state.hidden = definition.hidden;
                achievementStates.Add(definition.name, state);
            }

            // TODO build stuff for multi tier achievements
        }
Beispiel #2
0
    void OnGUI()
    {
        // list achievements
        if (definitions == null)
        {
            if (GUILayout.Button("Create Achievements"))
            {
                // check if file already exists, if so, display error
                if (AssetDatabase.LoadAssetAtPath("Assets/Resources/achievements.asset", typeof(AchievementDefinitions)) as AchievementDefinitions != null)
                {
                    EditorUtility.DisplayDialog("Error", "Achievements file already exists. Please reopen the achievement editor", "Close");
                    Close();
                    return;
                }

                // create new asset definitions file
                achievementDefinitions = ScriptableObject.CreateInstance <AchievementDefinitions>();
                if (!Directory.Exists(Application.dataPath + Path.DirectorySeparatorChar + "Resources"))
                {
                    AssetDatabase.CreateFolder("Assets", "Resources");
                }
                AssetDatabase.CreateAsset(achievementDefinitions, "Assets/Resources/Achievements.asset");
                AssetDatabase.SaveAssets();

                // reload instance
                OnEnable();
            }
        }
        else
        {
            // display definitions
            DisplayDefinitions();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(achievementDefinitions);
            }
        }
    }
Beispiel #3
0
    void OnEnable()
    {
        // do init stuff;
        // build category list
        categories = new Dictionary <int, Category>();
        Category cat = new Category();

        cat.category      = new AchievementCategory();
        cat.category.name = "Uncategorized";
        cat.category.id   = 0;
        categories.Add(cat.category.id, cat);

        achievementDefinitions = AssetDatabase.LoadAssetAtPath("Assets/Resources/achievements.asset", typeof(AchievementDefinitions)) as AchievementDefinitions;
        if (achievementDefinitions != null)
        {
            // add categories from definition
            foreach (AchievementCategory category in achievementDefinitions.categories)
            {
                cat          = new Category();
                cat.category = category;
                categories.Add(cat.category.id, cat);
            }

            definitions = new List <AchievementDefinitionInfo>();
            foreach (AchievementDefinition definition in achievementDefinitions.definitions)
            {
                AchievementDefinitionInfo info = new AchievementDefinitionInfo(definition);
                definitions.Add(info);

                // add to category
                categories[definition.categoryId].achievements.Add(info);
            }
        }

        splitterIcon = AssetDatabase.LoadAssetAtPath("Assets/Achievements/Editor/splitter.png", typeof(Texture2D)) as Texture2D;

        BuildCategoryPopup();
    }