Beispiel #1
0
        // ----------------------
        public TouchSteeringWheelSpriteAnimator() : base(typeof(TouchSteeringWheel))
        {
            this.rotationRange         = 45;
            this.rotationSmoothingTime = 0.05f;

            this.spritePressed = new SpriteConfig(true, false, 1.2f);
        }
Beispiel #2
0
        // ----------------------
        override protected void OnUpdateAnimator(bool skipAnim)
        {
            TouchTrackPad trackPad = (TouchTrackPad)this.sourceControl;

            if ((trackPad == null) || (this.image == null))
            {
                return;
            }


            SpriteConfig sprite = null;

            if (trackPad.Pressed() && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spritePressed;
            }

            if (((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutral;
            }



            this.BeginSpriteAnim(sprite, skipAnim);

            this.UpdateSpriteAnimation(skipAnim);
        }
 // ------------------
 void ISpriteAnimator.OnSpriteOptimization(ISpriteOptimizer optimizer)
 {
     for (ControlState i = ControlStateFirst; i < ControlStateCount; ++i)
     {
         SpriteConfig spr = this.GetStateSpriteConfig(i);
         spr.sprite = optimizer.GetOptimizedSprite(spr.sprite);
     }
 }
 public static void AddSprite(string path, SpriteConfig config)
 {
     path = Util.GetFullPath(path);
     if (!SpriteMap.ContainsKey(path))
     {
         SpriteMap.Add(path, config);
     }
 }
Beispiel #5
0
        private byte[] GetSpritesFromSpec(string spec)
        {
            var bytes = new List <byte>();

            bytes.AddRange(Enumerable.Repeat((byte)0, 16));
            var spriteConfig = SpriteConfig.Read(spec, Palettes.Read(this.palettesTextBox.Text));

            for (var i = 1; i < 256; i++)
            {
                var sprite = spriteConfig.Sprites.FirstOrDefault(s => s.Id == i);
                if (sprite != null)
                {
                    var lowBits  = new List <byte>();
                    var highBits = new List <byte>();
                    var image    = sprite.GetSprite();

                    for (var y = 0; y < Constants.SpriteHeight; y++)
                    {
                        byte lowBit  = 0;
                        byte highBit = 0;

                        for (var x = 0; x < Constants.SpriteWidth; x++)
                        {
                            lowBit  = (byte)(lowBit << 1);
                            highBit = (byte)(highBit << 1);

                            var pixel = spriteConfig.PaletteMappings[sprite.Mapping].ColorMappings.First(c => c.Color == image.GetPixel(x, y)).To;

                            if (pixel == 1 || pixel == 3)
                            {
                                // low bit set
                                lowBit |= 1;
                            }

                            if (pixel == 2 || pixel == 3)
                            {
                                // high bit set
                                highBit |= 1;
                            }
                        }

                        lowBits.Add(lowBit);
                        highBits.Add(highBit);
                    }

                    bytes.AddRange(lowBits);
                    bytes.AddRange(highBits);
                }
                else
                {
                    bytes.AddRange(Enumerable.Repeat((byte)0, 16));
                }
            }

            return(bytes.ToArray());
        }
Beispiel #6
0
        // ----------------------
        public TouchButtonSpriteAnimator() : base(typeof(TouchButton))
        {
            this.spritePressed           = new SpriteConfig(true, false, 1.2f);
            this.spriteToggled           = new SpriteConfig(false, false, 1.1f);
            this.spriteToggledAndPressed = new SpriteConfig(false, false, 1.3f);

            this.spritePressed.scale           = 1.25f;
            this.spriteToggled.scale           = 1.1f;
            this.spriteToggledAndPressed.scale = 1.3f;
        }
Beispiel #7
0
        // ------------------
        public void SetStateSprite(ControlState state, Sprite sprite)
        {
            SpriteConfig c = this.GetStateSpriteConfig(state);

            if (c == null)
            {
                this.SetSprite(sprite);
            }
            else
            {
                c.sprite = sprite;
            }
        }
Beispiel #8
0
        // ------------------
        public void SetStateColor(ControlState state, Color color)
        {
            SpriteConfig c = this.GetStateSpriteConfig(state);

            if (c == null)
            {
                this.SetColor(color);
            }
            else
            {
                c.color = color;
            }
        }
Beispiel #9
0
        private void LoadFiles()
        {
            this.palettes = Palettes.Read(palettesTextBox.Text);
            this.config   = SpriteConfig.Read(specTextBox.Text, this.palettes);

            this.framesListBox.Items.Clear();
            this.animationListBox.Items.Clear();
            foreach (var animation in config.Animations)
            {
                this.animationListBox.Items.Add(animation);
            }

            this.animationListBox.SelectedIndex = 0;
        }
        //
        // Enemy
        //

        public bool TryGetEnemy(SpriteConfig enConfig, out Enemy enemy)
        {
            // Set out value to null.
            enemy = null;

            // Create initialized instance.
            var name      = (string)this.enemyComboBox.SelectedItem;
            var animation = enConfig.Animations.First(a => a.Name == name);
            var newEnemy  = Enemy.CreateInitialized(animation);

            // Set values that cannot fail.
            newEnemy.MovementType    = this.MovementType;
            newEnemy.Direction       = this.Direction;
            newEnemy.SpecialMovement = this.SpecialMovement;
            newEnemy.InitialFlip     = this.InitialFlip;
            newEnemy.ShouldFlip      = this.ShouldFlip;
            newEnemy.Speed           = this.GetSpeed();

            // Get values that can fail.
            BlinkingType blinkingType;
            int          x, y, min, max, shootingFreq, shootingInitialFreq, blinkingFreq, blinkingInitialFreq;

            if (!this.TryGetX(out x) ||
                !this.TryGetY(out y) ||
                !this.TryGetMin(out min) ||
                !this.TryGetMax(out max) ||
                !this.TryGetShootingFreq(out shootingFreq) ||
                !this.TryGetShootingInitialFreq(out shootingInitialFreq) ||
                !this.TryGetBlinkingType(out blinkingType) ||
                !this.TryGetBlinkingFreq(out blinkingFreq) ||
                !this.TryGetBlinkingInitialFreq(out blinkingInitialFreq))
            {
                return(false);
            }

            // Set values that can fail.
            newEnemy.X                        = x;
            newEnemy.Y                        = y;
            newEnemy.MinPosition              = min;
            newEnemy.MaxPosition              = max;
            newEnemy.ShootingFrequency        = shootingFreq;
            newEnemy.ShootingInitialFrequency = shootingInitialFreq;
            newEnemy.BlinkingType             = blinkingType;
            newEnemy.BlinkingFrequency        = blinkingFreq;
            newEnemy.BlinkingInitialFrequency = blinkingInitialFreq;

            // Set output value.
            enemy = newEnemy;
            return(true);
        }
    private void OnLoadHandler()
    {
        if (File.Exists(_savePath))                                                               // Don't try to load a file that isn't there
        {
            string loadedJson = File.ReadAllText(_savePath);                                      // read existing file

            SpriteConfig loadedConfig = JsonConvert.DeserializeObject <SpriteConfig>(loadedJson); // string back to sprite config object
                                                                                                  //charState[HAT] = charSaved[HAT];
            Debug.Log("loadedConfig sprite name = " + loadedConfig.names[loadedConfig.index]);
            _config.names = loadedConfig.names;
            _config.index = loadedConfig.index;
            ChangeSprite();
        }
    }
    private void Awake()
    {
        // keep a reference to the sprite renderer on this gameobject
        _savePath = Path.Combine(Application.persistentDataPath, "swappy_sprite_config.json");
        _renderer = gameObject.GetComponent <SpriteRenderer>();

        // Use var as the type so we don't have to type "List<string>" twice.
        // This is like the c++ "auto" keyword
        var names = new List <string>()
        {
            "spr_zelda", "spr_link", "spr_zelda_roar", "spr_link_hide"
        };

        _config = new SpriteConfig(names, 2);
        ChangeSprite();
    }
Beispiel #13
0
        private void LoadFiles()
        {
            this.palettes = Palettes.Read(palettesTextBox.Text);
            this.config   = SpriteConfig.Read(specTextBox.Text, this.palettes);
            CreateCachedBitmaps();

            this.bulletsListBox.Items.Clear();
            foreach (var bullet in config.Bullets)
            {
                this.bulletsListBox.Items.Add(bullet);
            }

            this.bulletsListBox.SelectedIndex = 0;

            ValidateBullets();
        }
 // ----------------------
 public SuperTouchZoneSpriteAnimator() : base(typeof(ControlFreak2.SuperTouchZone))
 {
     this.spriteRawPress      = new SpriteConfig(true, false, 1.2f);
     this.spriteNormalPress   = new SpriteConfig(false, false, 1.2f);
     this.spriteLongPress     = new SpriteConfig(false, false, 1.2f);
     this.spriteTap           = new SpriteConfig(false, true, 1.2f);
     this.spriteDoubleTap     = new SpriteConfig(false, true, 1.2f);
     this.spriteLongTap       = new SpriteConfig(false, true, 1.2f);
     this.spriteNormalScrollU = new SpriteConfig(false, true, 1.2f);
     this.spriteNormalScrollR = new SpriteConfig(false, true, 1.2f);
     this.spriteNormalScrollD = new SpriteConfig(false, true, 1.2f);
     this.spriteNormalScrollL = new SpriteConfig(false, true, 1.2f);
     this.spriteLongScrollU   = new SpriteConfig(false, true, 1.2f);
     this.spriteLongScrollR   = new SpriteConfig(false, true, 1.2f);
     this.spriteLongScrollD   = new SpriteConfig(false, true, 1.2f);
     this.spriteLongScrollL   = new SpriteConfig(false, true, 1.2f);
 }
        // -------------------
        public TouchJoystickSpriteAnimator() : base(typeof(TouchJoystick))
        {
            this.animateTransl = false;
            this.moveScale     = new Vector2(0.5f, 0.5f);

            this.rotationMode          = RotationMode.Disabled;
            this.rotationSmoothingTime = 0.01f;
            this.simpleRotationRange   = 45.0f;
            this.lastSafeCompassAngle  = 0;

            this.spriteNeutralPressed = new SpriteConfig(true, false, 1.2f);
            this.spriteUp             = new SpriteConfig(false, false, 1.2f);
            this.spriteUpRight        = new SpriteConfig(false, false, 1.2f);
            this.spriteRight          = new SpriteConfig(false, false, 1.2f);
            this.spriteDownRight      = new SpriteConfig(false, false, 1.2f);
            this.spriteDown           = new SpriteConfig(false, false, 1.2f);
            this.spriteDownLeft       = new SpriteConfig(false, false, 1.2f);
            this.spriteLeft           = new SpriteConfig(false, false, 1.2f);
            this.spriteUpLeft         = new SpriteConfig(false, false, 1.2f);
        }
Beispiel #16
0
    private void UpdatePortraits()
    {
        SpriteConfig config = (SpriteConfig)target;

        string[] folders = new string[1] {
            "Assets/Sprites/Portraits"
        };
        string filterString = "t:Sprite";

        config.ClearPortraits();

        string[] assets = AssetDatabase.FindAssets(filterString, folders);
        for (int i = 0; i < assets.Length; i++)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(assets[i]);
            Sprite sprite    = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
            config.AddPortrait(sprite);
        }

        config.SetDirty();
    }
Beispiel #17
0
    private void UpdateBackgorunds()
    {
        SpriteConfig config = (SpriteConfig)target;

        string[] findPath = new string[1] {
            "Assets/Sprites/Back"
        };
        string filterString = "t:Sprite";

        config.ClearBackgrounds();

        string[] assets = AssetDatabase.FindAssets(filterString, findPath);
        for (int i = 0; i < assets.Length; i++)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(assets[i]);
            Sprite sprite    = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
            config.AddBackground(sprite);
        }

        config.SetDirty();
    }
Beispiel #18
0
        public static void Run()
        {
            /* Create BitcodinApi */
            const string apiKey = "YOUR_API_KEY";
            var          bitApi = new BitcodinApi(apiKey);

            var spriteConfig = new SpriteConfig
            {
                //insert your jobID
                JobId    = 312840,
                Height   = 90,
                Width    = 120,
                Distance = 10,
                Async    = true
            };

            var sprite = bitApi.CreateSprite(spriteConfig);

            Debug.WriteLine("Thumbnail URL: " + sprite.SpriteUrl);
            Debug.WriteLine("Thumbnail VTT URL: " + sprite.VttUrl);
        }
Beispiel #19
0
        // ----------------------
        override protected void OnUpdateAnimator(bool skipAnim)
        {
            TouchButton button = (TouchButton)this.sourceControl;

            if ((button == null) || (this.image == null))
            {
                return;
            }


            bool pressed = button.Pressed();
            bool toggled = button.Toggled();

            SpriteConfig sprite = null;

            if ((pressed && toggled) && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteToggledAndPressed;
            }

            if (toggled && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteToggled;
            }

            if (pressed && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spritePressed;
            }

            if (((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutral;
            }


            this.BeginSpriteAnim((sprite == null) ? this.spriteNeutral : sprite, false);

            this.UpdateSpriteAnimation(skipAnim);
        }
Beispiel #20
0
        // ----------------------
        override protected void OnUpdateAnimator(bool skipAnim)
        {
            if ((this.sourceControl == null) || (this.image == null))
            {
                return;
            }

            TouchSteeringWheel wheel = (TouchSteeringWheel)this.sourceControl;


            SpriteConfig sprite = null;

            if (wheel.Pressed() && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spritePressed;
            }

            if (((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutral;
            }



            if (!CFUtils.editorStopped && !this.IsIllegallyAttachedToSource())
            {
                this.extraRotation = CFUtils.SmoothTowardsAngle(this.extraRotation, -(wheel.GetValue() *
                                                                                      ((wheel.wheelMode == TouchSteeringWheel.WheelMode.Swipe) ? this.rotationRange : wheel.maxTurnAngle)),
                                                                this.rotationSmoothingTime, CFUtils.realDeltaTimeClamped, 0.001f);
            }
            else
            {
                this.extraRotation = 0;
            }


            this.BeginSpriteAnim(sprite, skipAnim);

            this.UpdateSpriteAnimation(skipAnim);
        }
Beispiel #21
0
 public Sprite CreateSprite(SpriteConfig config)
 {
     return(Post <Sprite>("sprite", config));
 }
Beispiel #22
0
 protected SpriteBase(ISpriteSheet spriteSheet, SpriteConfig config)
 {
     this.SpriteSheet = spriteSheet;
     this.config      = config;
 }
        // ---------------
        public void Draw(SpriteConfig target, Object undoObject, bool skipTransforms, bool canBeDisabled = true)
        {
            bool
                enabled = target.enabled;
            Color
                color = target.color;
            Sprite
                sprite = target.sprite;
            float
                rotation = target.rotation,
                scale    = target.scale;
            Vector2
                offset = target.offset;
            bool
                resetOffset   = target.resetOffset,
                resetScale    = target.resetScale,
                resetRotation = target.resetRotation;

            float
                baseTransitionTime       = target.baseTransitionTime,
                colorTransitionFactor    = target.colorTransitionFactor,
                offsetTransitionFactor   = target.offsetTransitionFactor,
                rotationTransitionFactor = target.rotationTransitionFactor,
                scaleTransitionFactor    = target.scaleTransitionFactor,
                duration = target.duration;


            if (!canBeDisabled)
            {
                enabled = true;
            }

            Color initialGuiColor = GUI.color;


            EditorGUILayout.BeginVertical(CFEditorStyles.Inst.transpBevelBG);

            EditorGUILayout.BeginVertical();


            GUI.enabled = canBeDisabled;
            enabled     = EditorGUILayout.ToggleLeft(labelContent, enabled, CFEditorStyles.Inst.boldText, GUILayout.MinWidth(30), GUILayout.ExpandWidth(true));
            GUI.enabled = true;


            if (enabled)
            {
#if UNITY_PRE_5_2
                color  = EditorGUILayout.ColorField(color, GUILayout.ExpandWidth(true));
                sprite = (Sprite)EditorGUILayout.ObjectField(sprite, typeof(Sprite), false);
#else
                EditorGUILayout.BeginHorizontal();
                color  = EditorGUILayout.ColorField(color, GUILayout.ExpandWidth(true));
                sprite = (Sprite)EditorGUILayout.ObjectField(sprite, typeof(Sprite), false, GUILayout.Width(64), GUILayout.Height(64));
                EditorGUILayout.EndHorizontal();
#endif
            }



//			EditorGUILayout.BeginHorizontal();
//				//GUILayout.Label(labelContent, CFEditorStyles.Inst.boldText, GUILayout.MinWidth(30), GUILayout.ExpandWidth(true));

//				if (enabled)
//					color = EditorGUILayout.ColorField(color,  GUILayout.ExpandWidth(true));

//			if (enabled)
//				{
//#if UNITY_PRE_5_2
//				sprite = (Sprite)EditorGUILayout.ObjectField(sprite, typeof(Sprite), false);
//#else
//				sprite = (Sprite)EditorGUILayout.ObjectField(sprite, typeof(Sprite), false, GUILayout.Width(64), GUILayout.Height(64));
//#endif
//				}
//			EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            if (enabled)
            {
                if (target.oneShotState)
                {
                    duration = CFGUI.FloatFieldEx(new GUIContent("Duration", "Duration if this one-shot state in milliseconds."),
                                                  duration, 0, 100, 1000, true, 120);
                }

                baseTransitionTime = CFGUI.FloatFieldEx(new GUIContent("Base transition time", "Base transition time in milliseconds to all transtions below..."),
                                                        baseTransitionTime, 0, 100, 1000, true, 120);

                colorTransitionFactor = CFGUI.Slider(new GUIContent("Color Transition", "Color Transition as a fraction on the Base Transition Time."),
                                                     colorTransitionFactor, 0, 1, 120);
                offsetTransitionFactor = CFGUI.Slider(new GUIContent("Offset Transition", "Offset Transition as a fraction on the Base Transition Time."),
                                                      offsetTransitionFactor, 0, 1, 120);
                rotationTransitionFactor = CFGUI.Slider(new GUIContent("Rotation Transition", "Rotation Transition as a fraction on the Base Transition Time."),
                                                        rotationTransitionFactor, 0, 1, 120);
                scaleTransitionFactor = CFGUI.Slider(new GUIContent("Scale Transition", "Scale Transition as a fraction on the Base Transition Time."),
                                                     scaleTransitionFactor, 0, 1, 120);


                if (!skipTransforms)
                {
                    EditorGUILayout.Space();

                    resetScale = EditorGUILayout.ToggleLeft(new GUIContent("Reset Scale", "Reset scale on start."),
                                                            resetScale, GUILayout.ExpandWidth(true), GUILayout.MinWidth(30));
                    scale = CFGUI.FloatField(new GUIContent("Scale", "State specific scale"),
                                             scale, 0, 100, 80);

                    EditorGUILayout.Space();

                    resetRotation = EditorGUILayout.ToggleLeft(new GUIContent("Reset Rotation", "Reset rotation on start."),
                                                               resetRotation, GUILayout.ExpandWidth(true), GUILayout.MinWidth(30));
                    rotation = CFGUI.FloatField(new GUIContent("Rotation", "State specific rotation"),
                                                rotation, -10000, 10000, 80);
                    EditorGUILayout.Space();

                    resetOffset = EditorGUILayout.ToggleLeft(new GUIContent("Reset Offset", "Reset Offset on start."),
                                                             resetOffset, GUILayout.ExpandWidth(true), GUILayout.MinWidth(30));

                    offset.x = CFGUI.FloatField(new GUIContent("Offset X", "State specific offset X"),
                                                offset.x, -1000000, 100000, 80);
                    offset.y = CFGUI.FloatField(new GUIContent("Offset Y", "State specific offset X"),
                                                offset.y, -1000000, 100000, 80);
                }
            }


            EditorGUILayout.EndVertical();



            GUI.color = initialGuiColor;


            // Record undo...

            if ((enabled != target.enabled) ||
                (color != target.color) ||
                (rotation != target.rotation) ||
                (scale != target.scale) ||
                (offset != target.offset) ||
                (sprite != target.sprite) ||
                (resetOffset != target.resetOffset) ||
                (resetScale != target.resetScale) ||
                (resetRotation != target.resetRotation) ||
                (baseTransitionTime != target.baseTransitionTime) ||
                (colorTransitionFactor != target.colorTransitionFactor) ||
                (offsetTransitionFactor != target.offsetTransitionFactor) ||
                (rotationTransitionFactor != target.rotationTransitionFactor) ||
                (scaleTransitionFactor != target.scaleTransitionFactor) ||
                (duration != target.duration))
            {
                CFGUI.CreateUndo("Modify sprite config for " + undoObject.name, undoObject);

                target.enabled  = enabled;
                target.color    = color;
                target.sprite   = sprite;
                target.scale    = scale;
                target.rotation = rotation;
                target.offset   = offset;

                target.resetOffset   = resetOffset;
                target.resetScale    = resetScale;
                target.resetRotation = resetRotation;


                target.baseTransitionTime       = baseTransitionTime;
                target.colorTransitionFactor    = colorTransitionFactor;
                target.offsetTransitionFactor   = offsetTransitionFactor;
                target.rotationTransitionFactor = rotationTransitionFactor;
                target.scaleTransitionFactor    = scaleTransitionFactor;
                target.duration = duration;


                CFGUI.EndUndo(undoObject);
            }
        }
Beispiel #24
0
 public DefaultAnimatedSprite(ISpriteSheet spriteSheet, SpriteConfig config)
     : base(spriteSheet, config)
 {
 }
Beispiel #25
0
 // ----------------------
 public TouchTrackPadSpriteAnimator() : base(typeof(TouchTrackPad))
 {
     this.spritePressed = new SpriteConfig(true, false, 1.2f);
 }
        // ----------------------
        override protected void OnUpdateAnimator(bool skipAnim)
        {
            ControlFreak2.SuperTouchZone zone = (ControlFreak2.SuperTouchZone) this.sourceControl;

            if ((zone == null) || (this.image == null))
            {
                return;
            }

            Vector2 scrollDelta = zone.GetScrollDelta(1);

            SpriteConfig sprite = null;

            if ((zone.JustTapped(1, 2) || zone.JustTapped(2, 2) || zone.JustTapped(3, 2)) && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteDoubleTap;
            }
            if ((zone.JustTapped(1, 1) || zone.JustTapped(2, 1) || zone.JustTapped(3, 1)) && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteTap;
            }

            if ((zone.JustLongTapped(1) || zone.JustLongTapped(2) || zone.JustLongTapped(3)) && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteLongTap;
            }

            if ((zone.PressedLong(1) || zone.PressedLong(2) || zone.PressedLong(3)) && ((sprite == null) || !sprite.enabled))
            {
                if ((scrollDelta.x > 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteLongScrollR;
                }
                if ((scrollDelta.x < 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteLongScrollL;
                }
                if ((scrollDelta.y > 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteLongScrollU;
                }
                if ((scrollDelta.y < 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteLongScrollD;
                }

                if (((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteLongPress;
                }                                                                                                                                          //Debug.Log(CFUtils.LogPrefix()  + "Long Press"); }
            }
            else if ((zone.PressedNormal(1) || zone.PressedNormal(2) || zone.PressedNormal(3)) && ((sprite == null) || !sprite.enabled))
            {
                if ((scrollDelta.x > 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteNormalScrollR;
                }
                if ((scrollDelta.x < 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteNormalScrollL;
                }
                if ((scrollDelta.y > 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteNormalScrollU;
                }
                if ((scrollDelta.y < 0) && ((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteNormalScrollD;
                }
                if (((sprite == null) || !sprite.enabled))
                {
                    sprite = this.spriteNormalPress;
                }
            }

            if ((zone.PressedRaw(1) || zone.PressedRaw(2) || zone.PressedRaw(3)) && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteRawPress;
            }

            if ((sprite == null) || !sprite.enabled)
            {
                sprite = this.spriteNeutral;
            }


            this.BeginSpriteAnim(sprite, skipAnim);

            this.UpdateSpriteAnimation(skipAnim);
        }
        // ----------------------
        override protected void OnUpdateAnimator(bool skipAnim)
        {
#if UNITY_EDITOR
            if (!UnityEditor.EditorApplication.isPlaying)
            {
                //this.CheckHierarchy();
                //return;
            }
#endif

            TouchJoystick joystick = (TouchJoystick)this.sourceControl;

            if ((joystick == null) || (this.image == null))
            {
                return;
            }


            JoystickState joyState = joystick.GetState();     //false); //this.useVirtualJoystickState);



            SpriteConfig sprite = null;

            if ((this.spriteMode == SpriteMode.FourWay) || (this.spriteMode == SpriteMode.EightWay))
            {
                Dir curDir = Dir.N;

                if (this.spriteMode == SpriteMode.FourWay)
                {
                    curDir = joyState.GetDir4();
                }
                else if (this.spriteMode == SpriteMode.EightWay)
                {
                    curDir = joyState.GetDir8();
                }

                switch (curDir)
                {
                case Dir.U: sprite = this.spriteUp; break;

                case Dir.UR: sprite = this.spriteUpRight; break;

                case Dir.R: sprite = this.spriteRight; break;

                case Dir.DR: sprite = this.spriteDownRight; break;

                case Dir.D: sprite = this.spriteDown; break;

                case Dir.DL: sprite = this.spriteDownLeft; break;

                case Dir.L: sprite = this.spriteLeft; break;

                case Dir.UL: sprite = this.spriteUpLeft; break;
                }
            }


            if (joystick.Pressed() && ((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutralPressed;
            }


            if (((sprite == null) || !sprite.enabled))
            {
                sprite = this.spriteNeutral;
            }


            if (!CFUtils.editorStopped && !this.IsIllegallyAttachedToSource())
            {
                Vector2 joyVec = joyState.GetVectorEx((joystick.shape == TouchControl.Shape.Rectangle) || (joystick.shape == TouchControl.Shape.Square));


                if (this.animateTransl)
                {
                    this.extraOffset = CFUtils.SmoothTowardsVec2(this.extraOffset, Vector2.Scale(joyVec, this.moveScale),
                                                                 this.translationSmoothingTime, CFUtils.realDeltaTimeClamped, 0.0001f);
                }
                else
                {
                    this.extraOffset = Vector2.zero;
                }


                if (this.rotationMode != RotationMode.Disabled)
                {
                    float targetAngle = 0;

                    if (joystick.Pressed())
                    {
                        Vector2 v = joyState.GetVector();

                        if (this.rotationMode == RotationMode.Compass)
                        {
                            if (v.sqrMagnitude > 0.0001f)
                            {
                                this.lastSafeCompassAngle = joyState.GetAngle();          //CFUtils.VecToAngle(v.normalized);
                            }
                            targetAngle = -this.lastSafeCompassAngle;                     //targetRotation = Quaternion.Euler(0, 0, -this.lastSafeCompassAngle);
                        }
                        else
                        {
                            targetAngle = ((this.rotationMode == RotationMode.SimpleHorizontal) ? v.x : v.y) * -this.simpleRotationRange;
                        }
                    }
                    else
                    {
                        this.lastSafeCompassAngle = 0;
                        targetAngle = 0;
                    }


                    this.extraRotation = CFUtils.SmoothTowardsAngle(this.extraRotation, targetAngle,
                                                                    this.rotationSmoothingTime, CFUtils.realDeltaTimeClamped, 0.0001f);
                }
            }



            this.BeginSpriteAnim(sprite, skipAnim);

            this.UpdateSpriteAnimation(skipAnim);
        }
 public DefaultStaticSprite(ISpriteSheet spriteSheet, SpriteConfig config)
     : base(spriteSheet, config)
 {
 }
Beispiel #29
0
 public ISprite Create(SpriteConfig config = null)
 {
     return(new DefaultAnimatedSprite(this.spriteSheet, config ?? this.DefaultConfig));
 }