Exemplo n.º 1
0
        private static void FindSimilarAnimations(UnityEditor.MenuCommand command)
        {
            var set = (DirectionalAnimationSet)command.context;

            UnityEditor.Undo.RecordObject(set, "Find Animations");

            var directory = UnityEditor.AssetDatabase.GetAssetPath(set);

            directory = Path.GetDirectoryName(directory);

            var guids = UnityEditor.AssetDatabase.FindAssets(
                $"{set.name} t:{nameof(AnimationClip)}",
                new string[] { directory });

            for (int i = 0; i < guids.Length; i++)
            {
                var path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[i]);
                var clip = UnityEditor.AssetDatabase.LoadAssetAtPath <AnimationClip>(path);
                if (clip == null)
                {
                    continue;
                }

                set.SetClipByName(clip);
            }
        }
Exemplo n.º 2
0
        static GrassBender CreateBender(UnityEditor.MenuCommand menuCommand)
        {
            GrassBender gb = CreateBender();

            UnityEditor.Selection.activeObject = gb.gameObject;
            return(gb);
        }
        private static void ToggleLooping(UnityEditor.MenuCommand command)
        {
            var set = (DirectionalAnimationSet)command.context;

            var count = set.ClipCount;

            for (int i = 0; i < count; i++)
            {
                var clip = set.GetClip(i);
                if (clip == null)
                {
                    continue;
                }

                var isLooping = !clip.isLooping;
                Debug.Log("Setting " + set.name + " clips to " + (isLooping ? "Looping" : "Not Looping") +
                          ". Note that you need to restart Unity for this change to take effect.", set);

                for (i = 0; i < count; i++)
                {
                    clip = set.GetClip(i);
                    if (clip == null)
                    {
                        continue;
                    }

                    Animancer.Editor.AnimancerEditorUtilities.SetLooping(clip, !clip.isLooping);
                }

                break;
            }
        }
        private static void ToggleLooping(UnityEditor.MenuCommand command)
        {
            var set = (DirectionalAnimationSet)command.context;

            var count = set.ClipCount;

            for (int i = 0; i < count; i++)
            {
                var clip = set.GetClip(i);
                if (clip == null)
                {
                    continue;
                }

                var isLooping = !clip.isLooping;
                for (i = 0; i < count; i++)
                {
                    clip = set.GetClip(i);
                    if (clip == null)
                    {
                        continue;
                    }

                    Animancer.Editor.AnimancerEditorUtilities.SetLooping(clip, isLooping);
                }

                break;
            }
        }
Exemplo n.º 5
0
        static void CreateCanvas(UnityEditor.MenuCommand menuCommand)
        {
            string canvasName = MASTER_CANVAS_NAME;

            UICanvas[] searchResults = FindObjectsOfType <UICanvas>();
            if (searchResults != null && searchResults.Length > 0)
            {
                bool renameRequired = true;
                int  canvasCount    = 0;
                while (renameRequired)
                {
                    renameRequired = false;
                    for (int i = 0; i < searchResults.Length; i++)
                    {
                        if (canvasName.Equals(searchResults[i].canvasName))
                        {
                            canvasCount++;
                            canvasName     = "UICanvas " + canvasCount;
                            renameRequired = true;
                            break;
                        }
                    }
                }
            }
            UICanvas canvas = UIManager.CreateCanvas(canvasName);

            UnityEditor.Undo.RegisterCreatedObjectUndo(canvas.gameObject, "Create " + canvas.gameObject.name);
            UnityEditor.Selection.activeObject = canvas.gameObject;
        }
Exemplo n.º 6
0
        public static void ConvertNGUIAtlasToUI(UnityEditor.MenuCommand command)
        {
            UIAtlas   atlas       = UnityEditor.Selection.activeGameObject.GetComponent <UIAtlas> ();
            Texture2D spriteSheet = atlas.texture as Texture2D;
            string    assetPath   = UnityEditor.AssetDatabase.GetAssetPath(spriteSheet.GetInstanceID());

            Debug.Log("Getting asset importer at path " + assetPath);
            UnityEditor.TextureImporter importer = UnityEditor.TextureImporter.GetAtPath(assetPath) as UnityEditor.TextureImporter;

            if (atlas == null || spriteSheet == null)
            {
                return;
            }
            List <UnityEditor.SpriteMetaData> spriteData = new List <UnityEditor.SpriteMetaData> ();

            List <string> spriteNames = atlas.GetListOfSprites();
            int           height      = spriteSheet.height;
            int           width       = spriteSheet.width;

            foreach (string spriteName in spriteNames)
            {
                UIAtlas.Sprite sprite = atlas.GetSprite(spriteName);
                //flip the positions
                Rect rect = sprite.outer;
                //Rect rect = new Rect (0, 0, 50, 50);
                rect.y = height - rect.y - rect.height;
                Vector2 pivot = new Vector2(0.5f, 0.5f);                 // = rect.center;
                //pivot.y = height - pivot.y;
                Vector4 border = Vector4.zero;

                /*if (sprite.hasPadding) {
                 *      border.w = sprite.inner.width;
                 *      border.x = sprite.paddingRight;
                 *      border.y = sprite.paddingTop;
                 *      border.z = sprite.paddingBottom;
                 * }*/
                UnityEditor.SpriteMetaData data = new UnityEditor.SpriteMetaData();
                data.border    = border;
                data.pivot     = pivot;
                data.rect      = rect;
                data.name      = spriteName;
                data.alignment = 0;
                Debug.Log("Created sprite " + spriteName + " with rect: "
                          + "xMin" + rect.xMin + ", "
                          + "xMax" + rect.xMax + ", "
                          + "yMin" + rect.yMin + ", "
                          + "yMax" + rect.yMax + "\n"
                          + "pivotx " + pivot.x + ", "
                          + "pivoty " + pivot.y);
                spriteData.Add(data);
            }

            importer.spriteImportMode = UnityEditor.SpriteImportMode.Multiple;
            importer.spritesheet      = spriteData.ToArray();

            //UnityEditor.AssetDatabase.StartAssetEditing ();
            UnityEditor.AssetDatabase.ImportAsset(importer.assetPath);
            //UnityEditor.AssetDatabase.StopAssetEditing ();
        }
Exemplo n.º 7
0
        public static void CreateImageObject(UnityEditor.MenuCommand command)
        {
            var gameObject = new GameObject("ExImage", typeof(ExImage));

            UnityEditor.GameObjectUtility.SetParentAndAlign(gameObject, command.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(gameObject, $"Create {gameObject.name}");
            UnityEditor.Selection.activeObject = gameObject;
        }
Exemplo n.º 8
0
        static void CreateCustomGameObject(UnityEditor.MenuCommand menuCommand)
        {
            GameObject go = new GameObject("New PlaymakerEventDispatcher", typeof(PlaymakerEventDispatcher));

            UnityEditor.GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 9
0
        private static void ClearDotInstances(UnityEditor.MenuCommand menuCommand)
        {
            var self = menuCommand.context as DotsScrollbar;

            if (self != null)
            {
                self.ClearDotInstances();
            }
        }
Exemplo n.º 10
0
    static void SelectReflectorTextureItemInWwisePicker(UnityEditor.MenuCommand command)
    {
        AkSurfaceReflector component = (AkSurfaceReflector)command.context;

        if (component.AcousticTextures.Length > 0 && component.AcousticTextures[0].ObjectReference != null)
        {
            SelectInWwisePicker(component.AcousticTextures[0].ObjectReference.Guid);
        }
    }
Exemplo n.º 11
0
        private static void SaveToIndex(UnityEditor.MenuCommand mc, int index)
        {
            PositionSwapper ps = mc.context as PositionSwapper;

            while (ps.Positions.Length <= index)
            {
                UnityEditor.ArrayUtility.Add <Vector3>(ref ps.Positions, Vector3.zero);
            }
            ps.Positions[index] = ps.transform.localPosition;
        }
Exemplo n.º 12
0
        private static void RecordPosition(UnityEditor.MenuCommand menuCommand)
        {
            var component = menuCommand.context as MoveTo;

            if (component == null)
            {
                return;
            }
            component.target = component.transform.localPosition;
        }
Exemplo n.º 13
0
        private static void RecordScale(UnityEditor.MenuCommand menuCommand)
        {
            var component = menuCommand.context as ScaleTo;

            if (component == null)
            {
                return;
            }
            component.scaleTo = component.transform.localScale;
        }
Exemplo n.º 14
0
        private static void RecordRotate(UnityEditor.MenuCommand menuCommand)
        {
            var component = menuCommand.context as RotateTo;

            if (component == null)
            {
                return;
            }
            component.eulerAngle = component.transform.localRotation.eulerAngles;
        }
Exemplo n.º 15
0
        private static void InvokeStartAnimation(UnityEditor.MenuCommand menuCommand)
        {
            var component = menuCommand.context as iTweenBehaviourBase;

            if (component == null)
            {
                return;
            }
            component.Initialize();
            component.StartAnimation();
        }
Exemplo n.º 16
0
    static void SelectItemInWwisePicker(UnityEditor.MenuCommand command)
    {
        AkTriggerHandler component = (AkTriggerHandler)command.context;

        try
        {
            var data = component.GetType().GetField("data");
            var guid = (data.GetValue(component) as AK.Wwise.BaseType).ObjectReference.Guid;
            SelectInWwisePicker(guid);
        }
        catch { }
    }
Exemplo n.º 17
0
        static GrassBender CreateWind(UnityEditor.MenuCommand menuCommand)
        {
            GrassBender gb = CreateBender("Wind");
            GameObject  go = gb.gameObject;

            go.transform.localScale = new Vector3(1, 1, 5);
            gb.Noise     = 1f;
            gb.Hardness  = 5f;
            gb.Direction = 1f;
            gb.Power     = 1f;
            UnityEditor.Selection.activeObject = go;
            return(gb);
        }
Exemplo n.º 18
0
        static void CreateTrigger(UnityEditor.MenuCommand menuCommand)
        {
            GameObject go = new GameObject("UITrigger", typeof(UITrigger));

            UnityEditor.GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            if (go.transform.root.GetComponent <RectTransform>() != null)
            {
                go.AddComponent <RectTransform>();
                go.GetComponent <RectTransform>().localScale = Vector3.one;
            }
            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 19
0
        private static void CreateComponentHoldingGameObject(UnityEditor.MenuCommand menuCommand)
        {
            if (FindObjectOfType <Verbose>() != null)
            {
                return;
            }
            var g = new GameObject("Reflect.Helpers.Verbose", new System.Type[1] {
                typeof(Verbose)
            });

            UnityEditor.GameObjectUtility.SetParentAndAlign(g, menuCommand.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(g, "Create Reflect Verbose");
        }
Exemplo n.º 20
0
        static InputFieldKZ Create(UnityEditor.MenuCommand mc)
        {
            Color      normalColor = new Color(0.85f, 0.85f, 0.85f, 1);
            GameObject g           = new GameObject("inpKZ_");

            UnityEditor.GameObjectUtility.SetParentAndAlign(g, mc.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(g, "Create " + g.name);
            UnityEditor.Selection.activeObject = g;

            Image image = g.AddComponent <Image>();

            image.sprite = UnityEditor.AssetDatabase
                           .GetBuiltinExtraResource <Sprite>("UI/Skin/InputFieldBackground.psd");
            image.type = Image.Type.Sliced;
            image.rectTransform.sizeDelta = new Vector2(160, 30);
            image.color = normalColor;

            Text field = new GameObject("txtField").AddComponent <Text>();
            Text caret = new GameObject("txtCaret").AddComponent <Text>();

            field.transform.SetParent(g.transform);
            caret.transform.SetParent(g.transform);

            field.color     = caret.color = Color.black;
            field.fontSize  = caret.fontSize = 14;
            field.alignment = caret.alignment = TextAnchor.MiddleLeft;
            field.rectTransform.anchorMin = caret.rectTransform.anchorMin = Vector2.zero;
            field.rectTransform.anchorMax = caret.rectTransform.anchorMax = Vector2.one;
            field.transform.localScale    = caret.transform.localScale = Vector3.one;

            Vector2 offset = Vector2.one * 5;

            field.rectTransform.offsetMin = caret.rectTransform.offsetMin = offset;
            field.rectTransform.offsetMax = caret.rectTransform.offsetMax = -offset;

            var kzInp = g.AddComponent <InputFieldKZ>();

            kzInp.settings = new InternalSettings()
            {
                imgBack  = image,
                txtField = field,
                txtCaret = caret
            };
            kzInp.colors = new InpColors()
            {
                normal   = normalColor,
                selected = Color.white
            };

            return(kzInp);
        }
Exemplo n.º 21
0
        static GrassBender CreateChildBender(UnityEditor.MenuCommand menuCommand)
        {
            GrassBender gb = CreateBender();

            if (UnityEditor.Selection.activeTransform != null)
            {
                gb.transform.SetParent(UnityEditor.Selection.activeTransform, false);
                gb.transform.localPosition = Vector3.zero;
                gb.transform.localRotation = Quaternion.identity;
                gb.transform.localScale    = Vector3.one;
            }
            UnityEditor.Selection.activeObject = gb.gameObject;
            return(gb);
        }
Exemplo n.º 22
0
        static void CreateSceneLoader(UnityEditor.MenuCommand menuCommand)
        {
            if (FindObjectOfType <SceneLoader>() != null)
            {
                Debug.Log("[Scene Loader] Cannot add another Scene Loader to this Scene because you don't need more than one.");
                UnityEditor.Selection.activeObject = FindObjectOfType <SceneLoader>();
                return;
            }

            GameObject go = new GameObject("SceneLoader", typeof(SceneLoader));

            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 23
0
        public static void Create(UnityEditor.MenuCommand menuCommand)
        {
            GameObject go = new GameObject("LocalizationManager");

            go.AddComponent <LocalizationManager>();

            // Ensure it gets reparented if this was a context click (otherwise does nothing)
            UnityEditor.GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            // Create a custom game object
            // Register the creation in the undo system
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);

            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 24
0
        public static void CreateVolume(UnityEditor.MenuCommand menuCommand)
        {
            PermanentBendingVolume[] volumes = FindObjectsOfType <PermanentBendingVolume>();
            if (volumes.Length > 0)
            {
                Debug.LogWarning("There are already " + volumes.Length + " bending volumes in this scene, keep in mind you can only use 1 at the time.");
            }

            GameObject             go  = new GameObject("Bending Volume");
            PermanentBendingVolume vol = go.AddComponent <PermanentBendingVolume>();

            vol.VolumeFromTerrains();
            UnityEditor.GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 25
0
        static GrassBender CreateCharacterBender(UnityEditor.MenuCommand menuCommand)
        {
            GrassBender gb = CreateBender("Character Bender");

            //gb.transform.localRotation = Quaternion.Euler(90, 0, 0);
            gb.Direction        = .9f;
            gb.Hardness         = 7f;
            gb.Power            = 3f;
            gb.PermanentBending = true;
            if (UnityEditor.Selection.activeTransform != null)
            {
                gb.transform.SetParent(UnityEditor.Selection.activeTransform, true);
                gb.AdaptToBounds(UnityEditor.Selection.activeTransform);
            }

            UnityEditor.Selection.activeObject = gb.gameObject;
            return(gb);
        }
Exemplo n.º 26
0
        static void CreateElement(UnityEditor.MenuCommand menuCommand)
        {
            UICanvas   targetCanvas = null;
            GameObject selectedGO   = menuCommand.context as GameObject;

            if (selectedGO != null)                                  //check that a gameObject is selected
            {
                targetCanvas = selectedGO.GetComponent <UICanvas>(); //check if the selected gameObject is an UICanvas, otherwise get the root and check
                if (targetCanvas == null)
                {
                    targetCanvas = selectedGO.transform.root.GetComponent <UICanvas>(); //check if there is an UICanvas on the root of the selected gameOhject
                }
            }
            if (targetCanvas == null) //because we did not find any UICanvas on the selected gameObject (or on it's root transform), we get the MasterCanvas; if the MasterCanvas does not exist, it will be created automatically by the system
            {
                targetCanvas = UIManager.GetMasterCanvas();
            }
            GameObject go = new GameObject("UIElement", typeof(RectTransform), typeof(UIElement));

            UnityEditor.GameObjectUtility.SetParentAndAlign(go, targetCanvas.gameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            go.GetComponent <UIElement>().Reset();
            go.GetComponent <RectTransform>().localScale = Vector3.one;
            go.GetComponent <RectTransform>().anchorMin  = Vector2.zero;
            go.GetComponent <RectTransform>().anchorMax  = Vector2.one;
            go.GetComponent <RectTransform>().sizeDelta  = Vector2.zero;
            go.GetComponent <RectTransform>().pivot      = new Vector2(0.5f, 0.5f);

            GameObject background = new GameObject("Background", typeof(RectTransform), typeof(Image));

            UnityEditor.GameObjectUtility.SetParentAndAlign(background, go);
            background.GetComponent <RectTransform>().localScale = Vector3.one;
            background.GetComponent <RectTransform>().anchorMin  = Vector2.zero;
            background.GetComponent <RectTransform>().anchorMax  = Vector2.one;
            background.GetComponent <RectTransform>().sizeDelta  = Vector2.zero;
            background.GetComponent <RectTransform>().pivot      = new Vector2(0.5f, 0.5f);
            background.GetComponent <Image>().sprite             = DUI.Background;
            background.GetComponent <Image>().type       = Image.Type.Sliced;
            background.GetComponent <Image>().fillCenter = true;
            background.GetComponent <Image>().color      = new Color(31f / 255f, 136f / 255f, 201f / 255f, 100f / 255f);

            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 27
0
        static void CreateEffect(UnityEditor.MenuCommand menuCommand)
        {
            GameObject selectedGO = menuCommand.context as GameObject;
            GameObject go         = new GameObject("New UIEffect", typeof(UIEffect));

            UnityEditor.GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            if (selectedGO != null && selectedGO.GetComponent <RectTransform>() != null)
            {
                go.AddComponent <RectTransform>();
                go.GetComponent <RectTransform>().localScale = Vector3.one;
                go.GetComponent <UIEffect>().targetUIElement = selectedGO.GetComponent <UIElement>();
                if (go.GetComponent <UIEffect>().targetUIElement != null)
                {
                    go.name = DUI.DUISettings.UIEffect_Inspector_RenameGameObjectPrefix + go.GetComponent <UIEffect>().targetUIElement.elementName + DUI.DUISettings.UIEffect_Inspector_RenameGameObjectSuffix;
                }
            }
            UnityEditor.Selection.activeObject = go;
        }
Exemplo n.º 28
0
        static int _m_AddComp_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                {
                    UnityEditor.MenuCommand _command = (UnityEditor.MenuCommand)translator.GetObject(L, 1, typeof(UnityEditor.MenuCommand));

                    Pathfinding.RadiusModifier.AddComp(_command);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        private static void ToggleLooping(UnityEditor.MenuCommand command)
        {
            var set = (DirectionalAnimationSet)command.context;

            var count = set.ClipCount;

            for (int i = 0; i < count; i++)
            {
                var clip = set.GetClip(i);
                if (clip == null)
                {
                    continue;
                }

                var isLooping = !clip.isLooping;
                Debug.Log("Setting " + set.name + " clips to " + (isLooping ? "Looping" : "Not Looping") +
                          ". Note that you need to restart Unity for this change to take effect.", set);

                for (i = 0; i < count; i++)
                {
                    clip = set.GetClip(i);
                    if (clip == null)
                    {
                        continue;
                    }

                    var settings = UnityEditor.AnimationUtility.GetAnimationClipSettings(clip);
                    settings.loopTime = isLooping;
                    UnityEditor.AnimationUtility.SetAnimationClipSettings(clip, settings);

                    // None of these let us avoid the need to restart Unity.
                    //AnimancerUtilities.SetDirty(clip);
                    //UnityEditor.AssetDatabase.SaveAssets();

                    //var path = UnityEditor.AssetDatabase.GetAssetPath(clip);
                    //UnityEditor.AssetDatabase.ImportAsset(path, UnityEditor.ImportAssetOptions.ForceUpdate);
                }

                break;
            }
        }
        private static SubUIButtonLayoutGroup EditorCreateButtonLayoutGroup <T>(UnityEditor.MenuCommand menuCommand) where T : LayoutGroup
        {
            GameObject             gameObject = new GameObject("ButtonLayoutGroup", typeof(RectTransform), typeof(T), typeof(ContentSizeFitter));
            SubUIButtonLayoutGroup btnLayout  = gameObject.AddComponent <SubUIButtonLayoutGroup>();

            LayoutGroup layoutGroup = gameObject.GetComponent <T>();

            btnLayout.layoutGroup = layoutGroup;

            GameObject itemTemplate = DefaultControls.CreateButton(EditorGetStandardResources());

            itemTemplate.name = "ItemTemplate";
            Text itemTemplateText = itemTemplate.GetComponentInChildren <Text>();

            itemTemplateText.text     = "Template Button";
            itemTemplateText.fontSize = 20;
            //itemTemplate.SetActive(false);
            itemTemplate.transform.SetParent(gameObject.transform, false);
            btnLayout.itemTemplate = itemTemplate;

            ContentSizeFitter fitter = gameObject.GetComponent <ContentSizeFitter>();

            fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            fitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

            GameObject parent = menuCommand.context as GameObject;

            if (parent != null)
            {
                gameObject.name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent.transform, gameObject.name);
            }
            UnityEditor.Undo.RegisterCreatedObjectUndo(gameObject, "Create" + gameObject.name);
            if (parent != null)
            {
                UnityEditor.Undo.SetTransformParent(gameObject.transform, parent.transform, "Parent" + gameObject.name);
                UnityEditor.GameObjectUtility.SetParentAndAlign(gameObject, parent);
            }

            UnityEditor.Selection.activeGameObject = gameObject;
            return(btnLayout);
        }