Example #1
0
        /// <summary>
        /// CinemachineSmoothPath上にアイテムを配置する
        /// </summary>
        /// <param name="itemPrefab">作成するアイテム</param>
        /// <param name="path">対象のpath</param>
        /// <param name="generateCount">作成する数</param>
        /// <param name="startpos">作成を開始する場所(0~1)</param>
        /// <param name="endpos">作成を終了するする場所(0~1)</param>
        /// <returns></returns>
        public static List <GameObject> GenerateItem_withPath(GameObject itemPrefab, CinemachineSmoothPath path, int generateCount, float startpos = 0, float endpos = 1)
        {
            //値の修正
            endpos   = Mathf.Clamp01(endpos);
            startpos = Mathf.Clamp01(startpos);
            if (endpos <= startpos)
            {
                var temp = endpos;
                endpos   = startpos;
                startpos = temp;
            }
            //経路の作成
            var posList  = new List <Vector3>();
            var distance = (endpos - startpos) / generateCount;

            for (int i = 0; i < generateCount; i++)
            {
                posList.Add(path.EvaluatePositionAtUnit(startpos + distance * i, CinemachinePathBase.PositionUnits.Normalized));
            }

            //アイテムの生成
            List <GameObject> resultList = new List <GameObject>();

            foreach (var pos in posList)
            {
                var obj = GameObject.Instantiate(itemPrefab, pos, Quaternion.identity);
                resultList.Add(obj);
            }
            return(resultList);
        }
 /// <summary>
 /// 设置位于曲线的位置
 /// </summary>
 /// <param name="trans"></param>
 /// <param name="distanceAlongPath"></param>
 void SetCartPosition(Transform trans, CinemachineSmoothPath path, float distanceAlongPath)
 {
     if (path != null)
     {
         float m_Position;
         m_Position     = path.StandardizeUnit(distanceAlongPath, m_PositionUnits);
         trans.position = path.EvaluatePositionAtUnit(m_Position, m_PositionUnits);
         trans.rotation = path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits);
     }
 }
Example #3
0
    void SetCartPosition(float distanceAlongPath)
    {
        if (m_Path != null)
        {
            m_Position = m_Path.StandardizeUnit(distanceAlongPath, m_PositionUnits);
            Vector3 pos = m_Path.EvaluatePositionAtUnit(m_Position, m_PositionUnits);
            transform.position = new Vector3(pos.x, pos.y, pos.z);

            //transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, m_Path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits).eulerAngles.y, transform.rotation.eulerAngles.z);
            transform.rotation = m_Path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits);
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (starSlot && path)
        {
            lastPoint = path.m_Waypoints.Length - 1;
            path.m_Waypoints[lastPoint].position = transform.InverseTransformPoint(starSlot.position);
        }

        if (objectOnPath)
        {
            float dist = path.PathLength * progress;
            objectOnPath.position = path.EvaluatePositionAtUnit(dist, CinemachinePathBase.PositionUnits.Distance);
        }
    }
Example #5
0
        /// <summary>
        /// pathに沿って円状にアイテムを配置する
        /// </summary>
        /// <param name="itemPrefab">作成するアイテム</param>
        /// <param name="path">対象のpath</param>
        /// <param name="circleCount">作成する円の数</param>
        /// <param name="unitItemCount">円一つ当たりの個数</param>
        /// <param name="startpos">作成を開始する場所(0~1)</param>
        /// <param name="endpos">作成を終了するする場所(0~1)</param>
        /// <param name="radias">円の大きさ</param>
        /// <returns></returns>
        public static List <GameObject> GenerateItem_aroundPath(GameObject itemPrefab, CinemachineSmoothPath path, int circleCount, int unitItemCount, float startpos = 0, float endpos = 1, float radias = 2.0f)
        {
            //値の修正
            endpos   = Mathf.Clamp01(endpos);
            startpos = Mathf.Clamp01(startpos);
            if (endpos <= startpos)
            {
                var temp = endpos;
                endpos   = startpos;
                startpos = temp;
            }
            //経路の作成
            var posList  = new List <(Vector3 pos, Vector3 direction)>();
            var distance = (endpos - startpos) / circleCount;

            //ちょっとずれた位置を調べてpathの傾きを取得
            for (int i = 0; i < circleCount; i++)
            {
                var checkPos = startpos + distance * i;
                var dl       = (checkPos < 1.0f) ? 0.01f : -0.01f;
                var pos      = path.EvaluatePositionAtUnit(checkPos, CinemachinePathBase.PositionUnits.Normalized);
                var dpos     = path.EvaluatePositionAtUnit(checkPos + dl, CinemachinePathBase.PositionUnits.Normalized);
                posList.Add((pos, ((dpos - pos) * Mathf.Sign(dl)).normalized));
            }

            //アイテムの生成
            List <GameObject> resultList = new List <GameObject>();

            foreach (var posData in posList)
            {
                var center = posData.pos;
                var up     = posData.direction;
                resultList.AddRange(GenerateItem_circle(itemPrefab, center, radias, unitItemCount, up));
            }
            return(resultList);
        }
    private void TurnSpeedModifier()
    {
        float3 startPosition = m_Path.EvaluatePositionAtUnit(m_DollyCart.m_Position, m_DollyCart.m_PositionUnits);
        float3 startTangent  = math.mul(m_Path.EvaluateOrientationAtUnit(m_DollyCart.m_Position, m_DollyCart.m_PositionUnits), c_XZPLANE);
        float3 prevTangent   = startTangent;
        float3 nextTangent   = float3.zero;

        float dotAverage = 0.0f;
        int   count      = 0;
        bool  turnRight  = false;

        for (int i = 1; i <= m_TurnSamplePositionCount; ++i)
        {
            nextTangent = math.mul(m_Path.EvaluateOrientationAtUnit(m_DollyCart.m_Position + (i * m_TurnLookAheadPathDistance), m_DollyCart.m_PositionUnits), c_XZPLANE);

            if (i == 1)
            {
                turnRight = math.cross(startTangent, nextTangent).y < 0 ? true : false;
            }

            if (math.cross(prevTangent, nextTangent).y > 0 && turnRight)
            {
                break;
            }

            dotAverage += math.dot(math.normalizesafe(prevTangent), math.normalizesafe(nextTangent)) * (1 - ((1 / m_TurnSamplePositionCount) * i));
            ++count;
        }

        dotAverage /= count;
        dotAverage  = math.clamp(dotAverage, 0, 1);

        m_TargetTurnSpeed = math.clamp(1 - ((1 - dotAverage) * m_MaxTurnSpeedModifier), 0, 1);

        if (math.distance(m_CurrentTurnSpeed, m_TargetTurnSpeed) < 0.01f)
        {
            m_TargetTurnSpeed = m_CurrentTurnSpeed;
        }

        if (m_CurrentTurnSpeed != m_TargetTurnSpeed)
        {
            m_CurrentTurnSpeed = m_CurrentTurnSpeed + (m_CurrentTurnSpeed < m_TargetTurnSpeed ? m_TurnAcceleration : -m_TurnBreakForce);
        }

        m_CurrentTurnSpeed = math.clamp(m_CurrentTurnSpeed, 0, 1);
    }