예제 #1
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 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);
    }