Search Unity

Released: Visualizer Studio - A Music Visualization scripting package!

Discussion in 'Assets and Asset Store' started by AlteredReality, Aug 16, 2011.

  1. DevSeb

    DevSeb

    Joined:
    Apr 25, 2015
    Posts:
    1
    Will VS read live audio from input jack on the sound card?

    Also, does it work with Unity 5?

    Thanks!
     
  2. AlteredReality

    AlteredReality

    Joined:
    Aug 15, 2011
    Posts:
    397
    It does support input from the microphone or any line-in on the device. However, this is using the native support for this in the unity Audio source.

    And yes, it does work with Unity 5.
     
  3. jameskyle

    jameskyle

    Joined:
    May 7, 2013
    Posts:
    37
    Does anyone have any advice on using VS with Playmaker? I'm trying to use the Playmaker action "Get Property" to access the same script variable that VS is using to alter properties of objects, etc. but can't seem to find it. What's the best way of getting these two working together?

    The best way I can think of is to create a proxy object that I can use to pass values from VS to PM but it'd be nice to have it happen in fewer steps.
     
  4. AlteredReality

    AlteredReality

    Joined:
    Aug 15, 2011
    Posts:
    397
    Unfortunately, I've never used playmaker before personally, so I can't vouch for the easiest way to do this. However, if you don't find something directly exposed in it, I do think a proxy script to help connect them would likely be your best bet. Sorry I can't be of any more help on this. If you have other general questions about Visualizer Studio though, please let me know.
     
  5. bArtch

    bArtch

    Joined:
    May 17, 2015
    Posts:
    4
    Hi, thanks for Visualizer Studio, you did a great job! I am trying to make a little app for android/ios with your package. I use the visMicrophone script, so, the music and sounds in the room where you are, has to trigger the animations /visualize the music.. However, on Android (HTC one m7) i notice a delay. So, if i yell into the microphone, my visualisations are triggered a second or 2 later. I need the triggering to be as instant as possible. Do you have a solution for me?
    regards,
    Bart
     
  6. AlteredReality

    AlteredReality

    Joined:
    Aug 15, 2011
    Posts:
    397
    Unfortunately, there is nothing I can do. I am just using Unity's built in microphone support found here:

    http://docs.unity3d.com/ScriptReference/Microphone.Start.html

    Sorry there isn't anything I can do. :-(
     
  7. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Hi mate.

    When using the SpawnPrefab on a middle range tablet it fails to spawn anything.
    Same code works on other things...

    Perhaps it is the garbage overhead burden? I dunno.

    upload_2015-9-27_12-45-10.png

    Anyways. that is the profiler on a desktop running the same code. (1/6mb per object? ouchy)

    I suppose I could dig around more - just advising you you have a demon somewhere on low power devices.

    EDIT: oh and here it is in a test. (The cubes and spheres are audio spawned)
    http://kaycare.co.uk/games/kayplunk2/

    that test fails on a midrange tablet for some reason.

    Suppose I will try pooling.
     
  8. AlteredReality

    AlteredReality

    Joined:
    Aug 15, 2011
    Posts:
    397
    Sorry for the delay in reply. I honest am not sure what would cause an instantiate to fail. My initial guess is that the object is being spawned, but you're not seeing it for some reason. I'd recommend putting a log statement in the instantiate code to verify if the trigger is being triggered. Although, like you mentioned, pooling would be your best bet, as spawning at runtime should generally be avoided. You could make a custom trigger script based off of the spawn one to do what you need.
     
  9. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Yeah, we tried all that.

    Cheers mate.
     
  10. AlteredReality

    AlteredReality

    Joined:
    Aug 15, 2011
    Posts:
    397
    If you didn't see it actually get triggered, then you may need to adjust thresholds to account for differences in framerate/visualization on the device. If you did see it get triggered, but nothing spawned, then I'm pretty sure it's not something in VS.
     
  11. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    It's tough to follow through properly on this since the tablet was running it via webplayer short of throwing in some more user facing debug (which I suppose we will at some point then), we still really enjoy the plugin, it onlys fail on that particular tablet so far. Thanks for your feedback.
     
  12. JamesThornton

    JamesThornton

    Joined:
    Jun 26, 2015
    Posts:
    52
    I love Visualizer Studio. It's so versatile, I've been able to do a lot more than expected. You pulled a ton of capability out of simple spectrum data. Great job!
     
  13. pencilking2002

    pencilking2002

    Joined:
    Sep 30, 2013
    Posts:
    23
    Thanks for making a cool plugin!
    I tried building to WebGL but the build failed with a message of "The name 'Microphone' does not exist in the current context" in the console. I think this error is related to the fact that WebGL and Microphone support sucks in Unity at the moment as seen in this post. When reading the thread however, it seems like there is a solution that can be implemented (at least until Unity's support is better). @AlteredReality Could you please look into this? Right now it seems like with your plugin installed, games cannot be shipped via WebGL.
     
  14. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Yup. I second this.
    WebGL build now does in fact build. But nothing happens.
    When I tried attaching the debugger unity exploded. I reported it.
    Any clues on Webgl use would be great.
     
  15. Dreamcube017

    Dreamcube017

    Joined:
    Dec 20, 2009
    Posts:
    253
    I'm trying to use this in Unity 2018.1.f1 and it's giving me the following errors.

    upload_2018-5-11_17-17-7.png

    I've tried installing the Substance plugin for the store, but the errors don't go away. It look like procedural materials are used throughout the scripts, so I can't figure out how to properly remove them.

    I know it's been a while, but do you have any suggestions? Thanks.
     
    twobob likes this.
  16. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Ok so both KLAK and I.C.E has issues on 2018.2.0b1 (after looking at them I find...)

    Yup. 3 files needed fixing and the particle system needs updating.

    VisMaterialPropertyTrigger.cs should have read

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. /// <summary>
    5. /// This trigger is used to set a float material
    6. /// property as a reaction to changes in the music.
    7. /// </summary>
    8. [AddComponentMenu("Visualizer Studio/Triggers/Material Property Trigger")]
    9. public class VisMaterialPropertyTrigger : VisBasePropertyTrigger
    10. {
    11.    #region Defaults Static Class
    12.  
    13.    /// <summary>
    14.     /// This internal class holds all of the defaults of the VisMaterialPropertyTrigger class.
    15.    /// </summary>
    16.    public static new class Defaults
    17.    {
    18.         public const string targetProperty = "";
    19.         public const bool setAsProceduralMaterial = false;
    20.         public const bool rebuildProceduralTexturesImmediately = false;
    21.         public const bool applyToMaterialIndex = false;
    22.         public const int materialIndex = 0;
    23.    }
    24.  
    25.    #endregion
    26.  
    27.    #region Public Member Variables
    28.  
    29.    /// <summary>
    30.    /// This is the target property to modify on the parent game object.
    31.    /// As an example of how this works:
    32.    /// minControllerValue = 0.2
    33.    /// maxControllerValue = 0.8
    34.    /// minPropertyValue = 2.0
    35.    /// maxPropertyValue = 4.0
    36.    /// invertValue = false
    37.    ///
    38.    /// controllerInputValue = 0.5 -- newPropertyValue = 3.0
    39.    /// controllerInputVlaue = 0.35 -- newPropertyValue = 2.5
    40.     /// </summary>
    41.     //[HideInInspector()]
    42.     public string targetProperty = Defaults.targetProperty;
    43.  
    44.     /// <summary>
    45.     /// This indicates if this material property modifier should treat the target as a procedural
    46.     /// material and attempt to set the target property as a procedural float.
    47.     /// </summary>
    48.     //[HideInInspector()]
    49.     public bool setAsProceduralMaterial = false;
    50.  
    51.     /// <summary>
    52.     /// This indicates if the procedural textures should immediately be regenerated when setting a float on the target material.
    53.     /// </summary>
    54.     //[HideInInspector()]
    55.     public bool rebuildProceduralTexturesImmediately = false;
    56.  
    57.     /// <summary>
    58.     /// This indicates if this material property modifier should apply
    59.     /// to a material in a specific index, or the main material.
    60.     /// </summary>
    61.     //[HideInInspector()]
    62.     public bool applyToMaterialIndex = false;
    63.  
    64.     /// <summary>
    65.     /// This is the material index to apply this property change to.
    66.     /// </summary>
    67.     //[HideInInspector()]
    68.     public int materialIndex = 0;
    69.  
    70.     #endregion
    71.  
    72.     #region Private Members
    73.  
    74.     /// <summary>
    75.     /// This indicates if there was a special target property name entrered for this material property trigger.
    76.     /// Valid values are ColorR, ColorRed, ColorG, ColorGreen, ColorB, ColorBlue, ColorA, ColorAlpha, and Color.
    77.     /// </summary>
    78.     private bool specialTargetProperty = false;
    79.  
    80.     #endregion
    81.  
    82.    #region Init/Deinit Functions
    83.  
    84.    /// <summary>
    85.    /// This is callled when this commponent is reset.
    86.    /// </summary>
    87.    public override void Reset()
    88.    {
    89.        base.Reset();
    90.  
    91.         targetProperty = Defaults.targetProperty;
    92.         setAsProceduralMaterial = Defaults.setAsProceduralMaterial;
    93.         rebuildProceduralTexturesImmediately = Defaults.rebuildProceduralTexturesImmediately;
    94.         applyToMaterialIndex = Defaults.applyToMaterialIndex;
    95.         materialIndex = Defaults.materialIndex;
    96.    }
    97.  
    98.    /// <summary>
    99.    /// This is called when this component is started.
    100.    /// </summary>
    101.    public override void Start()
    102.    {
    103.         base.Start();
    104.  
    105.         //check if this is using a special value
    106.         string lowerCaseTargetProperty = targetProperty.ToLower();
    107.         if (lowerCaseTargetProperty == "colorr" ||
    108.             lowerCaseTargetProperty == "colorred" ||
    109.             lowerCaseTargetProperty == "colorg" ||
    110.             lowerCaseTargetProperty == "colorgreen" ||
    111.             lowerCaseTargetProperty == "colorb" ||
    112.             lowerCaseTargetProperty == "colorblue" ||
    113.             lowerCaseTargetProperty == "colora" ||
    114.             lowerCaseTargetProperty == "coloralpha" ||
    115.             lowerCaseTargetProperty == "color")
    116.             specialTargetProperty = true;
    117.         else
    118.             specialTargetProperty = false;
    119.    }
    120.  
    121.    #endregion
    122.  
    123.     #region VisBasePropertyTrigger Implementation
    124.  
    125.     /// <summary>
    126.     /// This function is used to call into sub classes of
    127.     /// VisBasePropertyTrigger, in order for them to set their
    128.     /// target property to the new value specified.
    129.     /// </summary>
    130.     /// <param name="propertyValue">The new value to set the property to.</param>
    131.     public override void SetProperty(float propertyValue)
    132.     {
    133.         //create var to store target material
    134.         Material targetMaterial = null;
    135.         Renderer rendererComp = GetComponent<Renderer>();
    136.  
    137.         //get the target material
    138.         if (setAsProceduralMaterial &&
    139.             applyToMaterialIndex &&
    140.             rendererComp != null &&
    141.             materialIndex >= 0 &&
    142.             materialIndex < rendererComp.sharedMaterials.Length &&
    143. #if (!UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0 && !UNITY_2_6_1 && !UNITY_2_6 && !UNITY_2018_1_OR_NEWER) && (UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_EDITOR)
    144. rendererComp.sharedMaterials[materialIndex] as ProceduralMaterial)
    145.         {//get indexed material as procedural material
    146.             targetMaterial = rendererComp.sharedMaterials[materialIndex];
    147.         }
    148. #else
    149.             true)
    150.         {//can't sure procedural materials on IOS or Android!        
    151.             Debug.LogWarning("Procedural Materials cannot be used on IOS or Android, and also requires Unity 3.4 or later!");
    152.         }
    153. #endif
    154.         else if (setAsProceduralMaterial &&
    155.                  rendererComp != null &&
    156.                  rendererComp.sharedMaterial != null &&
    157. #if (!UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0 && !UNITY_2_6_1 && !UNITY_2_6 && !UNITY_2018_1_OR_NEWER) && (UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_EDITOR)
    158. rendererComp.sharedMaterial as ProceduralMaterial)
    159.         {//get main material as procedural material
    160.             targetMaterial = rendererComp.sharedMaterial;
    161.         }
    162. #else
    163.                  true)
    164.         {//can't sure procedural materials on IOS or Android!        
    165.             Debug.LogWarning("Procedural Materials cannot be used on IOS or Android, and also requires Unity 3.4 or later!");
    166.         }
    167. #endif
    168.         else if (applyToMaterialIndex &&
    169.             rendererComp != null &&
    170.             materialIndex >= 0 &&
    171.             materialIndex < rendererComp.materials.Length)
    172.         {//get indexed material as normal material
    173.             targetMaterial = rendererComp.materials[materialIndex];
    174.         }
    175.         else if (rendererComp != null &&
    176.                  rendererComp.material != null)
    177.         {//get main material as procedural material
    178.             targetMaterial = rendererComp.material;
    179.         }
    180.  
    181.         //make sure a target material was found
    182.         if (targetMaterial != null)
    183.         {
    184. #if (!UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0 && !UNITY_2_6_1 && !UNITY_2_6 && !UNITY_2018_1_OR_NEWER) && (UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_EDITOR)
    185.             //check if this should be set as a procedural material and it actual is on
    186.             if (setAsProceduralMaterial &&
    187.                 targetMaterial as ProceduralMaterial)
    188.             {
    189.                 //get procedural material
    190.                 ProceduralMaterial procMat = targetMaterial as ProceduralMaterial;
    191.  
    192.                 //make sure the value has changed
    193.                 float current = procMat.GetProceduralFloat(targetProperty);
    194.                 if (current != propertyValue)
    195.                 {
    196.                     //set float and rebuild texture
    197.                     procMat.SetProceduralFloat(targetProperty, propertyValue);
    198.                     if (rebuildProceduralTexturesImmediately)
    199.                         procMat.RebuildTexturesImmediately();
    200.                     else
    201.                         procMat.RebuildTextures();
    202.                 }
    203.             }
    204.             else
    205. #endif
    206.             {
    207.                 //check if there is a special target property set
    208.                 if (specialTargetProperty)
    209.                 {
    210.                     //check for special float
    211.                     switch (targetProperty.ToLower())
    212.                     {
    213.                         case "colorr":
    214.                         case "colorred":
    215.                             float clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    216.                             Color newColor = new Color(clampedValue,
    217.                                                        targetMaterial.color.g,
    218.                                                        targetMaterial.color.b,
    219.                                                        targetMaterial.color.a);
    220.                             targetMaterial.color = newColor;
    221.                             break;
    222.                         case "colorg":
    223.                         case "colorgreen":
    224.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    225.                             newColor = new Color(targetMaterial.color.r,
    226.                                                  clampedValue,
    227.                                                  targetMaterial.color.b,
    228.                                                  targetMaterial.color.a);
    229.                             targetMaterial.color = newColor;
    230.                             break;
    231.                         case "colorb":
    232.                         case "colorblue":
    233.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    234.                             newColor = new Color(targetMaterial.color.r,
    235.                                                  targetMaterial.color.g,
    236.                                                  clampedValue,
    237.                                                  targetMaterial.color.a);
    238.                             targetMaterial.color = newColor;
    239.                             break;
    240.                         case "colora":
    241.                         case "coloralpha":
    242.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    243.                             newColor = new Color(targetMaterial.color.r,
    244.                                                  targetMaterial.color.g,
    245.                                                  targetMaterial.color.b,
    246.                                                  clampedValue);
    247.                             targetMaterial.color = newColor;
    248.                             break;
    249.                         case "color":
    250.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    251.                             newColor = new Color(clampedValue,
    252.                                                  clampedValue,
    253.                                                  clampedValue,
    254.                                                  targetMaterial.color.a);
    255.                             targetMaterial.color = newColor;
    256.                             break;
    257.                         default:
    258.                             //set float
    259.                             targetMaterial.SetFloat(targetProperty, propertyValue);
    260.                             break;
    261.                     }
    262.                 }
    263.                 else
    264.                 {
    265.                     //set float
    266.                     targetMaterial.SetFloat(targetProperty, propertyValue);
    267.                 }
    268.             }
    269.         }
    270.     }
    271.  
    272.     #endregion
    273. }
    274.  


    VisPropertyHelper.cs Should have read (This still needs fixing I just nerfed the death on particles)

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. #region Enumerations
    4.  
    5. /// <summary>
    6. /// This enumeration describes what basic property
    7. /// of the game object should be modified.
    8. /// </summary>
    9. public enum GameObjectProperty
    10. {
    11.    /// <summary>
    12.    /// The game object x position.
    13.    /// </summary>
    14.    XPosition,
    15.  
    16.    /// <summary>
    17.    /// The game object y position.
    18.    /// </summary>
    19.    YPosition,
    20.  
    21.    /// <summary>
    22.    /// The game object z position.
    23.    /// </summary>
    24.    ZPosition,
    25.  
    26.    /// <summary>
    27.    /// The game object x rotation.
    28.    /// </summary>
    29.    XRotation,
    30.  
    31.    /// <summary>
    32.    /// The game object y rotation.
    33.    /// </summary>
    34.    YRotation,
    35.  
    36.    /// <summary>
    37.    /// The game object z rotation.
    38.    /// </summary>
    39.    ZRotation,
    40.  
    41.    /// <summary>
    42.    /// The game object x velocity.
    43.    /// </summary>
    44.    XVelocity,
    45.  
    46.    /// <summary>
    47.    /// The game object y velocity.
    48.    /// </summary>
    49.    YVelocity,
    50.  
    51.    /// <summary>
    52.    /// The game object z velocity.
    53.    /// </summary>
    54.    ZVelocity,
    55.  
    56.    /// <summary>
    57.    /// The game object x angular velocity.
    58.    /// </summary>
    59.    XAngularVelocity,
    60.  
    61.    /// <summary>
    62.    /// The game object y angular velocity.
    63.    /// </summary>
    64.    YAngularVelocity,
    65.  
    66.    /// <summary>
    67.    /// The game object z angular velocity.
    68.    /// </summary>
    69.    ZAngularVelocity,
    70.  
    71.    /// <summary>
    72.    /// The game object overall scale.
    73.    /// </summary>
    74.    UniformScale,
    75.  
    76.    /// <summary>
    77.    /// The game object x scale.
    78.    /// </summary>
    79.    XScale,
    80.  
    81.    /// <summary>
    82.    /// The game object y scale.
    83.    /// </summary>
    84.    YScale,
    85.  
    86.    /// <summary>
    87.    /// The game object z scale.
    88.    /// </summary>
    89.    ZScale
    90. }
    91.  
    92. public enum EmitterProperty
    93. {
    94.     AngularVelocity,
    95.     RandomAngularVelocity,
    96.     EmitterVelocityScale,
    97.     MinSize,
    98.     MaxSize,
    99.     MinEnergy,
    100.     MaxEnergy,
    101.     MinEmission,
    102.     MaxEmission
    103. }
    104.  
    105. public enum LightProperty
    106. {
    107.     ColorRed,
    108.     ColorGreen,
    109.     ColorBlue,
    110.     ColorRGB,
    111.     ColorAlpha,
    112.     Intensity,
    113.     Range,
    114.     SpotAngle,
    115.     ShadowBias,
    116. #if (UNITY_2_6 || UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6)
    117.     ShadowSoftness,
    118.     ShadowSoftnessFade,
    119. #else
    120.     ShadowSoftness_DEPRECATED,
    121.     ShadowSoftnessFade_DEPRECATED,
    122. #endif
    123.     ShadowStrength
    124. }
    125.  
    126. public enum AnimationStateProperty
    127. {
    128.     Speed,
    129.     NormalizedTime,
    130.     Weight
    131. }
    132.  
    133. #endregion
    134.  
    135. /// <summary>
    136. /// This static class is used to provide helper functions for Visualizer Studio.
    137. /// </summary>
    138. public static class VisPropertyHelper
    139. {    
    140.     #region Setter Functions
    141.  
    142.     /// <summary>
    143.     /// This function is used to help set basic properties on a game object
    144.     /// in a generic way.
    145.     /// </summary>
    146.     /// <param name="gameObject">The game object whose properties are to be set.</param>
    147.     /// <param name="targetProperty">The target property to set.</param>
    148.     /// <param name="propertyValue">The value to set the target property to.</param>
    149.     public static void SetGameObjectProperty(GameObject gameObject, GameObjectProperty targetProperty, float propertyValue)
    150.    {
    151.        //check if the game object is null
    152.        if (gameObject == null)
    153.        {
    154.            return;
    155.        }
    156.  
    157.         Rigidbody rigidbodyComp = gameObject.GetComponent<Rigidbody>();
    158.      
    159.        //set the property
    160.         switch (targetProperty)
    161.         {
    162.             case GameObjectProperty.XPosition:
    163.                 if (gameObject.transform != null)
    164.                     gameObject.transform.position = new Vector3(propertyValue,
    165.                                                                gameObject.transform.position.y,
    166.                                                                gameObject.transform.position.z);
    167.                 break;
    168.             case GameObjectProperty.YPosition:
    169.                 if (gameObject.transform != null)
    170.                     gameObject.transform.position = new Vector3(gameObject.transform.position.x,
    171.                                                                propertyValue,
    172.                                                                gameObject.transform.position.z);
    173.                 break;
    174.             case GameObjectProperty.ZPosition:
    175.                 if (gameObject.transform != null)
    176.                     gameObject.transform.position = new Vector3(gameObject.transform.position.x,
    177.                                                                gameObject.transform.position.y,
    178.                                                                  propertyValue);
    179.                 break;
    180.             case GameObjectProperty.XRotation:
    181.                 if (gameObject.transform != null)
    182.                     gameObject.transform.rotation = Quaternion.Euler(new Vector3(propertyValue,
    183.                                                                                   gameObject.transform.rotation.eulerAngles.y,
    184.                                                                                   gameObject.transform.rotation.eulerAngles.z));
    185.                 break;
    186.             case GameObjectProperty.YRotation:
    187.                 if (gameObject.transform != null)
    188.                     gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x,
    189.                                                                                   propertyValue,
    190.                                                                                 gameObject.transform.rotation.eulerAngles.z));
    191.                 break;
    192.             case GameObjectProperty.ZRotation:
    193.                 if (gameObject.transform != null)
    194.                     gameObject.transform.rotation = Quaternion.Euler(new Vector3(gameObject.transform.rotation.eulerAngles.x,
    195.                                                                                 gameObject.transform.rotation.eulerAngles.y,
    196.                                                                                 propertyValue));
    197.                 break;
    198.             case GameObjectProperty.XVelocity:
    199.                 if (rigidbodyComp != null)
    200.                     rigidbodyComp.velocity = new Vector3(propertyValue,
    201.                                                                rigidbodyComp.velocity.y,
    202.                                                                rigidbodyComp.velocity.z);
    203.                else if (gameObject.transform !=  null)
    204.                    gameObject.transform.Translate(propertyValue * Time.deltaTime, 0.0f, 0.0f);
    205.                 break;
    206.             case GameObjectProperty.YVelocity:
    207.                 if (rigidbodyComp != null)
    208.                     rigidbodyComp.velocity = new Vector3(rigidbodyComp.velocity.x,
    209.                                                                propertyValue,
    210.                                                                rigidbodyComp.velocity.z);
    211.                else if (gameObject.transform !=  null)
    212.                    gameObject.transform.Translate(0.0f, propertyValue * Time.deltaTime, 0.0f);
    213.                 break;
    214.             case GameObjectProperty.ZVelocity:
    215.                 if (rigidbodyComp != null)
    216.                     rigidbodyComp.velocity = new Vector3(rigidbodyComp.velocity.x,
    217.                                                                rigidbodyComp.velocity.y,
    218.                                                                propertyValue);
    219.                else if (gameObject.transform !=  null)
    220.                    gameObject.transform.Translate(0.0f, 0.0f, propertyValue * Time.deltaTime);
    221.                 break;
    222.             case GameObjectProperty.XAngularVelocity:
    223.                 if (rigidbodyComp != null)
    224.                     rigidbodyComp.angularVelocity = new Vector3(propertyValue,
    225.                                                                       rigidbodyComp.angularVelocity.y,
    226.                                                                       rigidbodyComp.angularVelocity.z);
    227.                else if (gameObject.transform != null)
    228.                    gameObject.transform.Rotate(propertyValue * Time.deltaTime, 0.0f, 0.0f);
    229.                 break;
    230.             case GameObjectProperty.YAngularVelocity:
    231.                 if (rigidbodyComp != null)
    232.                     rigidbodyComp.angularVelocity = new Vector3(rigidbodyComp.angularVelocity.x,
    233.                                                                        propertyValue,
    234.                                                                        rigidbodyComp.angularVelocity.z);
    235.                else if (gameObject.transform != null)
    236.                    gameObject.transform.Rotate(0.0f, propertyValue * Time.deltaTime, 0.0f);
    237.                 break;
    238.             case GameObjectProperty.ZAngularVelocity:
    239.                 if (rigidbodyComp != null)
    240.                     rigidbodyComp.angularVelocity = new Vector3(rigidbodyComp.angularVelocity.x,
    241.                                                                       rigidbodyComp.angularVelocity.y,
    242.                                                                       propertyValue);
    243.                else if (gameObject.transform != null)
    244.                    gameObject.transform.Rotate(0.0f, 0.0f, propertyValue * Time.deltaTime);
    245.                 break;
    246.             case GameObjectProperty.UniformScale:
    247.                 if (gameObject.transform)
    248.                     gameObject.transform.localScale = new Vector3(propertyValue,
    249.                                                                    propertyValue,
    250.                                                                    propertyValue);
    251.                 break;
    252.             case GameObjectProperty.XScale:
    253.                 if (gameObject.transform)
    254.                     gameObject.transform.localScale = new Vector3(propertyValue,
    255.                                                                    gameObject.transform.localScale.y,
    256.                                                                    gameObject.transform.localScale.z);
    257.                 break;
    258.             case GameObjectProperty.YScale:
    259.                 if (gameObject.transform)
    260.                     gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x,
    261.                                                                    propertyValue,
    262.                                                                    gameObject.transform.localScale.z);
    263.                 break;
    264.             case GameObjectProperty.ZScale:
    265.                 if (gameObject.transform)
    266.                     gameObject.transform.localScale = new Vector3(gameObject.transform.localScale.x,
    267.                                                                    gameObject.transform.localScale.y,
    268.                                                                    propertyValue);
    269.                 break;
    270.             default:
    271.                 break;
    272.         }
    273.    }
    274.  
    275.  
    276.  
    277.  
    278.  
    279.  
    280.  
    281.  
    282.  
    283.  
    284.  
    285.  
    286.  
    287.     /// <summary>
    288.     /// This function is used to help set basic properties on a particle emitter
    289.     /// in a generic way.
    290.     /// </summary>
    291.     /// <param name="emitter">The particle emitter whose properties are to be set.</param>
    292.     /// <param name="targetProperty">The target property to set.</param>
    293.     /// <param name="propertyValue">The value to set the target property to.</param>
    294.    public static void SetEmitterProperty(ParticleEmitter emitter, EmitterProperty targetProperty, float propertyValue)
    295.     {
    296.  
    297.     ParticleSystem system;
    298.  
    299.     ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams();
    300.  
    301.         ////check if the emitter is null
    302.         //if (emitter == null)
    303.         //{
    304.         //    return;
    305.         //}
    306.  
    307.         //// 2018  find something actually useful.
    308.  
    309.         //system = emitter.GetComponent<ParticleSystem>();
    310.    
    311.  
    312.         ////set the property
    313.         //switch (targetProperty)
    314.         //{
    315.  
    316.            
    317.  
    318.         //    case EmitterProperty.AngularVelocity:
    319.         //        emitParams.angularVelocity = propertyValue;
    320.         //        break;
    321.         //    case EmitterProperty.RandomAngularVelocity:
    322.  
    323.         //        // hmmm  I'll fix this later
    324.  
    325.         //        float rotation = Random.value * 360f;
    326.         //        emitParams.angularVelocity = rotation;
    327.         //        emitParams.rotation = rotation;
    328.         //        emitParams.angularVelocity = angularV;
    329.         //        emitParams.startLifetime = Random.Range(minEnergy, maxEnergy);
    330.         //        emitParams.startColor = color;
    331.         //        emitParams.startSize = Random.Range(minSize, maxSize);
    332.  
    333.  
    334.  
    335.  
    336.  
    337.  
    338.  
    339.         //        emitParams.angularVelocity = propertyValue;
    340.         //        break;
    341.         //    case EmitterProperty.EmitterVelocityScale:
    342.         //        emitParams.emitterVelocityScale = propertyValue;
    343.         //        break;
    344.         //    case EmitterProperty.MinSize:
    345.         //        emitParams.minSize = propertyValue;
    346.         //        break;
    347.         //    case EmitterProperty.MaxSize:
    348.         //        emitParams.maxSize = propertyValue;
    349.         //        break;
    350.         //    case EmitterProperty.MinEnergy:
    351.         //        emitParams.minEnergy = propertyValue;
    352.         //        break;
    353.         //    case EmitterProperty.MaxEnergy:
    354.         //        emitParams.maxEnergy = propertyValue;
    355.         //        break;
    356.         //    case EmitterProperty.MinEmission:
    357.         //        emitParams.minEmission = propertyValue;
    358.         //        break;
    359.         //    case EmitterProperty.MaxEmission:
    360.         //        emitParams.maxEmission = propertyValue;
    361.         //        break;
    362.         //    default:
    363.         //        break;
    364.         //}
    365.     }
    366.  
    367.     /// <summary>
    368.     /// This function is used to help set basic properties on a light
    369.     /// in a generic way.
    370.     /// </summary>
    371.     /// <param name="light">The light whose properties are to be set.</param>
    372.     /// <param name="targetProperty">The target property to set.</param>
    373.     /// <param name="propertyValue">The value to set the target property to.</param>
    374.    public static void SetLightProperty(Light light, LightProperty targetProperty, float propertyValue)
    375.    {
    376.        //check if the light is null
    377.        if (light == null)
    378.        {
    379.            return;
    380.        }
    381.  
    382.         //set the property
    383.         switch (targetProperty)
    384.         {
    385.             case LightProperty.ColorRed:
    386.                 light.color = new Color(propertyValue,
    387.                                         light.color.g,
    388.                                         light.color.b,
    389.                                         light.color.a);
    390.                 break;
    391.             case LightProperty.ColorGreen:
    392.                 light.color = new Color(light.color.r,
    393.                                         propertyValue,
    394.                                         light.color.b,
    395.                                         light.color.a);
    396.                 break;
    397.             case LightProperty.ColorBlue:
    398.                 light.color = new Color(light.color.r,
    399.                                         light.color.g,
    400.                                         propertyValue,
    401.                                         light.color.a);
    402.                 break;
    403.             case LightProperty.ColorRGB:
    404.                 light.color = new Color(propertyValue,
    405.                                         propertyValue,
    406.                                         propertyValue,
    407.                                         light.color.a);
    408.                 break;
    409.             case LightProperty.ColorAlpha:
    410.                 light.color = new Color(light.color.r,
    411.                                         light.color.g,
    412.                                         light.color.b,
    413.                                         propertyValue);
    414.                 break;
    415.             case LightProperty.Intensity:
    416.                 light.intensity = propertyValue;
    417.                 break;
    418.             case LightProperty.Range:
    419.                 light.range = propertyValue;
    420.                 break;
    421.             case LightProperty.SpotAngle:
    422.                 light.spotAngle = propertyValue;
    423.                 break;
    424.             case LightProperty.ShadowBias:
    425.                 light.shadowBias = propertyValue;
    426.                 break;
    427. #if (UNITY_2_6 || UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6)
    428.             case LightProperty.ShadowSoftness:
    429.                 light.shadowSoftness = propertyValue;
    430.                 break;
    431.             case LightProperty.ShadowSoftnessFade:
    432.                 light.shadowSoftnessFade = propertyValue;
    433.                 break;
    434. #endif
    435.             case LightProperty.ShadowStrength:
    436.                 light.shadowStrength = propertyValue;
    437.                 break;
    438.             default:
    439.                 break;
    440.         }
    441.    }
    442.  
    443.     /// <summary>
    444.     /// This function is used to help set basic properties on a animation state
    445.     /// in a generic way.
    446.     /// </summary>
    447.     /// <param name="animationState">The animation state whose properties are to be set.</param>
    448.     /// <param name="targetProperty">The target property to set.</param>
    449.     /// <param name="propertyValue">The value to set the target property to.</param>
    450.    public static void SetAnimationStateProperty(AnimationState animationState, AnimationStateProperty targetProperty, float propertyValue)
    451.    {
    452.        //check if the animation is null
    453.         if (animationState == null)
    454.        {
    455.            return;
    456.        }
    457.  
    458.         //set the property
    459.         switch (targetProperty)
    460.         {
    461.             case AnimationStateProperty.Speed:
    462.                 animationState.speed = propertyValue;
    463.                 break;
    464.             case AnimationStateProperty.NormalizedTime:
    465.                 animationState.normalizedTime = propertyValue;
    466.                 break;
    467.             case AnimationStateProperty.Weight:
    468.                 animationState.weight = propertyValue;
    469.                 break;
    470.             default:
    471.                 break;
    472.         }
    473.    }
    474.  
    475.     #endregion
    476. }
    VisMaterialPropertyModifier.cs

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. /// <summary>
    5. /// This modifier is used to set float material properties.
    6. /// </summary>
    7. [AddComponentMenu("Visualizer Studio/Modifiers/Material Property Modifier")]
    8. public class VisMaterialPropertyModifier : VisBasePropertyModifier
    9. {
    10.    #region Defaults Static Class
    11.  
    12.    /// <summary>
    13.     /// This internal class holds all of the defaults of the VisMaterialPropertyModifier class.
    14.    /// </summary>
    15.    public static new class Defaults
    16.    {
    17.         public const string targetProperty = "";
    18.         public const bool setAsProceduralMaterial = false;
    19.         public const bool rebuildProceduralTexturesImmediately = false;
    20.         public const bool applyToMaterialIndex = false;
    21.         public const int materialIndex = 0;
    22.    }
    23.  
    24.    #endregion
    25.  
    26.    #region Public Member Variables
    27.  
    28.    /// <summary>
    29.    /// This is the target property to modify on the parent game object.
    30.    /// As an example of how this works:
    31.    /// minControllerValue = 0.2
    32.    /// maxControllerValue = 0.8
    33.    /// minPropertyValue = 2.0
    34.    /// maxPropertyValue = 4.0
    35.    /// invertValue = false
    36.    ///
    37.    /// controllerInputValue = 0.5 -- newPropertyValue = 3.0
    38.    /// controllerInputVlaue = 0.35 -- newPropertyValue = 2.5
    39.    /// </summary>
    40.     //[HideInInspector()]
    41.    public string targetProperty = Defaults.targetProperty;
    42.  
    43.     /// <summary>
    44.     /// This indicates if this material property modifier should treat the target as a procedural
    45.     /// material and attempt to set the target property as a procedural float.
    46.     /// </summary>
    47.     //[HideInInspector()]
    48.     public bool setAsProceduralMaterial = false;
    49.  
    50.     /// <summary>
    51.     /// This indicates if the procedural textures should immediately be regenerated when setting a float on the target material.
    52.     /// </summary>
    53.     //[HideInInspector()]
    54.     public bool rebuildProceduralTexturesImmediately = false;
    55.  
    56.     /// <summary>
    57.     /// This indicates if this material property modifier should apply to a material in a specific index, or the main material.
    58.     /// </summary>
    59.     //[HideInInspector()]
    60.     public bool applyToMaterialIndex = false;
    61.  
    62.     /// <summary>
    63.     /// This is the material index to apply this property change to.
    64.     /// </summary>
    65.     //[HideInInspector()]
    66.     public int materialIndex = 0;
    67.  
    68.    #endregion
    69.  
    70.     #region Private Members
    71.  
    72.     /// <summary>
    73.     /// This indicates if there was a special target property name entrered for this material property modifier.
    74.     /// Valid values are ColorR, ColorRed, ColorG, ColorGreen, ColorB, ColorBlue, ColorA, ColorAlpha, and Color.
    75.     /// </summary>
    76.     private bool specialTargetProperty = false;
    77.  
    78.     #endregion
    79.  
    80.     #region Init/Deinit Functions
    81.  
    82.     /// <summary>
    83.    /// This is callled when this commponent is reset.
    84.    /// </summary>
    85.    public override void Reset()
    86.    {
    87.        base.Reset();
    88.          
    89.        targetProperty = Defaults.targetProperty;
    90.         setAsProceduralMaterial = Defaults.setAsProceduralMaterial;
    91.         applyToMaterialIndex = Defaults.applyToMaterialIndex;
    92.         materialIndex = Defaults.materialIndex;
    93.    }
    94.  
    95.    /// <summary>
    96.    /// This is called when this component is started.
    97.    /// </summary>
    98.    public override void Start()
    99.    {
    100.        base.Start();    
    101.  
    102.         //check if this is using a special value
    103.         string lowerCaseTargetProperty = targetProperty.ToLower();
    104.         if (lowerCaseTargetProperty == "colorr" ||
    105.             lowerCaseTargetProperty == "colorred" ||
    106.             lowerCaseTargetProperty == "colorg" ||
    107.             lowerCaseTargetProperty == "colorgreen" ||
    108.             lowerCaseTargetProperty == "colorb" ||
    109.             lowerCaseTargetProperty == "colorblue" ||
    110.             lowerCaseTargetProperty == "colora" ||
    111.             lowerCaseTargetProperty == "coloralpha" ||
    112.             lowerCaseTargetProperty == "color")
    113.             specialTargetProperty = true;
    114.         else
    115.             specialTargetProperty = false;
    116.    }
    117.  
    118.    #endregion
    119.  
    120.     #region VisBasePropertyModifier Implementation
    121.  
    122.     /// <summary>
    123.     /// This function is used to call into sub classes of
    124.     /// VisBasePropertyModifer, in order for them to set their
    125.     /// target property to the new value specified.
    126.     /// </summary>
    127.     /// <param name="propertyValue">The new value to set the property to.</param>
    128.     public override void SetProperty(float propertyValue)
    129.     {
    130.         //create var to store target material
    131.         Material targetMaterial = null;
    132.         Renderer rendererComp = GetComponent<Renderer>();
    133.  
    134.         //get the target material
    135.         if (setAsProceduralMaterial &&
    136.             applyToMaterialIndex &&
    137.             rendererComp != null &&
    138.             materialIndex >= 0 &&
    139.             materialIndex < rendererComp.sharedMaterials.Length &&
    140. #if (!UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0 && !UNITY_2_6_1 && !UNITY_2_6 && !UNITY_2018_1_OR_NEWER) && (UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_EDITOR)
    141.             rendererComp.sharedMaterials[materialIndex] as ProceduralMaterial)
    142.         {//get indexed material as procedural material
    143.             targetMaterial = rendererComp.sharedMaterials[materialIndex];
    144.         }
    145. #else
    146.             true)
    147.         {//can't sure procedural materials on IOS or Android!        
    148.             Debug.LogWarning("Procedural Materials cannot be used on IOS or Android, and also requires Unity 3.4 or later!");
    149.         }
    150. #endif
    151.         else if (setAsProceduralMaterial &&
    152.                  rendererComp != null &&
    153.                  rendererComp.sharedMaterial != null &&
    154. #if (!UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0 && !UNITY_2_6_1 && !UNITY_2_6 && !UNITY_2018_1_OR_NEWER) && (UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_EDITOR)
    155.                  rendererComp.sharedMaterial as ProceduralMaterial)
    156.         {//get main material as procedural material
    157.             targetMaterial = rendererComp.sharedMaterial;
    158.         }
    159. #else
    160.                  true)
    161.         {//can't sure procedural materials on IOS or Android!        
    162.             Debug.LogWarning("Procedural Materials cannot be used on IOS or Android, and also requires Unity 3.4 or later!");
    163.         }
    164. #endif
    165.         else if (applyToMaterialIndex &&
    166.                  rendererComp != null &&
    167.                  materialIndex >= 0 &&
    168.                  materialIndex < rendererComp.materials.Length)
    169.         {//get indexed material as normal material
    170.             targetMaterial = rendererComp.materials[materialIndex];
    171.         }
    172.         else if (rendererComp != null &&
    173.                  rendererComp.material != null)
    174.         {//get main material as procedural material
    175.             targetMaterial = rendererComp.material;
    176.         }
    177.  
    178.         //make sure a target material was found
    179.         if (targetMaterial != null)
    180.         {
    181. #if (!UNITY_3_5 && !UNITY_3_4 && !UNITY_3_3 && !UNITY_3_2 && !UNITY_3_1 && !UNITY_3_0_0 && !UNITY_3_0 && !UNITY_2_6_1 && !UNITY_2_6 && !UNITY_2018_1_OR_NEWER) && (UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_EDITOR)
    182.             //check if this should be set as a procedural material and it actual is on
    183.             if (setAsProceduralMaterial &&
    184.                 targetMaterial as ProceduralMaterial)
    185.             {
    186.                 //get procedural material
    187.                 ProceduralMaterial procMat = targetMaterial as ProceduralMaterial;
    188.  
    189.                 //make sure the value has changed
    190.                 float current = procMat.GetProceduralFloat(targetProperty);
    191.                 if (current != propertyValue)
    192.                 {
    193.                     //set float and rebuild texture
    194.                     procMat.SetProceduralFloat(targetProperty, propertyValue);
    195.                     if (rebuildProceduralTexturesImmediately)
    196.                         procMat.RebuildTexturesImmediately();
    197.                     else
    198.                         procMat.RebuildTextures();
    199.                 }
    200.             }
    201.             else
    202. #endif
    203.             {
    204.                 //check if there is a special target property set
    205.                 if (specialTargetProperty)
    206.                 {
    207.                     //check for special float
    208.                     switch (targetProperty.ToLower())
    209.                     {
    210.                         case "colorr":
    211.                         case "colorred":
    212.                             float clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    213.                             Color newColor = new Color(clampedValue,
    214.                                                        targetMaterial.color.g,
    215.                                                        targetMaterial.color.b,
    216.                                                        targetMaterial.color.a);
    217.                             targetMaterial.color = newColor;
    218.                             break;
    219.                         case "colorg":
    220.                         case "colorgreen":
    221.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    222.                             newColor = new Color(targetMaterial.color.r,
    223.                                                  clampedValue,
    224.                                                  targetMaterial.color.b,
    225.                                                  targetMaterial.color.a);
    226.                             targetMaterial.color = newColor;
    227.                             break;
    228.                         case "colorb":
    229.                         case "colorblue":
    230.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    231.                             newColor = new Color(targetMaterial.color.r,
    232.                                                  targetMaterial.color.g,
    233.                                                  clampedValue,
    234.                                                  targetMaterial.color.a);
    235.                             targetMaterial.color = newColor;
    236.                             break;
    237.                         case "colora":
    238.                         case "coloralpha":
    239.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    240.                             newColor = new Color(targetMaterial.color.r,
    241.                                                  targetMaterial.color.g,
    242.                                                  targetMaterial.color.b,
    243.                                                  clampedValue);
    244.                             targetMaterial.color = newColor;
    245.                             break;
    246.                         case "color":
    247.                             clampedValue = Mathf.Clamp(propertyValue, 0.0f, 1.0f);
    248.                             newColor = new Color(clampedValue,
    249.                                                  clampedValue,
    250.                                                  clampedValue,
    251.                                                  targetMaterial.color.a);
    252.                             targetMaterial.color = newColor;
    253.                             break;
    254.                         default:
    255.                             //set float
    256.                             targetMaterial.SetFloat(targetProperty, propertyValue);
    257.                             break;
    258.                     }
    259.                 }
    260.                 else
    261.                 {
    262.                     //set float
    263.                     targetMaterial.SetFloat(targetProperty, propertyValue);
    264.                 }
    265.             }
    266.         }
    267.     }
    268.  
    269.     #endregion
    270. }

    I think that gets you there.

    Good luck
     
  17. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058


    Seems to work fine now. With the caveat on particles