示例#1
0
 public void Instantiate(EiPrefab prefab)
 {
     buffer.ClearBuffer();
     buffer.Write((byte)EiNetworkInstantiateMask.None);                          /*01*/
     buffer.Write(prefab.Id);                                                    /*04*/
     buffer.Write(AllocateViewId);                                               /*04*/
     buffer.Write(localPlayer.Id);                                               /*04*/
     network.Instantiate(buffer.GetWrittenBuffer());                             /*Total 13 bytes*/
 }
示例#2
0
 public void Instantiate(EiPrefab prefab, Vector3 position)
 {
     buffer.ClearBuffer();
     buffer.Write((byte)EiNetworkInstantiateMask.Position);                      /*01*/
     buffer.Write(prefab.Id);                                                    /*04*/
     buffer.Write(AllocateViewId);                                               /*04*/
     buffer.Write(localPlayer.Id);                                               /*04*/
     buffer.Write(position);                                                     /*12*/
     network.Instantiate(buffer.GetWrittenBuffer());                             /*Total 25 bytes*/
 }
示例#3
0
 public void Instantiate(EiPrefab prefab, Vector3 position, Quaternion rotation, float scale)
 {
     buffer.ClearBuffer();
     buffer.Write((byte)EiNetworkInstantiateMask.PositionRotationScale);         /*01*/
     buffer.Write(prefab.Id);                                                    /*04*/
     buffer.Write(AllocateViewId);                                               /*04*/
     buffer.Write(localPlayer.Id);                                               /*04*/
     buffer.Write(position);                                                     /*12*/
     buffer.Write(rotation);                                                     /*12*/
     buffer.Write(scale);                                                        /*04*/
     network.Instantiate(buffer.GetWrittenBuffer());                             /*Total 41 bytes*/
 }
示例#4
0
 private bool Render(EiPrefab prefab, int i, bool folded)
 {
     EditorGUILayout.BeginHorizontal();
     if (GUILayout.Button("Select", GUILayout.Width(50)))
     {
         Selection.activeObject = prefab;
     }
     if (GUILayout.Button("X", GUILayout.Width(18)))
     {
         EditorGUILayout.EndHorizontal();
         return(false);
     }
     if (prefab == null)
     {
         EditorGUILayout.LabelField("Null Object");
     }
     else
     {
         if (prefab.Id != i)
         {
             if (Provider.enabled && Provider.isActive)
             {
                 var asset = Provider.GetAssetByPath(AssetDatabase.GetAssetPath(prefab));
                 if (asset.locked && Provider.CheckoutIsValid(asset))
                 {
                     Provider.Checkout(asset, CheckoutMode.Both);
                 }
                 if (!asset.locked)
                 {
                     ApplyUniqueId(prefab, i);
                 }
             }
             else
             {
                 ApplyUniqueId(prefab, i);
             }
         }
         var text = new GUIContent(prefab.Path.Replace("/", " / ") + " /");
         var size = EditorStyles.label.CalcSize(text);
         EditorGUILayout.LabelField(text, GUILayout.Width(size.x));
         EditorGUILayout.LabelField(prefab.ItemName, EditorStyles.boldLabel, GUILayout.Width(EditorStyles.boldLabel.CalcSize(new GUIContent(prefab.ItemName)).x));
     }
     EditorGUILayout.EndHorizontal();
     return(true);
 }
示例#5
0
        public void Instantiate(byte[] data)
        {
            EiBuffer buffer   = new EiBuffer(data);
            var      unpack   = (EiNetworkInstantiateMask)buffer.ReadByte();
            var      prefabId = buffer.ReadInt();
            var      viewId   = buffer.ReadInt();
            var      ownerId  = buffer.ReadInt();
            EiPrefab prefab   = Eitrum.Database.EiPrefabDatabase.Instance [prefabId];

            // Calculate Unpack type
            Vector3    position = unpack.HasFlag(EiNetworkInstantiateMask.Position) ? buffer.ReadVector3() : Vector3.zero;
            Quaternion rotation = unpack.HasFlag(EiNetworkInstantiateMask.Rotation) ? buffer.ReadQuaternion() : Quaternion.identity;
            float      scale    = unpack.HasFlag(EiNetworkInstantiateMask.Scale) ? buffer.ReadFloat() : 1f;
            Vector3    scale3D  = unpack.HasFlag(EiNetworkInstantiateMask.Scale3D) ? buffer.ReadVector3() : new Vector3(scale, scale, scale);
            Transform  parent   = null;

            if (unpack.HasFlag(EiNetworkInstantiateMask.Parent))
            {
                var parentViewId = buffer.ReadInt();
                var parentView   = EiNetworkView.Find(parentViewId);
                if (parentView)
                {
                    parent = parentView.transform;
                }
            }

            // Instantiate Prefab
            var go   = prefab.Instantiate(position, rotation, scale3D, parent);
            var view = go.GetComponent <EiNetworkView> ();

            if (view)
            {
                EiNetworkView.SetViewId(view, viewId);
                EiNetworkView.SetOwnerId(view, ownerId);
                EiNetworkView.SetNetwork(view, this);
            }
        }
示例#6
0
        public override void OnInspectorGUI()
        {
            var db   = (EiPrefabDatabase)target;
            var list = GetPrefabList(db);

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(editMode ? "List" : "Edit", GUILayout.Width(50)))
            {
                editMode = !editMode;
            }
            pathFilter = EditorGUILayout.TextField("Search Filter", pathFilter);

            EditorGUILayout.EndHorizontal();

            if (editMode)
            {
                EditorGUILayout.LabelField("Edit mode no longer supported");
                for (int i = 0; i < list.Count; i++)
                {
                    var prefab = list[i];
                    if (prefab.FullName.Contains(pathFilter))
                    {
                    }
                }
            }
            else
            {
                if (EditorGUIUtility.GetObjectPickerControlID() == 129)
                {
                    objPicker = EditorGUIUtility.GetObjectPickerObject() as EiPrefab;
                }
                else
                {
                    if (objPicker)
                    {
                        if (!list.Contains(objPicker) || EditorUtility.DisplayDialog("Add Prefab Warning", "You are about to add a prefab that is already in the database, do you want to proceed?", "Yes", "Cancel"))
                        {
                            list.Add(objPicker);
                        }
                        objPicker = null;
                    }
                }
                if (folded == null || folded.Length != list.Count)
                {
                    folded = new bool[list.Count];
                }
                for (int i = 0; i < list.Count; i++)
                {
                    var prefab = list[i];
                    if (prefab == null)
                    {
                        continue;
                    }
                    if (prefab.FullName.Contains(pathFilter))
                    {
                        var toRemove = !Render(prefab, i, folded[i]);
                        if (toRemove)
                        {
                            list.RemoveAt(i);
                            i--;
                        }
                    }
                }
                if (GUILayout.Button("Add Item", GUILayout.Width(100)))
                {
                    EditorGUIUtility.ShowObjectPicker <EiPrefab>(null, false, "", 129);
                }
            }
        }
示例#7
0
 public static void ApplyUniqueId(EiPrefab prefab, int id)
 {
     typeof(EiPrefab).GetField("id", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(prefab, id);
 }
 public static void DrawWirePrefab(EiPrefab prefab, Vector3 position, Quaternion rotation)
 {
     DrawWireGameObject(prefab.GameObject, position, rotation);
 }
 public static void DrawWirePrefab(EiPrefab prefab)
 {
     DrawWireGameObject(prefab.GameObject);
 }
示例#10
0
 public static GameObject Instantiate(EiPrefab prefab, Vector3 position, Quaternion rotation)
 {
     return(prefab.Instantiate(position, rotation));
 }
示例#11
0
 public static GameObject Instantiate(EiPrefab prefab)
 {
     return(prefab.Instantiate());
 }
示例#12
0
 public static GameObject Instantiate(EiPrefab prefab, Vector3 position, Quaternion rotation, Vector3 scale, Transform parent)
 {
     return(prefab.Instantiate(position, rotation, scale, parent));
 }