示例#1
0
 public static void SelectAndOverWriteAllKeyframes(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams)
 {
     animationParams.keyframeSum = 0;
     for (int i = 0; i <= substanceMaterialParams.MaterialVariableKeyframeList.Count() - 1; i++)
     {
         SubstanceTweenKeyframeUtility.SelectKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
         SubstanceTweenKeyframeUtility.OverWriteKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
         animationParams.keyframeSum += animationParams.keyFrameTimes[i];
     }
     SubstanceTweenAnimationUtility.CacheAnimatedProceduralVariables(substanceMaterialParams, animationParams);
 }
示例#2
0
 public static void  CheckForAddKeyFromCurveEditor(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
 {
     for (int i = 0; i <= animationParams.substanceCurveBackup.keys.Count() - 1; i++)
     {
         if (i <= animationParams.substanceCurve.keys.Count() - 1 && animationParams.substanceCurve.keys[i].time != animationParams.substanceCurveBackup.keys[i].time) // find keyframe that has just been created or deleted in the curve editor
         {
             if (animationParams.substanceCurve.keys.Count() > animationParams.substanceCurveBackup.keys.Count())
             {
                 animationParams.substanceCurve.MoveKey(i, new Keyframe(animationParams.substanceCurve.keys[i].time, animationParams.substanceCurve.keys[i].time)); // lerp does not work correctly if the keyframe value is different than the time. i cant edit the key so i delete then add a new one
                 float tempKeyframeTime = animationParams.substanceCurve.keys[i].time;
                 SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues);
                 SubstanceTweenKeyframeUtility.InsertKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
                 SubstanceTweenKeyframeUtility.SelectKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
                 animationParams.currentAnimationTime      = 0;
                 animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
                 SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
                 return;
             }
         }
     }
 }
示例#3
0
    public static void CheckForRemoveOrEditFromCurveEditor(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
    {
        bool         inEditKeysMode                     = false;
        int          keyframesModifiedSoFar             = 0;                                                                                               //number of keyframes deleted edited so far
        int          curvePointsCountDifference         = animationParams.substanceCurveBackup.keys.Count() - animationParams.substanceCurve.keys.Count(); // difference between number of points before the change compared to the number of points after the change
        List <float> BackupKeyframePointTimes           = new List <float>();                                                                              // points on curve before change
        List <float> CurrentKeyframePointTimes          = new List <float>();                                                                              // points on curve after change
        Keyframe     firstEditedKeyframeBeforeEdit      = new Keyframe(-1, -1);                                                                            //the first keyframe in the list that has been edited ore deleted
        int          firstEditedKeyframeIndexBeforeEdit = -1;                                                                                              // index of the first edited keyframe

        if (animationParams.substanceCurve.keys[0].time != 0)
        {
            animationParams.substanceCurve.keys[0].time = 0;
        }
        for (int i = 0; i <= animationParams.substanceCurveBackup.keys.Count() - 1; i++)
        {
            BackupKeyframePointTimes.Add(animationParams.substanceCurveBackup.keys[i].time);
        }
        for (int i = 0; i <= animationParams.substanceCurve.keys.Count() - 1; i++)
        {
            CurrentKeyframePointTimes.Add(animationParams.substanceCurve.keys[i].time);
        }

        for (int i = 0; i <= BackupKeyframePointTimes.Count() - 2; i++)
        {
            if (!CurrentKeyframePointTimes.Contains(BackupKeyframePointTimes[i]))
            { // find index of the first key that has ben edited using context menu
                firstEditedKeyframeBeforeEdit = animationParams.substanceCurveBackup.keys[i];
                float tempKeyframeTime = firstEditedKeyframeBeforeEdit.time;
                firstEditedKeyframeIndexBeforeEdit = i;
                SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues);
                break;
            }
        }

        for (int i = 0; i <= CurrentKeyframePointTimes.Count() - 2; i++)
        {
            if (!BackupKeyframePointTimes.Contains(CurrentKeyframePointTimes[i]))
            {// if  i use the context menu to edit multiple keyframes to a value that is not already on the graph i can find that new keyframe here.
             // I can tell when i have EDITED a keyframe to a new value because when deleting keyframes, every new point's time should also exist in the backup
                inEditKeysMode = true;
                float tempKeyframeTime = firstEditedKeyframeBeforeEdit.time;
                SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues); // find/set material based on first edited keyframe
                if (firstEditedKeyframeIndexBeforeEdit != -1)                                                                                                                                    // if multiple keyframes has been edited using context menu
                {
                    SubstanceTweenKeyframeUtility.OverWriteKeyframe(firstEditedKeyframeIndexBeforeEdit, substanceMaterialParams, animationParams, substanceToolParams);                          // overwrite new keyframe with material of the first edited keyframe
                }
            }
        }

        for (int i = BackupKeyframePointTimes.Count() - 1; i > 0; i--)            // Go through every key in the backup list(Before the keys got deleted)
        {
            if (!CurrentKeyframePointTimes.Contains(BackupKeyframePointTimes[i])) // if the current list of curve points does not contain this value(it was deleted in the curve editor)
            {                                                                     //Find the index of the value and delete any information that has not already been deleted in the curve editor
               // get the index of the deleted point and delete the Dictionary/List associated with that index
                keyframesModifiedSoFar++;
                animationParams.keyFrameTimes.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                substanceMaterialParams.MaterialVariableKeyframeList.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                substanceMaterialParams.MaterialVariableKeyframeDictionaryList.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                if (animationParams.keyFrames > 0)
                {
                    animationParams.keyFrames--;
                }
            }
            if (inEditKeysMode && i == 1 && keyframesModifiedSoFar > 0)
            { // if i edited multiple keyframes at the same time using the context menu I insert a keyframe when i reach the end of the for loop
                SubstanceTweenKeyframeUtility.InsertKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
            }
        }
        for (int i = 0; i <= animationParams.substanceCurve.keys.Count() - 2; i++)
        {                                                                                                                                     // rebuild/refresh animation times
            animationParams.keyFrameTimes[i] = animationParams.substanceCurve.keys[i + 1].time - animationParams.substanceCurve.keys[i].time; // this keyframe time = (next keyframe time - This keyframe time)
            substanceMaterialParams.MaterialVariableKeyframeList[i].animationTime = animationParams.substanceCurve.keys[i + 1].time - animationParams.substanceCurve.keys[i].time;
        }

        if (curvePointsCountDifference != keyframesModifiedSoFar)
        { // Because curvePoint EditDifference != keyframes Edited/changed, I know that keyframes have been changed with 'Edit Keys..' and not 'Delete'
          // when editing multipule keyframes to a new singular time that is not already on the list,
          // there should always be more edited keyframes then the difference between current curve points and backup curve points.
            if (animationParams.substanceCurve.keys[animationParams.substanceCurve.keys.Count() - 1].time > animationParams.substanceCurveBackup.keys[animationParams.substanceCurveBackup.keys.Count() - 1].time)
            {// Edited multiple keyframes to a new time that is more than the length of the backup curve
                SubstanceTweenKeyframeUtility.CreateKeyframe(substanceMaterialParams, animationParams, substanceToolParams);
            }
        }
        animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
        SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
        inEditKeysMode = false;
    }
 void CreateKeyframe()
 {
     SubstanceTweenKeyframeUtility.CreateKeyframe(testingScript.substanceMaterialParams, testingScript.animationParams, testingScript.substanceToolParams);
 }
    public IEnumerator SubstanceTweenPlayTestWithEnumeratorPasses()
    {
        // Use the Assert class to test conditions.
        // yield to skip a frame

        //SETUP SCENE/OBJECT
        SetupScene();
        SpawnAndSetupObject();
        yield return(new WaitForSeconds(0.5f));

        //LOAD PROCEDURAL MATERIALS
        LoadAllProceduralMaterialsFromFolder();
        SetSpecificProceduralMaterial("Crystal1-11");
        yield return(new WaitForSeconds(1));

        // ADD MAIN TOOL TO SELECTED OBJECT
        AddEditorToolToObject();

        //REMEMBER CURRENT MATERIAL AS THE STARTUP/BEFORE CHANGE
        materialVariablesBeforeChange = materialBeforeChange.GetProceduralPropertyDescriptions();
        AddSetProceduralVariablesBeforeChangeToKeyValue(materialBeforeChange, materialVariablesBeforeChange, materialKeysBeforeChange, materialValuesBeforeChange);
        AddSetProceduralVariablesBeforeChangeToKeyValue(materialAtStartup, materialVariablesAtStartup, materialKeysAtStartup, materialValuesAtStartup);
        materialVariablesAtStartup = materialAtStartup.GetProceduralPropertyDescriptions();
        yield return(new WaitForSeconds(0.5f));

        // RANDOMIZE VALUES
        SubstanceTweenSetParameterUtility.RandomizeProceduralValues(testingScript.substanceMaterialParams, testingScript.randomizeSettings);
        yield return(new WaitForSeconds(0.5f));

        // SET TO MINIMUM
        AddSetProceduralVariablesBeforeChangeToKeyValue(materialBeforeChange, materialVariablesBeforeChange, materialKeysBeforeChange, materialValuesBeforeChange);
        SubstanceTweenSetParameterUtility.SetAllProceduralValuesToMin(testingScript.substanceMaterialParams);
        yield return(new WaitForSeconds(0.5f));

        //SET TO MAXIMUM
        CheckForChangedMaterialParams(materialVariablesBeforeChange);
        AddSetProceduralVariablesBeforeChangeToKeyValue(materialBeforeChange, materialVariablesBeforeChange, materialKeysBeforeChange, materialValuesBeforeChange);
        SubstanceTweenSetParameterUtility.SetAllProceduralValuesToMax(testingScript.substanceMaterialParams);
        CheckForChangedMaterialParams(materialVariablesBeforeChange);
        yield return(new WaitForSeconds(0.5f));

        // RESET MATERIAL
        SubstanceTweenSetParameterUtility.ResetAllProceduralValues(testingScript.substanceDefaultMaterialParams, testingScript.substanceMaterialParams, testingScript.animationParams, testingScript.substanceToolParams);
        CheckForNoChangeInMaterialParams(materialAtStartup, materialVariablesAtStartup, materialKeysAtStartup, materialValuesAtStartup);
        AddSetProceduralVariablesBeforeChangeToKeyValue(materialBeforeChange, materialVariablesBeforeChange, materialKeysBeforeChange, materialValuesBeforeChange);
        yield return(new WaitForSeconds(0.5f));

        //CREATE KEYFRAMES
        SetSpecificMaterialParamsAndCreateKeyframes(5, "Crystal_Disorder", "Grunge_Map5_Contrast", "Base_Color");
        CheckForChangedMaterialParams(materialVariablesBeforeChange);
        ReWriteAllKeyframeTimes(1, testingScript.substanceMaterialParams, testingScript.animationParams);

        testingScript.substanceToolParams.selectedPrefabScript.animationToggle = true;
        yield return(new WaitForSeconds(40f));

        // START TESTING CURVES
        testingScript.substanceToolParams.testingCurve = true;
        float addKey = 19;

        testingScript.animationParams.substanceCurve.AddKey(addKey, addKey);                                                                                                                               // ADD KEY TO CURVE
        Assert.That(testingScript.animationParams.substanceCurve.keys.Count() != testingScript.animationParams.substanceCurveBackup.keys.Count(), "ERROR: Curve key count matches backup ");
        SubstanceTweenKeyframeUtility.CheckForAddKeyFromCurveEditor(testingScript.substanceMaterialParams, testingScript.animationParams, testingScript.substanceToolParams, testingScript.flickerValues); // checks if a key was added on the curve. if a curve key was added I add a keyframe for the material
        Assert.That(testingScript.animationParams.substanceCurve.keys.Count() == testingScript.animationParams.substanceCurveBackup.keys.Count(), "ERROR: Curve key does not count matches backup ");
        for (int i = 0; i <= testingScript.animationParams.substanceCurve.keys.Count() - 1; i++)
        {
            if (testingScript.animationParams.substanceCurve.keys[i].time == addKey)
            {
                testingScript.animationParams.substanceCurve.RemoveKey(i);
            }
        }
        Assert.That(testingScript.animationParams.substanceCurve.keys.Count() != testingScript.animationParams.substanceCurveBackup.keys.Count(), "ERROR: Curve key count matches backup ");
        SubstanceTweenKeyframeUtility.CheckForRemoveOrEditFromCurveEditor(testingScript.substanceMaterialParams, testingScript.animationParams, testingScript.substanceToolParams, testingScript.flickerValues); // checks if a key was removed/edited on the curve. if a curve key was removed/edited I reflect the changes to the material keyframes.

        Assert.That(testingScript.animationParams.substanceCurve.keys.Count() == testingScript.animationParams.substanceCurveBackup.keys.Count(), "ERROR: Curve key does not count matches backup ");

        //CREATE UNDO STATE
        Undo.RegisterCompleteObjectUndo(new UnityEngine.Object[] { testingScript.referenceToEditorScript }, "Edited Curve");

        //SIMULATE EDITING MULTIPLE CURVE KEYS TO A NEW VALUE THAT DOES NOT ALREADY EXIST ON THE CURVE
        testingScript.animationParams.substanceCurve.RemoveKey(2);
        testingScript.animationParams.substanceCurve.RemoveKey(1);
        testingScript.animationParams.substanceCurve.AddKey(4, 4);

        Assert.That(testingScript.animationParams.substanceCurve.keys.Count() != testingScript.animationParams.substanceCurveBackup.keys.Count(), "ERROR: Curve key count matches backup ");
        SubstanceTweenKeyframeUtility.CheckForRemoveOrEditFromCurveEditor(testingScript.substanceMaterialParams, testingScript.animationParams, testingScript.substanceToolParams, testingScript.flickerValues);
        Assert.That(testingScript.animationParams.substanceCurve.keys.Count() == testingScript.animationParams.substanceCurveBackup.keys.Count(), "ERROR: Curve key does not count matches backup ");

        yield return(new WaitForSeconds(10));

        // UNDO TO A PREVIOUS STATE
        Undo.PerformUndo();

        // STOP TESTING CURVES
        testingScript.substanceToolParams.testingCurve = false;

        yield return(new WaitForSeconds(50));

        //END TEST
        yield break;
    }