Пример #1
0
        private void OnDrawGizmos()
        {
            if (!DrawColliderGizmo_Advanced_Toggle.isEnabled)
            {
                return;
            }
            if (showDebugMesh && cachedCollider != null)
            {
                Color debugColorTemp = new Color(color.r, color.g, color.b, alpha);
                Gizmos.color  = debugColorTemp;
                Gizmos.matrix = transform.localToWorldMatrix;

                if (cachedCollider is BoxCollider boxCollider)
                {
                    Gizmos.DrawCube(boxCollider.center, boxCollider.size);
                    Gizmos.DrawWireCube(boxCollider.center, boxCollider.size);
                }

                if (cachedCollider is SphereCollider sphereCollider)
                {
                    Gizmos.DrawSphere(sphereCollider.center, sphereCollider.radius);
                    Gizmos.DrawWireSphere(sphereCollider.center, sphereCollider.radius);
                }

                if (cachedCollider is CapsuleCollider capsuleCollider)
                {
                    // TODO @Paalo: Somehow scale the debugMesh to be as big as the capsuleCollider.
                    Mesh debugMesh = SonigonPrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Capsule);
                    Gizmos.DrawMesh(debugMesh);
                    Gizmos.DrawWireMesh(debugMesh);
                }
            }
        }
Пример #2
0
        public static GameObject CreatePrimitive(PrimitiveType type, bool withCollider)
        {
            if (withCollider)
            {
                return(GameObject.CreatePrimitive(type));
            }

            GameObject gameObject = new GameObject(type.ToString());
            MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

            meshFilter.sharedMesh = SonigonPrimitiveHelper.GetPrimitiveMesh(type);
            gameObject.AddComponent <MeshRenderer>();

            return(gameObject);
        }
Пример #3
0
        private void OnEnable()
        {
            if (!DrawColliderGizmo_Advanced_Toggle.isEnabled)
            {
                return;
            }
            if (cachedCollider == null)
            {
                cachedCollider = GetComponent <Collider>();
            }

            // Spawn a mesh with the size of the trigger if "showInGame" is true
            if (showInGame && Application.isPlaying && cachedCollider != null)
            {
                var meshFilter = gameObject.AddComponent <MeshFilter>();

                if (cachedCollider is BoxCollider)
                {
                    meshFilter.mesh = SonigonPrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cube);
                }

                if (cachedCollider is SphereCollider)
                {
                    meshFilter.mesh = SonigonPrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Sphere);
                }

                if (cachedCollider is CapsuleCollider)
                {
                    meshFilter.mesh = SonigonPrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Capsule);
                }

                var meshRenderer = gameObject.AddComponent <MeshRenderer>();

                // Added nullcheck
                if (inGameMaterial != null)
                {
                    Material material       = new Material(inGameMaterial);
                    Color    debugColorTemp = new Color(color.r, color.g, color.b, alpha);

                    material.color        = debugColorTemp;
                    meshRenderer.material = material;
                }
            }
        }