Пример #1
0
        public void ClearSteps()
        {
            currPartIdx = 0;

            while (currPartIdx < transform.childCount)
            {
                Transform currPart = transform.GetChild(currPartIdx++);

                Step nestedStep = currPart.GetComponent <Step>();
                if (nestedStep != null)
                {
                    continue;
                }

                SubModel nestedSubModel = currPart.GetComponent <SubModel>();
                if (nestedSubModel != null)
                {
                    nestedSubModel.ClearSteps();
                    continue;
                }

                currPart.gameObject.SetActive(false);
            }

            currPartIdx = 0;
        }
Пример #2
0
        public void PlayAnimations()
        {
            // Walk back up the tree until you find another step or a subModel
            // and play the appropriate animation
            int currPartIdx = transform.GetSiblingIndex();

            while (currPartIdx > 0)
            {
                GameObject currPart = transform.parent.GetChild(--currPartIdx).gameObject;

                Step previousStep = currPart.GetComponent <Step>();
                if (previousStep != null)
                {
                    return;
                }

                SubModel previousSubModel = currPart.GetComponent <SubModel>();
                if (previousSubModel != null)
                {
                    // Animate the entire sub-model
                    PlaySubModelAnimation(previousSubModel);
                    return;
                }

                // Animate each part
                PlayPartAnimation(currPart);
            }
        }
Пример #3
0
        // Public methods

        public string PrepareSteps(string stepNumberPrefix, bool clear)
        {
            currPartIdx = 0;
            int    stepNumber = 1;
            string nestedSubModelLastStepNumber = string.Empty;

            if (!IsRoot)
            {
                stepNumberPrefix += '.';
            }

            while (currPartIdx < transform.childCount)
            {
                Transform currPart = transform.GetChild(currPartIdx++);

                Step nestedStep = currPart.GetComponent <Step>();
                if (nestedStep != null)
                {
                    if (nestedStep.Number.Length != 0)
                    {
                        // Re-number using custom scheme
                        string[] nestedStepNumberParts = nestedStep.Number.Split('.');
                        stepNumber = int.Parse(nestedStepNumberParts.Last());
                        nestedStepNumberParts[nestedStepNumberParts.Length - 1] = string.Empty;
                        stepNumberPrefix             = string.Join(".", nestedStepNumberParts);
                        nestedSubModelLastStepNumber = string.Empty;
                    }
                    else if (nestedSubModelLastStepNumber.Length != 0)
                    {
                        nestedStep.Number            = nestedSubModelLastStepNumber;
                        nestedSubModelLastStepNumber = string.Empty;
                    }
                    else
                    {
                        nestedStep.Number = stepNumberPrefix + stepNumber;
                    }
                    nestedStep.NumberVersion = new Version(nestedStep.Number);
                    if (!nestedStep.IsSubStep)
                    {
                        stepNumber++;
                    }
                    continue;
                }

                SubModel nestedSubModel = currPart.GetComponent <SubModel>();
                if (nestedSubModel != null)
                {
                    nestedSubModelLastStepNumber = nestedSubModel.PrepareSteps(stepNumberPrefix + stepNumber, clear);
                    continue;
                }

                currPart.gameObject.SetActive(!clear);
            }

            currPartIdx = 0;
            return(stepNumberPrefix + stepNumber);
        }
Пример #4
0
        private void PlaySubModelAnimation(SubModel subModel)
        {
            Animation animation = subModel.GetComponent <Animation>();

            if (animation == null)
            {
                animation = subModel.gameObject.AddComponent <Animation>();
                animation.AddClip(CreateAnimationClip(subModel.startPosition, subModel.finalPosition), "place");
            }

            animation.Play("place");
        }
Пример #5
0
        public bool PreviousStep()
        {
            Transform currPart = transform.GetChild(currPartIdx);

            if (currPart.GetComponent <Step>() != null)
            {
                currPartIdx--;
                // Edge case: When we step back into a sub model first move it
                // into start position without executing any steps
                currPart = transform.GetChild(currPartIdx);
                SubModel currentSubModel = currPart.GetComponent <SubModel>();
                if (currentSubModel != null)
                {
                    currentSubModel.transform.localPosition = currentSubModel.startPosition;
                    return(true);
                }
            }

            for (; currPartIdx >= 0; currPartIdx--)
            {
                currPart = transform.GetChild(currPartIdx);

                Step previousStep = currPart.GetComponent <Step>();
                if (previousStep != null)
                {
                    return(true);
                }

                SubModel nestedSubModel = currPart.GetComponent <SubModel>();
                if (nestedSubModel != null)
                {
                    nestedSubModel.transform.localPosition = nestedSubModel.startPosition;
                    if (!nestedSubModel.PreviousStep())
                    {
                        continue;
                    }
                    return(true);
                }

                currPart.gameObject.SetActive(false);
            }

            currPartIdx = 0;
            return(false);
        }
Пример #6
0
        public Step GetCurrentStep()
        {
            Transform currPart = transform.GetChild(currPartIdx);

            Step currentStep = currPart.GetComponent <Step>();

            if (currentStep != null)
            {
                return(currentStep);
            }

            SubModel currentSubModel = currPart.GetComponent <SubModel>();

            if (currentSubModel != null)
            {
                return(currentSubModel.GetCurrentStep());
            }

            return(null);
        }
Пример #7
0
        public bool NextStep()
        {
            Transform currPart = transform.GetChild(currPartIdx);

            if (currPart.GetComponent <Step>() != null)
            {
                currPartIdx++;
            }

            for (; currPartIdx < transform.childCount; currPartIdx++)
            {
                currPart = transform.GetChild(currPartIdx);

                Step nextStep = currPart.GetComponent <Step>();
                if (nextStep != null)
                {
                    nextStep.PlayAnimations();
                    return(true);
                }

                SubModel nestedSubModel = currPart.GetComponent <SubModel>();
                if (nestedSubModel != null)
                {
                    nestedSubModel.transform.localPosition = nestedSubModel.startPosition;
                    if (!nestedSubModel.NextStep())
                    {
                        continue;
                    }
                    return(true);
                }

                currPart.gameObject.SetActive(true);
            }

            currPartIdx = transform.childCount - 1;
            return(false);
        }
Пример #8
0
        // Unity lifecycle methods

        void Awake()
        {
            rootModel        = GetComponent <SubModel>();
            rootModel.IsRoot = true;
        }
Пример #9
0
 void Start()
 {
     rootModel = GetComponent <SubModel>();
 }