Exemple #1
0
    protected LevelCell BuildQuadTree(SBSBounds bounds, int depth, bool yUp = true)
    {
        LevelCell root = new LevelCell(bounds);

        this.RecursiveBuildQuadTree(null, root, 0, depth - 1, yUp);
        return(root);
    }
Exemple #2
0
        public LevelCell FindObjectContainmentCell(LevelObject obj)
        {
            SBSBounds objBounds = obj.Bounds;

            LevelCell curCell = this;

            while (curCell.parent != null && !curCell.bounds.Contains(objBounds))
            {
                curCell = curCell.parent;
            }

            int cellIndex, numCells;

            do
            {
                List <LevelCell> curChildren = curCell.children;
                numCells = curChildren.Count;
                for (cellIndex = 0; cellIndex < numCells; ++cellIndex)
                {
                    LevelCell child = curChildren[cellIndex];
                    if (child.bounds.Contains(objBounds))
                    {
                        curCell = child;
                        break;
                    }
                }
            }while (cellIndex != numCells);

            return(curCell);
        }
Exemple #3
0
    public void Initialize()
    {
        // create layers
        layers = new Layers();
        foreach (string layerName in layersName)
        {
            layers.Register(layerName);
        }

        // build quad tree
        worldBounds     = new SBSBounds();
        worldBounds.min = worldBoundsMin;
        worldBounds.max = worldBoundsMax;

        rootCell = this.BuildQuadTree(worldBounds, 5);

        // initialize level objects
        LevelObject[] objects = gameObject.GetComponentsInChildren <LevelObject>(true);
        foreach (LevelObject obj in objects)
        {
            obj.Initialize();
        }

        //if (RacingManager.Instance != null)
        //    RacingManager.Instance.track.Build();

        foreach (LevelObject obj in objects)
        {
            obj.gameObject.SendMessage("OnPostInit", SendMessageOptions.DontRequireReceiver);
        }
    }
Exemple #4
0
        public void Encapsulate(SBSBounds bounds)
        {
            min.x = SBSMath.Min(min.x, bounds.min.x);
            min.y = SBSMath.Min(min.y, bounds.min.y);
            min.z = SBSMath.Min(min.z, bounds.min.z);

            max.x = SBSMath.Max(max.x, bounds.max.x);
            max.y = SBSMath.Max(max.y, bounds.max.y);
            max.z = SBSMath.Max(max.z, bounds.max.z);
        }
Exemple #5
0
    public LevelObject[] Query(SBSBounds bbox, string category, int mask)
    {
        if (null == rootCell)
        {
            return(new LevelObject[0]);
        }
        List <LevelObject> results = new List <LevelObject>();

        rootCell.RecurseQuery(bbox, SBSMath.ClipStatus.Overlapping, category, mask, results);
        return(results.ToArray());
    }
Exemple #6
0
        public void RecurseQuery(SBSBounds bbox, SBSMath.ClipStatus clipStatus, string category, int mask, List <LevelObject> results)
        {
            if (!(null == category) && 0 == this.GetNumObjectsOfCategory(category))
            {
                return;
            }

            if (!(-1 == mask) && 0 == this.GetNumObjectsWithMask(mask))
            {
                return;
            }

            if (SBSMath.ClipStatus.Overlapping == clipStatus)
            {
                clipStatus = SBSMath.GetClipStatus(bbox, bounds);
            }

            if (SBSMath.ClipStatus.Outside == clipStatus)
            {
                return;
            }
            else
            {
                bool doMaskCheck     = !(-1 == mask);
                bool doCategoryCheck = !(null == category);
                bool doClipCheck     = (SBSMath.ClipStatus.Overlapping == clipStatus);

                foreach (LevelObject obj in objects)
                {
                    if (doMaskCheck && 0 == (mask & obj.LayersMask))
                    {
                        continue;
                    }

                    if (doCategoryCheck && category != obj.Category)
                    {
                        continue;
                    }

                    if (doClipCheck && SBSMath.ClipStatus.Outside == SBSMath.GetClipStatus(bbox, obj.Bounds))
                    {
                        continue;
                    }

                    results.Add(obj);
                }
            }

            foreach (LevelCell child in children)
            {
                child.RecurseQuery(bbox, clipStatus, category, mask, results);
            }
        }
Exemple #7
0
        public LevelCell(SBSBounds _bounds)
        {
            bounds           = _bounds;
            objects          = new List <LevelObject>();
            numObjectsByCat  = new Dictionary <string, int>();
            numObjectsByMask = new int[32];
            parent           = null;
            children         = new List <LevelCell>();

            for (int bit = 0; bit < 32; ++bit)
            {
                numObjectsByMask[bit] = 0;
            }
        }
Exemple #8
0
 public static ClipStatus GetClipStatus(SBSBounds a, SBSBounds b)
 {
     if (a.Contains(b))
     {
         return(ClipStatus.Inside);
     }
     else if (a.Intersect(b))
     {
         return(ClipStatus.Overlapping);
     }
     else
     {
         return(ClipStatus.Outside);
     }
 }
Exemple #9
0
    void Update()
    {
        if (GetComponent <Renderer>() != null)
        {
            _bounds = GetComponent <Renderer>().bounds;
        }
        else if (GetComponent <Collider>() != null)
        {
            _bounds = GetComponent <Collider>().bounds;
        }
        else
        {
            _bounds = new SBSBounds(_transform.position, SBSVector3.zero);
        }

        if (null == cell)
        {
            cell = LevelRoot.Instance.RootCell;
            if (null == cell)
            {
                return;
            }
            cell.AttachObject(this);
        }

        LevelCell newCell = cell.FindObjectContainmentCell(this);

        if (newCell != cell)
        {
            if (cell != null)
            {
                cell.DetachObject(this);
            }

            cell = newCell;
            cell.AttachObject(this);
        }

        _prevLocalToWorld = _localToWorld;
        _prevWorldToLocal = _worldToLocal;

        _localToWorld = _transform.localToWorldMatrix;
        _worldToLocal = _transform.worldToLocalMatrix;
    }
Exemple #10
0
    public virtual void Initialize()
    {
        _transform    = transform;
        _localToWorld = _transform.localToWorldMatrix;
        _worldToLocal = _transform.worldToLocalMatrix;

        if (GetComponent <Renderer>() != null)
        {
            _bounds = GetComponent <Renderer>().bounds;
        }
        else if (GetComponent <Collider>() != null)
        {
            _bounds = GetComponent <Collider>().bounds;
        }
        else
        {
            _bounds = new SBSBounds(_localToWorld.position, SBSVector3.zero);
        }

        cell = LevelRoot.Instance.RootCell.FindObjectContainmentCell(this);
        cell.AttachObject(this);

        gameObject.SendMessage("OnInit", SendMessageOptions.DontRequireReceiver);
    }
 public override SBSBounds GetBounds()
 {
     if (state == ElementsState.Cut)
     {
     return internalBounds;
     }
     bounds = new SBSBounds(transform.position, new SBSVector3(width, height, 0.0f));
     return bounds;
 }
 void SetSize(Vector2 size)
 {
     Width = size.x;
     Height = size.y;
     bounds = new SBSBounds(transform.position, new SBSVector3(Width, Height, 0.0f));
        // Debug.Log("getbound " + GetBounds());
 }
 void Awake()
 {
     gameObject.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Sprites/Default"));
     internalBounds = new SBSBounds();
 }
    void Awake()
    {
        isAction = false;
        actualFactorScale = 1.0f;
        elements = new WSList<GameObject>();
        float widthSize = Camera.main.orthographicSize * 2.0f * Camera.main.aspect;
        float heightSize = widthSize / Camera.main.aspect;
           // Debug.Log("***************************************** widthSize " + widthSize + " heightSize " + heightSize);
        bounds = new SBSBounds(Vector3.zero, Vector3.right * widthSize + Vector3.up * heightSize + Vector3.forward * float.MaxValue);

        halfScreenHeight = Camera.main.orthographicSize;
        halfScreenWidth = (halfScreenHeight * Screen.width) / Screen.height;
        outOffset = halfScreenWidth / 4;  //delimiter width is equal to 1/8 of screen width (100 px: 800px)

        colorList.Add(new Color(0.7373f, 0.0078f, 0.0078f, 1f));
        colorList.Add(new Color(1.0f, 0.7059f, 0.0f,1f));
        colorList.Add(new Color(0.2431f, 0.6627f, 0.9882f, 1f));
        colorList.Add(new Color(0.6588f, 0.4078f, 1.0f, 1f));

        UpdateWS();
    }
 public static ClipStatus GetClipStatus(SBSBounds a, SBSBounds b)
 {
     if (a.Contains(b))
         return ClipStatus.Inside;
     else if (a.Intersect(b))
         return ClipStatus.Overlapping;
     else
         return ClipStatus.Outside;
 }
Exemple #16
0
 public LevelObject[] Query(SBSBounds bbox)
 {
     return(this.Query(bbox, null, -1));
 }
 public virtual void UpdateCollider(SBSBounds bounds)
 {
 }
 void Awake()
 {
     internalBounds = new SBSBounds();
 }
Exemple #19
0
    public SBSBounds ComputeBounds()
    {
        int   i    = 0;
        float minX = float.MaxValue,
              minZ = float.MaxValue,
              maxX = float.MinValue,
              maxZ = float.MinValue;

        switch (type)
        {
        case TokenType.Curve:
            float offsetAngle     = transform.rotation.y * SBSMath.ToRadians,
                  oneOverArc      = 1.0f / arcAngle;
            float[] longitudinals =
            {
                0.0f,
                (SBSMath.PI * 0.5f - offsetAngle) * oneOverArc,
                (SBSMath.PI * 1.0f - offsetAngle) * oneOverArc,
                (SBSMath.PI * 1.5f - offsetAngle) * oneOverArc,
                (SBSMath.PI * 2.0f - offsetAngle) * oneOverArc,
                1.0f
            };
#if UNITY_FLASH
            SBSVector3 pos0 = new SBSVector3(), pos1 = new SBSVector3(), tang = new SBSVector3();
#else
            SBSVector3 pos0, pos1, tang;
#endif
            for (; i < 6; ++i)
            {
#if UNITY_FLASH
                this.TokenToWorld(Mathf.Clamp01(longitudinals[i]), -1.0f, pos0, tang);
                this.TokenToWorld(Mathf.Clamp01(longitudinals[i]), 1.0f, pos1, tang);
#else
                this.TokenToWorld(Mathf.Clamp01(longitudinals[i]), -1.0f, out pos0, out tang);
                this.TokenToWorld(Mathf.Clamp01(longitudinals[i]), 1.0f, out pos1, out tang);
#endif
                minX = SBSMath.Min(minX, SBSMath.Min(pos0.x, pos1.x));
                minZ = SBSMath.Min(minZ, SBSMath.Min(pos0.z, pos1.z));
                maxX = SBSMath.Max(maxX, SBSMath.Max(pos0.x, pos1.x));
                maxZ = SBSMath.Max(maxZ, SBSMath.Max(pos0.z, pos1.z));
            }
            break;

        case TokenType.Cross:
        case TokenType.Rect:
            Vector3[] corners =
            {
                new Vector3(-width * 0.5f, 0.0f,           0.0f),
                new Vector3(width * 0.5f,  0.0f,           0.0f),
                new Vector3(-width * 0.5f, 0.0f, lengthOrRadius),
                new Vector3(width * 0.5f,  0.0f, lengthOrRadius)
            };

            if (isCenterPivot)
            {
                corners[0].z = -lengthOrRadius * 0.5f;
                corners[1].z = -lengthOrRadius * 0.5f;
                corners[2].z = lengthOrRadius * 0.5f;
                corners[3].z = lengthOrRadius * 0.5f;
            }

            for (; i < 4; ++i)
            {
                Vector3 v = transform.TransformPoint(corners[i]);

                minX = SBSMath.Min(minX, v.x);
                minZ = SBSMath.Min(minZ, v.z);
                maxX = SBSMath.Max(maxX, v.x);
                maxZ = SBSMath.Max(maxZ, v.z);
            }
            break;
        }

        SBSBounds b = new SBSBounds();
        b.min.Set(minX, 0.0f, minZ);
        b.max.Set(maxX, 0.0f, maxZ);

        return(b);
    }
 public override SBSBounds GetBounds()
 {
     if (state == ElementsState.Fraction || state == ElementsState.Result || state == ElementsState.Equivalence)
     {
         bounds = new SBSBounds(transform.position, new SBSVector3(width, height, 0.0f));
         return bounds;
     }
     else
     {
         bounds.Reset();
         for (int i = 0; i < transform.childCount; i++)
         {
             GameObject child = transform.GetChild(i).gameObject;
             if (child.name.Equals("water"))
             {
                 bounds = child.renderer.bounds;
                 break;
             }
         }
         return bounds;
     }
 }
Exemple #21
0
 public bool Intersect(SBSBounds other)
 {
     return(!(SBSVector3.LessAny(max, other.min) || SBSVector3.GreaterAny(min, other.max)));
 }
 public override SBSBounds GetBounds()
 {
     if (state == ElementsState.Fraction || state == ElementsState.Result || state == ElementsState.Equivalence)
     {
         bounds = new SBSBounds(transform.position, new SBSVector3(width, height, 0.0f));
         return bounds;
     }
     else
     {
         bounds.Reset();
         for (int i = 0; i < transform.childCount; i++)
         {
             if (null != transform.GetChild(i).GetComponent<WSElement>() && transform.GetChild(i).name.Equals("numerator_slice"))
                 bounds.Encapsulate(transform.GetChild(i).GetComponent<WSElement>().GetBounds());
         }
         return bounds;
     }
 }
 public void Initialize()
 {
     gameObject.AddComponent<MeshRenderer>();
     mf = gameObject.AddComponent<MeshFilter>();
     bounds = new SBSBounds(transform.position, new SBSVector3(width, height, 0.0f));
     renderer.material = new Material(Shader.Find("VertexLit"));
 }
 public override SBSBounds GetBounds()
 {
     if (state == ElementsState.Fraction || state == ElementsState.Result || state == ElementsState.Equivalence)
     {
         bounds = new SBSBounds(new Vector3(transform.position.x - ((width) / 2) + ((singleWidth) / 2) - 0.20f, transform.position.y, transform.position.z), new SBSVector3(width, height, 0.0f));
         return bounds;
     }
     else if (state == ElementsState.Cut)
     {
         return internalBounds;
     }
     else
     {
         bounds.Reset();
         for (int i = 0; i < transform.childCount; i++)
         {
             if (null != transform.GetChild(i).GetComponent<EmptyElement>())
                 bounds.Encapsulate(transform.GetChild(i).GetComponent<EmptyElement>().GetBounds());
         }
         return bounds;
     }
 }
Exemple #25
0
 public LevelObject[] Query(SBSBounds bbox, string category)
 {
     return(this.Query(bbox, category, -1));
 }
 public override SBSBounds GetBounds()
 {
     bounds = new SBSBounds(transform.position, new SBSVector3(Width, Height, 0.0f));
        return bounds;
 }
Exemple #27
0
 public LevelObject[] Query(SBSBounds bbox, int mask)
 {
     return(this.Query(bbox, null, mask));
 }
 public override void UpdateCollider(SBSBounds bounds)
 {
     SBSVector3 pos = transform.position;
     //Debug.Log(" collider.center " + collider.center + " bounds max " + bounds.max + " bounds min " + bounds.min);
     collider.center = ((bounds.max + bounds.min) * 0.5f) - pos;
     collider.center = new Vector3(collider.center.x, collider.center.y, 0.0f);
     /* if (type == ElementsType.HeartSet ||type == ElementsType.MoonSet || type == ElementsType.StarSet)
      {
          collider.center = new Vector3(collider.center.x-0.20f, collider.center.y, 0.0f);
      }*/
     if (state == ElementsState.Cut || state == ElementsState.Result)
     {
         collider.size = (bounds.max - bounds.min);
     }
     else
     {
         collider.size = (bounds.max - bounds.min);
     }
     if (ActualfactorScale < 1.88f)
         collider.size = new Vector3(collider.size.x, collider.size.y / ActualfactorScale, collider.size.z);
     else
         collider.size = new Vector3(collider.size.x, collider.size.y / 1.88f, collider.size.z);
     //Debug.Log("actua" + ActualfactorScale);
 }
Exemple #29
0
 public bool Contains(SBSBounds other)
 {
     return(SBSVector3.LessAll(min, other.min) && SBSVector3.GreaterEqualAll(max, other.max));
 }