コード例 #1
0
ファイル: Plant.cs プロジェクト: minsikim/PB-flower-gen
    /// <summary> 처음 심었을때 새싹까지 Animation Controller의 OnStateUpdate에서 실행됨(약5초) </summary>
    public void SproutA(float progress)
    {
        //TODO !!!! AddComponent를 이미 존재하는 데이타로 하게끔
        //TODO Progress Scriptable Object 에서 설정하게끔 바꿔라
        float[] stemProgress = new float[2] {
            0f, .8f
        };
        float[] leafProgress = new float[2] {
            .5f, 1f
        };

        float currentStemProgress = (progress - stemProgress[0]) / (stemProgress[1] - stemProgress[0]);
        float currentLeafProgress = (progress - leafProgress[0]) / (leafProgress[1] - leafProgress[0]);

        if (0f <= currentStemProgress && currentStemProgress <= 1f)
        {
            float currentThicknessMin = _d.MainStem.SproutThickness.x * currentStemProgress;
            float currentThicknessMax = _d.MainStem.SproutThickness.y * currentStemProgress;
            DrawStem(CurrentMainSpline, currentThicknessMax, currentThicknessMin, 0f, currentStemProgress);
        }

        if (0f <= currentLeafProgress && currentLeafProgress <= 1f)
        {
            for (int i = 0; i < LeavesList.Count; i++)
            {
                LeafLocalData leafData     = _d.Leaves[i];
                float         currentScale = leafData.SproutScale * currentLeafProgress;
                UpdateTransformOnSpline(LeavesList[i], CurrentMainSpline, leafData.SproutPosition * progress, leafData.Rotation, currentScale);
            }
        }
    }
コード例 #2
0
    private List <LeafLocalData> DistributeLeafLocalData(LeafGrowRelation leafGrowRelation, LeafData SproutLeafData, LeafData GrownLeafData, ColorData colorData)
    {
        List <LeafLocalData> dataList = new List <LeafLocalData>();

        int TotalLeafCount       = Util.RandomRange(GrownLeafData.CountRange);
        int TotalSproutLeafCount = Util.RandomRange(SproutLeafData.CountRange);

        for (int i = 0; i < TotalLeafCount; i++)
        {
            LeafLocalData data = new LeafLocalData();

            data.LeafIndex      = i;
            data.TotalLeafCount = TotalLeafCount;

            //TODO use DistributeLeafRotations
            data.Rotation = Util.RandomRange(180f);

            data.FinalPosition  = DistributeLeafPosition(TotalLeafCount, i, GrownLeafData);
            data.SproutPosition = leafGrowRelation == LeafGrowRelation.Same ? data.FinalPosition : DistributeLeafPosition(TotalLeafCount, i, SproutLeafData);

            data.FinalScale  = GrownLeafData.BaseScale + Util.RandomRange(GrownLeafData.ScaleRandomValue);
            data.SproutScale = SproutLeafData.BaseScale + Util.RandomRange(SproutLeafData.ScaleRandomValue);

            data.leafColor = !colorData.isRandom ? colorData.Color : Util.GetColorFromRange(colorData.ColorRange1, colorData.ColorRange2);

            data.isSprout = i < TotalSproutLeafCount ? true : false;

            dataList.Add(data);
        }
        return(dataList);
    }
コード例 #3
0
ファイル: Plant.cs プロジェクト: minsikim/PB-flower-gen
 private void InitLeavesChildren(GameObject Leaves, List <LeafLocalData> LeafDatas)
 {
     for (int i = 0; i < LeafDatas.Count; i++)
     {
         GameObject leaf = Instantiate(LeafPrefab, Leaves.transform);
         leaf.AddComponent <LeafLocalData>();
         LeafLocalData leafData = leaf.GetComponent <LeafLocalData>().AssignValues(LeafDatas[i]);
         UpdateTransformOnSpline(leaf, CurrentMainSpline, leafData.SproutPosition, leafData.Rotation, 0f);
         LeavesList.Add(leaf);
     }
 }
コード例 #4
0
 public LeafLocalData(LeafLocalData data)
 {
     StemIndex      = data.StemIndex;
     LeafIndex      = data.LeafIndex;
     TotalLeafCount = data.TotalLeafCount;
     isSprout       = data.isSprout;
     SproutPosition = data.SproutPosition;
     FinalPosition  = data.FinalPosition;
     Rotation       = data.Rotation;
     SproutScale    = data.SproutScale;
     FinalScale     = data.FinalScale;
     leafColor      = data.leafColor;
 }