예제 #1
0
        public void DoSpawnOne()
        {
            var clone = EditorSafe.CreateFromPrefab(prefab);

            clone.transform.position = transform.position + GetRandomSpawnOffset();
            container.DoParent(_transform, clone.transform);
        }
예제 #2
0
        public void CreateInstances()
        {
            GameObject
            .FindGameObjectsWithTag(targetTag)
            .ToList()
            .ForEach(target => {
                var clone = EditorSafe.CreateFromPrefab(prefab);

                Transform cloneTransform  = clone.transform;
                Transform targetTransform = target.transform;

                // Parent
                if (instanceParent == ParentingMode.AppendToContainer)
                {
                    cloneTransform.parent = container;
                }
                else if (instanceParent == ParentingMode.AppendToTarget)
                {
                    cloneTransform.parent = targetTransform;
                }
                else if (instanceParent == ParentingMode.AppendToSceneRoot)
                {
                }

                // Copy rotations & Position
                if (instanceParent == ParentingMode.AppendToContainer ||
                    instanceParent == ParentingMode.AppendToSceneRoot)
                {
                    if (copyPosition)
                    {
                        cloneTransform.position = targetTransform.position;
                    }
                    if (copyRotation)
                    {
                        cloneTransform.localRotation = targetTransform.rotation;
                    }
                }


#if UNITY_EDITOR
                if (!EditorApplication.isPlaying)
                {
                    Undo.RegisterCreatedObjectUndo(clone, "Create instance");
                }
#endif
            });
        }