protected override void UpdateSprite() { if (_animation == null) { _animation = Animation as IDirectionalAnimation; if (_animation == null) { return; } } _lastOrientation = _billboard.Orientation; var facing = _billboard.Orientation; if (_billboard.Facing.RequiresFlipping()) { facing = _billboard.Orientation.GetFlippedSide(); Renderer.Flip(_billboard.Orientation.IsFlipped()); } var animFacing = _animation.GetFacing(facing); if (animFacing == null || Animator.FrameIndex >= animFacing.FrameIndices.Length) { return; } var idx = animFacing.FrameIndices[Animator.FrameIndex]; Renderer.SetSprite(_animation.GetSprite(idx), _animation.NormalMap, _animation.EmissiveMap, _animation.GetSpriteCollider(idx)); }
protected virtual void UpdateSprite() { if (_directionalAnimation == null) { _renderer.SetSprite( _animation.GetSprite(_animator.FrameIndex), _animation.NormalMap, _animation.EmissiveMap, _animation.GetSpriteCollider(_animator.FrameIndex), _animNode.InstancedIndex, _animNode.ForceReverse); return; } _lastOrientation = _billboard.Orientation; var facing = _billboard.Orientation; if (_billboard.Facing.RequiresFlipping()) { facing = _billboard.Orientation.GetFlippedSide(); _renderer.Flip(_billboard.Orientation.IsFlipped()); } var animFacing = _directionalAnimation.GetFacing(facing); if (animFacing == null || _animator.FrameIndex >= animFacing.FrameIndices.Length) { return; } var idx = animFacing.FrameIndices[_animator.FrameIndex]; _renderer.SetSprite(_directionalAnimation.GetSprite(idx), _directionalAnimation.NormalMap, _directionalAnimation.EmissiveMap, _directionalAnimation.GetSpriteCollider(idx), _animNode.InstancedIndex, _animNode.ForceReverse); }
public static bool ValidSide(this SpriteFacing facing, DirectionsEight side) { if (facing == SpriteFacing.Eightway) { return(side != DirectionsEight.Top); } switch (side) { case DirectionsEight.Front: case DirectionsEight.Right: case DirectionsEight.Rear: return(true); case DirectionsEight.Left: return(facing == SpriteFacing.Eightway || facing == SpriteFacing.Fourway); } if (facing == SpriteFacing.EightwayFlipped) { switch (side) { case DirectionsEight.FrontRight: case DirectionsEight.RearRight: return(true); } } if (facing == SpriteFacing.Eightway) { return(true); } return(false); }
public static void SetCameraPos(Camera camera, DirectionsEight index, float viewOffset, float heightOffset) { switch (index) { case DirectionsEight.Top: camera.transform.localPosition = new Vector3(0, viewOffset * 0.75f, 0); camera.transform.localRotation = Quaternion.Euler(90, 0, 0); break; default: case DirectionsEight.Front: camera.transform.localPosition = new Vector3(0, 0, viewOffset); camera.transform.localRotation = Quaternion.Euler(0, 180, 0); break; case DirectionsEight.FrontRight: camera.transform.localPosition = new Vector3( viewOffset * HalfSideOffset, 0, viewOffset * HalfSideOffset); camera.transform.localRotation = Quaternion.Euler(0, -135, 0); break; case DirectionsEight.Right: camera.transform.localPosition = new Vector3(viewOffset, 0, 0); camera.transform.localRotation = Quaternion.Euler(0, -90, 0); break; case DirectionsEight.RearRight: camera.transform.localPosition = new Vector3( viewOffset * HalfSideOffset, 0, -viewOffset * HalfSideOffset); camera.transform.localRotation = Quaternion.Euler(0, -45, 0); break; case DirectionsEight.Rear: camera.transform.localPosition = new Vector3(0, 0, -viewOffset); camera.transform.localRotation = Quaternion.Euler(0, 0, 0); break; case DirectionsEight.RearLeft: camera.transform.localPosition = new Vector3( -viewOffset * HalfSideOffset, 0, -viewOffset * HalfSideOffset); camera.transform.localRotation = Quaternion.Euler(0, 45, 0); break; case DirectionsEight.Left: camera.transform.localPosition = new Vector3(-viewOffset, 0, 0); camera.transform.localRotation = Quaternion.Euler(0, 90, 0); break; case DirectionsEight.FrontLeft: camera.transform.localPosition = new Vector3( -viewOffset * HalfSideOffset, 0, viewOffset * HalfSideOffset); camera.transform.localRotation = Quaternion.Euler(0, 135, 0); break; } camera.transform.position += new Vector3(0, heightOffset, 0); }
void Update() { if (!_active) { return; } _billboard.Apply(_renderer.transform, _backwards, ref _lastAngleHeight); bool inMargin; var orientation = SpriteFacingControl.GetCameraSide(_facing, transform, transform.parent, 5, out inMargin); if (_orientation == orientation || (inMargin && (orientation.IsAdjacent(_orientation)))) { return; } _orientation = orientation; var facing = orientation; if (_facing.RequiresFlipping()) { facing = _orientation.GetFlippedSide(); _renderer.flipX = _orientation.IsFlipped(); } var sprite = _sprite.GetFacingSprite(facing); if (sprite != null) { _renderer.sprite = sprite; } }
public bool CanPass(DirectionsEight dir) { if (!CanExit(dir)) { return(false); } return(true); }
public virtual bool CanExit(DirectionsEight dir) { if (_neighbors[(int)dir] == null || !_neighbors[(int)dir].Walkable) { return(false); } return(true); }
public virtual bool BlocksVision(DirectionsEight dir) { if (!CanExit(dir)) { return(true); } return(false); }
public DirectionalFrames(DirectionsEight side, int length) { Side = side; FrameIndices = new int[length]; for (int i = 0; i < FrameIndices.Length; i++) { FrameIndices[i] = -1; } }
public bool IsOpen(DirectionsEight dir) { var door = GetDoor(dir); if (door != null && !door.Opened) { return(false); } return(_borders[(int)dir] == BlockBorder.None || _borders[(int)dir] == BlockBorder.Impassable); }
public virtual bool BlocksVision(DirectionsEight dir) { if (!CanExit(dir)) { return(true); } var door = GetDoor(dir); return(door != null && door.BlocksVision); }
public virtual bool CanExit(DirectionsEight dir) { if (_neighbors[(int)dir] == null || !_neighbors[(int)dir].Walkable) { return(false); } var door = GetDoor(dir); return(door == null || door.Opened); }
public Sprite GetSpriteFrame(DirectionsEight facing, int frame) { var frames = GetFacingSprites(facing); if (frames != null) { return(frames[Mathf.Clamp(frame, 0, frames.Length - 1)]); } return(GetSpriteFrame(frame)); }
private Sprite[] GetFacingSprites(DirectionsEight side) { for (int i = 0; i < DirectionalFrames.Count; i++) { if (DirectionalFrames[i].Side == side) { return(DirectionalFrames[i].Frames); } } return(null); }
public SavedSpriteCollider GetSpriteCollider(DirectionsEight facing, int spriteIdx) { var frames = GetFacingIndices(facing); if (frames != null) { var idx = frames[spriteIdx]; return(Set.Colliders[Mathf.Clamp(idx, 0, Set.Colliders.Length - 1)]); } return(null); }
public Sprite GetSprite(DirectionsEight facing, int spriteIdx) { var frames = GetFacingIndices(facing); if (frames != null) { var idx = frames[spriteIdx]; return(Set.Sprites[Mathf.Clamp(idx, 0, Set.Sprites.Length - 1)]); } return(Set.Sprites[spriteIdx]); }
public static bool IsFlipped(this DirectionsEight facing) { switch (facing) { case DirectionsEight.FrontLeft: case DirectionsEight.Left: case DirectionsEight.RearLeft: return(true); } return(false); }
public DirectionalFrames GetFacing(DirectionsEight side) { for (int i = 0; i < DirectionalFrames.Count; i++) { if (DirectionalFrames[i].Side == side) { return(DirectionalFrames[i]); } } return(null); }
private IEnumerator TestAnimationRunnerBounds() { _spriteAnimator.ResetAnimation(_sprite); UpdateSpriteFrame(); int noCam = 0; _spriteCollider = _renderer.GetComponent <SpriteCollider>(); if (_spriteCollider != null) { _spriteCollider.OnCreate(null); } while (_spriteAnimator.Active) { if (!_looping) { break; } if (Camera.current == null) { yield return(null); noCam++; if (noCam > 500) { break; } continue; } Game.SpriteCamera = Camera.current; noCam = 0; var orientation = SpriteFacingControl.GetCameraSide(_facing, transform, transform, 5, out var inMargin); _billboard.Apply(_renderer.transform, _backwards, ref _lastAngleHeight); if (_spriteAnimator.CheckFrameUpdate()) { UpdateSpriteFrame(); } else if (_orientation != orientation && (!inMargin || (!orientation.IsAdjacent(_orientation)))) { _orientation = orientation; UpdateSpriteFrame(); } if (!_spriteAnimator.Active && _looping) { _spriteAnimator.ResetAnimation(_sprite); } if (_spriteCollider != null) { _spriteCollider.UpdateCollider(); } yield return(null); } }
public Sprite GetFacingSprite(DirectionsEight side) { if (Frames == null || Frames.Count == 0) { return(null); } for (int i = 0; i < Frames.Count; i++) { if (Frames[i].Side == side) { return(Frames[i].Frame); } } return(Frames[0].Frame); }
public static DirectionsEight GetFlippedSide(this DirectionsEight facing) { switch (facing) { case DirectionsEight.FrontLeft: return(DirectionsEight.FrontRight); case DirectionsEight.Left: return(DirectionsEight.Right); case DirectionsEight.RearLeft: return(DirectionsEight.RearRight); } return(facing); }
public bool CanExit(DirectionsEight dir, bool ignoreDoor) { if (this[dir] == null || !this[dir].Walkable) { return(false); } if (!_borders[(int)dir].CanExit()) { return(false); } if (ignoreDoor) { return(true); } var door = GetDoor(dir); return(door == null || door.Opened); }
public void OnSystemUpdate(float dt) { if (!_active) { return; } _billboard.Apply(_renderer.transform, _backwards, ref _lastAngleHeight); var orientation = SpriteFacingControl.GetCameraSide(_facing, transform, transform.parent, 5, out var inMargin); if (_orientation == orientation || (inMargin && (orientation.IsAdjacent(_orientation)))) { if (_spriteAnimator.CheckFrameUpdate()) { UpdateSpriteFrame(); } return; } _orientation = orientation; UpdateSpriteFrame(); }
public static void TakePicture(Transform parent, Bounds bounds, DirectionsEight dir, RenderTexture texture) { Camera.enabled = true; Camera.transform.parent = parent; Camera.targetTexture = texture; SpriteFacingControl.SetCameraPos(Camera, dir, main._viewOffset, 0f); if (main._debug) { DebugExtension.DebugArrow(Camera.transform.position, Camera.transform.forward, Color.blue, 5f); } main.Zoom(bounds); main.PositionBottom(parent.position); _canvasHackField.SetValue(null, null); Camera.Render(); _canvasHackField.SetValue(null, _canvasHackObject); Camera.Render(); Camera.enabled = false; //Camera.targetTexture = null; Camera.transform.parent = null; }
void Update() { if (!_active) { return; } if (_spriteAnimator.CheckFrameUpdate()) { UpdateSpriteFrame(); } _billboard.Apply(transform, _backwards); bool inMargin; var orientation = SpriteFacingControl.GetCameraSide(_facing, transform, transform.parent, 5, out inMargin); if (_orientation == orientation || (inMargin && (orientation.IsAdjacent(_orientation)))) { return; } _orientation = orientation; UpdateSpriteFrame(); }
public Door GetDoor(DirectionsEight dir) { var door = _doors[(int)dir]; if (door != null) { return(door); } if (!dir.IsCardinal()) { return(null); } var adjacent = dir.Adjacent(); for (int i = 0; i < adjacent.Length; i++) { door = _doors[(int)adjacent[i]]; if (door != null) { return(door); } } return(null); }
public BaseCell this[DirectionsEight index] { get { return(_neighbors[(int)index]); } set { _neighbors[(int)index] = value; } }
public void SetDoor(Door door, DirectionsEight dir) { _doors[(int)dir] = door; }
public DirRange(DirectionsEight dir, float min, float max) { Dir = dir; Min = min; Max = max; }
public BlockBorder GetBorder(DirectionsEight dir) { return(_borders[(int)dir]); }