Skip to content

Instantly share code, notes, and snippets.

View Petethegoat's full-sized avatar
😍

Pete Goodfellow Petethegoat

😍
View GitHub Profile
using UnityEngine;
using UnityEditor;
public static class SelectScript
{
[MenuItem("CONTEXT/Component/Select Script File")]
static void SelectScriptFile(MenuCommand command)
{
Selection.activeObject = AssetDatabase.LoadAssetAtPath<MonoScript>(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets(MonoScript.FromMonoBehaviour(command.context as MonoBehaviour).name)[0]));
//Does not handle non monobehaviour/monoscript components.
@Petethegoat
Petethegoat / AnnotationUtilityEx.cs
Created November 30, 2023 15:41
Allow toggling gizmos and selection highlights via hotkey in the Unity Editor.
using System.Reflection;
using static System.Reflection.BindingFlags;
using UnityEditor;
using UnityEditor.ShortcutManagement;
//https://github.com/Unity-Technologies/UnityCsReference/blob/e740821767d2290238ea7954457333f06e952bad/Editor/Mono/Annotation/AnnotationUtility.bindings.cs
public static class AnnotationUtilityEx
{
[MenuItem("Tools/Editor/Toggle Gizmos & Selection Highlight"), Shortcut("Toggle Gizmos & Selection Highlight", UnityEngine.KeyCode.Space, ShortcutModifiers.Control)]
public static void ToggleSelectionOutlinesAndGizmos()
@Petethegoat
Petethegoat / RenameAttribute.cs
Created November 21, 2023 19:00 — forked from antonkudin/RenameAttribute.cs
Rename variable names inside your properties
using UnityEngine;
#if UNITY_EDITOR
[System.AttributeUsage(System.AttributeTargets.Field)]
public class RenameAttribute : PropertyAttribute
{
public string[] renamePairs;
public RenameAttribute(params string[] renamePairs)
{
@Petethegoat
Petethegoat / PivotSpaceButtons.cs
Last active February 4, 2024 05:20
Replacement for the stupid 2022 pivot/center and global/local button changes.
using UnityEngine.UIElements;
using UnityEditor;
using UnityEditor.Overlays;
using UnityEditor.Toolbars;
using System.Collections.Generic;
[Overlay(typeof(SceneView), "Pivot & Space Selection", defaultDisplay = true)]
public class PivotSpaceButtons : Overlay, ICreateToolbar
{
IEnumerable<string> ICreateToolbar.toolbarElements => k_ToolbarItems;
#include "TES3Birthsign.h"
#include "LuaManager.h"
#include "TES3ObjectLua.h"
namespace mwse {
namespace lua {
void bindTES3Birthsign() {
// Get our lua state.
auto stateHandle = LuaManager::getInstance().getThreadSafeStateHandle();
using UnityEngine;
using UnityEditor;
public class TextureArrayWizard : ScriptableWizard
{
[SerializeField] private Texture2D[] textures = null;
[MenuItem("Assets/Create/Texture Array")]
static void CreateWizard()
{
int num_valid_controls = 0;
cata::optional<tripoint> vehicle_position;
cata::optional<vpart_reference> vehicle_controls;
for( const tripoint elem : m.points_in_radius( g->u.pos(), 1 ) ) {
if( const optional_vpart_position vp = m.veh_at( elem ) ) {
vehicle_controls = *vp.part_with_feature( "CONTROLS", true );
if( vehicle_controls ) {
num_valid_controls++;
vehicle_position = elem;
}
local function dropPlayerItems()
local equippedItems = {}
for _, stack in pairs(tes3.player.object.equipment) do
table.insert(equippedItems, stack.object)
end
for _, object in pairs(equippedItems) do
--tes3.mobilePlayer:unequip{item = object}
end
tes3ui.forcePlayerInventoryUpdate()
local function onItemTileUpdated(e)
if e.item.objectType == tes3.objectType.book then
if e.item.type == tes3.bookType.scroll then
if e.item.enchantment then
for i = 1, #e.item.enchantment.effects do
if e.item.enchantment.effects[i].id >= 0 then
-- local icon = e.element:createImage({ path = string.format("icons\\sc\\scroll_%s", e.item.enchantment.effects[i].id) })
local icon = e.element:createImage({ path = string.format("icons\\%s", e.item.enchantment.effects[i].object.icon) })
icon.consumeMouseEvents = false
icon.width = 16
local scriptNames = {
-- Services
travel = "showTravelScript",
barter = "showBarterScript",
repair = "showRepairScript",
spells = "showSpellsScript",
training = "showTrainingScript",
spellmaking = "showSpellmakingScript",
enchanting = "showEnchantingScript",
companion = "showCompanionScript",