Пример #1
0
 private void UpdateGroupComponentProxies(ref Context updateContext)
 {
     for (int i = 0; i < _groupComponentProxiesToDestroy.Count; i++)
     {
         GroupComponentProxy groupComponentProxy = _groupComponentProxiesToDestroy[i];
         if (!groupComponentProxy._groupComponent.IsComponentActive())
         {
             if (groupComponentProxy._groupComponent.ParentComponent != null)
             {
                 groupComponentProxy._groupComponent.ParentComponent.RemoveComponent(groupComponentProxy._groupComponent);
             }
             else
             {
                 _components.Remove(groupComponentProxy._groupComponent);
             }
             _groupComponentProxiesToDestroy.Remove(groupComponentProxy);
             UnityEngine.Object.DestroyObject(groupComponentProxy.gameObject);
         }
     }
 }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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();
                }
            }
        }