コード例 #1
0
        public static void AlignToGroundNormal(GroundAlign ga, IUndoManager undo = null)
        {
            if (undo != null)
            {
                undo.RecordTransform("Align", ga.transform);
            }

            bool resetLayer = false;

            if (LayerMask.LayerToName(ga.gameObject.layer) == "Environment")
            {
                ga.gameObject.layer = LayerMask.NameToLayer("Default");
                resetLayer          = true;
            }

            RaycastHit?hit;

            if (ga.OnlyAlignToTerrain)
            {
                hit = TerrainManager.GetTerrainHitOnly(ga.transform.position + Vector3.up * 100, Vector3.down);
            }
            else
            {
                hit = TerrainManager.GetGroundHit(ga.transform.position);
            }


            if (hit.HasValue)
            {
                Vector3 fromv = GetTransfomAxis(ga.transform, ga.FromAxis, ga.InvertAxis);

                ga.transform.rotation = Quaternion.FromToRotation(fromv, hit.Value.normal) * ga.transform.rotation;
            }
            else
            {
            }

            if (resetLayer)
            {
                ga.gameObject.layer = LayerMask.NameToLayer("Environment");
            }
        }
コード例 #2
0
        public static void AlignToGround(GroundAlign ga, IUndoManager undo = null)
        {
            if (undo != null)
            {
                undo.RecordTransform("Align", ga.transform);
            }

            bool resetLayer = false;

            if (LayerMask.LayerToName(ga.gameObject.layer) == "Environment")
            {
                ga.gameObject.layer = LayerMask.NameToLayer("Default");
                resetLayer          = true;
            }

            RaycastHit?hit;

            if (ga.OnlyAlignToTerrain)
            {
                hit = TerrainManager.GetTerrainHitOnly(ga.transform.position + Vector3.up * 100, Vector3.down);
            }
            else
            {
                hit = TerrainManager.GetGroundHit(ga.transform.position);
            }

            if (hit != null)
            {
                ga.transform.position = hit.Value.point + ga.Offset;
            }

            if (resetLayer)
            {
                ga.gameObject.layer = LayerMask.NameToLayer("Environment");
            }
        }