示例#1
0
        private void Find(BinderData data)
        {
            _list = new List <Data>();
            var prefabs = AssetDatabase.GetAllAssetPaths().Where(assetPath => assetPath.EndsWith(".prefab"));

            foreach (var path in prefabs)
            {
                var p = AssetDatabase.LoadAssetAtPath <GameObject>(path);

                foreach (var comp in p.GetComponentsInChildren(data.type, true))
                {
                    if (BinderIsNormal(comp, data))
                    {
                        continue;
                    }
                    var obj = _list.Find(d => d.PrefabPath == path);
                    if (obj != null)
                    {
                        ++obj.ComponentsCount;
                    }
                    else
                    {
                        _list.Add(new Data
                        {
                            PrefabPath      = path,
                            PrefabName      = p.name,
                            ComponentsCount = 1,
                            BinderData      = data
                        });
                    }
                }
            }
        }
示例#2
0
        private bool BinderIsNormal(object component, BinderData data)
        {
            var field = data.type.GetField(data._field,
                                           BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            return(field.GetValue(component) != null);
        }
        /// <summary>
        /// File のLoadリクエスト
        /// </summary>
        /// <param name="_fileName">ファイル名(CPKのRootからの相対パス)</param>
        /// <param name="_data">対象のBindData</param>
        /// <param name="_onComplete">コールバック</param>
        /// <returns></returns>
        private IEnumerator LoadFile(string _fileName, BinderData _data, OnCompleteLoad _onComplete)
        {
            // Validation
            if (string.IsNullOrEmpty(_fileName) || _data == null)
            {
                if (_onComplete != null)
                {
                    _onComplete.Invoke(false, null);
                }
                yield break;
            }

            CriFsLoadFileRequest req = CriFsUtility.LoadFile(_data.Binder, _fileName);

            // 待機
            yield return(req.WaitForDone(m_manager));

            bool isSucceeded = string.IsNullOrEmpty(req.error);

            if (!isSucceeded)
            {
                Debug.LogError("[Error]" + req.error);
                Debug.LogWarning("Failed to load :" + _fileName);
            }

            if (_onComplete != null)
            {
                _onComplete.Invoke(isSucceeded, req.bytes);
            }
            req.Dispose();
        }
        /// <summary>
        /// CPK からファイルのロードを行う
        /// </summary>
        /// <param name="_cpkName"></param>
        /// <param name="_fileName">CPKのRootからの相対パス</param>
        /// <param name="_onCompLoad">コールバック</param>
        /// <returns></returns>
        public IEnumerator LoadFile(string _cpkName, string _fileName, OnCompleteLoad _onCompLoad)
        {
            /*
             * ------------------------------
             * フロー
             * 1. Cache に無ければDownload -> Cache に保存
             * 2. Cache にあるCPKファイルをBind
             * 3. Bind したbinder から目的のファイルを取り出す
             * ------------------------------
             */

            // Download ~ Bind まで
            bool       isSucceededLoadCpk = false;
            BinderData bindedData         = null;

            yield return(LoadCPK(_cpkName, (bool _isSucceeded, BinderData _data) => {
                isSucceededLoadCpk = _isSucceeded;
                bindedData = _data;
            }));

            // Load 失敗したのでここで打ち止め
            if (!isSucceededLoadCpk)
            {
                if (_onCompLoad != null)
                {
                    _onCompLoad.Invoke(false, null);
                }
                yield break;
            }

            // File のLoad 部分
            yield return(LoadFile(_fileName, bindedData, _onCompLoad));
        }
示例#5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            _currentMonoBehaviour = (MonoBehaviour)property.serializedObject.targetObject;

            _currentBinderData = fieldInfo.GetValue(property.serializedObject.targetObject) as T;

            if (_bindStyle == null)
            {
                _bindStyle = new GUIStyle(GUI.skin.FindStyle("FrameBox"));
            }

            GetOptions(property);

            GUI.Box(position, "", _bindStyle);

            int        currentIndex   = GetOptionSetIndex();
            BinderData selectedOption = _binderList[currentIndex];

            // Property name label
            var binderLabelRect = position;

            binderLabelRect.x     += 5;
            binderLabelRect.height = EditorGUIUtility.singleLineHeight;
            var labelStyle = new GUIStyle(GUI.skin.label);

            labelStyle.richText = true;

            var origColor = GUI.color;

            GUI.color = !IsObjectValid ? BIND_NOT_SET_COLOR : origColor;

            GUI.Label(binderLabelRect, label.text + $" <i>({typeof(T).Name})</i>", labelStyle);

            GUI.color = origColor;

            // Drop down
            var dropDownRect = position;

            dropDownRect.x     += BINDING_SETUP_OFFSET;
            dropDownRect.y     += EditorGUIUtility.singleLineHeight;
            dropDownRect.width  = position.width - BINDING_SETUP_OFFSET - 5;
            dropDownRect.height = EditorGUIUtility.singleLineHeight;
            var dropDownStyle = new GUIStyle(GUI.skin.FindStyle("DropDownButton"));

            dropDownStyle.alignment = TextAnchor.MiddleLeft;

            dropDownRect = EditorGUI.PrefixLabel(dropDownRect, new GUIContent($"Target {BinderTypeName}"));

            var selectedLabel = $"{GetSelectedOptionName(selectedOption)}";

            if (GUI.Button(dropDownRect, selectedLabel, dropDownStyle))
            {
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("None"), currentIndex == 0, () => SetNewPropertyField(default));
        public bool SetRelease(string _cpkName)
        {
            BinderData data = null;
            bool       ret  = BindDict.TryGetValue(_cpkName, out data);

            if (!ret || data == null)
            {
                return(false);
            }

            data.SetRelease();
            return(true);
        }
        /// <summary>
        /// CPK のDownload~Bind までの処理
        /// LoadFileの途中処理としての利用や、CueSheet取得用などに用いると思われ
        /// </summary>
        /// <param name="_cpkName"></param>
        /// <param name="_onComplete"></param>
        /// <returns></returns>
        private IEnumerator LoadCPK(string _cpkName, string _versionHashName, OnCompleteBind _onComplete)
        {
            /*
             * ------------------------------
             * フロー
             * 1. Cache に無ければDownload -> Cache に保存
             * 2. Cache にあるCPKファイルをBind
             * ------------------------------
             */

            // Cache上に無い
            if (!CriPackageCacheController.IsCached(_cpkName, _versionHashName))
            {
                // Download すべきか、サーバー上のファイルを直接バインドすべきかは要検討
                yield return m_dlCtrl.DonwloadCPK(_cpkName, _versionHashName, null);

                //TODO: Retry 対応
            }

            // Dictionary未登録であればCache 上にあるCPKファイルをバインド
            if (!BindDict.ContainsKey(_cpkName))
            {
                yield return(BindCPK(_cpkName, _versionHashName));
            }

            BinderData data = null;
            bool       ret  = BindDict.TryGetValue(_cpkName, out data);

            if (_onComplete != null)
            {
                // Load 成功したので参照しているはず
                if (ret && data != null)
                {
                    data.SetReference();
                }
                _onComplete.Invoke(ret, data);
            }
        }