Exemplo n.º 1
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.magnetStrength / 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;
                }

                Vector3 direction = distance.normalized;

                transform.position += direction * magnetFactor * (attract ? 1 : -1);
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        private void ApplyPhysics()
        {
            PhysicsSimulation physicsSimulation = ScriptableObject.CreateInstance <PhysicsSimulation>();

            PhysicsSettings physicsSettings = new PhysicsSettings();

            physicsSettings.simulationStepCountMax   = gizmo.brushSettings.autoSimulationStepCountMax;
            physicsSettings.simulationStepIterations = gizmo.brushSettings.autoSimulationStepIterations;

            physicsSimulation.ApplySettings(physicsSettings);

            // TODO: use only the new added ones?
            Transform[] containerChildren = PrefabUtils.GetContainerChildren(gizmo.container);

            if (gizmo.brushSettings.autoSimulationType == BrushSettings.AutoSimulationType.Once)
            {
                physicsSimulation.RunSimulationOnce(containerChildren);
            }
            else if (gizmo.brushSettings.autoSimulationType == BrushSettings.AutoSimulationType.Continuous)
            {
                physicsSimulation.StartSimulation(containerChildren);
            }
        }
Exemplo n.º 4
0
 // TODO: create common class
 private Transform[] getContainerChildren()
 {
     return(PrefabUtils.GetContainerChildren(gizmo.container));
 }
Exemplo n.º 5
0
 private void StartSimulation()
 {
     Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container);
     AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, containerChildren, SpawnSettings.AutoSimulationType.Continuous);
 }
Exemplo n.º 6
0
        public static void ApplyPhysics(PhysicsSettings physicsSettings, GameObject container, SpawnSettings.AutoSimulationType autoSimulationType)
        {
            Transform[] containerChildren = PrefabUtils.GetContainerChildren(container);

            ApplyPhysics(physicsSettings, containerChildren, autoSimulationType);
        }