コード例 #1
0
        public static Transform LoadIcon(Transform iconPrefab, Transform icon, Vector3 localPosition, Vector3 localScale, Transform parent, int sortingOrderAdd, Orientation orientation, Color color, bool forGrid)
        {
            Transform transform = PartGrid.LoadIcon(iconPrefab, icon, localPosition, localScale, parent, sortingOrderAdd, color, forGrid);

            Orientation.ApplyOrientation(transform, orientation);
            return(transform);
        }
コード例 #2
0
        public static Texture2D CreatePreviewIcon(string jsonData)
        {
            Build.BuildSave buildSave = JsonUtility.FromJson <Build.BuildSave>(jsonData);
            Vector2         zero      = Vector2.zero;

            PartGrid.CenterToPositon(buildSave.parts, Build.main.partDatabase, ref zero, new Vector2(0f, -200f));
            List <GameObject> list = new List <GameObject>();

            foreach (Build.BuildSave.PlacedPartSave placedPartSave in buildSave.parts)
            {
                PartData partByName = Build.main.partDatabase.GetPartByName(placedPartSave.partName);
                if (partByName != null)
                {
                    list.Add(PartGrid.LoadIcon(Build.main.buildGrid.iconPrefab, partByName.prefab, placedPartSave.position, partByName.prefab.localScale, null, 0, placedPartSave.orientation, Color.white, true).gameObject);
                }
            }
            Build.main.previewIconCamera.transform.position = new Vector3(0f, -200f, Mathf.Clamp(-Mathf.Max(zero.x, zero.y), -100f, -1f) * 0.52f);
            Build.main.previewIconCamera.Render();
            while (list.Count > 0)
            {
                UnityEngine.Object.DestroyImmediate(list[0]);
                list.RemoveAt(0);
            }
            Texture2D texture2D = new Texture2D(Build.main.previewIconCamera.targetTexture.width, Build.main.previewIconCamera.targetTexture.height, TextureFormat.RGB24, false);

            RenderTexture.active = Build.main.previewIconCamera.targetTexture;
            texture2D.ReadPixels(new Rect(0f, 0f, (float)Build.main.previewIconCamera.targetTexture.width, (float)Build.main.previewIconCamera.targetTexture.height), 0, 0);
            texture2D.Apply();
            return(texture2D);
        }
コード例 #3
0
        public static Transform LoadIcon(Transform iconPrefab, Transform icon, Vector3 localPosition, Vector3 localScale, Transform parent, int sortingOrderAdd, Color color, bool forGrid)
        {
            Transform transform = UnityEngine.Object.Instantiate <Transform>(iconPrefab, parent);

            transform.name          = icon.name + " (C)";
            transform.localPosition = localPosition;
            transform.localRotation = icon.localRotation;
            transform.localScale    = localScale;
            transform.gameObject.SetActive(icon.gameObject.activeSelf);
            if (icon.GetComponent <SpriteRenderer>() != null)
            {
                transform.GetComponent <SpriteRenderer>().sprite         = icon.GetComponent <SpriteRenderer>().sprite;
                transform.GetComponent <SpriteRenderer>().sortingOrder   = icon.GetComponent <SpriteRenderer>().sortingOrder + sortingOrderAdd;
                transform.GetComponent <SpriteRenderer>().drawMode       = icon.GetComponent <SpriteRenderer>().drawMode;
                transform.GetComponent <SpriteRenderer>().size           = icon.GetComponent <SpriteRenderer>().size;
                transform.GetComponent <SpriteRenderer>().sharedMaterial = icon.GetComponent <SpriteRenderer>().sharedMaterial;
                Color b = Color.white;
                if (forGrid)
                {
                    ColorModule component = icon.GetComponent <ColorModule>();
                    if (component != null)
                    {
                        b = component.buildColor;
                    }
                }
                transform.GetComponent <SpriteRenderer>().color = icon.GetComponent <SpriteRenderer>().color *color *b;
            }
            for (int i = 0; i < icon.childCount; i++)
            {
                PartGrid.LoadIcon(iconPrefab, icon.GetChild(i), icon.GetChild(i).localPosition, icon.GetChild(i).localScale, transform, sortingOrderAdd, color, forGrid);
            }
            return(transform);
        }
コード例 #4
0
        private void UpdateInactive()
        {
            List <PlacedPart> list = new List <PlacedPart>();

            for (int i = 0; i < this.inactiveParts.Count; i++)
            {
                if (Ref.hasPartsExpansion || !this.inactiveParts[i].partData.inFull)
                {
                    bool flag = false;
                    for (int j = 0; j < this.parts.Count; j++)
                    {
                        if (PlacedPart.IsOverplaing(this.inactiveParts[i], this.parts[j]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        UnityEngine.Object.Destroy(this.inactiveParts[i].partIcon.gameObject);
                        this.inactiveParts[i].partIcon = PartGrid.LoadIcon(this.iconPrefab, this.inactiveParts[i].partData.prefab, this.inactiveParts[i].position, this.inactiveParts[i].partData.prefab.localScale, base.transform, 0, this.inactiveParts[i].orientation, Color.white, true);
                        list.Add(this.inactiveParts[i]);
                        MonoBehaviour.print(this.inactiveParts[i].partData.name);
                        this.parts.Add(this.inactiveParts[i]);
                        this.inactiveParts.RemoveAt(i);
                        i--;
                    }
                }
            }
            for (int k = 0; k < list.Count; k++)
            {
                list[k].UpdateConnected(this.parts);
            }
        }
コード例 #5
0
        public void LoadBuild(List <PlacedPart> newParts, List <PlacedPart> newInactiveParts)
        {
            this.DeleteAllIcons();
            Vector2 zero  = Vector2.zero;
            Vector2 zero2 = Vector2.zero;

            PartGrid.GetMinMax(newParts, ref zero2, ref zero);
            Vector2 vector = new Vector2(Mathf.Max(0f, zero.x - this.width), Mathf.Max(0f, zero.y - (this.height - 0.5f)));
            Vector2 b      = new Vector2(Mathf.Min(zero2.x, vector.x), Mathf.Min(zero2.y, vector.y));

            for (int i = 0; i < newParts.Count; i++)
            {
                newParts[i].position -= b;
            }
            if (!Ref.hasPartsExpansion)
            {
                for (int j = 0; j < newParts.Count; j++)
                {
                    if (newParts[j].partData.inFull)
                    {
                        newInactiveParts.Add(newParts[j]);
                        newParts.RemoveAt(j);
                        j--;
                    }
                }
            }
            this.parts         = newParts;
            this.inactiveParts = newInactiveParts;
            this.LoadAllIcons();
        }
コード例 #6
0
 public void LoadHoldingIcon(int fingerId, Vector2 touchPosWorld)
 {
     this.LoadPartDescription(this.holdingParts[fingerId].part.partData);
     this.holdingParts[fingerId].part.partIcon = PartGrid.LoadIcon(this.buildGrid.iconPrefab, this.holdingParts[fingerId].part.partData.prefab, touchPosWorld, Vector3.one, null, 100, Color.white, false);
     this.holdingParts[fingerId].SetAsPickIcon();
     this.holdingParts[fingerId].FlipX(0f);
     this.holdingParts[fingerId].FlipX(0f);
 }
コード例 #7
0
 public void LoadAllIcons()
 {
     this.DeleteAllIcons();
     foreach (PlacedPart current in this.parts)
     {
         if (current.partData != null && current.partData.prefab != null)
         {
             current.partIcon = PartGrid.LoadIcon(this.iconPrefab, current.partData.prefab, current.position, current.partData.prefab.localScale, base.transform, 0, current.orientation);
         }
     }
     this.UpdateAllConnections();
 }
コード例 #8
0
        public static void CenterParts(List <PlacedPart> parts, Vector2 targetCenter)
        {
            Vector2 zero  = Vector2.zero;
            Vector2 zero2 = Vector2.zero;

            PartGrid.GetMinMax(parts, ref zero2, ref zero);
            Vector2 b = (zero2 + zero) / 2f - targetCenter;

            for (int i = 0; i < parts.Count; i++)
            {
                parts[i].position -= b;
            }
        }
コード例 #9
0
        public Build.HoldingPart TryTakePart(Vector2 mousePos, bool remove)
        {
            Vector2    vector     = (Vector3)mousePos - base.transform.position;
            PlacedPart placedPart = PartGrid.PointCastParts(vector, this.parts);

            if (placedPart == null)
            {
                return(null);
            }
            if (remove)
            {
                this.RemovePart(placedPart);
            }
            Ref.inputController.PlayClickSound(0.2f);
            return(new Build.HoldingPart(placedPart.position - vector, new PlacedPart(null, placedPart.position, placedPart.orientation.DeepCopy(), placedPart.partData)));
        }
コード例 #10
0
 public void PlacePart(PlacedPart newPart)
 {
     this.ClampToLimits(newPart);
     for (int i = this.parts.Count - 1; i >= 0; i--)
     {
         if (PlacedPart.IsOverplaing(newPart, this.parts[i]))
         {
             this.RemovePart(this.parts[i]);
         }
     }
     if (newPart.partData.prefab != null)
     {
         newPart.partIcon = PartGrid.LoadIcon(this.iconPrefab, newPart.partData.prefab, newPart.position, newPart.partData.prefab.localScale, base.transform, 0, newPart.orientation);
     }
     this.parts.Add(newPart);
     this.UpdateAllConnections();
     Ref.inputController.PlayClickSound(0.6f);
 }
コード例 #11
0
 public void LoadAllIcons()
 {
     this.DeleteAllIcons();
     for (int i = 0; i < this.parts.Count; i++)
     {
         if (this.parts[i].partData != null && this.parts[i].partData.prefab != null)
         {
             this.parts[i].partIcon = PartGrid.LoadIcon(this.iconPrefab, this.parts[i].partData.prefab, this.parts[i].position, this.parts[i].partData.prefab.localScale, base.transform, 0, this.parts[i].orientation, Color.white, true);
         }
     }
     for (int j = 0; j < this.inactiveParts.Count; j++)
     {
         if (this.inactiveParts[j].partData != null && this.inactiveParts[j].partData.prefab != null)
         {
             this.inactiveParts[j].partIcon = PartGrid.LoadIcon(this.iconPrefab, this.inactiveParts[j].partData.prefab, this.inactiveParts[j].position, this.inactiveParts[j].partData.prefab.localScale, base.transform, -50, this.inactiveParts[j].orientation, Color.white, true);
         }
     }
     this.UpdateAllConnections();
 }
コード例 #12
0
 public void PlacePart(PlacedPart newPart, bool placeActive)
 {
     this.ClampToLimits(newPart);
     this.CreateUndoSave();
     Ref.inputController.PlayClickSound(0.6f);
     if (placeActive)
     {
         for (int i = 0; i < this.parts.Count; i++)
         {
             if (PlacedPart.IsOverplaing(newPart, this.parts[i]))
             {
                 UnityEngine.Object.Destroy(this.parts[i].partIcon.gameObject);
                 this.parts[i].partIcon = PartGrid.LoadIcon(this.iconPrefab, this.parts[i].partData.prefab, this.parts[i].position, this.parts[i].partData.prefab.localScale, base.transform, -50, this.parts[i].orientation, Color.white, true);
                 this.inactiveParts.Add(this.parts[i]);
                 this.parts.RemoveAt(i);
                 i--;
             }
         }
         this.parts.Add(newPart);
         newPart.partIcon = PartGrid.LoadIcon(this.iconPrefab, newPart.partData.prefab, newPart.position, newPart.partData.prefab.localScale, base.transform, 0, newPart.orientation, Color.white, true);
         foreach (PartData.AttachmentSurface surfaceA in newPart.partData.attachmentSurfaces)
         {
             foreach (PlacedPart placedPart in this.parts)
             {
                 foreach (PartData.AttachmentSurface surfaceB in placedPart.partData.attachmentSurfaces)
                 {
                     if (PlacedPart.SurfacesConnect(newPart, surfaceA, placedPart, surfaceB) > 0f)
                     {
                         placedPart.UpdateConnected(this.parts);
                     }
                 }
             }
         }
     }
     else
     {
         this.inactiveParts.Add(newPart);
         newPart.partIcon = PartGrid.LoadIcon(this.iconPrefab, newPart.partData.prefab, newPart.position, newPart.partData.prefab.localScale, base.transform, -50, newPart.orientation, Color.white, true);
     }
     newPart.UpdateConnected(this.parts);
 }
コード例 #13
0
 public void LoadIcons()
 {
     this.DeleteIcons();
     for (int i = 0; i < this.width; i++)
     {
         for (int j = 0; j < this.height; j++)
         {
             int num = i * this.height + j;
             if (num <= this.pickList[this.selectedListId].parts.Count - 1)
             {
                 Transform transform = PartGrid.LoadIcon(this.iconPrefab, this.pickList[this.selectedListId].parts[num].prefab, new Vector2((float)i + 0.5f, (float)(-(float)j) - 0.5f) - this.pickList[this.selectedListId].parts[num].centerOfRotation * this.orientation * this.pickList[this.selectedListId].parts[num].pickGridScale, Vector2.one, base.transform, 50);
                 Orientation.ApplyOrientation(transform, this.orientation);
                 transform.localScale *= this.pickList[this.selectedListId].parts[num].pickGridScale;
                 this.icons.Add(transform.gameObject);
                 for (int k = 0; k < this.pickList[this.selectedListId].parts[num].attachmentSprites.Length; k++)
                 {
                     Utility.GetByPath(transform, this.pickList[this.selectedListId].parts[num].attachmentSprites[k].path).gameObject.SetActive(this.pickList[this.selectedListId].parts[num].attachmentSprites[k].showInPick);
                 }
             }
         }
     }
 }