コード例 #1
0
 private void InitData()
 {
     rifleManData   = ScriptableObject.CreateInstance <RiflemanData>();
     juggernautData = ScriptableObject.CreateInstance <JuggernautData>();
     stalkerData    = ScriptableObject.CreateInstance <StalkerData>();
 }
コード例 #2
0
    private void SaveEnemyData()
    {
        string baseprefabPath;
        string newPrefabPath = "Assets/Prefabs/Enemy/";
        string dataPath      = "Assets/Resources/EnemyData/";

        switch (settingData)
        {
        //create rilfleman prefab
        case SettingType.Rifleman:
            dataPath += "Rifleman/" + ToolWindow.riflemanInfo.name + ".asset";
            RiflemanData riflemanInfo = (RiflemanData)Instantiate(ToolWindow.riflemanInfo);
            AssetDatabase.CreateAsset(ToolWindow.riflemanInfo, dataPath);

            newPrefabPath += "Rifleman/" + ToolWindow.riflemanInfo.name + ".prefab";

            baseprefabPath = AssetDatabase.GetAssetPath(ToolWindow.riflemanInfo.prefab);
            AssetDatabase.CopyAsset(baseprefabPath, newPrefabPath);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            GameObject rifleManPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(newPrefabPath);
            if (!rifleManPrefab.GetComponent <Rifleman>())
            {
                rifleManPrefab.AddComponent <Rifleman>();
            }
            rifleManPrefab.GetComponent <Rifleman>().riflemanData = ToolWindow.riflemanInfo;

            break;

        //create juggernaut asset
        case SettingType.Juggernaut:
            dataPath += "Juggernaut/" + ToolWindow.juggernautInfo.name + ".asset";
            JuggernautData juggernautInfo = (JuggernautData)Instantiate(ToolWindow.juggernautInfo);
            AssetDatabase.CreateAsset(ToolWindow.juggernautInfo, dataPath);

            newPrefabPath += "Juggernaut/" + ToolWindow.juggernautInfo.name + ".prefab";

            baseprefabPath = AssetDatabase.GetAssetPath(ToolWindow.juggernautInfo.prefab);
            AssetDatabase.CopyAsset(baseprefabPath, newPrefabPath);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            GameObject juggerNautPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(newPrefabPath);
            if (!juggerNautPrefab.GetComponent <Juggernaut>())
            {
                juggerNautPrefab.AddComponent <Juggernaut>();
            }
            juggerNautPrefab.GetComponent <Juggernaut>().juggernautData = ToolWindow.juggernautInfo;
            break;

        //create stalker asset
        case SettingType.Stalker:
            dataPath += "Stalker/" + ToolWindow.stalkerInfo.name + ".asset";
            StalkerData stalkerInfo = (StalkerData)Instantiate(ToolWindow.stalkerInfo);

            AssetDatabase.CreateAsset(ToolWindow.stalkerInfo, dataPath);

            newPrefabPath += "Stalker/" + ToolWindow.stalkerInfo.name + ".prefab";

            baseprefabPath = AssetDatabase.GetAssetPath(ToolWindow.stalkerInfo.prefab);
            AssetDatabase.CopyAsset(baseprefabPath, newPrefabPath);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            GameObject stalkerPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(newPrefabPath);
            if (!stalkerPrefab.GetComponent <Stalker>())
            {
                stalkerPrefab.AddComponent <Stalker>();
            }
            stalkerPrefab.GetComponent <Stalker>().stalkerData = ToolWindow.stalkerInfo;
            break;
        }
    }