예제 #1
0
        private void PerformClick()
        {
            Ray        ray = mPlantCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit rayHit;

            if (Physics.Raycast(ray, out rayHit))
            {
                PlantClickable hitPart = rayHit.collider.GetComponent <PlantClickable>();

                if (hitPart != null)
                {
                    HandleGoalClick(hitPart.Goal);
                }
            }
        }
예제 #2
0
        private void FillPlant()
        {
            mParts.Clear();

            // Create a list with all assignments and goals
            List <DataGoal> entryData = new List <DataGoal>(DataManager.Assignment.Data);

            // Only show goals which are completed or which have an end date less than a week away
            TimeSpan showGoalRange = TimeSpan.FromDays(7);

            for (int i = 0; i < DataManager.Plan.Data[0].Goals.Length; i++)
            {
                DataGoal goal = DataManager.Plan.Data[0].Goals[i];

                if (goal.IsDone || goal.EndAt.Value - DateTime.Now < showGoalRange)
                {
                    entryData.Add(goal);
                }
            }

            //entryData.AddRange(DataManager.Plan.Data[0].Goals);

            // Sort based on creation date for assignments and projected end dates for goals
            entryData.Sort((a, b) =>
            {
                DateTime aDate = (a is DataAssignment) ? a.CreatedAt.Value : a.EndAt.Value;
                DateTime bDate = (b is DataAssignment) ? b.CreatedAt.Value : b.EndAt.Value;
                return(aDate.CompareTo(bDate));
            });

            // Create a plant component for each entry
            for (int i = 0; i < entryData.Count; i++)
            {
                if (!mCurrentStem.HasOpenPoints)
                {
                    CreateStem();
                }

                Transform chosenPoint = mCurrentStem.GetPoint(mRandom.Next());

                PlantClickable prefab;
                int            random = mRandom.Next();

                if (entryData[i] is DataAssignment)
                {
                    // Assignment
                    if (entryData[i].IsPastDeadline)
                    {
                        prefab = mWitheredLeafPrefab;
                    }
                    else if (entryData[i].IsDone)
                    {
                        prefab = mLeafPrefabs[random % mLeafPrefabs.Length];
                    }
                    else
                    {
                        prefab = mBudPrefab;
                    }
                }
                else
                {
                    // Goal
                    prefab = mFlowerPrefabs[Mathf.Clamp(entryData[i].Category.ID - 1, 0, mFlowerPrefabs.Length)];
                }

                PlantClickable clickable        = Instantiate(prefab, chosenPoint);
                Transform      createdTransform = clickable.transform;
                createdTransform.localPosition = Vector3.zero;
                createdTransform.localRotation = Quaternion.Euler(0, 90f, 0);

                clickable.Initialize(entryData[i]);
                //created.localScale = Vector3.one;

                mParts.Add(clickable);
            }
        }