예제 #1
0
    //---------------------------------------------------
    // GetGroupToSpawn()
    // Will return the data for a group to spawn given
    // a mode and a scoring key.
    //---------------------------------------------------
    public static NinjaData GetGroupToSpawn(NinjaModes eMode, NinjaScoring eScoring)
    {
        if (hashData == null)
        {
            SetupData();
        }

        NinjaData data = null;

        // get the mode data
        if (hashData.Contains(eMode))
        {
            Hashtable hashMode = (Hashtable)hashData[eMode];

            // get the list of entries for the scoring key
            if (hashMode.Contains(eScoring))
            {
                List <NinjaData> listData = (List <NinjaData>)hashMode[eScoring];
                data = GetRandomData(listData);
            }
        }

        if (data == null)
        {
            Debug.LogError("Something going wrong with picking a group for the ninja game to spawn");
        }

        return(data);
    }
예제 #2
0
    public static void SetupData()
    {
        hashData = new Hashtable();

        //Load all data xml files
        UnityEngine.Object[] files = Resources.LoadAll("Ninja/Modes", typeof(TextAsset));
        foreach (TextAsset file in files)
        {
            string xmlString = file.text;

            // error message
            string strErrorFile = "Error in file " + file.name;

            //Create XMLParser instance
            XMLParser xmlParser = new XMLParser(xmlString);

            //Call the parser to build the IXMLNode objects
            XMLElement xmlElement = xmlParser.Parse();

            // we store the data per mode of the ninja game.  the name of the file is the mode.
            NinjaModes eMode = (NinjaModes)System.Enum.Parse(typeof(NinjaModes), file.name);
            hashData[eMode] = new Hashtable();
            Hashtable hashMode = (Hashtable)hashData[eMode];

            //Go through all child node of xmlElement (the parent of the file)
            for (int i = 0; i < xmlElement.Children.Count; i++)
            {
                IXMLNode childNode = xmlElement.Children[i];

                // Get id
                Hashtable hashAttr = XMLUtils.GetAttributes(childNode);
                string    id       = (string)hashAttr["ID"];
                string    strError = strErrorFile + "(" + id + "): ";

                NinjaData data = new NinjaData(id, hashAttr, childNode, strError);

                // we want to stuff the data in each of its scoring categories
                List <NinjaScoring> listScoring = data.GetScoringCategories();
                for (int j = 0; j < listScoring.Count; ++j)
                {
                    NinjaScoring eScoring = listScoring[j];

                    // if the mode doesn't contain this scoring key yet, add it
                    if (!hashMode.ContainsKey(eScoring))
                    {
                        hashMode[eScoring] = new List <NinjaData>();
                    }

                    // add the data to the list of data for this mode/scoring key
                    List <NinjaData> listData = (List <NinjaData>)hashMode[eScoring];
                    listData.Add(data);
                }
            }
        }
    }
예제 #3
0
    void Update()
    {
        if (isTutorialRunning || isGameOver)
        {
            return;
        }

        float deltaTime = Time.deltaTime;

        // update the player's combo
        UpdateComboTimer(deltaTime);

        // if there is a current group of spawn entries in process...
        if (currentTriggerEntries != null && currentTriggerEntries.Count > 0)
        {
            // count up
            timeCount += deltaTime;

            // if our time has surpassed the next entry's time, do it up and remove that entry
            NinjaDataEntry entry     = currentTriggerEntries[0];
            float          timeEntry = entry.GetTime();
            if (timeCount >= timeEntry)
            {
                SpawnGroup(entry);
                currentTriggerEntries.RemoveAt(0);
            }

            // if the list of current entries is empty...null the list and reset our count so we can count down again
            if (currentTriggerEntries.Count == 0)
            {
                currentTriggerEntries = null;
                timeCount             = timeBetweenSpawnGroups;
            }
        }
        else if (timeCount <= 0)
        {
            // otherwise, there is no current group and it is time to start one,
            // so figure out which one to begin
            NinjaScoring scoreKey;
            NinjaData    data = null;
            if (spawning)
            {
                scoreKey = GetScoringKey();
                data     = NinjaDataLoader.GetGroupToSpawn(NinjaModes.Classic, scoreKey);

                // cache the list -- ALMOST FOOLED ME....use new to copy the list
                currentTriggerEntries = new List <NinjaDataEntry>(data.GetEntries());
            }
        }
        else
        {
            timeCount -= deltaTime;             // otherwise, there is no group and we still need to countdown before spawning the next group
        }
    }
예제 #4
0
 // METHODS
 private void MainForm_Load(object sender, EventArgs e)
 {
     try
     {
         NinjaData.ConfigureFormSettings(this);
         Counter        = 0;
         Timer.Tick    += ChartTimer;
         Timer.Enabled  = true;
         Timer.Interval = 5000;
     }
     catch (Exception ex)
     {
         new Error(ex).ShowDialog();
     }
 }
예제 #5
0
    //---------------------------------------------------
    // GetRandomData()
    // Creates a weighted list with the incoming list of
    // data and then returns a random entry from it.
    //---------------------------------------------------
    private static NinjaData GetRandomData(List <NinjaData> listData)
    {
        List <NinjaData> listWeighted = new List <NinjaData>();

        // create the weighted list
        for (int i = 0; i < listData.Count; ++i)
        {
            NinjaData data    = listData[i];
            int       nWeight = data.GetWeight();
            for (int j = 0; j < nWeight; ++j)
            {
                listWeighted.Add(data);
            }
        }

        // pick a random element from the weighted list
        int       nRandom    = UnityEngine.Random.Range(0, listWeighted.Count);
        NinjaData dataRandom = listWeighted[nRandom];

        return(dataRandom);
    }
예제 #6
0
        void UpdateActorPrefabSet(int actorId, NinjaData aInfo, Transform targetPos)
        {
            if (aInfo == null)
            {
                Debuger.LogWarning("ActorInfo is null, actorId:" + actorId);
                return;
            }
            if (curActorObj != null && targetPos != null)
            {
                curActorObj.transform.parent        = targetPos;
                curActorObj.transform.localPosition = Vector3.zero;
                curActorObj.transform.localScale    = Vector3.one;
                curActorObj.transform.localRotation = Quaternion.identity;
                curActorObj.layer = 5;
                SpriteRenderer sprRender = curActorObj.GetComponent <SpriteRenderer>();
                if (sprRender != null && sprRender.sprite != null)
                {
                    if (this.CurActorSandAni != null)
                    {
                        // 将喇叭定位到idle帧的高度位置
                        this.CurActorSandAni.transform.localPosition = new Vector3(-sprRender.sprite.rect.width / 2, sprRender.sprite.rect.height - 25, 0);
                    }
                }

                SpriteRenderer[] sprRenders = curActorObj.GetComponentsInChildren <SpriteRenderer>(true);
                if (sprRenders != null)
                {
                    for (int i = 0; i < sprRenders.Length; ++i)
                    { // 根据白天/黑夜修改角色颜色
                        if (sprRenders[i] != null)
                        {
                            sprRenders[i].color = this.ActorColorMask;
                        }
                    }
                }
                UIEventListener.Get(targetPos.gameObject).onClick = (GameObject go) =>
                {
                    Debuger.Log("点击忍者");

                    if (aInfo.audioId == null || aInfo.audioId == "0.0")
                    {
                        aInfo.audioId = "9003";
                    }
                    bool canPlay = true;
                    if (curActorSnd != null && curActorSnd.EventInst != null)
                    {
                        FMOD.Studio.PLAYBACK_STATE stat;
                        if (FMOD.RESULT.OK == curActorSnd.EventInst.getPlaybackState(out stat) && stat != FMOD.Studio.PLAYBACK_STATE.STOPPED)
                        {
                            canPlay = false;
                        }
                    }

                    if (canPlay)
                    {
                        int audioId;
                        if (int.TryParse(aInfo.audioId, out audioId))
                        {
                            curActorSnd = KHAudioManager.PlaySound(audioId);
                        }
                        if (this.CurActorSandAni != null)
                        {
//                             curActorSndAni.gameObject.SetActive(true);
//                             curActorSndAni.ResetTrigger("beginTalk");
//                             curActorSndAni.SetTrigger("beginTalk");
                        }
                    }
                };
            }
        }