Exemple #1
0
        public static void MakeAllChildrenDeformables()
        {
            var newSelection = new HashSet <GameObject> ();

            var selections = Selection.gameObjects;

            Undo.SetCurrentGroupName("Made All Children Deformable");
            foreach (var selection in selections)
            {
                var allChildren = selection.transform.GetComponentsInChildren <Transform>();
                foreach (Transform child in allChildren)
                {
                    if (child.GetComponent <Deformable> ())
                    {
                        continue;
                    }
                    if (MeshTarget.IsValid(child.gameObject))
                    {
                        newSelection.Add(Undo.AddComponent <Deformable> (child.gameObject).gameObject);
                    }
                }
            }

            Selection.objects = newSelection.ToArray();
        }
Exemple #2
0
        public void AddOrCreateDeformable()
        {
            var targets = Selection.gameObjects;

            // If we don't have any objects selected, create a new Deformable.
            if (targets == null || targets.Length == 0)
            {
                CreateDeformable();
            }
            else
            {
                // Keep track of whether or not we've actually been able to add a Deformable component.
                var addedComponent = false;
                foreach (var target in Selection.gameObjects)
                {
                    // Check if there's already a Deformable/
                    var deformable = target.GetComponent <Deformable> ();
                    // If there isn't, we can add one
                    if (!PrefabUtility.IsPartOfPrefabAsset(target) && deformable == null && MeshTarget.IsValid(target))
                    {
                        Undo.AddComponent <Deformable> (target);
                        addedComponent = true;
                    }
                }

                // If we never ended up adding a Deformable component, we should create new one.
                if (!addedComponent)
                {
                    CreateDeformable();
                }
            }
        }
Exemple #3
0
 private void Awake()
 {
     target = new MeshTarget();
     mesh   = new Mesh();
 }
Exemple #4
0
        public static void AddOrCreateDeformable <T> () where T : Deformable
        {
            var targets = Selection.gameObjects;

            justAddedDeformablesPool.Clear();

            // If we don't have any objects selected, create a new Deformable.
            if (targets == null || targets.Length == 0)
            {
                CreateDeformable <T> ();
            }
            else
            {
                foreach (var target in Selection.gameObjects)
                {
                    // We can't add components to a gameobject that's part of a prefab asset
                    if (!PrefabUtility.IsPartOfPrefabAsset(target))
                    {
                        T deformable = null;

                        // Check if there's an LOD Group
                        var lodGroup = target.GetComponent <LODGroup>();

                        // If an LOD Group is selected, lets add Deformables to its children
                        if (lodGroup != null)
                        {
                            if (EditorUtility.DisplayDialog
                                (
                                    title: "Deformable LOD Group",
                                    message: $"You just tried to add a {typeof(T).Name} to an {nameof(LODGroup)}. Would you like to make its childen Deformable?",
                                    ok: "Yes",
                                    cancel:"No"
                                ))
                            {
                                foreach (Transform child in lodGroup.transform)
                                {
                                    // Check if there's already a Deformable
                                    deformable = child.GetComponent <T>();
                                    // If there isn't, we can add one
                                    if (deformable == null && MeshTarget.IsValid(child))
                                    {
                                        justAddedDeformablesPool.Add(Undo.AddComponent <T>(child.gameObject));
                                    }
                                }

                                if (EditorUtility.DisplayDialog
                                    (
                                        title: "Deformable LOD Group",
                                        message: $"A {nameof(GroupDeformer)} can help you keep deformers in sync across multiple LODs. Would you like one added automatically?",
                                        ok: "Yes",
                                        cancel:"No"
                                    ))
                                {
                                    GroupDeformer group = Undo.AddComponent <GroupDeformer>(target.gameObject);

                                    foreach (var d in justAddedDeformablesPool)
                                    {
                                        Undo.RecordObject(d, "Added deformer");
                                        d.AddDeformer(group);
                                    }
                                }
                            }

                            return;
                        }

                        // Since there wasn't an LOD group, check if there's already a Deformable
                        deformable = target.GetComponent <T>();
                        // If there isn't, we can add one
                        if (deformable == null && MeshTarget.IsValid(target))
                        {
                            justAddedDeformablesPool.Add(Undo.AddComponent <T>(target));
                        }
                    }
                }

                // If we never ended up adding a Deformable component, we should create new one.
                if (justAddedDeformablesPool.Count == 0)
                {
                    CreateDeformable <T> ();
                }
            }
        }