コード例 #1
0
ファイル: ReboundTemplate.cs プロジェクト: zamixn/PongRoyale
        public virtual IReboundStrategy ChooseStrategy()
        {
            IsReboundingFromPaddle();
            IsReboundingFromArenaObject();
            if (ReboundFromPaddle)
            {
                switch (BType)
                {
                case BallType.Deadly:
                    return(new BallDeadlyStrategy());

                case BallType.Normal:
                    if (PaddleSpeed < 0)
                    {
                        return(new PaddleMovingLeft());
                    }
                    else if (PaddleSpeed > 0)
                    {
                        return(new PaddleMovingRight());
                    }
                    else     //if PaddleSpeed == 0
                    {
                        return(new PaddleNotMoving());
                    }
                }
            }
            else if (ReboundFromArenaObject)
            {
                if (ArObject.GetType() == typeof(Obstacle))
                {
                    switch (ArObjectType)
                    {
                    case ArenaObjectType.Passable:
                        return(new PassableObstacleStrategy());

                    case ArenaObjectType.NonPassable:
                        return(new NonPassableObstacleStrategy());

                    default:
                        return(null);
                    }
                }
                else if (ArObject.GetType() == typeof(PowerUp))
                {
                    switch (ArObjectType)
                    {
                    case ArenaObjectType.Passable:
                        return(new PassablePowerupStrategy());

                    case ArenaObjectType.NonPassable:
                        return(new NonPassablePowerupStrategy());

                    default:
                        return(null);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
 private Vector3 GetTarketPosition(ArObject arObject)
 {
     if (arObject == null
         )
     {
         return(new Vector3(0, 0, 0));
     }
     return(arObject.TargetPosition);
 }
コード例 #3
0
    // Create the ar objects depending on the downloaded text
    private void CreateArObjects(string text)
    {
        // Place the objects
        var lines = text.Split('\n');

        foreach (var entry in lines)
        {
            if (string.IsNullOrEmpty(entry))
            {
                // Empty line, ignore
                continue;
            }
            var line = entry.Trim();
            if (string.IsNullOrEmpty(line) || line.StartsWith("#") || line.StartsWith("//"))
            {
                // Empty line or comment line, ignore
                continue;
            }

            string     arGameObjectTag;
            GameObject arGameObject = null;

            var parts = line.Split(',');
            if (parts.Length == 1)
            {
                if ("ShowInfo".Equals(parts[0].Trim()))
                {
                    _showInfo = true;
                    continue;
                }
                else
                {
                    _error = line + "', bad command: " + parts[0].Trim();
                    break;
                }
            }
            if (parts.Length == 2)
            {
                if ("DEL".Equals(parts[0].Trim()))
                {
                    // Destroy the objects, so they are not visible in the scene
                    arGameObjectTag = parts[1].Trim();
                    arGameObject    = FindGameObjectWithTag(arGameObjectTag);
                    if (arGameObject == null)
                    {
                        _error = line + ", bad tag: " + arGameObjectTag;
                        break;
                    }
                    Destroy(arGameObject, .1f);
                    continue;
                }
                else
                {
                    _error = line + ", bad command: " + parts[0].Trim();
                    break;
                }
            }

            // 6 parts: Command,Tag, Name to set, Lat, Lon, alt
            if (parts.Length != 6)
            {
                _error = line + ", bad text: ";
                break;
            }

            if (!"REL".Equals(parts[0].Trim()) && !"ABS".Equals(parts[0].Trim()))
            {
                _error = line + ", bad command: " + parts[0].Trim();
                break;
            }

            // First part is the tag of the game object
            arGameObjectTag = parts[1].Trim();

            arGameObject = FindGameObjectWithTag(arGameObjectTag);
            if (arGameObject == null)
            {
                _error = line + ", bad tag: '" + arGameObjectTag + "'";
                break;
            }

            // Wrap the object in a wrapper
            var wrapper = Instantiate(_wrapper);
            if (wrapper == null)
            {
                _error = "Instantiate(_wrapper) failed";
                break;
            }
            wrapper.transform.parent = _sceneAnchor.transform;

            // Create a copy of the object
            arGameObject = Instantiate(arGameObject);
            if (arGameObject == null)
            {
                _error = "Instantiate(" + arGameObjectTag + ") failed";
                break;
            }
            arGameObject.transform.parent = wrapper.transform;

            // Set the name of the instantiated game object
            arGameObject.name = parts[2].Trim();

            if ("ABS".Equals(parts[0].Trim()))
            {
                // Get lat and lon of the object
                double value;
                if (!double.TryParse(parts[3].Trim(), out value))
                {
                    _error = line + ", bad lat: " + parts[3].Trim();
                    break;
                }
                var latitude = (float)value;

                if (!double.TryParse(parts[4].Trim(), out value))
                {
                    _error = line + ", bad lon: " + parts[4].Trim();
                    break;
                }
                var longitude = (float)value;

                if (!double.TryParse(parts[5].Trim(), out value))
                {
                    _error = line + ", bad alt: " + parts[5].Trim();
                    break;
                }
                var altitude = (float)value;

                // Create the AR object
                var arObject = new ArObject
                {
                    IsRelative       = false,
                    Text             = line,
                    GameObject       = wrapper,
                    Latitude         = latitude,
                    Longitude        = longitude,
                    RelativeAltitude = altitude
                };

                // Latitude or longitude 0 means objects should take device latitude or longitude
                var arObjectLatitude = arObject.Latitude;
                if (arObjectLatitude == 0f)
                {
                    arObjectLatitude = _originalLatitude;
                }
                var arObjectLongitude = arObject.Longitude;
                if (arObjectLongitude == 0f)
                {
                    arObjectLongitude = _originalLongitude;
                }

                var latDistance = Calc(arObjectLatitude, arObjectLongitude, _originalLatitude, arObjectLongitude);
                var lonDistance = Calc(arObjectLatitude, arObjectLongitude, arObjectLatitude, _originalLongitude);

                var distance = Mathf.Sqrt(latDistance * latDistance + lonDistance * lonDistance);
                if (distance < 250)
                {
                    _arObjects.Add(arObject);
                }
            }
            else
            {
                // Get x offset and z offset of the object
                double value;
                if (!double.TryParse(parts[3].Trim(), out value))
                {
                    _error = line + ", bad x: " + parts[3].Trim();
                    break;
                }
                var xOffset = (float)value;

                if (!double.TryParse(parts[4].Trim(), out value))
                {
                    _error = line + ", bad z: " + parts[4].Trim();
                    break;
                }
                var zOffset = (float)value;

                if (!double.TryParse(parts[5].Trim(), out value))
                {
                    _error = line + ", bad alt: " + parts[5].Trim();
                    break;
                }
                var altitude = (float)value;

                // Create the ar object
                var arObject = new ArObject
                {
                    IsRelative       = true,
                    Text             = line,
                    GameObject       = wrapper,
                    RelativeAltitude = altitude
                };
                _arObjects.Add(arObject);
                arObject.GameObject.transform.position = arObject.TargetPosition = new Vector3(xOffset, arObject.RelativeAltitude, zOffset);
            }
        }
    }