Example #1
0
            public void Initialize()
            {
                if (IsInitialized)
                {
                    return;
                }

                IsInitialized = true;

                if (AnimationObject == null)
                {
                    IsCanceled = true;
                }
                else
                {
                    try {
                        DeltaValue  = (EndValue - StartValue) / Steps;
                        CurrentStep = 0;
                        ValueType   = ReflectionUtils.GetPropertyType(
                            AnimationObject.GetType(), PropertyName);

                        SetValue(StartValue);
                    } catch (Exception ex) {
                        IsCanceled = true;
                        ex.LogError();
                    }
                }
            }
Example #2
0
    // Use this for initialization
    void Start()
    {
        animationScript = gameObject.GetComponent<AnimationObject>();
        animationScript.Animation_Complete += OnSpawnAnimComplete;

        lifeTimer = new Timer(PUDDLE_LIFE_DURATION);
    }
Example #3
0
    public static AnimationObject GenerateAnimationObject(string id, MapCoords source, MapCoords dest)
    {
        AnimationObject temp = Resources.Load <AnimationObject>("SkillAnimationControllers/" + id);

        MapCoords position;

        if (temp.startAtSource)
        {
            position = source;
        }
        else
        {
            position = dest;
        }

        AnimationObject obj = GameObject.Instantiate <AnimationObject>(temp, Globals.GridToWorld(position.X, position.Y), Quaternion.identity);

        /*
         * Debug.Log("attempt to load: " + "AnimationControllers/" + id);
         * obj.GetComponent<Animator>().runtimeAnimatorController =
         *  Resources.Load<RuntimeAnimatorController>("AnimationControllers/" + id);
         */

        return(obj);
    }
Example #4
0
    void Awake()
    {
        // load animation
        foreach (string path in prefab.animationPath)
        {
            AnimationObject obj = GameObject.Find(path).GetComponent <AnimationObject>();
            animationList.Add(obj);
        }

        //load trigger
        foreach (string path in prefab.triggerPath)
        {
            TriggerObject obj = GameObject.Find(path).GetComponent <TriggerObject>();
            triggerList.Add(obj);
        }

        // init sprite list
        spriteList = new List <MySprite>();
        MySprite sprite1 = GameObject.Find("Sprite1").GetComponent <MySprite>();
        MySprite sprite2 = GameObject.Find("Sprite2").GetComponent <MySprite>();

        spriteList.Add(sprite1);
        spriteList.Add(sprite2);
        int id = data.playerId;

        mainSprite = GameObject.Find("Sprite" + id).GetComponent <MySprite>();
        mainSprite.SetMainPlayer();

        // init id
        rpc.SetMainSpriteId(mainSprite.Id);
        rpc.initPlayerList();
        rpc.SetStatus("Id", mainSprite.Id);
    }
        public bool PlayAnimation(AnimationBaseDefinition definition, UnityAction callback = null, bool forceAnimation = false)
        {
            if (currentState == null)
            {
                return(false);
            }

            if (!forceAnimation && currentAnimation != null && definition.animationLabel == currentAnimation.label)
            {
                LogFormat("ActorAnimatorController: Try to trigger Animation twice '{0}'", definition.animationLabel);
                return(false);
            }

            // --- Search Animation ---
            AnimationObject animationObj = currentState.GetAnimation(definition);

            // --- Play Animation ---
            bool status = false;

            if (animationObj != null && animationObj.clip != null)
            {
                status = PlayAnimation(animationObj, callback, forceAnimation);
            }
            else if (animationObj != null && animationObj.clip == null)
            {
                LogErrorFormat("{0}[{2}] (ActorAnimatorController): AnimationClip is not set '{1}'", name, animationObj.label, currentState.Name);
            }
            else
            {
                LogErrorFormat("{0}[{2}] (ActorAnimatorController): Animation is not found: '{1}'", name, definition.animationLabel, currentState.Name);
            }

            return(status);
        }
Example #6
0
    private void DoMovingToBarricades(ZombieAction lastAction)
    {
        _moveState = ZombieMoveState.Moving;
        OnStateChanged();
        _rigidBody.constraints = DefaultConstraints;
        _animationQueue.Clear();

        if (lastAction != ZombieAction.Rotating)
        {
            AnimationObject animObj = null;
            if (_model.Type == ZombieType.Acid || _model.Type == ZombieType.Fire)
            {
                animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieWalk, new List <object> {
                    false
                });
            }
            else
            {
                animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieWalk, new List <object> {
                    _model.IsBoss
                });
            }

            _animationQueue.Add(animObj);
            _animationQueue.PlayNext();
        }
    }
    //Controls the current character's pump animation state and the pump handles animation state
    internal void ControlPumpAnimations(AnimationObject character, bool pumpState, int characterState)
    {
        //Starts the animations for pump movement and characters pump animation
        pumpAnimator.SetBool("Pump", pumpState);
        switch (character)
        {
        case AnimationObject.Player:
            playerAnimator.SetInteger("Character State", characterState);
            break;

        case AnimationObject.AI1:
            AI1Animator.SetInteger("Character State", characterState);
            break;

        case AnimationObject.AI2:
            AI2Animator.SetInteger("Character State", characterState);
            break;

        case AnimationObject.AI3:
            AI3Animator.SetInteger("Character State", characterState);
            break;

        default:
            break;
        }
    }
    IEnumerator PlayAnimations(Skill skill, CutsceneController controller, bool playNext)
    {
        int count = skill.animControllerID.Count;
        int curr  = 0;

        foreach (string item in skill.GetAnimControllerID())
        {
            curr++;

            AnimationObject animation = Globals.GenerateAnimationObject(item, spawnPosition, destposition);
            animation.transform.SetParent(controller.spawnPoint);

            controller.skillObjects.Add(animation);

            if (curr == count & playNext)
            {
                animation.AnimationObjectDestroyed += controller.NextNode;
            }

            animation.InitAnimatorObject(item, destposition.X, destposition.Y, false, null);


            SFXController.sfxInstance.ChangeSong(skill.GetSFXKey());

            yield return(new WaitForSeconds(0.5f));
        }
    }
Example #9
0
    public AnimationExportData(Transform transform, bool useQuaternion)
    {
        t = transform;

        Animator ator = t.GetComponent <Animator>();

        a = ator.runtimeAnimatorController;

        defaultAnimation = a.animationClips[0];

        AnimationClipCurveData[] data = AnimationUtility.GetAllCurves(defaultAnimation, true);
        properties = new Hashtable();

        foreach (AnimationClipCurveData d in data)
        {
            string jn = AnimationUtil.ExtractPropertyName(d.propertyName);

            if (!properties.ContainsKey(d.path))
            {
                properties.Add(d.path, new AnimationObject(d.path));
            }

            AnimationObject ao = (AnimationObject)properties[d.path];

            AnimationProperty p = new AnimationProperty(jn, d);
            ao.Properties.Add(p);
        }
    }
Example #10
0
    private void DoInFly()
    {
        _animationQueue.Clear();
        AnimationObject animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieFly, null);

        _animationQueue.Add(animObj);
        _animationQueue.PlayNext();
    }
        public override bool PlayModularAnimation(string label, ActorAnimatorLayer layer, string subState, UnityAction callback = null)
        {
            AnimationObject         animationObj = null;
            AnimationBaseDefinition definition   = new AnimationBaseDefinition(label);
            ModularBaseState        modularState = null;
            int  layerIndex = -1;
            bool status     = false;

            if (!IsModularStateExisting(layer, subState, out modularState, out layerIndex))
            {
                LogErrorFormat("{0}[{2}] (ActorAnimatorController): ModularLayer not found '{1}'.", name, layer, currentState.Name);
                return(status);
            }

            // Get Animation
            animationObj = modularState.GetAnimation(definition);

            // --- Play Animation ---
            if (animationObj != null && animationObj.clip != null)
            {
                LogFormat("{0} (ActorAnimatorController): Play Modular Animation: '{1}'", name, animationObj.label);

                // Set Animation
                animator.SetBool(modularState.Name, true);
                animator.SetTrigger(animationObj.label); // Play Animation

                // FadeIn LayerWeight
                float layerWeight = animator.GetLayerWeight(layerIndex);

                if (layerWeight < 1f)
                {
                    if (modularState.fadeInDuration > 0f)
                    {
                        StartCoroutine(BlendLayer(layerIndex, animator.GetLayerWeight(layerIndex), 1f, modularState.fadeInDuration));
                    }
                    else
                    {
                        animator.SetLayerWeight(layerIndex, 1f);
                    }
                }

                status = true;

                // Set Callback
                currentModularAnimationCallbacks[0] = callback; // layerIndex - 1
            }
            else
            {
                LogErrorFormat("{0}[{2}] (ActorAnimatorController): ModularAnimationClip is not set '{1}'. Reset weight to '0'.", name, label, currentState.Name);
                animator.SetTrigger(string.Format("{0}_Reset", modularState.Name));
                animator.SetBool(modularState.Name, false);

                // Reset LayerWeight
                animator.SetLayerWeight(layerIndex, 0f);
            }

            return(status);
        }
    protected override void DoAnimation(Cell caster, Cell target)
    {
        base.DoAnimation(caster, target);

        if (AnimationObject != null)
        {
            AnimationObject.transform.position = target.GetVector3Position();
            AnimationObject.SetActive(true);
        }
    }
 /// <summary>
 /// 欲觀看動畫的播放按鈕點擊事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Btn_Watch_Click(object sender, RoutedEventArgs e)
 {
     this.Dispatcher.BeginInvoke(new Action(() =>
     {
         MainWindow mainWindow               = Application.Current.MainWindow as MainWindow;
         AnimationObject animationObject     = ((Button)sender).DataContext as AnimationObject;
         mainWindow.Flyout_Animation.Content = new AnimationViewUserControl(animationObject);
         mainWindow.Flyout_Animation.IsOpen  = true;
     }));
 }
Example #14
0
    IEnumerator PlayAnimations()
    {
        bool calculateCombat = true; //basically making it so we still calculate combat after

        foreach (AnimationData item in combat.animationDatas)
        {
            List <string> ids = item.skillUsed.GetAnimControllerID();

            for (int i = 0; i < ids.Count; i++)
            {
                calculateCombat = false;

                // SO we think this is the problem currently
                //


                AnimationObject animObj = Globals.GenerateAnimationObject(ids[i], item.sourceNode, item.DestNode);

                animObj.InitAnimatorObject(ids[i], item.DestNode.data.posX, item.DestNode.data.posY, false, this);
                animations.Add(animObj);

                if (i == ids.Count - 1)
                {
                    animObj.lastObj = true;
                }

                SFXController.sfxInstance.ChangeSong(item.skillUsed.GetSFXKey());

                yield return(new WaitForSeconds(0.5f));
            }
        }

        if (calculateCombat)
        {
            ApplyCombatDamage();
        }



        /*
         * foreach (string animation in animationIDs)
         * {
         *
         *  AnimationObject animObj = AnimationObject.SpawnAnimationObject(startNode);
         *  animObj.InitAnimatorObject(animation, targetNode);
         *
         *
         *
         *  yield return new WaitForSeconds(0.5f);
         * }
         *
         * ApplyCombatDamage();
         */
    }
Example #15
0
 private IObjectPool <AnimationObject> MakeNewPool(AnimationObject prefab)
 {
     return(new QueueBasedObjectPool <AnimationObject>(
                // We must instantiate a clone of the prefab instance as part of the contruction function, and make sure it starts off deactivated
                () => {
         var toRet = Instantiate(prefab);
         toRet.gameObject.SetActive(false);
         return toRet;
     }, ANIMATION_OBJ_PRE_INIT_SIZE
                ));
 }
Example #16
0
    public override IEnumerator Play(Animator animator, Cell caster, Cell target, System.Action endAction)
    {
        yield return(new WaitForSeconds(DelayBeforeStart));

        if (AnimationString != "")
        {
            animator.SetBool(UseAnimationPrefix ? caster.IsTaken.AnimationPrefix + AnimationString : AnimationString, true);
        }


        Vector3 targetPos = target.GetVector3Position() + new Vector3(0, 0.5f, 0);
        Vector3 startPos  = AnimationObject.transform.position = caster.GetVector3Position() + new Vector3(0, 0.5f, 0);
        Vector3 moveDir   = (targetPos - AnimationObject.transform.position).normalized;

        AnimationObject.transform.rotation = Quaternion.LookRotation(moveDir) * Quaternion.Euler(ProjectileInitialRotation);


        Rigidbody.velocity = BallisticVel(startPos, targetPos, moveDir, ParabolaAngle);

        AnimationObject.SetActive(true);

        while (AnimationObject.transform.position != targetPos)
        {
            /*AnimationObject.transform.rotation = */
            //AnimationObject.transform.LookAt(targetPos);// * Quaternion.Euler(ProjectileInitialRotation);

            yield return(new WaitForEndOfFrame());
        }

        if (AnimationString != "")
        {
            animator.SetBool(UseAnimationPrefix ? caster.IsTaken.AnimationPrefix + AnimationString : AnimationString, false);
        }

        if (AnimationObject != null)
        {
            AnimationObject.SetActive(false);
        }

        if (ImpactAnimationObject != null)
        {
            ImpactAnimationObject.transform.position = targetPos;
            ImpactAnimationObject.SetActive(true);
            yield return(new WaitForSeconds(ImpactDuration));

            ImpactAnimationObject.SetActive(false);
        }

        if (DoEndAction)
        {
            endAction();
        }
        yield return(null);
    }
    public void changeAnimation()
    {
        StopAllCoroutines();
        if (animationDataObject.name != liveObject.name)
        {
            animationDataObject = liveObject;
        }

        activateAnimation = true;
        animatiting       = false;
    }
Example #18
0
    private void DoHitAndAliveOnGround(DamageInfo damageInfo)
    {
        _animationQueue.Clear();
//        AnimationObject animObj = _animationObjPool.GetZombieHit(damageInfo.DamageType);
        List <object> parameters = new List <object>();

        parameters.Add(damageInfo.DamageType);
        AnimationObject animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieHit, parameters);

        _animationQueue.Add(animObj);
        _animationQueue.PlayNext();
    }
Example #19
0
    public override void Init()
    {
        if ((Rigidbody = AnimationObject.GetComponent <Rigidbody>()) == null)
        {
            Rigidbody = AnimationObject.AddComponent <Rigidbody>();
        }

        if (ImpactObjectReference != null && ImpactAnimationObject == null)
        {
            ImpactAnimationObject = Instantiate(ImpactObjectReference);
            ImpactAnimationObject.SetActive(false);
        }
    }
 // Start is called before the first frame update
 void Start()
 {
     if (animationDataObject != null)
     {
         liveObject        = animationDataObject;
         activateAnimation = true;
         forwatrdAnimation = animationDataObject.animationSprites;
     }
     else
     {
         activateAnimation = false;
         Debug.LogError("Animation data object is missing");
     }
 }
    public override IEnumerator Play(Animator animator, Cell caster, Cell target, System.Action endAction)
    {
        yield return(new WaitForSeconds(DelayBeforeStart));

        if (AnimationString != "")
        {
            animator.SetBool(UseAnimationPrefix ? caster.IsTaken.AnimationPrefix + AnimationString : AnimationString, true);
        }

        Vector3 targetPos = target.GetVector3Position() + new Vector3(0, 0.5f, 0);

        AnimationObject.transform.position = caster.GetVector3Position() + new Vector3(0, 0.5f, 0);
        Vector3 moveDir = (targetPos - AnimationObject.transform.position).normalized;

        AnimationObject.transform.rotation = Quaternion.LookRotation(moveDir) * Quaternion.Euler(ProjectileInitialRotation);

        AnimationObject.SetActive(true);

        while (AnimationObject.transform.position != targetPos)
        {
            AnimationObject.transform.position = Vector3.MoveTowards(AnimationObject.transform.position, targetPos, Time.deltaTime * ProjectileSpeed);
            AnimationObject.transform.Rotate(0, 0, ProjectileRotationSpeed * Time.deltaTime, Space.Self);
            yield return(new WaitForEndOfFrame());
        }

        if (AnimationString != "")
        {
            animator.SetBool(UseAnimationPrefix ? caster.IsTaken.AnimationPrefix + AnimationString : AnimationString, false);
        }

        if (AnimationObject != null)
        {
            AnimationObject.SetActive(false);
        }

        if (ImpactAnimationObject != null)
        {
            ImpactAnimationObject.transform.position = targetPos;
            ImpactAnimationObject.SetActive(true);
            yield return(new WaitForSeconds(ImpactDuration));

            ImpactAnimationObject.SetActive(false);
        }

        if (DoEndAction)
        {
            endAction();
        }
        yield return(null);
    }
Example #22
0
    private void DoGettingUp()
    {
        _lastForceType = ForceType.Unknown;
        _moveState     = ZombieMoveState.Laying;
        OnStateChanged();
//        AnimationObject animObj = _animationObjPool.GetZombieAfterJump(_transform);

        List <object> parameters = new List <object>();

        parameters.Add(_transform);
        AnimationObject animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieAfterJump, parameters);

        _animationQueue.Add(animObj);
        _animationQueue.PlayNext();
    }
Example #23
0
    private void DoDieOnGround(DamageInfo damageInfo)
    {
        _collider.enabled      = false;
        _rigidBody.useGravity  = false;
        _rigidBody.constraints = RigidbodyConstraints.FreezeAll;
        _animationQueue.Clear();
//        AnimationObject animObj = _animationObjPool.GetZombieDeath(damageInfo.DamageType);

        List <object> parameters = new List <object>();

        parameters.Add(damageInfo.DamageType);
        AnimationObject animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieDeath, parameters);

        _animationQueue.Add(animObj);
        _animationQueue.PlayNext();
    }
    public void changeAnimation(AnimationObject newAnnimation)
    {
        if (animationDataObject != newAnnimation)
        {
            StopAllCoroutines();
        }
        animationDataObject = newAnnimation;
        liveObject          = newAnnimation;
        forwatrdAnimation   = newAnnimation.animationSprites;

        StartCoroutine(startAnimation());
        render.sprite = newAnnimation.animationSprites[0];


        activateAnimation = true;
        animatiting       = false;
        Debug.LogWarning("Animation changed");
    }
Example #25
0
    private void DoDieInFly(DamageInfo damageInfo)
    {
        _animationQueue.Clear();
        Vector3  standRotation = new Vector3(0, _transform.rotation.y, _transform.rotation.z);
        Sequence seq           = DOTween.Sequence();

        seq.Append(_transform.DORotate(standRotation, 0.5f));
//        AnimationObject animObj = _animationObjPool.GetZombieFlyDeath(seq, damageInfo.DamageType);

        List <object> parameters = new List <object>();

        parameters.Add(seq);
        parameters.Add(damageInfo.DamageType);
        AnimationObject animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieFlyDeath, parameters);

        _animationQueue.Add(animObj);
        _animationQueue.PlayNext();
    }
Example #26
0
    protected override void DoAnimation(Cell caster, Cell target)
    {
        base.DoAnimation(caster, target);

        if (AnimationObject != null)
        {
            AnimationObject.transform.position = caster.GetVector3Position();

            if (RotateTowardsTarget)
            {
                Vector3 targetPos = target.GetVector3PositionSimple();
                Vector3 moveDir   = (targetPos - AnimationObject.transform.position).normalized;
                AnimationObject.transform.rotation = Quaternion.LookRotation(moveDir);
            }

            AnimationObject.SetActive(true);
        }
    }
Example #27
0
        /// <summary>
        /// 輸入動畫連結即可取得動畫名稱及圖片
        /// 結果會立即反映於UI
        /// </summary>
        /// <param name="name">動畫名稱</param>
        /// <param name="href">動畫連結</param>
        /// <returns></returns>
        private async Task AddAnimation(string href)
        {
            AnimationObject recentWatch = CheckRecentWatch(href);

            if (recentWatch != null)
            {
                Animations.Add(recentWatch);
            }
            else
            {
                var context  = BrowsingContext.New(Configuration.Default.WithDefaultLoader());                    // 產生瀏覽網頁的物件
                var document = await context.OpenAsync(href);                                                     // 異步取得網站內容

                var meta  = document.QuerySelector("*[name='keywords']") as IHtmlMetaElement;                     // 從Meta Tag取得動畫名稱
                var image = document.QuerySelector("div.info_img_box.fl").FirstElementChild as IHtmlImageElement; // 從網站內取得特定id tag裡面的li
                Animations.Add(new AnimationObject(meta.Content, image.Source, href));
            }
        }
Example #28
0
 private static void loadTimelineKeys(List <XmlNode> keys,
                                      TimeLine timeline)
 {
     for (int i = 0; i < keys.Count; i++)
     {
         XmlNode k   = keys[i];
         XmlNode obj = XmlReader.getChildByName(k, "bone");
         Key     key = new Key();
         key.setId(XmlReader.getInt(k, "id"));
         key.setSpin(XmlReader.getInt(k, "spin", 1));
         key.setTime(System.Convert.ToInt64(XmlReader.getInt(k, "time", 0)));
         string name = XmlReader.getAttribute(k.ParentNode, "name");
         timeline.setName(name);
         if (obj != null)
         {
             Bone bone = new Bone();
             bone.setAngle(XmlReader.getFloat(obj, "angle", 0f));
             bone.setX(XmlReader.getFloat(obj, "x", 0f));
             bone.setY(XmlReader.getFloat(obj, "y", 0f));
             bone.setScaleX(XmlReader.getFloat(obj, "scale_x", 1f));
             bone.setScaleY(XmlReader.getFloat(obj, "scale_y", 1f));
             key.setBone(bone);
         }
         else
         {
             AnimationObject @object = new AnimationObject
                                           ();
             obj = XmlReader.getChildByName(k, "object");
             @object.setAngle(XmlReader.getFloat(obj, "angle", 0f));
             @object.setX(XmlReader.getFloat(obj, "x", 0f));
             @object.setY(XmlReader.getFloat(obj, "y", 0f));
             @object.setScaleX(XmlReader.getFloat(obj, "scale_x", 1f));
             @object.setScaleY(XmlReader.getFloat(obj, "scale_y", 1f));
             @object.setFolder(XmlReader.getInt(obj, "folder"));
             @object.setFile(XmlReader.getInt(obj, "file"));
             File f = data.getFolder()[@object.getFolder()].getFile
                          ()[@object.getFile()];
             @object.setPivotX(XmlReader.getFloat(obj, "pivot_x", f.getPivotX()));
             @object.setPivotY(XmlReader.getFloat(obj, "pivot_y", f.getPivotY()));
             key.getObject().Add(@object);
         }
         timeline.getKey().Add(key);
     }
 }
        protected override void PlayButtonAni(bool isDown)
        {
            base.PlayButtonAni(isDown);

            AnimationObject.DOComplete();

            if (isDown)
            {
                switch (animationType)
                {
                case AnimationType.NonTween:
                    AnimationObject.DOScale(pressingScale, 0.0f);
                    break;

                case AnimationType.Tween:
                    AnimationObject.DOScale(pressingScale, 0.2f);
                    break;

                case AnimationType.Jelly:
                    AnimationObject.DOScale(pressingScale, 0.2f);
                    break;
                }
            }
            else
            {
                switch (animationType)
                {
                case AnimationType.NonTween:
                    AnimationObject.DOScale(1f, 0.0f);
                    break;

                case AnimationType.Tween:
                    AnimationObject.DOScale(1f, 0.2f);
                    break;

                case AnimationType.Jelly:
                    AnimationObject.localScale = Vector3.one;
                    AnimationObject.DOPunchScale(new Vector3(0.2f, 0.2f, 0.2f), 0.4f, 10, 5);
                    break;
                }
            }
        }
Example #30
0
    private void DoRotating()
    {
        _view.ShowShadow(_model.IsBoss, true);
//        AnimationObject animObj = _animationObjPool.GetZombieRotateToTarget(_transform, _target, () =>
//            {
//                OnAnimationFinished(ZombieAnimation.RotateToTarget.ToString());
//            });

        List <object> parameters = new List <object>();

        parameters.Add(_transform);
        parameters.Add(_target);
        AnimationObject animObj = _animationObjPool.GetZombieAnimation(AnimationObjectType.ZombieRotateToTarget, parameters, () =>
        {
            OnAnimationFinished(ZombieAnimation.RotateToTarget.ToString());
        });

        _animationQueue.Add(animObj);
        _animationQueue.PlayNext();
    }
        /// <summary>
        /// 更新近期觀看的動畫至Json檔
        /// </summary>
        /// <param name="animationObject">欲更新的動畫</param>
        public static void UpdateRecentWatch(AnimationObject animationObject)
        {
            // 檢索速度最快, 使用的HashSet必須自定義Comparer
            var recentWatch = ReadFromFile <HashSet <AnimationObject> >(RecentWatchPath);
            HashSet <AnimationObject> animationList;

            if (recentWatch == null)
            {
                animationList = new HashSet <AnimationObject>(new AnimationObjectComparer());
            }
            else
            {
                animationList = recentWatch.ToHashSet(new AnimationObjectComparer());
                if (animationList.Contains(animationObject))
                {
                    animationList.Remove(animationObject);                                          // 若資料已存在HashSet, 先刪除
                }
            }
            animationList.Add(animationObject);          // 添加資料進去HashSet
            WriteToFile(animationList, RecentWatchPath); // 儲存
        }
        // Create object in room upon user click
        private void MakeSpaceObject(string texName, Image tex, DrawPoint mp)
        {
            texName = texName.Replace(".png", "");

            string[] lastname_ary= (string[])texName.Split('\\');
            string lastname = lastname_ary[lastname_ary.Length-1];

            string texStripName = texName.Replace(lastname,"strips\\"+lastname) + "_strip";

            //int numberOfFrames = SpaceObject.GetNumberOfFrames(texName);

            Vector2 screenposition = Conversion.DrawPointToVector2(mp);
            Vector2 gameposition = new Vector2(screenposition.X / CASSWorld.SCALE, screenposition.Y / CASSWorld.SCALE);

            if (rb_AnimationObjects.Checked)
            {
                AnimationObject ao;
                // TODO : i'm not a fan of these ifs, since the only thing that's changing are those last two numbers
                //        having to do with the animation. is there a way they could be passed in, or even better,
                //        derived from the strip image?
                if (lastname == "fan")
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 7);
                else if (lastname == "broken_platform")
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8);
                else if (lastname == "light" || lastname == "fire")
                {
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8,false, false);
                    //ao.RemoveFromWorld();
                    //world.World.DestroyBody(ao.Body);
                }
                else if (lastname == "rollingpin")
                {
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8, true, true);
                }
                else
                {
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8);
                }
                ao.Position = gameposition;
                world.AddObject(ao);
            }
            else if (rb_BoxObjects.Checked)
            {
                BoxObject bo;
                bo = new BoxObject(world.World, texName, 0, .5f, 0, 1, false);
                bo.Position = gameposition;
                world.AddObject(bo);
            }
            else if (rb_CircleObjects.Checked)
            {
                CircleObject co;
                co = new CircleObject(world.World, texName, 1, .5f, 0, 1);
                co.Position = gameposition;
                world.AddObject(co);
            }
            else if (rb_WinDoorObject.Checked)
            {
                WinDoorObject so;
                // HACK - hard-coded for the win-door
                so = new WinDoorObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 5);
                so.Position = gameposition;
                world.AddObject(so);
            }
            else if (rb_PistonObject.Checked)
            {
                PistonObject po;
                Console.WriteLine("{0}", gameposition);
                po = new PistonObject(world.World, .5f, .5f, 12f, 13f, 9.7f, 12.6f, .01f, .1f, gameposition);
                po.Position = gameposition;
                world.AddObject(po);
            }
            else if(rb_SeeSawObject.Checked)
            {
                SeeSawObject ss;
                ss = new SeeSawObject(world.World, texName, 1.5f, gameposition);
                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_SwitchObject.Checked)
            {
                SwitchObject ss1;
             //       ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip","Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
             //       ss1.Position = gameposition;
              //  world.AddObject(ss1);

                if (lastname == "button")
                {
                    ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);

                    ss1.Position = gameposition;
                    world.AddObject(ss1);
                }
                else if (lastname == "death")
                {

                    DeathPlatform ss2;
                    ss2 = new DeathPlatform(world.World, "Art\\Objects\\SwitchObjects\\button_death_strip", "Art\\Objects\\SwitchObjects\\death", 181, 84, 20, 2);

                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss2.Position = gameposition;
                    world.AddObject(ss2);
                }
                else
                {
                    FailButtonObject ss2;
                    ss2 = new FailButtonObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\fail_button", 181, 84, 20, 2);

                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss2.Position = gameposition;
                    world.AddObject(ss2);
                }

            }
            else if (rb_HoleObject.Checked)
            {
                HoleObject ss;
                ss = new HoleObject(world.World, "Art\\Objects\\HoleObjects\\hole_strip", "Art\\Objects\\HoleObjects\\hole");
                //hole1 = new HoleObject(World, "Art\\Objects\\HoleObjects\\hole_strip", "Art\\Objects\\HoleObjects\\hole");
                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_MovingPlatform.Checked)
            {
                MovingObject ss;
              //  ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\moving_platform", 1000, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
               // movPlatform1 = new MovingObject(World, "moving platform", 1000f, .5f, 0, 1, false, brokenMovingPlatform1, new Vector2(0, -11500), 4.5f, 14.2f);
               // ss.Position = gameposition;
              //  world.AddObject(ss);

                if (lastname == "moving_platform")
                    ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\moving_platform", 0, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
                else if (lastname == "gate")
                {
                    SwitchObject ssfine;
                    ssfine = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                    ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\gate", 0, 0.5f, 0, 1, false, ssfine, new Vector2(0, -11500), 4.5f, 14.2f);
                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ssfine.Position = gameposition;
                    world.AddObject(ssfine);
                }
                else
                {

                    SwitchObject ss1;
                    ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                    ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\switchmoving_platform", 0, 0.5f, 0, 1, false, ss1, new Vector2(0, -11500), 4.5f, 14.2f);
                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss1.Position = gameposition;
                    world.AddObject(ss1);
                }

                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_HorizontalMovingPlatform.Checked)
            {
                HorizontalMovingObject ss;
              //  ss = new HorizontalMovingObject(world.World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
               // movPlatform2 = new HorizontalMovingObject(World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0f, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 32f, 38f);

                if (lastname == "moving_platform")
                    ss = new HorizontalMovingObject(world.World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
                else
                {

                    SwitchObject ss1;
                    ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                    ss = new HorizontalMovingObject(world.World, "Art\\Objects\\HorizontalMovingPlatformObjects\\switchmoving_platform", 0, 0.5f, 0, 1, false, ss1, new Vector2(0, -11500), 4.5f, 14.2f);
                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss1.Position = gameposition;
                    world.AddObject(ss1);
                }

                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_PaintedObjects.Checked)
            {
                switch (lastname)
                {
                    case "block_long":
                        InstasteelObject io;
                        io = new InstasteelObject(world.World, texName, 580, 1, .5f, 0, 1, false);
                        io.Position = gameposition;
                        world.AddObject(io);
                        break;
                    case "disk_long":
                        InstasteelCircleObject ico;
                        ico = new InstasteelCircleObject(world.World, texName, 480, 1, .5f, 0, 1);
                        ico.Position = gameposition;
                        world.AddObject(ico);
                        break;
                    case "line_long":
                        InstasteelObject ilo;
                        ilo = new InstasteelObject(world.World, texName, 190, 1, .5f, 0, 1, false);
                        ilo.Position = gameposition;
                        world.AddObject(ilo);
                        break;
                    default:
                        break;
                }
            }
                /*
            else if (rb_PaintedObjects.Checked)
            {
                PaintedObject po;
                List<Vector2> blobs = new List<Vector2>();
                float radius;
                float sidelength;
                Vector2 centeroff;
                switch (lastname)
                {
                    case "line_short":
                        float linelength_short = (30f/60f) * 1.2f;
                        blobs.Add(gameposition + new Vector2(linelength_short/2f, 0f));
                        blobs.Add(gameposition + new Vector2(-linelength_short/2f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                    case "line":
                        float linelength = 1.2f;
                        blobs.Add(gameposition + new Vector2(linelength/2, 0f));
                        blobs.Add(gameposition + new Vector2(-linelength/2f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                    case "line_long":
                        float linelength_long = (200f/60f) * 1.2f;
                        blobs.Add(gameposition + new Vector2(linelength_long/2f, 0f));
                        blobs.Add(gameposition + new Vector2(-linelength_long/2f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk_short":
                        radius =  (30f/60f) *0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk_small":
                        radius =  (40f/60f) *0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk":
                        radius =  0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk_long":
                        radius =  (150f/60f) * 0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "block_short":
                        sidelength =  (30f/60f) *0.6f;
                        blobs = paintedSquare((30f/60f) * 1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    case "block_small":
                        sidelength =  (40f/60f) *0.6f;
                        blobs = paintedSquare((40f/60f) * 1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    case "block":
                        sidelength =  0.6f;
                        blobs = paintedSquare(1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    case "block_long":
                        sidelength =  (150f/60f) * 0.6f;
                        blobs = paintedSquare((150f/60f) * 1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    default:
                        blobs.Add(gameposition + new Vector2(0.6f, 0f));
                        blobs.Add(gameposition + new Vector2(-0.6f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                }
                po = new PaintedObject(world.World, "paint", "paintedsegment", blobs);
                po.TextureFilename = "Art\\Objects\\PaintedObjects\\" + lastname;
                po.Position = gameposition + centeroff;
                world.AddObject(po);
            }
            */
            else if (rb_BackgroundObjects.Checked)
            {
                BackgroundObject bo;
                bo = new BackgroundObject(world.World, world, texName,gameposition);
                bo.Position = gameposition;
                world.AddObject(bo);

            }

                /*
            else if (rb_Player.Checked)
            {
                mp.X -= (int)((texture.Width * Constants.PLAYER_SCALE) / 2);
                mp.Y -= (int)((texture.Height * Constants.PLAYER_SCALE) / 2);

                world.player = new Player(
                    Conversion.DrawPointToVector2(mp),
                    currdir + "\\" + texName + ".tri"
                    );

                world.CurrentRoom = currentlySelectedRoom;
                world.player.TextureName = texName;
            }
            */
        }
Example #33
0
 // Use this for initialization
 void Start()
 {
     animScript = gameObject.GetComponent<AnimationObject>();
     animScript.Animation_Complete += OnAnimationComplete;
 }
        public void TestSetCurrentTime()
        {
            var p_o1 = new AnimationObject();
            var p_o2 = new AnimationObject();
            var p_o3 = new AnimationObject();
            var t_o1 = new AnimationObject();
            var t_o2 = new AnimationObject();

            // parallel operating on different object/properties
            QAnimationGroup parallel = new QParallelAnimationGroup();
            var a1_p_o1 = new QPropertyAnimation(p_o1, new QByteArray("value"));
            var a1_p_o2 = new QPropertyAnimation(p_o2, new QByteArray("value"));
            var a1_p_o3 = new QPropertyAnimation(p_o3, new QByteArray("value"));
            a1_p_o2.LoopCount = 3;
            parallel.AddAnimation(a1_p_o1);
            parallel.AddAnimation(a1_p_o2);
            parallel.AddAnimation(a1_p_o3);

            var notTimeDriven = new UncontrolledAnimation(t_o1, new QByteArray("value"));
            Assert.AreEqual(-1, notTimeDriven.TotalDuration);

            QVariantAnimation loopsForever = new QPropertyAnimation(t_o2, new QByteArray("value"));
            loopsForever.LoopCount = -1;
            Assert.AreEqual(-1, loopsForever.TotalDuration);

            var group = new QParallelAnimationGroup();
            group.AddAnimation(parallel);
            group.AddAnimation(notTimeDriven);
            group.AddAnimation(loopsForever);

            // Current time = 1
            group.CurrentTime = 1;
            Assert.AreEqual(QAnimationGroup.State.Stopped, group.state);
            Assert.AreEqual(QAnimationGroup.State.Stopped, parallel.state);
            Assert.AreEqual(QAnimationGroup.State.Stopped, a1_p_o1.state);
            Assert.AreEqual(QAnimationGroup.State.Stopped, a1_p_o2.state);
            Assert.AreEqual(QAnimationGroup.State.Stopped, a1_p_o3.state);
            Assert.AreEqual(QAnimationGroup.State.Stopped, notTimeDriven.state);
            Assert.AreEqual(QAnimationGroup.State.Stopped, loopsForever.state);

            Assert.AreEqual(1, group.CurrentLoopTime);
            Assert.AreEqual(1, a1_p_o1.CurrentLoopTime);
            Assert.AreEqual(1, a1_p_o2.CurrentLoopTime);
            Assert.AreEqual(1, a1_p_o3.CurrentLoopTime);
            Assert.AreEqual(1, notTimeDriven.CurrentLoopTime);
            Assert.AreEqual(1, loopsForever.CurrentLoopTime);

            // Current time = 250
            group.CurrentTime = 250;
            Assert.AreEqual(250, group.CurrentLoopTime);
            Assert.AreEqual(250, a1_p_o1.CurrentLoopTime);
            Assert.AreEqual(0, a1_p_o2.CurrentLoopTime);
            Assert.AreEqual(1, a1_p_o2.CurrentLoop);
            Assert.AreEqual(250, a1_p_o3.CurrentLoopTime);
            Assert.AreEqual(250, notTimeDriven.CurrentLoopTime);
            Assert.AreEqual(0, loopsForever.CurrentLoopTime);
            Assert.AreEqual(1, loopsForever.CurrentLoop);

            // Current time = 251
            group.CurrentTime = 251;
            Assert.AreEqual(251, group.CurrentLoopTime);

            Assert.AreEqual(250, a1_p_o1.CurrentLoopTime);
            Assert.AreEqual(1, a1_p_o2.CurrentLoopTime);
            Assert.AreEqual(1, a1_p_o2.CurrentLoop);

            Assert.AreEqual(250, a1_p_o3.CurrentLoopTime);

            Assert.AreEqual(251, notTimeDriven.CurrentLoopTime);
            Assert.AreEqual(1, loopsForever.CurrentLoopTime);
        }