コード例 #1
0
        private void OnSceneGUI()
        {
            if (Selection.gameObjects.Length > 0 && (target as SuperPlane).gameObject != Selection.activeGameObject)
            {
                return;
            }

            SuperPlane box = target as SuperPlane;

            CheckScale(box);
            Vector3 rtb = box.Extents / 2;
            Vector3 lbf = -box.Extents / 2;

            // Hide the gizmo if the user holds down Shift
            if (Event.current.shift && SuperCubeEditorUtil.mGizmoTool == Tool.None)
            {
                SuperCubeEditorUtil.mGizmoTool = Tools.current;
                Tools.current = Tool.None;
            }
            else if (!Event.current.shift && SuperCubeEditorUtil.mGizmoTool != Tool.None)
            {
                Tools.current = SuperCubeEditorUtil.mGizmoTool;
                SuperCubeEditorUtil.mGizmoTool = Tool.None;
            }

            Undo.RecordObject(box.transform, "SuperPlane transform Edit");
            Undo.RecordObject(box, "SuperPlane Edit");

            ShowGuides(box);
            TransformHandles(box, rtb, lbf);
        }
コード例 #2
0
        private void ReplaceWithPlaneButton()
        {
            if (GUILayout.Button(new GUIContent("Replace with boring planes", "This will replace all selected SuperPlane objects with Unity's standard plane. This will remove any extra components you may have added. Can undo!")))
            {
                Object[] objs = new Object[targets.Length];
                for (int i = 0; i < targets.Length; ++i)
                {
                    SuperPlane plane = targets[i] as SuperPlane;
                    if (plane == null)
                    {
                        continue;
                    }

                    GameObject go = GameObject.CreatePrimitive(PrimitiveType.Plane);
                    go.transform.parent        = plane.transform.parent;
                    go.transform.localScale    = plane.Extents / 10;
                    go.transform.position      = plane.transform.TransformPoint(Vector3.zero);
                    go.transform.localRotation = plane.transform.localRotation;
                    objs[i] = go;
                    Undo.RegisterCreatedObjectUndo(go, "Replaced SuperPlane");
                }
                Selection.objects = objs;
                for (int i = 0; i < targets.Length; ++i)
                {
                    SuperPlane plane = targets[i] as SuperPlane;
                    Undo.DestroyObjectImmediate(plane.gameObject);
                }
            }
        }
コード例 #3
0
        private static void TransformHandles(SuperPlane aPlane, Vector3 rtb, Vector3 lbf)
        {
            Vector3 snap = EditorTools.GetUnitySnap();

            EditorTools.capDir = Matrix4x4.TRS(Vector3.zero, aPlane.transform.rotation, Vector3.one);

            Handles.color = Color.Lerp(Color.red, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Right, aPlane.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
            SuperCubeEditorUtil.Handle(PivotType.Left, aPlane.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);

            Handles.color = Color.Lerp(Color.blue, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Front, aPlane.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
            SuperCubeEditorUtil.Handle(PivotType.Back, aPlane.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);

            Handles.color = Color.Lerp(Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.blue, Color.white, 0.5f), .5f);
            SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Right, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
            SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Left, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
            SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Right, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
            SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Left, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);

            // Check if there was an edit, and update the mesh!
            Vector3 newExtents = new Vector3(Mathf.Abs(rtb.x - lbf.x), Mathf.Abs(rtb.y - lbf.y), Mathf.Abs(rtb.z - lbf.z));

            if (aPlane.Extents != newExtents)
            {
                aPlane.transform.position += aPlane.transform.TransformDirection(lbf + new Vector3((rtb.x - lbf.x) / 2, (rtb.y - lbf.y) / 2, (rtb.z - lbf.z) / 2));
                aPlane.Extents             = newExtents;
                aPlane.Build(true);
            }
        }
コード例 #4
0
 private void CheckScale(SuperPlane aPlane)
 {
     if (aPlane != null && aPlane.transform.localScale != Vector3.one)
     {
         aPlane.Extents = new Vector3(aPlane.Extents.x * aPlane.transform.localScale.x, aPlane.Extents.y * aPlane.transform.localScale.y, aPlane.Extents.z * aPlane.transform.localScale.z);
         aPlane.transform.localScale = Vector3.one;
         aPlane.Build(true);
     }
 }
コード例 #5
0
        private static void ShowGuides(SuperPlane aBox)
        {
            bool showX = SuperCubeSettings.ShowGuideX;
            bool showY = SuperCubeSettings.ShowGuideY;
            bool showZ = SuperCubeSettings.ShowGuideZ;

            if (!(showX || showY || showZ))
            {
                return;
            }

            Matrix4x4 mat   = aBox.transform.localToWorldMatrix;
            Vector3   pos   = aBox.transform.position;
            float     right = aBox.Extents.x / 2;
            float     left  = -aBox.Extents.x / 2;
            float     back  = aBox.Extents.z / 2;
            float     front = -aBox.Extents.z / 2;

            if (showX)
            {
                Color c = Color.Lerp(Color.red, Color.white, 0.5f);
                c.a           = SuperCubeSettings.GuideAlpha;
                Handles.color = c;
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(-1000, pos.y, front)), mat.MultiplyPoint3x4(new Vector3(1000, pos.y, front)));
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(-1000, pos.y, back)), mat.MultiplyPoint3x4(new Vector3(1000, pos.y, back)));
            }

            if (showY)
            {
                Color c = Color.Lerp(Color.green, Color.white, 0.5f);
                c.a           = SuperCubeSettings.GuideAlpha;
                Handles.color = c;
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(left, -1000, front)), mat.MultiplyPoint3x4(new Vector3(left, 1000, front)));
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(left, -1000, back)), mat.MultiplyPoint3x4(new Vector3(left, 1000, back)));
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(right, -1000, front)), mat.MultiplyPoint3x4(new Vector3(right, 1000, front)));
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(right, -1000, back)), mat.MultiplyPoint3x4(new Vector3(right, 1000, back)));
            }

            if (showZ)
            {
                Color c = Color.Lerp(Color.blue, Color.white, 0.5f);
                c.a           = SuperCubeSettings.GuideAlpha;
                Handles.color = c;
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(left, pos.y, -1000)), mat.MultiplyPoint3x4(new Vector3(left, pos.y, 1000)));
                EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(right, pos.y, -1000)), mat.MultiplyPoint3x4(new Vector3(right, pos.y, 1000)));
            }
        }
コード例 #6
0
        private void ForceNewMeshButton()
        {
            if (GUILayout.Button(new GUIContent("Force new mesh", "For use with prefab meshes! This creates a new mesh with the same settings, disconnecting it from any prefab connections it might have. Can undo!")))
            {
                for (int i = 0; i < targets.Length; ++i)
                {
                    SuperPlane plane = targets[i] as SuperPlane;
                    if (plane == null)
                    {
                        continue;
                    }

                    Undo.RecordObject(plane, "Force new mesh");
                    plane.ForceNewMesh();
                }
            }
        }
コード例 #7
0
    /// <summary>
    /// Creates a SuperPlane game object, and assigns the given data! This function will build the mesh right away.
    /// </summary>
    /// <param name="aAt">Location in world space.</param>
    /// <param name="aSize">The width and height of the SuperPlane.</param>
    /// <param name="aMaterial">The material to assign to it, don't want that awful pink color!</param>
    /// <param name="aType">What type of UV coordinates do you want on the plane?</param>
    /// <param name="aSliceDistance">How far apart should extra verts be spaced out on the surface? 0 for none at all. floor(size/sliceDistance)</param>
    /// <returns>A ready-to-go SuperPlane GameObject named "SuperPlane" with a with a fully built SuperPlane, MeshFilter, Renderer, and BoxCollider component!</returns>
    public static GameObject Create(Vector3 aAt, Vector2 aSize, Material aMaterial, UVType aType = UVType.Unit, float aSliceDistance = 0)
    {
        GameObject go    = new GameObject("SuperPlane");
        SuperPlane plane = go.AddComponent <SuperPlane>();

        plane.mUVType            = aType;
        plane.Extents            = new Vector3(aSize.x, 0, aSize.y);
        plane.transform.position = aAt;
        if (aSliceDistance > 0)
        {
            plane.mSliceDistance = aSliceDistance;
            plane.mSliceFaces    = true;
        }
        plane.Build(true);
        go.GetComponent <Renderer>().sharedMaterial = aMaterial;

        go.AddComponent <BoxCollider>();
        return(go);
    }
コード例 #8
0
ファイル: SuperPlaneEditor.cs プロジェクト: 2ty/race3d
		private void CheckScale(SuperPlane aPlane) {
			if (aPlane != null && aPlane.transform.localScale != Vector3.one) {
				aPlane.Extents = new Vector3(aPlane.Extents.x * aPlane.transform.localScale.x, aPlane.Extents.y * aPlane.transform.localScale.y, aPlane.Extents.z * aPlane.transform.localScale.z);
				aPlane.transform.localScale = Vector3.one;
				aPlane.Build(true);
			}
		}
コード例 #9
0
ファイル: SuperPlaneEditor.cs プロジェクト: 2ty/race3d
		private static  void TransformHandles      (SuperPlane aPlane, Vector3 rtb, Vector3 lbf) {
			Vector3 snap = EditorTools.GetUnitySnap();
	        
			EditorTools.capDir = Matrix4x4.TRS(Vector3.zero, aPlane.transform.rotation, Vector3.one);
	        
			Handles.color = Color.Lerp(Color.red, Color.white, 0.5f);
			SuperCubeEditorUtil.Handle(PivotType.Right, aPlane.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
			SuperCubeEditorUtil.Handle(PivotType.Left,  aPlane.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
	        
			Handles.color = Color.Lerp(Color.blue, Color.white, 0.5f);
			SuperCubeEditorUtil.Handle(PivotType.Front, aPlane.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
			SuperCubeEditorUtil.Handle(PivotType.Back,  aPlane.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
	        
			Handles.color = Color.Lerp( Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.blue, Color.white, 0.5f), .5f);
			SuperCubeEditorUtil.Handle(PivotType.Back  | PivotType.Right, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
			SuperCubeEditorUtil.Handle(PivotType.Back  | PivotType.Left,  aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
			SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Right, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
			SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Left,  aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);

			// Check if there was an edit, and update the mesh!
			Vector3 newExtents = new Vector3(Mathf.Abs(rtb.x - lbf.x), Mathf.Abs(rtb.y - lbf.y), Mathf.Abs(rtb.z - lbf.z));
			if (aPlane.Extents != newExtents) {
				aPlane.transform.position += aPlane.transform.TransformDirection(lbf + new Vector3((rtb.x - lbf.x) / 2, (rtb.y - lbf.y) / 2, (rtb.z - lbf.z) / 2));
				aPlane.Extents = newExtents;
				aPlane.Build(true);
			}
		}
コード例 #10
0
ファイル: SuperPlaneEditor.cs プロジェクト: 2ty/race3d
		private static void ShowGuides(SuperPlane aBox) {
			bool showX = SuperCubeSettings.ShowGuideX;
			bool showY = SuperCubeSettings.ShowGuideY;
			bool showZ = SuperCubeSettings.ShowGuideZ;
			if (!(showX || showY || showZ)) return;

			Matrix4x4 mat = aBox.transform.localToWorldMatrix;
			Vector3   pos = aBox.transform.position;
			float right =  aBox.Extents.x/2;
			float left  = -aBox.Extents.x/2;
			float back  =  aBox.Extents.z/2;
			float front = -aBox.Extents.z/2;
			
			if (showX) {
				Color c =  Color.Lerp(Color.red, Color.white, 0.5f);
				c.a = SuperCubeSettings.GuideAlpha;
				Handles.color = c;
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(-1000, pos.y, front)), mat.MultiplyPoint3x4(new Vector3(1000, pos.y, front)));
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(-1000, pos.y, back )), mat.MultiplyPoint3x4(new Vector3(1000, pos.y, back )));
			}
			
			if (showY) {
				Color c =  Color.Lerp(Color.green, Color.white, 0.5f);
				c.a = SuperCubeSettings.GuideAlpha;
				Handles.color = c;
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(left,  -1000, front)), mat.MultiplyPoint3x4(new Vector3(left,  1000, front)));
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(left,  -1000, back )), mat.MultiplyPoint3x4(new Vector3(left,  1000, back )));
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(right, -1000, front)), mat.MultiplyPoint3x4(new Vector3(right, 1000, front)));
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(right, -1000, back )), mat.MultiplyPoint3x4(new Vector3(right, 1000, back )));
			}
			
			if (showZ) {
				Color c = Color.Lerp(Color.blue, Color.white, 0.5f);
				c.a = SuperCubeSettings.GuideAlpha;
				Handles.color = c;
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(left,  pos.y, -1000)), mat.MultiplyPoint3x4(new Vector3(left,  pos.y, 1000)));
				EditorTools.DrawDepthLine(mat.MultiplyPoint3x4(new Vector3(right, pos.y, -1000)), mat.MultiplyPoint3x4(new Vector3(right, pos.y, 1000)));
			}
		}