
C#
诗远
Unity,Cocos程序 游戏 开发。
喜欢折腾,软路由,nas,电视盒子。欢迎大家相互交流问题。
展开
-
基于Unity的PoissonDiscSampling泊松盘采样 随机分布位置不均匀的点
Unity 算法 根据长宽随机分布大小不均匀的位置点。原创 2023-02-21 11:17:40 · 626 阅读 · 0 评论 -
Unity 退出编辑器模式
Unity在编辑器模式下取消运行通过宏定义判断当前在什么环境下然后对其进行操作 #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif原创 2022-05-30 18:09:32 · 1370 阅读 · 0 评论 -
C# dictionary 自定义类型的containkey 方法实现
C# dictionary 自定义类型的containkey 方法实现https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.7.2参考博客https://blog.youkuaiyun.com/ghhong1988/article/details/110469145public class myVectorEqualityComparer : IEquali原创 2022-03-11 09:37:48 · 546 阅读 · 0 评论 -
C# Unity 随机概率刷权重 可更改 0-100 任意调整
class WeightedRandomBag<T>{ private struct Entry { public double accumulatedWeight; public T item; } private List<Entry> entries = new List<Entry>(); private double accumulatedWeight; private Sys原创 2021-11-11 18:59:04 · 4431 阅读 · 0 评论 -
在Unity中遍历一个物体节点下的所有物体
// Use this for initialization void Start() { GetAllChild(this.transform); } //使用队列实现 public void GetAllChild(Transform parent) { //队列存放需要被遍历的节点 //加入的逻辑为:当前节点的子节点,从第一个子节点到最后一个子节点顺序加入 Queue<Trans..原创 2021-08-30 15:32:34 · 1477 阅读 · 0 评论 -
Unity Shader Standard 带光照带透明通道
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)Shader "Standard (Specular setup)"{ Properties { _Color("Color", Color) = (1,1,1,1) _MainTex("Albedo", 2D) = "white" {} .原创 2021-06-10 11:49:57 · 583 阅读 · 2 评论 -
C# 实现红黑树
public class RBTree<K, V> : Map<K, V> where K : System.IComparable<K>{ private const bool RED = true; private const bool BLACK = false; public class Node { public K key; public V value; public N..原创 2021-05-16 23:32:41 · 572 阅读 · 0 评论 -
C# 实现并查集
路径压缩原创 2021-05-10 19:07:06 · 528 阅读 · 0 评论 -
C#实现 Trie 字典树公共前缀
public interface Map<K, V>{ void add(K key, V value); V remove(K key); bool contains(K key); V get(K key); void set(K key, V value); int getSize(); bool isEmpty();}public class BSTMap<K, V> : Map<K, V> wher.原创 2021-05-09 16:52:07 · 381 阅读 · 0 评论 -
C# 实现 基于二叉树 BSTMap 的映射(Map)实现
public interface Map<K, V>{ void add(K key, V value); V remove(K key); bool contains(K key); V get(K key); void set(K key, V value); int getSize(); bool isEmpty();}public class BSTMap<K, V> : Map<K, V> wh.原创 2021-05-09 16:48:43 · 491 阅读 · 0 评论 -
C# 实现 基于链表 LinkedListMap 的映射(Map)实现
public interface Map<K, V>{ void add(K key, V value); V remove(K key); bool contains(K key); V get(K key); void set(K key, V value); int getSize(); bool isEmpty();}public class LinkedListMap<K, V> : Map<K, V.原创 2021-05-09 16:46:39 · 488 阅读 · 0 评论 -
C# 实现 LeetCode 677. 键值映射
废了好大劲 用的二叉树结构 不会使用迭代器,就用Dictionary模拟了一下迭代器public interface Map<K, V>{ void add(K key, V value); V remove(K key); bool contains(K key); V get(K key); void set(K key, V value); int getSize(); bool isEmpty();}...原创 2021-05-09 15:34:59 · 331 阅读 · 0 评论 -
UploadStringTaskAsync outTime
public class WebClientto : WebClient { /// <summary> /// 过期时间 /// </summary> public int Timeout { get; set; } public WebClientto(int timeout = 6 * 1000) { Timeout = timeout; ...原创 2021-05-08 16:01:40 · 431 阅读 · 0 评论 -
C# 实现LeetCode 307. 区域和检索 - 数组可修改
public class NumArray{ public interface Merger<T> { T morge(T a, T b); } public class SegmentTree<T> { private T[] data; public T[] tree; private Merger<T> merger; public Se..原创 2021-05-07 00:09:27 · 283 阅读 · 0 评论 -
C# List通过List的属性新建一个List《属性》的List
using System.Linq;public List<BtnItem> normalrequest1 = new List<BtnItem>(); [Serializable] public struct BtnItem { public GameObjectButton GameObjectButton; public ObjType ObjType; public BtnType BtnType; .原创 2021-05-06 17:33:50 · 1502 阅读 · 0 评论 -
C# 实现 Leetcode203. 移除链表元素
创建一个虚拟头结点 从虚拟头结点去遍历public class Solution{ public ListNode RemoveElements(ListNode head, int val) { ListNode dummyHead = new ListNode(-1); dummyHead.next = head; ListNode prev = dummyHead; while (prev.next != ...原创 2021-05-04 11:51:45 · 341 阅读 · 0 评论 -
C# 实现单向链表
public class LinkedList<T>{ private class Node { public T data; public Node next; public Node(T data, Node next) { this.data = data; this.next = next; } public Node(T .原创 2021-05-04 10:35:56 · 412 阅读 · 0 评论 -
visual studio code 生成dll 注释 xml
开发Unity的过程中 为了方便都会封装dll 方便调用在使用的过程中会发现 没有代码注释,为此恨懊恼 ,就再网上找各种办法 说是要生成xml文件 我又去找相关资料 发现 只有visual studio 可以How to: Generate XML Documentation for a Project | Microsoft Docs我不服只好先用visual studio 打开 工程 勾选了xml 以后发现多了一句代码我把这段代码复制到百度上看到Roslyn 如何给每个平台.原创 2021-04-22 15:34:06 · 1264 阅读 · 0 评论 -
C# 实现线段树
线段树 第n层 的数量 2^(n-1)前n层的数量 2^n -1如果一个数组中有n个元素 存放在线段树中 开创 数组的大小应该为4npublic interface Merger<T>{ T morge(T a, T b);}public class SegmentTree<T>{ private T[] data; public T[] tree; private Merger<T> merger; ...原创 2021-04-20 19:28:50 · 411 阅读 · 0 评论 -
C# 实现希尔排序
public class ShellSort{ private ShellSort() { } public static void Sort<T>(T[] data) where T : System.IComparable<T> { int h = data.Length / 2; while (h >= 1) { for (var start = 0; start <.原创 2021-04-16 23:12:16 · 363 阅读 · 0 评论 -
Unity C# Encoding 936 data could not be found. Make sure you have correct internation
字面意思编码936的数据找不到。请确保已安装并启用了正确的国际代码集程序集。Plugins文件夹缺少dll原创 2021-04-15 19:04:12 · 1737 阅读 · 0 评论 -
C#实现冒泡排序
using System;public class BubbleSort{ private BubbleSort() { } public static void Sort<T>(T[] data) where T : IComparable { for (var i = 0; i < data.Length;) { int lastSwapIndex = 0; /.原创 2021-04-04 00:17:54 · 338 阅读 · 0 评论 -
C# PriorityQueue 优先队列
using System;using System.Collections.Generic;/// <summary>/// 最大堆 优先级/// </summary>/// <typeparam name="T"></typeparam>public class MaxHeap<T> where T : IComparable<T>{ public List<T> data; publ.原创 2021-04-03 22:36:03 · 1308 阅读 · 0 评论 -
C# 实现 215. 数组中的第K个最大元素
使用双路快速排序实现public class Solution { public int FindKthLargest(int[] nums, int k) { System.Random random = new System.Random(); return selectK(nums, 0, nums.Length , random, nums.Length - k); } public int selectK(int[] arr, in.原创 2021-04-03 22:24:52 · 351 阅读 · 0 评论 -
C# 实现 剑指 Offer 40. 最小的k个数
快速排序 求得结果public class Solution { public int[] GetLeastNumbers(int[] arr, int k) { if (k == 0) return new int[0] { }; System.Random random = new System.Random(); selectK(arr, 0, arr.Length - 1, random, k); int[] .原创 2021-04-03 22:03:58 · 344 阅读 · 0 评论 -
C# 实现最小堆
using System;using System.Collections.Generic;/// <summary>/// 最大堆 优先级/// </summary>/// <typeparam name="T"></typeparam>public class MinHeap<T> where T : IComparable<T>{ public List<T> data; publ.原创 2021-04-03 21:12:54 · 374 阅读 · 0 评论 -
C# 实现二分查找法 二分搜索树
using System.Collections;using System.Collections.Generic;using System.Text;/// <summary>/// 二分搜索树/// </summary>public class BST<T> where T : System.IComparable<T>{ public class Node { public T data; ..原创 2021-04-03 19:43:04 · 460 阅读 · 0 评论 -
C# 实现最大堆 用于优先级排序 堆排序
using System;using System.Text;namespace myCode{ class Program { static void Main(string[] args) { //回文.LongestPalindrome("mmmmmmm"); // XXCZ(); //TestNumber(); // TestGenerate().原创 2021-04-02 00:15:49 · 424 阅读 · 0 评论 -
Unity localEulerAngles 获取的和Inspector面板不一致
//获取到旋转的正确数值 public Vector3 GetInspectorRotationValueMethod(Transform transform) { // 获取原生值 System.Type transformType = transform.GetType(); PropertyInfo m_propertyInfo_rotationOrder = transformType.GetProperty("rotatio...原创 2021-03-30 17:03:19 · 2031 阅读 · 1 评论 -
Unity 用鼠标拖动3D物体 跟随鼠标移动
public class MouseMove : MonoBehaviour{ //鼠标经过时改变物体颜色 private Color mouseOverColor = Color.blue;//声明变量为蓝色 private Color originalColor;//声明变量来存储本来颜色 void Start() { originalColor = renderer.sharedMaterial.color;//开始时得到物体着色 .原创 2021-03-24 08:53:08 · 2511 阅读 · 0 评论 -
C# 实现快速排序 双路快速排序 三路快速排序
从左向右依次递归 如果 数组中的元素都相等,就会变成 n²级别的复杂度算法public class QuickSort{ private QuickSort() { } public static void Sort<T>(T[] arr) where T : System.IComparable<T> { Sort(arr, 0, arr.Length - 1 , new System.Random() ); }原创 2021-02-16 16:47:47 · 291 阅读 · 0 评论 -
C#实现 剑指 Offer 51. 数组中的逆序对
题目https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/归并排序参考https://mp.youkuaiyun.com/editor/html/112734224代码public class Solution{ public int res = 0; public int ReversePairs(int[] nums) { res = 0; int[] ..原创 2021-02-15 13:53:50 · 256 阅读 · 0 评论 -
C# 实现选择排序
实现方式。using System;public class SelectionSort{ private SelectionSort() { } public static void Sort<T>(T[] arr) where T : IComparable<T> { for (var i = 0; i < arr.Length; i++) { int...原创 2021-02-09 13:26:52 · 297 阅读 · 0 评论 -
C# 实现插入排序
插入排序using System;public class InsertionSort{ private InsertionSort() { } public static void Sort<T>(T[] data) where T : IComparable<T> { for (var i = 0; i < data.Length; i++) { for (var j = i;原创 2021-02-09 11:46:23 · 632 阅读 · 0 评论 -
Unity3D-Color与十六进制颜色互相转换
Unity中已经提供了现成的方法,可以直接调用:ColorUtility.TryParseHtmlString:传入的字符串是 “#FFFFFF”的格式,用法如下:Color nowColor;ColorUtility.TryParseHtmlString("#FECEE1", out nowColor);Color转回去使用下面的方法:ColorUtility.ToHtmlStringRGB:传入的是一个Color结构体,返回一个字符串,形式是“FFFFFF”,用法如下:inpu原创 2021-02-05 14:19:54 · 1677 阅读 · 0 评论 -
Unity 鼠标拖动图片
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;public class ShiYuanOnDrag : UIBehaviour, IDragHandler, IPointerDownHandler, IEndDragHandler, IBeginDragHandler{ RectTransform _rectTransf.原创 2021-02-04 15:48:35 · 702 阅读 · 0 评论 -
Unity 多个Camera融合 合并截一张图
插件Ultimate Screenshot Creator 1.4.3原创 2021-01-28 14:53:12 · 1917 阅读 · 0 评论 -
C# 实现归并算法
源码using System;using System.Text;public class 归并{ private 归并() { } private static int depth = 0; public static void Sort<T>(T[] arr) where T : IComparable<T> { Sort(arr, 0, arr.Length - 1); depth.原创 2021-01-17 11:38:44 · 360 阅读 · 0 评论 -
C#如何测试代码运行时间
方法1System.Diagnostics.Stopwatch stopwatch = new Stopwatch();stopwatch.Start(); // 开始监视代码运行时间// 需要测试的代码 ....stopwatch.Stop(); // 停止监视TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间double hours = timespan.TotalHours; // 总小时double minute原创 2021-01-03 13:48:59 · 1652 阅读 · 0 评论 -
Unity Slider OnBeginDrag OnEndDrag 开始拖动结束拖动的事件监听
重写 Slider 继承IBeginDragHandler,IEndDragHandler接口using UnityEngine.UI;using UnityEngine.EventSystems;using System;public class MySlider : Slider, IBeginDragHandler, IEndDragHandler{ public Action beiginDrag { get; set; } public Action end..原创 2020-12-10 09:06:27 · 4162 阅读 · 0 评论