private void Sweep()
        {
            for (var i = Fingers.Count - 1; i >= 0; i--)
            {
                var finger = Fingers[i];

                if (finger.Marked == true)
                {
                    // Tap?
                    if (finger.Age <= 0.5f)
                    {
                        var screenMovement  = Vector2.Distance(finger.StartScreenPosition, finger.ScreenPosition);
                        var screenThreshold = Mathf.Min(Screen.width, Screen.height) * 0.025f;

                        if (screenMovement <= screenThreshold)
                        {
                            if (OnFingerTap != null)
                            {
                                OnFingerTap(finger);
                            }
                        }
                    }

                    // Remove and pool
                    Fingers.RemoveAt(i);

                    SgtPoolClass <Finger> .Add(finger);
                }
            }
        }
        private void AddFinger(int index, Vector2 screenPosition)
        {
            var finger = FindFinger(index);

            if (finger != null)
            {
                finger.Index              = index;
                finger.Marked             = false;
                finger.Age               += Time.deltaTime;
                finger.LastScreenPosition = finger.ScreenPosition;
                finger.ScreenPosition     = screenPosition;
            }
            else
            {
                finger = SgtPoolClass <Finger> .Pop() ?? new Finger();

                finger.Index  = index;
                finger.Marked = false;
                finger.Age    = 0.0f;
                finger.StartScreenPosition = screenPosition;
                finger.LastScreenPosition  = screenPosition;
                finger.ScreenPosition      = screenPosition;
                finger.StartedOverGui      = PointOverGui(screenPosition);

                Fingers.Add(finger);
            }
        }
Ejemplo n.º 3
0
        public SgtStarfieldCustom MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale)
        {
#if UNITY_EDITOR
            SgtHelper.BeginUndo("Create Editable Starfield Copy");
#endif
            var gameObject      = SgtHelper.CreateGameObject("Editable Starfield Copy", layer, parent, localPosition, localRotation, localScale);
            var customStarfield = SgtHelper.AddComponent <SgtStarfieldCustom>(gameObject, false);
            var quads           = new List <SgtStarfieldStar>();
            var starCount       = BeginQuads();

            for (var i = 0; i < starCount; i++)
            {
                var quad = SgtPoolClass <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar();

                NextQuad(ref quad, i);

                quads.Add(quad);
            }

            EndQuads();

            // Copy common settings
            customStarfield.Color         = Color;
            customStarfield.Brightness    = Brightness;
            customStarfield.MainTex       = MainTex;
            customStarfield.Layout        = Layout;
            customStarfield.LayoutColumns = LayoutColumns;
            customStarfield.LayoutRows    = LayoutRows;
            customStarfield.LayoutRects   = new List <Rect>(LayoutRects);
            customStarfield.BlendMode     = BlendMode;
            customStarfield.RenderQueue   = RenderQueue;
            customStarfield.PowerRgb      = PowerRgb;
            customStarfield.ClampSize     = ClampSize;
            customStarfield.ClampSizeMin  = ClampSizeMin;
            customStarfield.Stretch       = Stretch;
            customStarfield.StretchVector = StretchVector;
            customStarfield.StretchScale  = StretchScale;
            customStarfield.StretchLimit  = StretchLimit;
            customStarfield.Near          = Near;
            customStarfield.NearTex       = NearTex;
            customStarfield.NearThickness = NearThickness;
            customStarfield.Pulse         = Pulse;
            customStarfield.PulseOffset   = PulseOffset;
            customStarfield.PulseSpeed    = PulseSpeed;

            // Copy custom settings
            customStarfield.Stars = quads;

            // Update
            customStarfield.UpdateMaterial();
            customStarfield.UpdateMeshesAndModels();

            return(customStarfield);
        }
Ejemplo n.º 4
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (Stars != null)
            {
                for (var i = Stars.Count - 1; i >= 0; i--)
                {
                    SgtPoolClass <SgtStarfieldStar> .Add(Stars[i]);
                }
            }
        }
Ejemplo n.º 5
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (asteroids != null)
            {
                for (var i = asteroids.Count - 1; i >= 0; i--)
                {
                    SgtPoolClass <SgtBeltAsteroid> .Add(asteroids[i]);
                }
            }
        }
Ejemplo n.º 6
0
        public static void Clear <T>(List <T> cameraStates)
            where T : SgtCameraState
        {
            if (cameraStates != null)
            {
                for (var i = cameraStates.Count - 1; i >= 0; i--)
                {
                    SgtPoolClass <T> .Add(cameraStates[i]);
                }

                cameraStates.Clear();
            }
        }
Ejemplo n.º 7
0
        public SgtBeltCustom MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale)
        {
#if UNITY_EDITOR
            SgtHelper.BeginUndo("Create Editable Belt Copy");
#endif
            var gameObject = SgtHelper.CreateGameObject("Editable Belt Copy", layer, parent, localPosition, localRotation, localScale);
            var customBelt = SgtHelper.AddComponent <SgtBeltCustom>(gameObject, false);
            var quads      = new List <SgtBeltAsteroid>();
            var quadCount  = BeginQuads();

            for (var i = 0; i < quadCount; i++)
            {
                var asteroid = SgtPoolClass <SgtBeltAsteroid> .Pop() ?? new SgtBeltAsteroid();

                NextQuad(ref asteroid, i);

                quads.Add(asteroid);
            }

            EndQuads();

            // Copy common settings
            customBelt.Color         = Color;
            customBelt.Brightness    = Brightness;
            customBelt.MainTex       = MainTex;
            customBelt.Layout        = Layout;
            customBelt.LayoutColumns = LayoutColumns;
            customBelt.LayoutRows    = LayoutRows;
            customBelt.LayoutRects   = new List <Rect>(LayoutRects);
            customBelt.BlendMode     = BlendMode;
            customBelt.RenderQueue   = RenderQueue;
            customBelt.OrbitOffset   = OrbitOffset;
            customBelt.OrbitSpeed    = OrbitSpeed;
            customBelt.Lit           = Lit;
            customBelt.LightingTex   = LightingTex;
            customBelt.AmbientColor  = AmbientColor;
            customBelt.PowerRgb      = PowerRgb;

            // Copy custom settings
            customBelt.Asteroids = quads;

            // Update
            customBelt.UpdateMaterial();
            customBelt.UpdateMeshesAndModels();

            return(customBelt);
        }
Ejemplo n.º 8
0
        public SgtStarfieldCustom MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale)
        {
#if UNITY_EDITOR
            SgtHelper.BeginUndo("Create Editable Starfield Copy");
#endif
            var gameObject      = SgtHelper.CreateGameObject("Editable Starfield Copy", layer, parent, localPosition, localRotation, localScale);
            var customStarfield = SgtHelper.AddComponent <SgtStarfieldCustom>(gameObject, false);
            var stars           = customStarfield.Stars;
            var starCount       = BeginQuads();

            for (var i = 0; i < starCount; i++)
            {
                var star = SgtPoolClass <SgtStarfieldStar> .Pop() ?? new SgtStarfieldStar();

                NextQuad(ref star, i);

                stars.Add(star);
            }

            EndQuads();

            // Copy common settings
            customStarfield.Color         = color;
            customStarfield.Brightness    = brightness;
            customStarfield.MainTex       = mainTex;
            customStarfield.Layout        = layout;
            customStarfield.LayoutColumns = layoutColumns;
            customStarfield.LayoutRows    = layoutRows;
            customStarfield.layoutRects   = new List <Rect>(layoutRects);
            customStarfield.blendMode     = blendMode;
            customStarfield.renderQueue   = renderQueue;
            customStarfield.powerRgb      = powerRgb;
            customStarfield.clampSize     = clampSize;
            customStarfield.clampSizeMin  = clampSizeMin;
            customStarfield.stretch       = stretch;
            customStarfield.stretchVector = stretchVector;
            customStarfield.stretchScale  = stretchScale;
            customStarfield.stretchLimit  = stretchLimit;
            customStarfield.near          = near;
            customStarfield.nearTex       = nearTex;
            customStarfield.nearThickness = nearThickness;
            customStarfield.pulse         = pulse;
            customStarfield.pulseOffset   = pulseOffset;
            customStarfield.pulseSpeed    = pulseSpeed;

            return(customStarfield);
        }
Ejemplo n.º 9
0
        public SgtBeltCustom MakeEditableCopy(int layer, Transform parent, Vector3 localPosition, Quaternion localRotation, Vector3 localScale)
        {
#if UNITY_EDITOR
            SgtHelper.BeginUndo("Create Editable Belt Copy");
#endif
            var gameObject = SgtHelper.CreateGameObject("Editable Belt Copy", layer, parent, localPosition, localRotation, localScale);
            var customBelt = SgtHelper.AddComponent <SgtBeltCustom>(gameObject, false);
            var asteroids  = customBelt.Asteroids;
            var quadCount  = BeginQuads();

            for (var i = 0; i < quadCount; i++)
            {
                var asteroid = SgtPoolClass <SgtBeltAsteroid> .Pop() ?? new SgtBeltAsteroid();

                NextQuad(ref asteroid, i);

                asteroids.Add(asteroid);
            }

            EndQuads();

            // Copy common settings
            customBelt.Color         = Color;
            customBelt.Brightness    = Brightness;
            customBelt.mainTex       = mainTex;
            customBelt.layout        = layout;
            customBelt.layoutColumns = layoutColumns;
            customBelt.layoutRows    = layoutRows;
            customBelt.layoutRects   = new List <Rect>(layoutRects);
            customBelt.blendMode     = blendMode;
            customBelt.renderQueue   = renderQueue;
            customBelt.orbitOffset   = orbitOffset;
            customBelt.orbitSpeed    = orbitSpeed;
            customBelt.lit           = lit;
            customBelt.lightingTex   = lightingTex;
            customBelt.ambientColor  = ambientColor;
            customBelt.powerRgb      = powerRgb;

            return(customBelt);
        }
Ejemplo n.º 10
0
        public static T Find <T>(ref List <T> cameraStates, Camera camera)
            where T : SgtCameraState, new()
        {
            if (cameraStates == null)
            {
                cameraStates = new List <T>();
            }

            for (var i = cameraStates.Count - 1; i >= 0; i--)
            {
                var cameraState = cameraStates[i];

                if (cameraState == null)
                {
                    cameraStates.RemoveAt(i); continue;
                }

                if (cameraState.Camera == null)
                {
                    SgtPoolClass <T> .Add(cameraState); cameraStates.RemoveAt(i); continue;
                }

                if (cameraState.Camera == camera)
                {
                    return(cameraState);
                }
            }

            var newCameraState = SgtPoolClass <T> .Pop() ?? new T();

            newCameraState.Camera = camera;

            cameraStates.Add(newCameraState);

            return(newCameraState);
        }