예제 #1
0
    public object GetEntryValue(int entryIndex, int fieldIndex)
    {
        object entryValue = "";

        if (CurrentAssetType != null)
        {
            string         fieldValue = mAssetFields[CurrentAssetType][fieldIndex];
            UpdatableAsset asset      = mAssets[CurrentAssetType][entryIndex];
            switch (fieldValue)
            {
            case NAME_FIELD:
                entryValue = asset.Name;
                break;

            case DESCRIPTION_FIELD:
                entryValue = asset.Description;
                break;

            default:
                if (asset.Custom != null && asset.Custom.ContainsKey(fieldValue))
                {
                    entryValue = asset.Custom[fieldValue];
                }
                break;
            }
        }
        return(entryValue);
    }
예제 #2
0
    public TableAdapter.Status GetEntryStatus(int entryIndex)
    {
        TableAdapter.Status ret = TableAdapter.Status.UNMODIFIED;
        if (CurrentAssetType != null && entryIndex < mAssets[CurrentAssetType].Count)
        {
            UpdatableAsset asset = mAssets[CurrentAssetType][entryIndex];
            switch (asset.CurrentStatus)
            {
            case UpdatableAsset.Status.EXISTING:
                if (!asset.Modified)
                {
                    ret = TableAdapter.Status.UNMODIFIED;
                }
                else
                {
                    ret = TableAdapter.Status.MODIFIED;
                }
                break;

            case UpdatableAsset.Status.NEW:
                ret = TableAdapter.Status.NEW;
                break;

            case UpdatableAsset.Status.DELETED:
                ret = TableAdapter.Status.DELETED;
                break;
            }
        }
        return(ret);
    }
예제 #3
0
    public void UpdateEntryValue(int entryIndex, int fieldIndex, string value)
    {
        if (CurrentAssetType != null)
        {
            string         fieldValue = mAssetFields[CurrentAssetType][fieldIndex];
            UpdatableAsset asset      = mAssets[CurrentAssetType][entryIndex];
            switch (fieldValue)
            {
            case NAME_FIELD:
                asset.Name = value;
                break;

            case DESCRIPTION_FIELD:
                asset.Description = value;
                break;

            default:
                if (asset.Custom == null)
                {
                    asset.Custom = new Dictionary <string, object>();
                }
                asset.UpdateCustomField(fieldValue, value);
                break;
            }
        }
    }
예제 #4
0
 public void RestoreEntry(int entryIndex)
 {
     if (CurrentAssetType != null)
     {
         UpdatableAsset asset = mAssets[CurrentAssetType][entryIndex];
         asset.Restore();
     }
 }
예제 #5
0
    public bool AddNewEntry(int entryIndex)
    {
        bool success = false;

        if (CurrentAssetType != null)
        {
            UpdatableAsset asset = new UpdatableAsset(CurrentAssetType);
            AddAsset(asset);
            success = true;
        }
        return(success);
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        UpdatableAsset asset = (UpdatableAsset)target;

        if (GUILayout.Button("Update"))
        {
            asset.Notify();
            EditorUtility.SetDirty(target);
        }
    }
예제 #7
0
 private bool AssetNameExists(UpdatableAsset updateAsset)
 {
     foreach (var p in mAssets)
     {
         foreach (UpdatableAsset asset in p.Value)
         {
             if (updateAsset != asset && updateAsset.Name == asset.Name)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #8
0
 public void DeleteEntry(int entryIndex)
 {
     if (CurrentAssetType != null)
     {
         UpdatableAsset asset = mAssets[CurrentAssetType][entryIndex];
         if (asset.CurrentStatus == UpdatableAsset.Status.NEW)
         {
             mAssets[asset.AssetType].Remove(asset);
         }
         else
         {
             asset.MarkDeleted();
         }
     }
 }
예제 #9
0
 public void RemoveAsset(UpdatableAsset asset)
 {
     mAssets[asset.AssetType].Remove(asset);
 }
예제 #10
0
 public void AddAsset(UpdatableAsset asset)
 {
     mAssets[asset.AssetType].Add(asset);
 }
예제 #11
0
    public void SaveData(Action <string> saveCallback)
    {
        string output             = "";
        bool   processedAllAssets = false;
        int    counter            = 0;
        bool   savingSomething    = false;

        Action TriggerSaveCallbackIfReady = () => {
            if (processedAllAssets && counter == 0 && saveCallback != null)
            {
                saveCallback(output);
            }
        };

        foreach (List <UpdatableAsset> assets in mAssets.Values)
        {
            for (int i = assets.Count - 1; i >= 0; --i)
            {
                UpdatableAsset asset = assets[i];

                if (asset.CurrentStatus != UpdatableAsset.Status.EXISTING || asset.Modified)
                {
                    counter++;
                    savingSomething = true;

                    Action <Asset, NPNFError> innerSaveCallback = (Asset resultAsset, NPNFError error) => {
                        counter--;
                        string assetName = (resultAsset != null ? resultAsset.Name : asset.Name);
                        if (error != null)
                        {
                            Debug.Log("Saving asset failed: " + assetName);
                            output += "Saving asset failed: " + assetName + "\n";
                        }
                        else
                        {
                            Debug.Log("Saving asset succeeded: " + assetName);
                            if (resultAsset != null)
                            {
                                asset.BackingAsset = resultAsset;
                            }
                        }
                        TriggerSaveCallbackIfReady();
                    };
                    if (asset.CurrentStatus == UpdatableAsset.Status.NEW || asset.Modified)
                    {
                        if (!AssetNameExists(asset))
                        {
                            if (asset.Modified)
                            {
                                mAdmin.UpdateAsset(asset, innerSaveCallback);
                            }
                            else
                            {
                                mAdmin.CreateAsset(asset, innerSaveCallback);
                            }
                        }
                        else
                        {
                            counter--;
                            Debug.Log("Save failed: Asset name already exists: " + asset.Name);
                            output += "Save failed: Asset name already exists: " + asset.Name + "\n";
                        }
                    }
                    else if (asset.CurrentStatus == UpdatableAsset.Status.DELETED)
                    {
                        mAdmin.DeleteAsset(asset, (Asset resultAsset, NPNFError error) => {
                            counter--;
                            string assetName = (resultAsset != null ? resultAsset.Name : asset.Name);
                            if (error != null)
                            {
                                Debug.Log("Deleting asset failed: " + assetName);
                                output += "Deleting asset failed: " + assetName;
                            }
                            else
                            {
                                Debug.Log("Deleting asset succeeded: " + assetName);
                                List <UpdatableAsset> assetsToRemoveFrom = mAssets[resultAsset.AssetType];
                                assetsToRemoveFrom.Remove(asset);
                            }
                            TriggerSaveCallbackIfReady();
                        });
                    }
                }
            }
        }
        if (!savingSomething)
        {
            saveCallback("No changes were made. Nothing to save.");
        }
        else
        {
            processedAllAssets = true;
            TriggerSaveCallbackIfReady();
        }
    }
예제 #12
0
 public void AddAsset(UpdatableAsset asset)
 {
     mAssets[asset.AssetType].Add(asset);
 }
예제 #13
0
 private bool AssetNameExists(UpdatableAsset updateAsset)
 {
     foreach (var p in mAssets)
     {
         foreach (UpdatableAsset asset in p.Value)
         {
             if (updateAsset != asset && updateAsset.Name == asset.Name)
             {
                 return true;
             }
         }
     }
     return false;
 }
예제 #14
0
 public void RemoveAsset(UpdatableAsset asset)
 {
     mAssets[asset.AssetType].Remove(asset);
 }
예제 #15
0
 public bool AddNewEntry(int entryIndex)
 {
     bool success = false;
     if (CurrentAssetType != null)
     {
         UpdatableAsset asset = new UpdatableAsset(CurrentAssetType);
         AddAsset(asset);
         success = true;
     }
     return success;
 }