Example #1
0
    void InstantiateObject()
    {
        for (int i = 0; i < Count; ++i)
        {
            Vector2 v = Random.insideUnitCircle * radius;

            GameObject prefab = Prefabs[Count == 1 ? 0 : Random.Range(0, Prefabs.Count)];

            GameObject go = Instantiate(prefab) as GameObject;
            go.transform.position = Count == 1?new Vector3(0, 5, -10): new Vector3(v.x, 0, v.y);
            go.SetActive(true);

            if (Controll && Count == 1)
            {
                samplePlay = go.AddComponent <SamplePlay>();
            }
            if (Rotate && Count == 1)
            {
                go.AddComponent <SampleRotate>();
            }

            SamplePlayEffect samplePlayEffect = go.GetComponent <SamplePlayEffect>();
            if (samplePlayEffect != null)
            {
                samplePlayEffect.enabled = ShowEffect && Count == 1;
            }

            GpuInstancedAnimation animation = go.GetComponent <GpuInstancedAnimation>();

            int index          = Random.Range(0, animation.animationClips.Count);
            var animationFrame = animation.animationClips[index];
            animation.speed = Count == 1? 1: Random.Range(0.5f, 3);
            animation.Play(animationFrame.Name);

            mUpdateList.Add(animation);

            if (Count == 1)
            {
                controllAnimation = animation;
            }
            if (Count > 1)
            {
                foreach (var clip in animation.animationClips)
                {
                    clip.wrapMode = GpuInstancedAnimationClip.WrapMode.Loop;
                }
            }
        }
    }
Example #2
0
    void Start()
    {
        SetButtonActive(false);

        if (ObjectCountinputField)
        {
            ObjectCountinputField.onValueChanged.AddListener(s =>
            {
                int.TryParse(s, out Count);
            });
        }

        if (InstantiateButton)
        {
            InstantiateButton.onClick.AddListener(InstantiateObject);
        }

        if (ControllToggle)
        {
            ControllToggle.onValueChanged.AddListener(v => {
                Controll = v;
                SetButtonActive(v);

                if (controllAnimation)
                {
                    if (Controll)
                    {
                        if (samplePlay == null)
                        {
                            samplePlay = controllAnimation.gameObject.AddComponent <SamplePlay>();
                        }
                    }
                    else
                    {
                        if (samplePlay)
                        {
                            Destroy(samplePlay);
                            samplePlay = null;
                        }
                    }
                }
            });
        }
        if (ShowEffectToggle)
        {
            ShowEffectToggle.onValueChanged.AddListener(v => {
                ShowEffect = v;
                if (controllAnimation)
                {
                    SamplePlayEffect samplePlayEffect = controllAnimation.GetComponent <SamplePlayEffect>();
                    if (samplePlayEffect != null)
                    {
                        samplePlayEffect.enabled = ShowEffect;
                    }
                }
            });
        }
        if (RotateToggle)
        {
            RotateToggle.onValueChanged.AddListener(v => {
                Rotate = v;
                if (controllAnimation)
                {
                    SampleRotate sampleRotate = controllAnimation.GetComponent <SampleRotate>();
                    if (sampleRotate == null)
                    {
                        sampleRotate = controllAnimation.gameObject.AddComponent <SampleRotate>();
                    }
                    if (sampleRotate != null)
                    {
                        sampleRotate.enabled = Rotate;
                    }
                }
            });
        }
        if (IdleButton)
        {
            IdleButton.onClick.AddListener(() => {
                if (samplePlay)
                {
                    samplePlay.PlayIdle();
                }
            });
        }
        if (RunButton)
        {
            RunButton.onClick.AddListener(() =>
            {
                if (samplePlay)
                {
                    samplePlay.PlayRun();
                }
            });
        }
        if (AttackButton)
        {
            AttackButton.onClick.AddListener(() =>
            {
                if (samplePlay)
                {
                    samplePlay.PlayAttack();
                }
            });
        }
        if (DieButton)
        {
            DieButton.onClick.AddListener(() =>
            {
                if (samplePlay)
                {
                    samplePlay.PlayDie();
                }
            });
        }
        if (BlendButton)
        {
            BlendButton.onClick.AddListener(() =>
            {
                if (samplePlay)
                {
                    samplePlay.PlayBlend();
                }
            });
        }
    }