/// <summary>
        /// Creates GUI elements for fields common to all colliders.
        /// </summary>
        protected virtual void BuildGUI(Collider collider)
        {
            isTriggerField.OnChanged += x => { collider.IsTrigger = x; MarkAsModified(); ConfirmModify(); };

            massField.OnChanged += x => { collider.Mass = x; MarkAsModified(); };
            massField.OnConfirmed += ConfirmModify;
            massField.OnFocusLost += ConfirmModify;

            materialField.OnChanged += x =>
            {
                PhysicsMaterial mesh = Resources.Load<PhysicsMaterial>(x);
                collider.Material = mesh;

                MarkAsModified();
                ConfirmModify();
            };

            contactOffsetField.OnChanged += x => { collider.ContactOffset = x; MarkAsModified(); };
            contactOffsetField.OnConfirmed += ConfirmModify;
            contactOffsetField.OnFocusLost += ConfirmModify;

            restOffsetField.OnChanged += x => { collider.RestOffset = x; MarkAsModified(); };
            restOffsetField.OnConfirmed += ConfirmModify;
            restOffsetField.OnFocusLost += ConfirmModify;

            collisionReportModeField.OnSelectionChanged += x =>
            {
                collider.CollisionReportMode = (CollisionReportMode)x;

                MarkAsModified();
                ConfirmModify();
            };

            layerField.OnSelectionChanged += x =>
            {
                ulong layer = 0;
                bool[] states = layerField.States;
                for (int i = 0; i < states.Length; i++)
                    layer |= states[i] ? Layers.Values[i] : 0;

                layersValue = layer;
                collider.Layer = layer;

                MarkAsModified();
                ConfirmModify();
            };

            Layout.AddElement(isTriggerField);
            Layout.AddElement(massField);
            Layout.AddElement(materialField);
            Layout.AddElement(contactOffsetField);
            Layout.AddElement(restOffsetField);
            Layout.AddElement(collisionReportModeField);
            Layout.AddElement(layerField);
        }
Exemple #2
0
        /// <summary>
        /// Converts an array of native colliders to collider components.
        /// </summary>
        /// <param name="colliders">Native colliders.</param>
        /// <returns>Managed collider components.</returns>
        private static Collider[] ConvertColliders(NativeCollider[] colliders)
        {
            Collider[] output = new Collider[colliders.Length];
            for (int i = 0; i < colliders.Length; i++)
                output[i] = colliders[i].Component;

            return output;
        }
Exemple #3
0
        public void RemoveCollider(Collider collider)
        {
            if (collider == null)
                return;

            IntPtr colliderPtr = collider.native.GetCachedPtr();
            Internal_RemoveCollider(mCachedPtr, colliderPtr);
        }
Exemple #4
0
        public void AddCollider(Collider collider)
        {
            if (collider == null || collider.native == null)
                return;

            IntPtr colliderPtr = collider.native.GetCachedPtr();
            Internal_AddCollider(mCachedPtr, colliderPtr);
        }
Exemple #5
0
        /// <summary>
        /// Unregisters the collider from the Rigidbody.
        /// </summary>
        /// <param name="collider">Collider to unregister.</param>
        internal void RemoveCollider(Collider collider)
        {
            if (native == null)
                return;

            if (children.Exists(x => x == collider))
            {
                native.RemoveCollider(collider);
                children.Remove(collider);
            }
        }
Exemple #6
0
        /// <summary>
        /// Registers a new collider with the Rigidbody. This collider will then be used to calculate Rigidbody's geometry
        /// used for collisions, and optionally (depending on set flags) total mass, inertia tensors and center of mass.
        /// </summary>
        /// <param name="collider">Collider to register.</param>
        internal void AddCollider(Collider collider)
        {
            if (native == null)
                return;

            children.Add(collider);
            native.AddCollider(collider);
        }
        /// <summary>
        /// Updates all GUI elements from current values in the collider.
        /// </summary>
        /// <param name="collider">Collider to update the GUI from.</param>
        protected virtual void Refresh(Collider collider)
        {
            isTriggerField.Value = collider.IsTrigger;
            massField.Value = collider.Mass;
            materialField.Value = collider.Material;
            contactOffsetField.Value = collider.ContactOffset;
            restOffsetField.Value = collider.RestOffset;
            collisionReportModeField.Value = (ulong)collider.CollisionReportMode;

            if (layersValue != collider.Layer)
            {
                bool[] states = new bool[64];
                for (int i = 0; i < states.Length; i++)
                    states[i] = (collider.Layer & Layers.Values[i]) == Layers.Values[i];

                layerField.States = states;
                layersValue = collider.Layer;
            }
        }