예제 #1
0
 public void Init(GroupComponent groupComponent)
 {
     _activeParameter.Reset(0f);
     _volumeParameter.Reset(0f);
     _pitchParameter.Reset(0f);
     _groupComponent = groupComponent;
 }
        private void RegisterPrefab(GameObject prefab)
        {
            if (prefab == null)
            {
                return;
            }
            GroupComponent component = prefab.GetComponent <GroupComponent>();

            if (component == null)
            {
                return;
            }
            GameObject gameObject = GameObject.Find(prefab.name);

            if (gameObject == null)
            {
                GroupComponent._createProxy = false;
                gameObject = UnityEngine.Object.Instantiate(prefab);
                GroupComponent._createProxy = true;
                gameObject.name             = gameObject.name.Replace("(Clone)", "");
            }
            if (gameObject != null)
            {
                GroupComponent component2 = gameObject.GetComponent <GroupComponent>();
                if (component2 != null)
                {
                    component2.IncRef();
                }
                _prefabInstances.Add(gameObject);
            }
        }
예제 #3
0
 private void Update()
 {
     if (!_isInitialised)
     {
         _groupComponents = FabricManager.Instance.gameObject.GetComponentsInChildren <GroupComponent>();
         _isInitialised   = true;
     }
     if (_presetList != null)
     {
         for (int i = 0; i < _presetList.Length; i++)
         {
             Preset preset = _presetList[i];
             if (preset.HasEventNameSet() && preset.IsEventActive())
             {
                 AddPreset(preset);
             }
         }
     }
     if (_groupComponents == null)
     {
         return;
     }
     for (int j = 0; j < _groupComponents.Length; j++)
     {
         GroupComponent groupComponent = _groupComponents[j];
         float          num            = 0f;
         float          num2           = 1f;
         for (int k = 0; k < _activePresets.Count; k++)
         {
             Preset preset2 = _activePresets[k];
             if (preset2.HasEventNameSet() && !preset2.IsEventActive() && !preset2.IsDeactivating)
             {
                 preset2.Deactivate();
             }
             if (preset2.IsActive())
             {
                 GroupPreset groupComponentByID = preset2.GetGroupComponentByID(groupComponent.GetInstanceID());
                 if (groupComponentByID != null)
                 {
                     num  += groupComponentByID.CalculateVolume();
                     num2 *= groupComponentByID.CalculatePitch();
                 }
             }
             else
             {
                 _activePresets.Remove(preset2);
             }
         }
         float value = AudioTools.DBToLinear(num);
         AudioTools.Limit(ref value, 0f, 1f);
         groupComponent.MixerVolume = value;
         groupComponent.MixerPitch  = num2;
     }
 }
예제 #4
0
 public bool HasGroupComponent(GroupComponent groupComponent)
 {
     GroupPreset[] componentsInChildren = base.gameObject.GetComponentsInChildren <GroupPreset>();
     foreach (GroupPreset groupPreset in componentsInChildren)
     {
         if (groupPreset.GroupComponent != null && groupPreset.GroupComponent == groupComponent)
         {
             return(true);
         }
     }
     return(false);
 }
        private void UnregisterPrefab(GameObject prefab)
        {
            GroupComponent component = prefab.GetComponent <GroupComponent>();

            if (component != null)
            {
                component.DecRef();
                if (component._registeredWithMainRefCount == 0)
                {
                    UnityEngine.Object.Destroy(component.gameObject);
                }
            }
        }
예제 #6
0
        public void MixerSlot(string title, GroupComponent component)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginVertical();
            DisplayCenterText("Pitch");
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            component.Pitch = GUILayout.HorizontalSlider(component.Pitch, -4f, 4f, GUILayout.MinWidth(50f));
            GUILayout.Label(component.Pitch.ToString("F"));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.BeginHorizontal(GUILayout.MaxHeight(GetActualSize(40f)));
            GUILayout.FlexibleSpace();
            component.Mute = GUILayout.Toggle(component.Mute, "Mute", "button");
            bool solo = component.Solo;

            component.Solo = GUILayout.Toggle(component.Solo, "Solo", "button");
            if (component.Solo)
            {
                for (int i = 0; i < _soloComponents.Count; i++)
                {
                    if (_soloComponents[i] != null && _soloComponents[i] != component)
                    {
                        _soloComponents[i].Mute = true;
                    }
                }
            }
            else if (solo != component.Solo)
            {
                for (int j = 0; j < _soloComponents.Count; j++)
                {
                    if (_soloComponents[j] != null && _soloComponents[j] != component)
                    {
                        _soloComponents[j].Mute = false;
                    }
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.BeginVertical();
            DisplayCenterText("Volume");
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            component.Volume = GUILayout.VerticalSlider(component.Volume, 1f, 0f, GUILayout.MinHeight(100f));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            DisplayCenterText(AudioTools.LinearToDB(component.Volume).ToString("F") + "dB");
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
예제 #7
0
 public void RemoveGroupComponent(GroupComponent groupComponent)
 {
     _groupPreset = GetComponents <GroupPreset>();
     if (_groupPreset == null)
     {
         return;
     }
     for (int i = 0; i < _groupPreset.Length; i++)
     {
         if (_groupPreset[i].GroupComponent != null && _groupPreset[i].GroupComponent.Name == groupComponent.Name)
         {
             UnityEngine.Object.DestroyImmediate(_groupPreset[i]);
             break;
         }
     }
 }
예제 #8
0
 private void DrawComponent(Component component, ref float x, float y)
 {
     if (component.ToString().Contains("GroupComponent"))
     {
         GroupComponent groupComponent = (GroupComponent)component;
         if (!_soloComponents.Contains(groupComponent))
         {
             _soloComponents.Add(groupComponent);
         }
         component.ToString().LastIndexOf(".");
         string text = component.name;
         int    num  = text.Length * 10;
         float  num2 = slotHeight;
         if (num < 120)
         {
             num = 120;
         }
         VolumeMeter component2 = groupComponent.GetComponent <VolumeMeter>();
         if ((bool)component2)
         {
             num2 += 120f;
         }
         SideChain component3 = groupComponent.GetComponent <SideChain>();
         if ((bool)component3)
         {
             num2 += 120f;
         }
         GUILayout.BeginArea(new Rect(x, y, num, GetActualSize(num2)), text, GUI.skin.window);
         MixerSlot(text, groupComponent);
         if ((bool)component2)
         {
             DrawVolumeMeters(component2, GetActualSize(num - 10));
         }
         if ((bool)component3)
         {
             DrawSideChain(component3, GetActualSize(num - 30));
         }
         GUILayout.EndArea();
         x += num + 20;
     }
 }
예제 #9
0
        public void AddGroupComponent(GroupComponent groupComponent)
        {
            GroupPreset groupPreset = base.gameObject.AddComponent <GroupPreset>();

            groupPreset.Init(groupComponent);
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
0
        public static void UpdateHierarchy(Component component = null)
        {
            GameObject       gameObject = null;
            List <Component> list       = null;

            if (component == null && Instance != null)
            {
                gameObject = Instance.gameObject;
                list       = Instance._components;
            }
            else if (component != null)
            {
                gameObject = component.gameObject;
                list       = component.Components;
            }
            if (gameObject == null || list == null)
            {
                return;
            }
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Component component2 = gameObject.transform.GetChild(i).GetComponent <Component>();
                if (!(component2 != null) || component2.IsInstance)
                {
                    continue;
                }
                GroupComponent groupComponent = component2 as GroupComponent;
                if (groupComponent != null && groupComponent._isRegisteredWithMainHierarchy)
                {
                    groupComponent.UnregisterWithMainHierarchy();
                }
                bool flag = false;
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j] == component2)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    list.Add(component2);
                    if (component != null)
                    {
                        component.UpdateComponentsArray();
                    }
                    if (component2.ParentComponent != null)
                    {
                        component2.ParentComponent.Initialise(component, isComponentInstance: false);
                    }
                    else
                    {
                        component2.Initialise(component, isComponentInstance: false);
                    }
                    Instance.RefreshComponents();
                }
                else
                {
                    UpdateHierarchy(component2);
                }
            }
            for (int k = 0; k < list.Count; k++)
            {
                bool flag2 = false;
                for (int l = 0; l < gameObject.transform.childCount; l++)
                {
                    Component           component3 = gameObject.transform.GetChild(l).GetComponent <Component>();
                    GroupComponentProxy component4 = gameObject.transform.GetChild(l).GetComponent <GroupComponentProxy>();
                    if (component3 == list[k] || (component4 != null && component4._groupComponent == list[k]))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    Component      component5      = list[k];
                    GroupComponent groupComponent2 = component5 as GroupComponent;
                    list.Remove(component5);
                    if (component != null)
                    {
                        component.UpdateComponentsArray();
                    }
                    if (component5.ParentComponent != null)
                    {
                        component5.ParentComponent.Initialise(component, isComponentInstance: false);
                    }
                    if (groupComponent2 != null)
                    {
                        groupComponent2.RegisterWithMainHierarchy();
                    }
                    Instance.RefreshComponents();
                }
            }
        }