예제 #1
0
        private CollisionControllerElement CreateTriggersColliders(GameObject originalColliderHolder)
        {
            GameObject collidersContainer = new GameObject("TempCollidersContainer");

            collidersContainer.transform.parent        = originalColliderHolder.transform;
            collidersContainer.transform.localPosition = Vector3.zero;
            collidersContainer.transform.localRotation = Quaternion.identity;
            collidersContainer.transform.localScale    = Vector3.one * 1.1f;

            Collider[] colliders = originalColliderHolder.GetComponents <Collider>();

            foreach (Collider collider in colliders)
            {
                if (!collider.isTrigger)
                {
                    Collider newCollider = DuplicateComponent(collider, collidersContainer);

                    if (newCollider.GetType() == typeof(MeshCollider))
                    {
                        MeshCollider meshCollider = (MeshCollider)newCollider;
                        meshCollider.convex = true;
                    }

                    newCollider.isTrigger = true;

                    if (ProjectData.GameMode == GameMode.Edit)
                    {
                        collider.enabled = false;
                    }
                }
            }

            CollisionControllerElement element = collidersContainer.AddComponent <CollisionControllerElement>();

            return(element);
        }
예제 #2
0
        public void InitializeController(InputController inputController = null)
        {
            _inputController = inputController;

            if (_inputController != null)
            {
                _defaultHighlightConfig = _inputController.DefaultHighlightConfig;
            }
            else
            {
                var defHighlighter = gameObject.AddComponent <DefaultHightlighter>();
                _defaultHighlightConfig = defHighlighter.HightLightConfig();
            }

            _highlight = gameObject.GetComponent <VarwinHighlightEffect>();

            if (_highlight == null)
            {
                _highlight = gameObject.AddComponent <VarwinHighlightEffect>();
            }


            HightLightConfig config = new HightLightConfig(true,
                                                           0.3f,
                                                           Color.red,
                                                           false,
                                                           0.2f,
                                                           0.1f,
                                                           0.3f,
                                                           Color.red,
                                                           false,
                                                           0.8f,
                                                           0.5f,
                                                           Color.red,
                                                           true,
                                                           0.5f,
                                                           1.0f,
                                                           Color.red);


            _collisionControllerHighlightConfig = config;

            _highlight.SetConfiguration(_collisionControllerHighlightConfig);

            _tempColliders  = new List <CollisionControllerElement>();
            _childColliders = new List <Collider>();

            List <GameObject> objectsWithColliders = new List <GameObject>();

            Collider[] children = GetComponentsInChildren <Collider>();

            foreach (Collider child in children)
            {
                if (!child.isTrigger && child.enabled)
                {
                    _childColliders.Add(child);

                    if (!objectsWithColliders.Contains(child.gameObject))
                    {
                        objectsWithColliders.Add(child.gameObject);
                    }
                }
            }

            foreach (GameObject objectWithCollider in objectsWithColliders)
            {
                CollisionControllerElement triggerObject = CreateTriggersColliders(objectWithCollider);
                triggerObject.OnCollisionEnterDelegate += OnCollide;
                triggerObject.OnTriggerExitDelegate    += OnColliderExit;
                _tempColliders.Add(triggerObject);
            }

            ProjectData.GameModeChanged += GameModeChanged;
        }