public static CharacterClippingScriptableResult SaveOutToCache(ClippingProtectorSetup Setup, ClippingProtectorResult Result)
    {
        CharacterClippingScriptableResult Existing = TryGetExisting(Setup);

        if (Existing != null)
        {
            Debug.Log("Existing save found for Character Clipping Simulation");
            return(Existing);
        }
        CharacterClippingScriptableResult CCR = CharacterClippingScriptableResult.CreateInstance <CharacterClippingScriptableResult>();
        string ScriptableName = "CacheResult_" + System.DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss_ms");

        CheckDirExists(ScriptableName);
        //Make sure results are saved as proper meshes
        foreach (Mesh m in Result.FinalMeshes)
        {
            AssetDatabase.CreateAsset(m, "Assets/Resources/CharacterClippingCache/" + ScriptableName + "/" + m.name + "_" + ScriptableName + ".asset");
        }
        //Save out the asset
        UnityEditor.AssetDatabase.CreateAsset(CCR, "Assets/Resources/CharacterClippingCache/" + ScriptableName + "/" + ScriptableName + ".asset");
        CCR.Result = Result;
        CCR.Setup  = Setup;
        UnityEditor.EditorUtility.SetDirty(CCR);
        UnityEditor.AssetDatabase.SaveAssets();
        Debug.Log("Saved out Character Clipping Simulation");
        return(CCR);
    }
    public static ClippingProtectorResult TryLoadCachedResult(ClippingProtectorSetup Setup)
    {
        CharacterClippingScriptableResult Exist = TryGetExisting(Setup);

        if (Exist != null)
        {
            return(Exist.Result);
        }
        return(new ClippingProtectorResult());
    }
Beispiel #3
0
    void NotifyUserCacheSizeNewSize(CharacterClippingScriptableResult Res)
    {
        //New Item size
        StartCheckTime = System.DateTime.Now;
        float ItemSize = CalculateFolderSize("Assets/Resources/CharacterClippingCache/" + Res.name);

        StartCheckTime = System.DateTime.Now;
        float OverallSize = CalculateFolderSize("Assets/Resources/CharacterClippingCache");

        EditorUtility.DisplayDialog("Item Saved", "Simulation has been saved as: " + Res.name + " simulation size: " + GetSizeAsStr(ItemSize) + "MB overall cache size: " + GetSizeAsStr(OverallSize) + "MB", "Ok Thanks");;
    }
Beispiel #4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        CharacterClippingProtector ClipProtector = (CharacterClippingProtector)target;

        if (GUILayout.Button("Reset Meshes & Cache"))
        {
            ClipProtector.ResetMeshesToOriginal();
            ClipProtector.ResetCachedResults();
        }
        if (GUILayout.Button("Save Last Result In Resources"))
        {
            CharacterClippingScriptableResult Res = CharacterClippingScriptableResult.SaveLastResultToCache(ClipProtector);
            //Notify user of cache size & new item size
            NotifyUserCacheSizeNewSize(Res);
        }
        if (GUILayout.Button("Run Clipping Protector"))
        {
            ClipProtector.StartEditorCoroutine();
        }
    }
Beispiel #5
0
    /// <summary>
    /// Check our cached previous simulations and see if we can skip the simulation process
    /// </summary>
    private bool CheckCached(ClippingProtectorSetup Check)
    {
        //Check local cached
        foreach (ClippingProtectorSetup cs in CachedResults.Keys)
        {
            if (cs.SetupEqual(Check))
            {
                List <Mesh> NewMeshes = CachedResults[cs].FinalMeshes;
                SetFromCachedMeshes(NewMeshes);
                return(true);
            }
        }
        //Check Saved cache scriptbales
        ClippingProtectorResult Res = CharacterClippingScriptableResult.TryLoadCachedResult(Check);

        if (Res.FinalMeshes != null && Res.FinalMeshes.Count > 0)
        {
            SetFromCachedMeshes(Res.FinalMeshes);
            return(true);
        }
        return(false);
    }
 public static CharacterClippingScriptableResult SaveLastResultToCache(CharacterClippingProtector ClipProtector)
 {
     if (ClipProtector.GetOriginalMeshes().Count > 0)
     {
         if (!ClipProtector.CacheResults)
         {
             EditorUtility.DisplayDialog("Caching Not Set", "Please enable caching on the script to save to editor", "I Will");
         }
         else
         {
             Dictionary <ClippingProtectorSetup, ClippingProtectorResult> Cached = ClipProtector.GetCachedResults();
             if (Cached.Count == 0)
             {
                 EditorUtility.DisplayDialog("No Simulations", "No similations have been run", "I Will Run A Simulation"); return(null);
             }
             CharacterClippingScriptableResult Saved = CharacterClippingScriptableResult.SaveOutToCache(ClipProtector.LastSetup, Cached[ClipProtector.LastSetup]);
             //Refresh Cache
             RefreshResour();
             return(Saved);
         }
     }
     return(null);
 }