コード例 #1
0
        public void Awake()
        {
            if (_instance == null)
            {
                _instance = this;
                DontDestroyOnLoad(gameObject);

                // TODO All of this should be GENERATED HERE instead of adquired by using GetComponent<>()
                CharMovement           = GetComponent <CharacterMovement>();
                CharController         = GetComponent <CharacterController>();
                MainCamera             = GetComponentInChildren <Camera>();
                Animator               = GetComponent <Animator>();
                _collider              = GetComponent <CapsuleCollider>();
                _layerMaskAllButPlayer = ~(1 << LayerMaskManager.Get(Layer.Player));
                _shovel          = GetComponentInChildren <ShovelMovementComponent>();
                Look             = new Look(gameObject);
                CameraController = gameObject.AddComponent <CameraController>();

                Camera landmarkCamera = GameObject.Find("LandmarkCamera").GetComponent <Camera>();
                CameraController.Init(MainCamera, landmarkCamera);
            }
            else
            {
                Debug.LogWarning("Player singleton instance destroyed!");
                Destroy(gameObject);
            }
        }
コード例 #2
0
    public override Interaction CheckForPromotion()
    {
        Ray        ray = new Ray(Player.GetInstance().MainCamera.transform.position, Player.GetInstance().MainCamera.transform.forward);
        RaycastHit hit;

        Debug.DrawRay(ray.origin, ray.direction, Color.red);
        _hasHit = Physics.SphereCast(ray, 0.05f, out hit, 1000.0f, 1 << LayerMaskManager.Get(Layer.Verse),
                                     QueryTriggerInteraction.Collide);

        if (_hasHit)
        {
            if (_selectedGameObject != null && _selectedGameObject.GetInstanceID() != hit.collider.gameObject.GetInstanceID())
            {
                HideFeedback();
            }
            _selectedGameObject = hit.collider.gameObject;
            _selectedVerse      = _selectedGameObject.GetComponent <VerseInfoComponent>().Info;
            ShowFeedback();
        }
        else
        {
            HideFeedback();
            _selectedGameObject = null;
        }
        return(this);
    }
コード例 #3
0
 private void BaseInit()
 {
     _iconGameObject = new GameObject("_marker");
     _iconGameObject.transform.parent = transform;
     _iconGameObject.transform.LocalReset();
     _iconGameObject.layer = LayerMaskManager.Get(Layer.DrawFront);
     _icon = _iconGameObject.AddComponent <SpriteRenderer>();
 }
コード例 #4
0
 public override void HideFeedback()
 {
     _mark.enabled = true;
     foreach (MeshRenderer r in _model.GetComponentsInChildren <MeshRenderer>())
     {
         r.gameObject.layer = LayerMaskManager.Get(Layer.Landmark);
     }
 }
コード例 #5
0
 public override void ShowFeedback()
 {
     _mark.enabled = false;
     foreach (MeshRenderer r in _model.GetComponentsInChildren <MeshRenderer>())
     {
         r.gameObject.layer = LayerMaskManager.Get(Layer.Outline);
     }
 }
コード例 #6
0
 public static int Get(Layer layer)
 {
     if (_instance == null)
     {
         _instance = new LayerMaskManager();
     }
     return(_instance._map[layer]);
 }
コード例 #7
0
        public void Start()
        {
            int player = 1 << LayerMaskManager.Get(Layer.Player);

            _layerMaskAllButPlayer = ~player;
            _collider     = GetComponent <CapsuleCollider>();
            _charMovement = GetComponent <CharacterMovement>();
        }
コード例 #8
0
 public override void DoInteraction()
 {
     AudioController.GetInstance().PlayPickupCoffin();
     _coffin.transform.parent = _slot;
     _coffin.transform.LocalReset();
     _coffin.layer = LayerMaskManager.Get(Layer.Landmark);
     _coffin.GetComponent <Collider>().enabled = true;
     Player.GetInstance().CurrentState = new WalkRunState();
 }
コード例 #9
0
 public override void DoInteraction()
 {
     _coffin.layer = LayerMaskManager.Get(Layer.Landmark);
     AnimationUtils.MoveSmoothlyTo(_coffin.transform, _tomb.transform.position - Vector3.up * 1.5f, 0.5f);
     AnimationUtils.LookTowardsHorizontal(_coffin.transform, _tomb.transform.right, 0.5f, () => {
         _coffin.transform.parent = _tomb.transform;
         _coffin.GetComponent <Collider>().enabled = true;
     });
     // TODO LookTowardsVertical (using arg lookDir instead of LookAtPoint)
     _tombComponent.PlayerTombTransition(new PoemState(_tombComponent), false);
     _tombComponent.HideMarker();
     _tombComponent.HideColliders();
     AudioController.GetInstance().AddMusicChannel();
 }
コード例 #10
0
    void Awake()
    {
        if (instance == null)
        {
            DontDestroyOnLoad(gameObject);
            instance = this;
        }
        else if (instance != null)
        {
            Destroy(gameObject);
        }

        if (Audio == null)
        {
            Audio = GetComponent <AudioManager>();
        }
        if (Gameplay == null)
        {
            Gameplay = GetComponent <GameplayManager>();
        }
        if (PauseMenu == null)
        {
            PauseMenu = GetComponent <PauseMenuManager>();
        }
        if (SaveLoad == null)
        {
            SaveLoad = GetComponent <SaveLoadManager>();
        }
        if (Pooler == null)
        {
            Pooler = GetComponent <ObjectPoolerManager>();
        }
        if (LayerMasks == null)
        {
            LayerMasks = GetComponent <LayerMaskManager>();
        }

        _startSequence = new List <IGameManager>();
        if (!InMainMenu)
        {
            _startSequence.Add(Gameplay);
            _startSequence.Add(PauseMenu);
            _startSequence.Add(Pooler);
        }
        _startSequence.Add(Audio);
        _startSequence.Add(SaveLoad);

        StartCoroutine(StartupManagers());
    }
コード例 #11
0
        public void Awake()
        {
            _mainCamera        = GetComponent <Camera>();
            _alwaysFrontCamera = new GameObject("AlwaysFrontCamera").AddComponent <Camera>();
            _alwaysFrontCamera.transform.parent        = transform;
            _alwaysFrontCamera.transform.localPosition = Vector3.zero;
            _alwaysFrontCamera.transform.eulerAngles   = Vector3.zero;
            _layerMaskDrawFront  = 1 << LayerMaskManager.Get(Layer.DrawFront);
            _layerMaskDrawFront |= 1 << LayerMaskManager.Get(Layer.Verse);

            _alwaysFrontCamera.CopyFrom(_mainCamera);
            _alwaysFrontCamera.depth       = Depth;
            _alwaysFrontCamera.clearFlags  = CameraClearFlags.Depth;
            _alwaysFrontCamera.depth       = _mainCamera.depth + 1;
            _alwaysFrontCamera.cullingMask = _layerMaskDrawFront;
        }
コード例 #12
0
        public override void DoInteraction()
        {
            Coffin.layer = LayerMaskManager.Get(Layer.DrawFront);
            MarkableComponent m = Coffin.GetComponent <MarkableComponent>();

            if (m != null)
            {
                m.enabled = false;
            }
            else
            {
                DebugMsg.ComponentNotFound(Debug.LogWarning, typeof(MarkableComponent));
            }
            AudioController.GetInstance().PlayPickupCoffin();
            Player.GetInstance().CurrentState = new DragCoffinState(Coffin);
        }
コード例 #13
0
        public CartMovementBehaviour(Transform transform, GameObject cart, SuperConfig config) : base(transform)
        {
            _cartConfig    = config.DriveCartMovement;
            _movement      = new SmoothMovementHandler(config.CartAcceleration).SetMovement();
            _cartTransform = cart.transform;
            foreach (Collider c in cart.GetComponentsInChildren <Collider>())
            {
                if (!c.isTrigger)
                {
                    c.enabled = false;
                    _disabledColliders.Add(c);
                }
            }
            _layerMaskAllButPlayer = ~(1 << LayerMaskManager.Get(Layer.Player));
            _moveBackAction        = Player.GetInstance().Actions.GetAction(PlayerAction.MoveBack);

            Utils.AnimationUtils.LookTowardsHorizontal(transform, cart.transform.forward, _cartConfig.GoInsideTimeSeconds);
            Utils.AnimationUtils.LookTowardsVertical(Player.GetInstance().MainCamera.transform, transform.position + cart.transform.forward, _cartConfig.GoInsideTimeSeconds);
            AudioController.GetInstance().PlayCart();
        }
コード例 #14
0
        public VersesDisplayer(int length)
        {
            _displayMeshText = new TextMesh[length];
            _shadowMeshText  = new TextMesh[length];

            _container = new GameObject("_textMeshContainer");
            Font     font    = Resources.Load <Font>("Fonts/HammerheadRegular");
            Material fontMat = Resources.Load <Material>("Fonts/HammerheadRegularAlwaysFrontMat");

            for (int i = 0; i < _displayMeshText.Length; ++i)
            {
                GameObject child = new GameObject("_child" + i);
                child.layer            = LayerMaskManager.Get(Layer.Verse);
                child.transform.parent = _container.transform;
                child.transform.LocalReset();
                _displayMeshText[i]                      = child.AddComponent <TextMesh>();
                _displayMeshText[i].fontSize             = FontSize;
                _displayMeshText[i].transform.localScale = Vector3.one * Scale;
                _displayMeshText[i].alignment            = TextAlignment.Center;
                _displayMeshText[i].anchor               = TextAnchor.MiddleCenter;
                _displayMeshText[i].font                 = font;
                _displayMeshText[i].GetComponent <Renderer>().material       = fontMat;
                _displayMeshText[i].GetComponent <Renderer>().material.color = BaseColor;

                GameObject subchild = new GameObject("_shadow" + i);
                subchild.layer            = LayerMaskManager.Get(Layer.Verse);
                subchild.transform.parent = child.transform;
                subchild.transform.LocalReset();
                _shadowMeshText[i]                      = subchild.AddComponent <TextMesh>();
                _shadowMeshText[i].fontSize             = FontSize;
                _shadowMeshText[i].transform.localScale = Vector3.one;
                _shadowMeshText[i].offsetZ              = ShadowOffset;
                _shadowMeshText[i].alignment            = TextAlignment.Center;
                _shadowMeshText[i].anchor               = TextAnchor.MiddleCenter;
                _shadowMeshText[i].font                 = font;
                _shadowMeshText[i].GetComponent <Renderer>().material       = fontMat;
                _shadowMeshText[i].GetComponent <Renderer>().material.color = ShadowColor;

                _displayMeshText[i].gameObject.SetActive(false);
            }
        }
コード例 #15
0
        public void Awake()
        {
            _outlineShader                   = Shader.Find("Custom/PostOutline");
            _drawSimpleShader                = Shader.Find("Custom/DrawSimple");
            _mainCamera                      = GetComponent <Camera>();
            _outlinerCamera                  = new GameObject("CameraOutliner").AddComponent <Camera>();
            _outlinerCamera.enabled          = false;
            _outlinerCamera.transform.parent = transform;
            _outlinerCamera.transform.LocalReset();
            _layerMaskOnlyOutline = 1 << LayerMaskManager.Get(Layer.Outline);
            _material             = new Material(_outlineShader)
            {
                color = OutlineColor
            };
            _material.SetInt("_Thickness", Thickness);

            _outlinerCamera.CopyFrom(_mainCamera);
            _outlinerCamera.clearFlags      = CameraClearFlags.Color;        // TODO: these params should be changed based on a MainCamera listener, not per frame
            _outlinerCamera.backgroundColor = Color.black;
            _outlinerCamera.cullingMask     = _layerMaskOnlyOutline;
        }
コード例 #16
0
        public CarveTerrainInteraction()
        {
            if (_digMarker == null)
            {
                _digMarker = GameObject.CreatePrimitive(PrimitiveType.Cube);
                Object.Destroy(_digMarker.GetComponent <Collider>());
                _digMarker.SetActive(false);
                _digMarker.name = "_digMarker";
                _digMarker.transform.localScale = new Vector3(4, 0.1f, 4);
                _digMarker.layer = LayerMaskManager.Get(Layer.Outline);
                _digMarker.GetComponent <MeshRenderer>().material = new Material(Shader.Find("UI/Default"));
                IconMarkerComponent icon = _digMarker.AddComponent <IconMarkerComponent>();
                icon.Init("Sprites/dig", new Color(0, 81.0f / 255.0f, 240.0f / 255.0f));
            }

            _player = Player.GetInstance();

            string     terrainName = "Terrain Volume";
            GameObject terrain     = GameObject.Find(terrainName);

            if (!terrain)
            {
                DebugMsg.GameObjectNotFound(Debug.LogError, terrainName);
            }
            else
            {
                var terrainVolume = terrain.GetComponent <TerrainVolume>();
                if (!terrainVolume)
                {
                    DebugMsg.ComponentNotFound(Debug.LogError, typeof(TerrainVolume));
                }

                _terrainCarver = terrain.GetComponent <CarveTerrainVolumeComponent>();
                if (!_terrainCarver)
                {
                    DebugMsg.ComponentNotFound(Debug.LogError, typeof(CarveTerrainVolumeComponent));
                }
            }
        }
コード例 #17
0
        public override void DoInteraction()
        {
            _coffin.transform.parent = null;
            _coffin.GetComponent <Collider>().enabled = true;
            Rigidbody rb = _coffin.GetComponent <Rigidbody>();

            rb.isKinematic = false;
            _coffin.layer  = LayerMaskManager.Get(Layer.Landmark);

            MarkableComponent m = _coffin.GetComponent <MarkableComponent>();

            if (m == null)
            {
                Debug.LogWarning("Object <b>" + _coffin.gameObject.name + "</b> could not be marked. (Missing MarkableComponent!)");                 // TODO extract to Error class
            }
            else
            {
                //TODO: ADD GUARD -> enable only if not throwed into a hole
                m.enabled = true;
            }

            AudioController.GetInstance().PlayThrowCoffin();
            Player.GetInstance().CurrentState = new WalkRunState();
        }
コード例 #18
0
        public bool PassHeightRestrictions(Vector3 point, Vector3 normal)
        {
            RaycastHit[] hits = Physics.BoxCastAll(point + Vector3.up * 5.0f, _digMarker.transform.localScale, Vector3.down,
                                                   Quaternion.identity, 10.0f, ~(1 << LayerMaskManager.Get(Layer.Player)), QueryTriggerInteraction.Collide);
            if (hits.Length == 0)
            {
                return(true);
            }

            float maxHeight = -99;
            float minHeight = 99;

            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.gameObject.tag != TagManager.Get(Tag.Terrain))
                {
                    return(false);
                }
                if (hit.distance == 0.0f)
                {
                    return(false);
                }
                if (hit.distance > maxHeight)
                {
                    maxHeight = hit.distance;
                }
                if (hit.distance < minHeight)
                {
                    minHeight = hit.distance;
                }
            }
            if (maxHeight - minHeight > 1.0f)
            {
                return(false);
            }
            return(true);
        }
コード例 #19
0
 public override void ShowFeedback()
 {
     Coffin.layer = LayerMaskManager.Get(Layer.Outline);
 }
コード例 #20
0
        public void Init(Vector3 upperLeft, Vector3 lowerRight)
        {
            if (!_groundInstantiator)
            {
                _groundInstantiator      = Resources.Load <GameObject>("Prefabs/Ground");
                _groundInstantiator.name = "_ground";
                _groundInstantiator.SetActive(false);
            }
            if (!_groundHeapInstantiator)
            {
                _groundHeapInstantiator      = Resources.Load <GameObject>("Prefabs/GroundHeap");
                _groundHeapInstantiator.name = "_groundHeap";
                _groundHeapInstantiator.SetActive(false);
            }
            if (!_gravestoneInstantiator)
            {
                _gravestoneInstantiator      = Resources.Load <GameObject>("Prefabs/Tombstone");
                _gravestoneInstantiator.name = "_gravestone";
                _gravestoneInstantiator.SetActive(false);
            }

            _icon = gameObject.AddComponent <IconMarkerComponent>();
            _icon.Init("Sprites/bury", new Color(0, 81.0f / 255.0f, 240.0f / 255.0f));

            _ground = Object.Instantiate(_groundInstantiator);
            _ground.transform.parent = transform;
            _ground.transform.LocalReset();
            _ground.transform.localPosition = Vector3.down * 0.5f;
            _ground.SetActive(true);

            _groundHeap = Object.Instantiate(_groundHeapInstantiator);
            _groundHeap.transform.parent = transform;
            _groundHeap.transform.LocalReset();
            _groundHeap.transform.up            = Vector3.up;
            _groundHeap.transform.localPosition = new Vector3(-2, -1.25f, -3.5f);
            _groundHeap.SetActive(true);

            SphereCollider c = gameObject.AddComponent <SphereCollider>();

            c.isTrigger        = false;
            c.radius           = 2.75f;
            c.center           = new Vector3(0, 0.85f, 0);
            c.gameObject.layer = LayerMaskManager.Get(Layer.IgnoreRaycast);

            SphereCollider trigger = gameObject.AddComponent <SphereCollider>();

            trigger.isTrigger = true;
            trigger.radius    = 4.5f;

            TTomb triggerTomb = gameObject.AddComponent <TTomb>();

            triggerTomb.Init(this);

            Vector3    position = (lowerRight - upperLeft) / 2.0f + upperLeft;
            RaycastHit hit;

            Player.GetInstance().GetEyeSight(out hit);
            transform.position = position;
            transform.up       = hit.normal;

            const float offset   = 1.75f;
            Vector3     middleUp = new Vector3(lowerRight.x + offset, hit.point.y, lowerRight.z - (lowerRight.z - upperLeft.z) / 2.0f);

            _gravestone = Object.Instantiate(_gravestoneInstantiator);
            _gravestone.SetActive(true);
            _gravestone.transform.parent = transform;
            _gravestone.transform.LocalReset();
            _gravestone.transform.position       = middleUp;
            _gravestone.transform.localPosition -= Vector3.up * 3.0f;
            MiddleLow = new Vector3(upperLeft.x - offset, hit.point.y, lowerRight.z - (lowerRight.z - upperLeft.z) / 2.0f);
        }