Esempio n. 1
0
        // This method is used by Component specific classes (e.g. ChiselBoxEditor)
        // to create a menu Item that creates a gameObject with a specific component (e.g. ChiselBox)
        // Since MenuItems can only be created with attributes, and strings must be constant,
        // we can only do this from place where we specifically know which component the menu is for.
        protected static void CreateAsGameObjectMenuCommand(MenuCommand menuCommand, string name)
        {
            T   component;
            var parentGameObject = (menuCommand.context as GameObject) ?? Selection.activeGameObject;
            var parentTransform  = parentGameObject?.transform;

            if (parentTransform &&
                parentTransform.GetComponent <ChiselGeneratorComponent>())
            {
                parentTransform = parentTransform.parent;
            }

            if (parentTransform)
            {
                component = ChiselComponentFactory.Create <T>(name, parentTransform);
            }
            else
            {
                if (typeof(T) == typeof(ChiselModel))
                {
                    component = ChiselComponentFactory.Create <T>(name);
                }
                else
                {
                    component = ChiselComponentFactory.Create <T>(name, ChiselModelManager.GetActiveModelOrCreate());
                }
            }

            var gameObject = component.gameObject;

            GameObjectUtility.SetParentAndAlign(gameObject, parentTransform?.gameObject);
            Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name);
            Selection.activeObject = gameObject;
        }
        // This method is used by Component specific classes (e.g. ChiselBoxEditor)
        // to create a menu Item that creates a gameObject with a specific component (e.g. ChiselBox)
        // Since MenuItems can only be created with attributes, and strings must be constant,
        // we can only do this from place where we specifically know which component the menu is for.
        protected static void CreateAsGameObjectMenuCommand(MenuCommand menuCommand, string name)
        {
            var component  = ChiselComponentFactory.Create <T>(name, ChiselModelManager.GetActiveModelOrCreate());
            var gameObject = component.gameObject;

            GameObjectUtility.SetParentAndAlign(gameObject, menuCommand.context as GameObject);
            Undo.RegisterCreatedObjectUndo(gameObject, "Create " + gameObject.name);
            Selection.activeObject = gameObject;
        }