Beispiel #1
0
    internal void EnsureAllControllersRegistered()
    {
        if (target is MonoBehaviour)
        {
            VisManager          manager         = (target as MonoBehaviour).gameObject.GetComponent <VisManager>();
            VisBaseController[] controllerArray = (target as MonoBehaviour).gameObject.GetComponents <VisBaseController>();

            if (manager != null)
            {
                manager.ClearDataGroups();
            }
            for (int i = 0; i < controllerArray.Length; i++)
            {
                controllerArray[i].EnsureRegistered();
            }
        }

        Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));
        for (int i = 0; i < visManagers.Length; i++)
        {
            (visManagers[i] as VisManager).ClearControllers();
        }

        Object[] controllers = GameObject.FindObjectsOfType(typeof(VisBaseController));
        for (int i = 0; i < controllers.Length; i++)
        {
            if (controllers[i])
            {
                (controllers[i] as VisBaseController).EnsureRegistered();
            }
        }
    }
    /// <summary>
    /// This attempts to restore the last set controller on the target.
    /// </summary>
    /// <param name="target">The target to restore.</param>
    /// <returns>Whether or not the target was restored.</returns>
    public static bool RestoreVisBaseControllerTarget(IVisBaseControllerTarget target)
    {
        //make sure the controller is set, and if not, check if there
        //is a name set and try and find that object as the controller
        if (target.Controller == null && target.LastControllerName != null && target.LastControllerName.Length > 0)
        {
            //try to get the manager for this target
            VisManager manager = null;
            if (target is IVisManagerTarget)
            {
                manager = (target as IVisManagerTarget).Manager;
            }

            //make sure a manager was found
            if (manager != null)
            {
                //loop through all controllers and make sure it was found
                for (int i = 0; i < manager.Controllers.Count; i++)
                {
                    if (manager.Controllers[i].controllerName == target.LastControllerName)
                    {
                        target.Controller = manager.Controllers[i];
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
Beispiel #3
0
    internal void EnsureAllDataGroupsRegistered()
    {
        if (target is MonoBehaviour)
        {
            VisManager     manager        = (target as MonoBehaviour).gameObject.GetComponent <VisManager>();
            VisDataGroup[] dataGroupArray = (target as MonoBehaviour).gameObject.GetComponents <VisDataGroup>();

            if (manager != null)
            {
                manager.ClearDataGroups();
            }
            for (int i = 0; i < dataGroupArray.Length; i++)
            {
                dataGroupArray[i].EnsureRegistered();
            }
        }

        Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));
        for (int i = 0; i < visManagers.Length; i++)
        {
            (visManagers[i] as VisManager).ClearDataGroups();
        }

        Object[] dataGroups = GameObject.FindObjectsOfType(typeof(VisDataGroup));
        for (int i = 0; i < dataGroups.Length; i++)
        {
            if (dataGroups[i])
            {
                (dataGroups[i] as VisDataGroup).EnsureRegistered();
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// This function is called when this trigger is started.
    /// Should be override by sub classes to initialize.
    /// </summary>
    public virtual void Start()
    {
        //make sure to restore the targets if needed
        VisManager.RestoreVisManagerTarget(this);
        VisBaseController.RestoreVisBaseControllerTarget(this);

        //validate trigger variables.
        triggerThreshold       = VisHelper.Validate(triggerThreshold, 0.0001f, 10000.0f, Defaults.triggerThreshold, this, "triggerThreshold", false);
        triggerReactivateDelay = VisHelper.Validate(triggerReactivateDelay, 0.0f, 10000.0f, Defaults.triggerReactivateDelay, this, "triggerReactivateDelay", false);
    }
Beispiel #5
0
    /// <summary>
    /// Main inspector gui function.
    /// </summary>
    public override void OnInspectorGUI()
    {
        //make this look like inspect and make sure the target is valid
#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)
        EditorGUIUtility.LookLikeInspector();
#endif

        GUI.changed = false;

        VisManager manager = target as VisManager;
        if (manager == null)
        {
            return;
        }

        manager.audioSource = (AudioSource)EditorGUILayout.ObjectField("  Audio Source", manager.audioSource, typeof(AudioSource), true);
        manager.channel     = (VisManager.Channel)EditorGUILayout.EnumPopup("  Audio Channel", (Enum)manager.channel);
        manager.windowSize  = (VisManager.WindowSize)EditorGUILayout.EnumPopup("  Window Size", (Enum)manager.windowSize);
        manager.windowType  = (UnityEngine.FFTWindow)EditorGUILayout.EnumPopup("  Window Type", (Enum)manager.windowType);

        displayDebugFoldOut = EditorGUILayout.Foldout(displayDebugFoldOut, "Debug");
        if (displayDebugFoldOut)
        {
            manager.displaySpectrumDebug = EditorGUILayout.Toggle("    Display Sectrum", manager.displaySpectrumDebug);
            if (manager.displaySpectrumDebug)
            {
                manager.debugSpectrumBarWidth  = Math.Abs(EditorGUILayout.IntField("      Spectrum Bar Width", manager.debugSpectrumBarWidth));
                manager.debugSpectrumBarHeight = Math.Abs(EditorGUILayout.IntField("      Spectrum Bar Height", manager.debugSpectrumBarHeight));
                manager.debugRawAudioBarHeight = Math.Abs(EditorGUILayout.IntField("      Raw Audio Bar Height", manager.debugRawAudioBarHeight));
            }

            manager.displayDataGroupDebug = EditorGUILayout.Toggle("    Display Data Group", manager.displayDataGroupDebug);
            if (manager.displayDataGroupDebug)
            {
                manager.debugDataGroupBarWidth  = Math.Abs(EditorGUILayout.IntField("      Bar Width", manager.debugDataGroupBarWidth));
                manager.debugDataGroupBarHeight = Math.Abs(EditorGUILayout.IntField("      Bar Height", manager.debugDataGroupBarHeight));
            }

            manager.displayControllerDebug = EditorGUILayout.Toggle("    Display Controller", manager.displayControllerDebug);
            if (manager.displayControllerDebug)
            {
                manager.debugControllerBarWidth  = Math.Abs(EditorGUILayout.IntField("      Bar Width", manager.debugControllerBarWidth));
                manager.debugControllerBarHeight = Math.Abs(EditorGUILayout.IntField("      Bar Height", manager.debugControllerBarHeight));
            }

            manager.debugSeparation = Math.Abs(EditorGUILayout.IntField("    Separation", manager.debugSeparation));
            manager.debugTexture    = (Texture)EditorGUILayout.ObjectField("    Texture", manager.debugTexture, typeof(Texture), false);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Beispiel #6
0
        void Awake()
        {
            if (AmbienceSource == null)
                AmbienceSource = gameObject.AddComponent<AudioSource>();
            if (MovementSource == null)
                MovementSource = gameObject.AddComponent<AudioSource>();
            if (BreathingSource == null)
                BreathingSource = gameObject.AddComponent<AudioSource>();
            if (HeartbeatAudioSource == null)
                HeartbeatAudioSource = gameObject.AddComponent<AudioSource>();
            if (FlatlineSource == null) FlatlineSource = gameObject.AddComponent<AudioSource>();

            if (instance == null) instance = this;
            
            if (HeartbeatAudioSource != null)
            {
                HeartbeatAudioSource.clip = HeartBeat;
                HeartbeatAudioSource.pitch = (Player.Instance.Rate == 0) ? 1 : Player.Instance.Rate;
                HeartbeatAudioSource.loop = true;
                HeartbeatAudioSource.Play();
            }

            if (AmbienceSource != null)
            {
                AmbienceSource.clip = AmbientMusic;
                AmbienceSource.loop = true;
                AmbienceSource.volume = .5f;
                AmbienceSource.Play(5);
            }

            if (BreathingSource != null)
            {
                BreathingSource.clip = Breathing;
                BreathingSource.loop = true;
            }

            if (FlatlineSource != null)
            {
                FlatlineSource.clip = Flatline;
                FlatlineSource.volume = 0.5f;
            }
<<<<<<< HEAD
=======

            VisManager = this.GetComponentInChildren<VisManager>();
            VisManager.audioSource = HeartbeatAudioSource;

>>>>>>> commit this shit
        }
    /// <summary>
    /// This is called when this component is woken up.
    /// </summary>
    public virtual void Awake()
    {
        //make sure to restore the targets if needed
        VisManager.RestoreVisManagerTarget(this);

        //check if there is already a vis manager assigned to this data group
        if (m_oVisManager == null)
        {
            //try to grab a vis manager that belongs to this game object.
            m_oVisManager = GetComponent <VisManager>();

            //check if a vis manager was found
            if (m_oVisManager == null)
            {
                //find all game objects with vis managers
                Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));
                for (int i = 0; i < visManagers.Length; i++)
                {
                    //get this manager and check if it is enabled
                    VisManager manager = visManagers[i] as VisManager;
                    if (manager.enabled)
                    {
                        //assign this vis manager
                        m_oVisManager = manager;
                        break;
                    }
                }
            }
        }

        //validate manager
        ValidateManager(true);

        //make sure this data group is registered with it vis manager
        EnsureRegistered();

        //log an error if no vis manager is assigned
        if (m_oVisManager == null)
        {
            Debug.LogError("This Controller does not have a VisManager assigned to it, nor could it find an active VisManager. In order to function, this Controller needs a VisManager!");
        }
    }
 /// <summary>
 /// This function is called when this modifier is started.
 /// Should be override by sub classes to initialize.
 /// </summary>
 public virtual void Start()
 {
     //make sure to restore the targets if needed
     VisManager.RestoreVisManagerTarget(this);
     VisBaseController.RestoreVisBaseControllerTarget(this);
 }
	/// <summary>
	/// This is called when this component is woken up. 
	/// </summary>
	public virtual void Awake()
    {
        //make sure to restore the targets if needed
        VisManager.RestoreVisManagerTarget(this);

		//check if there is already a vis manager assigned to this data group
		if (m_oVisManager == null)
		{
			//try to grab a vis manager that belongs to this game object.
			m_oVisManager = GetComponent<VisManager>();
			
			//check if a vis manager was found
			if (m_oVisManager == null)
			{
				//find all game objects with vis managers
				Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));
				for (int i = 0; i < visManagers.Length; i++)
				{
					//get this manager and check if it is enabled
					VisManager manager = visManagers[i] as VisManager;
					if (manager.enabled)
					{
						//assign this vis manager
						m_oVisManager = manager;
						break;
					}
				}
			}
        }

        //validate manager
        ValidateManager(true);
	
		//make sure this data group is registered with it vis manager
		EnsureRegistered();
		
		//log an error if no vis manager is assigned
		if (m_oVisManager == null)
		{
			Debug.LogError("This Controller does not have a VisManager assigned to it, nor could it find an active VisManager. In order to function, this Controller needs a VisManager!");
		}
	}
Beispiel #10
0
    /// <summary>
    /// This displays the drop down for selecting a manager from the inspector.
    /// </summary>
    /// <param name="managerTarget">The manager target to set the manager for.</param>
    /// <returns>Whether or not a manager is currently set.</returns>
    public bool DisplayIVisManagerTargetGUI(IVisManagerTarget managerTarget)
    {
        if (managerTarget != null)
        {
            if (managerTarget is MonoBehaviour)
            {
                GameObject gameObject = (managerTarget as MonoBehaviour).gameObject;
                if (managerTarget.Manager == null ||
                    managerTarget.Manager.gameObject != gameObject)
                {
                    VisManager manager = gameObject.GetComponent <VisManager>();
                    if (manager != null)
                    {
                        managerTarget.Manager = manager;
                        return(true);
                    }
                }
                else if (managerTarget.Manager != null &&
                         managerTarget.Manager.gameObject == gameObject)
                {
                    return(true);
                }
            }

            bool result = false;

            EditorGUILayout.BeginHorizontal();

            //make sure and try to restore it first
            VisManager.RestoreVisManagerTarget(managerTarget);

            Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));

            if (visManagers.Length > 0)
            {
                //create list of vis manager names and a dictionary to map IDs, and sort it
                List <string>            sortedNames    = new List <string>(visManagers.Length);
                Dictionary <string, int> nameToIndexMap = new Dictionary <string, int>(visManagers.Length);
                for (int i = 0; i < visManagers.Length; i++)
                {
                    string name = (visManagers[i] as VisManager).name;
                    if (nameToIndexMap.ContainsKey(name) &&
                        ((visManagers[nameToIndexMap[name]] as VisManager).Controllers.Count < (visManagers[i] as VisManager).Controllers.Count ||
                         (visManagers[nameToIndexMap[name]] as VisManager).DataGroups.Count < (visManagers[i] as VisManager).DataGroups.Count))
                    {//override index
                        nameToIndexMap[name] = i;
                    }
                    else
                    {//add new
                        sortedNames.Add((visManagers[i] as VisManager).name);
                        nameToIndexMap.Add((visManagers[i] as VisManager).name, i);
                    }
                }
                sortedNames.Sort();

                //create array of names and set current index
                int      currentIndex   = 0;
                string[] displayedNames = new string[visManagers.Length + 1];
                displayedNames[0] = "None";
                for (int i = 0; i < sortedNames.Count; i++)
                {
                    displayedNames[i + 1] = sortedNames[i];
                    if (managerTarget.Manager == visManagers[nameToIndexMap[sortedNames[i]]])
                    {
                        currentIndex = i + 1;
                    }
                }

                //display popup
                int newIndex = EditorGUILayout.Popup("   Manager", currentIndex, displayedNames);

                //set new vis manager if the index has changed
                if (newIndex != currentIndex)
                {
                    if (newIndex == 0)
                    {
                        managerTarget.Manager = null;
                    }
                    else
                    {
                        string newName       = sortedNames[newIndex - 1];
                        int    remappedIndex = nameToIndexMap[newName];
                        managerTarget.Manager = visManagers[remappedIndex] as VisManager;
                    }
                    EditorUtility.SetDirty(target);
                }
                result = managerTarget.Manager != null;
            }
            else
            {
                if (managerTarget.LastManagerName != null && managerTarget.LastManagerName.Length > 0)
                {
                    EditorGUILayout.LabelField("   Manager", managerTarget.LastManagerName + " (not found, try selecting the Object with this Manager)");
                }
                else
                {
                    EditorGUILayout.LabelField("   Manager", "NO MANAGERS FOUND!");
                }
                result = false;
            }

            managerTarget.Manager = (VisManager)EditorGUILayout.ObjectField(managerTarget.Manager, typeof(VisManager), true, GUILayout.Width(Screen.width * 0.2f));

            EditorGUILayout.EndHorizontal();

            return(result);
        }
        return(false);
    }
Beispiel #11
0
    /// <summary>
    /// This displays the drop down for selecting a controller from the inspector.
    /// </summary>
    /// <param name="baseControllerTarget">The base controller target to set the controller for.</param>
    /// <returns>Whether or not a controller is currently set.</returns>
    public bool DisplayIVisBaseControllerTargetGUI(IVisBaseControllerTarget baseControllerTarget)
    {
        EnsureAllControllersRegistered();

        if (baseControllerTarget != null && baseControllerTarget is IVisManagerTarget)
        {
            //make sure and try to restore it first
            VisBaseController.RestoreVisBaseControllerTarget(baseControllerTarget);

            VisManager manager = (baseControllerTarget as IVisManagerTarget).Manager;
            if (manager != null)
            {
                ReadOnlyCollection <VisBaseController> controllers = manager.Controllers;
                if (controllers.Count > 0)
                {
                    //create list of vis controller names and a dictionary to map IDs, and sort it
                    List <string>            sortedNames    = new List <string>(controllers.Count);
                    Dictionary <string, int> nameToIndexMap = new Dictionary <string, int>(controllers.Count);
                    for (int i = 0; i < controllers.Count; i++)
                    {
                        sortedNames.Add((controllers[i] as VisBaseController).controllerName);
                        nameToIndexMap.Add((controllers[i] as VisBaseController).controllerName, i);
                    }
                    sortedNames.Sort();

                    //create array of names and set current index
                    int      currentIndex   = 0;
                    string[] displayedNames = new string[controllers.Count + 1];
                    displayedNames[0] = "None";
                    for (int i = 0; i < sortedNames.Count; i++)
                    {
                        displayedNames[i + 1] = sortedNames[i];
                        if (baseControllerTarget.Controller == controllers[nameToIndexMap[sortedNames[i]]])
                        {
                            currentIndex = i + 1;
                        }
                    }

                    //display popup
                    int newIndex = EditorGUILayout.Popup("   Controller", currentIndex, displayedNames);

                    //set new vis controller if the index has changed
                    if (newIndex != currentIndex)
                    {
                        if (newIndex == 0)
                        {
                            baseControllerTarget.Controller = null;
                        }
                        else
                        {
                            string newName       = sortedNames[newIndex - 1];
                            int    remappedIndex = nameToIndexMap[newName];
                            baseControllerTarget.Controller = controllers[remappedIndex] as VisBaseController;
                        }
                        EditorUtility.SetDirty(target);
                    }
                    return(baseControllerTarget.Controller != null);
                }
                else
                {
                    if (baseControllerTarget.LastControllerName != null && baseControllerTarget.LastControllerName.Length > 0)
                    {
                        EditorGUILayout.LabelField("   Controller", baseControllerTarget.LastControllerName + " (not found, try selecting the Object with this Controller)");
                    }
                    else
                    {
                        EditorGUILayout.LabelField("   Controller", "NO CONTROLLERS FOUND!");
                    }
                    return(false);
                }
            }
        }
        return(false);
    }
Beispiel #12
0
    /// <summary>
    /// This displays the drop down for selecting a data group from the inspector.
    /// </summary>
    /// <param name="dataGroupTarget">The data group target to set the data group for.</param>
    /// <returns>Whether or not a data group is currently set.</returns>
    public bool DisplayIVisDataGroupTargetGUI(IVisDataGroupTarget dataGroupTarget)
    {
        EnsureAllDataGroupsRegistered();

        if (dataGroupTarget != null && dataGroupTarget is IVisManagerTarget)
        {
            //make sure and try to restore it first
            VisDataGroup.RestoreVisDataGroupTarget(dataGroupTarget);

            VisManager manager = (dataGroupTarget as IVisManagerTarget).Manager;
            if (manager != null)
            {
                ReadOnlyCollection <VisDataGroup> dataGroups = manager.DataGroups;
                if (dataGroups.Count > 0)
                {
                    //create list of vis data group names and a dictionary to map IDs, and sort it
                    List <string>            sortedNames    = new List <string>(dataGroups.Count);
                    Dictionary <string, int> nameToIndexMap = new Dictionary <string, int>(dataGroups.Count);
                    for (int i = 0; i < dataGroups.Count; i++)
                    {
                        sortedNames.Add((dataGroups[i] as VisDataGroup).dataGroupName);
                        nameToIndexMap.Add((dataGroups[i] as VisDataGroup).dataGroupName, i);
                    }
                    sortedNames.Sort();

                    //create array of names and set current index
                    int      currentIndex   = 0;
                    string[] displayedNames = new string[dataGroups.Count + 1];
                    displayedNames[0] = "None";
                    for (int i = 0; i < sortedNames.Count; i++)
                    {
                        displayedNames[i + 1] = sortedNames[i];
                        if (dataGroupTarget.DataGroup == dataGroups[nameToIndexMap[sortedNames[i]]])
                        {
                            currentIndex = i + 1;
                        }
                    }

                    //display popup
                    int newIndex = EditorGUILayout.Popup("   Data Group", currentIndex, displayedNames);

                    //set new vis data group if the index has changed
                    if (newIndex != currentIndex)
                    {
                        if (newIndex == 0)
                        {
                            dataGroupTarget.DataGroup = null;
                        }
                        else
                        {
                            string newName       = sortedNames[newIndex - 1];
                            int    remappedIndex = nameToIndexMap[newName];
                            dataGroupTarget.DataGroup = dataGroups[remappedIndex] as VisDataGroup;
                        }
                        EditorUtility.SetDirty(target);
                    }
                    return(dataGroupTarget.DataGroup != null);
                }
                else
                {
                    if (dataGroupTarget.LastDataGroupName != null && dataGroupTarget.LastDataGroupName.Length > 0)
                    {
                        EditorGUILayout.LabelField("   Data Group", dataGroupTarget.LastDataGroupName + " (not found, try selecting the Object with this Data Group)");
                    }
                    else
                    {
                        EditorGUILayout.LabelField("   Data Group", "NO DATA GROUPS FOUND!");
                    }
                    return(false);
                }
            }
        }
        return(false);
    }