Пример #1
0
    void OnEnable()
    {
        GetAllPipestyls();

        segmentPrefabCollector      = (PrefabCollector)CreateInstance("PrefabCollector");
        bendSegmentPrefabCollector  = (PrefabCollector)CreateInstance("PrefabCollector");
        interjacentPrefabCollector  = (PrefabCollector)CreateInstance("PrefabCollector");
        endPointPrefabCollector     = (PrefabCollector)CreateInstance("PrefabCollector");
        snappablePrefabCollector    = (PrefabCollector)CreateInstance("PrefabCollector");
        controlPointPrefabCollector = (PrefabCollector)CreateInstance("PrefabCollector");

        if (pipesystem != null)
        {
            segmentPrefabCollector.Setup(pipesystem.segmentPrefab, pipesystem.segmentProbability, usedStyle.segmentPrefab, usedStyle.segmentProbability);
            segmentPrefabCollector.SetupOldProbability();

            bendSegmentPrefabCollector.Setup(pipesystem.bendSegmentPrefab, pipesystem.bendSegmentProbability, usedStyle.bendSegmentPrefab, usedStyle.bendSegmentProbability);
            bendSegmentPrefabCollector.SetupOldProbability();

            interjacentPrefabCollector.Setup(pipesystem.interjacentPrefab, pipesystem.interjacentProbability, usedStyle.interjacentPrefab, usedStyle.interjacentProbability);
            interjacentPrefabCollector.SetupOldProbability();

            endPointPrefabCollector.Setup(pipesystem.endPointPrefab, pipesystem.endPointProbability, usedStyle.endPointPrefab, usedStyle.endPointProbability);
            endPointPrefabCollector.SetupOldProbability();

            snappablePrefabCollector.Setup(pipesystem.snappablePrefab, pipesystem.snappableProbability, usedStyle.snappablePrefab, usedStyle.snappableProbability);
            snappablePrefabCollector.SetupOldProbability();

            controlPointPrefabCollector.Setup(pipesystem.controlPointPrefab, pipesystem.controlPointProbability, usedStyle.controlPointPrefab, usedStyle.controlPointProbability);
            controlPointPrefabCollector.SetupOldProbability();
        }
    }
        void Awake()
        {
            ExecuteOnMainThread       = new Queue <Action>();
            _creatureHelper           = GameObject.Find("GameManager").GetComponent <CreatureHelper>();
            _player                   = Networking.Network.Instance.ClientPlayer;
            _creatureHelper.Creatures = new List <AbstractCreature>();

            MustAttack = false;
            _canMove   = false;

            GameFlow.Instance.Channel = new NetworkMessageChannel(_player);
            GameFlow.Instance.Channel.MoveCallback        += DrawPath;
            GameFlow.Instance.Channel.TurnCallback        += ChangeTurn;
            GameFlow.Instance.Channel.SyncHeroesCallback  += SyncHero;
            GameFlow.Instance.Channel.Attack              += Attack;
            GameFlow.Instance.Channel.GameIsReadyCallback += GameIsReady;
            GameFlow.Instance.Channel.DieCallback         += Die;
            GameFlow.Instance.Channel.FinishGame          += FinishGame;

            Messenger <TileBehaviour> .AddListener("Tile selected", MoveCreatureToSelectedTile);

            Messenger <CreatureComponent> .AddListener("Action finish", FinishAction);

            Messenger <CreatureComponent> .AddListener("CreatureComponent Selected", MouseOverCreature);

            Messenger <CreatureComponent> .AddListener("CreatureComponent Exit", MouseExitCreature);

            Messenger <CreatureComponent> .AddListener("CreatureComponent Attack", MouseClickCreature);

            _hero1Obj = Instantiate(Hero1Prefab) as GameObject;
            _hero2Obj = Instantiate(Hero2Prefab) as GameObject;

            _prefabCollector = PrefabDatabase.GetComponent <PrefabCollector>();

            _creaturePrefabDictionary.Add("Marksman", "GoblinHex");
            _creaturePrefabDictionary.Add("Troglodyte", "OrcHex");

            _creatureHelper.PlayerLeft.text  = GameFlow.Instance.PlayerLeftName;
            _creatureHelper.PlayerRight.text = GameFlow.Instance.PlayerRightName;

            _imageDictionary = new Dictionary <NetworkTypes.CreatureType, Sprite>()
            {
                { NetworkTypes.CreatureType.Range, _prefabCollector.CreatureImages.SingleOrDefault(x => x.Name == "Range").Image },
                { NetworkTypes.CreatureType.Melee, _prefabCollector.CreatureImages.SingleOrDefault(x => x.Name == "Melee").Image }
            };

            var roomName = new SimpleMessage {
                Message = GameFlow.Instance.RoomName
            };
            var parameters = new List <SerializableType> {
                roomName
            };
            var remoteInvokeMethod = new RemoteInvokeMethod("", Command.InitializeBoard, parameters);

            Client.BeginSendPackage(remoteInvokeMethod);
        }
Пример #3
0
        /// <summary>
        /// Translate by sprite's type
        /// </summary>
        /// <param name="targetFolder">Target folder for generating atlas or sprite.</param>
        /// <param name="forward">If true, translate sprite to atlas, else translate atlas to sprite</param>
        public void Translate(string targetFolder, bool forward, string resourceFolder = null, PackSetting setting = null)
        {
            var collectors = new List <ICollector>();
            var transfer   = new List <UnityEngine.UI.Sprite>();
            var exclude    = new List <UnityEngine.UI.Sprite>();
            var prefabs    = AssetDatabase.FindAssets("t:prefab").Select(i => AssetDatabase.GUIDToAssetPath(i)).ToArray();

            for (int i = 0; i < prefabs.Length; i++)
            {
                EditorUtility.DisplayProgressBar("Prefab", prefabs[i], (float)i / prefabs.Length);
                var prefabCollector = new PrefabCollector();
                prefabCollector.path = prefabs[i];
                prefabCollector.Collect();
                collectors.Add(prefabCollector);
                transfer.AddRange(prefabCollector.sprites);
            }
            var scenes = AssetDatabase.FindAssets("t:scene").Select(i => AssetDatabase.GUIDToAssetPath(i)).ToArray();

            for (int i = 0; i < scenes.Length; i++)
            {
                EditorUtility.DisplayProgressBar("Scene", scenes[i], (float)i / scenes.Length);
                var sceneCollector = new SceneCollector();
                sceneCollector.path = scenes[i];
                sceneCollector.Collect();
                collectors.Add(sceneCollector);
                transfer.AddRange(sceneCollector.sprites);
            }
            var clips = AssetDatabase.FindAssets("t:animationclip").Select(i => AssetDatabase.GUIDToAssetPath(i)).ToArray();

            for (int i = 0; i < clips.Length; i++)
            {
                EditorUtility.DisplayProgressBar("AnimationClip", clips[i], (float)i / scenes.Length);
                var clipCollector = new AnimationClipCollector();
                clipCollector.path = clips[i];
                clipCollector.Collect();
                exclude.AddRange(clipCollector.sprites);
            }
            // 过滤类型不符的sprite,过滤在AnimationClip引用的sprite,过滤不在resourceFolder中的资源
            for (int i = transfer.Count - 1; i >= 0; i--)
            {
                if (transfer[i] != null &&
                    ((transfer[i].type == UnityEngine.UI.Sprite.Type.Sprite) != forward ||
                     exclude.Any(e => e == transfer[i])))
                {
                    transfer[i] = null;
                }
            }
            if (!string.IsNullOrEmpty(resourceFolder))
            {
                for (int i = transfer.Count - 1; i >= 0; i--)
                {
                    if (transfer[i] != null)
                    {
                        var transferPath = "";
                        if (transfer[i].type == UnityEngine.UI.Sprite.Type.Sprite)
                        {
                            transferPath = AssetDatabase.GetAssetPath(transfer[i].sprite);
                        }
                        else if (transfer[i].type == UnityEngine.UI.Sprite.Type.Atlas)
                        {
                            transferPath = AssetDatabase.GetAssetPath(transfer[i].atlasRaw);
                        }
                        if (!transferPath.Contains(resourceFolder))
                        {
                            transfer[i] = null;
                        }
                    }
                }
            }
            if (forward)
            {
                MapSprite2Atlas(targetFolder, setting, transfer);
            }
            else
            {
                MapAtlas2Sprite(targetFolder, transfer);
            }
            Util.RebindThenTranslate(collectors, transfer);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.ClearProgressBar();
        }