예제 #1
0
 public void UnloadAsset(string componentName, bool ignoreUnloadUnusedAssets = false)
 {
     if (_globalComponentTable.ContainsKey(componentName))
     {
         Component component = _globalComponentTable[componentName];
         if (component != null)
         {
             _components.Remove(component);
             if (component.ParentComponent != null)
             {
                 component.ParentComponent.RemoveComponent(component);
             }
             RemoveChildComponentsFromGlobalTable(component, componentName);
             component.Destroy();
             UnityEngine.Object.Destroy(component.gameObject);
             if (!ignoreUnloadUnusedAssets)
             {
                 Resources.UnloadUnusedAssets();
             }
             DebugLog.Print("Assets [" + componentName + "] unloaded succesfuly");
         }
         else
         {
             DebugLog.Print("Assets [" + componentName + "] failed to unload", DebugLevel.Error);
         }
     }
     else
     {
         DebugLog.Print("Target Component [" + componentName + "] not found", DebugLevel.Error);
     }
 }
예제 #2
0
 public void DecRef(bool unloadAudioClip = true)
 {
     _refCount--;
     if (_refCount != 0)
     {
         return;
     }
     if (unloadAudioClip)
     {
         if (_audioClip != null && IsAudioClipPathSet())
         {
             Resources.UnloadAsset(_audioClip);
             _audioClip = null;
         }
         else if (_audioClip != null)
         {
             if (!_loadAudioDataEventAction)
             {
                 _audioClip.UnloadAudioData();
             }
         }
         else
         {
             DebugLog.Print("AudioClipHandle Failed to unload audio clip [" + _audioClipPath + "]", DebugLevel.Error);
         }
     }
     else
     {
         UnityEngine.Object.DestroyImmediate(_audioClip);
     }
 }
예제 #3
0
 public void Stop(float fadeOut = 0f)
 {
     DebugLog.Print("Stop all components");
     for (int i = 0; i < _components.Count; i++)
     {
         Component component = _components[i];
         component.Stop(stopInstances: true, forceStop: true, ignoreFade: true, 0f);
     }
 }
예제 #4
0
 public void Pause(bool pause)
 {
     DebugLog.Print("Pause all components");
     for (int i = 0; i < _components.Count; i++)
     {
         Component component = _components[i];
         component.Pause(pause);
     }
 }
예제 #5
0
 public void RemoveDSPInstance(UnityEngine.Component dspComponentInstance)
 {
     if (_dspInstances == null)
     {
         DebugLog.Print("DSPComponent [ " + base.name + " ] failed to remove dsp instance", DebugLevel.Error);
     }
     else
     {
         _dspInstances.Remove(dspComponentInstance);
     }
 }
예제 #6
0
        public bool ProcessEvent(Event postedEvent)
        {
            bool   result    = false;
            string eventName = postedEvent._eventName;

            if (eventName == null)
            {
                return(false);
            }
            if (!_listeners.ContainsKey(eventName))
            {
                DebugLog.Print(DebugLevel.Warning, "Event \"", eventName, "\" triggered has no listeners!");
                postedEvent.eventStatus = EventStatus.Failed_No_Listeners;
            }
            else
            {
                if (_eventSequencer != null)
                {
                    _eventSequencer.ProcessEvent(postedEvent);
                }
                List <IEventListener> list = _listeners[eventName];
                int count = list.Count;
                for (int i = 0; i < count; i++)
                {
                    IEventListener eventListener = list[i];
                    if (IsNullOrDestroyed(eventListener))
                    {
                        continue;
                    }
                    if (eventListener.GetEventListeners(eventName, eventListeners))
                    {
                        Event @event = ApplyOverrideEventActions(eventListeners, postedEvent, overrideEvent);
                        if (@event != null)
                        {
                            postedEvent.eventStatus = eventListener.Process(@event);
                        }
                    }
                    else
                    {
                        postedEvent.eventStatus = eventListener.Process(postedEvent);
                    }
                    if (Application.isEditor && postedEvent.EventAction == EventAction.PlaySound)
                    {
                        AddActiveEvent(postedEvent, eventListener as Component);
                    }
                }
                result = ((postedEvent.eventStatus == EventStatus.Handled || postedEvent.eventStatus == EventStatus.Handled_Virtualized) ? true : false);
            }
            LogEvent(postedEvent);
            return(result);
        }
예제 #7
0
        public VirtualizationEventInstance Alloc(Event e)
        {
            if (_eventInstancePool.Count == 0)
            {
                DebugLog.Print("VirtualizationEventInstance: Failed to allocate event instance for Event: " + e._eventName, DebugLevel.Error);
                return(null);
            }
            VirtualizationEventInstance virtualizationEventInstance = _eventInstancePool.Dequeue();
            Event @event = new Event();

            @event.Copy(e);
            virtualizationEventInstance._event = @event;
            return(virtualizationEventInstance);
        }
예제 #8
0
 private void InitData()
 {
     if (_audioClipPath != null)
     {
         AudioClip audioClip = Resources.Load(_audioClipPath) as AudioClip;
         if (audioClip != null)
         {
             int num = audioClip.samples * audioClip.channels;
             _data = new float[num];
             audioClip.GetData(_data, 0);
         }
         else
         {
             DebugLog.Print(DebugLevel.Error, "Sample File [", _name, "] Not loaded");
         }
     }
 }
예제 #9
0
        private bool ProcessEventID(Event postedEvent)
        {
            bool result  = false;
            int  eventID = postedEvent._eventID;

            if (!_listenersHashed.ContainsKey(eventID))
            {
                DebugLog.Print("Event \"" + eventID + "\" triggered has no listeners!", DebugLevel.Warning);
                postedEvent.eventStatus = EventStatus.Failed_No_Listeners;
            }
            else
            {
                if (_eventSequencer != null)
                {
                    _eventSequencer.ProcessEvent(postedEvent);
                }
                List <IEventListener> list = _listenersHashed[eventID];
                int count = list.Count;
                for (int i = 0; i < count; i++)
                {
                    IEventListener eventListener = list[i];
                    if (IsNullOrDestroyed(eventListener))
                    {
                        continue;
                    }
                    if (eventListener.GetEventListeners(eventID, eventListeners))
                    {
                        Event @event = ApplyOverrideEventActions(eventListeners, postedEvent, overrideEvent);
                        if (@event != null)
                        {
                            postedEvent.eventStatus = eventListener.Process(@event);
                        }
                    }
                    else
                    {
                        postedEvent.eventStatus = eventListener.Process(postedEvent);
                    }
                }
                result = ((postedEvent.eventStatus == EventStatus.Handled) ? true : false);
            }
            LogEvent(postedEvent);
            return(result);
        }
예제 #10
0
 public void LoadAsset(string prefabName, string destinationComponent)
 {
     if (_globalComponentTable.ContainsKey(destinationComponent))
     {
         Component          component = _globalComponentTable[destinationComponent];
         UnityEngine.Object @object   = Resources.Load(prefabName);
         if (@object != null)
         {
             GameObject gameObject = UnityEngine.Object.Instantiate(@object) as GameObject;
             gameObject.name = gameObject.name.Replace("(Clone)", "");
             string key = destinationComponent + "_" + gameObject.name;
             if (_globalComponentTable.ContainsKey(key))
             {
                 UnityEngine.Object.Destroy(gameObject);
                 return;
             }
             gameObject.transform.parent = component.transform;
             Component component2 = gameObject.GetComponent <Component>();
             if (component2 != null)
             {
                 component2.Initialise(component, isComponentInstance: false);
                 component.AddComponent(component2);
                 AddChildComponentsToGlobalTable(component2, destinationComponent);
             }
             VolumeMeter component3 = component.GetComponent <VolumeMeter>();
             if (component3 != null)
             {
                 component3.CollectAudioComponents();
             }
             DebugLog.Print("Asset [" + prefabName + "] loaded succesfuly");
         }
         else
         {
             DebugLog.Print("Asset [" + prefabName + "] name not found", DebugLevel.Error);
         }
     }
     else
     {
         DebugLog.Print("Target Component [" + destinationComponent + "] not found", DebugLevel.Error);
     }
 }
예제 #11
0
        public bool UnregisterListener(IEventListener listener, string eventName)
        {
            if (!_listeners.ContainsKey(eventName))
            {
                return(false);
            }
            List <IEventListener> list = _listeners[eventName];

            if (!list.Contains(listener))
            {
                DebugLog.Print("failed to find listener", DebugLevel.Error);
                return(false);
            }
            list.Remove(listener);
            if (list.Count == 0)
            {
                _listeners.Remove(eventName);
                _listenersHashed.Remove(GetIDFromEventName(eventName));
            }
            return(true);
        }
예제 #12
0
 public void LoadAsset(GameObject component, string destinationComponent)
 {
     if (_globalComponentTable.ContainsKey(destinationComponent))
     {
         Component component2 = _globalComponentTable[destinationComponent];
         if (component != null)
         {
             component.name = component.name.Replace("(Clone)", "");
             string key = destinationComponent + "_" + component.name;
             if (_globalComponentTable.ContainsKey(key))
             {
                 UnityEngine.Object.DestroyImmediate(component);
                 return;
             }
             component.transform.parent = component2.transform;
             Component component3 = component.GetComponent <Component>();
             if (component3 != null)
             {
                 component3.Initialise(component2, isComponentInstance: false);
                 component2.AddComponent(component3);
                 AddChildComponentsToGlobalTable(component3, destinationComponent);
                 VolumeMeter component4 = component2.GetComponent <VolumeMeter>();
                 if (component4 != null)
                 {
                     component4.CollectAudioComponents();
                 }
             }
             DebugLog.Print("Asset [" + component.name + "] loaded succesfuly");
         }
         else
         {
             DebugLog.Print("Asset [" + component.name + "] name not found", DebugLevel.Error);
         }
     }
     else
     {
         DebugLog.Print("Target Component [" + destinationComponent + "] not found", DebugLevel.Error);
     }
 }
예제 #13
0
 public AudioClip IncRef(bool loadAudioClip = true)
 {
     if (_refCount == 0 && loadAudioClip)
     {
         if (_audioClip == null && IsAudioClipPathSet())
         {
             _audioClip = Resources.Load(_audioClipPath) as AudioClip;
         }
         else if (_audioClip != null)
         {
             if (!_loadAudioDataEventAction && _audioClip.loadState != AudioDataLoadState.Loaded)
             {
                 _audioClip.LoadAudioData();
             }
         }
         else
         {
             DebugLog.Print("AudioClipHandle Failed to load audio clip [" + _audioClipPath + "]", DebugLevel.Error);
         }
     }
     _refCount++;
     return(_audioClip);
 }
예제 #14
0
        public bool RegisterListener(IEventListener listener, string eventName)
        {
            if (IsNullOrDestroyed(listener) || eventName == null)
            {
                DebugLog.Print("EventManager register listener failed", DebugLevel.Error);
                return(false);
            }
            List <IEventListener> list = null;

            if (!_listeners.ContainsKey(eventName))
            {
                list = new List <IEventListener>();
                _listeners.Add(eventName, list);
                _listenersHashed.Add(GetIDFromEventName(eventName), list);
            }
            list = _listeners[eventName];
            if (list.Contains(listener))
            {
                DebugLog.Print("Listener " + listener.GetType().ToString() + " is already registered to listen for event " + eventName);
                return(false);
            }
            list.Add(listener);
            return(true);
        }
예제 #15
0
 public void CreateVoicePool(int count)
 {
     for (int i = 0; i < count; i++)
     {
         GameObject gameObject     = null;
         AudioVoice audioVoice     = null;
         bool       addAudioSource = true;
         if (FabricManager.Instance._VRAudioManager != null && FabricManager.Instance._VRAudioManager._vrSolutions.Count > 0)
         {
             gameObject = FabricManager.Instance._VRAudioManager.GetAudioSource();
             if ((bool)gameObject)
             {
                 addAudioSource = false;
             }
             else
             {
                 gameObject = new GameObject();
             }
         }
         else
         {
             gameObject = new GameObject();
         }
         gameObject.name = "AudioVoice_" + i;
         audioVoice      = gameObject.AddComponent <AudioVoice>();
         if (audioVoice == null || gameObject == null)
         {
             DebugLog.Print("Failed to allocate audio source in the pool!", DebugLevel.Error);
             break;
         }
         audioVoice.Init(addAudioSource);
         audioVoice.transform.parent = base.transform;
         Generic.SetGameObjectActive(audioVoice.gameObject, active: false);
         _audioVoicePool.Enqueue(audioVoice);
     }
 }
예제 #16
0
        public bool UnregisterGroupComponent(GroupComponent groupComponent, bool ignoreFadeOut = true)
        {
            if (!_allowExternalGroupComponents)
            {
                DebugLog.Print("External GroupComponent registration is disabled");
                return(false);
            }
            bool result = true;

            if (groupComponent != null)
            {
                if (!ignoreFadeOut)
                {
                    for (int i = 0; i < _groupComponentProxies.Count; i++)
                    {
                        GroupComponentProxy groupComponentProxy = _groupComponentProxies[i];
                        if (groupComponentProxy._groupComponent == groupComponent)
                        {
                            groupComponent.Stop();
                            GameObject gameObject = new GameObject();
                            groupComponentProxy._groupComponent = gameObject.AddComponent <GroupComponent>();
                            groupComponentProxy._groupComponent.transform.parent = groupComponentProxy.transform;
                            groupComponentProxy._groupComponent.name             = groupComponent.name;
                            groupComponentProxy._groupComponent.CopyPropertiesFrom(groupComponent);
                            if (groupComponent.ParentComponent != null)
                            {
                                groupComponent.ParentComponent.RemoveComponent(groupComponent);
                                groupComponent.ParentComponent.AddComponent(groupComponentProxy._groupComponent);
                            }
                            else
                            {
                                _components.Remove(groupComponent);
                                _components.Remove(groupComponentProxy._groupComponent);
                            }
                            Component[] childComponents = groupComponent.GetChildComponents();
                            for (int j = 0; j < childComponents.Length; j++)
                            {
                                groupComponentProxy._groupComponent.AddComponent(childComponents[j]);
                                childComponents[j].transform.parent = groupComponentProxy._groupComponent.transform;
                                childComponents[j].ParentComponent  = groupComponentProxy._groupComponent;
                            }
                            _groupComponentProxies.Remove(groupComponentProxy);
                            _groupComponentProxiesToDestroy.Add(groupComponentProxy);
                            groupComponentProxy._groupComponent.SetComponentActive(groupComponent.IsComponentActive());
                            DebugLog.Print("GroupComponent [" + groupComponent.name + "] scheduled to be unregistered");
                        }
                    }
                }
                else
                {
                    if (groupComponent.ParentComponent != null)
                    {
                        groupComponent.ParentComponent.RemoveComponent(groupComponent);
                    }
                    else
                    {
                        _components.Remove(groupComponent);
                    }
                    for (int k = 0; k < _groupComponentProxies.Count; k++)
                    {
                        GroupComponentProxy groupComponentProxy2 = _groupComponentProxies[k];
                        if (groupComponentProxy2 != null && groupComponentProxy2._groupComponent == groupComponent)
                        {
                            _groupComponentProxies.Remove(groupComponentProxy2);
                            UnityEngine.Object.DestroyImmediate(groupComponentProxy2.gameObject);
                            break;
                        }
                    }
                    DebugLog.Print("GroupComponent [" + groupComponent.name + "] unregistered succesfuly");
                }
                result = false;
            }
            else
            {
                DebugLog.Print("GroupComponent [" + groupComponent.name + "] failed to unregistred", DebugLevel.Error);
            }
            return(result);
        }
예제 #17
0
        public bool RegisterGroupComponent(GroupComponent groupComponent, string targetGroupComponentPath, bool createProxy = true)
        {
            if (!_allowExternalGroupComponents)
            {
                DebugLog.Print("External GroupComponent registration is disabled");
                return(false);
            }
            bool      result          = false;
            Component componentByName = GetComponentByName(targetGroupComponentPath);

            if (groupComponent != null)
            {
                groupComponent.Initialise(componentByName, isComponentInstance: false);
                if (componentByName != null)
                {
                    componentByName.AddComponent(groupComponent);
                }
                else
                {
                    _components.Add(groupComponent);
                }
                if (createProxy)
                {
                    GameObject gameObject = new GameObject();
                    gameObject.hideFlags = HideFlags.DontSave;
                    GroupComponentProxy groupComponentProxy = gameObject.AddComponent <GroupComponentProxy>();
                    groupComponentProxy._groupComponent = groupComponent;
                    groupComponentProxy.name            = groupComponent.name + "_Proxy";
                    if (componentByName != null)
                    {
                        groupComponentProxy.transform.parent = componentByName.transform;
                    }
                    else
                    {
                        groupComponentProxy.transform.parent = base.gameObject.transform;
                    }
                    _groupComponentProxies.Add(groupComponentProxy);
                }
                else if (componentByName != null)
                {
                    groupComponent.transform.parent = componentByName.transform;
                }
                else
                {
                    groupComponent.transform.parent = base.gameObject.transform;
                }
                if (componentByName != null)
                {
                    VolumeMeter component = componentByName.GetComponent <VolumeMeter>();
                    if (component != null)
                    {
                        component.CollectAudioComponents();
                    }
                }
                DebugLog.Print("GroupComponent [" + groupComponent.name + "] registred succesfuly");
                result = true;
            }
            else
            {
                DebugLog.Print("GroupComponent [" + groupComponent.name + "] failed to register", DebugLevel.Error);
            }
            return(result);
        }
예제 #18
0
 public void Awake()
 {
     if (_isInitialised)
     {
         return;
     }
     _instance = this;
     if (_VRAudioManager.HasVRSolutions())
     {
         FabricAudioListener fabricAudioListener = (FabricAudioListener)UnityEngine.Object.FindObjectOfType(typeof(FabricAudioListener));
         if (fabricAudioListener != null)
         {
             GameObject audioListener = _VRAudioManager.GetAudioListener();
             if (audioListener != null)
             {
                 audioListener.transform.parent = fabricAudioListener.gameObject.transform;
             }
         }
         if (_audioSourcePool == 0)
         {
             _audioSourcePool = 100;
         }
     }
     if (_audioSourcePool > 0)
     {
         if (_audioSourcePoolManager == null)
         {
             _audioSourcePoolManager = base.gameObject.GetComponentInChildren <AudioSourcePool>();
             if (_audioSourcePoolManager == null)
             {
                 _audioSourcePoolManager = AudioSourcePool.Create();
             }
             _audioSourcePoolManager.Initialise(_audioSourcePool, _audioSourcePoolFadeInTime, _audioSourcePoolFadeOutTime);
         }
         if (_audioSourcePoolManager != null)
         {
             _audioSourcePoolManager.Refresh();
         }
     }
     InitialiseComponents();
     RefreshComponents();
     if (_dontDestroyOnLoad)
     {
         if (Application.isPlaying)
         {
             UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
         }
         DebugLog.Print("FabricManager initialised (DontDestroyOnLoad flag enabled)");
     }
     else
     {
         DebugLog.Print("FabricManager initialised (DontDestroyOnLoad flag disabled)");
     }
     if (Application.isEditor)
     {
         CodeProfiler.enabled = true;
         FabricManager[] array = UnityEngine.Object.FindObjectsOfType(typeof(FabricManager)) as FabricManager[];
         if (array.Length > 1)
         {
             DebugLog.Print("More than two FabricManager instances available!!!", DebugLevel.Error);
         }
     }
     for (int i = 0; i < _musicTimeSignatures.Count; i++)
     {
         _musicTimeSignatures[i].Init();
     }
     _isInitialised = true;
 }