예제 #1
0
 public SComponent AddComponent(Type type)
 {
     if (!isAlive)
     {
         return(null);
     }
     if (!HasComponent(type))
     {
         SComponent sComponent = Activator.CreateInstance(type) as SComponent;
         if (sComponent != null)
         {
             sComponent._gameObject = this;
             _willAddComponent.Enqueue(new ComponentTypePair(type, sComponent));
             _commandQueue.Enqueue(AddComponent);
             //_componentList.Add(type, sComponent);
             return(sComponent);
         }
         else
         {
             SDebug.LogError("Create Component Instance Failed");
         }
     }
     else
     {
         SDebug.LogError("this kind of component has already been added");
     }
     return(null);
 }
예제 #2
0
        public SGameObject(STransform2D transform2D)
        {
            SDebug.Assert(SFrameWork.frameWork != null);
            this.transform = AddComponent <STransform>();
            _componentList.Add(typeof(STransform2D), transform2D);
            this.transform2D = transform2D;
            _parents         = null;

            _name = "New_SGameObject_" + SFrameWork.frameWork.gameObjectNum;
            SFrameWork.frameWork.AddToList(this);
        }
예제 #3
0
        public SGameObject(string objname)
        {
            SDebug.Assert(SFrameWork.frameWork != null);
            transform   = AddComponent <STransform>();
            transform2D = AddComponent <STransform2D>();
            _parents    = null;

            _name = objname;

            SFrameWork.frameWork.AddToList(this);
        }
예제 #4
0
        public SGameObject()
        {
            SDebug.Assert(SFrameWork.frameWork != null);
            transform   = AddComponent <STransform>();
            transform2D = AddComponent <STransform2D>();
            _parents    = null;

            _name = "New_SGameObject_" + SFrameWork.frameWork.gameObjectNum;

            SFrameWork.frameWork.AddToList(this);
        }
예제 #5
0
 public static bool InitFramework()
 {
     lock (mutex)
     {
         if (_framework == null)
         {
             _framework = new SFrameWork();
             return(true);
         }
         else
         {
             SDebug.LogWarning("the Framework has been inited");
             return(false);
         }
     }
 }
예제 #6
0
        public SGameObject(SGameObject parents, string name)
        {
            SDebug.Assert(SFrameWork.frameWork != null);
            transform   = AddComponent <STransform>();
            transform2D = AddComponent <STransform2D>();
            if (parents != null && parents.isAlive)
            {
                this.parents = parents;
            }
            else
            {
                this.parents = null;
            }
            transform2D.localPosition = SVector2.zero;
            transform2D.localRotation = (Fix64)0;

            _name = name;
            SFrameWork.frameWork.AddToList(this);
        }
예제 #7
0
 public void RemoveComponent(Type type)
 {
     if (!isAlive)
     {
         return;
     }
     if (HasComponent(type))
     {
         _willDeleteComponent.Enqueue(new ComponentTypePair(type, null));
         _commandQueue.Enqueue(RemoveComponent);
     }
     // if (_componentList.ContainsKey(type))
     // {
     //     _componentList.Remove(type);
     // }
     else
     {
         SDebug.LogError("this kind of component has not been added yet");
     }
 }
예제 #8
0
 protected override bool GenerateCollisionRes(SICollider other, out SCollisionResult selfres, out SCollisionResult otherres)
 {
     if (other.GetType().Equals(typeof(SSphereCollider)))
     {
         var minDis = (other.position - position).sqrtMagnitude;
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             //SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
     else if (other.GetType().Equals(typeof(SCapsuleCollider)))
     {
         var   oth    = other as SCapsuleCollider;
         Fix64 minDis = Fix64.MaxValue;
         var   atop   = position - oth.positionA;
         var   btop   = position - oth.positionB;
         var   ti     = atop.Dot(oth.up);
         var   tj     = btop.Dot(oth.up);
         var   w      = position - oth.positionA;
         if (ti * tj < Fix64.Zero)
         {
             minDis = w.sqrtMagnitude - w.Dot(oth.up) * w.Dot(up);
         }
         else if (ti <= Fix64.Zero)
         {
             minDis = atop.sqrtMagnitude;
         }
         else if (tj >= Fix64.Zero)
         {
             minDis = btop.sqrtMagnitude;
         }
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
     selfres  = new SCollisionResult();
     otherres = new SCollisionResult();
     return(false);
 }
예제 #9
0
        public T AddComponent <T>() where T : SComponent, new()
        {
            if (!isAlive)
            {
                return(null);
            }
            Type type = typeof(T);

            if (!HasComponent(type))
            {
                T t = new T();
                t._gameObject = this;
                _willAddComponent.Enqueue(new ComponentTypePair(type, t));
                _commandQueue.Enqueue(AddComponent);
                //_componentList.Add(type, t);
                return(t);
            }
            else
            {
                SDebug.LogError("this kind of component has already been added");
            }
            return(null);
        }
예제 #10
0
 internal override void DetectCollision(SICollider other)
 {
     if (other.GetType().Equals(typeof(SSphereCollider)))
     {
         var minDis = (other.position - position).sqrtMagnitude;
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
     else if (other.GetType().Equals(typeof(SCapsuleCollider)))
     {
         var   oth    = other as SCapsuleCollider;
         Fix64 minDis = Fix64.MaxValue;
         var   atop   = position - oth.positionA;
         var   btop   = position - oth.positionB;
         var   ti     = atop.Dot(oth.up);
         var   tj     = btop.Dot(oth.up);
         var   w      = position - oth.positionA;
         if (ti * tj < Fix64.Zero)
         {
             minDis = w.sqrtMagnitude - w.Dot(oth.up) * w.Dot(up);
         }
         else if (ti <= Fix64.Zero)
         {
             minDis = atop.sqrtMagnitude;
         }
         else if (tj >= Fix64.Zero)
         {
             minDis = btop.sqrtMagnitude;
         }
         if (minDis <= (radius + other.radius) * (radius + other.radius))
         {
             SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
         }
     }
 }
예제 #11
0
        internal override void DetectCollision(SICollider other)
        {
            if (other.GetType().Equals(typeof(SSphereCollider)))
            {
                Fix64 minDis = Fix64.MaxValue;
                var   atop   = other.position - positionA;
                var   btop   = other.position - positionB;
                var   ti     = atop.Dot(up);
                var   tj     = btop.Dot(up);
                var   w      = other.position - positionA;
                if (ti * tj < Fix64.Zero)
                {
                    minDis = w.sqrtMagnitude - w.Dot(up) * w.Dot(up);
                }
                else if (ti <= Fix64.Zero)
                {
                    minDis = atop.sqrtMagnitude;
                }
                else if (tj >= Fix64.Zero)
                {
                    minDis = btop.sqrtMagnitude;
                }
                if (minDis <= (radius + other.radius) * (radius + other.radius))
                {
                    SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
                }
            }
            else if (other.GetType().Equals(typeof(SCapsuleCollider)))
            {
                Fix64 deltaRange = (Fix64)1 / (Fix64)1000;
                //SDebug.Log(deltaRange);

                SCapsuleCollider oth = other as SCapsuleCollider;
                if (Fix64.Abs(up.Dot(oth.up)) > deltaRange)
                {
                    Fix64 tIn1   = (oth.positionA.Dot(oth.up) - positionA.Dot(oth.up)) / up.Dot(oth.up);
                    Fix64 tIn2   = (oth.positionB.Dot(oth.up) - positionA.Dot(oth.up)) / up.Dot(oth.up);
                    Fix64 tInMin = ((tIn1 < tIn2) ? tIn1 : tIn2);
                    Fix64 tInMax = ((tIn1 < tIn2) ? tIn2 : tIn1);

                    //SDebug.Log(tInMin + "  " + tInMax);

                    var w    = positionA - oth.positionA;
                    var wf   = positionA - oth.positionB;
                    var u12  = up.Dot(oth.up);
                    var u1w  = up.Dot(w);
                    var u2w  = oth.up.Dot(w);
                    var u1wf = up.Dot(wf);


                    var minDis    = Fix64.MaxValue;
                    var minMiddle = Fix64.MaxValue;
                    var minLeft   = Fix64.MaxValue;
                    var minRight  = Fix64.MaxValue;

                    Fix64 et       = Fix64.Zero;
                    Fix64 etLeft   = Fix64.Zero;
                    Fix64 etMiddle = Fix64.Zero;
                    Fix64 etRight  = Fix64.Zero;

                    if (tInMin <= length && tInMax >= Fix64.Zero)
                    {
                        minMiddle = minValueFunc((Fix64)1 - u12 * u12, (Fix64)2 * (u1w - u12 * u2w), w.sqrtMagnitude - u2w * u2w,
                                                 MathF.max((Fix64)0, tInMin), MathF.min(length, tInMax), out etMiddle);
                        //SDebug.Log(gameObject.name+"  middle: " + minMiddle);
                    }
                    if (tInMin >= Fix64.Zero)
                    {
                        Fix64 temEtLeft1 = Fix64.Zero;
                        Fix64 temEtLeft2 = Fix64.Zero;

                        var temMin1 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1w, w.sqrtMagnitude,
                                         Fix64.Zero, MathF.min(length, tInMin), out temEtLeft1);

                        var temMin2 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1wf, wf.sqrtMagnitude,
                                         Fix64.Zero, MathF.min(length, tInMin), out temEtLeft2);

                        etLeft  = (temMin1 < temMin2) ? temEtLeft1 : temEtLeft2;
                        minLeft = MathF.min(temMin1, temMin2);
                        //SDebug.Log(gameObject.name+"  left: " + minLeft + " " + etLeft);
                    }
                    if (tInMax <= length)
                    {
                        Fix64 temEtRight1 = Fix64.Zero;
                        Fix64 temEtRight2 = Fix64.Zero;

                        var temMin1 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1w, w.sqrtMagnitude,
                                         MathF.max(Fix64.Zero, tInMax), length, out temEtRight1);

                        var temMin2 =
                            minValueFunc(Fix64.One, (Fix64)2 * u1wf, wf.sqrtMagnitude,
                                         MathF.max(Fix64.Zero, tInMax), length, out temEtRight2);

                        etRight  = (temMin1 < temMin2) ? temEtRight1 : temEtRight2;
                        minRight = MathF.min(temMin1, temMin2);
                        //SDebug.Log(gameObject.name+"  right: " + minRight + " " + etRight);
                    }
                    if (minLeft <= minRight && minLeft <= minMiddle)
                    {
                        et     = etLeft;
                        minDis = minLeft;
                    }
                    else if (minMiddle <= minLeft && minMiddle <= minRight)
                    {
                        et     = etMiddle;
                        minDis = minMiddle;
                    }
                    else
                    {
                        et     = etRight;
                        minDis = minRight;
                    }
                    if (minDis <= (radius + oth.radius) * (radius + oth.radius))
                    {
                        SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
                    }
                }
                else
                {
                    Fix64 minDis = Fix64.MaxValue;
                    Fix64 et     = Fix64.Zero;
                    SDebug.LogWarning("Vertical");


                    var p1tp2  = positionA - oth.positionA;
                    var p1tp2f = positionA - oth.positionB;
                    var ti     = p1tp2.Dot(oth.up);
                    var tj     = p1tp2f.Dot(oth.up);

                    if (ti * tj <= Fix64.Zero)
                    {
                        var a = Fix64.One;
                        var w = positionA - oth.positionA;
                        var b = (Fix64)2 * up.Dot(w);
                        var c = w.sqrtMagnitude - oth.up.Dot(w) * oth.up.Dot(w);


                        minDis =
                            minValueFunc(a, b, c, Fix64.Zero, length, out et);
                        //minDis = temMin;
                    }
                    else if (ti <= Fix64.Zero)
                    {
                        var w   = positionA - oth.positionA;
                        var u1w = up.Dot(w);
                        minDis =
                            minValueFunc(Fix64.One, (Fix64)2 * u1w, w.sqrtMagnitude, Fix64.Zero, length, out et);
                    }
                    else if (tj >= Fix64.Zero)
                    {
                        var wf   = positionA - oth.positionB;
                        var u1wf = up.Dot(wf);
                        minDis =
                            minValueFunc(Fix64.One, (Fix64)2 * u1wf, wf.sqrtMagnitude, Fix64.Zero, length, out et);
                    }

                    if (minDis <= (radius + oth.radius) * (radius + oth.radius))
                    {
                        SDebug.LogWarning(gameObject.name + " BAAAAAANG!!!  " + minDis);
                    }
                }
            }
        }