Ejemplo n.º 1
0
        // TODO: check performance; currently invoked multiple times in the editor loop
        private void SetScalePrefabs(RaycastHit hit)
        {
            float   scaleValue  = editorTarget.interactionSettings.setScale.setScaleValue;
            Vector3 scaleVector = new Vector3(scaleValue, scaleValue, scaleValue);

            Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container, hit, editorTarget.brushSettings.brushSize);

            foreach (Transform transform in containerChildren)
            {
                Undo.RegisterCompleteObjectUndo(transform, "Set scale");

                transform.localScale = scaleVector;
            }
        }
        // TODO: check performance; currently invoked multiple times in the editor loop
        private void ChangeScalePrefabs(RaycastHit hit, bool grow)
        {
            // just some arbitrary value depending on the magnet strength which ranges from 0..100
            float adjustFactor = editorTarget.interactionSettings.changeScale.changeScaleStrength / 1000f;

            Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container, hit, editorTarget.brushSettings.brushSize);

            foreach (Transform transform in containerChildren)
            {
                Undo.RegisterCompleteObjectUndo(transform, "Change scale");

                transform.localScale += transform.localScale * adjustFactor * (grow ? 1 : -1);
            }
        }
        /// <summary>
        /// Increment y-position in world space
        /// </summary>
        /// <param name="hit"></param>
        private void AntiGravity(RaycastHit hit)
        {
            // just some arbitrary value depending on the magnet strength which ranges from 0..100
            float antiGravityFactor = editorTarget.interactionSettings.antiGravity.strength / 1000f;

            Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container, hit, editorTarget.brushSettings.brushSize);

            foreach (Transform transform in containerChildren)
            {
                // https://docs.unity3d.com/ScriptReference/Transform-up.html
                // https://docs.unity3d.com/ScriptReference/Vector3-up.html
                transform.position += Vector3.up * antiGravityFactor;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attract/Repell the gameobjects of the container which are within the brush
        /// </summary>
        /// <param name="hit"></param>
        /// <param name="attract"></param>
        private void Magnet(RaycastHit hit, bool attract)
        {
            // just some arbitrary value depending on the magnet strength which ranges from 0..100
            float magnetFactor = editorTarget.interactionSettings.magnet.strength / 1000f;

            Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container, hit, editorTarget.brushSettings.brushSize);

            foreach (Transform transform in containerChildren)
            {
                Vector3 distance  = hit.point - transform.position;
                Vector3 direction = distance.normalized;

                transform.position += direction * magnetFactor * (attract ? 1 : -1);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Remove prefabs
        /// </summary>
        private void RemovePrefabs(RaycastHit raycastHit)
        {
            if (!editor.IsEditorSettingsValid())
            {
                return;
            }

            switch (editorTarget.brushSettings.spawnTarget)
            {
            case BrushSettings.SpawnTarget.PrefabContainer:

                // get children within brush
                Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container, raycastHit, editorTarget.brushSettings.brushSize);

                // remove gameobjects
                foreach (Transform transform in containerChildren)
                {
                    Undo.DestroyObjectImmediate(transform.gameObject);
                }

                break;

            case BrushSettings.SpawnTarget.TerrainTrees:

                unityTerrainTreesIntegration.RemovePrefabs(raycastHit);

                break;

            case BrushSettings.SpawnTarget.TerrainDetails:

                Debug.LogError("Not implemented");

                break;

            case BrushSettings.SpawnTarget.VegetationStudioPro:

                Debug.LogError("Not implemented");

                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Increment y-position in world space
        /// </summary>
        /// <param name="hit"></param>
        private void AntiGravity(RaycastHit hit)
        {
            // just some arbitrary value depending on the magnet strength which ranges from 0..100
            float antiGravityFactor = editorTarget.interactionSettings.antiGravityStrength / 1000f;

            Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container);

            foreach (Transform transform in containerChildren)
            {
                Vector3 distance = hit.point - transform.position;

                // only those within the brush
                if (distance.magnitude > editorTarget.brushSettings.brushSize / 2f)
                {
                    continue;
                }

                // https://docs.unity3d.com/ScriptReference/Transform-up.html
                // https://docs.unity3d.com/ScriptReference/Vector3-up.html
                transform.position += Vector3.up * antiGravityFactor;
            }
        }
        public static void ApplyPhysics(PhysicsSettings physicsSettings, GameObject container, SpawnSettings.AutoSimulationType autoSimulationType)
        {
            Transform[] containerChildren = PrefabUtils.GetContainerChildren(container);

            ApplyPhysics(physicsSettings, containerChildren, autoSimulationType);
        }
Ejemplo n.º 8
0
 private void StartSimulation()
 {
     Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container);
     AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, containerChildren, SpawnSettings.AutoSimulationType.Continuous);
 }