예제 #1
0
    protected List <GameObjectRelationship> InitSubData(List <RelationShipStruct> _relationList, int _myLevel, GameObjectRelationship _parent)
    {
        //if (_myLevel > maxLevel) return new List<GameObjectRelationship>();
        List <GameObjectRelationship> resultList = new List <GameObjectRelationship>();

        foreach (RelationShipStruct item in _relationList)
        {
            if (item.level == _myLevel && item.parentName == _parent.objName && item.parentInstanceID == _parent.instanceID)
            {
                GameObjectRelationship gameObjectRelationship = new GameObjectRelationship();
                gameObjectRelationship.parentName       = item.parentName;
                gameObjectRelationship.objName          = item.objName;
                gameObjectRelationship.matNames         = item.matNames;
                gameObjectRelationship.instanceID       = item.instanceID;
                gameObjectRelationship.parentInstanceID = item.parentInstanceID;
                resultList.Add(gameObjectRelationship);
            }
        }
        _myLevel += 1;
        foreach (var item in resultList)
        {
            item.childRelationList = InitSubData(_relationList, _myLevel, item);
        }
        return(resultList);
    }
예제 #2
0
    GameObjectRelationship BuildGameObjRelation(GameObject _obj)
    {
        GameObjectRelationship data = new GameObjectRelationship();

        if (_obj == null)
        {
            return(data);
        }
        data.objName = _obj.name;
        Renderer rd = _obj.GetComponent <Renderer>();

        if (rd == null)
        {
            rd = _obj.GetComponent <SkinnedMeshRenderer>();
        }
        if (rd != null)
        {
            foreach (var item in rd.sharedMaterials)
            {
                if (item != null)
                {
                    data.matNames.Add(item.name.ToLower());
                }
            }
        }
        int count = _obj.transform.childCount;

        for (int i = 0; i < count; i++)
        {
            data.childRelationList.Add(BuildGameObjRelation(_obj.transform.GetChild(i).gameObject));
        }
        return(data);
    }
예제 #3
0
    /// <summary>
    /// 针对unity4.65版本以后的纪录方式,避免序列化对象中的循环嵌套 by吴江
    /// </summary>
    /// <param name="_obj"></param>
    /// <returns></returns>
    GameObjectRelationship BuildGameObjRelationFor465(GameObject _obj)
    {
        GameObjectRelationship data = new GameObjectRelationship();

        if (_obj == null)
        {
            return(data);
        }
        GetRelationShipStructList(data.relationList, _obj, 0);
        return(data);
    }
예제 #4
0
 /// <summary>
 /// 根据关联性配置组装物体
 /// </summary>
 /// <param name="_prefab"></param>
 /// <param name="_relationship"></param>
 public void ProcessGameObjectRelation(GameObject _prefab, GameObjectRelationship _relationship)
 {
     if (_prefab == null || _relationship == null) return;//如果物体为空或关联性配置为空,返回
     if (_relationship.matNames.Count > 0 && _prefab.GetComponent<Renderer>() != null)//如果关联性配置中数据为0或者该物体没有渲染组件,返回
     {
         int count = _relationship.matNames.Count;
         Material[] matArray = _prefab.GetComponent<Renderer>().sharedMaterials;
         for (int i = 0; i < count; i++)//遍历关联性配置数据
         {
             if (i >= matArray.Length)
             {
                 Debug.LogError(_prefab.name + "的配置文件记录的材质数量与实际材质数量不符合,请美术检查资源!");
                 break;
             }
             if (LoadCache.HasLoaded(_relationship.matNames[i], AssetType.material))//如果材质资源缓存中有关联性配置中需求的材质
             {
                 matArray[i] = LoadCache.GetMaterial(_relationship.matNames[i]);//materialAssetBundleRefDic[_relationship.matNames[i]].mainAsset as Material;
                 if (matArray[i] != null && matArray[i].shader != null)
                 {
                     Shader temp = Shader.Find(matArray[i].shader.name);
                     if (temp != null)
                         matArray[i].shader = temp;
                 }
             }
             else
             {
                 Debug.LogError(_prefab.name + " , can't find material that names " + _relationship.matNames[i] + " , please check it ! " + LoadCache.materialRefDic.Count);
             }
         }
         _prefab.GetComponent<Renderer>().sharedMaterials = matArray;
         //_prefab.SetActive(true);
     }
     //对子物体进行递归
     if (_prefab.transform.childCount > 0 && _relationship.childRelationList.Count > 0)
     {
         int fixedCount = Mathf.Min(_prefab.transform.childCount, _relationship.childRelationList.Count);
         for (int i = 0; i < fixedCount; i++)
         {
             ProcessGameObjectRelation(_prefab.transform.GetChild(i).gameObject, _relationship.childRelationList[i]);
         }
     }
 }
예제 #5
0
 public void DebugGameObjectRelation(GameObject _prefab, GameObjectRelationship _relationship)
 {
     if (_prefab == null || _relationship == null) return;//如果物体为空或关联性配置为空,返回
     if (_relationship.matNames.Count > 0)
     {
         int count = _relationship.matNames.Count;
         for (int i = 0; i < count; i++)//遍历关联性配置数据
         {
             Debug.logger.Log("mat = " + _relationship.matNames[i]);
         }
     }
     //对子物体进行递归
     if (_prefab.transform.childCount > 0 && _relationship.childRelationList.Count > 0)
     {
         int fixedCount = Mathf.Min(_prefab.transform.childCount, _relationship.childRelationList.Count);
         for (int i = 0; i < fixedCount; i++)
         {
             DebugGameObjectRelation(_prefab.transform.GetChild(i).gameObject, _relationship.childRelationList[i]);
         }
     }
 }
예제 #6
0
 public SceneAsset(GameObject _sceneObj)
 {
     sceneName = _sceneObj.name;
     gameObjectRelationship = BuildGameObjRelationFor465(_sceneObj as GameObject);
 }
예제 #7
0
        protected static void OnSimMouseUp(WindowBase sender, UIMouseEventArgs eventArgs)
        {
            try
            {
                Window window = sender as Window;
                if ((window != null) && (window.Parent != null))
                {
                    if (eventArgs.MouseKey == MouseKeys.kMouseLeft)
                    {
                        if ((eventArgs.Modifiers & Modifiers.kModifierMaskControl) == Modifiers.kModifierMaskControl)
                        {
                            Sim activeActor = Sim.ActiveActor;

                            if (window.Parent.Tag is SimDescription)
                            {
                                Relationship relation = Relationship.Get((window.Parent.Tag as SimDescription), activeActor.SimDescription, false);
                                if (relation != null)
                                {
                                    Relationship.RemoveRelationship(relation);
                                }
                            }
                            else
                            {
                                MiniSimDescriptionProxy proxy = window.Parent.Tag as MiniSimDescriptionProxy;

                                if ((proxy != null) && (proxy.mSim is GameObjectDescription))
                                {
                                    GameObjectDescription choice = proxy.mSim as GameObjectDescription;

                                    for (int i = activeActor.SimDescription.GameObjectRelationships.Count - 1; i >= 0; i--)
                                    {
                                        GameObjectRelationship relation = activeActor.SimDescription.GameObjectRelationships[i];

                                        if (relation.GameObjectDescription.GameObject == choice.GameObject)
                                        {
                                            activeActor.SimDescription.GameObjectRelationships.RemoveAt(i);
                                        }
                                    }
                                }
                                else
                                {
                                    IMiniSimDescription miniSim = window.Parent.Tag as IMiniSimDescription;

                                    RemoveMiniRelationship(miniSim.SimDescriptionId, activeActor.SimDescription.SimDescriptionId);
                                    RemoveMiniRelationship(activeActor.SimDescription.SimDescriptionId, miniSim.SimDescriptionId);
                                }
                            }

                            RelationshipsPanel.Instance.Repopulate(RelationshipsPanel.Instance.mHudModel.CurrentRelationships);
                        }
                        else if (window.Parent.Tag is SimDescription)
                        {
                            SimDescriptionEx.OnPickFromPanel(window.Parent.Tag as SimDescription, eventArgs, new GameObjectHit(GameObjectHitType.Object));
                        }
                        else if (window.Parent.Tag is MiniSimDescriptionProxy)
                        {
                            MiniSimDescriptionProxy proxy = window.Parent.Tag as MiniSimDescriptionProxy;

                            if (proxy.mSim is GameObjectDescription)
                            {
                                (proxy.mSim as GameObjectDescription).OnPickFromPanel(eventArgs, new GameObjectHit(GameObjectHitType.Object));
                            }
                            else
                            {
                                MiniSimDescriptionEx.OnPickFromPanel(proxy.mSim as MiniSimDescription, eventArgs, new GameObjectHit(GameObjectHitType.Object));
                            }
                        }
                        else
                        {
                            (window.Parent.Tag as IMiniSimDescription).OnPickFromPanel(eventArgs, new GameObjectHit(GameObjectHitType.Object));
                        }
                    }
                    else if (eventArgs.MouseKey == MouseKeys.kMouseRight)
                    {
                        ObjectGuid objectGuid = (window.Tag == null) ? ObjectGuid.InvalidObjectGuid : ((ObjectGuid)window.Tag);
                        if (objectGuid != ObjectGuid.InvalidObjectGuid)
                        {
                            RelationshipsPanel.Instance.mHudModel.MoveCameraToSim(objectGuid);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Common.Exception("OnSimMouseUp", exception);
            }
        }