//void Start() { //} // Update is called once per frame //void Update() { //} private void SetRippleSize(Transform rippleFor, float zOffset, Color rippleColor) { _border.color = rippleColor; Vector3 worldPosition = rippleFor.position; worldPosition.z -= ((rippleFor.localScale.z / 2f) + 0.025f); worldPosition.z += zOffset; _tr.position = worldPosition; _tr.parent = rippleFor.parent; stWidth = (rippleFor.localScale.x * 100f); stHeight = (rippleFor.localScale.y * 100f); stWidth += ((_border.guiBorder.border.left + _border.guiBorder.border.right)); stHeight += ((_border.guiBorder.border.top + _border.guiBorder.border.bottom)); stWidth /= (_border.scale.x * 100f); stHeight /= (_border.scale.y * 100f); _border.width = stWidth; _border.height = stHeight; _border.Commit(); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void OnSceneGUI() { // if (editSpriteBorder.meshFilter == null || editSpriteBorder.meshFilter.sharedMesh == null) { return; } // Vector3[] vertices = new Vector3[4]; Vector3[] corners = new Vector3[5]; Vector3[] controls = new Vector3[8]; float halfWidthScaled = editSpriteBorder.width * editSpriteBorder.scale.x * 0.5f; float halfHeightScaled = editSpriteBorder.height * editSpriteBorder.scale.y * 0.5f; float offsetX = 0.0f; float offsetY = 0.0f; // switch (editSpriteBorder.anchor) { case exPlane.Anchor.TopLeft: offsetX = -halfWidthScaled; offsetY = -halfHeightScaled; break; case exPlane.Anchor.TopCenter: offsetX = 0.0f; offsetY = -halfHeightScaled; break; case exPlane.Anchor.TopRight: offsetX = halfWidthScaled; offsetY = -halfHeightScaled; break; case exPlane.Anchor.MidLeft: offsetX = -halfWidthScaled; offsetY = 0.0f; break; case exPlane.Anchor.MidCenter: offsetX = 0.0f; offsetY = 0.0f; break; case exPlane.Anchor.MidRight: offsetX = halfWidthScaled; offsetY = 0.0f; break; case exPlane.Anchor.BotLeft: offsetX = -halfWidthScaled; offsetY = halfHeightScaled; break; case exPlane.Anchor.BotCenter: offsetX = 0.0f; offsetY = halfHeightScaled; break; case exPlane.Anchor.BotRight: offsetX = halfWidthScaled; offsetY = halfHeightScaled; break; default: offsetX = 0.0f; offsetY = 0.0f; break; } // vertices[0] = new Vector3(-halfWidthScaled - offsetX, halfHeightScaled + offsetY, 0.0f); vertices[1] = new Vector3(halfWidthScaled - offsetX, halfHeightScaled + offsetY, 0.0f); vertices[2] = new Vector3(halfWidthScaled - offsetX, -halfHeightScaled + offsetY, 0.0f); vertices[3] = new Vector3(-halfWidthScaled - offsetX, -halfHeightScaled + offsetY, 0.0f); // DELME { // // // switch ( editSpriteBorder.plane ) { // case exPlane.Plane.XY: // vertices[0] = new Vector3 (-halfWidthScaled-offsetX, halfHeightScaled+offsetY, 0.0f ); // vertices[1] = new Vector3 ( halfWidthScaled-offsetX, halfHeightScaled+offsetY, 0.0f ); // vertices[2] = new Vector3 ( halfWidthScaled-offsetX, -halfHeightScaled+offsetY, 0.0f ); // vertices[3] = new Vector3 (-halfWidthScaled-offsetX, -halfHeightScaled+offsetY, 0.0f ); // break; // case exPlane.Plane.XZ: // vertices[0] = new Vector3 (-halfWidthScaled-offsetX, 0.0f, halfHeightScaled+offsetY ); // vertices[1] = new Vector3 ( halfWidthScaled-offsetX, 0.0f, halfHeightScaled+offsetY ); // vertices[2] = new Vector3 ( halfWidthScaled-offsetX, 0.0f, -halfHeightScaled+offsetY ); // vertices[3] = new Vector3 (-halfWidthScaled-offsetX, 0.0f, -halfHeightScaled+offsetY ); // break; // case exPlane.Plane.ZY: // vertices[0] = new Vector3 (0.0f, halfHeightScaled+offsetY, -halfWidthScaled-offsetX ); // vertices[1] = new Vector3 (0.0f, halfHeightScaled+offsetY, halfWidthScaled-offsetX ); // vertices[2] = new Vector3 (0.0f, -halfHeightScaled+offsetY, halfWidthScaled-offsetX ); // vertices[3] = new Vector3 (0.0f, -halfHeightScaled+offsetY, -halfWidthScaled-offsetX ); // break; // } // } DELME end // 0 -- 1 // | | // 3 -- 2 Transform trans = editSpriteBorder.transform; corners[0] = trans.localToWorldMatrix * new Vector4(vertices[0].x, vertices[0].y, vertices[0].z, 1.0f); corners[1] = trans.localToWorldMatrix * new Vector4(vertices[1].x, vertices[1].y, vertices[1].z, 1.0f); corners[2] = trans.localToWorldMatrix * new Vector4(vertices[2].x, vertices[2].y, vertices[2].z, 1.0f); corners[3] = trans.localToWorldMatrix * new Vector4(vertices[3].x, vertices[3].y, vertices[3].z, 1.0f); corners[4] = corners[0]; Handles.DrawPolyLine(corners); // 0 -- 1 -- 2 // | | // 7 3 // | | // 6 -- 5 -- 4 controls[0] = corners[0]; controls[1] = (corners[0] + corners[1]) / 2.0f; controls[2] = corners[1]; controls[3] = (corners[1] + corners[2]) / 2.0f; controls[4] = corners[2]; controls[5] = (corners[2] + corners[3]) / 2.0f; controls[6] = corners[3]; controls[7] = (corners[3] + corners[0]) / 2.0f; // TEMP: not sure this is good { Event e = Event.current; if (e.type == EventType.MouseDown && e.button == 0 && e.clickCount == 1) { Undo.RegisterSceneUndo("ex2D.Scene"); } // } TEMP end // for (int i = 0; i < controls.Length; ++i) { Vector3 pos = controls[i]; Handles.color = new Color(1.0f, 1.0f, 0.0f, 0.5f); Vector3 newPos = Handles.FreeMoveHandle(pos, editSpriteBorder.transform.rotation, HandleUtility.GetHandleSize(pos) / 20.0f, Vector3.zero, Handles.DotCap ); HandleRezie(i, pos, newPos); } // Handles.Label( editSpriteBorder.transform.position + Vector3.up * 2, // "Size = " + editSpriteBorder.width + " x " + editSpriteBorder.height ); if (GUI.changed) { editSpriteBorder.Commit(); EditorUtility.SetDirty(editSpriteBorder); } }