IEnumerator _Initialize(AssociationPiece piece)
        {
            var rb = GetComponent <Rigidbody>();

            rb.useGravity = false;
            rb.WakeUp();
            rb.isKinematic = true;
            yield return(null);

            var tranf = GetComponent <Transformer2D>();

            tranf.Speed = 25;

            _pg = GetComponent <PanGesture>();

            if (!string.IsNullOrEmpty(piece.sprite))
            {
                var image = GetComponent <Image>();
                if (!image)
                {
                    image = gameObject.AddComponent <Image>();
                }

                image.sprite = Resources.Load <Sprite>(piece.sprite);
            }

            Id = piece.id;

            IsStatic = piece.isStatic;

            _controllerType = ControllerTypes.Association;


            Initialize();
        }
Esempio n. 2
0
        void InstantiatePiece(AssociationPiece piece)
        {
            /*
             * var types = new Type[]
             * {
             *  typeof (RectTransform),
             *  typeof (Rigidbody),
             *  typeof (Transformer2D),
             *  typeof (PanGesture),
             *  typeof (AssociationObject)
             * };
             * /**/
            var temp = Instantiate(Resources.Load <GameObject>(_resourcesData.Prefabs.Find(x => x.category == PrefabCategory.AssociationObjectDynamic).name)); //new GameObject("Piece_" + piece.id + (piece.isStatic ? "_S" : "_D"), types);

            temp.transform.SetParent(_AssociationData.Root);

            temp.transform.localPosition    = piece.pos;
            temp.transform.localEulerAngles = Vector3.zero;
            temp.transform.localScale       = Vector3.one;

            instancedPieces.Add(temp);

            var ao = temp.GetComponent <AssociationObject>();

            ao.Initialize(piece);
        }
        public virtual void Initialize(AssociationPiece piece)
        {
            //StartCoroutine(_Initialize(piece));
            //return;
            Debug.Log("dsds");
            var rb = GetComponent <Rigidbody>();

            if (!rb)
            {
                rb = gameObject.AddComponent <Rigidbody>();
            }
            rb.useGravity  = false;
            rb.isKinematic = true;
            rb.WakeUp();

            var bx = GetComponent <BoxCollider>();

            if (!bx)
            {
                bx = gameObject.AddComponent <BoxCollider>();
            }

            var tranf = GetComponent <Transformer2D>();

            if (!tranf)
            {
                tranf = gameObject.AddComponent <Transformer2D>();
            }
            tranf.Speed = 25;

            _pg = GetComponent <PanGesture>();
            if (!_pg)
            {
                _pg = gameObject.AddComponent <PanGesture>();
            }

            if (!string.IsNullOrEmpty(piece.sprite))
            {
                var image = GetComponent <Image>();
                if (!image)
                {
                    image = gameObject.AddComponent <Image>();
                }

                image.sprite = Resources.Load <Sprite>(piece.sprite);
                image.SetNativeSize();

                if (piece.useSize)
                {
                    image.type = Image.Type.Sliced;
                }

                if (piece.isStatic)
                {
                    image.color = new Color(1, 1, 1, 1);
                }
            }

            if (piece.useSize)
            {
                var rect = GetComponent <RectTransform>();
                rect.sizeDelta = piece.size;
            }

            if (!string.IsNullOrEmpty(piece.text))
            {
                //text.text = piece.text;
            }

            Id  = piece.id;
            Ids = new List <int>(piece.ids);

            IsStatic = piece.isStatic;

            _controllerType = ControllerTypes.Association;

            Initialize();
        }