Example #1
0
    public override void Register()
    {
        RegisterItem("add-script", "Add Script", scriptItPrefab, () =>
        {
            Debug.Log("Script added");
            var host       = pixel.GetScriptableHost();
            var scriptable = Scriptable.CreateInstanceAndAssignTo(host);
            hierarchyManager.CreateScript(scriptable.gameObject);
            scriptManager.ShowImplementedScriptPanel(host);
        });

        RegisterItem("edit-script", "Edit Script", scriptItPrefab, () =>
        {
            Debug.Log("Edit script");
            var host = !pixel.group.IsNotNull()
                ? GetComponent <ScriptableHost>()
                : pixel.GetFirstGroup().GetComponent <ScriptableHost>();
            scriptManager.ShowImplementedScriptPanel(host);
        });

        RegisterItem("toggle-pivot", "Toggle Pivot", () =>
        {
            Debug.Log("Toggle pivot");
            if (pixel.group.IsNotNull())
            {
                var firstGroup = pixel.GetFirstGroup();
                firstGroup.TogglePivot();
            }
            else
            {
                pixel.TogglePivot();
            }
        });

        RegisterItem("group", "Group", () =>
        {
            Debug.Log("Group");
            Group.Create();
            hierarchyManager.UpdatePixelPart();
        });

        RegisterItem("ungroup-one-by-one", "Ungroup", () =>
        {
            Debug.Log("Ungroup One-by-one");
            Group.UngroupOneByOne();
            hierarchyManager.UpdatePixelPart();
        });

        RegisterItem("ungroup-single", "Ungroup", () =>
        {
            Debug.Log("Ungroup Single");
            Group.UngroupSingle(pixel);
            hierarchyManager.UpdatePixelPart();
        });

        RegisterItem("ungroup-all", "Ungroup All", () =>
        {
            Debug.Log("Ungroup All");
            Group.Ungroup();
            hierarchyManager.UpdatePixelPart();
        });

        RegisterItem("create-prefab", "Create Prefab", () =>
        {
            Debug.Log("Create Prefab");
            // var pixels = FindObjectsOfType<Pixel>();
            // var selectedPixels = pixels.Where(x => x.selecting);
            var selectedPixels = PixelManager.instance.GetPixels(x => x.selecting);
            if (selectedPixels.Any())
            {
                var groupsAlreadyInPrefab = new List <Group>();
                var selectedPixelsToArray = selectedPixels.ToArray();
                foreach (var pixel in selectedPixelsToArray)
                {
                    var group = pixel.GetFirstGroup();
                    if (group.IsNotNull())
                    {
                        if (groupsAlreadyInPrefab.Any(x => x.id == group.id))
                        {
                            continue;
                        }
                        groupsAlreadyInPrefab.Add(group);
                        hierarchyManager.CreatePrefab(group.gameObject);
                        continue;
                    }
                    hierarchyManager.CreatePrefab(pixel.gameObject);
                }
                groupsAlreadyInPrefab.Clear();
                groupsAlreadyInPrefab = null;
                selectedPixelsToArray = null;
                selectedPixels        = null;
            }
            else
            {
                var group = pixel.GetFirstGroup();
                if (group.IsNotNull())
                {
                    hierarchyManager.CreatePrefab(group.gameObject);
                    return;
                }
                hierarchyManager.CreatePrefab(pixel.gameObject);
            }
        });

        RegisterItem("take-off", "Delete", takeOffPrefab, () =>
        {
            Debug.Log("Take Off");
            // PixelRemovingManager.instance.Remove();
            var selectedPixels = PixelManager.instance.GetPixels(x => x.selecting);
            if (selectedPixels.Any())
            {
                var potentialDeletingGroups = Group.GetManyGroups(selectedPixels);
                var it = selectedPixels.ToList();
                it.ForEach(x => x.Remove());
                var potentialDeletingGroupsIt = potentialDeletingGroups.Where(x => x.IsNotNull()).ToList();
                Debug.Log(potentialDeletingGroupsIt.Count);
                potentialDeletingGroupsIt.ForEach(group => group.Remove());
                potentialDeletingGroupsIt.Clear();
                potentialDeletingGroups = null;
            }
            else
            {
                pixel.Remove();
            }
            hierarchyManager.UpdatePixelPart();
        });
    }
Example #2
0
 public override void Register()
 {
     if (Constants.HIERARCHY_SCRIPT_PART.Equals(item.name))
     {
         RegisterItem("create-script", "Create script", () =>
         {
             Debug.Log("Script created.");
             var scriptable = Scriptable.CreateInstance();
             hierarchyManager.CreateScript(scriptable.gameObject);
             scriptManager.ShowUnimplementedScriptPanel(scriptable);
         });
     }
     if (!(Constants.HIERARCHY_PIXEL_PART.Equals(item.name) ||
           Constants.HIERARCHY_PREFAB_PART.Equals(item.name) ||
           Constants.HIERARCHY_SCRIPT_PART.Equals(item.name)))
     {
         if (item.originalParentId == hierarchyManager.scriptPart.id)
         {
             RegisterItem("edit-script", "Edit Script", () =>
             {
                 Debug.Log("Edit script.");
                 var itemRef = item.reference;
                 if (itemRef.IsNull())
                 {
                     return;
                 }
                 var scriptable = itemRef.GetComponent <Scriptable>();
                 scriptManager.ShowUnimplementedScriptPanel(scriptable);
             });
         }
         RegisterItem("rename", "Rename", () =>
         {
             Debug.Log("rename.");
             item.ToggleInputField();
         });
         RegisterItem("delete", "Delete", takeOffPrefab, () =>
         {
             if (item.originalParentId == 0)
             {
                 return;
             }
             if (item.originalParentId == hierarchyManager.prefabPart.id)
             {
                 var itemRef = item.reference;
                 if (itemRef.IsNotNull())
                 {
                     DestroyImmediate(itemRef.gameObject);
                 }
                 hierarchyManager.ClearPrefabPart(item.id);
             }
             // else if (item.originalParentId == hierarchyManager.pixelPart.id)
             // {
             //     var itemRef = item.reference;
             //     if (itemRef.IsNotNull())
             //     {
             //         var itemRefIsPixel = itemRef.GetComponent<Pixel>();
             //         if(itemRefIsPixel.IsNotNull())
             //         {
             //             itemRefIsPixel.Remove();
             //         }
             //         else
             //         {
             //             var itemRefIsGroup = itemRef.GetComponent<Group>();
             //             if(itemRefIsGroup.IsNotNull())
             //                 itemRefIsGroup.Remove();
             //         }
             //         hierarchyManager.ClearPixelPart(item.id);
             //         hierarchyManager.UpdatePixelPart();
             //     }
             // }
             else if (item.originalParentId == hierarchyManager.scriptPart.id)
             {
                 var itemRef = item.reference;
                 if (itemRef.IsNotNull())
                 {
                     var itemRefIsScriptable = itemRef.GetComponent <Scriptable>();
                     if (itemRefIsScriptable.IsNotNull())
                     {
                         itemRefIsScriptable.Remove();
                         hierarchyManager.ClearScriptPart(item.id);
                     }
                 }
             }
         });
     }
 }