Exemplo n.º 1
0
    /// <summary>
    /// 同步加载AssetItem
    /// </summary>
    /// <param name="fullPath"></param>
    /// <returns></returns>
    public AssetItem LoadAsset(string fullPath)
    {
        switch (ABUtility.LoadMode)
        {
# if UNITY_EDITOR
        case LoadModeEnum.EditorOrigin:
            UnityEngine.Object obj       = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(fullPath);
            AssetItem          assetItem = GameMgr.m_ObjectMgr.Spawn <AssetItem>();
            assetItem.Init("", fullPath, obj);
            return(assetItem);

        case LoadModeEnum.EditorAB:
#endif
        case LoadModeEnum.StandaloneAB:
        case LoadModeEnum.DeviceFullAotAB:
            ABItem             ABItem = LoadAssetBundleByAssetName(fullPath);
            UnityEngine.Object obj2   = null;
            if (!fullPath.EndsWith(".unity"))
            {
                obj2 = ABItem.AssetBundle.LoadAsset(fullPath);
            }
            AssetItem assetItem2 = GameMgr.m_ObjectMgr.Spawn <AssetItem>();
            assetItem2.Init(ABItem.ABName, fullPath, obj2);
            return(assetItem2);

        default:
            return(null);
        }
    }
        //public static void ForEach<T>(this EventList<T> source, Action<T> action)
        //{
        //    for (int i = 0; i < source.Count; ++i)
        //    {
        //        action(source[i]);
        //    }
        //}


        public static void ThrowIfNull(this UnityEngine.Object obj)
        {
            if (obj == null)
            {
                throw new NullReferenceException("");
            }
        }
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, out string message, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusOptions)
        {
            string assetPath = GetAssetOrScenePath(assetObject);
            string metaPath  = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath);

            return(IsOpenForEdit(metaPath, out message, statusOptions));
        }
Exemplo n.º 4
0
        private void bothLoadComplete()
        {
            if (_onCreateComplete == null)
            {
                Utils.LogSys.Log("创建模型:---------------->_onCreateComplete == null" + _baseAssetbundleLoadTask._taskName);
                return;
            }
            //Utils.LogSys.Log("创建模型:---------------->bothLoadComplete" + _baseAssetbundleLoadTask._taskName);
            AssetBundle assetbundle = _baseAssetbundleLoadTask.getTargetAssetbundle();

            if (assetbundle == null)
            {
                Utils.LogSys.LogError("创建模型失败:" + _baseAssetbundleLoadTask._taskName);
                return;
            }
            UnityEngine.Object assetObj = (Object)assetbundle.LoadAsset <GameObject>("base.prefab");           //assetbundle.mainAsset;
            if (assetObj != null)
            {
                GameObject objBase = assetObj as GameObject;
                _baseAssetbundleLoadTask.unloadUnusedAssetbundle(false);

                //基础对象
                _pModelRoot = (GameObject)UnityEngine.Object.Instantiate(objBase, _tfDefaultPos, Quaternion.identity);

                _pModelRoot.name = _strModelName;
                _bIsBaseLoaded   = true;
            }
        }
Exemplo n.º 5
0
        internal override AssetInfo SetAsset(string name, UnityEngine.Object obj, string bundleName = null)
        {
            AssetInfo asset = new AssetInfo(obj, name, bundleName);

            cacheMgr.Cache.AddAsset(name, asset);
            return(asset);
        }
Exemplo n.º 6
0
        private IEnumerator DelayRun(string path, Action <Resource, bool> onLoad)
        {
            yield return(0.03f);//随机延迟时间0~0.333秒

            try
            {
//                Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", "isloading", path));

                UnityEngine.Object o = Resources.Load(path);
                if (o != null)
                {
                    Resource res = new Resource();
                    res.path     = path;
                    res.UnityObj = o;
                    onLoad(res, true);
//                    Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", "success", path));
                }
                else
                {
                    onLoad(null, false);
                    Debug.LogError("null Resource" + path);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("load " + path + " fail\n" + e.Message + e.StackTrace);
            }
        }
Exemplo n.º 7
0
        public void GetResAsync <T>(string address, Action <T> callback) where T : UnityEngine.Object
        {
            UnityEngine.Object asset = null;
            var data = cfg.ResData.GetResInfo(address);

            if (data == null)
            {
                Debug.LogError("不存在这个地址 addr:" + address);
            }
            else
            {
                if (data.isResourcesPath)
                {
                    LoadForResource(data.address, a => { asset = a; });
                }
                else
                {
                    LoadForAB(data.address, a => { asset = a; }, true);
                }
            }

            if (callback != null)
            {
                callback(asset as T);
            }
        }
Exemplo n.º 8
0
        protected override void PopulateContextMenu(GenericMenu menu, OverrideState overrideState,
                                                    IExposedPropertyTable exposedPropertyTable, SerializedProperty exposedName, SerializedProperty defaultValue)
        {
            PropertyName  propertyName = new PropertyName(exposedName.stringValue);
            OverrideState currentOverrideState;

            UnityEngine.Object currentValue = Resolve(new PropertyName(exposedName.stringValue), exposedPropertyTable,
                                                      defaultValue.objectReferenceValue, out currentOverrideState);
            if (overrideState == OverrideState.DefaultValue)
            {
                menu.AddItem(new GUIContent(ExposePropertyContent.text), on: false, delegate
                {
                    GUID gUID = GUID.Generate();
                    exposedName.stringValue = gUID.ToString();
                    exposedName.serializedObject.ApplyModifiedProperties();
                    PropertyName id = new PropertyName(exposedName.stringValue);
                    Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Set Exposed Property");
                    exposedPropertyTable.SetReferenceValue(id, currentValue);
                }, null);
            }
            else
            {
                menu.AddItem(UnexposePropertyContent, on: false, delegate
                {
                    exposedName.stringValue = "";
                    exposedName.serializedObject.ApplyModifiedProperties();
                    Undo.RecordObject(exposedPropertyTable as UnityEngine.Object, "Clear Exposed Property");
                    exposedPropertyTable.ClearReferenceValue(propertyName);
                }, null);
            }
        }
Exemplo n.º 9
0
 public static void DestroyReference(UnityEngine.Object obj)
 {
     if (lhDefine.projectType != ProjectType.develop)
     {
         lhBundleManager.DestroyReference(obj);
     }
 }
Exemplo n.º 10
0
 protected virtual List <MemberInfo> FilterAllowedMembersByUIType(UnityEngine.Object uiElement, List <MemberInfo> allMembers)
 {
     if (IsTextUI(uiElement))
     {
         return(FilterAllowedTextMembers(uiElement, allMembers));
     }
     if (IsInputFieldUI(uiElement))
     {
         return(FilterAllowedInputFieldMembers(uiElement, allMembers));
     }
     if (IsSliderUI(uiElement))
     {
         return(FilterAllowedSliderMembers(uiElement, allMembers));
     }
     if (IsToggleUI(uiElement))
     {
         return(FilterAllowedToggleMembers(uiElement, allMembers));
     }
     if (IsScrollbarUI(uiElement))
     {
         return(FilterAllowedScrollbarMembers(uiElement, allMembers));
     }
     if (IsDropdownUI(uiElement))
     {
         return(FilterAllowedDropdownMembers(uiElement, allMembers));
     }
     return(allMembers);
 }
        private void AddToAsset(UnityEngine.Object asset)
        {
//            asset.hideFlags |= HideFlags.HideInHierarchy;
            AssetDatabase.AddObjectToAsset(asset, TreeAsset);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemplo n.º 12
0
 public void AddObject(UnityEngine.Object asset)
 {
     if (asset != null)
     {
         s_ObjectsToUndo.Add(asset);
     }
 }
Exemplo n.º 13
0
 public void Unload()
 {
     isDestroyed = true;
     m_AssetName = "";
     m_ABName    = "";
     m_Object    = null;
 }
Exemplo n.º 14
0
    public void LoadAssetAsync(string fullPath, Action <AssetItem> successCall, Action failCall = null)
    {
        switch (ABUtility.LoadMode)
        {
# if UNITY_EDITOR
        case LoadModeEnum.EditorOrigin:
            AssetItem          item = GameMgr.m_ObjectMgr.Spawn <AssetItem>();
            UnityEngine.Object obj  = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(fullPath);
            item.Init("", fullPath, obj);
            successCall(item);
            break;

        case LoadModeEnum.EditorAB:
#endif
        case LoadModeEnum.StandaloneAB:
        case LoadModeEnum.DeviceFullAotAB:
            LoadAssetBundleByAssetNameAsync(fullPath, (abItem) => {
                GameMgr.StartCoroutine(_loadAssetFromABItemAsync(abItem, fullPath, successCall));
            });
            break;

        default:
            failCall?.Invoke();
            break;
        }
    }
Exemplo n.º 15
0
        /// <summary>
        /// 解析模型数量
        /// </summary>
        /// <param name="filePath"></param>
        private ModelBean parseModel(string filePath)
        {
            ModelBean modelBean = new ModelBean();

            modelBean.Name     = "  " + Path.GetFileNameWithoutExtension(filePath);
            modelBean.FilePath = filePath;

            UnityEngine.Object  resObj    = AssetDatabase.LoadAssetAtPath <Object>(filePath);
            GameObject          gObj      = GameObject.Instantiate(resObj) as GameObject;
            SkinnedMeshRenderer modelSkin = gObj.GetComponentInChildren <SkinnedMeshRenderer>();

            if (modelSkin != null)
            {
                readSkinMeshRender(modelSkin, modelBean);
            }
            else
            {
                MeshRenderer meshRenderer = gObj.GetComponentInChildren <MeshRenderer>();
                if (meshRenderer != null)
                {
                    readMeshRender(meshRenderer, modelBean);
                }
            }

            GameObject.DestroyImmediate(gObj);
            return(modelBean);
        }
Exemplo n.º 16
0
            private void ValidateObjectParamater(
                SerializedProperty arguments,
                PersistentListenerMode mode)
            {
                SerializedProperty propertyRelative1 = arguments.FindPropertyRelative("m_ObjectArgumentAssemblyTypeName");
                SerializedProperty propertyRelative2 = arguments.FindPropertyRelative("m_ObjectArgument");

                UnityEngine.Object objectReferenceValue = propertyRelative2.objectReferenceValue;
                if (mode != PersistentListenerMode.Object)
                {
                    propertyRelative1.stringValue          = typeof(UnityEngine.Object).AssemblyQualifiedName;
                    propertyRelative2.objectReferenceValue = (UnityEngine.Object)null;
                }
                else
                {
                    if (objectReferenceValue == (UnityEngine.Object)null)
                    {
                        return;
                    }
                    System.Type type = System.Type.GetType(propertyRelative1.stringValue, false);
                    if (typeof(UnityEngine.Object).IsAssignableFrom(type) && type.IsInstanceOfType((object)objectReferenceValue))
                    {
                        return;
                    }
                    propertyRelative2.objectReferenceValue = (UnityEngine.Object)null;
                }
            }
Exemplo n.º 17
0
        void LoadCheckUpdateAsset()
        {
            asset = AssetDatabase.LoadAssetAtPath <CheckUpdateAsset> ("Assets/" + assetFileName);
            Debug.Log(destinyFolder);

            if (asset == null)
            {
                Debug.LogError("Can't load Updates Log File");
                return;
            }

            Debug.Log(asset);

            profile = new SerializedObject(asset);

            if (profile != null)
            {
                Debug.Log("Profile loaded");

                _chVersion.version      = AssetUtility.LoadProperty("version", profile);
                _chVersion.dataReleased = AssetUtility.LoadProperty("dateReleased", profile);
                _chVersion.changeLog    = AssetUtility.LoadProperty("changeLog", profile);
                _chVersion.link         = AssetUtility.LoadProperty("link", profile);
            }
        }
Exemplo n.º 18
0
        private static void DestorySafe(UnityEngine.Object toDestroy)
        {
            if (toDestroy != null)
            {
                if (Application.isPlaying)
                {
                    Destroy(toDestroy);
                }
                else
                {
#if UNITY_EDITOR
                    // Let Unity handle unload of unused assets if lifecycle is transitioning from editor to play mode
                    // Defering the call during this transition would destroy reference only after play mode Awake, leading to possible broken material references on TMPro objects
                    if (!EditorApplication.isPlayingOrWillChangePlaymode)
                    {
                        EditorApplication.delayCall += () =>
                        {
                            if (toDestroy != null)
                            {
                                DestroyImmediate(toDestroy);
                            }
                        };
                    }
#endif
                }
            }
        }
Exemplo n.º 19
0
    private void OnAssetLoaded(string lowerResPath, AssetBundle ab, UnityEngine.Object asset)
    {
        SameRequestCache src;
        bool             isPreload = false;

        if (sameRequestCache_.TryGetValue(lowerResPath, out src))
        {
            try
            {
                foreach (AsyncLoadRequest request in src.srcList)
                {
                    isPreload = isPreload | request.isPreload;
                    Callback(lowerResPath, request, asset);
                }
                src.srcList.Clear();
                sameRequestCache_.Remove(lowerResPath);
            }
            catch (Exception ex)
            {
                Debug.Log(ex.Message);
                Debug.Log(ex.StackTrace);
                Debug.Log("Execption in OnAssetLoaded*********");
                Debug.Log(ex.ToString());
            }
        }
        if (ab && asset)
        {
            ResourceManager.Add(lowerResPath, ab, asset, isPreload);
        }
    }
Exemplo n.º 20
0
 GUIContent GetContentForOutput(PlayableBinding binding, UnityEngine.Object source)
 {
     m_BindingContent.text    = binding.streamName;
     m_BindingContent.tooltip = (source == null) ? Styles.NoBindingsContent.text : string.Empty;
     m_BindingContent.image   = AssetPreview.GetMiniTypeThumbnail(binding.outputTargetType) ?? m_DefaultScriptContentTexture;
     return(m_BindingContent);
 }
Exemplo n.º 21
0
            private void VisitObject(UnityEngine.Object value)
            {
                var handle = UnityObjectSerializer.ToObjectHandle(value);

                StringBuffer.Append(' ', Style.Space * Indent);

                if (false == IsListItem)
                {
                    StringBuffer.Append("\"");
                    StringBuffer.Append(Property.Name);
                    StringBuffer.Append("\": ");
                }

                if (string.IsNullOrEmpty(handle.Guid))
                {
                    StringBuffer.Append("{ \"$TypeId\": ");
                    StringBuffer.Append((int)UTinyTypeId.UnityObject);
                    StringBuffer.Append(" },\n");
                }
                else
                {
                    StringBuffer.Append("{ \"$TypeId\": ");
                    StringBuffer.Append((int)UTinyTypeId.UnityObject);
                    StringBuffer.Append(", \"Guid\": \"");
                    StringBuffer.Append(handle.Guid);
                    StringBuffer.Append("\", \"FileId\": ");
                    StringBuffer.Append(handle.FileId);
                    StringBuffer.Append(", \"Type\": ");
                    StringBuffer.Append(handle.Type);
                    StringBuffer.Append(" },\n");
                }
            }
Exemplo n.º 22
0
    private IEnumerator CreateFromWWW(LoadQueueData queueData)
    {
        working_++;
        yield return(null);

        string path = string.Empty;

        using (var www = new WWW(XYMisc.EncodeLocalFileURL(XYDirectory.Res + queueData.resPath)))
        {
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log(www.error);
            }

            AssetBundle        ab             = www.assetBundle;
            UnityEngine.Object mainAssetAsset = ab.mainAsset;
            if (ab && mainAssetAsset)
            {
                OnAssetLoaded(queueData.resPath, ab, mainAssetAsset);
                ab.Unload(false);
            }
            else
            {
                OnAssetLoaded(queueData.resPath, null, mainAssetAsset);
            }
        }
        working_--;
    }
        private void DeleteFromAsset(UnityEngine.Object asset)
        {
            Undo.RecordObject(TreeAsset, "Deleted action");
            Undo.RecordObject(asset, "Deleted action");

            if (asset is BehaviourTreeNode)
            {
                BehaviourTreeNode node = (BehaviourTreeNode)asset;

                RemoveNodeAssetRecursive(TreeAsset.RootNode, node);
                DestroyChildrenNodes(node);

                if (node == TreeAsset.RootNode)
                {
                    TreeAsset.RootNode = null;
                }

                DestroyImmediate(node, true);
            }
            else
            {
                DestroyImmediate(asset, true);
            }

            EditorUtility.SetDirty(TreeAsset);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            OnLoadAsset(TreeAsset);
        }
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, out string message, StatusQueryOptions statusOptions)
        {
            string assetPath = GetAssetOrScenePath(assetObject);
            string metaPath  = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath);

            return(IsOpenForEdit(metaPath, out message, statusOptions));
        }
Exemplo n.º 25
0
        public static AssetReferenceInfo Execute(UnityEngine.Object targetObject)
        {
            try
            {
                var assetPath = Application.dataPath;

                Action <int, int> reportProgress = (current, total) =>
                {
                    var title    = "Find References In Project";
                    var info     = string.Format("Loading Dependencies ({0}/{1})", current, total);
                    var progress = current / (float)total;

                    EditorUtility.DisplayProgressBar(title, info, progress);
                };

                var scenes    = FindAllFiles(assetPath, "*.unity");
                var prefabs   = FindAllFiles(assetPath, "*.prefab");
                var materials = FindAllFiles(assetPath, "*.mat");
                var assets    = FindAllFiles(assetPath, "*.asset");

                var ctx = new FindReferenceContext(scenes, prefabs, materials, assets, reportProgress);

                return(FindReferencesCore(ctx, targetObject));
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            return(null);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Asset加载完成回调
 /// </summary>
 /// <param name="_asset"></param>
 public void OnAssetLoaded(UnityEngine.Object _asset)
 {
     if (_asset != null)
     {
         m_loaded_asset.Add(_asset);
     }
 }
Exemplo n.º 27
0
        protected override void ModelChanged(UnityEngine.Object obj)
        {
            var inputs     = inputPorts;
            var newAnchors = new List <VFXDataAnchorController>();

            m_SyncingSlots = true;
            bool changed = UpdateSlots(newAnchors, slotContainer.inputSlots, true, true);

            NewInputSet(newAnchors);

            foreach (var anchorController in m_InputPorts.Except(newAnchors))
            {
                anchorController.OnDisable();
            }
            m_InputPorts = newAnchors;


            newAnchors = new List <VFXDataAnchorController>();
            changed   |= UpdateSlots(newAnchors, slotContainer.outputSlots, true, false);

            foreach (var anchorController in m_OutputPorts.Except(newAnchors))
            {
                anchorController.OnDisable();
            }
            m_OutputPorts  = newAnchors;
            m_SyncingSlots = false;

            // Call after base.ModelChanged which ensure the ui has been refreshed before we try to create potiential new edges.
            if (changed)
            {
                viewController.DataEdgesMightHaveChanged();
            }

            NotifyChange(AnyThing);
        }
Exemplo n.º 28
0
        public static void RemoveFromUnitySelection(UnityEngine.Object objectToRemove)
        {
            var newSelection = Selection.objects.ToList();

            newSelection.RemoveAll(element => element == objectToRemove);
            Selection.objects = newSelection.ToArray();
        }
Exemplo n.º 29
0
        public static void ReplaceShader(UnityEngine.Object obj, string url)
        {
            List <Renderer> render_list = new List <Renderer>();

            if (!obj)
            {
                return;
            }
            if (obj is GameObject)
            {
                //FindRenderers(render_list, (obj as GameObject).transform);
                FindRenderers(ref render_list, (obj as GameObject).transform);
                if (render_list.Count == 0)
                {
                    return;
                }
                for (int i = 0; i < render_list.Count; i++)
                {
                    ReplaceRendererShader(render_list[i], url);
                }
            }
            else if (obj is Material)
            {
                ReplaceMaterialShader(obj as Material, url);
            }

            return;
        }
Exemplo n.º 30
0
        void AddToLog(string msg, bool isAnError, UnityEngine.Object obj)
        {
            var st = new StackTrace(2, true);
            var sf = st.GetFrame(0);

            AddToLog(msg, sf.GetFileName(), sf.GetFileLineNumber(), isAnError, obj);
        }
Exemplo n.º 31
0
	void LoadCheckUpdateAsset(){
		asset = AssetDatabase.LoadAssetAtPath<CheckUpdateAsset> ("Assets/" + assetFileName);
		Debug.Log (destinyFolder);

		if (asset == null) {
			Debug.LogError("Can't load Updates Log File");
			return;
		}

		Debug.Log(asset);


		
		profile = new SerializedObject(asset);

		if (profile != null) {
			Debug.Log("Profile loaded");

			_chVersion.version = AssetUtility.LoadProperty("version", profile);
			_chVersion.dataReleased = AssetUtility.LoadProperty("dateReleased", profile);
			_chVersion.changeLog = AssetUtility.LoadProperty("changeLog", profile);
			_chVersion.link = AssetUtility.LoadProperty("link", profile);
		}


	}