void CalculatePrefabStatus()
        {
            m_PlayModeObjects               = false;
            m_IsAsset                       = false;
            m_ImmutableSelf                 = false;
            m_ImmutableSourceAsset          = false;
            m_IsDisconnected                = false;
            m_IsMissing                     = false;
            m_IsPrefabInstanceAnyRoot       = true;
            m_IsPrefabInstanceOutermostRoot = true;
            m_AllOfSamePrefabType           = true;
            PrefabAssetType      firstType   = PrefabUtility.GetPrefabAssetType(targets[0]);
            PrefabInstanceStatus firstStatus = PrefabUtility.GetPrefabInstanceStatus(targets[0]);

            foreach (var o in targets)
            {
                var                  go     = (GameObject)o;
                PrefabAssetType      type   = PrefabUtility.GetPrefabAssetType(go);
                PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(go);
                if (type != firstType || status != firstStatus)
                {
                    m_AllOfSamePrefabType = false;
                }

                if (Application.IsPlaying(go))
                {
                    m_PlayModeObjects = true;
                }
                if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
                {
                    m_IsPrefabInstanceAnyRoot = false; // Conservative is false if any is false
                }
                if (!m_IsPrefabInstanceAnyRoot || !PrefabUtility.IsOutermostPrefabInstanceRoot(go))
                {
                    m_IsPrefabInstanceOutermostRoot = false; // Conservative is false if any is false
                }
                if (PrefabUtility.IsPartOfPrefabAsset(go))
                {
                    m_IsAsset = true; // Conservative is true if any is true
                }
                if (m_IsAsset && PrefabUtility.IsPartOfImmutablePrefab(go))
                {
                    m_ImmutableSelf = true; // Conservative is true if any is true
                }
                GameObject originalSourceOrVariant = PrefabUtility.GetOriginalSourceOrVariantRoot(go);
                if (originalSourceOrVariant != null && PrefabUtility.IsPartOfImmutablePrefab(originalSourceOrVariant))
                {
                    m_ImmutableSourceAsset = true; // Conservative is true if any is true
                }
                if (PrefabUtility.IsDisconnectedFromPrefabAsset(go))
                {
                    m_IsDisconnected = true;
                }
                if (PrefabUtility.IsPrefabAssetMissing(go))
                {
                    m_IsMissing = true;
                }
            }
        }
示例#2
0
        private bool CheckIfChild(Object subEmitter)
        {
            ParticleSystem root = ParticleSystemEditorUtils.GetRoot(m_ParticleSystemUI.m_ParticleSystems[0]);
            ParticleSystem ps   = subEmitter as ParticleSystem;

            if (IsChild(ps, root))
            {
                return(true);
            }

            if (PrefabUtility.IsPartOfAnyPrefab(ps.gameObject) && !PrefabUtility.IsAnyPrefabInstanceRoot(ps.gameObject))
            {
                string kPrefabReparentWarn = $"The assigned sub emitter is not part of the current effect because it is not a child of the current root Particle System GameObject: '{root.gameObject.name}'. The Particle System cannot be moved because it is a child of a Prefab instance.";
                EditorUtility.WarnPrefab(ps.gameObject, "Reparent GameObjects", kPrefabReparentWarn, "OK");
                return(false);
            }

            string kReparentText = string.Format("The assigned sub emitter is not a child of the current root particle system GameObject: '{0}' and is therefore NOT considered a part of the current effect. Do you want to reparent it?", root.gameObject.name);

            if (EditorUtility.DisplayDialog(
                    "Reparent GameObjects",
                    kReparentText,
                    "Yes, Reparent",
                    "No, Remove"))
            {
                if (EditorUtility.IsPersistent(subEmitter))
                {
                    var newGo = Object.Instantiate(subEmitter) as GameObject;
                    if (newGo != null)
                    {
                        newGo.transform.parent        = m_ParticleSystemUI.m_ParticleSystems[0].transform;
                        newGo.transform.localPosition = Vector3.zero;
                        newGo.transform.localRotation = Quaternion.identity;
                    }
                }
                else
                {
                    if (ps != null)
                    {
                        Undo.SetTransformParent(ps.gameObject.transform.transform, m_ParticleSystemUI.m_ParticleSystems[0].transform, "Reparent sub emitter");
                    }
                }

                return(true);
            }
            else if (ps != null)
            {
                // Clear sub-emitters that have been deselected, to avoid having their particles left paused in the Scene View (case 946999)
                ps.Clear(true);
            }

            return(false);
        }
        void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item)
        {
            item.showPrefabModeButton = false;

            GameObject go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(go))
            {
                return;
            }

            if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
            {
                return;
            }

            // Don't show button if prefab asset is missing
            if (PrefabUtility.GetPrefabInstanceStatus(go) == PrefabInstanceStatus.Connected)
            {
                var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go);
                if (source == null)
                {
                    return;
                }

                // Don't show buttons for model prefabs but allow buttons for other immutables
                if (PrefabUtility.IsPartOfModelPrefab(source))
                {
                    return;
                }
            }
            else if (PrefabUtility.GetPrefabInstanceHandle(go) == null)
            {
                return;
            }
            else
            {
                var assetPath = PrefabUtility.GetAssetPathOfSourcePrefab(go);
                var broken    = AssetDatabase.LoadMainAssetAtPath(assetPath) as BrokenPrefabAsset;
                if (broken == null || !broken.isPrefabFileValid)
                {
                    return;
                }
            }

            item.showPrefabModeButton = true;
        }
示例#4
0
        void AddParentsBelowButIgnoreNestedPrefabsRecursive(Transform transform, List <int> gameObjectInstanceIDs)
        {
            gameObjectInstanceIDs.Add(transform.gameObject.GetInstanceID());

            int count = transform.childCount;

            for (int i = 0; i < count; ++i)
            {
                var child = transform.GetChild(i);
                if (child.childCount > 0 && !PrefabUtility.IsAnyPrefabInstanceRoot(child.gameObject))
                {
                    AddParentsBelowButIgnoreNestedPrefabsRecursive(child, gameObjectInstanceIDs);
                }
            }
        }
        void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item)
        {
            item.showPrefabModeButton = false;

            GameObject go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(go))
            {
                return;
            }

            if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
            {
                return;
            }

            // Don't show button for disconnected prefab instances and if prefab asset is missing
            if (PrefabUtility.GetPrefabInstanceStatus(go) != PrefabInstanceStatus.Connected)
            {
                return;
            }

            var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go);

            if (source == null)
            {
                return;
            }

            // Don't show buttons for model prefabs but allow buttons for other immutables
            if (PrefabUtility.IsPartOfModelPrefab(source))
            {
                return;
            }

            item.showPrefabModeButton = true;
        }
示例#6
0
        void CalculatePrefabStatus()
        {
            m_IsPrefabInstanceAnyRoot = false;
            m_IsAsset             = false;
            m_AllOfSamePrefabType = true;
            PrefabAssetType      firstType   = PrefabUtility.GetPrefabAssetType(targets[0]);
            PrefabInstanceStatus firstStatus = PrefabUtility.GetPrefabInstanceStatus(targets[0]);

            foreach (GameObject go in targets)
            {
                PrefabAssetType      type   = PrefabUtility.GetPrefabAssetType(go);
                PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(go);
                if (type != firstType || status != firstStatus)
                {
                    m_AllOfSamePrefabType = false;
                }

                if (PrefabUtility.IsAnyPrefabInstanceRoot(go))
                {
                    m_IsPrefabInstanceAnyRoot = true;
                }
                if (m_IsPrefabInstanceAnyRoot)
                {
                    m_IsPrefabInstanceOutermostRoot = PrefabUtility.IsOutermostPrefabInstanceRoot(go);
                }
                if (PrefabUtility.IsPartOfPrefabAsset(go))
                {
                    m_IsAsset = true;
                }
                if (m_IsAsset && PrefabUtility.IsPartOfImmutablePrefab(go))
                {
                    m_ImmutableSelf = true;
                }
                GameObject originalSourceOrVariant = PrefabUtility.GetOriginalSourceOrVariantRoot(go);
                if (originalSourceOrVariant != null && PrefabUtility.IsPartOfImmutablePrefab(originalSourceOrVariant))
                {
                    m_ImmutableSourceAsset = true;
                }
            }
        }
        void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item)
        {
            item.showPrefabModeButton = false;

            GameObject go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(go))
            {
                return;
            }

            if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
            {
                return;
            }

            // Don't show button for disconnected prefab instances and if prefab asset is missing
            if (PrefabUtility.GetPrefabInstanceStatus(go) != PrefabInstanceStatus.Connected)
            {
                return;
            }

            // We can't simply check if the go is part of an immutable prefab, since that would check the asset of the
            // outermost prefab this go is part of. Instead we have to check original source or variant root
            // - the same one that would get opened if clicking the arrow.
            var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go);

            if (source == null || PrefabUtility.IsPartOfImmutablePrefab(source))
            {
                return;
            }

            item.showPrefabModeButton = true;
        }