public static List <GameObject> ReplaceSelectedObjectsPrefabOnMouseClick()
        {
            MouseCursorRayHit cursorRayHit = ObjectSelection.Get().GetObjectPickedByCursor();

            if (cursorRayHit.WasAnObjectHit && !ObjectSelection.Get().IsGameObjectSelected(cursorRayHit.ClosestObjectRayHit.HitObject))
            {
                GameObject hitObject = cursorRayHit.ClosestObjectRayHit.HitObject;
                hitObject = Octave3DWorldBuilder.ActiveInstance.GetRoot(hitObject);
                if (hitObject == null)
                {
                    return(new List <GameObject>());
                }

                GameObject newPrefabForSelectedObjects = hitObject.GetSourcePrefab();
                if (newPrefabForSelectedObjects == null)
                {
                    return(new List <GameObject>());
                }

                List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
                ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects);
                List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, newPrefabForSelectedObjects);
                newObjects.RemoveAll(item => item == null);

                return(newObjects);
            }

            return(new List <GameObject>());
        }
Exemplo n.º 2
0
        public static List <GameObject> ReplaceSelectedObjectsWithPrefab(GameObject prefab)
        {
            List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();

            ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects);
            List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, prefab);

            newObjects.RemoveAll(item => item == null);

            return(newObjects);
        }
Exemplo n.º 3
0
        public static List <GameObject> ReplaceSelectedObjectsPrefabOnMouseClick()
        {
            MouseCursorRayHit cursorRayHit = ObjectSelection.Get().GetObjectPickedByCursor();

            if (cursorRayHit.WasAnObjectHit && !ObjectSelection.Get().IsGameObjectSelected(cursorRayHit.ClosestObjectRayHit.HitObject))
            {
                GameObject hitObject = cursorRayHit.ClosestObjectRayHit.HitObject;
                hitObject = Octave3DWorldBuilder.ActiveInstance.GetRoot(hitObject);
                if (hitObject == null)
                {
                    return(new List <GameObject>());
                }

                GameObject newPrefabForSelectedObjects = hitObject.GetSourcePrefab();
                if (newPrefabForSelectedObjects == null)
                {
                    List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
                    ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects);

                    List <GameObject> selectedRoots = Octave3DWorldBuilder.ActiveInstance.GetRoots(allSelectedObjects);
                    var newObjects = new List <GameObject>();
                    foreach (var root in selectedRoots)
                    {
                        Transform  rootTransform = root.transform;
                        GameObject newObject     = GameObjectExtensions.CloneAsWorkingObject(hitObject, hitObject.transform.parent, true);
                        if (newObject != null)
                        {
                            Transform objectTransform = newObject.transform;
                            objectTransform.position = rootTransform.position;
                            objectTransform.rotation = rootTransform.rotation;
                            objectTransform.SetWorldScale(rootTransform.lossyScale);
                            newObject.SetSelectedHierarchyWireframeHidden(ObjectPlacementSettings.Get().HideWireframeWhenPlacingObjects);

                            UndoEx.DestroyObjectImmediate(root);
                            newObjects.Add(newObject);
                        }
                    }

                    return(newObjects);
                }
                else
                {
                    List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();
                    ObjectSelection.Get().RemoveGameObjectCollectionFromSelection(allSelectedObjects);
                    List <GameObject> newObjects = ObjectActions.ReplaceGameObjectHierarchyCollectionPrefab(allSelectedObjects, newPrefabForSelectedObjects);
                    newObjects.RemoveAll(item => item == null);

                    return(newObjects);
                }
            }

            return(new List <GameObject>());
        }