Created
April 14, 2020 03:40
-
-
Save fanhexin/6e4727039cc2d109dd2023fedea7e624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
using UnityEngine; | |
namespace HopTiles.GamePlay | |
{ | |
// todo 待删除 | |
public class SlicedCube : MonoBehaviour | |
{ | |
[SerializeField] float _borderSize = 0.05f; | |
[SerializeField] Color _glowColor; | |
[SerializeField] Transform _core; | |
public Transform core => _core; | |
[Header("Front")] | |
[SerializeField] Transform _frontTop; | |
[SerializeField] Transform _frontBottom; | |
[SerializeField] Transform _frontLeft; | |
[SerializeField] Transform _frontRight; | |
[Header("Middle")] | |
[SerializeField] Transform _middleTopLeft; | |
[SerializeField] Transform _middleTopRight; | |
[SerializeField] Transform _middleBottomLeft; | |
[SerializeField] Transform _middleBottomRight; | |
[Header("Back")] | |
[SerializeField] Transform _backTop; | |
[SerializeField] Transform _backBottom; | |
[SerializeField] Transform _backLeft; | |
[SerializeField] Transform _backRight; | |
[Header("Corner")] | |
[SerializeField] Transform _cornerFrontTopLeft; | |
[SerializeField] Transform _cornerFrontTopRight; | |
[SerializeField] Transform _cornerFrontBottomLeft; | |
[SerializeField] Transform _cornerFrontBottomRight; | |
[SerializeField] Transform _cornerBackTopLeft; | |
[SerializeField] Transform _cornerBackTopRight; | |
[SerializeField] Transform _cornerBackBottomLeft; | |
[SerializeField] Transform _cornerBackBottomRight; | |
public Color glowColor | |
{ | |
set => _sharedMat.SetColor("_GlowColor", value); | |
} | |
Material _sharedMat; | |
void Awake() | |
{ | |
_sharedMat = _frontTop.GetComponent<Renderer>().sharedMaterial; | |
// glowColor = _glowColor; | |
} | |
public void SetSize(float width, float height, float length) | |
{ | |
_core.localScale = new Vector3(width - _borderSize, height - _borderSize, length - _borderSize); | |
var scale = new Vector3(width, _borderSize, _borderSize); | |
float x = width / 2; | |
float y = height / 2; | |
float z = length / 2; | |
_frontTop.localPosition = new Vector3(0, y, z); | |
_frontTop.localScale = scale; | |
_frontBottom.localPosition = new Vector3(0, -y, z); | |
_frontBottom.localScale = scale; | |
_backTop.localPosition = new Vector3(0, y, -z); | |
_backTop.localScale = scale; | |
_backBottom.localPosition = new Vector3(0, -y, -z); | |
_backBottom.localScale = scale; | |
scale = new Vector3(_borderSize, height, _borderSize); | |
_frontLeft.localPosition = new Vector3(-x, 0, z); | |
_frontLeft.localScale = scale; | |
_frontRight.localPosition = new Vector3(x, 0, z); | |
_frontRight.localScale = scale; | |
_backLeft.localPosition = new Vector3(-x, 0, -z); | |
_backLeft.localScale = scale; | |
_backRight.localPosition = new Vector3(x, 0, -z); | |
_backRight.localScale = scale; | |
scale = new Vector3(_borderSize, _borderSize, length); | |
_middleTopLeft.localPosition = new Vector3(-x, y, 0); | |
_middleTopLeft.localScale = scale; | |
_middleTopRight.localPosition = new Vector3(x, y, 0); | |
_middleTopRight.localScale = scale; | |
_middleBottomLeft.localPosition = new Vector3(-x, -y, 0); | |
_middleBottomLeft.localScale = scale; | |
_middleBottomRight.localPosition = new Vector3(x, -y, 0); | |
_middleBottomRight.localScale = scale; | |
// corner 位置设置 | |
_cornerFrontTopLeft.localPosition = new Vector3(-x, y, z); | |
_cornerFrontTopRight.localPosition = new Vector3(x, y, z); | |
_cornerFrontBottomLeft.localPosition = new Vector3(-x, -y, z); | |
_cornerFrontBottomRight.localPosition = new Vector3(x, -y, z); | |
_cornerBackTopLeft.localPosition = new Vector3(-x, y, -z); | |
_cornerBackTopRight.localPosition = new Vector3(x, y, -z); | |
_cornerBackBottomLeft.localPosition = new Vector3(-x, -y, -z); | |
_cornerBackBottomRight.localPosition = new Vector3(x, -y, -z); | |
} | |
#if UNITY_EDITOR | |
public SerializedProperty EditorGetGlowColor(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_glowColor)); | |
} | |
public SerializedProperty EditorGetBorderSize(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_borderSize)); | |
} | |
public SerializedProperty EditorGetFrontTop(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_frontTop)); | |
} | |
public SerializedProperty EditorGetFrontBottom(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_frontBottom)); | |
} | |
public SerializedProperty EditorGetFrontLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_frontLeft)); | |
} | |
public SerializedProperty EditorGetFrontRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_frontRight)); | |
} | |
public SerializedProperty EditorGetMiddleTopLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_middleTopLeft)); | |
} | |
public SerializedProperty EditorGetMiddleTopRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_middleTopRight)); | |
} | |
public SerializedProperty EditorGetMiddleBottomLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_middleBottomLeft)); | |
} | |
public SerializedProperty EditorGetMiddleBottomRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_middleBottomRight)); | |
} | |
public SerializedProperty EditorGetBackTop(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_backTop)); | |
} | |
public SerializedProperty EditorGetBackBottom(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_backBottom)); | |
} | |
public SerializedProperty EditorGetBackLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_backLeft)); | |
} | |
public SerializedProperty EditorGetBackRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_backRight)); | |
} | |
public SerializedProperty EditorGetCornerFrontTopLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerFrontTopLeft)); | |
} | |
public SerializedProperty EditorGetCornerFrontTopRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerFrontTopRight)); | |
} | |
public SerializedProperty EditorGetCornerFrontBottomLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerFrontBottomLeft)); | |
} | |
public SerializedProperty EditorGetCornerFrontBottomRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerFrontBottomRight)); | |
} | |
public SerializedProperty EditorGetCornerBackTopLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerBackTopLeft)); | |
} | |
public SerializedProperty EditorGetCornerBackTopRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerBackTopRight)); | |
} | |
public SerializedProperty EditorGetCornerBackBottomLeft(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerBackBottomLeft)); | |
} | |
public SerializedProperty EditorGetCornerBackBottomRight(SerializedObject so) | |
{ | |
return so.FindProperty(nameof(_cornerBackBottomRight)); | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment