예제 #1
0
    private bool GetUnitFromDictionary(out SerializedDynamicObject unit, string teamPrefix, int index, ref Dictionary <string, object> dictionary)
    {
        unit = null;
        bool isSuccess  = false;
        var  prefix     = teamPrefix + ".object[" + index + "]";
        var  prefabName = (string)DictionaryTools <string, object> .TryToGet(ref dictionary, prefix + ".prefabName", "", out isSuccess, true);

        if (!isSuccess)
        {
            return(false);
        }

        var obj = CreateObject(prefabName);

        if (!obj)
        {
            return(false);
        }
        unit = obj.GetComponent <SerializedDynamicObject>();
        if (!unit)
        {
            return(false);
        }
        return(unit.LoadObject(new KeyValuePair <string, Dictionary <string, object> >(prefix, dictionary)));
    }
예제 #2
0
    private bool AddUnitToDictionary(SerializedDynamicObject unit, string teamPrefix, int index, ref Dictionary <string, object> dictionary)
    {
        var prefix = teamPrefix + ".object[" + index + "]";

        if (!DictionaryTools <string, object> .TryToAdd(ref dictionary, prefix + ".prefabName", unit.PrefabName, true))
        {
            return(false);
        }
        return(unit.SaveObject(new KeyValuePair <string, Dictionary <string, object> >(prefix, dictionary)));
    }
예제 #3
0
    public void LoadStaticObject(SerializedStaticObject.SendMessageStruct param)
    {
        param.SetComponentResult(className, false);
        RemoveAllDynamicChild();
        var  id        = GetComponent <UniqueId>().ID;
        bool isSuccess = false;

        _numberUnits = (int)DictionaryTools <string, object> .TryToGet(ref param.dictionary, className + "[" + id + "]._numberUnits", _numberUnits, out isSuccess, true);

        if (!isSuccess)
        {
            return;
        }

        var numActiveUnits = (int)DictionaryTools <string, object> .TryToGet(ref param.dictionary, className + "[" + id + "].numActiveUnits", 0, out isSuccess, true);

        if (!isSuccess)
        {
            return;
        }

        var teamPrefix = className + "[" + id + "]";

        for (var index = 0; index < numActiveUnits; ++index)
        {
            SerializedDynamicObject unit = null;
            if (!GetUnitFromDictionary(out unit, teamPrefix, index, ref param.dictionary))
            {
                return;
            }

            unit.transform.parent = transform;
        }
        ;
        param.SetComponentResult(className, true);
    }