精华内容
下载资源
问答
  • !!!!百度云资源 !!!!商业项目 暗影之枪Unity源码 商业项目 暗影之枪Unity源码
  • 超级马里奥64HD版unity源码,有兴趣可以下载学习一下。
  • 淘宝买的,unity源码,大富豪源码(完整棋牌服务端(c++)+客户端(unity)+各种编译),是能用的,自己打开编译过。适合二次开发
  • 30Unity源码.txt

    2019-11-12 16:09:04
    unity的30套游戏源码还有其它 的各种源码,需要的来拿走吧,需要的来拿走吧,如果下载不了可以找我
  • unity 折叠菜单。 源码案例, 直接看代码即可。 代码简单, 直接拖入摄像机 即可使用。 适合初学者,不喜勿喷,谢谢支持。
  • 泰斗破坏神 Unity 源码

    2018-03-03 02:12:39
    TaidouARPGProject 很有参考价值 大家可以看下
  • Unity蓝牙通信测试DEMO
  • Unity开发2048游戏,自己做的,有原项目资源包,还有安卓APK,逻辑部分全在Logic脚本中。APK没有做自适应,分辨率为:1280*720。
  • 1.遍历,List可以 for 可以 foreach 还可以.ForEach(),而 Dictionary只能foreach (Unity某些版本使用foreach会由于拆装箱产生GC)。List的遍历顺序就是元素的添加顺序,Dictionary是Hash方式存储的,所以遍历时无法....

    List 和 Dictionary,是最常用的数据结构之二。

    先来看看List 和 Dictionary的优缺点:
    1.遍历,List可以 for 可以 foreach 还可以.ForEach(),而 Dictionary只能foreach (Unity某些版本使用foreach会由于拆装箱产生GC)。List的遍历顺序就是元素的添加顺序,Dictionary是Hash方式存储的,所以遍历时无法保证顺序。
    2.List是支持排序的(key为固定的整数索引)。可以直接调Sort()、Reverse()等方法, Dictionary不支持(key类型不确定)。
    3.List查找慢,需要遍历,时间复杂度是 O(n), Dictionary查找快,使用哈希查找方式,时间复杂度为 O(1)。
    4.List 移除效率低,内部由数组实现并非链表。 Remove(item)需要先遍历查找到对应的index,RemoveAt(index)方法需要从在移除index处的元素后,后边的元素依次向前补位。在List长度较长甚至同时需要多次移除时,对性能影响较大。
    msdn List 源码地址
    msdn Dictionary 源码地址

    --------------------NRatel割--------------------

    今天看UGUI源码时发现,Unity UnityEngine.UI.Collections 命名空间下实现了一个IndexedSet类,比较巧妙地吸取了List 和 Dictionary各自的优点。当然也不是完美的)。

    代码比较简单。这里我对它的注释做一下解释。

    这是这样的一个容器:
    1.items 都是唯一的 (item必须唯一,因为要用item作为字典的key, 这样带来的好处是查找变成了快速的hash查找方式)。
    2.快速随机移除 (移除时Remove不需要再先做线性查找了。RemoveAt将要移除的元素与尾部元素换位,然后移除尾部,避免了后边元素依次向前补位。这块其实也打乱了原来的排序,不过问题不大,如果想要恢复排序。可以在所有移除进行完之后执行一次Sort)
    3.Fast unique inclusion to the end (暂时没明白这句话的意思, 知道的可以留言告诉我)
    4.顺序访问(支持通过index查找,支持有序,支持灵活的遍历方式)

    缺点:
    1占用更多的内存。 (没办法,本来只用存一份,现在要列表中一份,字典中一份)
    2排序是非永久的。(移除操作为了提升效率,会打乱排序)
    3不易序列化. (因为是组合的数据结构)

    可以在符合上述条件的、恰当的情况下使用它。
    由于它是 internal class,不能直接调它的实现,可以拷贝一份出来再用。

    最后,贴上 IndexedSet 的源码,(纯粘贴自 Unity 2017.3.1f1)

    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    namespace UnityEngine.UI.Collections
    {
        internal class IndexedSet<T> : IList<T>
        {
            //This is a container that gives:
            //  - Unique items
            //  - Fast random removal
            //  - Fast unique inclusion to the end
            //  - Sequential access
            //Downsides:
            //  - Uses more memory
            //  - Ordering is not persistent
            //  - Not Serialization Friendly.
    
            //We use a Dictionary to speed up list lookup, this makes it cheaper to guarantee no duplicates (set)
            //When removing we move the last item to the removed item position, this way we only need to update the index cache of a single item. (fast removal)
            //Order of the elements is not guaranteed. A removal will change the order of the items.
    
            readonly List<T> m_List = new List<T>();
            Dictionary<T, int> m_Dictionary = new Dictionary<T, int>();
    
            public void Add(T item)
            {
                if (m_Dictionary.ContainsKey(item))
                    return;
    
                m_List.Add(item);
                m_Dictionary.Add(item, m_List.Count - 1);
            }
    
            public bool Remove(T item)
            {
                int index = -1;
                if (!m_Dictionary.TryGetValue(item, out index))
                    return false;
    
                RemoveAt(index);
                return true;
            }
    
            public IEnumerator<T> GetEnumerator()
            {
                throw new System.NotImplementedException();
            }
    
            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
    
            public void Clear()
            {
                m_List.Clear();
                m_Dictionary.Clear();
            }
    
            public bool Contains(T item)
            {
                return m_Dictionary.ContainsKey(item);
            }
    
            public void CopyTo(T[] array, int arrayIndex)
            {
                m_List.CopyTo(array, arrayIndex);
            }
    
            public int Count { get { return m_List.Count; } }
            public bool IsReadOnly { get { return false; } }
            public int IndexOf(T item)
            {
                int index = -1;
                m_Dictionary.TryGetValue(item, out index);
                return index;
            }
    
            public void Insert(int index, T item)
            {
                //We could support this, but the semantics would be weird. Order is not guaranteed..
                throw new NotSupportedException("Random Insertion is semantically invalid, since this structure does not guarantee ordering.");
            }
    
            public void RemoveAt(int index)
            {
                T item = m_List[index];
                m_Dictionary.Remove(item);
                if (index == m_List.Count - 1)
                    m_List.RemoveAt(index);
                else
                {
                    int replaceItemIndex = m_List.Count - 1;
                    T replaceItem = m_List[replaceItemIndex];
                    m_List[index] = replaceItem;
                    m_Dictionary[replaceItem] = index;
                    m_List.RemoveAt(replaceItemIndex);
                }
            }
    
            public T this[int index]
            {
                get { return m_List[index]; }
                set
                {
                    T item = m_List[index];
                    m_Dictionary.Remove(item);
                    m_List[index] = value;
                    m_Dictionary.Add(item, index);
                }
            }
    
            public void RemoveAll(Predicate<T> match)
            {
                //I guess this could be optmized by instead of removing the items from the list immediatly,
                //We move them to the end, and then remove all in one go.
                //But I don't think this is going to be the bottleneck, so leaving as is for now.
                int i = 0;
                while (i < m_List.Count)
                {
                    T item = m_List[i];
                    if (match(item))
                        Remove(item);
                    else
                        i++;
                }
            }
    
            //Sorts the internal list, this makes the exposed index accessor sorted as well.
            //But note that any insertion or deletion, can unorder the collection again.
            public void Sort(Comparison<T> sortLayoutFunction)
            {
                //There might be better ways to sort and keep the dictionary index up to date.
                m_List.Sort(sortLayoutFunction);
                //Rebuild the dictionary index.
                for (int i = 0; i < m_List.Count; ++i)
                {
                    T item = m_List[i];
                    m_Dictionary[item] = i;
                }
            }
        }
    }
    
    

    --------------------NRatel割--------------------
    NRatel
    转载请说明出处,谢谢

    展开全文
  • unity源码解析Component

    千次阅读 2016-04-06 11:32:36
    Component 这个没有声明好说的,因为他的方法实现基本都在GameObject中,就是上一篇中的额内容,就单单贴出源码好了 using System; using System.Collections.Generic; using System.Runtime.CompilerServices; ...

    Component 这个没有声明好说的,因为他的方法实现基本都在GameObject中,就是上一篇中的额内容,就单单贴出源码好了

    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using UnityEngine.Internal;
    using UnityEngineInternal;
    
    namespace UnityEngine
    {
    	public class Component : Object
    	{
    		public Transform transform
    		{
    			get
    			{
    				return this.InternalGetTransform();
    			}
    		}
    
    		public extern Rigidbody rigidbody
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Rigidbody2D rigidbody2D
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Camera camera
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Light light
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Animation animation
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern ConstantForce constantForce
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Renderer renderer
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern AudioSource audio
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern GUIText guiText
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern NetworkView networkView
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		[Obsolete("Please use guiTexture instead")]
    		public extern GUIElement guiElement
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern GUITexture guiTexture
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Collider collider
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern Collider2D collider2D
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern HingeJoint hingeJoint
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern ParticleEmitter particleEmitter
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public extern ParticleSystem particleSystem
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    		}
    
    		public GameObject gameObject
    		{
    			get
    			{
    				return this.InternalGetGameObject();
    			}
    		}
    
    		[Obsolete("the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead.")]
    		public extern bool active
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			set;
    		}
    
    		public extern string tag
    		{
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			get;
    			[WrapperlessIcall]
    			[MethodImpl(MethodImplOptions.InternalCall)]
    			set;
    		}
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		internal extern Transform InternalGetTransform();
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		internal extern GameObject InternalGetGameObject();
    
    		[WrapperlessIcall, TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		public extern Component GetComponent(Type type);
    
    		public T GetComponent<T>() where T : Component
    		{
    			return this.GetComponent(typeof(T)) as T;
    		}
    
    		public Component GetComponent(string type)
    		{
    			return this.gameObject.GetComponent(type);
    		}
    
    		[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    		public Component GetComponentInChildren(Type t)
    		{
    			return this.gameObject.GetComponentInChildren(t);
    		}
    
    		public T GetComponentInChildren<T>() where T : Component
    		{
    			return (T)((object)this.GetComponentInChildren(typeof(T)));
    		}
    
    		[ExcludeFromDocs]
    		public Component[] GetComponentsInChildren(Type t)
    		{
    			bool includeInactive = false;
    			return this.GetComponentsInChildren(t, includeInactive);
    		}
    
    		public Component[] GetComponentsInChildren(Type t, [DefaultValue("false")] bool includeInactive)
    		{
    			return this.gameObject.GetComponentsInChildren(t, includeInactive);
    		}
    
    		public T[] GetComponentsInChildren<T>(bool includeInactive) where T : Component
    		{
    			return this.gameObject.GetComponentsInChildren<T>(includeInactive);
    		}
    
    		public void GetComponentsInChildren<T>(bool includeInactive, List<T> result) where T : Component
    		{
    			this.gameObject.GetComponentsInChildren<T>(includeInactive, result);
    		}
    
    		public T[] GetComponentsInChildren<T>() where T : Component
    		{
    			return this.GetComponentsInChildren<T>(false);
    		}
    
    		public void GetComponentsInChildren<T>(List<T> results) where T : Component
    		{
    			this.GetComponentsInChildren<T>(false, results);
    		}
    
    		[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    		public Component GetComponentInParent(Type t)
    		{
    			return this.gameObject.GetComponentInParent(t);
    		}
    
    		public T GetComponentInParent<T>() where T : Component
    		{
    			return (T)((object)this.GetComponentInParent(typeof(T)));
    		}
    
    		[ExcludeFromDocs]
    		public Component[] GetComponentsInParent(Type t)
    		{
    			bool includeInactive = false;
    			return this.GetComponentsInParent(t, includeInactive);
    		}
    
    		public Component[] GetComponentsInParent(Type t, [DefaultValue("false")] bool includeInactive)
    		{
    			return this.gameObject.GetComponentsInParent(t, includeInactive);
    		}
    
    		public T[] GetComponentsInParent<T>(bool includeInactive) where T : Component
    		{
    			return this.gameObject.GetComponentsInParent<T>(includeInactive);
    		}
    
    		public T[] GetComponentsInParent<T>() where T : Component
    		{
    			return this.GetComponentsInParent<T>(false);
    		}
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		public extern Component[] GetComponents(Type type);
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		private extern Component[] GetComponentsWithCorrectReturnType(Type type);
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		private extern void GetComponentsForListInternal(Type searchType, Type listElementType, bool recursive, bool includeInactive, object resultList);
    
    		public T[] GetComponents<T>() where T : Component
    		{
    			return (T[])this.GetComponentsWithCorrectReturnType(typeof(T));
    		}
    
    		public void GetComponents(Type type, List<Component> results)
    		{
    			this.GetComponentsForListInternal(type, typeof(Component), false, true, results);
    		}
    
    		public void GetComponents<T>(List<T> results) where T : Component
    		{
    			this.GetComponentsForListInternal(typeof(T), typeof(T), false, true, results);
    		}
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		public extern bool CompareTag(string tag);
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		public extern void SendMessageUpwards(string methodName, [DefaultValue("null")] object value, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    
    		[ExcludeFromDocs]
    		public void SendMessageUpwards(string methodName, object value)
    		{
    			SendMessageOptions options = SendMessageOptions.RequireReceiver;
    			this.SendMessageUpwards(methodName, value, options);
    		}
    
    		[ExcludeFromDocs]
    		public void SendMessageUpwards(string methodName)
    		{
    			SendMessageOptions options = SendMessageOptions.RequireReceiver;
    			object value = null;
    			this.SendMessageUpwards(methodName, value, options);
    		}
    
    		public void SendMessageUpwards(string methodName, SendMessageOptions options)
    		{
    			this.SendMessageUpwards(methodName, null, options);
    		}
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		public extern void SendMessage(string methodName, [DefaultValue("null")] object value, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    
    		[ExcludeFromDocs]
    		public void SendMessage(string methodName, object value)
    		{
    			SendMessageOptions options = SendMessageOptions.RequireReceiver;
    			this.SendMessage(methodName, value, options);
    		}
    
    		[ExcludeFromDocs]
    		public void SendMessage(string methodName)
    		{
    			SendMessageOptions options = SendMessageOptions.RequireReceiver;
    			object value = null;
    			this.SendMessage(methodName, value, options);
    		}
    
    		public void SendMessage(string methodName, SendMessageOptions options)
    		{
    			this.SendMessage(methodName, null, options);
    		}
    
    		[WrapperlessIcall]
    		[MethodImpl(MethodImplOptions.InternalCall)]
    		public extern void BroadcastMessage(string methodName, [DefaultValue("null")] object parameter, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    
    		[ExcludeFromDocs]
    		public void BroadcastMessage(string methodName, object parameter)
    		{
    			SendMessageOptions options = SendMessageOptions.RequireReceiver;
    			this.BroadcastMessage(methodName, parameter, options);
    		}
    
    		[ExcludeFromDocs]
    		public void BroadcastMessage(string methodName)
    		{
    			SendMessageOptions options = SendMessageOptions.RequireReceiver;
    			object parameter = null;
    			this.BroadcastMessage(methodName, parameter, options);
    		}
    
    		public void BroadcastMessage(string methodName, SendMessageOptions options)
    		{
    			this.BroadcastMessage(methodName, null, options);
    		}
    	}
    }

    具体可以参考上一篇博客中Gameobject的实现


    展开全文
  • unity源码解析Texture

    千次阅读 2016-05-07 22:00:34
    Texture类继承自Object是作为一个Texture2D与Texture3D的基类存在的,一般也并不直接使用它,且其本身也并没有对纹理数据的存储 using System; using System.Runtime.CompilerServices; namespace UnityEngine ...

    Texture类继承自Object是作为一个Texture2D与Texture3D的基类存在的,一般也并不直接使用它,且其本身也并没有对纹理数据的管理,只有一个,就是获取纹理的id

    using System;
    using System.Runtime.CompilerServices;

    namespace UnityEngine
    {
        public class Texture : Object
        {
            public static extern int masterTextureLimit
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public static extern AnisotropicFiltering anisotropicFiltering
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public virtual int width
            {
                get
                {
                    return Texture.Internal_GetWidth(this);
                }
                set
                {
                    throw new Exception("not implemented");
                }
            }

            public virtual int height
            {
                get
                {
                    return Texture.Internal_GetHeight(this);
                }
                set
                {
                    throw new Exception("not implemented");
                }
            }

            public extern FilterMode filterMode
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public extern int anisoLevel
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public extern TextureWrapMode wrapMode
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public extern float mipMapBias
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public Vector2 texelSize
            {
                get
                {
                    Vector2 result;
                    Texture.Internal_GetTexelSize(this,out result);
                    return result;
                }
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public static extern void SetGlobalAnisotropicFilteringLimits(int forcedMin,int globalMax);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern int Internal_GetWidth(Texture mono);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern int Internal_GetHeight(Texture mono);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern void Internal_GetTexelSize(Texture tex,out Vector2 output);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern IntPtr GetNativeTexturePtr(); //读取本地文件生成的Texture获取指针,可以为Texture2d的创建提供数据

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern int GetNativeTextureID();
        }
    }

    展开全文
  • unity源码解析Transform

    千次阅读 2016-04-06 15:27:42
    Transform这个类继承自Component, IEnumerable。我们在开发的过程中之所以可以对Transform进行foreach,就是因为它实现了IEnumerable抽象方法GetEnumerator,该方法返回一个IEnumerator,而通过重写了IEnumerator中...

    Transform这个类继承自Component, IEnumerable。我们在开发的过程中之所以可以对Transform进行foreach,就是因为它实现了IEnumerable抽象方法GetEnumerator,该方法返回一个IEnumerator,而通过重写了IEnumerator中的Current,可以依次获得子对象。废话不多说了

    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;
    using UnityEngine.Internal;

    namespace UnityEngine
    {
        public class Transform : Component, IEnumerable
        {
            private sealed class Enumerator : IEnumerator
            {
                private Transform outer;

                private int currentIndex = -1;

                public object Current
                {
                    get
                    {
                        return this.outer.GetChild(this.currentIndex);
                    }
                }

                internal Enumerator(Transform outer)
                {
                    this.outer = outer;
                }

                public bool MoveNext()
                {
                    int childCount =this.outer.childCount;
                    return ++this.currentIndex < childCount;
                }

                public void Reset()
                {
                    this.currentIndex = -1;
                }
            }

            public Vector3 position
            {
                get
                {
                    Vector3 result;
                    this.INTERNAL_get_position(out result);
                    return result;
                }
                set
                {
                    this.INTERNAL_set_position(refvalue);
                }
            }

            public Vector3 localPosition
            {
                get
                {
                    Vector3 result;
                    this.INTERNAL_get_localPosition(out result);
                    return result;
                }
                set
                {
                    this.INTERNAL_set_localPosition(refvalue);
                }
            }

            public Vector3 eulerAngles
            {
                get
                {
                    return this.rotation.eulerAngles;
                }
                set
                {
                    this.rotation = Quaternion.Euler(value);
                }
            }

            public Vector3 localEulerAngles
            {
                get
                {
                    Vector3 result;
                    this.INTERNAL_get_localEulerAngles(out result);
                    return result;
                }
                set
                {
                    this.INTERNAL_set_localEulerAngles(refvalue);
                }
            }

            public Vector3 right
            {
                get
                {
                    return this.rotation * Vector3.right;
                }
                set
                {
                    this.rotation = Quaternion.FromToRotation(Vector3.right,value);
                }
            }

            public Vector3 up
            {
                get
                {
                    return this.rotation * Vector3.up;
                }
                set
                {
                    this.rotation = Quaternion.FromToRotation(Vector3.up,value);
                }
            }

            public Vector3 forward
            {
                get
                {
                    return this.rotation * Vector3.forward;
                }
                set
                {
                    this.rotation = Quaternion.LookRotation(value);
                }
            }

            public Quaternion rotation
            {
                get
                {
                    Quaternion result;
                    this.INTERNAL_get_rotation(out result);
                    return result;
                }
                set
                {
                    this.INTERNAL_set_rotation(refvalue);
                }
            }

            public Quaternion localRotation
            {
                get
                {
                    Quaternion result;
                    this.INTERNAL_get_localRotation(out result);
                    return result;
                }
                set
                {
                    this.INTERNAL_set_localRotation(refvalue);
                }
            }

            public Vector3 localScale
            {
                get
                {
                    Vector3 result;
                    this.INTERNAL_get_localScale(out result);
                    return result;
                }
                set
                {
                    this.INTERNAL_set_localScale(refvalue);
                }
            }

            public Transform parent
            {
                get
                {
                    return this.parentInternal;
                }
                set
                {
                    if (thisis RectTransform)
                    {
                        Debug.LogWarning("Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.",this);
                    }
                    this.parentInternal = value;
                }
            }

            internal extern Transform parentInternal
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            public Matrix4x4 worldToLocalMatrix
            {
                get
                {
                    Matrix4x4 result;
                    this.INTERNAL_get_worldToLocalMatrix(out result);
                    return result;
                }
            }

            public Matrix4x4 localToWorldMatrix
            {
                get
                {
                    Matrix4x4 result;
                    this.INTERNAL_get_localToWorldMatrix(out result);
                    return result;
                }
            }

            public extern Transform root
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
            }

            public extern int childCount
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
            }

            public Vector3 lossyScale
            {
                get
                {
                    Vector3 result;
                    this.INTERNAL_get_lossyScale(out result);
                    return result;
                }
            }

            public extern bool hasChanged
            {
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                get;
                [WrapperlessIcall]
                [MethodImpl(MethodImplOptions.InternalCall)]
                set;
            }

            protected Transform()
            {
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_position(out Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_set_position(ref Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_localPosition(out Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_set_localPosition(ref Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_localEulerAngles(out Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_set_localEulerAngles(ref Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_rotation(out Quaternionvalue);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_set_rotation(ref Quaternionvalue);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_localRotation(out Quaternionvalue);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_set_localRotation(ref Quaternionvalue);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_localScale(out Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_set_localScale(ref Vector3value);

            public void SetParent(Transform parent)
            {
                this.SetParent(parent,true);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern void SetParent(Transform parent, bool worldPositionStays);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_worldToLocalMatrix(out Matrix4x4value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_localToWorldMatrix(out Matrix4x4value);

            [ExcludeFromDocs]
            public void Translate(Vector3 translation)
            {
                Space relativeTo = Space.Self;
                this.Translate(translation, relativeTo);
            }
    //更新位置,如果传入得是世界坐标,则直接在原基础上增加,否则表示传入是一个该物体的方向上位移
            public void Translate(Vector3 translation, [DefaultValue("Space.Self")] Space relativeTo)
            {
                if (relativeTo == Space.World)
                {
                    this.position += translation;
                }
                else
                {
                    this.position += this.TransformDirection(translation);
                }
            }
    //默认传入值为当前物体的坐标系上的位移
            [ExcludeFromDocs]
            public void Translate(float x,float y, float z)
            {
                Space relativeTo = Space.Self;
                this.Translate(x, y, z, relativeTo);
            }
    //更新位置,如果传入得是世界坐标,则直接在原基础上增加,否则表示传入是一个该物体的方向上位移
            public void Translate(float x,float y, float z, [DefaultValue("Space.Self")] Space relativeTo)
            {
                this.Translate(newVector3(x, y, z), relativeTo);
            }
    //更新位置,如果传入relativeTo为空表示是世界坐标,则直接在原基础上增加,否则表示传入是一个该物体的方向上位移
            public void Translate(Vector3 translation, Transform relativeTo)
            {
                if (relativeTo)
                {
                    this.position += relativeTo.TransformDirection(translation);
                }
                else
                {
                    this.position += translation;
                }
            }
    //同上
            public void Translate(float x,float y, float z, Transform relativeTo)
            {
                this.Translate(newVector3(x, y, z), relativeTo);
            }
    //默认该物体的坐标系中旋转
            [ExcludeFromDocs]
            public void Rotate(Vector3 eulerAngles)
            {
                Space relativeTo = Space.Self;
                this.Rotate(eulerAngles, relativeTo);
            }
    //旋转,从这个方法我们可以看出来,unity的欧拉角旋转并非真正的欧拉角旋转,而是同样是四元数的方式
            public void Rotate(Vector3 eulerAngles, [DefaultValue("Space.Self")] Space relativeTo)
            {//相对于父节点的旋转
                Quaternion rhs = Quaternion.Euler(eulerAngles.x, eulerAngles.y, eulerAngles.z);
                if (relativeTo == Space.Self)
                {
                    this.localRotation *= rhs;
                }
                else
                { //世界空间的旋转
                    this.rotation *= Quaternion.Inverse(this.rotation) * rhs *this.rotation;
                }
            }
    //默认相对父节点旋转
            [ExcludeFromDocs]
            public void Rotate(float xAngle,float yAngle, float zAngle)
            {
                Space relativeTo = Space.Self;
                this.Rotate(xAngle, yAngle, zAngle, relativeTo);
            }

            public void Rotate(float xAngle,float yAngle, float zAngle, [DefaultValue("Space.Self")] Space relativeTo)
            {
                this.Rotate(newVector3(xAngle, yAngle, zAngle), relativeTo);
            }

            internal void RotateAroundInternal(Vector3 axis,float angle)
            {
                Transform.INTERNAL_CALL_RotateAroundInternal(this,ref axis, angle);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern void INTERNAL_CALL_RotateAroundInternal(Transform self,ref Vector3 axis, float angle);
    //绕着axis这跟轴旋转angle角度,非弧度制
            [ExcludeFromDocs]
            public void Rotate(Vector3 axis,float angle)
            {
                Space relativeTo = Space.Self;
                this.Rotate(axis, angle, relativeTo);
            }
    //绕着axis这跟轴旋转angle角度,非弧度制
            public void Rotate(Vector3 axis,float angle, [DefaultValue("Space.Self")] Space relativeTo)
            {
                if (relativeTo == Space.Self)
                {
                    this.RotateAroundInternal(base.transform.TransformDirection(axis), angle * 0.0174532924f);
                }
                else
                {
                    this.RotateAroundInternal(axis, angle *0.0174532924f);
                }
            }
    //在point处建立坐标系,方向向量为axis,绕着这跟轴旋转angle角度,非弧度制
            public void RotateAround(Vector3 point, Vector3 axis,float angle)
            {
                Vector3 vector = this.position;
                Quaternion rotation = Quaternion.AngleAxis(angle, axis);
                Vector3 vector2 = vector - point;
                vector2 = rotation * vector2;
                vector = point + vector2;
                this.position = vector;
                this.RotateAroundInternal(axis, angle *0.0174532924f);
            }

            [ExcludeFromDocs]
            public void LookAt(Transform target)
            {
                Vector3 up = Vector3.up;
                this.LookAt(target, up);
            }

            public void LookAt(Transform target, [DefaultValue("Vector3.up")] Vector3 worldUp)
            {
                if (target)
                {
                    this.LookAt(target.position, worldUp);
                }
            }

            public void LookAt(Vector3 worldPosition, [DefaultValue("Vector3.up")] Vector3 worldUp)
            {
                Transform.INTERNAL_CALL_LookAt(this,ref worldPosition, ref worldUp);
            }

            [ExcludeFromDocs]
            public void LookAt(Vector3 worldPosition)
            {
                Vector3 up = Vector3.up;
                Transform.INTERNAL_CALL_LookAt(this,ref worldPosition, ref up);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern void INTERNAL_CALL_LookAt(Transform self,ref Vector3 worldPosition, ref Vector3 worldUp);

            public Vector3 TransformDirection(Vector3 direction)
            {
                return Transform.INTERNAL_CALL_TransformDirection(this,ref direction);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern Vector3 INTERNAL_CALL_TransformDirection(Transform self, ref Vector3 direction);

            public Vector3 TransformDirection(float x,float y, float z)
            {
                return this.TransformDirection(newVector3(x, y, z));
            }

            public Vector3 InverseTransformDirection(Vector3 direction)
            {
                return Transform.INTERNAL_CALL_InverseTransformDirection(this,ref direction);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern Vector3 INTERNAL_CALL_InverseTransformDirection(Transform self, ref Vector3 direction);

            public Vector3 InverseTransformDirection(float x,float y, float z)
            {
                return this.InverseTransformDirection(newVector3(x, y, z));
            }

            public Vector3 TransformVector(Vector3 vector)
            {
                return Transform.INTERNAL_CALL_TransformVector(this,ref vector);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern Vector3 INTERNAL_CALL_TransformVector(Transform self, ref Vector3 vector);

            public Vector3 TransformVector(float x,float y, float z)
            {
                return this.TransformVector(newVector3(x, y, z));
            }

            public Vector3 InverseTransformVector(Vector3 vector)
            {
                return Transform.INTERNAL_CALL_InverseTransformVector(this,ref vector);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern Vector3 INTERNAL_CALL_InverseTransformVector(Transform self, ref Vector3 vector);

            public Vector3 InverseTransformVector(float x,float y, float z)
            {
                return this.InverseTransformVector(newVector3(x, y, z));
            }

            public Vector3 TransformPoint(Vector3 position)
            {
                return Transform.INTERNAL_CALL_TransformPoint(this,ref position);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern Vector3 INTERNAL_CALL_TransformPoint(Transform self, ref Vector3 position);

            public Vector3 TransformPoint(float x,float y, float z)
            {
                return this.TransformPoint(newVector3(x, y, z));
            }

            public Vector3 InverseTransformPoint(Vector3 position)
            {
                return Transform.INTERNAL_CALL_InverseTransformPoint(this,ref position);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern Vector3 INTERNAL_CALL_InverseTransformPoint(Transform self, ref Vector3 position);

            public Vector3 InverseTransformPoint(float x,float y, float z)
            {
                return this.InverseTransformPoint(newVector3(x, y, z));
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern void DetachChildren();

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern void SetAsFirstSibling();

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern void SetAsLastSibling();

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern void SetSiblingIndex(int index);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern int GetSiblingIndex();

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern Transform Find(string name);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private extern void INTERNAL_get_lossyScale(out Vector3value);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern bool IsChildOf(Transform parent);

            public Transform FindChild(string name)
            {
                return this.Find(name);
            }

            public IEnumerator GetEnumerator()
            {
                return new Transform.Enumerator(this);
            }

            [Obsolete("use Transform.Rotate instead.")]
            public void RotateAround(Vector3 axis,float angle)
            {
                Transform.INTERNAL_CALL_RotateAround(this,ref axis, angle);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern void INTERNAL_CALL_RotateAround(Transform self,ref Vector3 axis, float angle);

            [Obsolete("use Transform.Rotate instead.")]
            public void RotateAroundLocal(Vector3 axis,float angle)
            {
                Transform.INTERNAL_CALL_RotateAroundLocal(this,ref axis, angle);
            }

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            private static extern void INTERNAL_CALL_RotateAroundLocal(Transform self,ref Vector3 axis, float angle);

            [WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern Transform GetChild(int index);

            [Obsolete("use Transform.childCount instead."), WrapperlessIcall]
            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern int GetChildCount();
        }
    }

    展开全文
  • unity源码解析Material

    千次阅读 2016-04-08 20:30:32
    ,表示unity在什么时候渲染自己,可选值:Background(1000), Geometry(2000), AlphaTest(2450), Transparent(3000), Overlay(4000)   public extern int renderQueue  {  [WrapperlessIcall]  [ ...
  • unity源码解析GameObject

    千次阅读 2016-04-06 11:21:36
    using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine.Internal; using UnityEngineInternal; namespace UnityEngine ...sealed class
  • 分享个Unity 电视遥控器按钮事件控制源码,方便大家不用重复造轮子。 转载请附原文连接:https://editor.csdn.net/md?articleId=109031521 这里写目录标题一、如何消除电视上的全屏提示弹窗二、遥控器按钮事件控制...
  • 目前编辑器是开源的,可以直接在github上clone 网络上流传有4.3.1的源码,是没问题的 有若干网站在售卖所谓的"5.4"的源码,试了几个,都是骗子。 比如 enginecode.net ...
  • unity源码解析Texture2D

    千次阅读 2016-05-07 23:06:06
    游戏中图形的表现大多来自于纹理,纹理使用最多的是Texture2D,Texture2D继承自Texture,Texture里面大多是对纹理的一些参数的设置,那些设置对于2d3d纹理是通用的,本篇就来看看texture2D具体是如何工作的。...
  • 目前免费或者收费的git服务器基本达不到要求,只能自己搭建gitlab来实现源码管理。 gitlab 和 lfs 是首先解决方案。 gilab安装 gitlab 可以使用docker安装 : https://docs.gitlab.com/omnibus/docker/ ...
  • 这是一个2D横版小游戏项目 该完整项目本人亲测可完美运行 特征:游戏共有5个世界50个精心设计的关卡,有完整的人物、换装、武器、道具系统,编辑器强大,无需编程即可设计新的关卡、场景、人物、装备、道具!...
  • Unity4.6.9 Unity ColorPicker可视化的颜色操作和Color库的管理、颜色别名定义、颜色序列化。为开发者带来的极大的方便。如果读者不了解Unity ColorPicker,可先转至官方文档...
  • unity反编译源码

    2017-09-12 10:54:17
    unity 反编译 源码,这是从github上clone下来,外国大牛反编译unity源码,通过源码可以分析一些unity常用功能代码分析
  • Unity shader源码

    2018-10-23 10:07:17
    unity shader 源码

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,313
精华内容 2,125
关键字:

unity源码